*/ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once DOKU_PLUGIN.'action.php'; /** * search_namespaces1 * * like search_namespaces but with limited depth to 1 */ function treenav_search_namespaces(&$data,$base,$file,$type,$lvl,$opts){ $opts['listdirs'] = true; $opts['depth'] = 1; return search_universal($data,$base,$file,$type,$lvl,$opts); } /** * Helper class to list Pages and Namespaces */ class treenav_NamespaceNode { public $name; public $level; public function __construct($name, $level) { $this->name = $name; $this->level = $level; } public function getPages() { global $conf; $data = array(); search($data,$conf['datadir'], 'search_list', array(), str_replace(':','/', $this->name)); return $data; } public function getChildren() { global $conf; $data = array(); $childs = array(); search($data,$conf['datadir'], 'treenav_search_namespaces', array(), str_replace(':', '/', $this->name)); foreach ($data as $ns) { $childs[] = new treenav_NamespaceNode($ns['id'], $this->level+1); } return $childs; } } /** * DokuWiki Action Plugin. Inserts Tree Navigation in div "page" and wraps * actual page in div "inner__page" */ class action_plugin_treenav extends DokuWiki_Action_Plugin { function register(&$controller) { $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'hook_beforePage'); $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'hook_afterPage'); } function hook_beforePage(&$event, $param) { global $ID; $deps = p_get_metadata($id, 'treenav_deps', true); $cache = new cache(cleanID($ID), 'plugin_treenav'); if (count($deps)>0 && $cache->useCache($deps)) { $doc = $cache->retrieveCache(false); } else { $deps = array('files' => array()); $root = new treenav_NamespaceNode('',0); $renderer =& p_get_renderer('xhtml'); $renderer->listu_open(); $this->_print($root, $renderer, $deps); $renderer->listu_close(); $doc = $renderer->doc; $cache->storeCache($doc); p_set_metadata($id, array('treenav_deps' => $deps)); } echo '