-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsyntax.php
87 lines (68 loc) · 1.89 KB
/
syntax.php
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
<?php
/**
* Display Fortune cookies
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
class syntax_plugin_xfortune extends DokuWiki_Syntax_Plugin {
/**
* What kind of syntax are we?
*/
function getType() {
return 'substition';
}
/**
* What about paragraphs?
*/
function getPType() {
return 'block';
}
/**
* Where to sort in?
*/
function getSort() {
return 302;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{xfortune>[^}]*\}\}', $mode, 'plugin_xfortune');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler) {
$match = substr($match, 11, -2); //strip markup from start and end
$data = array();
//handle params
list($cookie, $params) = explode('?', $match, 2);
//xfortune cookie file
$data['cookie'] = cleanID($cookie);
//time interval for changing cookies
$data['time'] = 30;
if(preg_match('/\b(\d+)\b/i', $params, $match)) {
$data['time'] = (int) $match[1];
}
//no hammering please!
if($data['time'] < 5) $data['time'] = 5;
return $data;
}
/**
* Create output
*/
function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return false;
$attr = array(
'class' => 'plugin_xfortune',
'data-time' => $data['time'],
'data-cookie' => $data['cookie']
);
$renderer->doc .= '<div ' . buildAttributes($attr) . '>';
$renderer->doc .= helper_plugin_xfortune::getCookieHTML($data['cookie']);
$renderer->doc .= '</div>';
return true;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :