xref: /dokuwiki/inc/actions.php (revision b5e63f63ddb301be0f0cebc0ce984b10332d72fb)
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
9if(!defined('DOKU_INC')) die('meh.');
10
11
12function 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 */
34function act_sendheaders($headers) {
35    foreach ($headers as $hdr) header($hdr);
36}
37
38/**
39 * Sanitize the action command
40 *
41 * @author Andreas Gohr <andi@splitbrain.org>
42 *
43 * @param array|string $act
44 * @return string
45 */
46function 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