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 91 $opts = array( 92 'id' => $id, 93 'preact' => $preact 94 ); 95 //get section name when coming from section edit 96 if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 97 $check = false; //Byref 98 $opts['fragment'] = sectionID($match[0], $check); 99 } 100 101 trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); 102} 103 104/** 105 * Execute the redirect 106 * 107 * @param array $opts id and fragment for the redirect and the preact 108 */ 109function act_redirect_execute($opts){ 110 $go = wl($opts['id'],'',true); 111 if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; 112 113 //show it 114 send_redirect($go); 115} 116 117/** 118 * Validate POST data 119 * 120 * Validates POST data for a subscribe or unsubscribe request. This is the 121 * default action for the event ACTION_HANDLE_SUBSCRIBE. 122 * 123 * @author Adrian Lang <lang@cosmocode.de> 124 * 125 * @param array &$params the parameters: target, style and action 126 * @throws Exception 127 */ 128function subscription_handle_post(&$params) { 129 global $INFO; 130 global $lang; 131 /* @var Input $INPUT */ 132 global $INPUT; 133 134 // Get and validate parameters. 135 if (!isset($params['target'])) { 136 throw new Exception('no subscription target given'); 137 } 138 $target = $params['target']; 139 $valid_styles = array('every', 'digest'); 140 if (substr($target, -1, 1) === ':') { 141 // Allow “list” subscribe style since the target is a namespace. 142 $valid_styles[] = 'list'; 143 } 144 $style = valid_input_set('style', $valid_styles, $params, 145 'invalid subscription style given'); 146 $action = valid_input_set('action', array('subscribe', 'unsubscribe'), 147 $params, 'invalid subscription action given'); 148 149 // Check other conditions. 150 if ($action === 'subscribe') { 151 if ($INFO['userinfo']['mail'] === '') { 152 throw new Exception($lang['subscr_subscribe_noaddress']); 153 } 154 } elseif ($action === 'unsubscribe') { 155 $is = false; 156 foreach($INFO['subscribed'] as $subscr) { 157 if ($subscr['target'] === $target) { 158 $is = true; 159 } 160 } 161 if ($is === false) { 162 throw new Exception(sprintf($lang['subscr_not_subscribed'], 163 $INPUT->server->str('REMOTE_USER'), 164 prettyprint_id($target))); 165 } 166 // subscription_set deletes a subscription if style = null. 167 $style = null; 168 } 169 170 $params = compact('target', 'style', 'action'); 171} 172 173//Setup VIM: ex: et ts=2 : 174