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 900976812SAndreas Gohr if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/'); 106b13307fSandi require_once(DOKU_INC.'inc/template.php'); 116b13307fSandi 12af182434Sandi 136b13307fSandi/** 146b13307fSandi * Call the needed action handlers 156b13307fSandi * 166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 17c9570649SAndreas Gohr * @triggers ACTION_ACT_PREPROCESS 18c9570649SAndreas Gohr * @triggers ACTION_HEADERS_SEND 196b13307fSandi */ 206b13307fSandifunction act_dispatch(){ 216b13307fSandi global $INFO; 226b13307fSandi global $ACT; 236b13307fSandi global $ID; 246b13307fSandi global $QUERY; 256b13307fSandi global $lang; 266b13307fSandi global $conf; 276b13307fSandi 28*69cd1e27SAndreas Gohr $preact = $ACT; 29*69cd1e27SAndreas Gohr 30c2e830f2Schris // give plugins an opportunity to process the action 3124bb549bSchris $evt = new Doku_Event('ACTION_ACT_PREPROCESS',$ACT); 3224bb549bSchris if ($evt->advise_before()) { 33c2e830f2Schris 34af182434Sandi //sanitize $ACT 35af182434Sandi $ACT = act_clean($ACT); 36af182434Sandi 37b8957367SBenjamin Gilbert //check if searchword was given - else just show 380868021bSAndreas Gohr $s = cleanID($QUERY); 390868021bSAndreas Gohr if($ACT == 'search' && empty($s)){ 40b8957367SBenjamin Gilbert $ACT = 'show'; 41b8957367SBenjamin Gilbert } 42b8957367SBenjamin Gilbert 43b8957367SBenjamin Gilbert //login stuff 441b2a85e8SAndreas Gohr if(in_array($ACT,array('login','logout'))){ 45b8957367SBenjamin Gilbert $ACT = act_auth($ACT); 461b2a85e8SAndreas Gohr } 47b8957367SBenjamin Gilbert 481380fc45SAndreas Gohr //check if user is asking to (un)subscribe a page 491380fc45SAndreas Gohr if($ACT == 'subscribe' || $ACT == 'unsubscribe') 501380fc45SAndreas Gohr $ACT = act_subscription($ACT); 51b158d625SSteven Danz 5252b0dd67SGuy Brand //check if user is asking to (un)subscribe a namespace 5352b0dd67SGuy Brand if($ACT == 'subscribens' || $ACT == 'unsubscribens') 5452b0dd67SGuy Brand $ACT = act_subscriptionns($ACT); 5552b0dd67SGuy Brand 566b13307fSandi //check permissions 576b13307fSandi $ACT = act_permcheck($ACT); 586b13307fSandi 59b8957367SBenjamin Gilbert //register 60c9570649SAndreas Gohr $nil = array(); 61b3510079SAndreas Gohr if($ACT == 'register' && $_POST['save'] && register()){ 62b8957367SBenjamin Gilbert $ACT = 'login'; 63b8957367SBenjamin Gilbert } 646b13307fSandi 658b06d178Schris if ($ACT == 'resendpwd' && act_resendpwd()) { 668b06d178Schris $ACT = 'login'; 678b06d178Schris } 688b06d178Schris 698b06d178Schris //update user profile 708b06d178Schris if (($ACT == 'profile') && updateprofile()) { 714cb79657SMatthias Grimm msg($lang['profchanged'],1); 724cb79657SMatthias Grimm $ACT = 'show'; 738b06d178Schris } 748b06d178Schris 756b13307fSandi //save 761b2a85e8SAndreas Gohr if($ACT == 'save'){ 771b2a85e8SAndreas Gohr if(checkSecurityToken()){ 786b13307fSandi $ACT = act_save($ACT); 791b2a85e8SAndreas Gohr }else{ 801b2a85e8SAndreas Gohr $ACT = 'show'; 811b2a85e8SAndreas Gohr } 821b2a85e8SAndreas Gohr } 836b13307fSandi 84067c5d22SBen Coburn //cancel conflicting edit 85067c5d22SBen Coburn if($ACT == 'cancel') 86067c5d22SBen Coburn $ACT = 'show'; 87067c5d22SBen Coburn 88ee4c4a1bSAndreas Gohr //draft deletion 89ee4c4a1bSAndreas Gohr if($ACT == 'draftdel') 90ee4c4a1bSAndreas Gohr $ACT = act_draftdel($ACT); 91ee4c4a1bSAndreas Gohr 92ee4c4a1bSAndreas Gohr //draft saving on preview 93ee4c4a1bSAndreas Gohr if($ACT == 'preview') 94ee4c4a1bSAndreas Gohr $ACT = act_draftsave($ACT); 95ee4c4a1bSAndreas Gohr 966b13307fSandi //edit 97b146b32bSandi if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ 98af182434Sandi $ACT = act_edit($ACT); 996b13307fSandi }else{ 1006b13307fSandi unlock($ID); //try to unlock 1016b13307fSandi } 1026b13307fSandi 1036b13307fSandi //handle export 104ac83b9d8Sandi if(substr($ACT,0,7) == 'export_') 1056b13307fSandi $ACT = act_export($ACT); 1066b13307fSandi 1076b13307fSandi //display some infos 1086b13307fSandi if($ACT == 'check'){ 1096b13307fSandi check(); 1106b13307fSandi $ACT = 'show'; 1116b13307fSandi } 1126b13307fSandi 113c19fe9c0Sandi //handle admin tasks 114c19fe9c0Sandi if($ACT == 'admin'){ 11511e2ce22Schris // retrieve admin plugin name from $_REQUEST['page'] 116bb4866bdSchris if (!empty($_REQUEST['page'])) { 11711e2ce22Schris $pluginlist = plugin_list('admin'); 11811e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 11911e2ce22Schris // attempt to load the plugin 12011e2ce22Schris if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL) 12111e2ce22Schris $plugin->handle(); 12211e2ce22Schris } 12311e2ce22Schris } 124c19fe9c0Sandi } 1255f312bacSAndreas Gohr 1265f312bacSAndreas Gohr // check permissions again - the action may have changed 1275f312bacSAndreas Gohr $ACT = act_permcheck($ACT); 12824bb549bSchris } // end event ACTION_ACT_PREPROCESS default action 12924bb549bSchris $evt->advise_after(); 13024bb549bSchris unset($evt); 131c19fe9c0Sandi 132*69cd1e27SAndreas Gohr // when action 'show' and POST, do a redirect 133*69cd1e27SAndreas Gohr if($ACT == 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ 134*69cd1e27SAndreas Gohr act_redirect($ID,$preact); 135*69cd1e27SAndreas Gohr } 1365f312bacSAndreas Gohr 1376b13307fSandi //call template FIXME: all needed vars available? 138f63a2007Schris $headers[] = 'Content-Type: text/html; charset=utf-8'; 139746855cfSBen Coburn trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); 140f63a2007Schris 1415a892029SAndreas Gohr include(template('main.php')); 142c19fe9c0Sandi // output for the commands is now handled in inc/templates.php 143c19fe9c0Sandi // in function tpl_content() 1446b13307fSandi} 1456b13307fSandi 146f63a2007Schrisfunction act_sendheaders($headers) { 147f63a2007Schris foreach ($headers as $hdr) header($hdr); 148f63a2007Schris} 149f63a2007Schris 1506b13307fSandi/** 151af182434Sandi * Sanitize the action command 152af182434Sandi * 153af182434Sandi * Add all allowed commands here. 154af182434Sandi * 155af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 156af182434Sandi */ 157af182434Sandifunction act_clean($act){ 158af182434Sandi global $lang; 15960e6b550SAndreas Gohr global $conf; 160af182434Sandi 161ee4c4a1bSAndreas Gohr // check if the action was given as array key 162ee4c4a1bSAndreas Gohr if(is_array($act)){ 163ee4c4a1bSAndreas Gohr list($act) = array_keys($act); 164ee4c4a1bSAndreas Gohr } 165ee4c4a1bSAndreas Gohr 166ac83b9d8Sandi //remove all bad chars 167ac83b9d8Sandi $act = strtolower($act); 1682d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/','',$act); 169ac83b9d8Sandi 170ac83b9d8Sandi if($act == 'export_html') $act = 'export_xhtml'; 171cc2ae802SAndreas Gohr if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 172b146b32bSandi 173409d7af7SAndreas Gohr // check if action is disabled 174409d7af7SAndreas Gohr if(!actionOK($act)){ 175409d7af7SAndreas Gohr msg('Command disabled: '.htmlspecialchars($act),-1); 176409d7af7SAndreas Gohr return 'show'; 177409d7af7SAndreas Gohr } 178409d7af7SAndreas Gohr 17960e6b550SAndreas Gohr //disable all acl related commands if ACL is disabled 18060e6b550SAndreas Gohr if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', 18160e6b550SAndreas Gohr 'subscribe','unsubscribe','profile', 18252b0dd67SGuy Brand 'resendpwd','subscribens','unsubscribens',))){ 18360e6b550SAndreas Gohr msg('Command unavailable: '.htmlspecialchars($act),-1); 18460e6b550SAndreas Gohr return 'show'; 18560e6b550SAndreas Gohr } 18660e6b550SAndreas Gohr 187067c5d22SBen Coburn if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', 188ac83b9d8Sandi 'preview','search','show','check','index','revisions', 1891380fc45SAndreas Gohr 'diff','recent','backlink','admin','subscribe', 19018829381SAndreas Gohr 'unsubscribe','profile','resendpwd','recover','wordblock', 19152b0dd67SGuy Brand 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { 192ee4c4a1bSAndreas Gohr msg('Command unknown: '.htmlspecialchars($act),-1); 193af182434Sandi return 'show'; 194af182434Sandi } 195af182434Sandi return $act; 196af182434Sandi} 197af182434Sandi 198af182434Sandi/** 1996b13307fSandi * Run permissionchecks 2006b13307fSandi * 2016b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2026b13307fSandi */ 2036b13307fSandifunction act_permcheck($act){ 204dbbc6aa7Sandi global $INFO; 2055e199953Smatthiasgrimm global $conf; 206dbbc6aa7Sandi 207ee4c4a1bSAndreas Gohr if(in_array($act,array('save','preview','edit','recover'))){ 2086b13307fSandi if($INFO['exists']){ 209bdbc16bfSandi if($act == 'edit'){ 210bdbc16bfSandi //the edit function will check again and do a source show 211bdbc16bfSandi //when no AUTH_EDIT available 212bdbc16bfSandi $permneed = AUTH_READ; 213bdbc16bfSandi }else{ 2146b13307fSandi $permneed = AUTH_EDIT; 215bdbc16bfSandi } 2166b13307fSandi }else{ 2176b13307fSandi $permneed = AUTH_CREATE; 2186b13307fSandi } 2198b06d178Schris }elseif(in_array($act,array('login','search','recent','profile'))){ 2206b13307fSandi $permneed = AUTH_NONE; 2215e199953Smatthiasgrimm }elseif($act == 'register'){ 2225e199953Smatthiasgrimm $permneed = AUTH_NONE; 223ebd3d9ceSchris }elseif($act == 'resendpwd'){ 224ebd3d9ceSchris $permneed = AUTH_NONE; 225c19fe9c0Sandi }elseif($act == 'admin'){ 226f8cc712eSAndreas Gohr if($INFO['ismanager']){ 227f8cc712eSAndreas Gohr // if the manager has the needed permissions for a certain admin 228f8cc712eSAndreas Gohr // action is checked later 229f8cc712eSAndreas Gohr $permneed = AUTH_READ; 230f8cc712eSAndreas Gohr }else{ 231c19fe9c0Sandi $permneed = AUTH_ADMIN; 232f8cc712eSAndreas Gohr } 2336b13307fSandi }else{ 2346b13307fSandi $permneed = AUTH_READ; 2356b13307fSandi } 236dbbc6aa7Sandi if($INFO['perm'] >= $permneed) return $act; 237dbbc6aa7Sandi 2386b13307fSandi return 'denied'; 2396b13307fSandi} 2406b13307fSandi 2416b13307fSandi/** 242ee4c4a1bSAndreas Gohr * Handle 'draftdel' 243ee4c4a1bSAndreas Gohr * 244ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user 245ee4c4a1bSAndreas Gohr */ 246ee4c4a1bSAndreas Gohrfunction act_draftdel($act){ 247ee4c4a1bSAndreas Gohr global $INFO; 248ee4c4a1bSAndreas Gohr @unlink($INFO['draft']); 249ee4c4a1bSAndreas Gohr $INFO['draft'] = null; 250ee4c4a1bSAndreas Gohr return 'show'; 251ee4c4a1bSAndreas Gohr} 252ee4c4a1bSAndreas Gohr 253ee4c4a1bSAndreas Gohr/** 254ee4c4a1bSAndreas Gohr * Saves a draft on preview 255ee4c4a1bSAndreas Gohr * 256ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/ 257ee4c4a1bSAndreas Gohr */ 258ee4c4a1bSAndreas Gohrfunction act_draftsave($act){ 259ee4c4a1bSAndreas Gohr global $INFO; 260ee4c4a1bSAndreas Gohr global $ID; 261ee4c4a1bSAndreas Gohr global $conf; 262ee4c4a1bSAndreas Gohr if($conf['usedraft'] && $_POST['wikitext']){ 263ee4c4a1bSAndreas Gohr $draft = array('id' => $ID, 264ee4c4a1bSAndreas Gohr 'prefix' => $_POST['prefix'], 265ee4c4a1bSAndreas Gohr 'text' => $_POST['wikitext'], 266ee4c4a1bSAndreas Gohr 'suffix' => $_POST['suffix'], 267ee4c4a1bSAndreas Gohr 'date' => $_POST['date'], 268ee4c4a1bSAndreas Gohr 'client' => $INFO['client'], 269ee4c4a1bSAndreas Gohr ); 270ee4c4a1bSAndreas Gohr $cname = getCacheName($draft['client'].$ID,'.draft'); 271ee4c4a1bSAndreas Gohr if(io_saveFile($cname,serialize($draft))){ 272ee4c4a1bSAndreas Gohr $INFO['draft'] = $cname; 273ee4c4a1bSAndreas Gohr } 274ee4c4a1bSAndreas Gohr } 275ee4c4a1bSAndreas Gohr return $act; 276ee4c4a1bSAndreas Gohr} 277ee4c4a1bSAndreas Gohr 278ee4c4a1bSAndreas Gohr/** 2796b13307fSandi * Handle 'save' 2806b13307fSandi * 2816b13307fSandi * Checks for spam and conflicts and saves the page. 2826b13307fSandi * Does a redirect to show the page afterwards or 2836b13307fSandi * returns a new action. 2846b13307fSandi * 2856b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2866b13307fSandi */ 2876b13307fSandifunction act_save($act){ 2886b13307fSandi global $ID; 2896b13307fSandi global $DATE; 2906b13307fSandi global $PRE; 2916b13307fSandi global $TEXT; 2926b13307fSandi global $SUF; 2936b13307fSandi global $SUM; 2946b13307fSandi 2956b13307fSandi //spam check 2966b13307fSandi if(checkwordblock()) 2976b13307fSandi return 'wordblock'; 2986b13307fSandi //conflict check //FIXME use INFO 2996b13307fSandi if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) 3006b13307fSandi return 'conflict'; 3016b13307fSandi 3026b13307fSandi //save it 303b6912aeaSAndreas Gohr saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con 3046b13307fSandi //unlock it 3056b13307fSandi unlock($ID); 3066b13307fSandi 307ee4c4a1bSAndreas Gohr //delete draft 308ee4c4a1bSAndreas Gohr act_draftdel($act); 309*69cd1e27SAndreas Gohr session_write_close(); 310ee4c4a1bSAndreas Gohr 311*69cd1e27SAndreas Gohr // when done, show page 312*69cd1e27SAndreas Gohr return 'show'; 313*69cd1e27SAndreas Gohr} 314f951a474SAndreas Gohr 315*69cd1e27SAndreas Gohrfunction act_redirect($id,$preact){ 316*69cd1e27SAndreas Gohr global $PRE; 317*69cd1e27SAndreas Gohr global $TEXT; 318f951a474SAndreas Gohr 319f951a474SAndreas Gohr //get section name when coming from section edit 320f951a474SAndreas Gohr if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 321f951a474SAndreas Gohr #FIXME duplicates code from xhtml renderer 322f951a474SAndreas Gohr $title = $match[0]; 323f951a474SAndreas Gohr $title = str_replace(':','',cleanID($title)); 324f951a474SAndreas Gohr $title = ltrim($title,'0123456789._-'); 325f951a474SAndreas Gohr if(empty($title)) $title='section'; 326f951a474SAndreas Gohr } 327f951a474SAndreas Gohr 328*69cd1e27SAndreas Gohr $opts = array( 329*69cd1e27SAndreas Gohr 'id' => $id, 330*69cd1e27SAndreas Gohr 'fragment' => $title, 331*69cd1e27SAndreas Gohr 'preact' => $preact 332*69cd1e27SAndreas Gohr ); 333*69cd1e27SAndreas Gohr trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); 334*69cd1e27SAndreas Gohr} 335*69cd1e27SAndreas Gohr 336*69cd1e27SAndreas Gohrfunction act_redirect_execute($opts){ 337*69cd1e27SAndreas Gohr $go = wl($opts['id'],'',true); 338*69cd1e27SAndreas Gohr if($opts['fragment']) $go .= '#'.$opts['fragment']; 339*69cd1e27SAndreas Gohr 3406b13307fSandi //show it 341f951a474SAndreas Gohr header("Location: $go"); 3426b13307fSandi exit(); 3436b13307fSandi} 3446b13307fSandi 3456b13307fSandi/** 346b8957367SBenjamin Gilbert * Handle 'login', 'logout' 3476b13307fSandi * 3486b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3496b13307fSandi */ 3506b13307fSandifunction act_auth($act){ 35108eda5bcSmatthiasgrimm global $ID; 3527cace34dSAndreas Gohr global $INFO; 35308eda5bcSmatthiasgrimm 3546b13307fSandi //already logged in? 3552288dc06SGuy Brand if($_SERVER['REMOTE_USER'] && $act=='login'){ 3562288dc06SGuy Brand header("Location: ".wl($ID,'',true)); 3572288dc06SGuy Brand exit; 3582288dc06SGuy Brand } 3596b13307fSandi 3606b13307fSandi //handle logout 3616b13307fSandi if($act=='logout'){ 36208eda5bcSmatthiasgrimm $lockedby = checklock($ID); //page still locked? 363424c3c4fSJohannes Buchner if($lockedby == $_SERVER['REMOTE_USER']) 36408eda5bcSmatthiasgrimm unlock($ID); //try to unlock 36508eda5bcSmatthiasgrimm 3667cace34dSAndreas Gohr // do the logout stuff 3676b13307fSandi auth_logoff(); 3687cace34dSAndreas Gohr 3697cace34dSAndreas Gohr // rebuild info array 3707cace34dSAndreas Gohr $INFO = pageinfo(); 3717cace34dSAndreas Gohr 3726b13307fSandi return 'login'; 3736b13307fSandi } 3746b13307fSandi 3756b13307fSandi return $act; 3766b13307fSandi} 3776b13307fSandi 3786b13307fSandi/** 3796b13307fSandi * Handle 'edit', 'preview' 3806b13307fSandi * 3816b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3826b13307fSandi */ 3836b13307fSandifunction act_edit($act){ 384cd409024Sjorda global $ID; 385ee4c4a1bSAndreas Gohr global $INFO; 386cd409024Sjorda 3876b13307fSandi //check if locked by anyone - if not lock for my self 3886b13307fSandi $lockedby = checklock($ID); 3896b13307fSandi if($lockedby) return 'locked'; 3906b13307fSandi 3916b13307fSandi lock($ID); 3926b13307fSandi return $act; 3936b13307fSandi} 3946b13307fSandi 3956b13307fSandi/** 3966b13307fSandi * Handle 'edit', 'preview' 3976b13307fSandi * 3986b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3996b13307fSandi */ 4006b13307fSandifunction act_export($act){ 4016b13307fSandi global $ID; 4026b13307fSandi global $REV; 4036b13307fSandi 404c3673e61SAndreas Gohr // search engines: never cache exported docs! (Google only currently) 405c3673e61SAndreas Gohr header('X-Robots-Tag: noindex'); 406c3673e61SAndreas Gohr 407ac83b9d8Sandi // no renderer for this 408ac83b9d8Sandi if($act == 'export_raw'){ 409ac83b9d8Sandi header('Content-Type: text/plain; charset=utf-8'); 410ac83b9d8Sandi print rawWiki($ID,$REV); 411ac83b9d8Sandi exit; 412ac83b9d8Sandi } 413ac83b9d8Sandi 414ac83b9d8Sandi // html export #FIXME what about the template's style? 415ac83b9d8Sandi if($act == 'export_xhtml'){ 41685f8705cSAnika Henke global $conf; 41785f8705cSAnika Henke global $lang; 4186b13307fSandi header('Content-Type: text/html; charset=utf-8'); 41985f8705cSAnika Henke ptln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'); 42085f8705cSAnika Henke ptln(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); 42185f8705cSAnika Henke ptln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"'); 42285f8705cSAnika Henke ptln(' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">'); 4236b13307fSandi ptln('<head>'); 42485f8705cSAnika Henke ptln(' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'); 42585f8705cSAnika Henke ptln(' <title>'.$ID.'</title>'); 4266b13307fSandi tpl_metaheaders(); 4276b13307fSandi ptln('</head>'); 4286b13307fSandi ptln('<body>'); 4292c5c3308SAndreas Gohr ptln('<div class="dokuwiki export">'); 4303c86d7c9SAndreas Gohr $html = p_wiki_xhtml($ID,$REV,false); 4313c86d7c9SAndreas Gohr tpl_toc(); 4323c86d7c9SAndreas Gohr echo $html; 433c771e9edSAnika Henke ptln('</div>'); 4346b13307fSandi ptln('</body>'); 4356b13307fSandi ptln('</html>'); 4366b13307fSandi exit; 4376b13307fSandi } 4386b13307fSandi 439cc2ae802SAndreas Gohr // html body only 440cc2ae802SAndreas Gohr if($act == 'export_xhtmlbody'){ 4413c86d7c9SAndreas Gohr $html = p_wiki_xhtml($ID,$REV,false); 4423c86d7c9SAndreas Gohr tpl_toc(); 4433c86d7c9SAndreas Gohr echo $html; 444cc2ae802SAndreas Gohr exit; 445cc2ae802SAndreas Gohr } 446cc2ae802SAndreas Gohr 447b3510079SAndreas Gohr // try to run renderer 448ac83b9d8Sandi $mode = substr($act,7); 4492d5ccb39SAndreas Gohr $text = p_cached_output(wikiFN($ID,$REV), $mode); 45085767031SAndreas Gohr $headers = p_get_metadata($ID,"format $mode"); 451ac83b9d8Sandi if(!is_null($text)){ 45285767031SAndreas Gohr if(is_array($headers)) foreach($headers as $key => $val){ 45385767031SAndreas Gohr header("$key: $val"); 45485767031SAndreas Gohr } 455ac83b9d8Sandi print $text; 4566b13307fSandi exit; 4576b13307fSandi } 4586b13307fSandi 4596b13307fSandi return 'show'; 4606b13307fSandi} 461340756e4Sandi 462b158d625SSteven Danz/** 46352b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe' 464b158d625SSteven Danz * 465b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com> 4661380fc45SAndreas Gohr * @todo localize 467b158d625SSteven Danz */ 4681380fc45SAndreas Gohrfunction act_subscription($act){ 469b158d625SSteven Danz global $ID; 470b158d625SSteven Danz global $INFO; 471f9eb5648Ssteven-danz global $lang; 472b158d625SSteven Danz 4731380fc45SAndreas Gohr $file=metaFN($ID,'.mlist'); 4741380fc45SAndreas Gohr if ($act=='subscribe' && !$INFO['subscribed']){ 475b158d625SSteven Danz if ($INFO['userinfo']['mail']){ 4761380fc45SAndreas Gohr if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 4771380fc45SAndreas Gohr $INFO['subscribed'] = true; 478f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 479b158d625SSteven Danz } else { 480f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 481b158d625SSteven Danz } 482b158d625SSteven Danz } else { 483f9eb5648Ssteven-danz msg($lang['subscribe_noaddress']); 484b158d625SSteven Danz } 4851380fc45SAndreas Gohr } elseif ($act=='unsubscribe' && $INFO['subscribed']){ 486b158d625SSteven Danz if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 4871380fc45SAndreas Gohr $INFO['subscribed'] = false; 488f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 489b158d625SSteven Danz } else { 490f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 491b158d625SSteven Danz } 492b158d625SSteven Danz } 493b158d625SSteven Danz 494b158d625SSteven Danz return 'show'; 495b158d625SSteven Danz} 496b158d625SSteven Danz 49752b0dd67SGuy Brand/** 49852b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe' 49952b0dd67SGuy Brand * 50052b0dd67SGuy Brand */ 50152b0dd67SGuy Brandfunction act_subscriptionns($act){ 50252b0dd67SGuy Brand global $ID; 50352b0dd67SGuy Brand global $INFO; 50452b0dd67SGuy Brand global $lang; 50552b0dd67SGuy Brand 50652b0dd67SGuy Brand if(!getNS($ID)) { 50752b0dd67SGuy Brand $file = metaFN(getNS($ID),'.mlist'); 508613964ecSGuy Brand $ns = "root"; 50952b0dd67SGuy Brand } else { 51052b0dd67SGuy Brand $file = metaFN(getNS($ID),'/.mlist'); 511613964ecSGuy Brand $ns = getNS($ID); 51252b0dd67SGuy Brand } 51352b0dd67SGuy Brand 514613964ecSGuy Brand // reuse strings used to display the status of the subscribe action 515613964ecSGuy Brand $act_msg = rtrim($act, 'ns'); 516613964ecSGuy Brand 51752b0dd67SGuy Brand if ($act=='subscribens' && !$INFO['subscribedns']){ 51852b0dd67SGuy Brand if ($INFO['userinfo']['mail']){ 51952b0dd67SGuy Brand if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 52052b0dd67SGuy Brand $INFO['subscribedns'] = true; 521613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 52252b0dd67SGuy Brand } else { 523613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 52452b0dd67SGuy Brand } 52552b0dd67SGuy Brand } else { 52652b0dd67SGuy Brand msg($lang['subscribe_noaddress']); 52752b0dd67SGuy Brand } 52852b0dd67SGuy Brand } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ 52952b0dd67SGuy Brand if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 53052b0dd67SGuy Brand $INFO['subscribedns'] = false; 531613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 53252b0dd67SGuy Brand } else { 533613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 53452b0dd67SGuy Brand } 53552b0dd67SGuy Brand } 53652b0dd67SGuy Brand 53752b0dd67SGuy Brand return 'show'; 53852b0dd67SGuy Brand} 53952b0dd67SGuy Brand 540340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 541