====== Timer Plugin ====== ---- plugin ---- description: Show portion of page at specified time author : Otto Vainio email : otto@valjakko.net type : Syntax lastupdate : 2018-12-20 compatible : Greebo depends : conflicts : similar : tags : time, hide, date downloadurl: https://github.com/oiv/timer/zipball/master sourcerepo : https://github.com/oiv/timer bugtracker : https://github.com/oiv/timer/issues ---- ===== Description ===== With this plugin you can set portion of page to be displayed/hidden after specified date and time. The format is some **bold** text When you want to specify only the start time, then replace the end time with '-' [dash] some text > Added option P to print some helpful(?) debug information. You can use this e.g. when you do a review of the page. Good morning 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. Good morning ===== Installation ===== Using Plugin Manager from [[http://koti.mbnet.fi/oiv/pubtest/timer.zip|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: It is between 6 and 11 p.m. 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@valjakko.net|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@valjakko.net|Otto Vainio]] 2005-09-26 08:24// Ok, the debug option works fine. If I use the 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! --- //[[freddyw@gmx.net|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@valjakko.net|Otto Vainio]] 2005-10-21 17:43// >Hi. I put this text in a wiki page, > >Bom dia. > > > >Boa Tarde. > > > >Boa Noite. > > > >Já é tarde. > 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 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: Text to show * 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: Good morning Shows debug information (P option) * Have a nice weekend * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Otto Vainio * 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('(?=.*?\x3C/timer\x3E)',$mode,'plugin_timer'); } function postConnect() { $this->Lexer->addExitPattern('','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:" . strftime($conf['dformat']) . ""; $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:" . strftime($conf['dformat']) . ""; $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:" . strftime($conf['dformat']) . ""; } } } // 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".