xref: /dokuwiki/inc/actions.php (revision d868eb89f182718a31113373a6272670bd7f8012)
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 */
824870174SAndreas Gohruse dokuwiki\ActionRouter;
9cbb44eabSAndreas Gohruse dokuwiki\Extension\Event;
10cbb44eabSAndreas Gohr
116e4577dcSAndreas Gohr/**
126e4577dcSAndreas Gohr * All action processing starts here
136e4577dcSAndreas Gohr */
14*d868eb89SAndreas Gohrfunction act_dispatch()
15*d868eb89SAndreas Gohr{
166e4577dcSAndreas Gohr    // always initialize on first dispatch (test request may dispatch mutliple times on one request)
1724870174SAndreas Gohr    $router = ActionRouter::getInstance(true);
18e5802cb7SAndreas Gohr
1924870174SAndreas Gohr    $headers = ['Content-Type: text/html; charset=utf-8'];
20cbb44eabSAndreas Gohr    Event::createAndTrigger('ACTION_HEADERS_SEND', $headers, 'act_sendheaders');
21e5802cb7SAndreas Gohr
22e5802cb7SAndreas Gohr    // clear internal variables
23e5802cb7SAndreas Gohr    unset($router);
24e5802cb7SAndreas Gohr    unset($headers);
25e5802cb7SAndreas Gohr    // make all globals available to the template
26e5802cb7SAndreas Gohr    extract($GLOBALS);
27e5802cb7SAndreas Gohr
28e5802cb7SAndreas Gohr    include(template('main.php'));
29e5802cb7SAndreas Gohr    // output for the commands is now handled in inc/templates.php
30e5802cb7SAndreas Gohr    // in function tpl_content()
31e5802cb7SAndreas Gohr}
32e5802cb7SAndreas Gohr
336b13307fSandi/**
34c8b076b1SMichael Hamann * Send the given headers using header()
35c8b076b1SMichael Hamann *
36c8b076b1SMichael Hamann * @param array $headers The headers that shall be sent
37c8b076b1SMichael Hamann */
38*d868eb89SAndreas Gohrfunction act_sendheaders($headers)
39*d868eb89SAndreas Gohr{
40f63a2007Schris    foreach ($headers as $hdr) header($hdr);
41f63a2007Schris}
42f63a2007Schris
436b13307fSandi/**
44af182434Sandi * Sanitize the action command
45af182434Sandi *
46af182434Sandi * @author Andreas Gohr <andi@splitbrain.org>
4742ea7f44SGerrit Uitslag *
4842ea7f44SGerrit Uitslag * @param array|string $act
4942ea7f44SGerrit Uitslag * @return string
50af182434Sandi */
51*d868eb89SAndreas Gohrfunction act_clean($act)
52*d868eb89SAndreas Gohr{
53ee4c4a1bSAndreas Gohr    // check if the action was given as array key
54ee4c4a1bSAndreas Gohr    if(is_array($act)){
5524870174SAndreas Gohr        [$act] = array_keys($act);
56ee4c4a1bSAndreas Gohr    }
57ee4c4a1bSAndreas Gohr
58bf8f8509SAndreas Gohr    // no action given
59bf8f8509SAndreas Gohr    if($act === null) return 'show';
60bf8f8509SAndreas Gohr
61ac83b9d8Sandi    //remove all bad chars
62ac83b9d8Sandi    $act = strtolower($act);
632d5ccb39SAndreas Gohr    $act = preg_replace('/[^1-9a-z_]+/', '', $act);
64ac83b9d8Sandi
65ac83b9d8Sandi    if($act == 'export_html') $act = 'export_xhtml';
66cc2ae802SAndreas Gohr    if($act == 'export_htmlbody') $act = 'export_xhtmlbody';
67b146b32bSandi
68396c218fSAndreas Gohr    if($act === '') $act = 'show';
6962baad0fSMartin Doucha    return $act;
7062baad0fSMartin Doucha}
71