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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
-
+
-
-
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
-
+
-
+
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
+
-
-
-
+
+
-
-
+
+
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
|
<?php
/**
* Clock Plugin: Shows realtime clock
*
* @file clock/syntax.php
* @brief Show a clock in wikipage
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Luis Machuca B. <luis.machuca@gulix.cl>
* @version 1.0
*
* -----
* @author Luis Machuca Bezzaza <luis.machuca [at] gulix.cl>
* @version 1.5
* @date 2010-10-15
* @link http://www.dokuwiki.org/plugin:clock
* No longer in 'experimental'!
* -----
*
* This plugin's purpose is to display a clock using both
* CSS and JavaScript techniques normally available.
*
* For a live test point a decent web browser to my wiki.
* http://informatica.temuco.udelmar.cl/~lmachuca/dokuwiki-lucho/
* For a live test point a decent web browser to my wiki.
* http://ryan.gulix.cl/dw/desarrollo/
*
* Greetings.
* - Luis Machuca B. a.k.a. 'ryan.chappelle'
* - Luis Machuca Bezzaza a.k.a. 'ryan.chappelle'
*/
if(!defined('DW_LF')) define('DW_LF',"\n");
if(!defined('DOKU_INC'))
define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN'))
define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_clock extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
function getInfo() {
return array(
'author' => 'Luis Machuca B.',
'email' => 'luis.machuca@gulix.cl',
'date' => '2008-12-24',
'author' => 'Luis Machuca Bezzaza',
'email' => 'luis.machuca [at] gulix.cl',
'date' => '2010-10-15',
'name' => 'Clock Plugin',
'desc' => 'Shows a JavaScript-based clock',
'url' => 'http://wiki.splitbrain.org/plugin:clock',
'desc' => $this->getLang('descr'),
'url' => 'http://www.dokuwiki.org/plugin:clock',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* What can we Do?
*/
//function getAllowedTypes() {
// return array();
function getAllowedTypes() {
return array();
//}
/* A/N: getAllowedTyped is intentionally non-defined. */
}
/**
* Where to sort in?
*/
function getSort(){
return 299;
return 290;
}
/**
* What's our code layout?
*/
function getPType(){
return 'normal';
return 'block';
}
/**
* How do we get to the lexer?
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern (
'^\{\{clock\}\}$', $mode, 'plugin_clock');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
$data= array();
// get the clock ID and JS fallback flag
$theCS= $this->getConf('clock_style');
$theJS= $this->getConf('nojs_fallback');
$theWL= $this->getConf('clock_infopage');
// if 'nojs_fallback' is set, we get the time from the server
// if 'clock_infopage' contains a link, we convert it
/* compose the data array */
$data['style'] = $theCS;
$data['text'] = $theJS ? date('H:i:s') : $theCS;
$data['dolink'] = !empty($theWL);
$data['target'] = !empty($theWL) ? wl($theWL) : '';
/* Are we ready yet? */
return $data;
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
/* get the data from $data */
static $wasrendered= false;
static $wasrendered= false;
if ($mode == 'xhtml') {
if ($wasrendered == true) {
/* already rendered: nothing to do.
if (!$wasrendered) {
$nl = DW_LF;
$cid = $this->_get_clock_object_ID();
$html = $this->_clock_createblock_html($data);
$hbar = ($this->getConf('helpbar')) ? $this->_get_clock_helpbar() : '';
$renderer->doc .= <<<EOF
<div id="$cid">$nl $html $hbar$nl </div><!-- end clock-->
EOF;
$wasrendered= true;
*/
return true;
}
if($mode == 'xhtml'){
$renderer->doc .= $this->_clock_createblock_html($data);
$wasrendered= true;
return true;
}
else {
$renderer->doc.= <<<EOF
<p><a href="#$cid" class="wikilink" title="Go To Clock">⌚ clock</a></p>
EOF;
}
return true;
}
else if ($mode == 'odt') {
return false; // may be implemented in the future
}
else if ($mode == 'text') {
if ($wasrendered) return true;
$text= ' ['. $this->_get_clock_object_ID(). ' '. date('H:i'). '] ';
$renderer->doc .= $text;
$wasrendered= true;
return true;
}
if($mode == 'odt'){
return false; // may be implemented in the future
}
/* That's all about rendering that needs to be done, at the moment */
return false;
/* That's all about rendering that needs to be done, at the moment */
return false;
}
/**
* From this point onwards, local (helper) functions are implemented
*/
/**
* @fn dw_clock_object_ID
* @brief returns ID for the clock object
* This function sets the name used for the ID of the clock object.
* It is intended to return a somewhat unique name.
* If you want to change it, you may also want to update
* If you change it, you must also update the #id tags in 'style.css'.
* the #id tags in the 'style.css' file.
*/
function _get_clock_object_ID () {
return 'dw_clock_object';
}
return $this->getConf('clock_id');
}
/**
* @fn dw_clock_object_infoelem
* @brief Returns the tip fot the help element
* @fn dw_clock_helpbar
* @brief Returns the contents of the help bar
* This function returns the content (text) associated with the
* clock object's "help link". The text here is
* *not parsed by DokuWiki*.
* The helpbar is displayed only when $conf['helpbar'] is set.
*/
function _get_clock_object_infoelem () {
return '(?)';
private function _get_clock_helpbar () {
$p.= '<p class="helpbar" >';
$link= $this->getConf('clock_infopage');
if (empty($link) ) { // point to plugin page by default
$info= '[[doku>plugin:clock|Clock Plugin]]';
}
else {
$info= "[[$link|Info]]";
}
$info= p_render('xhtml', p_get_instructions($info), $info);
$info= trim(substr($info, 4, -5)); // remove <p>, </p>
$p.= $info;
$p.= '</p>';
return $p;
}
/**
* @fn _clock_createblock_html
* @brief Creates the HTML code for the clock object.
*/
function _clock_createblock_html($data) {
private function _clock_createblock_html($data) {
$theStyle = $data['style'];
$theText = $data['text'];
$theDoLink = $data['dolink'];
$theTarget = $data['target'];
$codetext.= '<div id="'. $this->_get_clock_object_ID(). '"' .
' class="'. $theStyle. '">';
$codetext.= '<div id="clock_face" class="face">'. $theText.
'</div>'. DW_LF;
$codetext.= '<div id="clock_face" class="'. $theStyle. ' face">'.
$theText. '</div>';
if ($theDoLink) {
$codetext.= '<span class="info">';
$codetext.= '<a href="'. $theTarget. '">'.
$this->_get_clock_object_infoelem(). '</a>'.
'</span>';
}
$codetext.= '</div>'. DW_LF;
return $codetext;
}
}
/*?> */
|