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