xref: /dokuwiki/inc/actions.php (revision cbb44eabe033d70affb048ec0daf4e579e09dd20)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki Actions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
9*cbb44eabSAndreas Gohruse dokuwiki\Extension\Event;
10*cbb44eabSAndreas Gohr
116e4577dcSAndreas Gohr/**
126e4577dcSAndreas Gohr * All action processing starts here
136e4577dcSAndreas Gohr */
14e5802cb7SAndreas Gohrfunction act_dispatch(){
156e4577dcSAndreas Gohr    // always initialize on first dispatch (test request may dispatch mutliple times on one request)
166e4577dcSAndreas Gohr    $router = \dokuwiki\ActionRouter::getInstance(true);
17e5802cb7SAndreas Gohr
18e795ba4dSAndreas Gohr    $headers = array('Content-Type: text/html; charset=utf-8');
19*cbb44eabSAndreas Gohr    Event::createAndTrigger('ACTION_HEADERS_SEND',$headers,'act_sendheaders');
20e5802cb7SAndreas Gohr
21e5802cb7SAndreas Gohr    // clear internal variables
22e5802cb7SAndreas Gohr    unset($router);
23e5802cb7SAndreas Gohr    unset($headers);
24e5802cb7SAndreas Gohr    // make all globals available to the template
25e5802cb7SAndreas Gohr    extract($GLOBALS);
26e5802cb7SAndreas Gohr
27e5802cb7SAndreas Gohr    include(template('main.php'));
28e5802cb7SAndreas Gohr    // output for the commands is now handled in inc/templates.php
29e5802cb7SAndreas Gohr    // in function tpl_content()
30e5802cb7SAndreas Gohr}
31e5802cb7SAndreas Gohr
326b13307fSandi/**
33c8b076b1SMichael Hamann * Send the given headers using header()
34c8b076b1SMichael Hamann *
35c8b076b1SMichael Hamann * @param array $headers The headers that shall be sent
36c8b076b1SMichael Hamann */
37f63a2007Schrisfunction act_sendheaders($headers) {
38f63a2007Schris    foreach ($headers as $hdr) header($hdr);
39f63a2007Schris}
40f63a2007Schris
416b13307fSandi/**
42af182434Sandi * Sanitize the action command
43af182434Sandi *
44af182434Sandi * @author Andreas Gohr <andi@splitbrain.org>
4542ea7f44SGerrit Uitslag *
4642ea7f44SGerrit Uitslag * @param array|string $act
4742ea7f44SGerrit Uitslag * @return string
48af182434Sandi */
49af182434Sandifunction act_clean($act){
50ee4c4a1bSAndreas Gohr    // check if the action was given as array key
51ee4c4a1bSAndreas Gohr    if(is_array($act)){
52ee4c4a1bSAndreas Gohr        list($act) = array_keys($act);
53ee4c4a1bSAndreas Gohr    }
54ee4c4a1bSAndreas Gohr
55ac83b9d8Sandi    //remove all bad chars
56ac83b9d8Sandi    $act = strtolower($act);
572d5ccb39SAndreas Gohr    $act = preg_replace('/[^1-9a-z_]+/','',$act);
58ac83b9d8Sandi
59ac83b9d8Sandi    if($act == 'export_html') $act = 'export_xhtml';
60cc2ae802SAndreas Gohr    if($act == 'export_htmlbody') $act = 'export_xhtmlbody';
61b146b32bSandi
62396c218fSAndreas Gohr    if($act === '') $act = 'show';
6362baad0fSMartin Doucha    return $act;
6462baad0fSMartin Doucha}
65