summaryrefslogtreecommitdiff
path: root/action.php
diff options
context:
space:
mode:
Diffstat (limited to 'action.php')
-rw-r--r--action.php84
1 files changed, 62 insertions, 22 deletions
diff --git a/action.php b/action.php
index d896aa7..da0fb22 100644
--- a/action.php
+++ b/action.php
@@ -7,12 +7,20 @@ 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 search_namespaces1(&$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 NamespaceNode {
public $name;
public $level;
@@ -41,44 +49,63 @@ class NamespaceNode {
}
+/**
+ * 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,
- '_before_page');
+ 'hook_beforePage');
$controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this,
- '_after_page');
-
+ 'hook_afterPage');
}
- function _after_page(&$event, $param) {
- echo '</div>' . DOKU_LF;
- }
- function _before_page(&$event, $param) {
+ function hook_beforePage(&$event, $param) {
global $ID;
- $root = new NamespaceNode('',0);
- $renderer =& p_get_renderer('xhtml');
- $renderer->listu_open();
- $this->_print($root, $renderer);
- $renderer->listu_close();
+ $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 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 '<div class="treenav">' . DOKU_LF . $renderer->doc . DOKU_LF . '</div>';
+ echo '<div class="treenav">' . DOKU_LF . $doc . DOKU_LF . '</div>';
echo '<div class="page__inner">' . DOKU_LF;
+
+ tpl_flush();
}
- function _print($node, &$renderer) {
+ function hook_afterPage(&$event, $param) {
+ echo '</div>' . DOKU_LF;
+ }
+
+ function _print($node, &$renderer, &$deps) {
global $ID;
foreach ($node->getChildren() as $child) {
foreach ($child->getPages() as $page) {
if (noNS($page['id']) === 'start') {
$renderer->listitem_open();
- $renderer->cdata('>');
+ $deps['files'][] = wikiFN($page['id']); // Add page file to dependencies
$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);
+ $this->_print($child, $renderer, $deps);
$renderer->listu_close();
}
$renderer->listitem_close();
@@ -90,21 +117,34 @@ class action_plugin_treenav extends DokuWiki_Action_Plugin {
if (noNS($page['id']) == 'start' && getNS($page['id']) != '')
continue;
$renderer->listitem_open();
+ $deps['files'][] = wikiFN($page['id']); // Add page file to dependencies
$this->_renderPagelink($page['id'], $renderer);
$renderer->listitem_close();
}
}
function _renderPagelink($id, &$renderer) {
+ global $conf;
+
$id = ':' . cleanID($id);
- $options = p_get_metadata($id, 'treenav', true);
- if ($options['icon']) {
- $iconID = $options['icon'];
+ $options = p_get_metadata($id, 'treenav');
+
+ // Icon
+ $iconID = $options['icon'];
+ if ($iconID) {
resolve_mediaid(getNS($id), $iconID, $exists);
- if ($exists) {
- $renderer->doc .= $renderer->_media($iconID, NULL, NULL, 16, 16);
+ }
+ if ($iconID && $exists) {
+ $link = ml($iconID, array('h'=>16, 'cache'=>NULL));
+ } else {
+ if (noNS($id) === $conf['start'] && getNS($id) !== '') {
+ $link = DOKU_REL . 'lib/plugins/treenav/images/zoom-in-symbolic.png';
+ } else {
+ $link = DOKU_REL . 'lib/plugins/treenav/images/go-next-symbolic.png';
}
}
+ $renderer->doc .= '<img height="16" src="'.$link.'" class="media" />' . DOKU_LF;
+
if ($options['title']) {
$title = $options['title'];
} else {
@@ -121,4 +161,4 @@ class action_plugin_treenav extends DokuWiki_Action_Plugin {
/* tab-width: 4 */
/* indent-tabs-mode: nil */
/* c-basic-offset: 4 */
-/* End: */ \ No newline at end of file
+/* End: */