xref: /plugin/bez/syntax/nav.php (revision a6dcc2a92e59da91c2c232b8766fcb113dd8507f)
165cfcae3Sghi<?php
265cfcae3Sghi/**
365cfcae3Sghi * Plugin Now: Inserts a timestamp.
465cfcae3Sghi *
565cfcae3Sghi * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
665cfcae3Sghi * @author     Szymon Olewniczak <szymon.olewniczak@rid.pl>
765cfcae3Sghi */
865cfcae3Sghi
965cfcae3Sghi// must be run within DokuWiki
1065cfcae3Sghiif(!defined('DOKU_INC')) die();
1165cfcae3Sghi
1265cfcae3Sghiif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
1365cfcae3Sghirequire_once DOKU_PLUGIN.'syntax.php';
14*a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/tasks.php";
15*a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/issues.php";
1665cfcae3Sghi/**
1765cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
1865cfcae3Sghi * need to inherit from this class
1965cfcae3Sghi */
2065cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
2165cfcae3Sghi
225536eef6Sghi    function getPType() { return 'block'; }
2365cfcae3Sghi    function getType() { return 'substition'; }
2465cfcae3Sghi    function getSort() { return 99; }
2565cfcae3Sghi
2665cfcae3Sghi
2765cfcae3Sghi    function connectTo($mode) {
2865cfcae3Sghi		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
2965cfcae3Sghi    }
3065cfcae3Sghi
3165cfcae3Sghi    function handle($match, $state, $pos, &$handler)
3265cfcae3Sghi    {
3365cfcae3Sghi		return true;
3465cfcae3Sghi    }
3565cfcae3Sghi
3608e8ea12Sghi    function render($mode, &$R, $pass) {
3708e8ea12Sghi		global $INFO;
3865cfcae3Sghi
395536eef6Sghi		$helper = $this->loadHelper('bez');
4008e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
4165cfcae3Sghi
4208e8ea12Sghi        $R->info['cache'] = false;
4308e8ea12Sghi
4408e8ea12Sghi		$data = array(
45*a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
4608e8ea12Sghi		);
4765cfcae3Sghi
485536eef6Sghi		if ($helper->user_editor())
49*a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
50*a6dcc2a9Sghi
51*a6dcc2a9Sghi		$isso = new Issues();
52*a6dcc2a9Sghi		$no = count($isso->get_close_issue());
53*a6dcc2a9Sghi		$title = str_replace('%d', $no, $this->getLang('menu_close_issue'));
54*a6dcc2a9Sghi		$data['bez:close_issue'] = array('id' => 'bez:close_issue', 'type' => 'f', 'level' => 2, 'title' => $title);
55*a6dcc2a9Sghi
56*a6dcc2a9Sghi		$tasko = new Tasks();
57*a6dcc2a9Sghi		$no = count($tasko->get_close_task());
58*a6dcc2a9Sghi		$title = str_replace('%d', $no, $this->getLang('menu_close_task'));
59*a6dcc2a9Sghi		$data['bez:close_task'] = array('id' => 'bez:close_task', 'type' => 'f', 'level' => 2, 'title' => $title);
60*a6dcc2a9Sghi
61*a6dcc2a9Sghi		$no = count($isso->get_comment_issue());
62*a6dcc2a9Sghi		$title = str_replace('%d', $no, $this->getLang('menu_comment_issue'));
63*a6dcc2a9Sghi		$data['bez:comment_issue'] = array('id' => 'bez:comment_issue', 'type' => 'f', 'level' => 2, 'title' => $title);
64*a6dcc2a9Sghi
65*a6dcc2a9Sghi
66*a6dcc2a9Sghi		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
6765cfcae3Sghi
683cc1f839Sghi		if ($helper->user_admin())
69*a6dcc2a9Sghi			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
703cc1f839Sghi
7108e8ea12Sghi
7208e8ea12Sghi		$id = $INFO['id'];
7308e8ea12Sghi		$ex = explode(':', $id);
7408e8ea12Sghi		$root = $ex[0];
7508e8ea12Sghi		if ($root == 'bez') {
76a42d0169Sghi			$data['bez:start']['open'] = true;
7708e8ea12Sghi		} else {
78a42d0169Sghi			$data['bez:start']['open'] = false;
7908e8ea12Sghi			array_splice($data, 1);
8008e8ea12Sghi		}
8108e8ea12Sghi
8208e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
8308e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
8408e8ea12Sghi        $R->doc .= '</div>';
8508e8ea12Sghi
865536eef6Sghi		return true;
8708e8ea12Sghi	}
88da9ebf75Sghi
8908e8ea12Sghi	function _bezlink($id, $title) {
9008e8ea12Sghi		$uri = wl($id);
91*a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
9208e8ea12Sghi	}
9308e8ea12Sghi
9408e8ea12Sghi    function _list($item){
9508e8ea12Sghi        global $INFO;
9608e8ea12Sghi
9708e8ea12Sghi        if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){
9808e8ea12Sghi            return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>';
9908e8ea12Sghi        }else{
10008e8ea12Sghi            return $this->_bezlink($item['id'], $item['title']);
10108e8ea12Sghi        }
10208e8ea12Sghi
10308e8ea12Sghi    }
10408e8ea12Sghi
10508e8ea12Sghi    function _li($item){
10608e8ea12Sghi        if($item['type'] == "f"){
10708e8ea12Sghi            return '<li class="level'.$item['level'].'">';
10808e8ea12Sghi        }elseif($item['open']){
10908e8ea12Sghi            return '<li class="open">';
11008e8ea12Sghi        }else{
11108e8ea12Sghi            return '<li class="closed">';
11208e8ea12Sghi        }
11365cfcae3Sghi    }
11465cfcae3Sghi}
115