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; 27066fee30SAndreas Gohr global $license; 286b13307fSandi 2969cd1e27SAndreas Gohr $preact = $ACT; 3069cd1e27SAndreas Gohr 31c2e830f2Schris // give plugins an opportunity to process the action 3224bb549bSchris $evt = new Doku_Event('ACTION_ACT_PREPROCESS',$ACT); 3324bb549bSchris if ($evt->advise_before()) { 34c2e830f2Schris 35af182434Sandi //sanitize $ACT 36af182434Sandi $ACT = act_clean($ACT); 37af182434Sandi 38b8957367SBenjamin Gilbert //check if searchword was given - else just show 390868021bSAndreas Gohr $s = cleanID($QUERY); 400868021bSAndreas Gohr if($ACT == 'search' && empty($s)){ 41b8957367SBenjamin Gilbert $ACT = 'show'; 42b8957367SBenjamin Gilbert } 43b8957367SBenjamin Gilbert 44b8957367SBenjamin Gilbert //login stuff 451b2a85e8SAndreas Gohr if(in_array($ACT,array('login','logout'))){ 46b8957367SBenjamin Gilbert $ACT = act_auth($ACT); 471b2a85e8SAndreas Gohr } 48b8957367SBenjamin Gilbert 491380fc45SAndreas Gohr //check if user is asking to (un)subscribe a page 501380fc45SAndreas Gohr if($ACT == 'subscribe' || $ACT == 'unsubscribe') 511380fc45SAndreas Gohr $ACT = act_subscription($ACT); 52b158d625SSteven Danz 5352b0dd67SGuy Brand //check if user is asking to (un)subscribe a namespace 5452b0dd67SGuy Brand if($ACT == 'subscribens' || $ACT == 'unsubscribens') 5552b0dd67SGuy Brand $ACT = act_subscriptionns($ACT); 5652b0dd67SGuy Brand 576b13307fSandi //check permissions 586b13307fSandi $ACT = act_permcheck($ACT); 596b13307fSandi 60b8957367SBenjamin Gilbert //register 61c9570649SAndreas Gohr $nil = array(); 62b3510079SAndreas Gohr if($ACT == 'register' && $_POST['save'] && register()){ 63b8957367SBenjamin Gilbert $ACT = 'login'; 64b8957367SBenjamin Gilbert } 656b13307fSandi 668b06d178Schris if ($ACT == 'resendpwd' && act_resendpwd()) { 678b06d178Schris $ACT = 'login'; 688b06d178Schris } 698b06d178Schris 708b06d178Schris //update user profile 7125b2a98cSMichael Klier if ($ACT == 'profile') { 7225b2a98cSMichael Klier if(!$_SERVER['REMOTE_USER']) { 7325b2a98cSMichael Klier $ACT = 'login'; 7425b2a98cSMichael Klier } else { 7525b2a98cSMichael Klier if(updateprofile()) { 764cb79657SMatthias Grimm msg($lang['profchanged'],1); 774cb79657SMatthias Grimm $ACT = 'show'; 788b06d178Schris } 7925b2a98cSMichael Klier } 8025b2a98cSMichael Klier } 818b06d178Schris 826b13307fSandi //save 831b2a85e8SAndreas Gohr if($ACT == 'save'){ 841b2a85e8SAndreas Gohr if(checkSecurityToken()){ 856b13307fSandi $ACT = act_save($ACT); 861b2a85e8SAndreas Gohr }else{ 871b2a85e8SAndreas Gohr $ACT = 'show'; 881b2a85e8SAndreas Gohr } 891b2a85e8SAndreas Gohr } 906b13307fSandi 91067c5d22SBen Coburn //cancel conflicting edit 92067c5d22SBen Coburn if($ACT == 'cancel') 93067c5d22SBen Coburn $ACT = 'show'; 94067c5d22SBen Coburn 95ee4c4a1bSAndreas Gohr //draft deletion 96ee4c4a1bSAndreas Gohr if($ACT == 'draftdel') 97ee4c4a1bSAndreas Gohr $ACT = act_draftdel($ACT); 98ee4c4a1bSAndreas Gohr 99ee4c4a1bSAndreas Gohr //draft saving on preview 100ee4c4a1bSAndreas Gohr if($ACT == 'preview') 101ee4c4a1bSAndreas Gohr $ACT = act_draftsave($ACT); 102ee4c4a1bSAndreas Gohr 1036b13307fSandi //edit 104b146b32bSandi if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ 105af182434Sandi $ACT = act_edit($ACT); 1066b13307fSandi }else{ 1076b13307fSandi unlock($ID); //try to unlock 1086b13307fSandi } 1096b13307fSandi 1106b13307fSandi //handle export 111ac83b9d8Sandi if(substr($ACT,0,7) == 'export_') 1126b13307fSandi $ACT = act_export($ACT); 1136b13307fSandi 1146b13307fSandi //display some infos 1156b13307fSandi if($ACT == 'check'){ 1166b13307fSandi check(); 1176b13307fSandi $ACT = 'show'; 1186b13307fSandi } 1196b13307fSandi 120c19fe9c0Sandi //handle admin tasks 121c19fe9c0Sandi if($ACT == 'admin'){ 12211e2ce22Schris // retrieve admin plugin name from $_REQUEST['page'] 123bb4866bdSchris if (!empty($_REQUEST['page'])) { 12411e2ce22Schris $pluginlist = plugin_list('admin'); 12511e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 12611e2ce22Schris // attempt to load the plugin 12711e2ce22Schris if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL) 12811e2ce22Schris $plugin->handle(); 12911e2ce22Schris } 13011e2ce22Schris } 131c19fe9c0Sandi } 1325f312bacSAndreas Gohr 1335f312bacSAndreas Gohr // check permissions again - the action may have changed 1345f312bacSAndreas Gohr $ACT = act_permcheck($ACT); 13524bb549bSchris } // end event ACTION_ACT_PREPROCESS default action 13624bb549bSchris $evt->advise_after(); 13724bb549bSchris unset($evt); 138c19fe9c0Sandi 13946c0ed74SMichael Hamann // when action 'show', the intial not 'show' and POST, do a redirect 14046c0ed74SMichael Hamann if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ 14169cd1e27SAndreas Gohr act_redirect($ID,$preact); 14269cd1e27SAndreas Gohr } 1435f312bacSAndreas Gohr 1446b13307fSandi //call template FIXME: all needed vars available? 145f63a2007Schris $headers[] = 'Content-Type: text/html; charset=utf-8'; 146746855cfSBen Coburn trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); 147f63a2007Schris 1485a892029SAndreas Gohr include(template('main.php')); 149c19fe9c0Sandi // output for the commands is now handled in inc/templates.php 150c19fe9c0Sandi // in function tpl_content() 1516b13307fSandi} 1526b13307fSandi 153f63a2007Schrisfunction act_sendheaders($headers) { 154f63a2007Schris foreach ($headers as $hdr) header($hdr); 155f63a2007Schris} 156f63a2007Schris 1576b13307fSandi/** 158af182434Sandi * Sanitize the action command 159af182434Sandi * 160af182434Sandi * Add all allowed commands here. 161af182434Sandi * 162af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 163af182434Sandi */ 164af182434Sandifunction act_clean($act){ 165af182434Sandi global $lang; 16660e6b550SAndreas Gohr global $conf; 167af182434Sandi 168ee4c4a1bSAndreas Gohr // check if the action was given as array key 169ee4c4a1bSAndreas Gohr if(is_array($act)){ 170ee4c4a1bSAndreas Gohr list($act) = array_keys($act); 171ee4c4a1bSAndreas Gohr } 172ee4c4a1bSAndreas Gohr 173ac83b9d8Sandi //remove all bad chars 174ac83b9d8Sandi $act = strtolower($act); 1752d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/','',$act); 176ac83b9d8Sandi 177ac83b9d8Sandi if($act == 'export_html') $act = 'export_xhtml'; 178cc2ae802SAndreas Gohr if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 179b146b32bSandi 180409d7af7SAndreas Gohr // check if action is disabled 181409d7af7SAndreas Gohr if(!actionOK($act)){ 182409d7af7SAndreas Gohr msg('Command disabled: '.htmlspecialchars($act),-1); 183409d7af7SAndreas Gohr return 'show'; 184409d7af7SAndreas Gohr } 185409d7af7SAndreas Gohr 18660e6b550SAndreas Gohr //disable all acl related commands if ACL is disabled 18760e6b550SAndreas Gohr if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', 18860e6b550SAndreas Gohr 'subscribe','unsubscribe','profile', 18952b0dd67SGuy Brand 'resendpwd','subscribens','unsubscribens',))){ 19060e6b550SAndreas Gohr msg('Command unavailable: '.htmlspecialchars($act),-1); 19160e6b550SAndreas Gohr return 'show'; 19260e6b550SAndreas Gohr } 19360e6b550SAndreas Gohr 194067c5d22SBen Coburn if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', 195ac83b9d8Sandi 'preview','search','show','check','index','revisions', 1961380fc45SAndreas Gohr 'diff','recent','backlink','admin','subscribe', 19718829381SAndreas Gohr 'unsubscribe','profile','resendpwd','recover','wordblock', 19852b0dd67SGuy Brand 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { 199ee4c4a1bSAndreas Gohr msg('Command unknown: '.htmlspecialchars($act),-1); 200af182434Sandi return 'show'; 201af182434Sandi } 202af182434Sandi return $act; 203af182434Sandi} 204af182434Sandi 205af182434Sandi/** 2066b13307fSandi * Run permissionchecks 2076b13307fSandi * 2086b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2096b13307fSandi */ 2106b13307fSandifunction act_permcheck($act){ 211dbbc6aa7Sandi global $INFO; 2125e199953Smatthiasgrimm global $conf; 213dbbc6aa7Sandi 214ee4c4a1bSAndreas Gohr if(in_array($act,array('save','preview','edit','recover'))){ 2156b13307fSandi if($INFO['exists']){ 216bdbc16bfSandi if($act == 'edit'){ 217bdbc16bfSandi //the edit function will check again and do a source show 218bdbc16bfSandi //when no AUTH_EDIT available 219bdbc16bfSandi $permneed = AUTH_READ; 220bdbc16bfSandi }else{ 2216b13307fSandi $permneed = AUTH_EDIT; 222bdbc16bfSandi } 2236b13307fSandi }else{ 2246b13307fSandi $permneed = AUTH_CREATE; 2256b13307fSandi } 2268b06d178Schris }elseif(in_array($act,array('login','search','recent','profile'))){ 2276b13307fSandi $permneed = AUTH_NONE; 2285e199953Smatthiasgrimm }elseif($act == 'register'){ 2295e199953Smatthiasgrimm $permneed = AUTH_NONE; 230ebd3d9ceSchris }elseif($act == 'resendpwd'){ 231ebd3d9ceSchris $permneed = AUTH_NONE; 232c19fe9c0Sandi }elseif($act == 'admin'){ 233f8cc712eSAndreas Gohr if($INFO['ismanager']){ 234f8cc712eSAndreas Gohr // if the manager has the needed permissions for a certain admin 235f8cc712eSAndreas Gohr // action is checked later 236f8cc712eSAndreas Gohr $permneed = AUTH_READ; 237f8cc712eSAndreas Gohr }else{ 238c19fe9c0Sandi $permneed = AUTH_ADMIN; 239f8cc712eSAndreas Gohr } 2406b13307fSandi }else{ 2416b13307fSandi $permneed = AUTH_READ; 2426b13307fSandi } 243dbbc6aa7Sandi if($INFO['perm'] >= $permneed) return $act; 244dbbc6aa7Sandi 2456b13307fSandi return 'denied'; 2466b13307fSandi} 2476b13307fSandi 2486b13307fSandi/** 249ee4c4a1bSAndreas Gohr * Handle 'draftdel' 250ee4c4a1bSAndreas Gohr * 251ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user 252ee4c4a1bSAndreas Gohr */ 253ee4c4a1bSAndreas Gohrfunction act_draftdel($act){ 254ee4c4a1bSAndreas Gohr global $INFO; 255ee4c4a1bSAndreas Gohr @unlink($INFO['draft']); 256ee4c4a1bSAndreas Gohr $INFO['draft'] = null; 257ee4c4a1bSAndreas Gohr return 'show'; 258ee4c4a1bSAndreas Gohr} 259ee4c4a1bSAndreas Gohr 260ee4c4a1bSAndreas Gohr/** 261ee4c4a1bSAndreas Gohr * Saves a draft on preview 262ee4c4a1bSAndreas Gohr * 263ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/ 264ee4c4a1bSAndreas Gohr */ 265ee4c4a1bSAndreas Gohrfunction act_draftsave($act){ 266ee4c4a1bSAndreas Gohr global $INFO; 267ee4c4a1bSAndreas Gohr global $ID; 268ee4c4a1bSAndreas Gohr global $conf; 269ee4c4a1bSAndreas Gohr if($conf['usedraft'] && $_POST['wikitext']){ 270ee4c4a1bSAndreas Gohr $draft = array('id' => $ID, 271ee4c4a1bSAndreas Gohr 'prefix' => $_POST['prefix'], 272ee4c4a1bSAndreas Gohr 'text' => $_POST['wikitext'], 273ee4c4a1bSAndreas Gohr 'suffix' => $_POST['suffix'], 274ee4c4a1bSAndreas Gohr 'date' => $_POST['date'], 275ee4c4a1bSAndreas Gohr 'client' => $INFO['client'], 276ee4c4a1bSAndreas Gohr ); 277ee4c4a1bSAndreas Gohr $cname = getCacheName($draft['client'].$ID,'.draft'); 278ee4c4a1bSAndreas Gohr if(io_saveFile($cname,serialize($draft))){ 279ee4c4a1bSAndreas Gohr $INFO['draft'] = $cname; 280ee4c4a1bSAndreas Gohr } 281ee4c4a1bSAndreas Gohr } 282ee4c4a1bSAndreas Gohr return $act; 283ee4c4a1bSAndreas Gohr} 284ee4c4a1bSAndreas Gohr 285ee4c4a1bSAndreas Gohr/** 2866b13307fSandi * Handle 'save' 2876b13307fSandi * 2886b13307fSandi * Checks for spam and conflicts and saves the page. 2896b13307fSandi * Does a redirect to show the page afterwards or 2906b13307fSandi * returns a new action. 2916b13307fSandi * 2926b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2936b13307fSandi */ 2946b13307fSandifunction act_save($act){ 2956b13307fSandi global $ID; 2966b13307fSandi global $DATE; 2976b13307fSandi global $PRE; 2986b13307fSandi global $TEXT; 2996b13307fSandi global $SUF; 3006b13307fSandi global $SUM; 3016b13307fSandi 3026b13307fSandi //spam check 3036b13307fSandi if(checkwordblock()) 3046b13307fSandi return 'wordblock'; 3056b13307fSandi //conflict check //FIXME use INFO 3066b13307fSandi if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) 3076b13307fSandi return 'conflict'; 3086b13307fSandi 3096b13307fSandi //save it 310b6912aeaSAndreas Gohr saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con 3116b13307fSandi //unlock it 3126b13307fSandi unlock($ID); 3136b13307fSandi 314ee4c4a1bSAndreas Gohr //delete draft 315ee4c4a1bSAndreas Gohr act_draftdel($act); 31669cd1e27SAndreas Gohr session_write_close(); 317ee4c4a1bSAndreas Gohr 31869cd1e27SAndreas Gohr // when done, show page 31969cd1e27SAndreas Gohr return 'show'; 32069cd1e27SAndreas Gohr} 321f951a474SAndreas Gohr 32214a122deSAndreas Gohr/** 32314a122deSAndreas Gohr * Do a redirect after receiving post data 32414a122deSAndreas Gohr * 32514a122deSAndreas Gohr * Tries to add the section id as hash mark after section editing 32614a122deSAndreas Gohr */ 32769cd1e27SAndreas Gohrfunction act_redirect($id,$preact){ 32869cd1e27SAndreas Gohr global $PRE; 32969cd1e27SAndreas Gohr global $TEXT; 33014a122deSAndreas Gohr global $MSG; 33114a122deSAndreas Gohr 33214a122deSAndreas Gohr //are there any undisplayed messages? keep them in session for display 33314a122deSAndreas Gohr //on the next page 33414a122deSAndreas Gohr if(isset($MSG) && count($MSG)){ 33514a122deSAndreas Gohr //reopen session, store data and close session again 33614a122deSAndreas Gohr @session_start(); 33714a122deSAndreas Gohr $_SESSION[DOKU_COOKIE]['msg'] = $MSG; 33814a122deSAndreas Gohr session_write_close(); 33914a122deSAndreas Gohr } 340f951a474SAndreas Gohr 341f951a474SAndreas Gohr //get section name when coming from section edit 342f951a474SAndreas Gohr if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 343f951a474SAndreas Gohr #FIXME duplicates code from xhtml renderer 344f951a474SAndreas Gohr $title = $match[0]; 345f951a474SAndreas Gohr $title = str_replace(':','',cleanID($title)); 346f951a474SAndreas Gohr $title = ltrim($title,'0123456789._-'); 347f951a474SAndreas Gohr if(empty($title)) $title='section'; 348f951a474SAndreas Gohr } 349f951a474SAndreas Gohr 35069cd1e27SAndreas Gohr $opts = array( 35169cd1e27SAndreas Gohr 'id' => $id, 35269cd1e27SAndreas Gohr 'fragment' => $title, 35369cd1e27SAndreas Gohr 'preact' => $preact 35469cd1e27SAndreas Gohr ); 35569cd1e27SAndreas Gohr trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); 35669cd1e27SAndreas Gohr} 35769cd1e27SAndreas Gohr 35869cd1e27SAndreas Gohrfunction act_redirect_execute($opts){ 35969cd1e27SAndreas Gohr $go = wl($opts['id'],'',true); 36069cd1e27SAndreas Gohr if($opts['fragment']) $go .= '#'.$opts['fragment']; 36169cd1e27SAndreas Gohr 3626b13307fSandi //show it 363f951a474SAndreas Gohr header("Location: $go"); 3646b13307fSandi exit(); 3656b13307fSandi} 3666b13307fSandi 3676b13307fSandi/** 368b8957367SBenjamin Gilbert * Handle 'login', 'logout' 3696b13307fSandi * 3706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3716b13307fSandi */ 3726b13307fSandifunction act_auth($act){ 37308eda5bcSmatthiasgrimm global $ID; 3747cace34dSAndreas Gohr global $INFO; 37508eda5bcSmatthiasgrimm 3766b13307fSandi //already logged in? 3772288dc06SGuy Brand if($_SERVER['REMOTE_USER'] && $act=='login'){ 378ca12ce46SAndreas Gohr return 'show'; 3792288dc06SGuy Brand } 3806b13307fSandi 3816b13307fSandi //handle logout 3826b13307fSandi if($act=='logout'){ 38308eda5bcSmatthiasgrimm $lockedby = checklock($ID); //page still locked? 384424c3c4fSJohannes Buchner if($lockedby == $_SERVER['REMOTE_USER']) 38508eda5bcSmatthiasgrimm unlock($ID); //try to unlock 38608eda5bcSmatthiasgrimm 3877cace34dSAndreas Gohr // do the logout stuff 3886b13307fSandi auth_logoff(); 3897cace34dSAndreas Gohr 3907cace34dSAndreas Gohr // rebuild info array 3917cace34dSAndreas Gohr $INFO = pageinfo(); 3927cace34dSAndreas Gohr 393e16eccb7SGuy Brand act_redirect($ID,'login'); 3946b13307fSandi } 3956b13307fSandi 3966b13307fSandi return $act; 3976b13307fSandi} 3986b13307fSandi 3996b13307fSandi/** 4006b13307fSandi * Handle 'edit', 'preview' 4016b13307fSandi * 4026b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 4036b13307fSandi */ 4046b13307fSandifunction act_edit($act){ 405cd409024Sjorda global $ID; 406ee4c4a1bSAndreas Gohr global $INFO; 407cd409024Sjorda 4086b13307fSandi //check if locked by anyone - if not lock for my self 4096b13307fSandi $lockedby = checklock($ID); 4106b13307fSandi if($lockedby) return 'locked'; 4116b13307fSandi 4126b13307fSandi lock($ID); 4136b13307fSandi return $act; 4146b13307fSandi} 4156b13307fSandi 4166b13307fSandi/** 417f6dad9fdSMichael Klier * Export a wiki page for various formats 418f6dad9fdSMichael Klier * 419f6dad9fdSMichael Klier * Triggers ACTION_EXPORT_POSTPROCESS 420f6dad9fdSMichael Klier * 421f6dad9fdSMichael Klier * Event data: 422f6dad9fdSMichael Klier * data['id'] -- page id 423f6dad9fdSMichael Klier * data['mode'] -- requested export mode 424f6dad9fdSMichael Klier * data['headers'] -- export headers 425f6dad9fdSMichael Klier * data['output'] -- export output 4266b13307fSandi * 4276b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 428f6dad9fdSMichael Klier * @author Michael Klier <chi@chimeric.de> 4296b13307fSandi */ 4306b13307fSandifunction act_export($act){ 4316b13307fSandi global $ID; 4326b13307fSandi global $REV; 43385f8705cSAnika Henke global $conf; 43485f8705cSAnika Henke global $lang; 4356b13307fSandi 436f6dad9fdSMichael Klier $pre = ''; 437f6dad9fdSMichael Klier $post = ''; 438f6dad9fdSMichael Klier $output = ''; 439f6dad9fdSMichael Klier $headers = array(); 440cc2ae802SAndreas Gohr 441f6dad9fdSMichael Klier // search engines: never cache exported docs! (Google only currently) 442f6dad9fdSMichael Klier $headers['X-Robots-Tag'] = 'noindex'; 443f6dad9fdSMichael Klier 444ac83b9d8Sandi $mode = substr($act,7); 445f6dad9fdSMichael Klier switch($mode) { 446f6dad9fdSMichael Klier case 'raw': 447*5adfc5afSAnika Henke $headers['Content-Type'] = 'text/plain; charset=utf-8'; 448f6dad9fdSMichael Klier $output = rawWiki($ID,$REV); 449f6dad9fdSMichael Klier break; 450f6dad9fdSMichael Klier case 'xhtml': 451f6dad9fdSMichael Klier $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF; 452f6dad9fdSMichael Klier $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF; 453f6dad9fdSMichael Klier $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF; 454f6dad9fdSMichael Klier $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF; 455f6dad9fdSMichael Klier $pre .= '<head>' . DOKU_LF; 456f6dad9fdSMichael Klier $pre .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF; 457f6dad9fdSMichael Klier $pre .= ' <title>'.$ID.'</title>' . DOKU_LF; 458f6dad9fdSMichael Klier 459f6dad9fdSMichael Klier // get metaheaders 460f6dad9fdSMichael Klier ob_start(); 461f6dad9fdSMichael Klier tpl_metaheaders(); 462f6dad9fdSMichael Klier $pre .= ob_get_clean(); 463f6dad9fdSMichael Klier 464f6dad9fdSMichael Klier $pre .= '</head>' . DOKU_LF; 465f6dad9fdSMichael Klier $pre .= '<body>' . DOKU_LF; 466f6dad9fdSMichael Klier $pre .= '<div class="dokuwiki export">' . DOKU_LF; 467f6dad9fdSMichael Klier 468f6dad9fdSMichael Klier // get toc 469f6dad9fdSMichael Klier $pre .= tpl_toc(true); 470f6dad9fdSMichael Klier 471f6dad9fdSMichael Klier $headers['Content-Type'] = 'text/html; charset=utf-8'; 472f6dad9fdSMichael Klier $output = p_wiki_xhtml($ID,$REV,false); 473f6dad9fdSMichael Klier 474f6dad9fdSMichael Klier $post .= '</div>' . DOKU_LF; 475f6dad9fdSMichael Klier $post .= '</body>' . DOKU_LF; 476f6dad9fdSMichael Klier $post .= '</html>' . DOKU_LF; 477f6dad9fdSMichael Klier break; 478f6dad9fdSMichael Klier case 'xhtmlbody': 479f6dad9fdSMichael Klier $headers['Content-Type'] = 'text/html; charset=utf-8'; 480f6dad9fdSMichael Klier $output = p_wiki_xhtml($ID,$REV,false); 481f6dad9fdSMichael Klier break; 482f6dad9fdSMichael Klier default: 48385767031SAndreas Gohr $headers = p_get_metadata($ID,"format $mode"); 484f6dad9fdSMichael Klier $output = p_cached_output(wikiFN($ID,$REV), $mode); 485f6dad9fdSMichael Klier break; 486f6dad9fdSMichael Klier } 487f6dad9fdSMichael Klier 488f6dad9fdSMichael Klier // prepare event data 489f6dad9fdSMichael Klier $data = array(); 490f6dad9fdSMichael Klier $data['id'] = $ID; 491f6dad9fdSMichael Klier $data['mode'] = $mode; 492f6dad9fdSMichael Klier $data['headers'] = $headers; 493f6dad9fdSMichael Klier $data['output'] =& $output; 494f6dad9fdSMichael Klier 495f6dad9fdSMichael Klier trigger_event('ACTION_EXPORT_POSTPROCESS', $data); 496f6dad9fdSMichael Klier 497f6dad9fdSMichael Klier if(!empty($data['output'])){ 498f6dad9fdSMichael Klier if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){ 49985767031SAndreas Gohr header("$key: $val"); 50085767031SAndreas Gohr } 501f6dad9fdSMichael Klier print $pre.$data['output'].$post; 5026b13307fSandi exit; 5036b13307fSandi } 5046b13307fSandi return 'show'; 5056b13307fSandi} 506340756e4Sandi 507b158d625SSteven Danz/** 50852b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe' 509b158d625SSteven Danz * 510b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com> 5111380fc45SAndreas Gohr * @todo localize 512b158d625SSteven Danz */ 5131380fc45SAndreas Gohrfunction act_subscription($act){ 514b158d625SSteven Danz global $ID; 515b158d625SSteven Danz global $INFO; 516f9eb5648Ssteven-danz global $lang; 517b158d625SSteven Danz 5181380fc45SAndreas Gohr $file=metaFN($ID,'.mlist'); 5191380fc45SAndreas Gohr if ($act=='subscribe' && !$INFO['subscribed']){ 520b158d625SSteven Danz if ($INFO['userinfo']['mail']){ 5211380fc45SAndreas Gohr if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 5221380fc45SAndreas Gohr $INFO['subscribed'] = true; 523f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 524b158d625SSteven Danz } else { 525f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 526b158d625SSteven Danz } 527b158d625SSteven Danz } else { 528f9eb5648Ssteven-danz msg($lang['subscribe_noaddress']); 529b158d625SSteven Danz } 5301380fc45SAndreas Gohr } elseif ($act=='unsubscribe' && $INFO['subscribed']){ 531b158d625SSteven Danz if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 5321380fc45SAndreas Gohr $INFO['subscribed'] = false; 533f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 534b158d625SSteven Danz } else { 535f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 536b158d625SSteven Danz } 537b158d625SSteven Danz } 538b158d625SSteven Danz 539b158d625SSteven Danz return 'show'; 540b158d625SSteven Danz} 541b158d625SSteven Danz 54252b0dd67SGuy Brand/** 54352b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe' 54452b0dd67SGuy Brand * 54552b0dd67SGuy Brand */ 54652b0dd67SGuy Brandfunction act_subscriptionns($act){ 54752b0dd67SGuy Brand global $ID; 54852b0dd67SGuy Brand global $INFO; 54952b0dd67SGuy Brand global $lang; 55052b0dd67SGuy Brand 55152b0dd67SGuy Brand if(!getNS($ID)) { 55252b0dd67SGuy Brand $file = metaFN(getNS($ID),'.mlist'); 553613964ecSGuy Brand $ns = "root"; 55452b0dd67SGuy Brand } else { 55552b0dd67SGuy Brand $file = metaFN(getNS($ID),'/.mlist'); 556613964ecSGuy Brand $ns = getNS($ID); 55752b0dd67SGuy Brand } 55852b0dd67SGuy Brand 559613964ecSGuy Brand // reuse strings used to display the status of the subscribe action 560613964ecSGuy Brand $act_msg = rtrim($act, 'ns'); 561613964ecSGuy Brand 56252b0dd67SGuy Brand if ($act=='subscribens' && !$INFO['subscribedns']){ 56352b0dd67SGuy Brand if ($INFO['userinfo']['mail']){ 56452b0dd67SGuy Brand if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 56552b0dd67SGuy Brand $INFO['subscribedns'] = true; 566613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 56752b0dd67SGuy Brand } else { 568613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 56952b0dd67SGuy Brand } 57052b0dd67SGuy Brand } else { 57152b0dd67SGuy Brand msg($lang['subscribe_noaddress']); 57252b0dd67SGuy Brand } 57352b0dd67SGuy Brand } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ 57452b0dd67SGuy Brand if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 57552b0dd67SGuy Brand $INFO['subscribedns'] = false; 576613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 57752b0dd67SGuy Brand } else { 578613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 57952b0dd67SGuy Brand } 58052b0dd67SGuy Brand } 58152b0dd67SGuy Brand 58252b0dd67SGuy Brand return 'show'; 58352b0dd67SGuy Brand} 58452b0dd67SGuy Brand 585340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 586