summaryrefslogtreecommitdiff
path: root/action.php
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2011-10-15 20:35:42 +0200
committerYves Fischer <yvesf-git@xapek.org>2011-10-15 20:35:42 +0200
commit7c67d22073a502e137241fb3659a77529c5711aa (patch)
tree77a7067cb825da45bb0e092658f45260d0953219 /action.php
downloaddokuwiki-plugin-treenav-7c67d22073a502e137241fb3659a77529c5711aa.tar.gz
dokuwiki-plugin-treenav-7c67d22073a502e137241fb3659a77529c5711aa.zip
Draft
Diffstat (limited to 'action.php')
-rw-r--r--action.php115
1 files changed, 115 insertions, 0 deletions
diff --git a/action.php b/action.php
new file mode 100644
index 0000000..cbf20c9
--- /dev/null
+++ b/action.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Simple Tree Navigation Plugin
+ *
+ * @author Yves Fischer <yvesf-git@xapek.org>
+ */
+
+if(!defined('DOKU_INC')) die();
+if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
+require_once DOKU_PLUGIN.'action.php';
+
+function search_namespaces1(&$data,$base,$file,$type,$lvl,$opts){
+ $opts['listdirs'] = true;
+ return search_universal($data,$base,$file,$type,$lvl,$opts);
+}
+
+class 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'], 'search_namespaces1', array(), str_replace(':', '/', $this->name));
+ foreach ($data as $ns) {
+ $childs[] = new NamespaceNode($ns['id'], $this->level+1);
+ }
+ return $childs;
+ }
+}
+
+
+class action_plugin_treenav extends DokuWiki_Action_Plugin {
+ function register(&$controller) {
+ $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this,
+ '_before_page');
+ $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this,
+ '_after_page');
+
+ }
+
+ function _after_page(&$event, $param) {
+ echo '</div>' . DOKU_LF;
+ }
+
+ function _before_page(&$event, $param) {
+ global $ID;
+ $root = new NamespaceNode('',0);
+ $renderer =& p_get_renderer('xhtml');
+ $renderer->listu_open();
+ $this->_print($root, $renderer);
+ $renderer->listu_close();
+
+ echo '<div class="treenav">' . DOKU_LF . $renderer->doc . DOKU_LF . '</div>';
+ echo '<div class="page__inner">' . DOKU_LF;
+ }
+
+ function _print($node, &$renderer) {
+ global $ID;
+ foreach ($node->getChildren() as $child) {
+ foreach ($child->getPages() as $page) {
+ if ($page['id'] == $child->name . ':start') {
+ $page_id_start = $page['id'];
+ }
+ }
+ if ($page_id_start) {
+ $renderer->listitem_open();
+ $renderer->cdata('>');
+ $this->_renderPagelink($page['id'], $renderer);
+ if (strpos(getNS($ID), $child->name) === 0) {
+ // Recursive Call with Sub-Namespace that contains
+ // current Page ($ID)
+ $renderer->listu_open();
+ $this->_print($child, $renderer);
+ $renderer->listu_close();
+ }
+ $renderer->listitem_close();
+ $page_id_start = NULL;
+ }
+ }
+
+ foreach ($node->getPages() as $page) {
+ if (noNS($page['id']) == 'start' && getNS($page['id']) != '')
+ continue;
+ $renderer->listitem_open();
+ $this->_renderPagelink($page['id'], $renderer);
+ $renderer->listitem_close();
+ }
+ }
+
+ function _renderPagelink($id, &$renderer) {
+ $id = ':' . cleanID($id);
+ $options = p_get_metadata($id, 'treenav', true);
+ if ($options['icon']) {
+ $mediaid = resolve_mediaid(getNS($id), $options['icon'], $exists);
+ if ($exists) {
+ $renderer->_media($mediaid, NULL, NULL, 32, 32);
+ }
+ }
+ // 432 function resolve_mediaid($ns,&$page,&$exists){
+ $renderer->internallink($id);
+ }
+}