xref: /plugin/bez/syntax/nav.php (revision 522c019c0bd8bcd6e522fddaa2cf94cce8e0780d)
1<?php
2
3use \dokuwiki\plugin\bez;
4
5// must be run within DokuWiki
6if(!defined('DOKU_INC')) die();
7
8class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
9
10    public function getPType() { return 'block'; }
11    public function getType() { return 'substition'; }
12    public function getSort() { return 99; }
13
14
15    public function connectTo($mode) {
16		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
17    }
18
19    public function handle($match, $state, $pos, Doku_Handler $handler) {
20		return true;
21    }
22
23    public function render($mode, Doku_Renderer $r, $data) {
24        if ($mode != 'xhtml') return;
25
26        $r->info['cache'] = false;
27
28        $r->doc .= '<nav id="plugin__bez">';
29        $r->doc .= '<div style="background-color: #eee; color: #333; padding: 0 .3em;">' .
30            inlineSVG(DOKU_PLUGIN . 'bez/images/logo.svg') .
31            $this->getLang('bez') .
32            '</div>';
33        $r->doc .= '<ul>';
34        $actions = array(
35            'start' => $this->getLang('nav my_activities'),
36            'threads' => $this->getLang('issues'),
37            'projects' => $this->getLang('nav projects'),
38            'tasks' => $this->getLang('tasks'),
39            'activity_report' => $this->getLang('activity_report')
40        );
41        /** @var bez\meta\BEZ_DokuWiki_Action_Plugin $action */
42        $bez_action = new action_plugin_bez_base();
43        $bez_action->createObjects();
44
45        if ($bez_action->get_level() >= BEZ_AUTH_ADMIN) {
46            $actions['types'] = $this->getLang('types_manage');
47            $actions['task_programs'] = $this->getLang('task_types');
48        }
49
50        foreach ($actions as $action => $label) {
51            $r->doc .= $this->_list($bez_action, $action, $label);
52        }
53        $r->doc .= '</ul>';
54        $r->doc .= '</nav>';
55    }
56
57    protected function _list(action_plugin_bez_base $bez_action, $action, $label) {
58        global $INFO;
59
60        $matches = array();
61        preg_match('/bez:([a-z_]*)/i', $INFO['id'], $matches);
62        $cur_action = '';
63        if (isset($matches[1])) {
64            $cur_action = $matches[1];
65        }
66
67        $ret = '<li>';
68        if ($cur_action == $action) $ret .= '<strong>';
69        $ret .= '<a href="' . $bez_action->url($action) . '">' . $label . '</a>';
70        if ($cur_action == $action) $ret .= '</strong>';
71        $ret .= '</li>';
72
73        return $ret;
74    }
75}
76