DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:timer

Timer Plugin

Compatible with DokuWiki

Greebo

plugin Show portion of page at specified time

Last updated on
2018-12-20
Provides
Syntax
Repository
Source

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with date, hide, time

Description

With this plugin you can set portion of page to be displayed/hidden after specified date and time. The format is

<timer 2005-08-11 08:00:00=2005-08-11 09:01:00>
   some **bold** text
</timer>

When you want to specify only the start time, then replace the end time with '-' [dash]

<timer 2005-08-04 16:33:00=->
  some text
</timer>
Added option P to print some helpful(?) debug information. You can use this e.g. when you do a review of the page.
<timer P 2005-08-04 07:00:00=2005-08-04 11:00:00>Good morning</timer>

The plugin sets that page as not cached when the timeperiod for the starttime or endtime is before the next cache refresh. This way you don't need to set the $conf['cachetime'] to anything too short.

The plugin should now work properly with only times.
<timer 07:00:00=11:00:00>
   Good morning
</timer>

Installation

Using Plugin Manager from here

Plugin

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

lib/plugin/timer/syntax.php:

Discussion

Nice Plugin, but in my installation it sometimes doesn't work. When I call the Wiki-Page:

<timer 18:00:01=23:00:00>
It is between 6 and 11 p.m.
</timer>

at 20:00 system time nothing appears.

vs241008:~# date
Thu Sep 22 20:00:20 CEST 2005

Thanks for hints. Bye Frank

You have to put the date in the input. I will try to update this to use without date. — Otto Vainio 2005-09-23 15:00

That would be great! Thanks, Frank

This should work. I added option P for the new version. This will show what time mktime() function gives you. It may have something to do with local/UTC time settings. Don't know.. — Otto Vainio 2005-09-26 08:24

Ok, the debug option works fine. If I use the <timer> without date (like mentioned before) it works only on the day where I save the Wiki page. Two days later I have for example the following debug output:

From:2005-10-04 18:00 To:2005-10-04 22:00 Now:2005-10-06 19:22

which means that the day of the last side change is implicit within the directive. Bye Frank

Ok I think I got it now. I probably should move the time parsing to the render function. This should fix it. I will check that.
Now this time is should work. ;-)

Yes, now it is working great! Nice. Thanks Frank


“Bug”: a footnote in the timered section is placed at the bottom of this section, not at bottom of page. No problem to me, just to let you and other users know… Thank you very much for this feature! — Freddy 2005-10-17 15:00 > I think it is this call

$renderer->doc .= p_render('xhtml',p_get_instructions($match),$info);

But how to fix it??? Let's just call it a feature now ;-)Otto Vainio 2005-10-21 17:43

Hi. I put this text in a wiki page,
<code><timer 07:00:01=12:00:00>
Bom dia.
</timer>

<timer 12:00:01=20:00:00>
Boa Tarde.
</timer>

<timer 20:00:01=23:00:00>
Boa Noite.
</timer>

<timer 23:00:01=07:00:00>
Já é tarde.
</timer><code> at the 18:26 and it give me Boa Tarde and Boa noite. And its Boa tarde the correct.
I don't think you need the <code> part, but if yes, the last one is missing the '/'. Try modifying it to see. Just a quick idea.

For me the plugin didnt work well, so I tried fixing things. Problem one was incorrect date format. Minutes were incorrect. This was due to the time format difference between date and strftime. Second problem was incorrect end time detection, except when using debug (P). Correction one: replace date( with strftime( Correction two: line 71 should only be used when using debug → put inside if statement. Complete corrected code:

syntax.php
<?php
  /**
  * Plugin Timer: Displays content at given time. (After next cache update)
  * Format: <TIMER [P ]starttime=[endtime|-]> Text to show </TIMER>
  * Time format must be parseable with 
  * {@LINK http://www.php.net/manual/en/function.strtotime.php php strtotime}
  * Valid timestamp formats are descibed {@LINK http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html here}
  * 
  * Examples: <TIMER P 07:00:00=10:00:00>Good morning</TIMER> Shows debug information (P option)
  *           <TIMER 2005-09-24 00:00:00=2005-09-25 23:59:00> Have a nice weekend</TIMER>
  * 
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * @author     Otto Vainio <oiv-timer@valjakko.net>
  * Updated     26-10-2014 by Roelski
  */
 
  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_timer extends DokuWiki_Syntax_Plugin {
 
    /**
    * return some info
    */
    function getInfo(){
      return array(
        'author' => 'Otto Vainio',
        'email'  => 'oiv-plugins@valjakko.net',
        'date'   => '2005-10-10',
        'name'   => 'Timer plugin',
        'desc'   => 'Show content at this time',
        'url'    => 'http://wiki.splitbrain.org/wiki:plugins',
      );
    }
 
    /**
    * What kind of syntax are we?
    */
    function getType(){
      return 'substition';
    }
 
    function getSort(){ 
      return 358;
    }
    function connectTo($mode) { 
      $this->Lexer->addEntryPattern('<timer.*?>(?=.*?\x3C/timer\x3E)',$mode,'plugin_timer'); 
    }
    function postConnect() { 
      $this->Lexer->addExitPattern('</timer>','plugin_timer'); 
    }
 
 
    /**
    * Handle the match
    */
    function handle($match, $state, $pos, &$handler){
      global $conf;
      switch ($state) {
        case DOKU_LEXER_ENTER :
          $str = substr($match, 7, -1);
          //$conf['dformat']
          $prt=0;
          if (substr($str,0,1)=="P") {
            $prt=1;
            $str=substr($str,1);
          }
          list($starttime, $endtime) = preg_split("/=/u", $str, 2);
          return array($state, array($prt,$starttime,$endtime));
        case DOKU_LEXER_UNMATCHED :  return array($state, $match);
        case DOKU_LEXER_EXIT :       return array($state, '');
      }
      return array();
    }
 
    /**
    * Create output
    */
    function render($mode, &$renderer, $data) {
      global $st;
      global $et;
      global $conf;
      global $prt;
      if($mode == 'xhtml'){
        list($state, $match) = $data;
        switch ($state) {
        case DOKU_LEXER_ENTER :      
          list($prts,$starttime,$endtime) = $match;
          $err = "";
          if (($timestamp = strtotime($starttime)) === -1) {
            // If time false do not show.
            $sts = mktime()+10000;
            $err= "Starttime ($starttime) is invalid";
          } else {
            $sts = $timestamp;
          }
          if ($endtime=="-") {
            $ets = strtotime("+1 days");
          } else {
            if (($timestamp = strtotime($endtime)) === -1) {
              // If time false do not show.
              $ets = mktime()-10000;
              $err .= " Endtime ($endtime) is invalid";
            } else {
              $ets = $timestamp;
            }
          }
          $prt = $prts;
          $st = $sts;
          $et = $ets;
          $renderer->doc .= $err;
          break;
        case DOKU_LEXER_UNMATCHED :
          $now = mktime();
          if (($st<$now) && ($et>$now)) {
            if ($prt>0) {
              $renderer->doc .= " From:" . strftime($conf['dformat'],$st);
              $renderer->doc .= " Now:<b>" . strftime($conf['dformat']) . "</b>";
              $renderer->doc .= " To:" . strftime($conf['dformat'],$et);
            }
              $renderer->doc .= p_render('xhtml',p_get_instructions($match),$info);
          } else {
            if ($prt>0) {
              if ($now<$st) {
                $renderer->doc .= " Now:<b>" . strftime($conf['dformat']) . "</b>";
                $renderer->doc .= " From:" . strftime($conf['dformat'],$st);
                $renderer->doc .= " To:" . strftime($conf['dformat'],$et);
              } else {
                $renderer->doc .= " From:" . strftime($conf['dformat'],$st);
                $renderer->doc .= " To:" . strftime($conf['dformat'],$et);
                $renderer->doc .= " Now:<b>" . strftime($conf['dformat']) . "</b>";
              }
 
            }
          }
          // Disable cache if start or end time within now and next cache refresh time
          if (($now>$st-$conf['cachetime'] && $now<$st) || ($now>$et-$conf['cachetime'] && $now<$et)) {
            $renderer->nocache();
          }
          $renderer->doc .= $cac;
          break;
        case DOKU_LEXER_EXIT :
          break;
        }
        return true;
      }
      return false;
    }
  }
?>

The timer plugin does not work with the installed PHP 8.x. The error when using it on a page is “mktime() expects at least 1 argument, 0 given”. This error can be eliminated by replacing the mktime() function with the time() function in “/var/www/html/dokuwiki/lib/plugins/timer/syntax.php”.

plugin/timer.txt · Last modified: 2023-01-19 22:14 by 91.115.199.69

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki