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