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='&'){ 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='&'){ 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='&'){ 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='&'){ 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 $ip[$i] = preg_replace('/[^0-9\.]+/','',$ip[$i]); 501 if(preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/',$ip[$i],$match)) { 502 $ip[$i] = $match[0]; 503 } else { 504 $ip[$i] = ''; 505 } 506 if(empty($ip[$i])) unset($ip[$i]); 507 } 508 $ip = array_values(array_unique($ip)); 509 if(!$ip[0]) $ip[0] = '0.0.0.0'; // for some strange reason we don't have a IP 510 511 if(!$single) return join(',',$ip); 512 513 // decide which IP to use, trying to avoid local addresses 514 $ip = array_reverse($ip); 515 foreach($ip as $i){ 516 if(preg_match('/^(127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)/',$i)){ 517 continue; 518 }else{ 519 return $i; 520 } 521 } 522 // still here? just use the first (last) address 523 return $ip[0]; 524} 525 526/** 527 * Checks if a given page is currently locked. 528 * 529 * removes stale lockfiles 530 * 531 * @author Andreas Gohr <andi@splitbrain.org> 532 */ 533function checklock($id){ 534 global $conf; 535 $lock = wikiLockFN($id); 536 537 //no lockfile 538 if(!@file_exists($lock)) return false; 539 540 //lockfile expired 541 if((time() - filemtime($lock)) > $conf['locktime']){ 542 unlink($lock); 543 return false; 544 } 545 546 //my own lock 547 $ip = io_readFile($lock); 548 if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){ 549 return false; 550 } 551 552 return $ip; 553} 554 555/** 556 * Lock a page for editing 557 * 558 * @author Andreas Gohr <andi@splitbrain.org> 559 */ 560function lock($id){ 561 $lock = wikiLockFN($id); 562 if($_SERVER['REMOTE_USER']){ 563 io_saveFile($lock,$_SERVER['REMOTE_USER']); 564 }else{ 565 io_saveFile($lock,clientIP()); 566 } 567} 568 569/** 570 * Unlock a page if it was locked by the user 571 * 572 * @author Andreas Gohr <andi@splitbrain.org> 573 * @return bool true if a lock was removed 574 */ 575function unlock($id){ 576 $lock = wikiLockFN($id); 577 if(@file_exists($lock)){ 578 $ip = io_readFile($lock); 579 if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){ 580 @unlink($lock); 581 return true; 582 } 583 } 584 return false; 585} 586 587/** 588 * convert line ending to unix format 589 * 590 * @see formText() for 2crlf conversion 591 * @author Andreas Gohr <andi@splitbrain.org> 592 */ 593function cleanText($text){ 594 $text = preg_replace("/(\015\012)|(\015)/","\012",$text); 595 return $text; 596} 597 598/** 599 * Prepares text for print in Webforms by encoding special chars. 600 * It also converts line endings to Windows format which is 601 * pseudo standard for webforms. 602 * 603 * @see cleanText() for 2unix conversion 604 * @author Andreas Gohr <andi@splitbrain.org> 605 */ 606function formText($text){ 607 $text = preg_replace("/\012/","\015\012",$text); 608 return htmlspecialchars($text); 609} 610 611/** 612 * Returns the specified local text in raw format 613 * 614 * @author Andreas Gohr <andi@splitbrain.org> 615 */ 616function rawLocale($id){ 617 return io_readFile(localeFN($id)); 618} 619 620/** 621 * Returns the raw WikiText 622 * 623 * @author Andreas Gohr <andi@splitbrain.org> 624 */ 625function rawWiki($id,$rev=''){ 626 return io_readWikiPage(wikiFN($id, $rev), $id, $rev); 627} 628 629/** 630 * Returns the pagetemplate contents for the ID's namespace 631 * 632 * @author Andreas Gohr <andi@splitbrain.org> 633 */ 634function pageTemplate($id){ 635 global $conf; 636 global $INFO; 637 $tpl = io_readFile(dirname(wikiFN($id)).'/_template.txt'); 638 $tpl = str_replace('@ID@',$id,$tpl); 639 $tpl = str_replace('@NS@',getNS($id),$tpl); 640 $tpl = str_replace('@PAGE@',strtr(noNS($id),'_',' '),$tpl); 641 $tpl = str_replace('@USER@',$_SERVER['REMOTE_USER'],$tpl); 642 $tpl = str_replace('@NAME@',$INFO['userinfo']['name'],$tpl); 643 $tpl = str_replace('@MAIL@',$INFO['userinfo']['mail'],$tpl); 644 $tpl = str_replace('@DATE@',date($conf['dformat']),$tpl); 645 return $tpl; 646} 647 648 649/** 650 * Returns the raw Wiki Text in three slices. 651 * 652 * The range parameter needs to have the form "from-to" 653 * and gives the range of the section in bytes - no 654 * UTF-8 awareness is needed. 655 * The returned order is prefix, section and suffix. 656 * 657 * @author Andreas Gohr <andi@splitbrain.org> 658 */ 659function rawWikiSlices($range,$id,$rev=''){ 660 list($from,$to) = split('-',$range,2); 661 $text = io_readWikiPage(wikiFN($id, $rev), $id, $rev); 662 if(!$from) $from = 0; 663 if(!$to) $to = strlen($text)+1; 664 665 $slices[0] = substr($text,0,$from-1); 666 $slices[1] = substr($text,$from-1,$to-$from); 667 $slices[2] = substr($text,$to); 668 669 return $slices; 670} 671 672/** 673 * Joins wiki text slices 674 * 675 * function to join the text slices with correct lineendings again. 676 * When the pretty parameter is set to true it adds additional empty 677 * lines between sections if needed (used on saving). 678 * 679 * @author Andreas Gohr <andi@splitbrain.org> 680 */ 681function con($pre,$text,$suf,$pretty=false){ 682 683 if($pretty){ 684 if($pre && substr($pre,-1) != "\n") $pre .= "\n"; 685 if($suf && substr($text,-1) != "\n") $text .= "\n"; 686 } 687 688 if($pre) $pre .= "\n"; 689 if($suf) $text .= "\n"; 690 return $pre.$text.$suf; 691} 692 693/** 694 * print debug messages 695 * 696 * little function to print the content of a var 697 * 698 * @author Andreas Gohr <andi@splitbrain.org> 699 */ 700function dbg($msg,$hidden=false){ 701 (!$hidden) ? print '<pre class="dbg">' : print "<!--\n"; 702 print_r($msg); 703 (!$hidden) ? print '</pre>' : print "\n-->"; 704} 705 706/** 707 * Print info to a log file 708 * 709 * @author Andreas Gohr <andi@splitbrain.org> 710 */ 711function dbglog($msg){ 712 global $conf; 713 $file = $conf['cachedir'].'/debug.log'; 714 $fh = fopen($file,'a'); 715 if($fh){ 716 fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n"); 717 fclose($fh); 718 } 719} 720 721/** 722 * Add's an entry to the changelog and saves the metadata for the page 723 * 724 * @author Andreas Gohr <andi@splitbrain.org> 725 * @author Esther Brunner <wikidesign@gmail.com> 726 * @author Ben Coburn <btcoburn@silicodon.net> 727 */ 728function addLogEntry($date, $id, $type='E', $summary='', $extra=''){ 729 global $conf, $INFO; 730 731 $id = cleanid($id); 732 $file = wikiFN($id); 733 $created = @filectime($file); 734 $minor = ($type==='e'); 735 $wasRemoved = ($type==='D'); 736 737 if(!$date) $date = time(); //use current time if none supplied 738 $remote = $_SERVER['REMOTE_ADDR']; 739 $user = $_SERVER['REMOTE_USER']; 740 741 $logline = array( 742 'date' => $date, 743 'ip' => $remote, 744 'type' => $type, 745 'id' => $id, 746 'user' => $user, 747 'sum' => $summary, 748 'extra' => $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 1092 if ($wasRemoved){ 1093 // remove empty file 1094 @unlink($file); 1095 // remove old meta info... 1096 $mfiles = metaFiles($id); 1097 $changelog = metaFN($id, '.changes'); 1098 foreach ($mfiles as $mfile) { 1099 // but keep per-page changelog to preserve page history 1100 if (file_exists($mfile) && $mfile!==$changelog) { @unlink($mfile); } 1101 } 1102 $del = true; 1103 // autoset summary on deletion 1104 if(empty($summary)) $summary = $lang['deleted']; 1105 // remove empty namespaces 1106 io_sweepNS($id, 'datadir'); 1107 io_sweepNS($id, 'mediadir'); 1108 }else{ 1109 // save file (namespace dir is created in io_writeWikiPage) 1110 io_writeWikiPage($file, $text, $id); 1111 $del = false; 1112 } 1113 1114 // select changelog line type 1115 $extra = ''; 1116 $type = 'E'; 1117 if ($wasReverted) { 1118 $type = 'R'; 1119 $extra = $REV; 1120 } 1121 else if ($wasCreated) { $type = 'C'; } 1122 else if ($wasRemoved) { $type = 'D'; } 1123 else if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = 'e'; } //minor edits only for logged in users 1124 1125 addLogEntry(@filemtime($file), $id, $type, $summary, $extra); 1126 // send notify mails 1127 notify($id,'admin',$old,$summary,$minor); 1128 notify($id,'subscribers',$old,$summary,$minor); 1129 1130 //purge cache on add by updating the purgefile 1131 if($conf['purgeonadd'] && (!$old || $del)){ 1132 io_saveFile($conf['cachedir'].'/purgefile',time()); 1133 } 1134} 1135 1136/** 1137 * moves the current version to the attic and returns its 1138 * revision date 1139 * 1140 * @author Andreas Gohr <andi@splitbrain.org> 1141 */ 1142function saveOldRevision($id){ 1143 global $conf; 1144 $oldf = wikiFN($id); 1145 if(!@file_exists($oldf)) return ''; 1146 $date = filemtime($oldf); 1147 $newf = wikiFN($id,$date); 1148 io_writeWikiPage($newf, rawWiki($id), $id, $date); 1149 return $date; 1150} 1151 1152/** 1153 * Sends a notify mail on page change 1154 * 1155 * @param string $id The changed page 1156 * @param string $who Who to notify (admin|subscribers) 1157 * @param int $rev Old page revision 1158 * @param string $summary What changed 1159 * @param boolean $minor Is this a minor edit? 1160 * @param array $replace Additional string substitutions, @KEY@ to be replaced by value 1161 * 1162 * @author Andreas Gohr <andi@splitbrain.org> 1163 */ 1164function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){ 1165 global $lang; 1166 global $conf; 1167 1168 // decide if there is something to do 1169 if($who == 'admin'){ 1170 if(empty($conf['notify'])) return; //notify enabled? 1171 $text = rawLocale('mailtext'); 1172 $to = $conf['notify']; 1173 $bcc = ''; 1174 }elseif($who == 'subscribers'){ 1175 if(!$conf['subscribers']) return; //subscribers enabled? 1176 if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return; //skip minors 1177 $bcc = subscriber_addresslist($id); 1178 if(empty($bcc)) return; 1179 $to = ''; 1180 $text = rawLocale('subscribermail'); 1181 }elseif($who == 'register'){ 1182 if(empty($conf['registernotify'])) return; 1183 $text = rawLocale('registermail'); 1184 $to = $conf['registernotify']; 1185 $bcc = ''; 1186 }else{ 1187 return; //just to be safe 1188 } 1189 1190 $text = str_replace('@DATE@',date($conf['dformat']),$text); 1191 $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text); 1192 $text = str_replace('@IPADDRESS@',$_SERVER['REMOTE_ADDR'],$text); 1193 $text = str_replace('@HOSTNAME@',gethostbyaddr($_SERVER['REMOTE_ADDR']),$text); 1194 $text = str_replace('@NEWPAGE@',wl($id,'',true),$text); 1195 $text = str_replace('@PAGE@',$id,$text); 1196 $text = str_replace('@TITLE@',$conf['title'],$text); 1197 $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); 1198 $text = str_replace('@SUMMARY@',$summary,$text); 1199 $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text); 1200 1201 foreach ($replace as $key => $substitution) { 1202 $text = str_replace('@'.strtoupper($key).'@',$substitution, $text); 1203 } 1204 1205 if($who == 'register'){ 1206 $subject = $lang['mail_new_user'].' '.$summary; 1207 }elseif($rev){ 1208 $subject = $lang['mail_changed'].' '.$id; 1209 $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",true),$text); 1210 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 1211 $df = new Diff(split("\n",rawWiki($id,$rev)), 1212 split("\n",rawWiki($id))); 1213 $dformat = new UnifiedDiffFormatter(); 1214 $diff = $dformat->format($df); 1215 }else{ 1216 $subject=$lang['mail_newpage'].' '.$id; 1217 $text = str_replace('@OLDPAGE@','none',$text); 1218 $diff = rawWiki($id); 1219 } 1220 $text = str_replace('@DIFF@',$diff,$text); 1221 $subject = '['.$conf['title'].'] '.$subject; 1222 1223 mail_send($to,$subject,$text,$conf['mailfrom'],'',$bcc); 1224} 1225 1226/** 1227 * extracts the query from a google referer 1228 * 1229 * @todo should be more generic and support yahoo et al 1230 * @author Andreas Gohr <andi@splitbrain.org> 1231 */ 1232function getGoogleQuery(){ 1233 $url = parse_url($_SERVER['HTTP_REFERER']); 1234 if(!$url) return ''; 1235 1236 if(!preg_match("#google\.#i",$url['host'])) return ''; 1237 $query = array(); 1238 parse_str($url['query'],$query); 1239 1240 return $query['q']; 1241} 1242 1243/** 1244 * Try to set correct locale 1245 * 1246 * @deprecated No longer used 1247 * @author Andreas Gohr <andi@splitbrain.org> 1248 */ 1249function setCorrectLocale(){ 1250 global $conf; 1251 global $lang; 1252 1253 $enc = strtoupper($lang['encoding']); 1254 foreach ($lang['locales'] as $loc){ 1255 //try locale 1256 if(@setlocale(LC_ALL,$loc)) return; 1257 //try loceale with encoding 1258 if(@setlocale(LC_ALL,"$loc.$enc")) return; 1259 } 1260 //still here? try to set from environment 1261 @setlocale(LC_ALL,""); 1262} 1263 1264/** 1265 * Return the human readable size of a file 1266 * 1267 * @param int $size A file size 1268 * @param int $dec A number of decimal places 1269 * @author Martin Benjamin <b.martin@cybernet.ch> 1270 * @author Aidan Lister <aidan@php.net> 1271 * @version 1.0.0 1272 */ 1273function filesize_h($size, $dec = 1){ 1274 $sizes = array('B', 'KB', 'MB', 'GB'); 1275 $count = count($sizes); 1276 $i = 0; 1277 1278 while ($size >= 1024 && ($i < $count - 1)) { 1279 $size /= 1024; 1280 $i++; 1281 } 1282 1283 return round($size, $dec) . ' ' . $sizes[$i]; 1284} 1285 1286/** 1287 * return an obfuscated email address in line with $conf['mailguard'] setting 1288 * 1289 * @author Harry Fuecks <hfuecks@gmail.com> 1290 * @author Christopher Smith <chris@jalakai.co.uk> 1291 */ 1292function obfuscate($email) { 1293 global $conf; 1294 1295 switch ($conf['mailguard']) { 1296 case 'visible' : 1297 $obfuscate = array('@' => ' [at] ', '.' => ' [dot] ', '-' => ' [dash] '); 1298 return strtr($email, $obfuscate); 1299 1300 case 'hex' : 1301 $encode = ''; 1302 for ($x=0; $x < strlen($email); $x++) $encode .= '&#x' . bin2hex($email{$x}).';'; 1303 return $encode; 1304 1305 case 'none' : 1306 default : 1307 return $email; 1308 } 1309} 1310 1311/** 1312 * Return DokuWikis version 1313 * 1314 * @author Andreas Gohr <andi@splitbrain.org> 1315 */ 1316function getVersion(){ 1317 //import version string 1318 if(@file_exists('VERSION')){ 1319 //official release 1320 return 'Release '.trim(io_readfile(DOKU_INC.'/VERSION')); 1321 }elseif(is_dir('_darcs')){ 1322 //darcs checkout 1323 $inv = file('_darcs/inventory'); 1324 $inv = preg_grep('#\*\*\d{14}[\]$]#',$inv); 1325 $cur = array_pop($inv); 1326 preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches); 1327 return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3]; 1328 }else{ 1329 return 'snapshot?'; 1330 } 1331} 1332 1333/** 1334 * Run a few sanity checks 1335 * 1336 * @author Andreas Gohr <andi@splitbrain.org> 1337 */ 1338function check(){ 1339 global $conf; 1340 global $INFO; 1341 1342 msg('DokuWiki version: '.getVersion(),1); 1343 1344 if(version_compare(phpversion(),'4.3.0','<')){ 1345 msg('Your PHP version is too old ('.phpversion().' vs. 4.3.+ recommended)',-1); 1346 }elseif(version_compare(phpversion(),'4.3.10','<')){ 1347 msg('Consider upgrading PHP to 4.3.10 or higher for security reasons (your version: '.phpversion().')',0); 1348 }else{ 1349 msg('PHP version '.phpversion(),1); 1350 } 1351 1352 if(is_writable($conf['changelog'])){ 1353 msg('Changelog is writable',1); 1354 }else{ 1355 if (file_exists($conf['changelog'])) { 1356 msg('Changelog is not writable',-1); 1357 } 1358 } 1359 1360 if (isset($conf['changelog_old']) && file_exists($conf['changelog_old'])) { 1361 msg('Old changelog exists.', 0); 1362 } 1363 1364 if (file_exists($conf['changelog'].'_failed')) { 1365 msg('Importing old changelog failed.', -1); 1366 } else if (file_exists($conf['changelog'].'_importing')) { 1367 msg('Importing old changelog now.', 0); 1368 } else if (file_exists($conf['changelog'].'_import_ok')) { 1369 msg('Old changelog imported.', 1); 1370 } 1371 1372 if(is_writable($conf['datadir'])){ 1373 msg('Datadir is writable',1); 1374 }else{ 1375 msg('Datadir is not writable',-1); 1376 } 1377 1378 if(is_writable($conf['olddir'])){ 1379 msg('Attic is writable',1); 1380 }else{ 1381 msg('Attic is not writable',-1); 1382 } 1383 1384 if(is_writable($conf['mediadir'])){ 1385 msg('Mediadir is writable',1); 1386 }else{ 1387 msg('Mediadir is not writable',-1); 1388 } 1389 1390 if(is_writable($conf['cachedir'])){ 1391 msg('Cachedir is writable',1); 1392 }else{ 1393 msg('Cachedir is not writable',-1); 1394 } 1395 1396 if(is_writable($conf['lockdir'])){ 1397 msg('Lockdir is writable',1); 1398 }else{ 1399 msg('Lockdir is not writable',-1); 1400 } 1401 1402 if(is_writable(DOKU_CONF.'users.auth.php')){ 1403 msg('conf/users.auth.php is writable',1); 1404 }else{ 1405 msg('conf/users.auth.php is not writable',0); 1406 } 1407 1408 if(function_exists('mb_strpos')){ 1409 if(defined('UTF8_NOMBSTRING')){ 1410 msg('mb_string extension is available but will not be used',0); 1411 }else{ 1412 msg('mb_string extension is available and will be used',1); 1413 } 1414 }else{ 1415 msg('mb_string extension not available - PHP only replacements will be used',0); 1416 } 1417 1418 if($conf['allowdebug']){ 1419 msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1); 1420 }else{ 1421 msg('Debugging support is disabled',1); 1422 } 1423 1424 msg('Your current permission for this page is '.$INFO['perm'],0); 1425 1426 if(is_writable($INFO['filepath'])){ 1427 msg('The current page is writable by the webserver',0); 1428 }else{ 1429 msg('The current page is not writable by the webserver',0); 1430 } 1431 1432 if($INFO['writable']){ 1433 msg('The current page is writable by you',0); 1434 }else{ 1435 msg('The current page is not writable you',0); 1436 } 1437} 1438 1439/** 1440 * Let us know if a user is tracking a page 1441 * 1442 * @author Andreas Gohr <andi@splitbrain.org> 1443 */ 1444function is_subscribed($id,$uid){ 1445 $file=metaFN($id,'.mlist'); 1446 if (@file_exists($file)) { 1447 $mlist = file($file); 1448 $pos = array_search($uid."\n",$mlist); 1449 return is_int($pos); 1450 } 1451 1452 return false; 1453} 1454 1455/** 1456 * Return a string with the email addresses of all the 1457 * users subscribed to a page 1458 * 1459 * @author Steven Danz <steven-danz@kc.rr.com> 1460 */ 1461function subscriber_addresslist($id){ 1462 global $conf; 1463 global $auth; 1464 1465 $emails = ''; 1466 1467 if (!$conf['subscribers']) return; 1468 1469 $mlist = array(); 1470 $file=metaFN($id,'.mlist'); 1471 if (file_exists($file)) { 1472 $mlist = file($file); 1473 } 1474 if(count($mlist) > 0) { 1475 foreach ($mlist as $who) { 1476 $who = rtrim($who); 1477 $info = $auth->getUserData($who); 1478 $level = auth_aclcheck($id,$who,$info['grps']); 1479 if ($level >= AUTH_READ) { 1480 if (strcasecmp($info['mail'],$conf['notify']) != 0) { 1481 if (empty($emails)) { 1482 $emails = $info['mail']; 1483 } else { 1484 $emails = "$emails,".$info['mail']; 1485 } 1486 } 1487 } 1488 } 1489 } 1490 1491 return $emails; 1492} 1493 1494/** 1495 * Removes quoting backslashes 1496 * 1497 * @author Andreas Gohr <andi@splitbrain.org> 1498 */ 1499function unslash($string,$char="'"){ 1500 return str_replace('\\'.$char,$char,$string); 1501} 1502 1503//Setup VIM: ex: et ts=2 enc=utf-8 : 1504