You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

73 lines
1.6 KiB

  1. <?php
  2. /**
  3. * DokuWiki Actions
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. */
  8. use dokuwiki\ActionRouter;
  9. use dokuwiki\Extension\Event;
  10. /**
  11. * All action processing starts here
  12. */
  13. function act_dispatch()
  14. {
  15. // always initialize on first dispatch (test request may dispatch mutliple times on one request)
  16. $router = ActionRouter::getInstance(true);
  17. $headers = ['Content-Type: text/html; charset=utf-8'];
  18. Event::createAndTrigger('ACTION_HEADERS_SEND', $headers, 'act_sendheaders');
  19. // clear internal variables
  20. unset($router);
  21. unset($headers);
  22. // make all globals available to the template
  23. extract($GLOBALS);
  24. include(template('main.php'));
  25. // output for the commands is now handled in inc/templates.php
  26. // in function tpl_content()
  27. }
  28. /**
  29. * Send the given headers using header()
  30. *
  31. * @param array $headers The headers that shall be sent
  32. */
  33. function act_sendheaders($headers)
  34. {
  35. foreach ($headers as $hdr) header($hdr);
  36. }
  37. /**
  38. * Sanitize the action command
  39. *
  40. * @author Andreas Gohr <andi@splitbrain.org>
  41. *
  42. * @param array|string $act
  43. * @return string
  44. */
  45. function act_clean($act)
  46. {
  47. // check if the action was given as array key
  48. if (is_array($act)) {
  49. [$act] = array_keys($act);
  50. }
  51. // no action given
  52. if ($act === null) return 'show';
  53. //remove all bad chars
  54. $act = strtolower($act);
  55. $act = preg_replace('/[^1-9a-z_]+/', '', $act);
  56. if ($act == 'export_html') $act = 'export_xhtml';
  57. if ($act == 'export_htmlbody') $act = 'export_xhtmlbody';
  58. if ($act === '') $act = 'show';
  59. return $act;
  60. }