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 304*f951a474SAndreas Gohr 305*f951a474SAndreas Gohr $go = wl($ID,'',true); 306*f951a474SAndreas Gohr 307*f951a474SAndreas Gohr //get section name when coming from section edit 308*f951a474SAndreas Gohr if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 309*f951a474SAndreas Gohr #FIXME duplicates code from xhtml renderer 310*f951a474SAndreas Gohr $title = $match[0]; 311*f951a474SAndreas Gohr $title = str_replace(':','',cleanID($title)); 312*f951a474SAndreas Gohr $title = ltrim($title,'0123456789._-'); 313*f951a474SAndreas Gohr if(empty($title)) $title='section'; 314*f951a474SAndreas Gohr $go .= '#'.$title; 315*f951a474SAndreas Gohr } 316*f951a474SAndreas Gohr 3176b13307fSandi //show it 3186b13307fSandi session_write_close(); 319*f951a474SAndreas Gohr header("Location: $go"); 3206b13307fSandi exit(); 3216b13307fSandi} 3226b13307fSandi 3236b13307fSandi/** 324b8957367SBenjamin Gilbert * Handle 'login', 'logout' 3256b13307fSandi * 3266b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3276b13307fSandi */ 3286b13307fSandifunction act_auth($act){ 32908eda5bcSmatthiasgrimm global $ID; 3307cace34dSAndreas Gohr global $INFO; 33108eda5bcSmatthiasgrimm 3326b13307fSandi //already logged in? 3332288dc06SGuy Brand if($_SERVER['REMOTE_USER'] && $act=='login'){ 3342288dc06SGuy Brand header("Location: ".wl($ID,'',true)); 3352288dc06SGuy Brand exit; 3362288dc06SGuy Brand } 3376b13307fSandi 3386b13307fSandi //handle logout 3396b13307fSandi if($act=='logout'){ 34008eda5bcSmatthiasgrimm $lockedby = checklock($ID); //page still locked? 341424c3c4fSJohannes Buchner if($lockedby == $_SERVER['REMOTE_USER']) 34208eda5bcSmatthiasgrimm unlock($ID); //try to unlock 34308eda5bcSmatthiasgrimm 3447cace34dSAndreas Gohr // do the logout stuff 3456b13307fSandi auth_logoff(); 3467cace34dSAndreas Gohr 3477cace34dSAndreas Gohr // rebuild info array 3487cace34dSAndreas Gohr $INFO = pageinfo(); 3497cace34dSAndreas Gohr 3506b13307fSandi return 'login'; 3516b13307fSandi } 3526b13307fSandi 3536b13307fSandi return $act; 3546b13307fSandi} 3556b13307fSandi 3566b13307fSandi/** 3576b13307fSandi * Handle 'edit', 'preview' 3586b13307fSandi * 3596b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3606b13307fSandi */ 3616b13307fSandifunction act_edit($act){ 362cd409024Sjorda global $ID; 363ee4c4a1bSAndreas Gohr global $INFO; 364cd409024Sjorda 3656b13307fSandi //check if locked by anyone - if not lock for my self 3666b13307fSandi $lockedby = checklock($ID); 3676b13307fSandi if($lockedby) return 'locked'; 3686b13307fSandi 3696b13307fSandi lock($ID); 3706b13307fSandi return $act; 3716b13307fSandi} 3726b13307fSandi 3736b13307fSandi/** 3746b13307fSandi * Handle 'edit', 'preview' 3756b13307fSandi * 3766b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3776b13307fSandi */ 3786b13307fSandifunction act_export($act){ 3796b13307fSandi global $ID; 3806b13307fSandi global $REV; 3816b13307fSandi 382c3673e61SAndreas Gohr // search engines: never cache exported docs! (Google only currently) 383c3673e61SAndreas Gohr header('X-Robots-Tag: noindex'); 384c3673e61SAndreas Gohr 385ac83b9d8Sandi // no renderer for this 386ac83b9d8Sandi if($act == 'export_raw'){ 387ac83b9d8Sandi header('Content-Type: text/plain; charset=utf-8'); 388ac83b9d8Sandi print rawWiki($ID,$REV); 389ac83b9d8Sandi exit; 390ac83b9d8Sandi } 391ac83b9d8Sandi 392ac83b9d8Sandi // html export #FIXME what about the template's style? 393ac83b9d8Sandi if($act == 'export_xhtml'){ 39485f8705cSAnika Henke global $conf; 39585f8705cSAnika Henke global $lang; 3966b13307fSandi header('Content-Type: text/html; charset=utf-8'); 39785f8705cSAnika Henke ptln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'); 39885f8705cSAnika Henke ptln(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); 39985f8705cSAnika Henke ptln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"'); 40085f8705cSAnika Henke ptln(' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">'); 4016b13307fSandi ptln('<head>'); 40285f8705cSAnika Henke ptln(' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'); 40385f8705cSAnika Henke ptln(' <title>'.$ID.'</title>'); 4046b13307fSandi tpl_metaheaders(); 4056b13307fSandi ptln('</head>'); 4066b13307fSandi ptln('<body>'); 4072c5c3308SAndreas Gohr ptln('<div class="dokuwiki export">'); 4083c86d7c9SAndreas Gohr $html = p_wiki_xhtml($ID,$REV,false); 4093c86d7c9SAndreas Gohr tpl_toc(); 4103c86d7c9SAndreas Gohr echo $html; 411c771e9edSAnika Henke ptln('</div>'); 4126b13307fSandi ptln('</body>'); 4136b13307fSandi ptln('</html>'); 4146b13307fSandi exit; 4156b13307fSandi } 4166b13307fSandi 417cc2ae802SAndreas Gohr // html body only 418cc2ae802SAndreas Gohr if($act == 'export_xhtmlbody'){ 4193c86d7c9SAndreas Gohr $html = p_wiki_xhtml($ID,$REV,false); 4203c86d7c9SAndreas Gohr tpl_toc(); 4213c86d7c9SAndreas Gohr echo $html; 422cc2ae802SAndreas Gohr exit; 423cc2ae802SAndreas Gohr } 424cc2ae802SAndreas Gohr 425b3510079SAndreas Gohr // try to run renderer 426ac83b9d8Sandi $mode = substr($act,7); 4272d5ccb39SAndreas Gohr $text = p_cached_output(wikiFN($ID,$REV), $mode); 42885767031SAndreas Gohr $headers = p_get_metadata($ID,"format $mode"); 429ac83b9d8Sandi if(!is_null($text)){ 43085767031SAndreas Gohr if(is_array($headers)) foreach($headers as $key => $val){ 43185767031SAndreas Gohr header("$key: $val"); 43285767031SAndreas Gohr } 433ac83b9d8Sandi print $text; 4346b13307fSandi exit; 4356b13307fSandi } 4366b13307fSandi 4376b13307fSandi return 'show'; 4386b13307fSandi} 439340756e4Sandi 440b158d625SSteven Danz/** 44152b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe' 442b158d625SSteven Danz * 443b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com> 4441380fc45SAndreas Gohr * @todo localize 445b158d625SSteven Danz */ 4461380fc45SAndreas Gohrfunction act_subscription($act){ 447b158d625SSteven Danz global $ID; 448b158d625SSteven Danz global $INFO; 449f9eb5648Ssteven-danz global $lang; 450b158d625SSteven Danz 4511380fc45SAndreas Gohr $file=metaFN($ID,'.mlist'); 4521380fc45SAndreas Gohr if ($act=='subscribe' && !$INFO['subscribed']){ 453b158d625SSteven Danz if ($INFO['userinfo']['mail']){ 4541380fc45SAndreas Gohr if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 4551380fc45SAndreas Gohr $INFO['subscribed'] = true; 456f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 457b158d625SSteven Danz } else { 458f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 459b158d625SSteven Danz } 460b158d625SSteven Danz } else { 461f9eb5648Ssteven-danz msg($lang['subscribe_noaddress']); 462b158d625SSteven Danz } 4631380fc45SAndreas Gohr } elseif ($act=='unsubscribe' && $INFO['subscribed']){ 464b158d625SSteven Danz if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 4651380fc45SAndreas Gohr $INFO['subscribed'] = false; 466f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 467b158d625SSteven Danz } else { 468f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 469b158d625SSteven Danz } 470b158d625SSteven Danz } 471b158d625SSteven Danz 472b158d625SSteven Danz return 'show'; 473b158d625SSteven Danz} 474b158d625SSteven Danz 47552b0dd67SGuy Brand/** 47652b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe' 47752b0dd67SGuy Brand * 47852b0dd67SGuy Brand */ 47952b0dd67SGuy Brandfunction act_subscriptionns($act){ 48052b0dd67SGuy Brand global $ID; 48152b0dd67SGuy Brand global $INFO; 48252b0dd67SGuy Brand global $lang; 48352b0dd67SGuy Brand 48452b0dd67SGuy Brand if(!getNS($ID)) { 48552b0dd67SGuy Brand $file = metaFN(getNS($ID),'.mlist'); 486613964ecSGuy Brand $ns = "root"; 48752b0dd67SGuy Brand } else { 48852b0dd67SGuy Brand $file = metaFN(getNS($ID),'/.mlist'); 489613964ecSGuy Brand $ns = getNS($ID); 49052b0dd67SGuy Brand } 49152b0dd67SGuy Brand 492613964ecSGuy Brand // reuse strings used to display the status of the subscribe action 493613964ecSGuy Brand $act_msg = rtrim($act, 'ns'); 494613964ecSGuy Brand 49552b0dd67SGuy Brand if ($act=='subscribens' && !$INFO['subscribedns']){ 49652b0dd67SGuy Brand if ($INFO['userinfo']['mail']){ 49752b0dd67SGuy Brand if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 49852b0dd67SGuy Brand $INFO['subscribedns'] = true; 499613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 50052b0dd67SGuy Brand } else { 501613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 50252b0dd67SGuy Brand } 50352b0dd67SGuy Brand } else { 50452b0dd67SGuy Brand msg($lang['subscribe_noaddress']); 50552b0dd67SGuy Brand } 50652b0dd67SGuy Brand } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ 50752b0dd67SGuy Brand if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 50852b0dd67SGuy Brand $INFO['subscribedns'] = false; 509613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 51052b0dd67SGuy Brand } else { 511613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 51252b0dd67SGuy Brand } 51352b0dd67SGuy Brand } 51452b0dd67SGuy Brand 51552b0dd67SGuy Brand return 'show'; 51652b0dd67SGuy Brand} 51752b0dd67SGuy Brand 518340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 519