1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Esther Brunner <wikidesign@gmail.com> 5 * @author Christopher Smith <chris@jalakai.co.uk> 6 * @author Gina Häußge, Michael Klier <dokuwiki@chimeric.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); 15 16require_once(DOKU_INC.'inc/search.php'); 17 18class helper_plugin_include extends DokuWiki_Plugin { // DokuWiki_Helper_Plugin 19 20 var $defaults = array(); 21 var $sec_close = true; 22 var $taghelper = null; 23 var $includes = array(); // deprecated - compatibility code for the blog plugin 24 25 /** 26 * Constructor loads default config settings once 27 */ 28 function helper_plugin_include() { 29 $this->defaults['noheader'] = $this->getConf('noheader'); 30 $this->defaults['firstsec'] = $this->getConf('firstseconly'); 31 $this->defaults['editbtn'] = $this->getConf('showeditbtn'); 32 $this->defaults['taglogos'] = $this->getConf('showtaglogos'); 33 $this->defaults['footer'] = $this->getConf('showfooter'); 34 $this->defaults['redirect'] = $this->getConf('doredirect'); 35 $this->defaults['date'] = $this->getConf('showdate'); 36 $this->defaults['mdate'] = $this->getConf('showmdate'); 37 $this->defaults['user'] = $this->getConf('showuser'); 38 $this->defaults['comments'] = $this->getConf('showcomments'); 39 $this->defaults['linkbacks'] = $this->getConf('showlinkbacks'); 40 $this->defaults['tags'] = $this->getConf('showtags'); 41 $this->defaults['link'] = $this->getConf('showlink'); 42 $this->defaults['permalink'] = $this->getConf('showpermalink'); 43 $this->defaults['indent'] = $this->getConf('doindent'); 44 $this->defaults['linkonly'] = $this->getConf('linkonly'); 45 $this->defaults['title'] = $this->getConf('title'); 46 $this->defaults['pageexists'] = $this->getConf('pageexists'); 47 $this->defaults['parlink'] = $this->getConf('parlink'); 48 $this->defaults['inline'] = false; 49 $this->defaults['order'] = $this->getConf('order'); 50 $this->defaults['rsort'] = $this->getConf('rsort'); 51 $this->defaults['depth'] = $this->getConf('depth'); 52 } 53 54 /** 55 * Available methods for other plugins 56 */ 57 function getMethods() { 58 $result = array(); 59 $result[] = array( 60 'name' => 'get_flags', 61 'desc' => 'overrides standard values for showfooter and firstseconly settings', 62 'params' => array('flags' => 'array'), 63 ); 64 return $result; 65 } 66 67 /** 68 * Overrides standard values for showfooter and firstseconly settings 69 */ 70 function get_flags($setflags) { 71 // load defaults 72 $flags = $this->defaults; 73 foreach ($setflags as $flag) { 74 $value = ''; 75 if (strpos($flag, '=') !== -1) { 76 list($flag, $value) = explode('=', $flag, 2); 77 } 78 switch ($flag) { 79 case 'footer': 80 $flags['footer'] = 1; 81 break; 82 case 'nofooter': 83 $flags['footer'] = 0; 84 break; 85 case 'firstseconly': 86 case 'firstsectiononly': 87 $flags['firstsec'] = 1; 88 break; 89 case 'fullpage': 90 $flags['firstsec'] = 0; 91 break; 92 case 'showheader': 93 case 'header': 94 $flags['noheader'] = 0; 95 break; 96 case 'noheader': 97 $flags['noheader'] = 1; 98 break; 99 case 'editbtn': 100 case 'editbutton': 101 $flags['editbtn'] = 1; 102 break; 103 case 'noeditbtn': 104 case 'noeditbutton': 105 $flags['editbtn'] = 0; 106 break; 107 case 'permalink': 108 $flags['permalink'] = 1; 109 break; 110 case 'nopermalink': 111 $flags['permalink'] = 0; 112 break; 113 case 'redirect': 114 $flags['redirect'] = 1; 115 break; 116 case 'noredirect': 117 $flags['redirect'] = 0; 118 break; 119 case 'link': 120 $flags['link'] = 1; 121 break; 122 case 'nolink': 123 $flags['link'] = 0; 124 break; 125 case 'user': 126 $flags['user'] = 1; 127 break; 128 case 'nouser': 129 $flags['user'] = 0; 130 break; 131 case 'comments': 132 $flags['comments'] = 1; 133 break; 134 case 'nocomments': 135 $flags['comments'] = 0; 136 break; 137 case 'linkbacks': 138 $flags['linkbacks'] = 1; 139 break; 140 case 'nolinkbacks': 141 $flags['linkbacks'] = 0; 142 break; 143 case 'tags': 144 $flags['tags'] = 1; 145 break; 146 case 'notags': 147 $flags['tags'] = 0; 148 break; 149 case 'date': 150 $flags['date'] = 1; 151 break; 152 case 'nodate': 153 $flags['date'] = 0; 154 break; 155 case 'mdate': 156 $flags['mdate'] = 1; 157 break; 158 case 'nomdate': 159 $flags['mdate'] = 0; 160 break; 161 case 'indent': 162 $flags['indent'] = 1; 163 break; 164 case 'noindent': 165 $flags['indent'] = 0; 166 break; 167 case 'linkonly': 168 $flags['linkonly'] = 1; 169 break; 170 case 'nolinkonly': 171 case 'include_content': 172 $flags['linkonly'] = 0; 173 break; 174 case 'inline': 175 $flags['inline'] = 1; 176 break; 177 case 'title': 178 $flags['title'] = 1; 179 break; 180 case 'pageexists': 181 $flags['pageexists'] = 1; 182 break; 183 case 'existlink': 184 $flags['pageexists'] = 1; 185 $flags['linkonly'] = 1; 186 break; 187 case 'noparlink': 188 $flags['parlink'] = 0; 189 break; 190 case 'order': 191 $flags['order'] = $value; 192 break; 193 case 'sort': 194 $flags['rsort'] = 0; 195 break; 196 case 'rsort': 197 $flags['rsort'] = 1; 198 break; 199 case 'depth': 200 $flags['depth'] = $value; 201 break; 202 } 203 } 204 // the include_content URL parameter overrides flags 205 if (isset($_REQUEST['include_content'])) 206 $flags['linkonly'] = 0; 207 return $flags; 208 } 209 210 /** 211 * Returns the converted instructions of a give page/section 212 * 213 * @author Michael Klier <chi@chimeric.de> 214 * @author Michael Hamann <michael@content-space.de> 215 */ 216 function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null) { 217 $key = ($sect) ? $page . '#' . $sect : $page; 218 $this->includes[$key] = true; // legacy code for keeping compatibility with other plugins 219 220 // keep compatibility with other plugins that don't know the $root_id parameter 221 if (is_null($root_id)) { 222 global $ID; 223 $root_id = $ID; 224 } 225 226 if ($flags['linkonly']) { 227 if (page_exists($page) || $flags['pageexists'] == 0) { 228 $title = ''; 229 if ($flags['title']) 230 $title = p_get_first_heading($page); 231 if($flags['parlink']) { 232 $ins = array( 233 array('p_open', array()), 234 array('internallink', array(':'.$key, $title)), 235 array('p_close', array()), 236 ); 237 } else { 238 $ins = array(array('internallink', array(':'.$key,$title))); 239 } 240 }else { 241 $ins = array(); 242 } 243 } else { 244 if (page_exists($page)) { 245 global $ID; 246 $backupID = $ID; 247 $ID = $page; // Change the global $ID as otherwise plugins like the discussion plugin will save data for the wrong page 248 $ins = p_cached_instructions(wikiFN($page)); 249 $ID = $backupID; 250 } else { 251 $ins = array(); 252 } 253 254 $this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id); 255 } 256 return $ins; 257 } 258 259 /** 260 * Converts instructions of the included page 261 * 262 * The funcion iterates over the given list of instructions and generates 263 * an index of header and section indicies. It also removes document 264 * start/end instructions, converts links, and removes unwanted 265 * instructions like tags, comments, linkbacks. 266 * 267 * Later all header/section levels are convertet to match the current 268 * inclusion level. 269 * 270 * @author Michael Klier <chi@chimeric.de> 271 */ 272 function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id) { 273 global $conf; 274 275 // filter instructions if needed 276 if(!empty($sect)) { 277 $this->_get_section($ins, $sect); // section required 278 } 279 280 if($flags['firstsec']) { 281 $this->_get_firstsec($ins, $page); // only first section 282 } 283 284 $ns = getNS($page); 285 $num = count($ins); 286 287 $conv_idx = array(); // conversion index 288 $lvl_max = false; // max level 289 $first_header = -1; 290 $no_header = false; 291 $sect_title = false; 292 $endpos = null; // end position of the raw wiki text 293 294 for($i=0; $i<$num; $i++) { 295 switch($ins[$i][0]) { 296 case 'document_start': 297 case 'document_end': 298 case 'section_edit': 299 unset($ins[$i]); 300 break; 301 case 'header': 302 // get section title of first section 303 if($sect && !$sect_title) { 304 $sect_title = $ins[$i][1][0]; 305 } 306 // check if we need to skip the first header 307 if((!$no_header) && $flags['noheader']) { 308 $no_header = true; 309 } 310 311 $conv_idx[] = $i; 312 // get index of first header 313 if($first_header == -1) $first_header = $i; 314 // get max level of this instructions set 315 if(!$lvl_max || ($ins[$i][1][1] < $lvl_max)) { 316 $lvl_max = $ins[$i][1][1]; 317 } 318 break; 319 case 'section_open': 320 if ($flags['inline']) 321 unset($ins[$i]); 322 else 323 $conv_idx[] = $i; 324 break; 325 case 'section_close': 326 if ($flags['inline']) 327 unset($ins[$i]); 328 break; 329 case 'internallink': 330 case 'internalmedia': 331 // make sure parameters aren't touched 332 $link_params = ''; 333 $link_id = $ins[$i][1][0]; 334 $link_parts = explode('?', $link_id, 2); 335 if (count($link_parts) === 2) { 336 $link_id = $link_parts[0]; 337 $link_params = $link_parts[1]; 338 } 339 // resolve the id without cleaning it 340 $link_id = resolve_id($ns, $link_id, false); 341 // this id is internal (i.e. absolute) now, add ':' to make resolve_id work again 342 if ($link_id{0} != ':') $link_id = ':'.$link_id; 343 // restore parameters 344 $ins[$i][1][0] = ($link_params != '') ? $link_id.'?'.$link_params : $link_id; 345 break; 346 case 'plugin': 347 // FIXME skip other plugins? 348 switch($ins[$i][1][0]) { 349 case 'tag_tag': // skip tags 350 case 'discussion_comments': // skip comments 351 case 'linkback': // skip linkbacks 352 case 'data_entry': // skip data plugin 353 case 'meta': // skip meta plugin 354 case 'indexmenu_tag': // skip indexmenu sort tag 355 case 'include_sorttag': // skip include plugin sort tag 356 unset($ins[$i]); 357 break; 358 // adapt indentation level of nested includes 359 case 'include_include': 360 if (!$flags['inline'] && $flags['indent']) 361 $ins[$i][1][1][4] += $lvl; 362 break; 363 /* 364 * if there is already a closelastsecedit instruction (was added by one of the section 365 * functions), store its position but delete it as it can't be determined yet if it is needed, 366 * i.e. if there is a header which generates a section edit (depends on the levels, level 367 * adjustments, $no_header, ...) 368 */ 369 case 'include_closelastsecedit': 370 $endpos = $ins[$i][1][1][0]; 371 unset($ins[$i]); 372 break; 373 } 374 break; 375 default: 376 break; 377 } 378 } 379 380 // calculate difference between header/section level and include level 381 $diff = 0; 382 if (!isset($lvl_max)) $lvl_max = 0; // if no level found in target, set to 0 383 $diff = $lvl - $lvl_max + 1; 384 if ($no_header) $diff -= 1; // push up one level if "noheader" 385 386 // convert headers and set footer/permalink 387 $hdr_deleted = false; 388 $has_permalink = false; 389 $footer_lvl = false; 390 $contains_secedit = false; 391 $section_close_at = false; 392 foreach($conv_idx as $idx) { 393 if($ins[$idx][0] == 'header') { 394 if ($section_close_at === false) { 395 // store the index of the first heading (the begin of the first section) 396 $section_close_at = $idx; 397 } 398 399 if($no_header && !$hdr_deleted) { 400 unset ($ins[$idx]); 401 $hdr_deleted = true; 402 continue; 403 } 404 405 if($flags['indent']) { 406 $lvl_new = (($ins[$idx][1][1] + $diff) > 5) ? 5 : ($ins[$idx][1][1] + $diff); 407 $ins[$idx][1][1] = $lvl_new; 408 } 409 410 if($ins[$idx][1][1] <= $conf['maxseclevel']) 411 $contains_secedit = true; 412 413 // set permalink 414 if($flags['link'] && !$has_permalink && ($idx == $first_header)) { 415 $this->_permalink($ins[$idx], $page, $sect, $flags); 416 $has_permalink = true; 417 } 418 419 // set footer level 420 if(!$footer_lvl && ($idx == $first_header) && !$no_header) { 421 if($flags['indent']) { 422 $footer_lvl = $lvl_new; 423 } else { 424 $footer_lvl = $lvl_max; 425 } 426 } 427 } else { 428 // it's a section 429 if($flags['indent']) { 430 $lvl_new = (($ins[$idx][1][0] + $diff) > 5) ? 5 : ($ins[$idx][1][0] + $diff); 431 $ins[$idx][1][0] = $lvl_new; 432 } 433 434 // check if noheader is used and set the footer level to the first section 435 if($no_header && !$footer_lvl) { 436 if($flags['indent']) { 437 $footer_lvl = $lvl_new; 438 } else { 439 $footer_lvl = $lvl_max; 440 } 441 } 442 } 443 } 444 445 // close last open section of the included page if there is any 446 if ($contains_secedit) { 447 array_push($ins, array('plugin', array('include_closelastsecedit', array($endpos)))); 448 } 449 450 // add edit button 451 if($flags['editbtn']) { 452 $this->_editbtn($ins, $page, $sect, $sect_title, ($flags['redirect'] ? $root_id : false)); 453 } 454 455 // add footer 456 if($flags['footer']) { 457 $ins[] = $this->_footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id); 458 } 459 460 // wrap content at the beginning of the include that is not in a section in a section 461 if ($lvl > 0 && $section_close_at !== 0 && $flags['indent'] && !$flags['inline']) { 462 if ($section_close_at === false) { 463 $ins[] = array('section_close', array()); 464 array_unshift($ins, array('section_open', array($lvl))); 465 } else { 466 $section_close_idx = array_search($section_close_at, array_keys($ins)); 467 if ($section_close_idx > 0) { 468 $before_ins = array_slice($ins, 0, $section_close_idx); 469 $after_ins = array_slice($ins, $section_close_idx); 470 $ins = array_merge($before_ins, array(array('section_close', array())), $after_ins); 471 array_unshift($ins, array('section_open', array($lvl))); 472 } 473 } 474 } 475 476 // add instructions entry wrapper 477 array_unshift($ins, array('plugin', array('include_wrap', array('open', $page, $flags['redirect'])))); 478 array_push($ins, array('plugin', array('include_wrap', array('close')))); 479 480 // close previous section if any and re-open after inclusion 481 if($lvl != 0 && $this->sec_close && !$flags['inline']) { 482 array_unshift($ins, array('section_close', array())); 483 $ins[] = array('section_open', array($lvl)); 484 } 485 } 486 487 /** 488 * Appends instruction item for the include plugin footer 489 * 490 * @author Michael Klier <chi@chimeric.de> 491 */ 492 function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) { 493 $footer = array(); 494 $footer[0] = 'plugin'; 495 $footer[1] = array('include_footer', array($page, $sect, $sect_title, $flags, $root_id, $footer_lvl)); 496 return $footer; 497 } 498 499 /** 500 * Appends instruction item for an edit button 501 * 502 * @author Michael Klier <chi@chimeric.de> 503 */ 504 function _editbtn(&$ins, $page, $sect, $sect_title, $root_id) { 505 $title = ($sect) ? $sect_title : $page; 506 $editbtn = array(); 507 $editbtn[0] = 'plugin'; 508 $editbtn[1] = array('include_editbtn', array($title)); 509 $ins[] = $editbtn; 510 } 511 512 /** 513 * Convert instruction item for a permalink header 514 * 515 * @author Michael Klier <chi@chimeric.de> 516 */ 517 function _permalink(&$ins, $page, $sect, $flags) { 518 $ins[0] = 'plugin'; 519 $ins[1] = array('include_header', array($ins[1][0], $ins[1][1], $ins[1][2], $page, $sect, $flags)); 520 } 521 522 /** 523 * Get a section including its subsections 524 * 525 * @author Michael Klier <chi@chimeric.de> 526 */ 527 function _get_section(&$ins, $sect) { 528 $num = count($ins); 529 $offset = false; 530 $lvl = false; 531 $end = false; 532 $endpos = null; // end position in the input text, needed for section edit buttons 533 534 $check = array(); // used for sectionID() in order to get the same ids as the xhtml renderer 535 536 for($i=0; $i<$num; $i++) { 537 if ($ins[$i][0] == 'header') { 538 539 // found the right header 540 if (sectionID($ins[$i][1][0], $check) == $sect) { 541 $offset = $i; 542 $lvl = $ins[$i][1][1]; 543 } elseif ($offset && $lvl && ($ins[$i][1][1] <= $lvl)) { 544 $end = $i - $offset; 545 $endpos = $ins[$i][1][2]; // the position directly after the found section, needed for the section edit button 546 break; 547 } 548 } 549 } 550 $offset = $offset ? $offset : 0; 551 $end = $end ? $end : ($num - 1); 552 if(is_array($ins)) { 553 $ins = array_slice($ins, $offset, $end); 554 // store the end position in the include_closelastsecedit instruction so it can generate a matching button 555 $ins[] = array('plugin', array('include_closelastsecedit', array($endpos))); 556 } 557 } 558 559 /** 560 * Only display the first section of a page and a readmore link 561 * 562 * @author Michael Klier <chi@chimeric.de> 563 */ 564 function _get_firstsec(&$ins, $page) { 565 $num = count($ins); 566 $first_sect = false; 567 $endpos = null; // end position in the input text 568 for($i=0; $i<$num; $i++) { 569 if($ins[$i][0] == 'section_close') { 570 $first_sect = $i; 571 } 572 if ($ins[$i][0] == 'header') { 573 /* 574 * Store the position of the last header that is encountered. As section_close/open-instruction are 575 * always (unless some plugin modifies this) around a header instruction this means that the last 576 * position that is stored here is exactly the position of the section_close/open at which the content 577 * is truncated. 578 */ 579 $endpos = $ins[$i][1][2]; 580 } 581 // only truncate the content and add the read more link when there is really 582 // more than that first section 583 if(($first_sect) && ($ins[$i][0] == 'section_open')) { 584 $ins = array_slice($ins, 0, $first_sect); 585 $ins[] = array('plugin', array('include_readmore', array($page))); 586 $ins[] = array('section_close', array()); 587 // store the end position in the include_closelastsecedit instruction so it can generate a matching button 588 $ins[] = array('plugin', array('include_closelastsecedit', array($endpos))); 589 return; 590 } 591 } 592 } 593 594 /** 595 * Gives a list of pages for a given include statement 596 * 597 * @author Michael Hamann <michael@content-space.de> 598 */ 599 function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { 600 global $conf; 601 $pages = array(); 602 switch($mode) { 603 case 'namespace': 604 $page = cleanID($page); 605 $ns = utf8_encodeFN(str_replace(':', '/', $page)); 606 // depth is absolute depth, not relative depth, but 0 has a special meaning. 607 $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0; 608 search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth), $ns); 609 if (is_array($pagearrays)) { 610 foreach ($pagearrays as $pagearray) { 611 if (!isHiddenPage($pagearray['id'])) // skip hidden pages 612 $pages[] = $pagearray['id']; 613 } 614 } 615 break; 616 case 'tagtopic': 617 if (!$this->taghelper) 618 $this->taghelper =& plugin_load('helper', 'tag'); 619 if(!$this->taghelper) { 620 msg('You have to install the tag plugin to use this functionality!', -1); 621 return array(); 622 } 623 $tag = $page; 624 $sect = ''; 625 $pagearrays = $this->taghelper->getTopic('', null, $tag); 626 foreach ($pagearrays as $pagearray) { 627 $pages[] = $pagearray['id']; 628 } 629 break; 630 default: 631 $page = $this->_apply_macro($page); 632 resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID 633 if (auth_quickaclcheck($page) >= AUTH_READ) 634 $pages[] = $page; 635 } 636 637 if (count($pages) > 1) { 638 if ($flags['order'] === 'id') { 639 if ($flags['rsort']) { 640 usort($pages, array($this, '_r_strnatcasecmp')); 641 } else { 642 natcasesort($pages); 643 } 644 } else { 645 $ordered_pages = array(); 646 foreach ($pages as $page) { 647 $key = ''; 648 switch ($flags['order']) { 649 case 'title': 650 $key = p_get_first_heading($page); 651 break; 652 case 'created': 653 $key = p_get_metadata($page, 'date created', METADATA_DONT_RENDER); 654 break; 655 case 'modified': 656 $key = p_get_metadata($page, 'date modified', METADATA_DONT_RENDER); 657 break; 658 case 'indexmenu': 659 $key = p_get_metadata($page, 'indexmenu_n', METADATA_RENDER_USING_SIMPLE_CACHE); 660 if ($key === null) 661 $key = ''; 662 break; 663 case 'custom': 664 $key = p_get_metadata($page, 'include_n', METADATA_RENDER_USING_SIMPLE_CACHE); 665 if ($key === null) 666 $key = ''; 667 break; 668 } 669 $key .= '_'.$page; 670 $ordered_pages[$key] = $page; 671 } 672 if ($flags['rsort']) { 673 uksort($ordered_pages, array($this, '_r_strnatcasecmp')); 674 } else { 675 uksort($ordered_pages, 'strnatcasecmp'); 676 } 677 $pages = $ordered_pages; 678 } 679 } 680 681 $result = array(); 682 foreach ($pages as $page) { 683 $exists = page_exists($page); 684 $result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id); 685 } 686 return $result; 687 } 688 689 /** 690 * String comparisons using a "natural order" algorithm in reverse order 691 * 692 * @link http://php.net/manual/en/function.strnatcmp.php 693 * @param string $a First string 694 * @param string $b Second string 695 * @return int Similar to other string comparison functions, this one returns < 0 if 696 * str1 is greater than str2; > 697 * 0 if str1 is lesser than 698 * str2, and 0 if they are equal. 699 */ 700 function _r_strnatcasecmp($a, $b) { 701 return strnatcasecmp($b, $a); 702 } 703 704 /** 705 * This function generates the list of all included pages from a list of metadata 706 * instructions. 707 */ 708 function _get_included_pages_from_meta_instructions($instructions) { 709 $pages = array(); 710 foreach ($instructions as $instruction) { 711 $mode = $instruction['mode']; 712 $page = $instruction['page']; 713 $sect = $instruction['sect']; 714 $parent_id = $instruction['parent_id']; 715 $flags = $instruction['flags']; 716 $pages = array_merge($pages, $this->_get_included_pages($mode, $page, $sect, $parent_id, $flags)); 717 } 718 return $pages; 719 } 720 721 /** 722 * Makes user or date dependent includes possible 723 */ 724 function _apply_macro($id) { 725 global $INFO; 726 global $auth; 727 728 // if we don't have an auth object, do nothing 729 if (!$auth) return $id; 730 731 $user = $_SERVER['REMOTE_USER']; 732 $group = $INFO['userinfo']['grps'][0]; 733 734 $time_stamp = time(); 735 if(preg_match('/@DATE(\w+)@/',$id,$matches)) { 736 switch($matches[1]) { 737 case 'PMONTH': 738 $time_stamp = strtotime("-1 month"); 739 break; 740 case 'NMONTH': 741 $time_stamp = strtotime("+1 month"); 742 break; 743 case 'NWEEK': 744 $time_stamp = strtotime("+1 week"); 745 break; 746 case 'PWEEK': 747 $time_stamp = strtotime("-1 week"); 748 break; 749 case 'TOMORROW': 750 $time_stamp = strtotime("+1 day"); 751 break; 752 case 'YESTERDAY': 753 $time_stamp = strtotime("-1 day"); 754 break; 755 case 'NYEAR': 756 $time_stamp = strtotime("+1 year"); 757 break; 758 case 'PYEAR': 759 $time_stamp = strtotime("-1 year"); 760 break; 761 } 762 $id = preg_replace('/@DATE(\w+)@/','', $id); 763 } 764 765 $replace = array( 766 '@USER@' => cleanID($user), 767 '@NAME@' => cleanID($INFO['userinfo']['name']), 768 '@GROUP@' => cleanID($group), 769 '@YEAR@' => date('Y',$time_stamp), 770 '@MONTH@' => date('m',$time_stamp), 771 '@WEEK@' => date('W',$time_stamp), 772 '@DAY@' => date('d',$time_stamp), 773 '@YEARPMONTH@' => date('Ym',strtotime("-1 month")), 774 '@PMONTH@' => date('m',strtotime("-1 month")), 775 '@NMONTH@' => date('m',strtotime("+1 month")), 776 '@YEARNMONTH@' => date('Ym',strtotime("+1 month")), 777 '@YEARPWEEK@' => date('YW',strtotime("-1 week")), 778 '@PWEEK@' => date('W',strtotime("-1 week")), 779 '@NWEEK@' => date('W',strtotime("+1 week")), 780 '@YEARNWEEK@' => date('YW',strtotime("+1 week")), 781 ); 782 return str_replace(array_keys($replace), array_values($replace), $id); 783 } 784} 785// vim:ts=4:sw=4:et: 786