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            'report' => $this->getLang('report'),
40            'activity_report' => $this->getLang('activity_report')
41        );
42        /** @var bez\meta\BEZ_DokuWiki_Action_Plugin $action */
43        $bez_action = new action_plugin_bez_base();
44        $bez_action->createObjects();
45
46        if ($bez_action->get_level() >= BEZ_AUTH_ADMIN) {
47            $actions['types'] = $this->getLang('types_manage');
48            $actions['task_programs'] = $this->getLang('task_types');
49        }
50
51        foreach ($actions as $action => $label) {
52            $r->doc .= $this->_list($bez_action, $action, $label);
53        }
54        $r->doc .= '</ul>';
55        $r->doc .= '</nav>';
56    }
57
58    protected function _list(action_plugin_bez_base $bez_action, $action, $label) {
59        global $INFO;
60
61        $matches = array();
62        preg_match('/bez:([a-z_]*)/i', $INFO['id'], $matches);
63        $cur_action = '';
64        if (isset($matches[1])) {
65            $cur_action = $matches[1];
66        }
67
68        $ret = '<li>';
69        if ($cur_action == $action) $ret .= '<strong>';
70        $ret .= '<a href="' . $bez_action->url($action) . '">' . $label . '</a>';
71        if ($cur_action == $action) $ret .= '</strong>';
72        $ret .= '</li>';
73
74        return $ret;
75    }
76}
77