Completed
Push — master ( bf6f54...20dc95 )
by Andreas
03:16
created

actions.php ➔ act_dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * DokuWiki Actions
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Andreas Gohr <[email protected]>
7
 */
8
9
if(!defined('DOKU_INC')) die('meh.');
10
11
12
function act_dispatch(){
13
    $router = \dokuwiki\ActionRouter::getInstance(); // is this needed here or could we delegate it to tpl_content() later?
14
15
    $headers = array('Content-Type: text/html; charset=utf-8');
16
    trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders');
17
18
    // clear internal variables
19
    unset($router);
20
    unset($headers);
21
    // make all globals available to the template
22
    extract($GLOBALS);
23
24
    include(template('main.php'));
25
    // output for the commands is now handled in inc/templates.php
26
    // in function tpl_content()
27
}
28
29
/**
30
 * Send the given headers using header()
31
 *
32
 * @param array $headers The headers that shall be sent
33
 */
34
function act_sendheaders($headers) {
35
    foreach ($headers as $hdr) header($hdr);
36
}
37
38
/**
39
 * Sanitize the action command
40
 *
41
 * @author Andreas Gohr <[email protected]>
42
 *
43
 * @param array|string $act
44
 * @return string
45
 */
46
function act_clean($act){
47
    // check if the action was given as array key
48
    if(is_array($act)){
49
        list($act) = array_keys($act);
50
    }
51
52
    //remove all bad chars
53
    $act = strtolower($act);
54
    $act = preg_replace('/[^1-9a-z_]+/','',$act);
55
56
    if($act == 'export_html') $act = 'export_xhtml';
57
    if($act == 'export_htmlbody') $act = 'export_xhtmlbody';
58
59
    if($act === '') $act = 'show';
60
    return $act;
61
}
62