xref: /plugin/bez/syntax/nav.php (revision 8ce39bb5b30654760cfbf59af91c047a132979b7)
1<?php
2/**
3 * Plugin Now: Inserts a timestamp.
4 *
5 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Szymon Olewniczak <szymon.olewniczak@rid.pl>
7 */
8
9// must be run within DokuWiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once DOKU_PLUGIN.'syntax.php';
14include_once DOKU_PLUGIN."bez/models/tasks.php";
15include_once DOKU_PLUGIN."bez/models/issues.php";
16/**
17 * All DokuWiki plugins to extend the parser/rendering mechanism
18 * need to inherit from this class
19 */
20class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
21
22    function getPType() { return 'block'; }
23    function getType() { return 'substition'; }
24    function getSort() { return 99; }
25
26
27    function connectTo($mode) {
28		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
29    }
30
31    function handle($match, $state, $pos, &$handler)
32    {
33		return true;
34    }
35
36    function render($mode, &$R, $pass) {
37		global $INFO;
38
39		$helper = $this->loadHelper('bez');
40		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
41
42        $R->info['cache'] = false;
43
44		$data = array(
45			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
46		);
47
48		if ($helper->user_editor())
49			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
50
51		$isso = new Issues();
52		$no = count($isso->get_close_issue());
53		$title = str_replace('%d', $no, $this->getLang('menu_close_issue'));
54		$data['bez:close_issue'] = array('id' => 'bez:close_issue', 'type' => 'f', 'level' => 2, 'title' => $title);
55
56		$tasko = new Tasks();
57		$no = count($tasko->get_close_task());
58		$title = str_replace('%d', $no, $this->getLang('menu_close_task'));
59		$data['bez:close_task'] = array('id' => 'bez:close_task', 'type' => 'f', 'level' => 2, 'title' => $title);
60
61		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
62
63		if ($helper->user_admin())
64			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
65
66
67		$id = $INFO['id'];
68		$ex = explode(':', $id);
69		$root = $ex[0];
70		if ($root == 'bez') {
71			$data['bez:start']['open'] = true;
72		} else {
73			$data['bez:start']['open'] = false;
74			array_splice($data, 1);
75		}
76
77        $R->doc .= '<div class="plugin__bez">';
78        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
79        $R->doc .= '</div>';
80
81		return true;
82	}
83
84	function _bezlink($id, $title) {
85		$uri = wl($id);
86		return '<a href="'.$uri.'">'.($title).'</a>';
87	}
88
89    function _list($item){
90        global $INFO;
91
92        if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){
93            return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>';
94        }else{
95            return $this->_bezlink($item['id'], $item['title']);
96        }
97
98    }
99
100    function _li($item){
101        if($item['type'] == "f"){
102            return '<li class="level'.$item['level'].'">';
103        }elseif($item['open']){
104            return '<li class="open">';
105        }else{
106            return '<li class="closed">';
107        }
108    }
109}
110