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