xref: /dokuwiki/inc/actions.php (revision 46c0ed7427c2ff2f45d7ec1a61cfb3b3dd92c914)
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
2869cd1e27SAndreas Gohr  $preact = $ACT;
2969cd1e27SAndreas 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*46c0ed74SMichael Hamann  // when action 'show', the intial not 'show' and POST, do a redirect
133*46c0ed74SMichael Hamann  if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
13469cd1e27SAndreas Gohr    act_redirect($ID,$preact);
13569cd1e27SAndreas 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);
30969cd1e27SAndreas Gohr  session_write_close();
310ee4c4a1bSAndreas Gohr
31169cd1e27SAndreas Gohr  // when done, show page
31269cd1e27SAndreas Gohr  return 'show';
31369cd1e27SAndreas Gohr}
314f951a474SAndreas Gohr
31569cd1e27SAndreas Gohrfunction act_redirect($id,$preact){
31669cd1e27SAndreas Gohr  global $PRE;
31769cd1e27SAndreas 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
32869cd1e27SAndreas Gohr  $opts = array(
32969cd1e27SAndreas Gohr    'id'       => $id,
33069cd1e27SAndreas Gohr    'fragment' => $title,
33169cd1e27SAndreas Gohr    'preact'   => $preact
33269cd1e27SAndreas Gohr  );
33369cd1e27SAndreas Gohr  trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute');
33469cd1e27SAndreas Gohr}
33569cd1e27SAndreas Gohr
33669cd1e27SAndreas Gohrfunction act_redirect_execute($opts){
33769cd1e27SAndreas Gohr  $go = wl($opts['id'],'',true);
33869cd1e27SAndreas Gohr  if($opts['fragment']) $go .= '#'.$opts['fragment'];
33969cd1e27SAndreas 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'){
356ca12ce46SAndreas Gohr    return 'show';
3572288dc06SGuy Brand  }
3586b13307fSandi
3596b13307fSandi  //handle logout
3606b13307fSandi  if($act=='logout'){
36108eda5bcSmatthiasgrimm    $lockedby = checklock($ID); //page still locked?
362424c3c4fSJohannes Buchner    if($lockedby == $_SERVER['REMOTE_USER'])
36308eda5bcSmatthiasgrimm      unlock($ID); //try to unlock
36408eda5bcSmatthiasgrimm
3657cace34dSAndreas Gohr    // do the logout stuff
3666b13307fSandi    auth_logoff();
3677cace34dSAndreas Gohr
3687cace34dSAndreas Gohr    // rebuild info array
3697cace34dSAndreas Gohr    $INFO = pageinfo();
3707cace34dSAndreas Gohr
3716b13307fSandi    return 'login';
3726b13307fSandi  }
3736b13307fSandi
3746b13307fSandi  return $act;
3756b13307fSandi}
3766b13307fSandi
3776b13307fSandi/**
3786b13307fSandi * Handle 'edit', 'preview'
3796b13307fSandi *
3806b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3816b13307fSandi */
3826b13307fSandifunction act_edit($act){
383cd409024Sjorda  global $ID;
384ee4c4a1bSAndreas Gohr  global $INFO;
385cd409024Sjorda
3866b13307fSandi  //check if locked by anyone - if not lock for my self
3876b13307fSandi  $lockedby = checklock($ID);
3886b13307fSandi  if($lockedby) return 'locked';
3896b13307fSandi
3906b13307fSandi  lock($ID);
3916b13307fSandi  return $act;
3926b13307fSandi}
3936b13307fSandi
3946b13307fSandi/**
395f6dad9fdSMichael Klier * Export a wiki page for various formats
396f6dad9fdSMichael Klier *
397f6dad9fdSMichael Klier * Triggers ACTION_EXPORT_POSTPROCESS
398f6dad9fdSMichael Klier *
399f6dad9fdSMichael Klier *  Event data:
400f6dad9fdSMichael Klier *    data['id']      -- page id
401f6dad9fdSMichael Klier *    data['mode']    -- requested export mode
402f6dad9fdSMichael Klier *    data['headers'] -- export headers
403f6dad9fdSMichael Klier *    data['output']  -- export output
4046b13307fSandi *
4056b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
406f6dad9fdSMichael Klier * @author Michael Klier <chi@chimeric.de>
4076b13307fSandi */
4086b13307fSandifunction act_export($act){
4096b13307fSandi  global $ID;
4106b13307fSandi  global $REV;
41185f8705cSAnika Henke  global $conf;
41285f8705cSAnika Henke  global $lang;
4136b13307fSandi
414f6dad9fdSMichael Klier  $pre = '';
415f6dad9fdSMichael Klier  $post = '';
416f6dad9fdSMichael Klier  $output = '';
417f6dad9fdSMichael Klier  $headers = array();
418cc2ae802SAndreas Gohr
419f6dad9fdSMichael Klier  // search engines: never cache exported docs! (Google only currently)
420f6dad9fdSMichael Klier  $headers['X-Robots-Tag'] = 'noindex';
421f6dad9fdSMichael Klier
422ac83b9d8Sandi  $mode = substr($act,7);
423f6dad9fdSMichael Klier  switch($mode) {
424f6dad9fdSMichael Klier    case 'raw':
425f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/plain; charse=utf-8';
426f6dad9fdSMichael Klier      $output = rawWiki($ID,$REV);
427f6dad9fdSMichael Klier      break;
428f6dad9fdSMichael Klier    case 'xhtml':
429f6dad9fdSMichael Klier      $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF;
430f6dad9fdSMichael Klier      $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF;
431f6dad9fdSMichael Klier      $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF;
432f6dad9fdSMichael Klier      $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF;
433f6dad9fdSMichael Klier      $pre .= '<head>' . DOKU_LF;
434f6dad9fdSMichael Klier      $pre .= '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF;
435f6dad9fdSMichael Klier      $pre .= '  <title>'.$ID.'</title>' . DOKU_LF;
436f6dad9fdSMichael Klier
437f6dad9fdSMichael Klier      // get metaheaders
438f6dad9fdSMichael Klier      ob_start();
439f6dad9fdSMichael Klier      tpl_metaheaders();
440f6dad9fdSMichael Klier      $pre .= ob_get_clean();
441f6dad9fdSMichael Klier
442f6dad9fdSMichael Klier      $pre .= '</head>' . DOKU_LF;
443f6dad9fdSMichael Klier      $pre .= '<body>' . DOKU_LF;
444f6dad9fdSMichael Klier      $pre .= '<div class="dokuwiki export">' . DOKU_LF;
445f6dad9fdSMichael Klier
446f6dad9fdSMichael Klier      // get toc
447f6dad9fdSMichael Klier      $pre .= tpl_toc(true);
448f6dad9fdSMichael Klier
449f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/html; charset=utf-8';
450f6dad9fdSMichael Klier      $output = p_wiki_xhtml($ID,$REV,false);
451f6dad9fdSMichael Klier
452f6dad9fdSMichael Klier      $post .= '</div>' . DOKU_LF;
453f6dad9fdSMichael Klier      $post .= '</body>' . DOKU_LF;
454f6dad9fdSMichael Klier      $post .= '</html>' . DOKU_LF;
455f6dad9fdSMichael Klier      break;
456f6dad9fdSMichael Klier    case 'xhtmlbody':
457f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/html; charset=utf-8';
458f6dad9fdSMichael Klier      $output = p_wiki_xhtml($ID,$REV,false);
459f6dad9fdSMichael Klier      break;
460f6dad9fdSMichael Klier    default:
46185767031SAndreas Gohr      $headers = p_get_metadata($ID,"format $mode");
462f6dad9fdSMichael Klier      $output = p_cached_output(wikiFN($ID,$REV), $mode);
463f6dad9fdSMichael Klier      break;
464f6dad9fdSMichael Klier  }
465f6dad9fdSMichael Klier
466f6dad9fdSMichael Klier  // prepare event data
467f6dad9fdSMichael Klier  $data = array();
468f6dad9fdSMichael Klier  $data['id'] = $ID;
469f6dad9fdSMichael Klier  $data['mode'] = $mode;
470f6dad9fdSMichael Klier  $data['headers'] = $headers;
471f6dad9fdSMichael Klier  $data['output'] =& $output;
472f6dad9fdSMichael Klier
473f6dad9fdSMichael Klier  trigger_event('ACTION_EXPORT_POSTPROCESS', $data);
474f6dad9fdSMichael Klier
475f6dad9fdSMichael Klier  if(!empty($data['output'])){
476f6dad9fdSMichael Klier    if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){
47785767031SAndreas Gohr      header("$key: $val");
47885767031SAndreas Gohr    }
479f6dad9fdSMichael Klier    print $pre.$data['output'].$post;
4806b13307fSandi    exit;
4816b13307fSandi  }
4826b13307fSandi  return 'show';
4836b13307fSandi}
484340756e4Sandi
485b158d625SSteven Danz/**
48652b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe'
487b158d625SSteven Danz *
488b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com>
4891380fc45SAndreas Gohr * @todo   localize
490b158d625SSteven Danz */
4911380fc45SAndreas Gohrfunction act_subscription($act){
492b158d625SSteven Danz  global $ID;
493b158d625SSteven Danz  global $INFO;
494f9eb5648Ssteven-danz  global $lang;
495b158d625SSteven Danz
4961380fc45SAndreas Gohr  $file=metaFN($ID,'.mlist');
4971380fc45SAndreas Gohr  if ($act=='subscribe' && !$INFO['subscribed']){
498b158d625SSteven Danz    if ($INFO['userinfo']['mail']){
4991380fc45SAndreas Gohr      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
5001380fc45SAndreas Gohr        $INFO['subscribed'] = true;
501f9eb5648Ssteven-danz        msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
502b158d625SSteven Danz      } else {
503f9eb5648Ssteven-danz        msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
504b158d625SSteven Danz      }
505b158d625SSteven Danz    } else {
506f9eb5648Ssteven-danz      msg($lang['subscribe_noaddress']);
507b158d625SSteven Danz    }
5081380fc45SAndreas Gohr  } elseif ($act=='unsubscribe' && $INFO['subscribed']){
509b158d625SSteven Danz    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
5101380fc45SAndreas Gohr      $INFO['subscribed'] = false;
511f9eb5648Ssteven-danz      msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
512b158d625SSteven Danz    } else {
513f9eb5648Ssteven-danz      msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
514b158d625SSteven Danz    }
515b158d625SSteven Danz  }
516b158d625SSteven Danz
517b158d625SSteven Danz  return 'show';
518b158d625SSteven Danz}
519b158d625SSteven Danz
52052b0dd67SGuy Brand/**
52152b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe'
52252b0dd67SGuy Brand *
52352b0dd67SGuy Brand */
52452b0dd67SGuy Brandfunction act_subscriptionns($act){
52552b0dd67SGuy Brand  global $ID;
52652b0dd67SGuy Brand  global $INFO;
52752b0dd67SGuy Brand  global $lang;
52852b0dd67SGuy Brand
52952b0dd67SGuy Brand  if(!getNS($ID)) {
53052b0dd67SGuy Brand    $file = metaFN(getNS($ID),'.mlist');
531613964ecSGuy Brand    $ns = "root";
53252b0dd67SGuy Brand  } else {
53352b0dd67SGuy Brand    $file = metaFN(getNS($ID),'/.mlist');
534613964ecSGuy Brand    $ns = getNS($ID);
53552b0dd67SGuy Brand  }
53652b0dd67SGuy Brand
537613964ecSGuy Brand  // reuse strings used to display the status of the subscribe action
538613964ecSGuy Brand  $act_msg = rtrim($act, 'ns');
539613964ecSGuy Brand
54052b0dd67SGuy Brand  if ($act=='subscribens' && !$INFO['subscribedns']){
54152b0dd67SGuy Brand    if ($INFO['userinfo']['mail']){
54252b0dd67SGuy Brand      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
54352b0dd67SGuy Brand        $INFO['subscribedns'] = true;
544613964ecSGuy Brand        msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1);
54552b0dd67SGuy Brand      } else {
546613964ecSGuy Brand        msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1);
54752b0dd67SGuy Brand      }
54852b0dd67SGuy Brand    } else {
54952b0dd67SGuy Brand      msg($lang['subscribe_noaddress']);
55052b0dd67SGuy Brand    }
55152b0dd67SGuy Brand  } elseif ($act=='unsubscribens' && $INFO['subscribedns']){
55252b0dd67SGuy Brand    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
55352b0dd67SGuy Brand      $INFO['subscribedns'] = false;
554613964ecSGuy Brand      msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1);
55552b0dd67SGuy Brand    } else {
556613964ecSGuy Brand      msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1);
55752b0dd67SGuy Brand    }
55852b0dd67SGuy Brand  }
55952b0dd67SGuy Brand
56052b0dd67SGuy Brand  return 'show';
56152b0dd67SGuy Brand}
56252b0dd67SGuy Brand
563340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
564