-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsyntax.php
More file actions
117 lines (100 loc) · 3.32 KB
/
syntax.php
File metadata and controls
117 lines (100 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
// include git utils, they should be located on same directory with syntax.php
require_once('git-utils.inc.php');
function find_end($string, $offset = 0)
{
if($offset >= strlen($string))
return FALSE;
for($i = $offset; $i < strlen($string); $i++)
{
if(!is_numeric($string[$i]))
return $i;
}
return strlen($string);
}
class syntax_plugin_dokugitviewer extends DokuWiki_Syntax_Plugin {
function getType(){
return 'substition';
}
function getSort(){
return 999;
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('<dokugitviewer:.+?>',$mode,'plugin_dokugitviewer');
}
function handle($match, $state, $pos, &$handler)
{
$start = strlen('<dokugitviewer:');
$end = -1;
$params = substr($match, $start, $end);
$params = preg_replace('/\s{2,}/', '', $params);
$params = preg_replace('/\s[=]/', '=', $params);
$params = preg_replace('/[=]\s/', '=', $params);
$return = array();
foreach(explode(' ', $params) as $param)
{
$val = explode('=', $param);
$return[$val[0]] = $val[1];
}
return $return;
}
function render($mode, &$renderer, $data) {
$elements = array('ft' => 'features',
'bug' => 'bugs');
if($mode == 'xhtml'){
if(isset($data['repository']))
{
if(isset($data['limit']) && is_numeric($data['limit']))
$limit = (int)($data['limit']);
else
$limit = 10;
if (empty($data['bare']))
$bare=false;
else
$bare=true;
$log = git_get_log($data['repository'], $limit,$bare);
$renderer->doc .= '<ul class="dokugitviewer">';
foreach($log as $row)
{
$renderer->doc .= '<li>';
$message = $row['message'];
for($index = 0; $index < strlen($message); $index++)
{
$char = $message[$index];
if($char == '#')
{
foreach(array_keys($elements) as $element)
{
$cmp = '#'.$element;
$src = substr($message, $index, strlen($cmp));
if(strstr($src, $cmp))
{
$key = substr($message, $index+1, strlen($cmp)-1);
$src= substr($message, $index+1+strlen($key));
$value = substr($src, 0, find_end($src));
$index += strlen($element.$value);
$renderer->internallink($data[$elements[$element]].'#'.$element.$value, '#'.$element.$value);
}
}
}
else
$renderer->doc .= $char;
}
//$renderer->doc .= '<strong>'.$message.'</strong>';
$renderer->doc .= '<br />';
$renderer->doc .= $row['author'].' on ';
$renderer->doc .= date(DATE_FORMAT,$row['timestamp']);
$renderer->doc .= '</li>';
}
$renderer->doc .= '</ul>';
}
return true;
}
return false;
}
}
?>