* * Plugin tiledblog: display blog in tile */ if (!defined ('DOKU_INC')) die (); if (!defined ('DOKU_PLUGIN')) define ('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); require_once (DOKU_PLUGIN.'syntax.php'); class syntax_plugin_tiledblog extends DokuWiki_Syntax_Plugin { // ============================================================ function getInfo () { return confToHash (dirname (__FILE__).'/INFO.txt'); } function getType () { return 'substition'; } function getPType () { return 'block'; } function getSort () { return 299; } function connectTo ($mode) { $this->Lexer->addSpecialPattern ('\{\{tiledBlog.*?\}\}', $mode, 'plugin_tiledblog'); } // ============================================================ function handle ($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_SPECIAL : return trim (substr ($match, 11, -2)); // "{{tiledBlog" => 11 "}}" => 2 } return false; } // ============================================================ function render ($mode, Doku_Renderer $renderer, $indata) { if ($mode != 'xhtml') return false; $data = " ".$indata." "; if (preg_match_all ("#(\"[^\"]*\")* help (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0) { $this->help ($renderer); return true; } global $ID; $ns = getNS ($ID); // namespace if (preg_match_all ("#^ >([^ ]*) .*#", strtolower ($data), $dumy) > 0) { $ns = $dumy[1][0]; if (($ns == '*') || ($ns == ':')) $ns = ''; elseif ($ns == '.') $ns = getNS ($ID); else $ns = cleanID ($ns); } global $conf; $savedir = ((!$conf['savedir'] || strpos ($conf['savedir'], '.') === 0) ? DOKU_INC : "").$conf['savedir']."/"; $cacheDir = $savedir."cache/tiledblog/"; if (!is_dir ($cacheDir)) { @mkdir ($cacheDir); @chmod ($cacheDir, 0775); } $renderer->info ['cache'] = FALSE; if (preg_match_all ("#(\"[^\"]*\")* sample (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0) { $this->sample ($renderer, $ns, $cacheDir); return true; } $this->tile ($renderer, $ns, $cacheDir); return true; } // ============================================================ function sample (Doku_Renderer $renderer, $ns, $cacheDir) { $filename = $cacheDir.md5($ns)."-sample.cache"; if (file_exists ($filename) && (time () - filemtime ($filename) < $this->getConf ('sampleDelai'))) { $renderer->doc .= file_get_contents ($filename); return; } if ($helperPlugin =& plugin_load ('helper', 'blog')) { $entries = $helperPlugin->getBlog ($ns); $width = $this->getConf ('iconSize'); $keys = array_keys ($entries); $rand = array_rand ($keys); $text = $this->getEntry ($entries [$keys [$rand]], $width); $renderer->doc .= $text.NL; file_put_contents ($filename, $text); } } // ============================================================ function tile (Doku_Renderer $renderer, $ns, $cacheDir) { $formPos = $this->getConf ('formPosition'); $blogPlugin =& plugin_load ('syntax', 'blog_blog'); $createPerm = (auth_quickaclcheck ($ns.':*') >= AUTH_CREATE); if ($formPos == 'top') $this->displayForm ($renderer, $blogPlugin, $ns, $createPerm); $filename = $cacheDir.md5($ns)."-tile.cache"; if (file_exists ($filename) && (time () - filemtime ($filename) < $this->getConf ('sampleDelai'))) { $renderer->doc .= file_get_contents ($filename); } else { if ($helperPlugin =& plugin_load ('helper', 'blog')) $entries = $helperPlugin->getBlog ($ns); $text = '