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 28c2e830f2Schris // give plugins an opportunity to process the action 2924bb549bSchris $evt = new Doku_Event('ACTION_ACT_PREPROCESS',$ACT); 3024bb549bSchris if ($evt->advise_before()) { 31c2e830f2Schris 32af182434Sandi //sanitize $ACT 33af182434Sandi $ACT = act_clean($ACT); 34af182434Sandi 35b8957367SBenjamin Gilbert //check if searchword was given - else just show 360868021bSAndreas Gohr $s = cleanID($QUERY); 370868021bSAndreas Gohr if($ACT == 'search' && empty($s)){ 38b8957367SBenjamin Gilbert $ACT = 'show'; 39b8957367SBenjamin Gilbert } 40b8957367SBenjamin Gilbert 41b8957367SBenjamin Gilbert //login stuff 421b2a85e8SAndreas Gohr if(in_array($ACT,array('login','logout'))){ 43b8957367SBenjamin Gilbert $ACT = act_auth($ACT); 441b2a85e8SAndreas Gohr } 45b8957367SBenjamin Gilbert 461380fc45SAndreas Gohr //check if user is asking to (un)subscribe a page 471380fc45SAndreas Gohr if($ACT == 'subscribe' || $ACT == 'unsubscribe') 481380fc45SAndreas Gohr $ACT = act_subscription($ACT); 49b158d625SSteven Danz 5052b0dd67SGuy Brand //check if user is asking to (un)subscribe a namespace 5152b0dd67SGuy Brand if($ACT == 'subscribens' || $ACT == 'unsubscribens') 5252b0dd67SGuy Brand $ACT = act_subscriptionns($ACT); 5352b0dd67SGuy Brand 546b13307fSandi //check permissions 556b13307fSandi $ACT = act_permcheck($ACT); 566b13307fSandi 57b8957367SBenjamin Gilbert //register 58c9570649SAndreas Gohr $nil = array(); 59b3510079SAndreas Gohr if($ACT == 'register' && $_POST['save'] && register()){ 60b8957367SBenjamin Gilbert $ACT = 'login'; 61b8957367SBenjamin Gilbert } 626b13307fSandi 638b06d178Schris if ($ACT == 'resendpwd' && act_resendpwd()) { 648b06d178Schris $ACT = 'login'; 658b06d178Schris } 668b06d178Schris 678b06d178Schris //update user profile 688b06d178Schris if (($ACT == 'profile') && updateprofile()) { 694cb79657SMatthias Grimm msg($lang['profchanged'],1); 704cb79657SMatthias Grimm $ACT = 'show'; 718b06d178Schris } 728b06d178Schris 736b13307fSandi //save 741b2a85e8SAndreas Gohr if($ACT == 'save'){ 751b2a85e8SAndreas Gohr if(checkSecurityToken()){ 766b13307fSandi $ACT = act_save($ACT); 771b2a85e8SAndreas Gohr }else{ 781b2a85e8SAndreas Gohr $ACT = 'show'; 791b2a85e8SAndreas Gohr } 801b2a85e8SAndreas Gohr } 816b13307fSandi 82067c5d22SBen Coburn //cancel conflicting edit 83067c5d22SBen Coburn if($ACT == 'cancel') 84067c5d22SBen Coburn $ACT = 'show'; 85067c5d22SBen Coburn 86ee4c4a1bSAndreas Gohr //draft deletion 87ee4c4a1bSAndreas Gohr if($ACT == 'draftdel') 88ee4c4a1bSAndreas Gohr $ACT = act_draftdel($ACT); 89ee4c4a1bSAndreas Gohr 90ee4c4a1bSAndreas Gohr //draft saving on preview 91ee4c4a1bSAndreas Gohr if($ACT == 'preview') 92ee4c4a1bSAndreas Gohr $ACT = act_draftsave($ACT); 93ee4c4a1bSAndreas Gohr 946b13307fSandi //edit 95b146b32bSandi if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ 96af182434Sandi $ACT = act_edit($ACT); 976b13307fSandi }else{ 986b13307fSandi unlock($ID); //try to unlock 996b13307fSandi } 1006b13307fSandi 1016b13307fSandi //handle export 102ac83b9d8Sandi if(substr($ACT,0,7) == 'export_') 1036b13307fSandi $ACT = act_export($ACT); 1046b13307fSandi 1056b13307fSandi //display some infos 1066b13307fSandi if($ACT == 'check'){ 1076b13307fSandi check(); 1086b13307fSandi $ACT = 'show'; 1096b13307fSandi } 1106b13307fSandi 111c19fe9c0Sandi //handle admin tasks 112c19fe9c0Sandi if($ACT == 'admin'){ 11311e2ce22Schris // retrieve admin plugin name from $_REQUEST['page'] 114bb4866bdSchris if (!empty($_REQUEST['page'])) { 11511e2ce22Schris $pluginlist = plugin_list('admin'); 11611e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 11711e2ce22Schris // attempt to load the plugin 11811e2ce22Schris if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL) 11911e2ce22Schris $plugin->handle(); 12011e2ce22Schris } 12111e2ce22Schris } 122c19fe9c0Sandi } 1235f312bacSAndreas Gohr 1245f312bacSAndreas Gohr // check permissions again - the action may have changed 1255f312bacSAndreas Gohr $ACT = act_permcheck($ACT); 12624bb549bSchris } // end event ACTION_ACT_PREPROCESS default action 12724bb549bSchris $evt->advise_after(); 12824bb549bSchris unset($evt); 129c19fe9c0Sandi 1305f312bacSAndreas Gohr 1316b13307fSandi //call template FIXME: all needed vars available? 132f63a2007Schris $headers[] = 'Content-Type: text/html; charset=utf-8'; 133746855cfSBen Coburn trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); 134f63a2007Schris 1355a892029SAndreas Gohr include(template('main.php')); 136c19fe9c0Sandi // output for the commands is now handled in inc/templates.php 137c19fe9c0Sandi // in function tpl_content() 1386b13307fSandi} 1396b13307fSandi 140f63a2007Schrisfunction act_sendheaders($headers) { 141f63a2007Schris foreach ($headers as $hdr) header($hdr); 142f63a2007Schris} 143f63a2007Schris 1446b13307fSandi/** 145af182434Sandi * Sanitize the action command 146af182434Sandi * 147af182434Sandi * Add all allowed commands here. 148af182434Sandi * 149af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 150af182434Sandi */ 151af182434Sandifunction act_clean($act){ 152af182434Sandi global $lang; 15360e6b550SAndreas Gohr global $conf; 154af182434Sandi 155ee4c4a1bSAndreas Gohr // check if the action was given as array key 156ee4c4a1bSAndreas Gohr if(is_array($act)){ 157ee4c4a1bSAndreas Gohr list($act) = array_keys($act); 158ee4c4a1bSAndreas Gohr } 159ee4c4a1bSAndreas Gohr 160ac83b9d8Sandi //remove all bad chars 161ac83b9d8Sandi $act = strtolower($act); 1622d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/','',$act); 163ac83b9d8Sandi 164ac83b9d8Sandi if($act == 'export_html') $act = 'export_xhtml'; 165cc2ae802SAndreas Gohr if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 166b146b32bSandi 167409d7af7SAndreas Gohr // check if action is disabled 168409d7af7SAndreas Gohr if(!actionOK($act)){ 169409d7af7SAndreas Gohr msg('Command disabled: '.htmlspecialchars($act),-1); 170409d7af7SAndreas Gohr return 'show'; 171409d7af7SAndreas Gohr } 172409d7af7SAndreas Gohr 17360e6b550SAndreas Gohr //disable all acl related commands if ACL is disabled 17460e6b550SAndreas Gohr if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', 17560e6b550SAndreas Gohr 'subscribe','unsubscribe','profile', 17652b0dd67SGuy Brand 'resendpwd','subscribens','unsubscribens',))){ 17760e6b550SAndreas Gohr msg('Command unavailable: '.htmlspecialchars($act),-1); 17860e6b550SAndreas Gohr return 'show'; 17960e6b550SAndreas Gohr } 18060e6b550SAndreas Gohr 181067c5d22SBen Coburn if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', 182ac83b9d8Sandi 'preview','search','show','check','index','revisions', 1831380fc45SAndreas Gohr 'diff','recent','backlink','admin','subscribe', 18418829381SAndreas Gohr 'unsubscribe','profile','resendpwd','recover','wordblock', 18552b0dd67SGuy Brand 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { 186ee4c4a1bSAndreas Gohr msg('Command unknown: '.htmlspecialchars($act),-1); 187af182434Sandi return 'show'; 188af182434Sandi } 189af182434Sandi return $act; 190af182434Sandi} 191af182434Sandi 192af182434Sandi/** 1936b13307fSandi * Run permissionchecks 1946b13307fSandi * 1956b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 1966b13307fSandi */ 1976b13307fSandifunction act_permcheck($act){ 198dbbc6aa7Sandi global $INFO; 1995e199953Smatthiasgrimm global $conf; 200dbbc6aa7Sandi 201ee4c4a1bSAndreas Gohr if(in_array($act,array('save','preview','edit','recover'))){ 2026b13307fSandi if($INFO['exists']){ 203bdbc16bfSandi if($act == 'edit'){ 204bdbc16bfSandi //the edit function will check again and do a source show 205bdbc16bfSandi //when no AUTH_EDIT available 206bdbc16bfSandi $permneed = AUTH_READ; 207bdbc16bfSandi }else{ 2086b13307fSandi $permneed = AUTH_EDIT; 209bdbc16bfSandi } 2106b13307fSandi }else{ 2116b13307fSandi $permneed = AUTH_CREATE; 2126b13307fSandi } 2138b06d178Schris }elseif(in_array($act,array('login','search','recent','profile'))){ 2146b13307fSandi $permneed = AUTH_NONE; 2155e199953Smatthiasgrimm }elseif($act == 'register'){ 2165e199953Smatthiasgrimm $permneed = AUTH_NONE; 217ebd3d9ceSchris }elseif($act == 'resendpwd'){ 218ebd3d9ceSchris $permneed = AUTH_NONE; 219c19fe9c0Sandi }elseif($act == 'admin'){ 220f8cc712eSAndreas Gohr if($INFO['ismanager']){ 221f8cc712eSAndreas Gohr // if the manager has the needed permissions for a certain admin 222f8cc712eSAndreas Gohr // action is checked later 223f8cc712eSAndreas Gohr $permneed = AUTH_READ; 224f8cc712eSAndreas Gohr }else{ 225c19fe9c0Sandi $permneed = AUTH_ADMIN; 226f8cc712eSAndreas Gohr } 2276b13307fSandi }else{ 2286b13307fSandi $permneed = AUTH_READ; 2296b13307fSandi } 230dbbc6aa7Sandi if($INFO['perm'] >= $permneed) return $act; 231dbbc6aa7Sandi 2326b13307fSandi return 'denied'; 2336b13307fSandi} 2346b13307fSandi 2356b13307fSandi/** 236ee4c4a1bSAndreas Gohr * Handle 'draftdel' 237ee4c4a1bSAndreas Gohr * 238ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user 239ee4c4a1bSAndreas Gohr */ 240ee4c4a1bSAndreas Gohrfunction act_draftdel($act){ 241ee4c4a1bSAndreas Gohr global $INFO; 242ee4c4a1bSAndreas Gohr @unlink($INFO['draft']); 243ee4c4a1bSAndreas Gohr $INFO['draft'] = null; 244ee4c4a1bSAndreas Gohr return 'show'; 245ee4c4a1bSAndreas Gohr} 246ee4c4a1bSAndreas Gohr 247ee4c4a1bSAndreas Gohr/** 248ee4c4a1bSAndreas Gohr * Saves a draft on preview 249ee4c4a1bSAndreas Gohr * 250ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/ 251ee4c4a1bSAndreas Gohr */ 252ee4c4a1bSAndreas Gohrfunction act_draftsave($act){ 253ee4c4a1bSAndreas Gohr global $INFO; 254ee4c4a1bSAndreas Gohr global $ID; 255ee4c4a1bSAndreas Gohr global $conf; 256ee4c4a1bSAndreas Gohr if($conf['usedraft'] && $_POST['wikitext']){ 257ee4c4a1bSAndreas Gohr $draft = array('id' => $ID, 258ee4c4a1bSAndreas Gohr 'prefix' => $_POST['prefix'], 259ee4c4a1bSAndreas Gohr 'text' => $_POST['wikitext'], 260ee4c4a1bSAndreas Gohr 'suffix' => $_POST['suffix'], 261ee4c4a1bSAndreas Gohr 'date' => $_POST['date'], 262ee4c4a1bSAndreas Gohr 'client' => $INFO['client'], 263ee4c4a1bSAndreas Gohr ); 264ee4c4a1bSAndreas Gohr $cname = getCacheName($draft['client'].$ID,'.draft'); 265ee4c4a1bSAndreas Gohr if(io_saveFile($cname,serialize($draft))){ 266ee4c4a1bSAndreas Gohr $INFO['draft'] = $cname; 267ee4c4a1bSAndreas Gohr } 268ee4c4a1bSAndreas Gohr } 269ee4c4a1bSAndreas Gohr return $act; 270ee4c4a1bSAndreas Gohr} 271ee4c4a1bSAndreas Gohr 272ee4c4a1bSAndreas Gohr/** 2736b13307fSandi * Handle 'save' 2746b13307fSandi * 2756b13307fSandi * Checks for spam and conflicts and saves the page. 2766b13307fSandi * Does a redirect to show the page afterwards or 2776b13307fSandi * returns a new action. 2786b13307fSandi * 2796b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2806b13307fSandi */ 2816b13307fSandifunction act_save($act){ 2826b13307fSandi global $ID; 2836b13307fSandi global $DATE; 2846b13307fSandi global $PRE; 2856b13307fSandi global $TEXT; 2866b13307fSandi global $SUF; 2876b13307fSandi global $SUM; 2886b13307fSandi 2896b13307fSandi //spam check 2906b13307fSandi if(checkwordblock()) 2916b13307fSandi return 'wordblock'; 2926b13307fSandi //conflict check //FIXME use INFO 2936b13307fSandi if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) 2946b13307fSandi return 'conflict'; 2956b13307fSandi 2966b13307fSandi //save it 297b6912aeaSAndreas Gohr saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con 2986b13307fSandi //unlock it 2996b13307fSandi unlock($ID); 3006b13307fSandi 301ee4c4a1bSAndreas Gohr //delete draft 302ee4c4a1bSAndreas Gohr act_draftdel($act); 303ee4c4a1bSAndreas Gohr 3046b13307fSandi //show it 3056b13307fSandi session_write_close(); 3066b13307fSandi header("Location: ".wl($ID,'',true)); 3076b13307fSandi exit(); 3086b13307fSandi} 3096b13307fSandi 3106b13307fSandi/** 311b8957367SBenjamin Gilbert * Handle 'login', 'logout' 3126b13307fSandi * 3136b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3146b13307fSandi */ 3156b13307fSandifunction act_auth($act){ 31608eda5bcSmatthiasgrimm global $ID; 3177cace34dSAndreas Gohr global $INFO; 31808eda5bcSmatthiasgrimm 3196b13307fSandi //already logged in? 3202288dc06SGuy Brand if($_SERVER['REMOTE_USER'] && $act=='login'){ 3212288dc06SGuy Brand header("Location: ".wl($ID,'',true)); 3222288dc06SGuy Brand exit; 3232288dc06SGuy Brand } 3246b13307fSandi 3256b13307fSandi //handle logout 3266b13307fSandi if($act=='logout'){ 32708eda5bcSmatthiasgrimm $lockedby = checklock($ID); //page still locked? 328424c3c4fSJohannes Buchner if($lockedby == $_SERVER['REMOTE_USER']) 32908eda5bcSmatthiasgrimm unlock($ID); //try to unlock 33008eda5bcSmatthiasgrimm 3317cace34dSAndreas Gohr // do the logout stuff 3326b13307fSandi auth_logoff(); 3337cace34dSAndreas Gohr 3347cace34dSAndreas Gohr // rebuild info array 3357cace34dSAndreas Gohr $INFO = pageinfo(); 3367cace34dSAndreas Gohr 3376b13307fSandi return 'login'; 3386b13307fSandi } 3396b13307fSandi 3406b13307fSandi return $act; 3416b13307fSandi} 3426b13307fSandi 3436b13307fSandi/** 3446b13307fSandi * Handle 'edit', 'preview' 3456b13307fSandi * 3466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3476b13307fSandi */ 3486b13307fSandifunction act_edit($act){ 349cd409024Sjorda global $ID; 350ee4c4a1bSAndreas Gohr global $INFO; 351cd409024Sjorda 3526b13307fSandi //check if locked by anyone - if not lock for my self 3536b13307fSandi $lockedby = checklock($ID); 3546b13307fSandi if($lockedby) return 'locked'; 3556b13307fSandi 3566b13307fSandi lock($ID); 3576b13307fSandi return $act; 3586b13307fSandi} 3596b13307fSandi 3606b13307fSandi/** 3616b13307fSandi * Handle 'edit', 'preview' 3626b13307fSandi * 3636b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3646b13307fSandi */ 3656b13307fSandifunction act_export($act){ 3666b13307fSandi global $ID; 3676b13307fSandi global $REV; 3686b13307fSandi 369c3673e61SAndreas Gohr // search engines: never cache exported docs! (Google only currently) 370c3673e61SAndreas Gohr header('X-Robots-Tag: noindex'); 371c3673e61SAndreas Gohr 372ac83b9d8Sandi // no renderer for this 373ac83b9d8Sandi if($act == 'export_raw'){ 374ac83b9d8Sandi header('Content-Type: text/plain; charset=utf-8'); 375ac83b9d8Sandi print rawWiki($ID,$REV); 376ac83b9d8Sandi exit; 377ac83b9d8Sandi } 378ac83b9d8Sandi 379ac83b9d8Sandi // html export #FIXME what about the template's style? 380ac83b9d8Sandi if($act == 'export_xhtml'){ 38185f8705cSAnika Henke global $conf; 38285f8705cSAnika Henke global $lang; 3836b13307fSandi header('Content-Type: text/html; charset=utf-8'); 38485f8705cSAnika Henke ptln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'); 38585f8705cSAnika Henke ptln(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); 38685f8705cSAnika Henke ptln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"'); 38785f8705cSAnika Henke ptln(' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">'); 3886b13307fSandi ptln('<head>'); 38985f8705cSAnika Henke ptln(' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'); 39085f8705cSAnika Henke ptln(' <title>'.$ID.'</title>'); 3916b13307fSandi tpl_metaheaders(); 3926b13307fSandi ptln('</head>'); 3936b13307fSandi ptln('<body>'); 3942c5c3308SAndreas Gohr ptln('<div class="dokuwiki export">'); 395*3c86d7c9SAndreas Gohr $html = p_wiki_xhtml($ID,$REV,false); 396*3c86d7c9SAndreas Gohr tpl_toc(); 397*3c86d7c9SAndreas Gohr echo $html; 398c771e9edSAnika Henke ptln('</div>'); 3996b13307fSandi ptln('</body>'); 4006b13307fSandi ptln('</html>'); 4016b13307fSandi exit; 4026b13307fSandi } 4036b13307fSandi 404cc2ae802SAndreas Gohr // html body only 405cc2ae802SAndreas Gohr if($act == 'export_xhtmlbody'){ 406*3c86d7c9SAndreas Gohr $html = p_wiki_xhtml($ID,$REV,false); 407*3c86d7c9SAndreas Gohr tpl_toc(); 408*3c86d7c9SAndreas Gohr echo $html; 409cc2ae802SAndreas Gohr exit; 410cc2ae802SAndreas Gohr } 411cc2ae802SAndreas Gohr 412b3510079SAndreas Gohr // try to run renderer 413ac83b9d8Sandi $mode = substr($act,7); 4142d5ccb39SAndreas Gohr $text = p_cached_output(wikiFN($ID,$REV), $mode); 41585767031SAndreas Gohr $headers = p_get_metadata($ID,"format $mode"); 416ac83b9d8Sandi if(!is_null($text)){ 41785767031SAndreas Gohr if(is_array($headers)) foreach($headers as $key => $val){ 41885767031SAndreas Gohr header("$key: $val"); 41985767031SAndreas Gohr } 420ac83b9d8Sandi print $text; 4216b13307fSandi exit; 4226b13307fSandi } 4236b13307fSandi 4246b13307fSandi return 'show'; 4256b13307fSandi} 426340756e4Sandi 427b158d625SSteven Danz/** 42852b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe' 429b158d625SSteven Danz * 430b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com> 4311380fc45SAndreas Gohr * @todo localize 432b158d625SSteven Danz */ 4331380fc45SAndreas Gohrfunction act_subscription($act){ 434b158d625SSteven Danz global $ID; 435b158d625SSteven Danz global $INFO; 436f9eb5648Ssteven-danz global $lang; 437b158d625SSteven Danz 4381380fc45SAndreas Gohr $file=metaFN($ID,'.mlist'); 4391380fc45SAndreas Gohr if ($act=='subscribe' && !$INFO['subscribed']){ 440b158d625SSteven Danz if ($INFO['userinfo']['mail']){ 4411380fc45SAndreas Gohr if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 4421380fc45SAndreas Gohr $INFO['subscribed'] = true; 443f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 444b158d625SSteven Danz } else { 445f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 446b158d625SSteven Danz } 447b158d625SSteven Danz } else { 448f9eb5648Ssteven-danz msg($lang['subscribe_noaddress']); 449b158d625SSteven Danz } 4501380fc45SAndreas Gohr } elseif ($act=='unsubscribe' && $INFO['subscribed']){ 451b158d625SSteven Danz if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 4521380fc45SAndreas Gohr $INFO['subscribed'] = false; 453f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 454b158d625SSteven Danz } else { 455f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 456b158d625SSteven Danz } 457b158d625SSteven Danz } 458b158d625SSteven Danz 459b158d625SSteven Danz return 'show'; 460b158d625SSteven Danz} 461b158d625SSteven Danz 46252b0dd67SGuy Brand/** 46352b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe' 46452b0dd67SGuy Brand * 46552b0dd67SGuy Brand */ 46652b0dd67SGuy Brandfunction act_subscriptionns($act){ 46752b0dd67SGuy Brand global $ID; 46852b0dd67SGuy Brand global $INFO; 46952b0dd67SGuy Brand global $lang; 47052b0dd67SGuy Brand 47152b0dd67SGuy Brand if(!getNS($ID)) { 47252b0dd67SGuy Brand $file = metaFN(getNS($ID),'.mlist'); 473613964ecSGuy Brand $ns = "root"; 47452b0dd67SGuy Brand } else { 47552b0dd67SGuy Brand $file = metaFN(getNS($ID),'/.mlist'); 476613964ecSGuy Brand $ns = getNS($ID); 47752b0dd67SGuy Brand } 47852b0dd67SGuy Brand 479613964ecSGuy Brand // reuse strings used to display the status of the subscribe action 480613964ecSGuy Brand $act_msg = rtrim($act, 'ns'); 481613964ecSGuy Brand 48252b0dd67SGuy Brand if ($act=='subscribens' && !$INFO['subscribedns']){ 48352b0dd67SGuy Brand if ($INFO['userinfo']['mail']){ 48452b0dd67SGuy Brand if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 48552b0dd67SGuy Brand $INFO['subscribedns'] = true; 486613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 48752b0dd67SGuy Brand } else { 488613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 48952b0dd67SGuy Brand } 49052b0dd67SGuy Brand } else { 49152b0dd67SGuy Brand msg($lang['subscribe_noaddress']); 49252b0dd67SGuy Brand } 49352b0dd67SGuy Brand } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ 49452b0dd67SGuy Brand if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 49552b0dd67SGuy Brand $INFO['subscribedns'] = false; 496613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 49752b0dd67SGuy Brand } else { 498613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 49952b0dd67SGuy Brand } 50052b0dd67SGuy Brand } 50152b0dd67SGuy Brand 50252b0dd67SGuy Brand return 'show'; 50352b0dd67SGuy Brand} 50452b0dd67SGuy Brand 505340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 506