* @version 2.0 * */ if(!defined('DW_LF')) define('DW_LF',"\n"); 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'); class syntax_plugin_clock extends DokuWiki_Syntax_Plugin { function getType(){ return 'substition'; } function getAllowedTypes() { return array(); } function getSort(){ return 290; } function getPType(){ return 'block'; } function connectTo($mode) { $this->Lexer->addSpecialPattern ( '^\{\{clock\}\}$', $mode, 'plugin_clock'); } function handle($match, $state, $pos, Doku_Handler $handler){ $data= array(); $theJS= $this->getConf('nojs_fallback'); // if 'nojs_fallback' is set, we get the time from the server // if 'clock_infopage' contains a link, we convert it /* compose the data array */ $data['type'] = $this->getConf('clock_type'); $data['style'] = $this->getConf('clock_style'); $data['text'] = $theJS ? date('H:i:s') : 'clock'; /* Are we ready yet? */ return $data; } function render($mode, Doku_Renderer $renderer, $data) { static $wasrendered= false; if ($wasrendered===true) {return true; } if ($mode == 'xhtml') { $nl = DW_LF; $cty = $this->getConf('clock_type'); $cid = $this->getConf('clock_id'); $html = $this->_clock_createblock_html($data, $cty); $hbar = ($this->getConf('helpbar')) ? $this->_get_clock_helpbar() : ''; $renderer->doc .= <<$html $hbar EOF; $wasrendered= true; } else if ($mode == 'odt') { return false; // may be implemented in the future } else if ($mode == 'text') { if ($wasrendered) return true; $text= ' ['. $c. ' '. date('H:i'). '] '; $renderer->doc .= $text; $wasrendered= true; return true; } /* That's all about rendering that needs to be done, at the moment */ return false; } /** * From this point onwards, local (helper) functions are implemented. */ /** * @fn dw_clock_helpbar * @brief Returns the contents of the help bar * The helpbar is displayed only when $conf['helpbar'] is set. */ private function _get_clock_helpbar () { $p.= '

'; $link= $this->getConf('clock_infopage'); if (empty($link) ) { // point to plugin page by default $info= '[[doku>plugin:clock|Clock Plugin]]'; } else { $info= "[[$link|Info]]"; } $info= p_render('xhtml', p_get_instructions($info), $info); $info= trim(substr($info, 4, -5)); // remove

,

$p.= $info; $p.= '

'; return $p; } private function _clock_createblock_html($data, $cty='text') { $theType = $data['type'] ?? 'text'; $theStyle = $data['style'] ?? 'plain'; $theText = $data['text']; $id= $this->getConf('clock_id'); $codetext= <<
{1}
EOF; if ($cty=== 'text' || $cty=== 'beats') { $s1= 'default'; } else if ($cty === 'binary') { $s1= << EOF; } $codetext= str_replace('{1}', $s1, $codetext); return $codetext; } }