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 = ['Content-Type: text/html; charset=utf-8'];
22    Event::createAndTrigger('ACTION_HEADERS_SEND', $headers, 'act_sendheaders');
23
24    // clear internal variables
25    unset($router);
26    unset($headers);
27    // make all globals available to the template
28    extract($GLOBALS);
29
30    include(template('main.php'));
31    // output for the commands is now handled in inc/templates.php
32    // in function tpl_content()
33}
34
35/**
36 * Send the given headers using header()
37 *
38 * @param array $headers The headers that shall be sent
39 */
40function act_sendheaders($headers)
41{
42    foreach ($headers as $hdr) header($hdr);
43}
44
45/**
46 * Sanitize the action command
47 *
48 * @author Andreas Gohr <andi@splitbrain.org>
49 *
50 * @param array|string $act
51 * @return string
52 */
53function act_clean($act)
54{
55    // check if the action was given as array key
56    if (is_array($act)) {
57        [$act] = array_keys($act);
58    }
59
60    // no action given
61    if ($act === null) return 'show';
62
63    //remove all bad chars
64    $act = strtolower($act);
65    $act = preg_replace('/[^1-9a-z_]+/', '', $act);
66
67    if ($act == 'export_html') $act = 'export_xhtml';
68    if ($act == 'export_htmlbody') $act = 'export_xhtmlbody';
69
70    if ($act === '') $act = 'show';
71    return $act;
72}
73