1<?php 2/** 3 * Nextday Plugin: Display the date of the closest $WEEKDAY 4 * 5 * @license MIT (http://www.opensource.org/licenses/mit-license.php) 6 * @author Pavol Rusnak <stick@gk2.sk> 7 */ 8 9if(!defined('DOKU_INC')) die(); 10if(!defined('DOKU_PLUGIN')) die(); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13class syntax_plugin_nextday extends DokuWiki_Syntax_Plugin { 14 15 function getType() { return 'substition'; } 16 17 function getPType() { return 'normal'; } 18 19 function getSort() { return 155; } 20 21 function connectTo($mode) { 22 $this->Lexer->addSpecialPattern('~~NEXTDAY:[^~]*~~', $mode, 'plugin_nextday'); 23 } 24 25 function handle($match, $state, $pos, Doku_Handler $handler) { 26 $in = explode(' ', substr($match,10,-2)); 27 $day = NULL; 28 if (count($in) == 1) { 29 if (in_array($in[0], array('mon','tue','wed','thu','fri','sat','sun'))) { 30 $day = strtotime('next ' . $in[0], strtotime('yesterday')); 31 } 32 } else if (count($in) == 2) { 33 if (in_array($in[0], array('first','second','third','fourth','fifth','last')) && 34 in_array($in[1], array('mon','tue','wed','thu','fri','sat','sun'))) { 35 $day_today = strtotime('today'); 36 $day_next = strtotime("${in[0]} ${in[1]} of next month"); 37 $day_this = strtotime("${in[0]} ${in[1]} of this month"); 38 $day = ($day_this < $day_today) ? $day_next : $day_this; 39 } 40 } 41 return $day ? strftime('%d %B %Y', $day) : ''; 42 } 43 44 function render($mode, Doku_Renderer $renderer, $data) { 45 $renderer->doc .= $data; 46 return true; 47 } 48 49} 50 51?> 52