16b13307fSandi<?php 2d4f83172SAndreas 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 */ 9d4f83172SAndreas 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 21*984279edSAndreas Gohr $headers = [ 22*984279edSAndreas Gohr 'Content-Type: text/html; charset=utf-8', 23*984279edSAndreas Gohr 'Referrer-Policy: strict-origin-when-cross-origin', 24*984279edSAndreas Gohr ]; 25cbb44eabSAndreas Gohr Event::createAndTrigger('ACTION_HEADERS_SEND', $headers, 'act_sendheaders'); 26e5802cb7SAndreas Gohr 27e5802cb7SAndreas Gohr // clear internal variables 28e5802cb7SAndreas Gohr unset($router); 29e5802cb7SAndreas Gohr unset($headers); 30e5802cb7SAndreas Gohr // make all globals available to the template 31e5802cb7SAndreas Gohr extract($GLOBALS); 32e5802cb7SAndreas Gohr 33e5802cb7SAndreas Gohr include(template('main.php')); 34e5802cb7SAndreas Gohr // output for the commands is now handled in inc/templates.php 35e5802cb7SAndreas Gohr // in function tpl_content() 36e5802cb7SAndreas Gohr} 37e5802cb7SAndreas Gohr 386b13307fSandi/** 39c8b076b1SMichael Hamann * Send the given headers using header() 40c8b076b1SMichael Hamann * 41c8b076b1SMichael Hamann * @param array $headers The headers that shall be sent 42c8b076b1SMichael Hamann */ 43d868eb89SAndreas Gohrfunction act_sendheaders($headers) 44d868eb89SAndreas Gohr{ 45f63a2007Schris foreach ($headers as $hdr) header($hdr); 46f63a2007Schris} 47f63a2007Schris 486b13307fSandi/** 49af182434Sandi * Sanitize the action command 50af182434Sandi * 51af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 5242ea7f44SGerrit Uitslag * 5342ea7f44SGerrit Uitslag * @param array|string $act 5442ea7f44SGerrit Uitslag * @return string 55af182434Sandi */ 56d868eb89SAndreas Gohrfunction act_clean($act) 57d868eb89SAndreas Gohr{ 58ee4c4a1bSAndreas Gohr // check if the action was given as array key 59ee4c4a1bSAndreas Gohr if (is_array($act)) { 6024870174SAndreas Gohr [$act] = array_keys($act); 61ee4c4a1bSAndreas Gohr } 62ee4c4a1bSAndreas Gohr 63bf8f8509SAndreas Gohr // no action given 64bf8f8509SAndreas Gohr if ($act === null) return 'show'; 65bf8f8509SAndreas Gohr 66ac83b9d8Sandi //remove all bad chars 67ac83b9d8Sandi $act = strtolower($act); 682d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/', '', $act); 69ac83b9d8Sandi 70ac83b9d8Sandi if ($act == 'export_html') $act = 'export_xhtml'; 71cc2ae802SAndreas Gohr if ($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 72b146b32bSandi 73396c218fSAndreas Gohr if ($act === '') $act = 'show'; 7462baad0fSMartin Doucha return $act; 7562baad0fSMartin Doucha} 76