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