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 */ 86b13307fSandi 9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 10af182434Sandi 11e5802cb7SAndreas Gohr 12e5802cb7SAndreas Gohrfunction act_dispatch(){ 13e5802cb7SAndreas Gohr $router = \dokuwiki\ActionRouter::getInstance(); // is this needed here or could we delegate it to tpl_content() later? 14e5802cb7SAndreas Gohr 15*e795ba4dSAndreas Gohr $headers = array('Content-Type: text/html; charset=utf-8'); 16e5802cb7SAndreas Gohr trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); 17e5802cb7SAndreas Gohr 18e5802cb7SAndreas Gohr // clear internal variables 19e5802cb7SAndreas Gohr unset($router); 20e5802cb7SAndreas Gohr unset($headers); 21e5802cb7SAndreas Gohr // make all globals available to the template 22e5802cb7SAndreas Gohr extract($GLOBALS); 23e5802cb7SAndreas Gohr 24e5802cb7SAndreas Gohr include(template('main.php')); 25e5802cb7SAndreas Gohr // output for the commands is now handled in inc/templates.php 26e5802cb7SAndreas Gohr // in function tpl_content() 27e5802cb7SAndreas Gohr} 28e5802cb7SAndreas Gohr 296b13307fSandi/** 30c8b076b1SMichael Hamann * Send the given headers using header() 31c8b076b1SMichael Hamann * 32c8b076b1SMichael Hamann * @param array $headers The headers that shall be sent 33c8b076b1SMichael Hamann */ 34f63a2007Schrisfunction act_sendheaders($headers) { 35f63a2007Schris foreach ($headers as $hdr) header($hdr); 36f63a2007Schris} 37f63a2007Schris 386b13307fSandi/** 39af182434Sandi * Sanitize the action command 40af182434Sandi * 41af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 4242ea7f44SGerrit Uitslag * 4342ea7f44SGerrit Uitslag * @param array|string $act 4442ea7f44SGerrit Uitslag * @return string 45af182434Sandi */ 46af182434Sandifunction act_clean($act){ 47ee4c4a1bSAndreas Gohr // check if the action was given as array key 48ee4c4a1bSAndreas Gohr if(is_array($act)){ 49ee4c4a1bSAndreas Gohr list($act) = array_keys($act); 50ee4c4a1bSAndreas Gohr } 51ee4c4a1bSAndreas Gohr 52ac83b9d8Sandi //remove all bad chars 53ac83b9d8Sandi $act = strtolower($act); 542d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/','',$act); 55ac83b9d8Sandi 56ac83b9d8Sandi if($act == 'export_html') $act = 'export_xhtml'; 57cc2ae802SAndreas Gohr if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 58b146b32bSandi 59396c218fSAndreas Gohr if($act === '') $act = 'show'; 6062baad0fSMartin Doucha return $act; 6162baad0fSMartin Doucha} 6262baad0fSMartin Doucha 636b13307fSandi 646b13307fSandi/** 65ee4c4a1bSAndreas Gohr * Handle 'draftdel' 66ee4c4a1bSAndreas Gohr * 67ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user 6842ea7f44SGerrit Uitslag * 6942ea7f44SGerrit Uitslag * @param string $act action command 7042ea7f44SGerrit Uitslag * @return string action command 71ee4c4a1bSAndreas Gohr */ 72ee4c4a1bSAndreas Gohrfunction act_draftdel($act){ 73ee4c4a1bSAndreas Gohr global $INFO; 74ee4c4a1bSAndreas Gohr @unlink($INFO['draft']); 75ee4c4a1bSAndreas Gohr $INFO['draft'] = null; 76ee4c4a1bSAndreas Gohr return 'show'; 77ee4c4a1bSAndreas Gohr} 78ee4c4a1bSAndreas Gohr 79ee4c4a1bSAndreas Gohr/** 80ee4c4a1bSAndreas Gohr * Saves a draft on preview 81ee4c4a1bSAndreas Gohr * 82ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/ 8342ea7f44SGerrit Uitslag * 8442ea7f44SGerrit Uitslag * @param string $act action command 8542ea7f44SGerrit Uitslag * @return string action command 86ee4c4a1bSAndreas Gohr */ 87ee4c4a1bSAndreas Gohrfunction act_draftsave($act){ 88ee4c4a1bSAndreas Gohr global $INFO; 89ee4c4a1bSAndreas Gohr global $ID; 9090f1b7bdSTom N Harris global $INPUT; 91ee4c4a1bSAndreas Gohr global $conf; 9290f1b7bdSTom N Harris if($conf['usedraft'] && $INPUT->post->has('wikitext')) { 93ee4c4a1bSAndreas Gohr $draft = array('id' => $ID, 9490f1b7bdSTom N Harris 'prefix' => substr($INPUT->post->str('prefix'), 0, -1), 9590f1b7bdSTom N Harris 'text' => $INPUT->post->str('wikitext'), 9690f1b7bdSTom N Harris 'suffix' => $INPUT->post->str('suffix'), 9790f1b7bdSTom N Harris 'date' => $INPUT->post->int('date'), 98ee4c4a1bSAndreas Gohr 'client' => $INFO['client'], 99ee4c4a1bSAndreas Gohr ); 100ee4c4a1bSAndreas Gohr $cname = getCacheName($draft['client'].$ID,'.draft'); 101ee4c4a1bSAndreas Gohr if(io_saveFile($cname,serialize($draft))){ 102ee4c4a1bSAndreas Gohr $INFO['draft'] = $cname; 103ee4c4a1bSAndreas Gohr } 104ee4c4a1bSAndreas Gohr } 105ee4c4a1bSAndreas Gohr return $act; 106ee4c4a1bSAndreas Gohr} 107ee4c4a1bSAndreas Gohr 1086b13307fSandi 1091246e016SAndreas Gohr 1101246e016SAndreas Gohr/** 11114a122deSAndreas Gohr * Do a redirect after receiving post data 11214a122deSAndreas Gohr * 11314a122deSAndreas Gohr * Tries to add the section id as hash mark after section editing 11442ea7f44SGerrit Uitslag * 11542ea7f44SGerrit Uitslag * @param string $id page id 11642ea7f44SGerrit Uitslag * @param string $preact action command before redirect 11714a122deSAndreas Gohr */ 11869cd1e27SAndreas Gohrfunction act_redirect($id,$preact){ 11969cd1e27SAndreas Gohr global $PRE; 12069cd1e27SAndreas Gohr global $TEXT; 121f951a474SAndreas Gohr 12269cd1e27SAndreas Gohr $opts = array( 12369cd1e27SAndreas Gohr 'id' => $id, 12469cd1e27SAndreas Gohr 'preact' => $preact 12569cd1e27SAndreas Gohr ); 126c66972f2SAdrian Lang //get section name when coming from section edit 127c66972f2SAdrian Lang if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 128c66972f2SAdrian Lang $check = false; //Byref 129c66972f2SAdrian Lang $opts['fragment'] = sectionID($match[0], $check); 130c66972f2SAdrian Lang } 131c66972f2SAdrian Lang 13269cd1e27SAndreas Gohr trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); 13369cd1e27SAndreas Gohr} 13469cd1e27SAndreas Gohr 135c8b076b1SMichael Hamann/** 136c8b076b1SMichael Hamann * Execute the redirect 137c8b076b1SMichael Hamann * 13842ea7f44SGerrit Uitslag * @param array $opts id and fragment for the redirect and the preact 139c8b076b1SMichael Hamann */ 14069cd1e27SAndreas Gohrfunction act_redirect_execute($opts){ 14169cd1e27SAndreas Gohr $go = wl($opts['id'],'',true); 142c66972f2SAdrian Lang if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; 14369cd1e27SAndreas Gohr 1446b13307fSandi //show it 145af2408d5SAndreas Gohr send_redirect($go); 1466b13307fSandi} 1476b13307fSandi 1486b13307fSandi/** 1498881fcc9SAdrian Lang * Validate POST data 1508881fcc9SAdrian Lang * 1518881fcc9SAdrian Lang * Validates POST data for a subscribe or unsubscribe request. This is the 1528881fcc9SAdrian Lang * default action for the event ACTION_HANDLE_SUBSCRIBE. 1538881fcc9SAdrian Lang * 1548881fcc9SAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 15542ea7f44SGerrit Uitslag * 15642ea7f44SGerrit Uitslag * @param array &$params the parameters: target, style and action 15742ea7f44SGerrit Uitslag * @throws Exception 1588881fcc9SAdrian Lang */ 1597a9add1cSAdrian Langfunction subscription_handle_post(&$params) { 1608881fcc9SAdrian Lang global $INFO; 1618881fcc9SAdrian Lang global $lang; 162585bf44eSChristopher Smith /* @var Input $INPUT */ 163585bf44eSChristopher Smith global $INPUT; 1648881fcc9SAdrian Lang 1655b75cd1fSAdrian Lang // Get and validate parameters. 1668881fcc9SAdrian Lang if (!isset($params['target'])) { 16715741132SAndreas Gohr throw new Exception('no subscription target given'); 1685b75cd1fSAdrian Lang } 1698881fcc9SAdrian Lang $target = $params['target']; 1705b75cd1fSAdrian Lang $valid_styles = array('every', 'digest'); 1715b75cd1fSAdrian Lang if (substr($target, -1, 1) === ':') { 1725b75cd1fSAdrian Lang // Allow “list” subscribe style since the target is a namespace. 1735b75cd1fSAdrian Lang $valid_styles[] = 'list'; 1745b75cd1fSAdrian Lang } 1758881fcc9SAdrian Lang $style = valid_input_set('style', $valid_styles, $params, 17615741132SAndreas Gohr 'invalid subscription style given'); 1778881fcc9SAdrian Lang $action = valid_input_set('action', array('subscribe', 'unsubscribe'), 17815741132SAndreas Gohr $params, 'invalid subscription action given'); 179613964ecSGuy Brand 1805b75cd1fSAdrian Lang // Check other conditions. 1815b75cd1fSAdrian Lang if ($action === 'subscribe') { 1825b75cd1fSAdrian Lang if ($INFO['userinfo']['mail'] === '') { 1835b75cd1fSAdrian Lang throw new Exception($lang['subscr_subscribe_noaddress']); 18452b0dd67SGuy Brand } 1855b75cd1fSAdrian Lang } elseif ($action === 'unsubscribe') { 1865b75cd1fSAdrian Lang $is = false; 1875b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $subscr) { 1885b75cd1fSAdrian Lang if ($subscr['target'] === $target) { 1895b75cd1fSAdrian Lang $is = true; 19052b0dd67SGuy Brand } 19152b0dd67SGuy Brand } 1925b75cd1fSAdrian Lang if ($is === false) { 19315741132SAndreas Gohr throw new Exception(sprintf($lang['subscr_not_subscribed'], 194585bf44eSChristopher Smith $INPUT->server->str('REMOTE_USER'), 1955b75cd1fSAdrian Lang prettyprint_id($target))); 1965b75cd1fSAdrian Lang } 1975b75cd1fSAdrian Lang // subscription_set deletes a subscription if style = null. 1985b75cd1fSAdrian Lang $style = null; 19952b0dd67SGuy Brand } 20052b0dd67SGuy Brand 20116c665d9SAndreas Gohr $params = compact('target', 'style', 'action'); 20252b0dd67SGuy Brand} 20352b0dd67SGuy Brand 204e3776c06SMichael Hamann//Setup VIM: ex: et ts=2 : 205