forked from alexandrebastien/minical
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.php
More file actions
284 lines (241 loc) · 10.1 KB
/
syntax.php
File metadata and controls
284 lines (241 loc) · 10.1 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/**
* DokuWiki Syntax Plugin MiniCal
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Alexandre Bastien <alexandre.bastien@fsaa.ulaval.ca>
* Forked from WikiCalendar (Michael Klier <chi@chimeric.de>)
*/
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_minical extends DokuWiki_Syntax_Plugin {
// namespace of the calendar
var $calendar_ns = '';
// namespace of the current viewed month
var $month_ns = '';
// indicator if first week of the month has been generated
var $firstWeek = false;
// array with localisations of weekdays
var $langDays = array();
// array with localistaions of month
var $langMonth = array();
// the current date
var $curDate = array();
// the month to show
var $showMonth = '';
// the year to show
var $showYear = '';
// the global timestamp for date-operations
var $gTimestamp = '';
// number days of the current month
var $numDays = '';
// date-date to generate the calendar
var $viewDate = array();
// return some info
function getInfo(){
return array(
'author' => 'Alexandre Bastien',
'email' => 'alexandre.bastien@fsaa.ulaval.ca',
'date' => @file_get_contents(DOKU_PLUGIN.'minical/VERSION'),
'name' => 'MiniCal Plugin',
'desc' => 'Implements a simple Calendar with links to wikipages. Stripped down version forked from Michael Klier\'s minical',
'url' => 'http://dokuwiki.org/plugin:minical'
);
}
/**
* Some Information first.
*/
function getType() { return 'substition'; }
function getPType() { return 'block'; }
function getSort() { return 125; }
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('{{minical>.+?}}',$mode,'plugin_minical');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
$match = substr($match,10,-2);
return array($match);
}
/**
* Create output
*/
function render($mode, Doku_Renderer $renderer, $data) {
global $ID;
global $conf;
if($mode == 'xhtml'){
$tz = date_default_timezone_get();
if($this->getConf('timezone')) {
date_default_timezone_set($this->getConf('timezone'));
}
// define some variables first
$this->calendar_ns = ($data[0]) ? $data[0] : $ID;
$this->langDays = $this->getLang('days');
$this->langMonth = $this->getLang('month');
$this->curDate = getdate(time());
$this->showMonth = (is_numeric($_REQUEST['plugin_minical_month'])) ? $_REQUEST['plugin_minical_month'] : $this->curDate['mon'];
$this->showYear = (is_numeric($_REQUEST['plugin_minical_year'])) ? $_REQUEST['plugin_minical_year'] : $this->curDate['year'];
$this->gTimestamp = mktime(0,0,0,$this->showMonth,1,$this->showYear);
$this->numDays = date('t',$this->gTimestamp);
$this->viewDate = getdate($this->gTimestamp);
$this->today = ($this->viewDate['mon'] == $this->curDate['mon'] &&
$this->viewDate['year'] == $this->curDate['year']) ?
$this->curDate['mday'] : null;
// if month directory exists we keep the old scheme
if(is_dir($conf['datadir'].'/'.str_replace(':','/',$this->calendar_ns.':'.$this->showYear.':'.$this->showMonth))) {
$this->month_ns = $this->calendar_ns.':'.$this->showYear.':'.$this->showMonth;
} else {
if($this->showMonth < 10) {
$this->month_ns = $this->calendar_ns.':'.$this->showYear.':0'.$this->showMonth;
} else {
$this->month_ns = $this->calendar_ns.':'.$this->showYear.':'.$this->showMonth;
}
}
if($this->MonthStart == 7 && $this->getConf('weekstart') == 'Sunday') {
$this->MonthStart = 0;
} else {
$this->MonthStart = ($this->viewDate['wday'] == 0) ? 7 : $this->viewDate['wday'];
}
// turn off caching
$renderer->info['cache'] = false;
$renderer->doc .= '<div class="plugin_minical">' . DOKU_LF;
$renderer->doc .= $this->_month_xhtml();
$renderer->doc .= '</div>' . DOKU_LF;
date_default_timezone_set($tz);
return true;
}
return false;
}
// Renders the Calendar (month-view)
function _month_xhtml() {
global $ID;
$script = script();
$prevMonth = ($this->showMonth-1 > 0) ? ($this->showMonth-1) : 12;
$nextMonth = ($this->showMonth+1 < 13) ? ($this->showMonth+1) : 1;
switch(true) {
case($prevMonth == 12):
$prevYear = ($this->showYear-1);
$nextYear = $this->showYear;
break;
case($nextMonth == 1):
$nextYear = ($this->showYear+1);
$prevYear = $this->showYear;
break;
default:
$prevYear = $this->showYear;
$nextYear = $this->showYear;
break;
}
// create calendar-header
$out .= <<<CALHEAD
<table class="plugin_minical">
<tr>
<td class="month">
<form action="{$script}" method="post" class="prevnext">
<input type="hidden" name="id" value="{$ID}" />
<input type="hidden" name="plugin_minical_year" value="{$prevYear}" />
<input type="hidden" name="plugin_minical_month" value="{$prevMonth}" />
<input type="submit" class="btn_prev_month" name="submit" value="←" accesskey="P" title="{$this->langMonth[$prevMonth]} {$prevYear}" />
</form>
</td>
<td class="month" colspan="3">{$this->langMonth[$this->viewDate['mon']]}</td>
<td class="month" colspan="2">{$this->showYear}</td>
<td class="month">
<form action="{$script}" method="post" class="prevnext">
<input type="hidden" name="id" value="{$ID}" />
<input type="hidden" name="plugin_minical_year" value="{$nextYear}" />
<input type="hidden" name="plugin_minical_month" value="{$nextMonth}" />
<input type="submit" class="btn_next_month" name="submit" value="→" accesskey="N" title="{$this->langMonth[$nextMonth]} {$nextYear}" />
</form>
</td>
</tr>
CALHEAD;
// create calendar weekday-headers
$out .= "<tr>";
if($this->getConf('weekstart') == 'Sunday') {
$last = array_pop($this->langDays);
array_unshift($this->langDays, $last);
}
foreach($this->langDays as $day) {
$out .= '<td class="weekday">'.$day.'</td>';
}
$out .= "</tr>\n";
// create calendar-body
for($i=1;$i<=$this->numDays;$i++) {
$day = $i;
//set day-wikipage - use leading zeros on new pages
if($day < 10) {
if(page_exists($this->month_ns.':'.$day)) {
$dayWP = $this->month_ns.':'.$day;
} else {
$dayWP = $this->month_ns.':0'.$day;
}
} else {
$dayWP = $this->month_ns.':'.$day;
}
// close row at end of week
if($wd == 7) $out .= '</tr>';
// set weekday
if(!isset($wd) or $wd == 7) { $wd = 0; }
// start new row when new week starts
if($wd == 0) $out .= '<tr>';
// create blank fields up to the first day of the month
$offset = ($this->getConf('weekstart') == 'Sunday') ? 0 : 1;
if(!$this->firstWeek) {
while($wd < ($this->MonthStart - $offset)) {
$out .= '<td class="blank"> </td>';
$wd++;
}
// ok - first week is printet
$this->firstWeek = true;
}
// check for today
if($this->today == $day) {
$out .= '<td class="today">'.$this->_calendar_day($dayWP,$day).'</td>';
} else {
$out .= '<td class="day">'.$this->_calendar_day($dayWP,$day).'</td>';
}
// fill remaining days with blanks
if($i == $this->numDays && $wd < 7) {
while($wd<6) {
$out .= '<td class="blank"> </td>';
$wd++;
}
$out .= '</tr>';
}
// dont forget to count weekdays
$wd++;
}
// finally close the table
$out .= '</table>';
return ($out);
}
// Generates the content of each day in the calendar-table.
function _calendar_day($wp, $day) {
global $lang;
global $ID;
if(file_exists(wikiFN($wp))) {
$out .= '<div class="isevent">';
if(auth_quickaclcheck($wp) >= AUTH_READ) {
}
$out .= '<div class="day_num"><a href="' . wl($wp) . '" class="wikilink1" title="' . $wp . '">'.$day.'</a></div>';
$out .= '<div class="abstract">' . p_get_metadata($wp, 'description abstract') . '</div>' . DOKU_LF;
} else {
$out .= '<div class="noevent">';
if(auth_quickaclcheck($wp) >= AUTH_CREATE) {
$out .= '<a href="' . wl($wp, array('do' => 'edit', 'plugin_minical_redirect_id' => $ID, 'plugin_minical_month' => $this->showMonth, 'plugin_minical_year' => $this->showYear)) . '" class="plugin_minical_btn" title="' . $lang['btn_create'] . '">'.$day.'</a>' . DOKU_LF;
}
}
$out .= '</div>';
return ($out);
}
}