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])) . '">&nbsp;</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                       create_function(
68                       '$matches',
69                       '$elems = explode("|",$matches[1]);
70                       return html_wikilink($elems[0],$elems[1]);'
71                       ),
72                       $match);
73                 if(strpos($match, '<br') || strpos($match, '<BR') || strpos($match, "\n")) {
74                   $NL .= "\n";
75                   $ENDL = "\n**/";
76                 }
77                 else if(preg_match("/<(em|b)/",$match)) {
78                    $NL = '';
79                    $ENDL = '';
80                    $match = preg_replace("/<(b|em|code)>/", "<$1 class = 'codedoc_hilite'>",$match);
81					$renderer->doc .= $match;
82					return true;
83                 }
84                 $data = "$NL $match $ENDL";
85                 $class='codedoc_hilite';
86            }
87            $renderer->doc .= '<span class="' . $class. '">' .$data . '</span>';
88            return true;
89        }
90        return false;
91    }
92}
93
94
95