xref: /dokuwiki/inc/common.php (revision e45b34cdb82ad8fad44374c0d8f1df64952dc3a7)
1<?php
2/**
3 * Common DokuWiki functions
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10  require_once(DOKU_CONF.'dokuwiki.php');
11  require_once(DOKU_INC.'inc/io.php');
12  require_once(DOKU_INC.'inc/utf8.php');
13  require_once(DOKU_INC.'inc/mail.php');
14  require_once(DOKU_INC.'inc/parserutils.php');
15
16/**
17 * These constants are used with the recents function
18 */
19define('RECENTS_SKIP_DELETED',2);
20define('RECENTS_SKIP_MINORS',4);
21define('RECENTS_SKIP_SUBSPACES',8);
22
23/**
24 * Wrapper around htmlspecialchars()
25 *
26 * @author Andreas Gohr <andi@splitbrain.org>
27 * @see    htmlspecialchars()
28 */
29function hsc($string){
30  return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
31}
32
33/**
34 * print a newline terminated string
35 *
36 * You can give an indention as optional parameter
37 *
38 * @author Andreas Gohr <andi@splitbrain.org>
39 */
40function ptln($string,$intend=0){
41  for($i=0; $i<$intend; $i++) print ' ';
42  print"$string\n";
43}
44
45/**
46 * Return info about the current document as associative
47 * array.
48 *
49 * @author Andreas Gohr <andi@splitbrain.org>
50 */
51function pageinfo(){
52  global $ID;
53  global $REV;
54  global $USERINFO;
55  global $conf;
56
57  if($_SERVER['REMOTE_USER']){
58    $info['userinfo']   = $USERINFO;
59    $info['perm']       = auth_quickaclcheck($ID);
60    $info['subscribed'] = is_subscribed($ID,$_SERVER['REMOTE_USER']);
61    $info['client']     = $_SERVER['REMOTE_USER'];
62
63    // if some outside auth were used only REMOTE_USER is set
64    if(!$info['userinfo']['name']){
65      $info['userinfo']['name'] = $_SERVER['REMOTE_USER'];
66    }
67
68  }else{
69    $info['perm']       = auth_aclcheck($ID,'',null);
70    $info['subscribed'] = false;
71    $info['client']     = clientIP(true);
72  }
73
74  $info['namespace'] = getNS($ID);
75  $info['locked']    = checklock($ID);
76  $info['filepath']  = realpath(wikiFN($ID,$REV));
77  $info['exists']    = @file_exists($info['filepath']);
78  if($REV && !$info['exists']){
79    //check if current revision was meant
80    $cur = wikiFN($ID);
81    if(@file_exists($cur) && (@filemtime($cur) == $REV)){
82      $info['filepath'] = realpath($cur);
83      $info['exists']   = true;
84      $REV = '';
85    }
86  }
87  $info['rev'] = $REV;
88  if($info['exists']){
89    $info['writable'] = (is_writable($info['filepath']) &&
90                         ($info['perm'] >= AUTH_EDIT));
91  }else{
92    $info['writable'] = ($info['perm'] >= AUTH_CREATE);
93  }
94  $info['editable']  = ($info['writable'] && empty($info['lock']));
95  $info['lastmod']   = @filemtime($info['filepath']);
96
97  //load page meta data
98  $info['meta'] = p_get_metadata($ID);
99
100  //who's the editor
101  if($REV){
102    $revinfo = getRevisionInfo($ID, $REV, 1024);
103  }else{
104    $revinfo = $info['meta']['last_change'];
105  }
106  $info['ip']     = $revinfo['ip'];
107  $info['user']   = $revinfo['user'];
108  $info['sum']    = $revinfo['sum'];
109  // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID.
110  // Use $INFO['meta']['last_change']['type']==='e' in place of $info['minor'].
111
112  if($revinfo['user']){
113    $info['editor'] = $revinfo['user'];
114  }else{
115    $info['editor'] = $revinfo['ip'];
116  }
117
118  // draft
119  $draft = getCacheName($info['client'].$ID,'.draft');
120  if(@file_exists($draft)){
121    if(@filemtime($draft) < @filemtime(wikiFN($ID))){
122      // remove stale draft
123      @unlink($draft);
124    }else{
125      $info['draft'] = $draft;
126    }
127  }
128
129  return $info;
130}
131
132/**
133 * Build an string of URL parameters
134 *
135 * @author Andreas Gohr
136 */
137function buildURLparams($params, $sep='&amp;'){
138  $url = '';
139  $amp = false;
140  foreach($params as $key => $val){
141    if($amp) $url .= $sep;
142
143    $url .= $key.'=';
144    $url .= rawurlencode($val);
145    $amp = true;
146  }
147  return $url;
148}
149
150/**
151 * Build an string of html tag attributes
152 *
153 * @author Andreas Gohr
154 */
155function buildAttributes($params){
156  $url = '';
157  foreach($params as $key => $val){
158    $url .= $key.'="';
159    $url .= htmlspecialchars ($val);
160    $url .= '" ';
161  }
162  return $url;
163}
164
165
166/**
167 * print a message
168 *
169 * If HTTP headers were not sent yet the message is added
170 * to the global message array else it's printed directly
171 * using html_msgarea()
172 *
173 *
174 * Levels can be:
175 *
176 * -1 error
177 *  0 info
178 *  1 success
179 *
180 * @author Andreas Gohr <andi@splitbrain.org>
181 * @see    html_msgarea
182 */
183function msg($message,$lvl=0,$line='',$file=''){
184  global $MSG;
185  $errors[-1] = 'error';
186  $errors[0]  = 'info';
187  $errors[1]  = 'success';
188
189  if($line || $file) $message.=' ['.basename($file).':'.$line.']';
190
191  if(!headers_sent()){
192    if(!isset($MSG)) $MSG = array();
193    $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
194  }else{
195    $MSG = array();
196    $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
197    if(function_exists('html_msgarea')){
198      html_msgarea();
199    }else{
200      print "ERROR($lvl) $message";
201    }
202  }
203}
204
205/**
206 * This builds the breadcrumb trail and returns it as array
207 *
208 * @author Andreas Gohr <andi@splitbrain.org>
209 */
210function breadcrumbs(){
211  // we prepare the breadcrumbs early for quick session closing
212  static $crumbs = null;
213  if($crumbs != null) return $crumbs;
214
215  global $ID;
216  global $ACT;
217  global $conf;
218  $crumbs = $_SESSION[$conf['title']]['bc'];
219
220  //first visit?
221  if (!is_array($crumbs)){
222    $crumbs = array();
223  }
224  //we only save on show and existing wiki documents
225  $file = wikiFN($ID);
226  if($ACT != 'show' || !@file_exists($file)){
227    $_SESSION[$conf['title']]['bc'] = $crumbs;
228    return $crumbs;
229  }
230
231  // page names
232  $name = noNS($ID);
233  if ($conf['useheading']) {
234    // get page title
235    $title = p_get_first_heading($ID);
236    if ($title) {
237      $name = $title;
238    }
239  }
240
241  //remove ID from array
242  if (isset($crumbs[$ID])) {
243    unset($crumbs[$ID]);
244  }
245
246  //add to array
247  $crumbs[$ID] = $name;
248  //reduce size
249  while(count($crumbs) > $conf['breadcrumbs']){
250    array_shift($crumbs);
251  }
252  //save to session
253  $_SESSION[$conf['title']]['bc'] = $crumbs;
254  return $crumbs;
255}
256
257/**
258 * Filter for page IDs
259 *
260 * This is run on a ID before it is outputted somewhere
261 * currently used to replace the colon with something else
262 * on Windows systems and to have proper URL encoding
263 *
264 * Urlencoding is ommitted when the second parameter is false
265 *
266 * @author Andreas Gohr <andi@splitbrain.org>
267 */
268function idfilter($id,$ue=true){
269  global $conf;
270  if ($conf['useslash'] && $conf['userewrite']){
271    $id = strtr($id,':','/');
272  }elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' &&
273      $conf['userewrite']) {
274    $id = strtr($id,':',';');
275  }
276  if($ue){
277    $id = rawurlencode($id);
278    $id = str_replace('%3A',':',$id); //keep as colon
279    $id = str_replace('%2F','/',$id); //keep as slash
280  }
281  return $id;
282}
283
284/**
285 * This builds a link to a wikipage
286 *
287 * It handles URL rewriting and adds additional parameter if
288 * given in $more
289 *
290 * @author Andreas Gohr <andi@splitbrain.org>
291 */
292function wl($id='',$more='',$abs=false,$sep='&amp;'){
293  global $conf;
294  if(is_array($more)){
295    $more = buildURLparams($more,$sep);
296  }else{
297    $more = str_replace(',',$sep,$more);
298  }
299
300  $id    = idfilter($id);
301  if($abs){
302    $xlink = DOKU_URL;
303  }else{
304    $xlink = DOKU_BASE;
305  }
306
307  if($conf['userewrite'] == 2){
308    $xlink .= DOKU_SCRIPT.'/'.$id;
309    if($more) $xlink .= '?'.$more;
310  }elseif($conf['userewrite']){
311    $xlink .= $id;
312    if($more) $xlink .= '?'.$more;
313  }else{
314    $xlink .= DOKU_SCRIPT.'?id='.$id;
315    if($more) $xlink .= $sep.$more;
316  }
317
318  return $xlink;
319}
320
321/**
322 * This builds a link to an alternate page format
323 *
324 * Handles URL rewriting if enabled. Follows the style of wl().
325 *
326 * @author Ben Coburn <btcoburn@silicodon.net>
327 */
328function exportlink($id='',$format='raw',$more='',$abs=false,$sep='&amp;'){
329  global $conf;
330  if(is_array($more)){
331    $more = buildURLparams($more,$sep);
332  }else{
333    $more = str_replace(',',$sep,$more);
334  }
335
336  $format = rawurlencode($format);
337  $id = idfilter($id);
338  if($abs){
339    $xlink = DOKU_URL;
340  }else{
341    $xlink = DOKU_BASE;
342  }
343
344  if($conf['userewrite'] == 2){
345    $xlink .= DOKU_SCRIPT.'/'.$id.'?do=export_'.$format;
346    if($more) $xlink .= $sep.$more;
347  }elseif($conf['userewrite'] == 1){
348    $xlink .= '_export/'.$format.'/'.$id;
349    if($more) $xlink .= '?'.$more;
350  }else{
351    $xlink .= DOKU_SCRIPT.'?do=export_'.$format.$sep.'id='.$id;
352    if($more) $xlink .= $sep.$more;
353  }
354
355  return $xlink;
356}
357
358/**
359 * Build a link to a media file
360 *
361 * Will return a link to the detail page if $direct is false
362 */
363function ml($id='',$more='',$direct=true,$sep='&amp;'){
364  global $conf;
365  if(is_array($more)){
366    $more = buildURLparams($more,$sep);
367  }else{
368    $more = str_replace(',',$sep,$more);
369  }
370
371  $xlink = DOKU_BASE;
372
373  // external URLs are always direct without rewriting
374  if(preg_match('#^(https?|ftp)://#i',$id)){
375    $xlink .= 'lib/exe/fetch.php';
376    if($more){
377      $xlink .= '?'.$more;
378      $xlink .= $sep.'media='.rawurlencode($id);
379    }else{
380      $xlink .= '?media='.rawurlencode($id);
381    }
382    return $xlink;
383  }
384
385  $id = idfilter($id);
386
387  // decide on scriptname
388  if($direct){
389    if($conf['userewrite'] == 1){
390      $script = '_media';
391    }else{
392      $script = 'lib/exe/fetch.php';
393    }
394  }else{
395    if($conf['userewrite'] == 1){
396      $script = '_detail';
397    }else{
398      $script = 'lib/exe/detail.php';
399    }
400  }
401
402  // build URL based on rewrite mode
403   if($conf['userewrite']){
404     $xlink .= $script.'/'.$id;
405     if($more) $xlink .= '?'.$more;
406   }else{
407     if($more){
408       $xlink .= $script.'?'.$more;
409       $xlink .= $sep.'media='.$id;
410     }else{
411       $xlink .= $script.'?media='.$id;
412     }
413   }
414
415  return $xlink;
416}
417
418
419
420/**
421 * Just builds a link to a script
422 *
423 * @todo   maybe obsolete
424 * @author Andreas Gohr <andi@splitbrain.org>
425 */
426function script($script='doku.php'){
427#  $link = getBaseURL();
428#  $link .= $script;
429#  return $link;
430  return DOKU_BASE.DOKU_SCRIPT;
431}
432
433/**
434 * Spamcheck against wordlist
435 *
436 * Checks the wikitext against a list of blocked expressions
437 * returns true if the text contains any bad words
438 *
439 * @author Andreas Gohr <andi@splitbrain.org>
440 */
441function checkwordblock(){
442  global $TEXT;
443  global $conf;
444
445  if(!$conf['usewordblock']) return false;
446
447  $wordblocks = getWordblocks();
448  //how many lines to read at once (to work around some PCRE limits)
449  if(version_compare(phpversion(),'4.3.0','<')){
450    //old versions of PCRE define a maximum of parenthesises even if no
451    //backreferences are used - the maximum is 99
452    //this is very bad performancewise and may even be too high still
453    $chunksize = 40;
454  }else{
455    //read file in chunks of 600 - this should work around the
456    //MAX_PATTERN_SIZE in modern PCRE
457    $chunksize = 400;
458  }
459  while($blocks = array_splice($wordblocks,0,$chunksize)){
460    $re = array();
461    #build regexp from blocks
462    foreach($blocks as $block){
463      $block = preg_replace('/#.*$/','',$block);
464      $block = trim($block);
465      if(empty($block)) continue;
466      $re[]  = $block;
467    }
468    if(preg_match('#('.join('|',$re).')#si',$TEXT, $match=array())) {
469      return true;
470    }
471  }
472  return false;
473}
474
475/**
476 * Return the IP of the client
477 *
478 * Honours X-Forwarded-For and X-Real-IP Proxy Headers
479 *
480 * It returns a comma separated list of IPs if the above mentioned
481 * headers are set. If the single parameter is set, it tries to return
482 * a routable public address, prefering the ones suplied in the X
483 * headers
484 *
485 * @param  boolean $single If set only a single IP is returned
486 * @author Andreas Gohr <andi@splitbrain.org>
487 */
488function clientIP($single=false){
489  $ip = array();
490  $ip[] = $_SERVER['REMOTE_ADDR'];
491  if($_SERVER['HTTP_X_FORWARDED_FOR'])
492    $ip = array_merge($ip,explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']));
493  if($_SERVER['HTTP_X_REAL_IP'])
494    $ip = array_merge($ip,explode(',',$_SERVER['HTTP_X_REAL_IP']));
495
496  // remove any non-IP stuff
497  $cnt = count($ip);
498  $match = array();
499  for($i=0; $i<$cnt; $i++){
500    if(preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/',$ip[$i],$match)) {
501      $ip[$i] = $match[0];
502    } else {
503      $ip[$i] = '';
504    }
505    if(empty($ip[$i])) unset($ip[$i]);
506  }
507  $ip = array_values(array_unique($ip));
508  if(!$ip[0]) $ip[0] = '0.0.0.0'; // for some strange reason we don't have a IP
509
510  if(!$single) return join(',',$ip);
511
512  // decide which IP to use, trying to avoid local addresses
513  $ip = array_reverse($ip);
514  foreach($ip as $i){
515    if(preg_match('/^(127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)/',$i)){
516      continue;
517    }else{
518      return $i;
519    }
520  }
521  // still here? just use the first (last) address
522  return $ip[0];
523}
524
525/**
526 * Checks if a given page is currently locked.
527 *
528 * removes stale lockfiles
529 *
530 * @author Andreas Gohr <andi@splitbrain.org>
531 */
532function checklock($id){
533  global $conf;
534  $lock = wikiLockFN($id);
535
536  //no lockfile
537  if(!@file_exists($lock)) return false;
538
539  //lockfile expired
540  if((time() - filemtime($lock)) > $conf['locktime']){
541    @unlink($lock);
542    return false;
543  }
544
545  //my own lock
546  $ip = io_readFile($lock);
547  if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){
548    return false;
549  }
550
551  return $ip;
552}
553
554/**
555 * Lock a page for editing
556 *
557 * @author Andreas Gohr <andi@splitbrain.org>
558 */
559function lock($id){
560  $lock = wikiLockFN($id);
561  if($_SERVER['REMOTE_USER']){
562    io_saveFile($lock,$_SERVER['REMOTE_USER']);
563  }else{
564    io_saveFile($lock,clientIP());
565  }
566}
567
568/**
569 * Unlock a page if it was locked by the user
570 *
571 * @author Andreas Gohr <andi@splitbrain.org>
572 * @return bool true if a lock was removed
573 */
574function unlock($id){
575  $lock = wikiLockFN($id);
576  if(@file_exists($lock)){
577    $ip = io_readFile($lock);
578    if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){
579      @unlink($lock);
580      return true;
581    }
582  }
583  return false;
584}
585
586/**
587 * convert line ending to unix format
588 *
589 * @see    formText() for 2crlf conversion
590 * @author Andreas Gohr <andi@splitbrain.org>
591 */
592function cleanText($text){
593  $text = preg_replace("/(\015\012)|(\015)/","\012",$text);
594  return $text;
595}
596
597/**
598 * Prepares text for print in Webforms by encoding special chars.
599 * It also converts line endings to Windows format which is
600 * pseudo standard for webforms.
601 *
602 * @see    cleanText() for 2unix conversion
603 * @author Andreas Gohr <andi@splitbrain.org>
604 */
605function formText($text){
606  $text = preg_replace("/\012/","\015\012",$text);
607  return htmlspecialchars($text);
608}
609
610/**
611 * Returns the specified local text in raw format
612 *
613 * @author Andreas Gohr <andi@splitbrain.org>
614 */
615function rawLocale($id){
616  return io_readFile(localeFN($id));
617}
618
619/**
620 * Returns the raw WikiText
621 *
622 * @author Andreas Gohr <andi@splitbrain.org>
623 */
624function rawWiki($id,$rev=''){
625  return io_readWikiPage(wikiFN($id, $rev), $id, $rev);
626}
627
628/**
629 * Returns the pagetemplate contents for the ID's namespace
630 *
631 * @author Andreas Gohr <andi@splitbrain.org>
632 */
633function pageTemplate($id){
634  global $conf;
635  global $INFO;
636  $tpl = io_readFile(dirname(wikiFN($id)).'/_template.txt');
637  $tpl = str_replace('@ID@',$id,$tpl);
638  $tpl = str_replace('@NS@',getNS($id),$tpl);
639  $tpl = str_replace('@PAGE@',strtr(noNS($id),'_',' '),$tpl);
640  $tpl = str_replace('@USER@',$_SERVER['REMOTE_USER'],$tpl);
641  $tpl = str_replace('@NAME@',$INFO['userinfo']['name'],$tpl);
642  $tpl = str_replace('@MAIL@',$INFO['userinfo']['mail'],$tpl);
643  $tpl = str_replace('@DATE@',date($conf['dformat']),$tpl);
644  return $tpl;
645}
646
647
648/**
649 * Returns the raw Wiki Text in three slices.
650 *
651 * The range parameter needs to have the form "from-to"
652 * and gives the range of the section in bytes - no
653 * UTF-8 awareness is needed.
654 * The returned order is prefix, section and suffix.
655 *
656 * @author Andreas Gohr <andi@splitbrain.org>
657 */
658function rawWikiSlices($range,$id,$rev=''){
659  list($from,$to) = split('-',$range,2);
660  $text = io_readWikiPage(wikiFN($id, $rev), $id, $rev);
661  if(!$from) $from = 0;
662  if(!$to)   $to   = strlen($text)+1;
663
664  $slices[0] = substr($text,0,$from-1);
665  $slices[1] = substr($text,$from-1,$to-$from);
666  $slices[2] = substr($text,$to);
667
668  return $slices;
669}
670
671/**
672 * Joins wiki text slices
673 *
674 * function to join the text slices with correct lineendings again.
675 * When the pretty parameter is set to true it adds additional empty
676 * lines between sections if needed (used on saving).
677 *
678 * @author Andreas Gohr <andi@splitbrain.org>
679 */
680function con($pre,$text,$suf,$pretty=false){
681
682  if($pretty){
683    if($pre && substr($pre,-1) != "\n") $pre .= "\n";
684    if($suf && substr($text,-1) != "\n") $text .= "\n";
685  }
686
687  if($pre) $pre .= "\n";
688  if($suf) $text .= "\n";
689  return $pre.$text.$suf;
690}
691
692/**
693 * print debug messages
694 *
695 * little function to print the content of a var
696 *
697 * @author Andreas Gohr <andi@splitbrain.org>
698 */
699function dbg($msg,$hidden=false){
700  (!$hidden) ? print '<pre class="dbg">' : print "<!--\n";
701  print_r($msg);
702  (!$hidden) ? print '</pre>' : print "\n-->";
703}
704
705/**
706 * Print info to a log file
707 *
708 * @author Andreas Gohr <andi@splitbrain.org>
709 */
710function dbglog($msg){
711  global $conf;
712  $file = $conf['cachedir'].'/debug.log';
713  $fh = fopen($file,'a');
714  if($fh){
715    fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n");
716    fclose($fh);
717  }
718}
719
720/**
721 * Add's an entry to the changelog and saves the metadata for the page
722 *
723 * @author Andreas Gohr <andi@splitbrain.org>
724 * @author Esther Brunner <wikidesign@gmail.com>
725 * @author Ben Coburn <btcoburn@silicodon.net>
726 */
727function addLogEntry($date, $id, $type='E', $summary='', $extra=''){
728  global $conf, $INFO;
729
730  $id = cleanid($id);
731  $file = wikiFN($id);
732  $created = @filectime($file);
733  $minor = ($type==='e');
734  $wasRemoved = ($type==='D');
735
736  if(!$date) $date = time(); //use current time if none supplied
737  $remote = $_SERVER['REMOTE_ADDR'];
738  $user   = $_SERVER['REMOTE_USER'];
739
740  $strip = array("\t", "\n");
741  $logline = array(
742    'date'  => $date,
743    'ip'    => $remote,
744    'type'  => str_replace($strip, '', $type),
745    'id'    => $id,
746    'user'  => $user,
747    'sum'   => str_replace($strip, '', $summary),
748    'extra' => str_replace($strip, '', $extra)
749  );
750
751  // update metadata
752  if (!$wasRemoved) {
753    $meta = array();
754    if (!$INFO['exists']){ // newly created
755      $meta['date']['created'] = $created;
756      if ($user) $meta['creator'] = $INFO['userinfo']['name'];
757    } elseif (!$minor) {   // non-minor modification
758      $meta['date']['modified'] = $date;
759      if ($user) $meta['contributor'][$user] = $INFO['userinfo']['name'];
760    }
761    $meta['last_change'] = $logline;
762    p_set_metadata($id, $meta, true);
763  }
764
765  // add changelog lines
766  $logline = implode("\t", $logline)."\n";
767  io_saveFile(metaFN($id,'.changes'),$logline,true); //page changelog
768  io_saveFile($conf['changelog'],$logline,true); //global changelog cache
769}
770
771/**
772 * Internal function used by getRecents
773 *
774 * don't call directly
775 *
776 * @see getRecents()
777 * @author Andreas Gohr <andi@splitbrain.org>
778 * @author Ben Coburn <btcoburn@silicodon.net>
779 */
780function _handleRecent($line,$ns,$flags){
781  static $seen  = array();         //caches seen pages and skip them
782  if(empty($line)) return false;   //skip empty lines
783
784  // split the line into parts
785  $recent = parseChangelogLine($line);
786  if ($recent===false) { return false; }
787
788  // skip seen ones
789  if(isset($seen[$recent['id']])) return false;
790
791  // skip minors
792  if($recent['type']==='e' && ($flags & RECENTS_SKIP_MINORS)) return false;
793
794  // remember in seen to skip additional sights
795  $seen[$recent['id']] = 1;
796
797  // check if it's a hidden page
798  if(isHiddenPage($recent['id'])) return false;
799
800  // filter namespace
801  if (($ns) && (strpos($recent['id'],$ns.':') !== 0)) return false;
802
803  // exclude subnamespaces
804  if (($flags & RECENTS_SKIP_SUBSPACES) && (getNS($recent['id']) != $ns)) return false;
805
806  // check ACL
807  if (auth_quickaclcheck($recent['id']) < AUTH_READ) return false;
808
809  // check existance
810  if((!@file_exists(wikiFN($recent['id']))) && ($flags & RECENTS_SKIP_DELETED)) return false;
811
812  return $recent;
813}
814
815
816/**
817 * returns an array of recently changed files using the
818 * changelog
819 *
820 * The following constants can be used to control which changes are
821 * included. Add them together as needed.
822 *
823 * RECENTS_SKIP_DELETED   - don't include deleted pages
824 * RECENTS_SKIP_MINORS    - don't include minor changes
825 * RECENTS_SKIP_SUBSPACES - don't include subspaces
826 *
827 * @param int    $first   number of first entry returned (for paginating
828 * @param int    $num     return $num entries
829 * @param string $ns      restrict to given namespace
830 * @param bool   $flags   see above
831 *
832 * @author Ben Coburn <btcoburn@silicodon.net>
833 */
834function getRecents($first,$num,$ns='',$flags=0){
835  global $conf;
836  $recent = array();
837  $count  = 0;
838
839  if(!$num)
840    return $recent;
841
842  // read all recent changes. (kept short)
843  $lines = file($conf['changelog']);
844
845  // handle lines
846  for($i = count($lines)-1; $i >= 0; $i--){
847    $rec = _handleRecent($lines[$i], $ns, $flags);
848    if($rec !== false) {
849      if(--$first >= 0) continue; // skip first entries
850      $recent[] = $rec;
851      $count++;
852      // break when we have enough entries
853      if($count >= $num){ break; }
854    }
855  }
856
857  return $recent;
858}
859
860/**
861 * parses a changelog line into it's components
862 *
863 * @author Ben Coburn <btcoburn@silicodon.net>
864 */
865function parseChangelogLine($line) {
866  $tmp = explode("\t", $line);
867    if ($tmp!==false && count($tmp)>1) {
868      $info = array();
869      $info['date']  = $tmp[0]; // unix timestamp
870      $info['ip']    = $tmp[1]; // IPv4 address (127.0.0.1)
871      $info['type']  = $tmp[2]; // log line type
872      $info['id']    = $tmp[3]; // page id
873      $info['user']  = $tmp[4]; // user name
874      $info['sum']   = $tmp[5]; // edit summary (or action reason)
875      $info['extra'] = rtrim($tmp[6], "\n"); // extra data (varies by line type)
876      return $info;
877  } else { return false; }
878}
879
880/**
881 * Get the changelog information for a specific page id
882 * and revision (timestamp). Adjacent changelog lines
883 * are optimistically parsed and cached to speed up
884 * consecutive calls to getRevisionInfo. For large
885 * changelog files, only the chunk containing the
886 * requested changelog line is read.
887 *
888 * @author Ben Coburn <btcoburn@silicodon.net>
889 */
890function getRevisionInfo($id, $rev, $chunk_size=8192) {
891  global $cache_revinfo;
892  $cache =& $cache_revinfo;
893  if (!isset($cache[$id])) { $cache[$id] = array(); }
894  $rev = max($rev, 0);
895
896  // check if it's already in the memory cache
897  if (isset($cache[$id]) && isset($cache[$id][$rev])) {
898    return $cache[$id][$rev];
899  }
900
901  $file = metaFN($id, '.changes');
902  if (!@file_exists($file)) { return false; }
903  if (filesize($file)<$chunk_size || $chunk_size==0) {
904    // read whole file
905    $lines = file($file);
906    if ($lines===false) { return false; }
907  } else {
908    // read by chunk
909    $fp = fopen($file, 'rb'); // "file pointer"
910    if ($fp===false) { return false; }
911    $head = 0;
912    fseek($fp, 0, SEEK_END);
913    $tail = ftell($fp);
914    $finger = 0;
915    $finger_rev = 0;
916
917    // find chunk
918    while ($tail-$head>$chunk_size) {
919      $finger = $head+floor(($tail-$head)/2.0);
920      fseek($fp, $finger);
921      fgets($fp); // slip the finger forward to a new line
922      $finger = ftell($fp);
923      $tmp = fgets($fp); // then read at that location
924      $tmp = parseChangelogLine($tmp);
925      $finger_rev = $tmp['date'];
926      if ($finger==$head || $finger==$tail) { break; }
927      if ($finger_rev>$rev) {
928        $tail = $finger;
929      } else {
930        $head = $finger;
931      }
932    }
933
934    if ($tail-$head<1) {
935      // cound not find chunk, assume requested rev is missing
936      fclose($fp);
937      return false;
938    }
939
940    // read chunk
941    $chunk = '';
942    $chunk_size = max($tail-$head, 0); // found chunk size
943    $got = 0;
944    fseek($fp, $head);
945    while ($got<$chunk_size && !feof($fp)) {
946      $tmp = fread($fp, max($chunk_size-$got, 0));
947      if ($tmp===false) { break; } //error state
948      $got += strlen($tmp);
949      $chunk .= $tmp;
950    }
951    $lines = explode("\n", $chunk);
952    array_pop($lines); // remove trailing newline
953    fclose($fp);
954  }
955
956  // parse and cache changelog lines
957  foreach ($lines as $value) {
958    $tmp = parseChangelogLine($value);
959    if ($tmp!==false) {
960      $cache[$id][$tmp['date']] = $tmp;
961    }
962  }
963  if (!isset($cache[$id][$rev])) { return false; }
964  return $cache[$id][$rev];
965}
966
967/**
968 * Return a list of page revisions numbers
969 * Does not guarantee that the revision exists in the attic,
970 * only that a line with the date exists in the changelog.
971 * By default the current revision is skipped.
972 *
973 * id:    the page of interest
974 * first: skip the first n changelog lines
975 * num:   number of revisions to return
976 *
977 * The current revision is automatically skipped when the page exists.
978 * See $INFO['meta']['last_change'] for the current revision.
979 *
980 * For efficiency, the log lines are parsed and cached for later
981 * calls to getRevisionInfo. Large changelog files are read
982 * backwards in chunks untill the requested number of changelog
983 * lines are recieved.
984 *
985 * @author Ben Coburn <btcoburn@silicodon.net>
986 */
987function getRevisions($id, $first, $num, $chunk_size=8192) {
988  global $cache_revinfo;
989  $cache =& $cache_revinfo;
990  if (!isset($cache[$id])) { $cache[$id] = array(); }
991
992  $revs = array();
993  $lines = array();
994  $count  = 0;
995  $file = metaFN($id, '.changes');
996  $num = max($num, 0);
997  $chunk_size = max($chunk_size, 0);
998  if ($first<0) { $first = 0; }
999  else if (@file_exists(wikiFN($id))) {
1000     // skip current revision if the page exists
1001    $first = max($first+1, 0);
1002  }
1003
1004  if (!@file_exists($file)) { return $revs; }
1005  if (filesize($file)<$chunk_size || $chunk_size==0) {
1006    // read whole file
1007    $lines = file($file);
1008    if ($lines===false) { return $revs; }
1009  } else {
1010    // read chunks backwards
1011    $fp = fopen($file, 'rb'); // "file pointer"
1012    if ($fp===false) { return $revs; }
1013    fseek($fp, 0, SEEK_END);
1014    $tail = ftell($fp);
1015
1016    // chunk backwards
1017    $finger = max($tail-$chunk_size, 0);
1018    while ($count<$num+$first) {
1019      fseek($fp, $finger);
1020      if ($finger>0) {
1021        fgets($fp); // slip the finger forward to a new line
1022        $finger = ftell($fp);
1023      }
1024
1025      // read chunk
1026      if ($tail<=$finger) { break; }
1027      $chunk = '';
1028      $read_size = max($tail-$finger, 0); // found chunk size
1029      $got = 0;
1030      while ($got<$read_size && !feof($fp)) {
1031        $tmp = fread($fp, max($read_size-$got, 0));
1032        if ($tmp===false) { break; } //error state
1033        $got += strlen($tmp);
1034        $chunk .= $tmp;
1035      }
1036      $tmp = explode("\n", $chunk);
1037      array_pop($tmp); // remove trailing newline
1038
1039      // combine with previous chunk
1040      $count += count($tmp);
1041      $lines = array_merge($tmp, $lines);
1042
1043      // next chunk
1044      if ($finger==0) { break; } // already read all the lines
1045      else {
1046        $tail = $finger;
1047        $finger = max($tail-$chunk_size, 0);
1048      }
1049    }
1050    fclose($fp);
1051  }
1052
1053  // skip parsing extra lines
1054  $num = max(min(count($lines)-$first, $num), 0);
1055  if      ($first>0 && $num>0)  { $lines = array_slice($lines, max(count($lines)-$first-$num, 0), $num); }
1056  else if ($first>0 && $num==0) { $lines = array_slice($lines, 0, max(count($lines)-$first, 0)); }
1057  else if ($first==0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$num, 0)); }
1058
1059  // handle lines in reverse order
1060  for ($i = count($lines)-1; $i >= 0; $i--) {
1061    $tmp = parseChangelogLine($lines[$i]);
1062    if ($tmp!==false) {
1063      $cache[$id][$tmp['date']] = $tmp;
1064      $revs[] = $tmp['date'];
1065    }
1066  }
1067
1068  return $revs;
1069}
1070
1071/**
1072 * Saves a wikitext by calling io_writeWikiPage
1073 *
1074 * @author Andreas Gohr <andi@splitbrain.org>
1075 * @author Ben Coburn <btcoburn@silicodon.net>
1076 */
1077function saveWikiText($id,$text,$summary,$minor=false){
1078  global $conf;
1079  global $lang;
1080  global $REV;
1081  // ignore if no changes were made
1082  if($text == rawWiki($id,'')){
1083    return;
1084  }
1085
1086  $file = wikiFN($id);
1087  $old  = saveOldRevision($id);
1088  $wasRemoved = empty($text);
1089  $wasCreated = !@file_exists($file);
1090  $wasReverted = ($REV==true);
1091  $newRev = false;
1092
1093  if ($wasRemoved){
1094    // pre-save deleted revision
1095    @touch($file);
1096    $newRev = saveOldRevision($id);
1097    // remove empty file
1098    @unlink($file);
1099    // remove old meta info...
1100    $mfiles = metaFiles($id);
1101    $changelog = metaFN($id, '.changes');
1102    foreach ($mfiles as $mfile) {
1103      // but keep per-page changelog to preserve page history
1104      if (@file_exists($mfile) && $mfile!==$changelog) { @unlink($mfile); }
1105    }
1106    $del = true;
1107    // autoset summary on deletion
1108    if(empty($summary)) $summary = $lang['deleted'];
1109    // remove empty namespaces
1110    io_sweepNS($id, 'datadir');
1111    io_sweepNS($id, 'mediadir');
1112  }else{
1113    // save file (namespace dir is created in io_writeWikiPage)
1114    io_writeWikiPage($file, $text, $id);
1115    $newRev = @filemtime($file);
1116    $del = false;
1117  }
1118
1119  // select changelog line type
1120  $extra = '';
1121  $type = 'E';
1122  if ($wasReverted) {
1123    $type = 'R';
1124    $extra = $REV;
1125  }
1126  else if ($wasCreated) { $type = 'C'; }
1127  else if ($wasRemoved) { $type = 'D'; }
1128  else if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = 'e'; } //minor edits only for logged in users
1129
1130  addLogEntry($newRev, $id, $type, $summary, $extra);
1131  // send notify mails
1132  notify($id,'admin',$old,$summary,$minor);
1133  notify($id,'subscribers',$old,$summary,$minor);
1134
1135  //purge cache on add by updating the purgefile
1136  if($conf['purgeonadd'] && (!$old || $del)){
1137    io_saveFile($conf['cachedir'].'/purgefile',time());
1138  }
1139}
1140
1141/**
1142 * moves the current version to the attic and returns its
1143 * revision date
1144 *
1145 * @author Andreas Gohr <andi@splitbrain.org>
1146 */
1147function saveOldRevision($id){
1148  global $conf;
1149  $oldf = wikiFN($id);
1150  if(!@file_exists($oldf)) return '';
1151  $date = filemtime($oldf);
1152  $newf = wikiFN($id,$date);
1153  io_writeWikiPage($newf, rawWiki($id), $id, $date);
1154  return $date;
1155}
1156
1157/**
1158 * Sends a notify mail on page change
1159 *
1160 * @param  string  $id       The changed page
1161 * @param  string  $who      Who to notify (admin|subscribers)
1162 * @param  int     $rev      Old page revision
1163 * @param  string  $summary  What changed
1164 * @param  boolean $minor    Is this a minor edit?
1165 * @param  array   $replace  Additional string substitutions, @KEY@ to be replaced by value
1166 *
1167 * @author Andreas Gohr <andi@splitbrain.org>
1168 */
1169function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
1170  global $lang;
1171  global $conf;
1172
1173  // decide if there is something to do
1174  if($who == 'admin'){
1175    if(empty($conf['notify'])) return; //notify enabled?
1176    $text = rawLocale('mailtext');
1177    $to   = $conf['notify'];
1178    $bcc  = '';
1179  }elseif($who == 'subscribers'){
1180    if(!$conf['subscribers']) return; //subscribers enabled?
1181    if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return; //skip minors
1182    $bcc  = subscriber_addresslist($id);
1183    if(empty($bcc)) return;
1184    $to   = '';
1185    $text = rawLocale('subscribermail');
1186  }elseif($who == 'register'){
1187    if(empty($conf['registernotify'])) return;
1188    $text = rawLocale('registermail');
1189    $to   = $conf['registernotify'];
1190    $bcc  = '';
1191  }else{
1192    return; //just to be safe
1193  }
1194
1195  $text = str_replace('@DATE@',date($conf['dformat']),$text);
1196  $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text);
1197  $text = str_replace('@IPADDRESS@',$_SERVER['REMOTE_ADDR'],$text);
1198  $text = str_replace('@HOSTNAME@',gethostbyaddr($_SERVER['REMOTE_ADDR']),$text);
1199  $text = str_replace('@NEWPAGE@',wl($id,'',true),$text);
1200  $text = str_replace('@PAGE@',$id,$text);
1201  $text = str_replace('@TITLE@',$conf['title'],$text);
1202  $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
1203  $text = str_replace('@SUMMARY@',$summary,$text);
1204  $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text);
1205
1206  foreach ($replace as $key => $substitution) {
1207    $text = str_replace('@'.strtoupper($key).'@',$substitution, $text);
1208  }
1209
1210  if($who == 'register'){
1211    $subject = $lang['mail_new_user'].' '.$summary;
1212  }elseif($rev){
1213    $subject = $lang['mail_changed'].' '.$id;
1214    $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",true),$text);
1215    require_once(DOKU_INC.'inc/DifferenceEngine.php');
1216    $df  = new Diff(split("\n",rawWiki($id,$rev)),
1217                    split("\n",rawWiki($id)));
1218    $dformat = new UnifiedDiffFormatter();
1219    $diff    = $dformat->format($df);
1220  }else{
1221    $subject=$lang['mail_newpage'].' '.$id;
1222    $text = str_replace('@OLDPAGE@','none',$text);
1223    $diff = rawWiki($id);
1224  }
1225  $text = str_replace('@DIFF@',$diff,$text);
1226  $subject = '['.$conf['title'].'] '.$subject;
1227
1228  mail_send($to,$subject,$text,$conf['mailfrom'],'',$bcc);
1229}
1230
1231/**
1232 * extracts the query from a google referer
1233 *
1234 * @todo   should be more generic and support yahoo et al
1235 * @author Andreas Gohr <andi@splitbrain.org>
1236 */
1237function getGoogleQuery(){
1238  $url = parse_url($_SERVER['HTTP_REFERER']);
1239  if(!$url) return '';
1240
1241  if(!preg_match("#google\.#i",$url['host'])) return '';
1242  $query = array();
1243  parse_str($url['query'],$query);
1244
1245  return $query['q'];
1246}
1247
1248/**
1249 * Try to set correct locale
1250 *
1251 * @deprecated No longer used
1252 * @author     Andreas Gohr <andi@splitbrain.org>
1253 */
1254function setCorrectLocale(){
1255  global $conf;
1256  global $lang;
1257
1258  $enc = strtoupper($lang['encoding']);
1259  foreach ($lang['locales'] as $loc){
1260    //try locale
1261    if(@setlocale(LC_ALL,$loc)) return;
1262    //try loceale with encoding
1263    if(@setlocale(LC_ALL,"$loc.$enc")) return;
1264  }
1265  //still here? try to set from environment
1266  @setlocale(LC_ALL,"");
1267}
1268
1269/**
1270 * Return the human readable size of a file
1271 *
1272 * @param       int    $size   A file size
1273 * @param       int    $dec    A number of decimal places
1274 * @author      Martin Benjamin <b.martin@cybernet.ch>
1275 * @author      Aidan Lister <aidan@php.net>
1276 * @version     1.0.0
1277 */
1278function filesize_h($size, $dec = 1){
1279  $sizes = array('B', 'KB', 'MB', 'GB');
1280  $count = count($sizes);
1281  $i = 0;
1282
1283  while ($size >= 1024 && ($i < $count - 1)) {
1284    $size /= 1024;
1285    $i++;
1286  }
1287
1288  return round($size, $dec) . ' ' . $sizes[$i];
1289}
1290
1291/**
1292 * return an obfuscated email address in line with $conf['mailguard'] setting
1293 *
1294 * @author Harry Fuecks <hfuecks@gmail.com>
1295 * @author Christopher Smith <chris@jalakai.co.uk>
1296 */
1297function obfuscate($email) {
1298  global $conf;
1299
1300  switch ($conf['mailguard']) {
1301    case 'visible' :
1302      $obfuscate = array('@' => ' [at] ', '.' => ' [dot] ', '-' => ' [dash] ');
1303      return strtr($email, $obfuscate);
1304
1305    case 'hex' :
1306      $encode = '';
1307      for ($x=0; $x < strlen($email); $x++) $encode .= '&#x' . bin2hex($email{$x}).';';
1308      return $encode;
1309
1310    case 'none' :
1311    default :
1312      return $email;
1313  }
1314}
1315
1316/**
1317 * Return DokuWikis version
1318 *
1319 * @author Andreas Gohr <andi@splitbrain.org>
1320 */
1321function getVersion(){
1322  //import version string
1323  if(@file_exists('VERSION')){
1324    //official release
1325    return 'Release '.trim(io_readfile(DOKU_INC.'/VERSION'));
1326  }elseif(is_dir('_darcs')){
1327    //darcs checkout
1328    $inv = file('_darcs/inventory');
1329    $inv = preg_grep('#\*\*\d{14}[\]$]#',$inv);
1330    $cur = array_pop($inv);
1331    preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
1332    return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
1333  }else{
1334    return 'snapshot?';
1335  }
1336}
1337
1338/**
1339 * Run a few sanity checks
1340 *
1341 * @author Andreas Gohr <andi@splitbrain.org>
1342 */
1343function check(){
1344  global $conf;
1345  global $INFO;
1346
1347  msg('DokuWiki version: '.getVersion(),1);
1348
1349  if(version_compare(phpversion(),'4.3.0','<')){
1350    msg('Your PHP version is too old ('.phpversion().' vs. 4.3.+ recommended)',-1);
1351  }elseif(version_compare(phpversion(),'4.3.10','<')){
1352    msg('Consider upgrading PHP to 4.3.10 or higher for security reasons (your version: '.phpversion().')',0);
1353  }else{
1354    msg('PHP version '.phpversion(),1);
1355  }
1356
1357  if(is_writable($conf['changelog'])){
1358    msg('Changelog is writable',1);
1359  }else{
1360    if (@file_exists($conf['changelog'])) {
1361      msg('Changelog is not writable',-1);
1362    }
1363  }
1364
1365  if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
1366    msg('Old changelog exists.', 0);
1367  }
1368
1369  if (@file_exists($conf['changelog'].'_failed')) {
1370    msg('Importing old changelog failed.', -1);
1371  } else if (@file_exists($conf['changelog'].'_importing')) {
1372    msg('Importing old changelog now.', 0);
1373  } else if (@file_exists($conf['changelog'].'_import_ok')) {
1374    msg('Old changelog imported.', 1);
1375    if (!plugin_isdisabled('importoldchangelog')) {
1376      msg('Importoldchangelog plugin not disabled after import.', -1);
1377    }
1378  }
1379
1380  if(is_writable($conf['datadir'])){
1381    msg('Datadir is writable',1);
1382  }else{
1383    msg('Datadir is not writable',-1);
1384  }
1385
1386  if(is_writable($conf['olddir'])){
1387    msg('Attic is writable',1);
1388  }else{
1389    msg('Attic is not writable',-1);
1390  }
1391
1392  if(is_writable($conf['mediadir'])){
1393    msg('Mediadir is writable',1);
1394  }else{
1395    msg('Mediadir is not writable',-1);
1396  }
1397
1398  if(is_writable($conf['cachedir'])){
1399    msg('Cachedir is writable',1);
1400  }else{
1401    msg('Cachedir is not writable',-1);
1402  }
1403
1404  if(is_writable($conf['lockdir'])){
1405    msg('Lockdir is writable',1);
1406  }else{
1407    msg('Lockdir is not writable',-1);
1408  }
1409
1410  if(is_writable(DOKU_CONF.'users.auth.php')){
1411    msg('conf/users.auth.php is writable',1);
1412  }else{
1413    msg('conf/users.auth.php is not writable',0);
1414  }
1415
1416  if(function_exists('mb_strpos')){
1417    if(defined('UTF8_NOMBSTRING')){
1418      msg('mb_string extension is available but will not be used',0);
1419    }else{
1420      msg('mb_string extension is available and will be used',1);
1421    }
1422  }else{
1423    msg('mb_string extension not available - PHP only replacements will be used',0);
1424  }
1425
1426  if($conf['allowdebug']){
1427    msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1);
1428  }else{
1429    msg('Debugging support is disabled',1);
1430  }
1431
1432  msg('Your current permission for this page is '.$INFO['perm'],0);
1433
1434  if(is_writable($INFO['filepath'])){
1435    msg('The current page is writable by the webserver',0);
1436  }else{
1437    msg('The current page is not writable by the webserver',0);
1438  }
1439
1440  if($INFO['writable']){
1441    msg('The current page is writable by you',0);
1442  }else{
1443    msg('The current page is not writable you',0);
1444  }
1445}
1446
1447/**
1448 * Let us know if a user is tracking a page
1449 *
1450 * @author Andreas Gohr <andi@splitbrain.org>
1451 */
1452function is_subscribed($id,$uid){
1453  $file=metaFN($id,'.mlist');
1454  if (@file_exists($file)) {
1455    $mlist = file($file);
1456    $pos = array_search($uid."\n",$mlist);
1457    return is_int($pos);
1458  }
1459
1460  return false;
1461}
1462
1463/**
1464 * Return a string with the email addresses of all the
1465 * users subscribed to a page
1466 *
1467 * @author Steven Danz <steven-danz@kc.rr.com>
1468 */
1469function subscriber_addresslist($id){
1470  global $conf;
1471  global $auth;
1472
1473  $emails = '';
1474
1475  if (!$conf['subscribers']) return;
1476
1477  $mlist = array();
1478  $file=metaFN($id,'.mlist');
1479  if (@file_exists($file)) {
1480    $mlist = file($file);
1481  }
1482  if(count($mlist) > 0) {
1483    foreach ($mlist as $who) {
1484      $who = rtrim($who);
1485      $info = $auth->getUserData($who);
1486      $level = auth_aclcheck($id,$who,$info['grps']);
1487      if ($level >= AUTH_READ) {
1488        if (strcasecmp($info['mail'],$conf['notify']) != 0) {
1489          if (empty($emails)) {
1490            $emails = $info['mail'];
1491          } else {
1492            $emails = "$emails,".$info['mail'];
1493          }
1494        }
1495      }
1496    }
1497  }
1498
1499  return $emails;
1500}
1501
1502/**
1503 * Removes quoting backslashes
1504 *
1505 * @author Andreas Gohr <andi@splitbrain.org>
1506 */
1507function unslash($string,$char="'"){
1508  return str_replace('\\'.$char,$char,$string);
1509}
1510
1511//Setup VIM: ex: et ts=2 enc=utf-8 :
1512