1<?php 2/** 3 * Lastmod Plugin: Display the timestamp of the last modification 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Dennis Ploeger <develop@dieploegers.de> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_lastmod extends DokuWiki_Syntax_Plugin { 18 19 /** 20 * What kind of syntax are we? 21 */ 22 function getType(){ 23 return 'substition'; 24 } 25 26 /** 27 * What about paragraphs? 28 */ 29 function getPType(){ 30 return 'normal'; 31 } 32 33 /** 34 * Where to sort in? 35 */ 36 function getSort(){ 37 return 155; 38 } 39 40 41 /** 42 * Connect pattern to lexer 43 */ 44 function connectTo($mode) { 45 $this->Lexer->addSpecialPattern('~~LASTMOD[^~]*~~',$mode,'plugin_lastmod'); 46 } 47 48 49 /** 50 * Handle the match 51 */ 52 53 function handle($match, $state, $pos, Doku_Handler $handler){ 54 55 global $ID,$INFO; 56 57 if (preg_match("/:/", $match)) { 58 59 preg_match("/:([^~]*)/", $match, $matches); 60 61 $id = $matches[1]; 62 63 $id_save = $ID; 64 $ID = $id; 65 66 $tmp_info = pageinfo(); 67 68 $lastmod = $tmp_info['lastmod']; 69 70 $ID = $id_save; 71 72 } else { 73 74 $tmp_info = pageinfo(); 75 76 $lastmod = $tmp_info['lastmod']; 77 78 } 79 80 return array($lastmod); 81 } 82 83 /** 84 * Create output 85 */ 86 function render($mode, Doku_Renderer $renderer, $data) { 87 global $INFO, $conf; 88 89 if($mode == 'xhtml'){ 90 91 if (preg_match("/%/", $conf['dformat'])) { 92 93 $renderer->doc .= strftime($conf['dformat'], $data[0]); 94 95 } else { 96 97 $renderer->doc .= date($conf['dformat'], $data[0]); 98 99 } 100 101 return true; 102 } 103 return false; 104 } 105 106} 107 108//Setup VIM: ex: et ts=4 enc=utf-8 : 109 110?> 111