3 * Plugin Countdown: Displays countdown from a specific date
4 * Syntax: <COUNTDOWN:date|description>
5 * date has to be formatted as GNU date (see strtotime)
6 * e.g. <COUNTDOWN:yyyy-mm-dd|description>
7 * <COUNTDOWN:mm/dd/yyy|description>
9 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
11 * @author Ekkart Kleinod <ekkart [at] ekkart.de> (V 2.x)
12 * @author Ron Peters <rbpeters [at] peterro.com> (V 1.0)
13 * @author Luis Machuca <luis [dot] machuca [at] gulix [dot] cl> (V 2.5+)
15 * @version 2.5rc (2009-12-18)
16 * under new management
17 * use Dokuwiki getLang, getConf functions
19 * countdown now displays hours and minutes left
20 * @version 2.1.3 (2009-01-24)
21 * french language file
22 * @version 2.1.2 (2008-07-20)
23 * estonian language file
24 * @version 2.1.1 (2008-04-17)
25 * polish language file
26 * correct swedish translation for 'today'
27 * @version 2.1 (2008-03-04)
28 * bugfix: no newline after "?>" (Warning: Cannot modify header information...)
29 * bugfix: computation of days with ceil (problem with 1 day into future)
30 * new: today, use_today
31 * @version 2.0.1 (2008-02-20)
32 * swedish language file
33 * @version 2.0 (2008-02-18)
34 * enhanced functionality
35 * enhanced input (using strtotime, and therefore GNU date formats)
36 * optional output of entered date
38 * based on a nucleuswiki plugin by Trent Adams | Edmond Hui
39 * basic input functionality
43 * Attention: the last characters of the file have to be "?>", no newline or something else
46 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__
).'/../../').'/');
47 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC
.'lib/plugins/');
48 require_once(DOKU_PLUGIN
.'syntax.php');
51 * Plugin-Class for Countdown-Plugin.
53 * All DokuWiki plugins to extend the parser/rendering mechanism
54 * need to inherit from DokuWiki_Syntax_Plugin
56 class syntax_plugin_countdown
extends DokuWiki_Syntax_Plugin
{
61 function syntax_plugin_countdown() {
62 // enable direct access to language strings
64 // enable direct access to configuration
65 //$this->loadConfig();
69 * Return plugin info for admin page.
73 'author' => 'Ekkart Kleinod',
74 'email' => 'ekkart@ekkart.de',
75 'date' => '2009-12-18',
76 'name' => 'Countdown v2.5rc',
77 'desc' => $this->getLang('desc'),
78 'url' => 'http://wiki.splitbrain.org/plugin:countdown',
83 * What kind of syntax are we?
98 * Connect pattern to lexer.
100 function connectTo($mode) {
101 $this->Lexer
->addSpecialPattern('\<COUNTDOWN\:.*?\>',$mode,'plugin_countdown');
107 function handle($match, $state, $pos, &$handler){
108 //strip <countdown: from start and > from end
109 $stripped = substr($match,11,-1);
110 // separate date from description
111 $stripped = explode('|',$stripped);
112 // $stripped has the form <date>|<description>|<format>
119 function render($mode, &$renderer, $data) {
121 if ($mode == 'xhtml') {
123 $parsedDate = strtotime($data[0]);
126 if ($parsedDate <= 0) {
127 $renderer->doc
.= $this->getLand('wrongformat'). $data[0] . ": " . $data[1];
132 $description = $data[1];
134 $description = $this->getLang('nodesc');
137 // compute date difference in days
138 // 86400 = 24*60*60 = seconds of one day
139 $diffseconds = $parsedDate - time(void
);
140 $difference = $diffseconds / 86400;
141 // convert $time into integer value
142 $difference = ceil($difference);
145 $difdata['days']= $difference;
146 $difdata['hours']= ($diffseconds / 3600) %
24;
147 $difdata['minutes']= ($diffseconds / 60) %
60;
148 $difdata['seconds']= ($diffseconds ) %
60;
149 // compute number of weeks according to full-week algorithm
153 if (($difference == 0) && $this->getConf('use_today') ) {
155 $renderer->doc
.= "<strong>" . $this->getLang('today') . "</strong>";
158 $renderer->doc
.= "<div align = center><strong>" . sprintf("%.0f", abs($difference)) . ' ';
159 $renderer->doc
.= (abs($difference) == 1) ?
$this->getLang('oneday') : $this->getLang('days');
160 $renderer->doc
.= ' ';
161 // if with_hours, ... hh:mm left ...
162 if ($this->getConf('with_hours') ) $renderer->doc
.= sprintf('%02d',$difdata['hours']). ':'. sprintf('%02d',$difdata['minutes']) . ' ';
163 // "since" or "until"
164 $renderer->doc
.= ($difference < 0) ?
$this->getLang('since') : $this->getLang('until');
165 $renderer->doc
.= "</strong> ";
167 $renderer->doc
.= " " . $description . "</div>";
170 if ($this->getConf('include_date') ) {
171 $renderer->doc
.= " (" . strftime($this->getLang('outputformat'), $parsedDate) . ")";