xref: /dokuwiki/inc/actions.php (revision af2408d59bbe5e59c6c6b3a8125e6b512a887663)
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
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
106b13307fSandirequire_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)){
343443d207bSAndreas Gohr    $check = false;
344443d207bSAndreas Gohr    $title = sectionID($match[0],$check);
345f951a474SAndreas Gohr  }
346f951a474SAndreas Gohr
34769cd1e27SAndreas Gohr  $opts = array(
34869cd1e27SAndreas Gohr    'id'       => $id,
34969cd1e27SAndreas Gohr    'fragment' => $title,
35069cd1e27SAndreas Gohr    'preact'   => $preact
35169cd1e27SAndreas Gohr  );
35269cd1e27SAndreas Gohr  trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute');
35369cd1e27SAndreas Gohr}
35469cd1e27SAndreas Gohr
35569cd1e27SAndreas Gohrfunction act_redirect_execute($opts){
35669cd1e27SAndreas Gohr  $go = wl($opts['id'],'',true);
35769cd1e27SAndreas Gohr  if($opts['fragment']) $go .= '#'.$opts['fragment'];
35869cd1e27SAndreas Gohr
3596b13307fSandi  //show it
360*af2408d5SAndreas Gohr  send_redirect($go);
3616b13307fSandi}
3626b13307fSandi
3636b13307fSandi/**
364b8957367SBenjamin Gilbert * Handle 'login', 'logout'
3656b13307fSandi *
3666b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3676b13307fSandi */
3686b13307fSandifunction act_auth($act){
36908eda5bcSmatthiasgrimm  global $ID;
3707cace34dSAndreas Gohr  global $INFO;
37108eda5bcSmatthiasgrimm
3726b13307fSandi  //already logged in?
3732288dc06SGuy Brand  if($_SERVER['REMOTE_USER'] && $act=='login'){
374ca12ce46SAndreas Gohr    return 'show';
3752288dc06SGuy Brand  }
3766b13307fSandi
3776b13307fSandi  //handle logout
3786b13307fSandi  if($act=='logout'){
37908eda5bcSmatthiasgrimm    $lockedby = checklock($ID); //page still locked?
380424c3c4fSJohannes Buchner    if($lockedby == $_SERVER['REMOTE_USER'])
38108eda5bcSmatthiasgrimm      unlock($ID); //try to unlock
38208eda5bcSmatthiasgrimm
3837cace34dSAndreas Gohr    // do the logout stuff
3846b13307fSandi    auth_logoff();
3857cace34dSAndreas Gohr
3867cace34dSAndreas Gohr    // rebuild info array
3877cace34dSAndreas Gohr    $INFO = pageinfo();
3887cace34dSAndreas Gohr
389e16eccb7SGuy Brand    act_redirect($ID,'login');
3906b13307fSandi  }
3916b13307fSandi
3926b13307fSandi  return $act;
3936b13307fSandi}
3946b13307fSandi
3956b13307fSandi/**
3966b13307fSandi * Handle 'edit', 'preview'
3976b13307fSandi *
3986b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3996b13307fSandi */
4006b13307fSandifunction act_edit($act){
401cd409024Sjorda  global $ID;
402ee4c4a1bSAndreas Gohr  global $INFO;
403cd409024Sjorda
4046b13307fSandi  //check if locked by anyone - if not lock for my self
4056b13307fSandi  $lockedby = checklock($ID);
4066b13307fSandi  if($lockedby) return 'locked';
4076b13307fSandi
4086b13307fSandi  lock($ID);
4096b13307fSandi  return $act;
4106b13307fSandi}
4116b13307fSandi
4126b13307fSandi/**
413f6dad9fdSMichael Klier * Export a wiki page for various formats
414f6dad9fdSMichael Klier *
415f6dad9fdSMichael Klier * Triggers ACTION_EXPORT_POSTPROCESS
416f6dad9fdSMichael Klier *
417f6dad9fdSMichael Klier *  Event data:
418f6dad9fdSMichael Klier *    data['id']      -- page id
419f6dad9fdSMichael Klier *    data['mode']    -- requested export mode
420f6dad9fdSMichael Klier *    data['headers'] -- export headers
421f6dad9fdSMichael Klier *    data['output']  -- export output
4226b13307fSandi *
4236b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
424f6dad9fdSMichael Klier * @author Michael Klier <chi@chimeric.de>
4256b13307fSandi */
4266b13307fSandifunction act_export($act){
4276b13307fSandi  global $ID;
4286b13307fSandi  global $REV;
42985f8705cSAnika Henke  global $conf;
43085f8705cSAnika Henke  global $lang;
4316b13307fSandi
432f6dad9fdSMichael Klier  $pre = '';
433f6dad9fdSMichael Klier  $post = '';
434f6dad9fdSMichael Klier  $output = '';
435f6dad9fdSMichael Klier  $headers = array();
436cc2ae802SAndreas Gohr
437f6dad9fdSMichael Klier  // search engines: never cache exported docs! (Google only currently)
438f6dad9fdSMichael Klier  $headers['X-Robots-Tag'] = 'noindex';
439f6dad9fdSMichael Klier
440ac83b9d8Sandi  $mode = substr($act,7);
441f6dad9fdSMichael Klier  switch($mode) {
442f6dad9fdSMichael Klier    case 'raw':
4435adfc5afSAnika Henke      $headers['Content-Type'] = 'text/plain; charset=utf-8';
444f6dad9fdSMichael Klier      $output = rawWiki($ID,$REV);
445f6dad9fdSMichael Klier      break;
446f6dad9fdSMichael Klier    case 'xhtml':
447f6dad9fdSMichael Klier      $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF;
448f6dad9fdSMichael Klier      $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF;
449f6dad9fdSMichael Klier      $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF;
450f6dad9fdSMichael Klier      $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF;
451f6dad9fdSMichael Klier      $pre .= '<head>' . DOKU_LF;
452f6dad9fdSMichael Klier      $pre .= '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF;
453f6dad9fdSMichael Klier      $pre .= '  <title>'.$ID.'</title>' . DOKU_LF;
454f6dad9fdSMichael Klier
455f6dad9fdSMichael Klier      // get metaheaders
456f6dad9fdSMichael Klier      ob_start();
457f6dad9fdSMichael Klier      tpl_metaheaders();
458f6dad9fdSMichael Klier      $pre .= ob_get_clean();
459f6dad9fdSMichael Klier
460f6dad9fdSMichael Klier      $pre .= '</head>' . DOKU_LF;
461f6dad9fdSMichael Klier      $pre .= '<body>' . DOKU_LF;
462f6dad9fdSMichael Klier      $pre .= '<div class="dokuwiki export">' . DOKU_LF;
463f6dad9fdSMichael Klier
464f6dad9fdSMichael Klier      // get toc
465f6dad9fdSMichael Klier      $pre .= tpl_toc(true);
466f6dad9fdSMichael Klier
467f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/html; charset=utf-8';
468f6dad9fdSMichael Klier      $output = p_wiki_xhtml($ID,$REV,false);
469f6dad9fdSMichael Klier
470f6dad9fdSMichael Klier      $post .= '</div>' . DOKU_LF;
471f6dad9fdSMichael Klier      $post .= '</body>' . DOKU_LF;
472f6dad9fdSMichael Klier      $post .= '</html>' . DOKU_LF;
473f6dad9fdSMichael Klier      break;
474f6dad9fdSMichael Klier    case 'xhtmlbody':
475f6dad9fdSMichael Klier      $headers['Content-Type'] = 'text/html; charset=utf-8';
476f6dad9fdSMichael Klier      $output = p_wiki_xhtml($ID,$REV,false);
477f6dad9fdSMichael Klier      break;
478f6dad9fdSMichael Klier    default:
47985767031SAndreas Gohr      $headers = p_get_metadata($ID,"format $mode");
480f6dad9fdSMichael Klier      $output = p_cached_output(wikiFN($ID,$REV), $mode);
481f6dad9fdSMichael Klier      break;
482f6dad9fdSMichael Klier  }
483f6dad9fdSMichael Klier
484f6dad9fdSMichael Klier  // prepare event data
485f6dad9fdSMichael Klier  $data = array();
486f6dad9fdSMichael Klier  $data['id'] = $ID;
487f6dad9fdSMichael Klier  $data['mode'] = $mode;
488f6dad9fdSMichael Klier  $data['headers'] = $headers;
489f6dad9fdSMichael Klier  $data['output'] =& $output;
490f6dad9fdSMichael Klier
491f6dad9fdSMichael Klier  trigger_event('ACTION_EXPORT_POSTPROCESS', $data);
492f6dad9fdSMichael Klier
493f6dad9fdSMichael Klier  if(!empty($data['output'])){
494f6dad9fdSMichael Klier    if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){
49585767031SAndreas Gohr      header("$key: $val");
49685767031SAndreas Gohr    }
497f6dad9fdSMichael Klier    print $pre.$data['output'].$post;
4986b13307fSandi    exit;
4996b13307fSandi  }
5006b13307fSandi  return 'show';
5016b13307fSandi}
502340756e4Sandi
503b158d625SSteven Danz/**
50452b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe'
505b158d625SSteven Danz *
506b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com>
5071380fc45SAndreas Gohr * @todo   localize
508b158d625SSteven Danz */
5091380fc45SAndreas Gohrfunction act_subscription($act){
510b158d625SSteven Danz  global $ID;
511b158d625SSteven Danz  global $INFO;
512f9eb5648Ssteven-danz  global $lang;
513b158d625SSteven Danz
5141380fc45SAndreas Gohr  $file=metaFN($ID,'.mlist');
5151380fc45SAndreas Gohr  if ($act=='subscribe' && !$INFO['subscribed']){
516b158d625SSteven Danz    if ($INFO['userinfo']['mail']){
5171380fc45SAndreas Gohr      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
5181380fc45SAndreas Gohr        $INFO['subscribed'] = true;
519f9eb5648Ssteven-danz        msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
520b158d625SSteven Danz      } else {
521f9eb5648Ssteven-danz        msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
522b158d625SSteven Danz      }
523b158d625SSteven Danz    } else {
524f9eb5648Ssteven-danz      msg($lang['subscribe_noaddress']);
525b158d625SSteven Danz    }
5261380fc45SAndreas Gohr  } elseif ($act=='unsubscribe' && $INFO['subscribed']){
527b158d625SSteven Danz    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
5281380fc45SAndreas Gohr      $INFO['subscribed'] = false;
529f9eb5648Ssteven-danz      msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
530b158d625SSteven Danz    } else {
531f9eb5648Ssteven-danz      msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
532b158d625SSteven Danz    }
533b158d625SSteven Danz  }
534b158d625SSteven Danz
535b158d625SSteven Danz  return 'show';
536b158d625SSteven Danz}
537b158d625SSteven Danz
53852b0dd67SGuy Brand/**
53952b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe'
54052b0dd67SGuy Brand *
54152b0dd67SGuy Brand */
54252b0dd67SGuy Brandfunction act_subscriptionns($act){
54352b0dd67SGuy Brand  global $ID;
54452b0dd67SGuy Brand  global $INFO;
54552b0dd67SGuy Brand  global $lang;
54652b0dd67SGuy Brand
54752b0dd67SGuy Brand  if(!getNS($ID)) {
54852b0dd67SGuy Brand    $file = metaFN(getNS($ID),'.mlist');
549613964ecSGuy Brand    $ns = "root";
55052b0dd67SGuy Brand  } else {
55152b0dd67SGuy Brand    $file = metaFN(getNS($ID),'/.mlist');
552613964ecSGuy Brand    $ns = getNS($ID);
55352b0dd67SGuy Brand  }
55452b0dd67SGuy Brand
555613964ecSGuy Brand  // reuse strings used to display the status of the subscribe action
556613964ecSGuy Brand  $act_msg = rtrim($act, 'ns');
557613964ecSGuy Brand
55852b0dd67SGuy Brand  if ($act=='subscribens' && !$INFO['subscribedns']){
55952b0dd67SGuy Brand    if ($INFO['userinfo']['mail']){
56052b0dd67SGuy Brand      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
56152b0dd67SGuy Brand        $INFO['subscribedns'] = true;
562613964ecSGuy Brand        msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1);
56352b0dd67SGuy Brand      } else {
564613964ecSGuy Brand        msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1);
56552b0dd67SGuy Brand      }
56652b0dd67SGuy Brand    } else {
56752b0dd67SGuy Brand      msg($lang['subscribe_noaddress']);
56852b0dd67SGuy Brand    }
56952b0dd67SGuy Brand  } elseif ($act=='unsubscribens' && $INFO['subscribedns']){
57052b0dd67SGuy Brand    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
57152b0dd67SGuy Brand      $INFO['subscribedns'] = false;
572613964ecSGuy Brand      msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1);
57352b0dd67SGuy Brand    } else {
574613964ecSGuy Brand      msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1);
57552b0dd67SGuy Brand    }
57652b0dd67SGuy Brand  }
57752b0dd67SGuy Brand
57852b0dd67SGuy Brand  return 'show';
57952b0dd67SGuy Brand}
58052b0dd67SGuy Brand
581340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
582