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 63 64/** 65 * Handle 'draftdel' 66 * 67 * Deletes the draft for the current page and user 68 * 69 * @param string $act action command 70 * @return string action command 71 */ 72function act_draftdel($act){ 73 global $INFO; 74 @unlink($INFO['draft']); 75 $INFO['draft'] = null; 76 return 'show'; 77} 78 79/** 80 * Do a redirect after receiving post data 81 * 82 * Tries to add the section id as hash mark after section editing 83 * 84 * @param string $id page id 85 * @param string $preact action command before redirect 86 */ 87function act_redirect($id,$preact){ 88 global $PRE; 89 global $TEXT; 90 global $INPUT; 91 92 $opts = array( 93 'id' => $id, 94 'preact' => $preact 95 ); 96 //get section name when coming from section edit 97 if ($INPUT->has('hid')) { 98 // Use explicitly transmitted header id 99 $opts['fragment'] = $INPUT->str('hid'); 100 } else if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 101 // Fallback to old mechanism 102 $check = false; //Byref 103 $opts['fragment'] = sectionID($match[0], $check); 104 } 105 106 trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); 107} 108 109/** 110 * Execute the redirect 111 * 112 * @param array $opts id and fragment for the redirect and the preact 113 */ 114function act_redirect_execute($opts){ 115 $go = wl($opts['id'],'',true); 116 if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; 117 118 //show it 119 send_redirect($go); 120} 121 122 123//Setup VIM: ex: et ts=2 : 124