1<?php 2/** 3 * Plugin Now: Inserts a timestamp. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Myron Turner <tunermm02@shaw.ca> 7 */ 8 9// must be run within DokuWiki 10if(!defined('DOKU_INC')) die(); 11 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13require_once DOKU_PLUGIN.'syntax.php'; 14 15/** 16 * All DokuWiki plugins to extend the parser/rendering mechanism 17 * need to inherit from this class 18 */ 19class syntax_plugin_codedoc_specials extends DokuWiki_Syntax_Plugin { 20 21 22 function getType() { return 'substition'; } 23 function getSort() { return 32; } 24 25 function connectTo($mode) { 26 $this->Lexer->addSpecialPattern('~~codedoc:.*?~~',$mode,'plugin_codedoc_specials'); 27 } 28 29 function handle($match, $state, $pos, Doku_Handler $handler) { 30 $match = trim(substr($match,10,-2)); 31 $type = strtolower($match); 32 if(trim($type) == 'timestamp') { 33 return array($type, $state); 34 } 35 return array($match,$state); 36 } 37 38 function render($mode, Doku_Renderer $renderer, $data) { 39 global $ID; 40 if($mode == 'xhtml'){ 41 list($match, $state) = $data; 42 if(preg_match('/\s*xref:(.*)/i',$match,$matches)) { 43 $renderer->doc .= '<a name="' . trim(strtolower($matches[1])) . '"> </a>'; 44 return true; 45 } 46 47 if(preg_match('/\s*clean:(.*)/i',$match,$matches)) { 48 $data = $matches[1]; 49 $class="codedoc_clean"; 50 } 51 52 elseif($match == 'timestamp') { 53 $data = date("F d Y H:i:s.", filemtime(wikiFN($ID))); 54 } 55 elseif($match == 'user') { 56 global $INFO; 57 $userinfo = $INFO['userinfo']; 58 if(isset($userinfo) && isset($userinfo['name'])) { 59 $data = $userinfo['name']; 60 } 61 else $data = ""; 62 } 63 else { 64 $NL = '/* '; 65 $ENDL = ' */'; 66 $match = preg_replace_callback("/\[\[(.*?)\]\]/", 67 function($matches){ 68 $elems = explode("|",$matches[1]); 69 return htmlentities(html_wikilink($elems[0],$elems[1])); 70 }, 71 $match); 72 if(strpos($match, '<br') || strpos($match, '<BR') || strpos($match, "\n")) { 73 $NL .= "\n"; 74 $ENDL = "\n**/"; 75 } 76 else if(preg_match("/<(em|b)/",$match)) { 77 $NL = ''; 78 $ENDL = ''; 79 $match = preg_replace("/<(b|em|code)>/", "<$1 class = 'codedoc_hilite'>",$match); 80 $renderer->doc .= $match; 81 return true; 82 } 83 $data = "$NL $match $ENDL"; 84 $class='codedoc_hilite'; 85 } 86 $renderer->doc .= '<span class="' . $class. '">' .$data . '</span>'; 87 return true; 88 } 89 return false; 90 } 91} 92 93 94