Countdown Plugin

By Ron Peters. This is a modified version of the nucleuswiki plugin by Trent Adams and Edmond Hui

Description

With this plugin you can insert a countdown into your page where it will display the number of days till or since the text that you include. The format is:

<COUNTDOWN:mm,dd,yyyy|the day to remember>

This will be replaced with:

XX days until the day to remember

or

XX days since the day to remember

Installation

Install with Plugin Manager from here

Plugin

Create a new folder lib/plugin/countdown/ and place the following file in it: syntax.php.

lib/plugin/countdown/syntax.php:

<?php
/**
 * Plugin Countdown: Displays countdown from a specific date
 *                   Syntax: <COUNTDOWN:mm,dd,yyyy|text being counted to>
 * 
 * @author  Ron Peters based on a nucleuswiki plugin by Trent Adams | Edmond Hui
 */
 
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_countdown extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Ron Peters',
            'email'  => 'rbpeters@peterro.com',
            'date'   => '2007-09-21',
            'name'   => 'Countdown',
            'desc'   => 'This plugin can be used to display days until a specified day using the parameters in the plugin.  Use is <COUNTDOWN:3,23,2004|My 2nd Aniversary> to show x days until (or since if the day is in the past) My 2nd Anniversary on March 23rd, 2004.  It is based on a nucleuswiki plugin by Trent Adams and Edmond Hui',
            'url'    => 'http://www.peterro.com/',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 721;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('\<COUNTDOWN\:.*?\>',$mode,'plugin_countdown');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        //strip <countdown: from start and > from end 
        $match = substr($match,11,-1);
        $match = explode("|",$match);
        //return array();
        return $match;
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
 
                $passed = explode(",",$data[0]);
 
                if ($data[1]){
                        $theword = $data[1];
                } else {
                        $theword = "need countdown day,";
                }
 
                if ($passed[0]){
                        $themonth = $passed[0];
                } else {
                        $theword = "need month,";
                }
 
                if ($passed[1]){
                        $theday = $passed[1];
                } else {
                        $theword = "need day,";
                }
 
                if ($passed[2]){
                        $theyear = $passed[2];
                } else {
                        $theword = "need year,";
                }
 
                $time = ((mktime (0,0,0,$themonth,$theday,$theyear) - time(void))/86400);
                $when = "until";
                if ($time < 0){
                        $when = "since";
                }
 
                $the_time = sprintf("%.0f",abs($time));
                $renderer->doc .="<b>" . $the_time . "</b> days " . $when . ' ' . $theword;
                return true;
 
        }
        return false;
    }
}
?>

Discussion

 
dokuwiki/plugins.txt · Last modified: 2007/09/22 08:33 by rbpeters
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki