-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyntax.php
51 lines (41 loc) · 1.63 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
<?php
/**
* Nextday Plugin: Display the date of the closest $WEEKDAY
*
* @license MIT (http://www.opensource.org/licenses/mit-license.php)
* @author Pavol Rusnak <[email protected]>
*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) die();
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_nextday extends DokuWiki_Syntax_Plugin {
function getType() { return 'substition'; }
function getPType() { return 'normal'; }
function getSort() { return 155; }
function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~NEXTDAY:[^~]*~~', $mode, 'plugin_nextday');
}
function handle($match, $state, $pos, Doku_Handler $handler) {
$in = explode(' ', substr($match,10,-2));
$day = NULL;
if (count($in) == 1) {
if (in_array($in[0], array('mon','tue','wed','thu','fri','sat','sun'))) {
$day = strtotime('next ' . $in[0], strtotime('yesterday'));
}
} else if (count($in) == 2) {
if (in_array($in[0], array('first','second','third','fourth','fifth','last')) &&
in_array($in[1], array('mon','tue','wed','thu','fri','sat','sun'))) {
$day_today = strtotime('today');
$day_next = strtotime("${in[0]} ${in[1]} of next month");
$day_this = strtotime("${in[0]} ${in[1]} of this month");
$day = ($day_this < $day_today) ? $day_next : $day_this;
}
}
return $day ? strftime('%d %B %Y', $day) : '';
}
function render($mode, Doku_Renderer $renderer, $data) {
$renderer->doc .= $data;
return true;
}
}
?>