1<?php
2/**
3*  topbarsyntax Plugin: topbar as syntax plugin to be placed anywhere on the page
4*
5* portions of code taken from Michael Klier <chi@chimeric.de> simple template
6*
7* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8* @author     Taggic <taggic@t-online.de>
9*
10*
11*
12*/
13//session_start();
14if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
15if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16require_once(DOKU_PLUGIN.'syntax.php');
17
18/******************************************************************************
19* All DokuWiki plugins to extend the parser/rendering mechanism
20* need to inherit from this class
21*/
22class syntax_plugin_topbarsyntax extends DokuWiki_Syntax_Plugin
23{
24/******************************************************************************/
25/* return some info
26*/
27    function getInfo(){
28        return confToHash(dirname(__FILE__).'/plugin.info.txt');
29    }
30
31    function getType(){ return 'substition';}
32    function getPType(){ return 'block';}
33    function getSort(){ return 169;}
34
35/******************************************************************************/
36/* Connect pattern to lexer
37*/
38    function connectTo($mode){
39        $this->Lexer->addSpecialPattern('\{\{topbarsyntax>[^}]*\}\}',$mode,'plugin_topbarsyntax');
40    }
41
42/******************************************************************************/
43/* handle the match
44*/
45    function handle($match, $state, $pos, Doku_Handler &$handler) {
46        global $ID;
47        $match = substr($match,strlen('{{topbarsyntax>'),-2); //strip markup from start and end
48        //handle params
49        $data = array();
50        // params can be a width and the bar orientation (h = horizontal, v = vertical)
51        $params = explode(',',$match);  // if you will have more parameters and choose ',' to delim them
52        return $params;
53     }
54/******************************************************************************/
55/* render output
56* @author Michael Klier <chi@chimeric.de>
57* modified by Taggic <taggic@t-online.de>
58*/
59    function render($mode, Doku_Renderer &$renderer, $data) {
60        $width = $data[0];   // width of the main bar
61        $orient = $data[1];  // orientation of the menu
62
63        if (!$width) { $width = "100%"; }
64        if (!$orient) { $orient = "h"; }
65        global $ID;
66
67        $found = false;
68        $tbar  = '';
69        $path  = explode(':', $ID);
70
71        while(!$found && count($path) >= 0) {
72            $tbar = implode(':', $path) . ':' . 'topbar';
73            $found = @file_exists(wikiFN($tbar));
74            array_pop($path);
75            // check if nothing was found
76            if(!$found && $tbar == ':topbar') return;
77        }
78
79        if($found && auth_quickaclcheck($tbar) >= AUTH_READ) {
80            if ($orient === "h") {
81//              $renderer->doc .= "<div>orient = ".$orient.'</div><br />';
82              $renderer->doc .= '<div id="tpl_smplbar_navi1" style="width:'.$width.'">'.p_wiki_xhtml($tbar,'',false).'</div>'.NL;
83              }
84            else if ($orient === "vl") {
85//              $renderer->doc .= "<div>orient = ".$orient.'</div><br />';
86              $renderer->doc .= '<div id="tpl_smplbar_navi2" style="width:'.$width.'">'.p_wiki_xhtml($tbar,'',true).'</div>'.NL;
87            }
88            else {
89//              $renderer->doc .= "<div>orient = ".$orient.'</div><br />';
90              $renderer->doc .= '<div id="tpl_smplbar_navi3" style="width:'.$width.'">'.p_wiki_xhtml($tbar,'',true).'</div>'.NL;
91            }
92
93        }
94     }
95}