xref: /dokuwiki/inc/actions.php (revision 066fee3089513b988d1beac2040e32a365921310)
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;
27*066fee30SAndreas 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
718b06d178Schris    if (($ACT == 'profile') && updateprofile()) {
724cb79657SMatthias Grimm      msg($lang['profchanged'],1);
734cb79657SMatthias Grimm      $ACT = 'show';
748b06d178Schris    }
758b06d178Schris
766b13307fSandi    //save
771b2a85e8SAndreas Gohr    if($ACT == 'save'){
781b2a85e8SAndreas Gohr      if(checkSecurityToken()){
796b13307fSandi        $ACT = act_save($ACT);
801b2a85e8SAndreas Gohr      }else{
811b2a85e8SAndreas Gohr        $ACT = 'show';
821b2a85e8SAndreas Gohr      }
831b2a85e8SAndreas Gohr    }
846b13307fSandi
85067c5d22SBen Coburn    //cancel conflicting edit
86067c5d22SBen Coburn    if($ACT == 'cancel')
87067c5d22SBen Coburn      $ACT = 'show';
88067c5d22SBen Coburn
89ee4c4a1bSAndreas Gohr    //draft deletion
90ee4c4a1bSAndreas Gohr    if($ACT == 'draftdel')
91ee4c4a1bSAndreas Gohr      $ACT = act_draftdel($ACT);
92ee4c4a1bSAndreas Gohr
93ee4c4a1bSAndreas Gohr    //draft saving on preview
94ee4c4a1bSAndreas Gohr    if($ACT == 'preview')
95ee4c4a1bSAndreas Gohr      $ACT = act_draftsave($ACT);
96ee4c4a1bSAndreas Gohr
976b13307fSandi    //edit
98b146b32bSandi    if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){
99af182434Sandi      $ACT = act_edit($ACT);
1006b13307fSandi    }else{
1016b13307fSandi      unlock($ID); //try to unlock
1026b13307fSandi    }
1036b13307fSandi
1046b13307fSandi    //handle export
105ac83b9d8Sandi    if(substr($ACT,0,7) == 'export_')
1066b13307fSandi      $ACT = act_export($ACT);
1076b13307fSandi
1086b13307fSandi    //display some infos
1096b13307fSandi    if($ACT == 'check'){
1106b13307fSandi      check();
1116b13307fSandi      $ACT = 'show';
1126b13307fSandi    }
1136b13307fSandi
114c19fe9c0Sandi    //handle admin tasks
115c19fe9c0Sandi    if($ACT == 'admin'){
11611e2ce22Schris      // retrieve admin plugin name from $_REQUEST['page']
117bb4866bdSchris      if (!empty($_REQUEST['page'])) {
11811e2ce22Schris          $pluginlist = plugin_list('admin');
11911e2ce22Schris          if (in_array($_REQUEST['page'], $pluginlist)) {
12011e2ce22Schris            // attempt to load the plugin
12111e2ce22Schris            if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL)
12211e2ce22Schris                $plugin->handle();
12311e2ce22Schris          }
12411e2ce22Schris      }
125c19fe9c0Sandi    }
1265f312bacSAndreas Gohr
1275f312bacSAndreas Gohr    // check permissions again - the action may have changed
1285f312bacSAndreas Gohr    $ACT = act_permcheck($ACT);
12924bb549bSchris  }  // end event ACTION_ACT_PREPROCESS default action
13024bb549bSchris  $evt->advise_after();
13124bb549bSchris  unset($evt);
132c19fe9c0Sandi
13346c0ed74SMichael Hamann  // when action 'show', the intial not 'show' and POST, do a redirect
13446c0ed74SMichael Hamann  if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
13569cd1e27SAndreas Gohr    act_redirect($ID,$preact);
13669cd1e27SAndreas Gohr  }
1375f312bacSAndreas Gohr
1386b13307fSandi  //call template FIXME: all needed vars available?
139f63a2007Schris  $headers[] = 'Content-Type: text/html; charset=utf-8';
140746855cfSBen Coburn  trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders');
141f63a2007Schris
1425a892029SAndreas Gohr  include(template('main.php'));
143c19fe9c0Sandi  // output for the commands is now handled in inc/templates.php
144c19fe9c0Sandi  // in function tpl_content()
1456b13307fSandi}
1466b13307fSandi
147f63a2007Schrisfunction act_sendheaders($headers) {
148f63a2007Schris  foreach ($headers as $hdr) header($hdr);
149f63a2007Schris}
150f63a2007Schris
1516b13307fSandi/**
152af182434Sandi * Sanitize the action command
153af182434Sandi *
154af182434Sandi * Add all allowed commands here.
155af182434Sandi *
156af182434Sandi * @author Andreas Gohr <andi@splitbrain.org>
157af182434Sandi */
158af182434Sandifunction act_clean($act){
159af182434Sandi  global $lang;
16060e6b550SAndreas Gohr  global $conf;
161af182434Sandi
162ee4c4a1bSAndreas Gohr  // check if the action was given as array key
163ee4c4a1bSAndreas Gohr  if(is_array($act)){
164ee4c4a1bSAndreas Gohr    list($act) = array_keys($act);
165ee4c4a1bSAndreas Gohr  }
166ee4c4a1bSAndreas Gohr
167ac83b9d8Sandi  //remove all bad chars
168ac83b9d8Sandi  $act = strtolower($act);
1692d5ccb39SAndreas Gohr  $act = preg_replace('/[^1-9a-z_]+/','',$act);
170ac83b9d8Sandi
171ac83b9d8Sandi  if($act == 'export_html') $act = 'export_xhtml';
172cc2ae802SAndreas Gohr  if($act == 'export_htmlbody') $act = 'export_xhtmlbody';
173b146b32bSandi
174409d7af7SAndreas Gohr  // check if action is disabled
175409d7af7SAndreas Gohr  if(!actionOK($act)){
176409d7af7SAndreas Gohr    msg('Command disabled: '.htmlspecialchars($act),-1);
177409d7af7SAndreas Gohr    return 'show';
178409d7af7SAndreas Gohr  }
179409d7af7SAndreas Gohr
18060e6b550SAndreas Gohr  //disable all acl related commands if ACL is disabled
18160e6b550SAndreas Gohr  if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin',
18260e6b550SAndreas Gohr                                             'subscribe','unsubscribe','profile',
18352b0dd67SGuy Brand                                             'resendpwd','subscribens','unsubscribens',))){
18460e6b550SAndreas Gohr    msg('Command unavailable: '.htmlspecialchars($act),-1);
18560e6b550SAndreas Gohr    return 'show';
18660e6b550SAndreas Gohr  }
18760e6b550SAndreas Gohr
188067c5d22SBen Coburn  if(!in_array($act,array('login','logout','register','save','cancel','edit','draft',
189ac83b9d8Sandi                          'preview','search','show','check','index','revisions',
1901380fc45SAndreas Gohr                          'diff','recent','backlink','admin','subscribe',
19118829381SAndreas Gohr                          'unsubscribe','profile','resendpwd','recover','wordblock',
19252b0dd67SGuy Brand                          'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) {
193ee4c4a1bSAndreas Gohr    msg('Command unknown: '.htmlspecialchars($act),-1);
194af182434Sandi    return 'show';
195af182434Sandi  }
196af182434Sandi  return $act;
197af182434Sandi}
198af182434Sandi
199af182434Sandi/**
2006b13307fSandi * Run permissionchecks
2016b13307fSandi *
2026b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2036b13307fSandi */
2046b13307fSandifunction act_permcheck($act){
205dbbc6aa7Sandi  global $INFO;
2065e199953Smatthiasgrimm  global $conf;
207dbbc6aa7Sandi
208ee4c4a1bSAndreas Gohr  if(in_array($act,array('save','preview','edit','recover'))){
2096b13307fSandi    if($INFO['exists']){
210bdbc16bfSandi      if($act == 'edit'){
211bdbc16bfSandi        //the edit function will check again and do a source show
212bdbc16bfSandi        //when no AUTH_EDIT available
213bdbc16bfSandi        $permneed = AUTH_READ;
214bdbc16bfSandi      }else{
2156b13307fSandi        $permneed = AUTH_EDIT;
216bdbc16bfSandi      }
2176b13307fSandi    }else{
2186b13307fSandi      $permneed = AUTH_CREATE;
2196b13307fSandi    }
2208b06d178Schris  }elseif(in_array($act,array('login','search','recent','profile'))){
2216b13307fSandi    $permneed = AUTH_NONE;
2225e199953Smatthiasgrimm  }elseif($act == 'register'){
2235e199953Smatthiasgrimm    $permneed = AUTH_NONE;
224ebd3d9ceSchris  }elseif($act == 'resendpwd'){
225ebd3d9ceSchris    $permneed = AUTH_NONE;
226c19fe9c0Sandi  }elseif($act == 'admin'){
227f8cc712eSAndreas Gohr    if($INFO['ismanager']){
228f8cc712eSAndreas Gohr      // if the manager has the needed permissions for a certain admin
229f8cc712eSAndreas Gohr      // action is checked later
230f8cc712eSAndreas Gohr      $permneed = AUTH_READ;
231f8cc712eSAndreas Gohr    }else{
232c19fe9c0Sandi      $permneed = AUTH_ADMIN;
233f8cc712eSAndreas Gohr    }
2346b13307fSandi  }else{
2356b13307fSandi    $permneed = AUTH_READ;
2366b13307fSandi  }
237dbbc6aa7Sandi  if($INFO['perm'] >= $permneed) return $act;
238dbbc6aa7Sandi
2396b13307fSandi  return 'denied';
2406b13307fSandi}
2416b13307fSandi
2426b13307fSandi/**
243ee4c4a1bSAndreas Gohr * Handle 'draftdel'
244ee4c4a1bSAndreas Gohr *
245ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user
246ee4c4a1bSAndreas Gohr */
247ee4c4a1bSAndreas Gohrfunction act_draftdel($act){
248ee4c4a1bSAndreas Gohr  global $INFO;
249ee4c4a1bSAndreas Gohr  @unlink($INFO['draft']);
250ee4c4a1bSAndreas Gohr  $INFO['draft'] = null;
251ee4c4a1bSAndreas Gohr  return 'show';
252ee4c4a1bSAndreas Gohr}
253ee4c4a1bSAndreas Gohr
254ee4c4a1bSAndreas Gohr/**
255ee4c4a1bSAndreas Gohr * Saves a draft on preview
256ee4c4a1bSAndreas Gohr *
257ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/
258ee4c4a1bSAndreas Gohr */
259ee4c4a1bSAndreas Gohrfunction act_draftsave($act){
260ee4c4a1bSAndreas Gohr  global $INFO;
261ee4c4a1bSAndreas Gohr  global $ID;
262ee4c4a1bSAndreas Gohr  global $conf;
263ee4c4a1bSAndreas Gohr  if($conf['usedraft'] && $_POST['wikitext']){
264ee4c4a1bSAndreas Gohr    $draft = array('id'     => $ID,
265ee4c4a1bSAndreas Gohr                   'prefix' => $_POST['prefix'],
266ee4c4a1bSAndreas Gohr                   'text'   => $_POST['wikitext'],
267ee4c4a1bSAndreas Gohr                   'suffix' => $_POST['suffix'],
268ee4c4a1bSAndreas Gohr                   'date'   => $_POST['date'],
269ee4c4a1bSAndreas Gohr                   'client' => $INFO['client'],
270ee4c4a1bSAndreas Gohr                  );
271ee4c4a1bSAndreas Gohr    $cname = getCacheName($draft['client'].$ID,'.draft');
272ee4c4a1bSAndreas Gohr    if(io_saveFile($cname,serialize($draft))){
273ee4c4a1bSAndreas Gohr      $INFO['draft'] = $cname;
274ee4c4a1bSAndreas Gohr    }
275ee4c4a1bSAndreas Gohr  }
276ee4c4a1bSAndreas Gohr  return $act;
277ee4c4a1bSAndreas Gohr}
278ee4c4a1bSAndreas Gohr
279ee4c4a1bSAndreas Gohr/**
2806b13307fSandi * Handle 'save'
2816b13307fSandi *
2826b13307fSandi * Checks for spam and conflicts and saves the page.
2836b13307fSandi * Does a redirect to show the page afterwards or
2846b13307fSandi * returns a new action.
2856b13307fSandi *
2866b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2876b13307fSandi */
2886b13307fSandifunction act_save($act){
2896b13307fSandi  global $ID;
2906b13307fSandi  global $DATE;
2916b13307fSandi  global $PRE;
2926b13307fSandi  global $TEXT;
2936b13307fSandi  global $SUF;
2946b13307fSandi  global $SUM;
2956b13307fSandi
2966b13307fSandi  //spam check
2976b13307fSandi  if(checkwordblock())
2986b13307fSandi    return 'wordblock';
2996b13307fSandi  //conflict check //FIXME use INFO
3006b13307fSandi  if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE )
3016b13307fSandi    return 'conflict';
3026b13307fSandi
3036b13307fSandi  //save it
304b6912aeaSAndreas Gohr  saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con
3056b13307fSandi  //unlock it
3066b13307fSandi  unlock($ID);
3076b13307fSandi
308ee4c4a1bSAndreas Gohr  //delete draft
309ee4c4a1bSAndreas Gohr  act_draftdel($act);
31069cd1e27SAndreas Gohr  session_write_close();
311ee4c4a1bSAndreas Gohr
31269cd1e27SAndreas Gohr  // when done, show page
31369cd1e27SAndreas Gohr  return 'show';
31469cd1e27SAndreas Gohr}
315f951a474SAndreas Gohr
31614a122deSAndreas Gohr/**
31714a122deSAndreas Gohr * Do a redirect after receiving post data
31814a122deSAndreas Gohr *
31914a122deSAndreas Gohr * Tries to add the section id as hash mark after section editing
32014a122deSAndreas Gohr */
32169cd1e27SAndreas Gohrfunction act_redirect($id,$preact){
32269cd1e27SAndreas Gohr  global $PRE;
32369cd1e27SAndreas Gohr  global $TEXT;
32414a122deSAndreas Gohr  global $MSG;
32514a122deSAndreas Gohr
32614a122deSAndreas Gohr  //are there any undisplayed messages? keep them in session for display
32714a122deSAndreas Gohr  //on the next page
32814a122deSAndreas Gohr  if(isset($MSG) && count($MSG)){
32914a122deSAndreas Gohr    //reopen session, store data and close session again
33014a122deSAndreas Gohr    @session_start();
33114a122deSAndreas Gohr    $_SESSION[DOKU_COOKIE]['msg'] = $MSG;
33214a122deSAndreas Gohr    session_write_close();
33314a122deSAndreas Gohr  }
334f951a474SAndreas Gohr
335f951a474SAndreas Gohr  //get section name when coming from section edit
336f951a474SAndreas Gohr  if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){
337f951a474SAndreas Gohr    #FIXME duplicates code from xhtml renderer
338f951a474SAndreas Gohr    $title = $match[0];
339f951a474SAndreas Gohr    $title = str_replace(':','',cleanID($title));
340f951a474SAndreas Gohr    $title = ltrim($title,'0123456789._-');
341f951a474SAndreas Gohr    if(empty($title)) $title='section';
342f951a474SAndreas Gohr  }
343f951a474SAndreas Gohr
34469cd1e27SAndreas Gohr  $opts = array(
34569cd1e27SAndreas Gohr    'id'       => $id,
34669cd1e27SAndreas Gohr    'fragment' => $title,
34769cd1e27SAndreas Gohr    'preact'   => $preact
34869cd1e27SAndreas Gohr  );
34969cd1e27SAndreas Gohr  trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute');
35069cd1e27SAndreas Gohr}
35169cd1e27SAndreas Gohr
35269cd1e27SAndreas Gohrfunction act_redirect_execute($opts){
35369cd1e27SAndreas Gohr  $go = wl($opts['id'],'',true);
35469cd1e27SAndreas Gohr  if($opts['fragment']) $go .= '#'.$opts['fragment'];
35569cd1e27SAndreas Gohr
3566b13307fSandi  //show it
357f951a474SAndreas Gohr  header("Location: $go");
3586b13307fSandi  exit();
3596b13307fSandi}
3606b13307fSandi
3616b13307fSandi/**
362b8957367SBenjamin Gilbert * Handle 'login', 'logout'
3636b13307fSandi *
3646b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3656b13307fSandi */
3666b13307fSandifunction act_auth($act){
36708eda5bcSmatthiasgrimm  global $ID;
3687cace34dSAndreas Gohr  global $INFO;
36908eda5bcSmatthiasgrimm
3706b13307fSandi  //already logged in?
3712288dc06SGuy Brand  if($_SERVER['REMOTE_USER'] && $act=='login'){
372ca12ce46SAndreas Gohr    return 'show';
3732288dc06SGuy Brand  }
3746b13307fSandi
3756b13307fSandi  //handle logout
3766b13307fSandi  if($act=='logout'){
37708eda5bcSmatthiasgrimm    $lockedby = checklock($ID); //page still locked?
378424c3c4fSJohannes Buchner    if($lockedby == $_SERVER['REMOTE_USER'])
37908eda5bcSmatthiasgrimm      unlock($ID); //try to unlock
38008eda5bcSmatthiasgrimm
3817cace34dSAndreas Gohr    // do the logout stuff
3826b13307fSandi    auth_logoff();
3837cace34dSAndreas Gohr
3847cace34dSAndreas Gohr    // rebuild info array
3857cace34dSAndreas Gohr    $INFO = pageinfo();
3867cace34dSAndreas Gohr
387e16eccb7SGuy Brand    act_redirect($ID,'login');
3886b13307fSandi  }
3896b13307fSandi
3906b13307fSandi  return $act;
3916b13307fSandi}
3926b13307fSandi
3936b13307fSandi/**
3946b13307fSandi * Handle 'edit', 'preview'
3956b13307fSandi *
3966b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3976b13307fSandi */
3986b13307fSandifunction act_edit($act){
399cd409024Sjorda  global $ID;
400ee4c4a1bSAndreas Gohr  global $INFO;
401cd409024Sjorda
4026b13307fSandi  //check if locked by anyone - if not lock for my self
4036b13307fSandi  $lockedby = checklock($ID);
4046b13307fSandi  if($lockedby) return 'locked';
4056b13307fSandi
4066b13307fSandi  lock($ID);
4076b13307fSandi  return $act;
4086b13307fSandi}
4096b13307fSandi
4106b13307fSandi/**
411f6dad9fdSMichael Klier * Export a wiki page for various formats
412f6dad9fdSMichael Klier *
413f6dad9fdSMichael Klier * Triggers ACTION_EXPORT_POSTPROCESS
414f6dad9fdSMichael Klier *
415f6dad9fdSMichael Klier *  Event data:
416f6dad9fdSMichael Klier *    data['id']      -- page id
417f6dad9fdSMichael Klier *    data['mode']    -- requested export mode
418f6dad9fdSMichael Klier *    data['headers'] -- export headers
419f6dad9fdSMichael Klier *    data['output']  -- export output
4206b13307fSandi *
4216b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
422f6dad9fdSMichael Klier * @author Michael Klier <chi@chimeric.de>
4236b13307fSandi */
4246b13307fSandifunction act_export($act){
4256b13307fSandi  global $ID;
4266b13307fSandi  global $REV;
42785f8705cSAnika Henke  global $conf;
42885f8705cSAnika Henke  global $lang;
4296b13307fSandi
430f6dad9fdSMichael Klier  $pre = '';
431f6dad9fdSMichael Klier  $post = '';
432f6dad9fdSMichael Klier  $output = '';
433f6dad9fdSMichael Klier  $headers = array();
434cc2ae802SAndreas Gohr
435f6dad9fdSMichael Klier  // search engines: never cache exported docs! (Google only currently)
436f6dad9fdSMichael Klier  $headers['X-Robots-Tag'] = 'noindex';
437f6dad9fdSMichael Klier
438ac83b9d8Sandi  $mode = substr($act,7);
439f6dad9fdSMichael Klier  switch($mode) {
440f6dad9fdSMichael Klier    case 'raw':
441f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/plain; charse=utf-8';
442f6dad9fdSMichael Klier      $output = rawWiki($ID,$REV);
443f6dad9fdSMichael Klier      break;
444f6dad9fdSMichael Klier    case 'xhtml':
445f6dad9fdSMichael Klier      $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF;
446f6dad9fdSMichael Klier      $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF;
447f6dad9fdSMichael Klier      $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF;
448f6dad9fdSMichael Klier      $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF;
449f6dad9fdSMichael Klier      $pre .= '<head>' . DOKU_LF;
450f6dad9fdSMichael Klier      $pre .= '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF;
451f6dad9fdSMichael Klier      $pre .= '  <title>'.$ID.'</title>' . DOKU_LF;
452f6dad9fdSMichael Klier
453f6dad9fdSMichael Klier      // get metaheaders
454f6dad9fdSMichael Klier      ob_start();
455f6dad9fdSMichael Klier      tpl_metaheaders();
456f6dad9fdSMichael Klier      $pre .= ob_get_clean();
457f6dad9fdSMichael Klier
458f6dad9fdSMichael Klier      $pre .= '</head>' . DOKU_LF;
459f6dad9fdSMichael Klier      $pre .= '<body>' . DOKU_LF;
460f6dad9fdSMichael Klier      $pre .= '<div class="dokuwiki export">' . DOKU_LF;
461f6dad9fdSMichael Klier
462f6dad9fdSMichael Klier      // get toc
463f6dad9fdSMichael Klier      $pre .= tpl_toc(true);
464f6dad9fdSMichael Klier
465f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/html; charset=utf-8';
466f6dad9fdSMichael Klier      $output = p_wiki_xhtml($ID,$REV,false);
467f6dad9fdSMichael Klier
468f6dad9fdSMichael Klier      $post .= '</div>' . DOKU_LF;
469f6dad9fdSMichael Klier      $post .= '</body>' . DOKU_LF;
470f6dad9fdSMichael Klier      $post .= '</html>' . DOKU_LF;
471f6dad9fdSMichael Klier      break;
472f6dad9fdSMichael Klier    case 'xhtmlbody':
473f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/html; charset=utf-8';
474f6dad9fdSMichael Klier      $output = p_wiki_xhtml($ID,$REV,false);
475f6dad9fdSMichael Klier      break;
476f6dad9fdSMichael Klier    default:
47785767031SAndreas Gohr      $headers = p_get_metadata($ID,"format $mode");
478f6dad9fdSMichael Klier      $output = p_cached_output(wikiFN($ID,$REV), $mode);
479f6dad9fdSMichael Klier      break;
480f6dad9fdSMichael Klier  }
481f6dad9fdSMichael Klier
482f6dad9fdSMichael Klier  // prepare event data
483f6dad9fdSMichael Klier  $data = array();
484f6dad9fdSMichael Klier  $data['id'] = $ID;
485f6dad9fdSMichael Klier  $data['mode'] = $mode;
486f6dad9fdSMichael Klier  $data['headers'] = $headers;
487f6dad9fdSMichael Klier  $data['output'] =& $output;
488f6dad9fdSMichael Klier
489f6dad9fdSMichael Klier  trigger_event('ACTION_EXPORT_POSTPROCESS', $data);
490f6dad9fdSMichael Klier
491f6dad9fdSMichael Klier  if(!empty($data['output'])){
492f6dad9fdSMichael Klier    if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){
49385767031SAndreas Gohr      header("$key: $val");
49485767031SAndreas Gohr    }
495f6dad9fdSMichael Klier    print $pre.$data['output'].$post;
4966b13307fSandi    exit;
4976b13307fSandi  }
4986b13307fSandi  return 'show';
4996b13307fSandi}
500340756e4Sandi
501b158d625SSteven Danz/**
50252b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe'
503b158d625SSteven Danz *
504b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com>
5051380fc45SAndreas Gohr * @todo   localize
506b158d625SSteven Danz */
5071380fc45SAndreas Gohrfunction act_subscription($act){
508b158d625SSteven Danz  global $ID;
509b158d625SSteven Danz  global $INFO;
510f9eb5648Ssteven-danz  global $lang;
511b158d625SSteven Danz
5121380fc45SAndreas Gohr  $file=metaFN($ID,'.mlist');
5131380fc45SAndreas Gohr  if ($act=='subscribe' && !$INFO['subscribed']){
514b158d625SSteven Danz    if ($INFO['userinfo']['mail']){
5151380fc45SAndreas Gohr      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
5161380fc45SAndreas Gohr        $INFO['subscribed'] = true;
517f9eb5648Ssteven-danz        msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
518b158d625SSteven Danz      } else {
519f9eb5648Ssteven-danz        msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
520b158d625SSteven Danz      }
521b158d625SSteven Danz    } else {
522f9eb5648Ssteven-danz      msg($lang['subscribe_noaddress']);
523b158d625SSteven Danz    }
5241380fc45SAndreas Gohr  } elseif ($act=='unsubscribe' && $INFO['subscribed']){
525b158d625SSteven Danz    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
5261380fc45SAndreas Gohr      $INFO['subscribed'] = false;
527f9eb5648Ssteven-danz      msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
528b158d625SSteven Danz    } else {
529f9eb5648Ssteven-danz      msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
530b158d625SSteven Danz    }
531b158d625SSteven Danz  }
532b158d625SSteven Danz
533b158d625SSteven Danz  return 'show';
534b158d625SSteven Danz}
535b158d625SSteven Danz
53652b0dd67SGuy Brand/**
53752b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe'
53852b0dd67SGuy Brand *
53952b0dd67SGuy Brand */
54052b0dd67SGuy Brandfunction act_subscriptionns($act){
54152b0dd67SGuy Brand  global $ID;
54252b0dd67SGuy Brand  global $INFO;
54352b0dd67SGuy Brand  global $lang;
54452b0dd67SGuy Brand
54552b0dd67SGuy Brand  if(!getNS($ID)) {
54652b0dd67SGuy Brand    $file = metaFN(getNS($ID),'.mlist');
547613964ecSGuy Brand    $ns = "root";
54852b0dd67SGuy Brand  } else {
54952b0dd67SGuy Brand    $file = metaFN(getNS($ID),'/.mlist');
550613964ecSGuy Brand    $ns = getNS($ID);
55152b0dd67SGuy Brand  }
55252b0dd67SGuy Brand
553613964ecSGuy Brand  // reuse strings used to display the status of the subscribe action
554613964ecSGuy Brand  $act_msg = rtrim($act, 'ns');
555613964ecSGuy Brand
55652b0dd67SGuy Brand  if ($act=='subscribens' && !$INFO['subscribedns']){
55752b0dd67SGuy Brand    if ($INFO['userinfo']['mail']){
55852b0dd67SGuy Brand      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
55952b0dd67SGuy Brand        $INFO['subscribedns'] = true;
560613964ecSGuy Brand        msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1);
56152b0dd67SGuy Brand      } else {
562613964ecSGuy Brand        msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1);
56352b0dd67SGuy Brand      }
56452b0dd67SGuy Brand    } else {
56552b0dd67SGuy Brand      msg($lang['subscribe_noaddress']);
56652b0dd67SGuy Brand    }
56752b0dd67SGuy Brand  } elseif ($act=='unsubscribens' && $INFO['subscribedns']){
56852b0dd67SGuy Brand    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
56952b0dd67SGuy Brand      $INFO['subscribedns'] = false;
570613964ecSGuy Brand      msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1);
57152b0dd67SGuy Brand    } else {
572613964ecSGuy Brand      msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1);
57352b0dd67SGuy Brand    }
57452b0dd67SGuy Brand  }
57552b0dd67SGuy Brand
57652b0dd67SGuy Brand  return 'show';
57752b0dd67SGuy Brand}
57852b0dd67SGuy Brand
579340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
580