summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--action.php193
-rw-r--r--plugin.info.txt7
-rw-r--r--style.css9
-rw-r--r--syntax.php46
4 files changed, 162 insertions, 93 deletions
diff --git a/action.php b/action.php
index 941937c..d896aa7 100644
--- a/action.php
+++ b/action.php
@@ -1,117 +1,124 @@
<?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;
- $opts['depth'] = 1;
- return search_universal($data,$base,$file,$type,$lvl,$opts);
+ $opts['listdirs'] = true;
+ $opts['depth'] = 1;
+ 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);
+ 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;
}
- 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 (noNS($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();
- }
- }
+ function register(&$controller) {
+ $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this,
+ '_before_page');
+ $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this,
+ '_after_page');
+
}
- 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 _after_page(&$event, $param) {
+ echo '</div>' . DOKU_LF;
}
- }
-
- 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);
- }
+
+ 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;
}
- if ($options['title']) {
- $title = $options['title'];
- } else {
- $title = p_get_first_heading($id);
+
+ function _print($node, &$renderer) {
+ global $ID;
+ foreach ($node->getChildren() as $child) {
+ foreach ($child->getPages() as $page) {
+ if (noNS($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();
+ }
+ }
+ }
+
+ 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();
+ }
}
- $renderer->internallink($id, $title);
- }
+ function _renderPagelink($id, &$renderer) {
+ $id = ':' . cleanID($id);
+ $options = p_get_metadata($id, 'treenav', true);
+ if ($options['icon']) {
+ $iconID = $options['icon'];
+ resolve_mediaid(getNS($id), $iconID, $exists);
+ if ($exists) {
+ $renderer->doc .= $renderer->_media($iconID, NULL, NULL, 16, 16);
+ }
+ }
+ if ($options['title']) {
+ $title = $options['title'];
+ } else {
+ $title = p_get_first_heading($id);
+ }
+
+ $renderer->internallink($id, $title);
+ }
}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* Local Variables: */
+/* tab-width: 4 */
+/* indent-tabs-mode: nil */
+/* c-basic-offset: 4 */
+/* End: */ \ No newline at end of file
diff --git a/plugin.info.txt b/plugin.info.txt
new file mode 100644
index 0000000..bde3922
--- /dev/null
+++ b/plugin.info.txt
@@ -0,0 +1,7 @@
+base treenav
+author Yves Fischer
+email yvesf-git@xapek.org
+date 2011-01-01
+name Simple tree navigation
+desc Simple tree Navigation
+url http://www.example.com
diff --git a/style.css b/style.css
index 5e061e6..5fee2bd 100644
--- a/style.css
+++ b/style.css
@@ -5,6 +5,15 @@ div.dokuwiki div.page div.treenav {
background-color: white;
}
+div.dokuwiki div.page div.treenav ul {
+ list-style: none;
+}
+
+div.dokuwiki div.page div.treenav img.media {
+ margin: 0px;
+ margin-right: 2px;
+}
+
div.dokuwiki div.page div.page__inner {
position: relative;
margin-left: 300px;
diff --git a/syntax.php b/syntax.php
new file mode 100644
index 0000000..fc6f648
--- /dev/null
+++ b/syntax.php
@@ -0,0 +1,46 @@
+<?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.'syntax.php';
+
+class syntax_plugin_treenav extends DokuWiki_Syntax_Plugin {
+ private $keys = array("icon", "title");
+
+ function getType() { return 'baseonly'; }
+ function getSort() { return 32; }
+
+ function connectTo($mode) {
+ foreach ($this->keys as $key) {
+ $this->Lexer->addSpecialPattern('~~'.$key.':.*?~~',$mode,'plugin_treenav');
+ }
+ }
+
+ function handle($match, $state, $pos, &$handler) {
+ switch ($state) {
+ case DOKU_LEXER_SPECIAL:
+ $match = substr($match, 2, -2);
+ @list($key, $value) = explode(':', $match, 2);
+ if (in_array($key, $this->keys)) {
+ $this->setMetadata($key, $value);
+ }
+ }
+ }
+
+ function setMetadata($key, $value) {
+ global $ID;
+ $data = p_get_metadata($ID, "treenav", false) or array();
+ $data[$key] = $value;
+ return p_set_metadata($ID, array("treenav" => $data));
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* Local Variables: */
+/* tab-width: 4 */
+/* indent-tabs-mode: nil */
+/* c-basic-offset: 4 */
+/* End: */ \ No newline at end of file