16b13307fSandi<?php 2*d4f83172SAndreas Gohr 36b13307fSandi/** 46b13307fSandi * DokuWiki Actions 56b13307fSandi * 66b13307fSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 76b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 86b13307fSandi */ 9*d4f83172SAndreas Gohr 1024870174SAndreas Gohruse dokuwiki\ActionRouter; 11cbb44eabSAndreas Gohruse dokuwiki\Extension\Event; 12cbb44eabSAndreas Gohr 136e4577dcSAndreas Gohr/** 146e4577dcSAndreas Gohr * All action processing starts here 156e4577dcSAndreas Gohr */ 16d868eb89SAndreas Gohrfunction act_dispatch() 17d868eb89SAndreas Gohr{ 186e4577dcSAndreas Gohr // always initialize on first dispatch (test request may dispatch mutliple times on one request) 1924870174SAndreas Gohr $router = ActionRouter::getInstance(true); 20e5802cb7SAndreas Gohr 2124870174SAndreas Gohr $headers = ['Content-Type: text/html; charset=utf-8']; 22cbb44eabSAndreas Gohr Event::createAndTrigger('ACTION_HEADERS_SEND', $headers, 'act_sendheaders'); 23e5802cb7SAndreas Gohr 24e5802cb7SAndreas Gohr // clear internal variables 25e5802cb7SAndreas Gohr unset($router); 26e5802cb7SAndreas Gohr unset($headers); 27e5802cb7SAndreas Gohr // make all globals available to the template 28e5802cb7SAndreas Gohr extract($GLOBALS); 29e5802cb7SAndreas Gohr 30e5802cb7SAndreas Gohr include(template('main.php')); 31e5802cb7SAndreas Gohr // output for the commands is now handled in inc/templates.php 32e5802cb7SAndreas Gohr // in function tpl_content() 33e5802cb7SAndreas Gohr} 34e5802cb7SAndreas Gohr 356b13307fSandi/** 36c8b076b1SMichael Hamann * Send the given headers using header() 37c8b076b1SMichael Hamann * 38c8b076b1SMichael Hamann * @param array $headers The headers that shall be sent 39c8b076b1SMichael Hamann */ 40d868eb89SAndreas Gohrfunction act_sendheaders($headers) 41d868eb89SAndreas Gohr{ 42f63a2007Schris foreach ($headers as $hdr) header($hdr); 43f63a2007Schris} 44f63a2007Schris 456b13307fSandi/** 46af182434Sandi * Sanitize the action command 47af182434Sandi * 48af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 4942ea7f44SGerrit Uitslag * 5042ea7f44SGerrit Uitslag * @param array|string $act 5142ea7f44SGerrit Uitslag * @return string 52af182434Sandi */ 53d868eb89SAndreas Gohrfunction act_clean($act) 54d868eb89SAndreas Gohr{ 55ee4c4a1bSAndreas Gohr // check if the action was given as array key 56ee4c4a1bSAndreas Gohr if (is_array($act)) { 5724870174SAndreas Gohr [$act] = array_keys($act); 58ee4c4a1bSAndreas Gohr } 59ee4c4a1bSAndreas Gohr 60bf8f8509SAndreas Gohr // no action given 61bf8f8509SAndreas Gohr if ($act === null) return 'show'; 62bf8f8509SAndreas Gohr 63ac83b9d8Sandi //remove all bad chars 64ac83b9d8Sandi $act = strtolower($act); 652d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/', '', $act); 66ac83b9d8Sandi 67ac83b9d8Sandi if ($act == 'export_html') $act = 'export_xhtml'; 68cc2ae802SAndreas Gohr if ($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 69b146b32bSandi 70396c218fSAndreas Gohr if ($act === '') $act = 'show'; 7162baad0fSMartin Doucha return $act; 7262baad0fSMartin Doucha} 73