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