1<?php 2/** 3 * popoutviewer Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author i-net software <tools@inetsoftware.de> 7 * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) die(); 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14require_once(DOKU_PLUGIN.'syntax.php'); 15 16class syntax_plugin_tipoftheday_totns extends DokuWiki_Syntax_Plugin { 17 18 function getType() { return 'substition'; } 19 function getPType() { return 'block'; } 20 function getSort() { return 40; } 21 22 function connectTo($mode) { 23 $this->Lexer->addSpecialPattern('{{totns>.+?}}', $mode, 'plugin_totd_totns'); 24 } 25 26 function handle($match, $state, $pos, Doku_Handler $handler) { 27 28 $match = substr($match, 2, -2); // strip markup 29 list($match, $flags) = explode('&', $match, 2); 30 31 // break the pattern up into its parts 32 list($mode, $page, $sect) = preg_split('/>|#/u', $match, 3); 33 34 $header = $this->_getNSFiles(getNS($page)); 35 36 $page = $header[intval(date('W')) % count($header)]; 37 if ( empty($page) ) { 38 $page = $header[0]; 39 } 40 41 return array($page, explode('&', $flags)); 42 } 43 44 function render($mode, Doku_Renderer $renderer, $data) { 45 global $ID; 46 47 if ( $mode == 'xhtml' ) { 48 list($page, $flags) = $data; 49 if ( !is_Array($flags) ) { 50 $flags = array($flags); 51 } 52 53 $ins = p_cached_instructions(wikiFN($page)); 54 $renderer->doc .= p_render($mode, $ins, $myINFO); 55 } 56 } 57 58 /** 59 * Get a section including its subsections 60 */ 61 function _getNSFiles($ns) { 62 global $conf; 63 64 $page = array(); 65 $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 66 $data = array(); 67 require_once (DOKU_INC.'inc/search.php'); 68 $opts['skipacl'] = 0; // no ACL skipping for XMLRPC 69 70 $data = array(); 71 search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 72 foreach ( $data as $dat ) { 73 $page[] = $dat['id']; 74 } 75 76 return $page; 77 } 78} 79// vim:ts=4:sw=4:et:enc=utf-8: 80