actions.php 1.6 KB

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