xref: /plugin/bez/syntax/nav.php (revision 7f226579b5ebd86ad26e5e9d7c71f3a38b5bb2a0)
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';
14a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/tasks.php";
15a6dcc2a9Sghiinclude_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 {
21*7f226579Sghi	private $value = array();
2265cfcae3Sghi
235536eef6Sghi    function getPType() { return 'block'; }
2465cfcae3Sghi    function getType() { return 'substition'; }
2565cfcae3Sghi    function getSort() { return 99; }
2665cfcae3Sghi
2765cfcae3Sghi
2865cfcae3Sghi    function connectTo($mode) {
2965cfcae3Sghi		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
3065cfcae3Sghi    }
3165cfcae3Sghi
32*7f226579Sghi	function __construct() {
33*7f226579Sghi
34*7f226579Sghi		$ex = explode(':', $_GET['id']);
35*7f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
36*7f226579Sghi			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
37*7f226579Sghi	}
38*7f226579Sghi
3965cfcae3Sghi    function handle($match, $state, $pos, &$handler)
4065cfcae3Sghi    {
4165cfcae3Sghi		return true;
4265cfcae3Sghi    }
4365cfcae3Sghi
4408e8ea12Sghi    function render($mode, &$R, $pass) {
4508e8ea12Sghi		global $INFO;
4665cfcae3Sghi
475536eef6Sghi		$helper = $this->loadHelper('bez');
4808e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
4965cfcae3Sghi
5008e8ea12Sghi        $R->info['cache'] = false;
5108e8ea12Sghi
5208e8ea12Sghi		$data = array(
53a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
5408e8ea12Sghi		);
5565cfcae3Sghi
565536eef6Sghi		if ($helper->user_editor())
57a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
58a6dcc2a9Sghi
59a6dcc2a9Sghi		$isso = new Issues();
60a6dcc2a9Sghi		$no = count($isso->get_close_issue());
61a6dcc2a9Sghi		$title = str_replace('%d', $no, $this->getLang('menu_close_issue'));
62a6dcc2a9Sghi		$data['bez:close_issue'] = array('id' => 'bez:close_issue', 'type' => 'f', 'level' => 2, 'title' => $title);
63a6dcc2a9Sghi
64a6dcc2a9Sghi		$tasko = new Tasks();
65a6dcc2a9Sghi		$no = count($tasko->get_close_task());
66a6dcc2a9Sghi		$title = str_replace('%d', $no, $this->getLang('menu_close_task'));
67a6dcc2a9Sghi		$data['bez:close_task'] = array('id' => 'bez:close_task', 'type' => 'f', 'level' => 2, 'title' => $title);
68a6dcc2a9Sghi
69a6dcc2a9Sghi		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
70c9044e56Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
7165cfcae3Sghi
72d21fa58cSghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
73f01326efSghi
747e9a45a9Sghi
757e9a45a9Sghi
767e9a45a9Sghi
77*7f226579Sghi		if ($this->value['bez'] == 'report') {
78*7f226579Sghi			$data['bez:report']['open'] = true;
79*7f226579Sghi
807e9a45a9Sghi			$oldest = $isso->get_oldest_date();
817e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
827e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
837e9a45a9Sghi			$year_now = (int)date('Y');
847e9a45a9Sghi			$mon_now = (int)date('n');
857e9a45a9Sghi
867e9a45a9Sghi			$entity = '';
87*7f226579Sghi			if (array_key_exists('entity', $this->value)) {
88*7f226579Sghi				$entity = ':entity:'.urlencode($this->value['entity']);
897e9a45a9Sghi			}
907e9a45a9Sghi
917e9a45a9Sghi			$mon = $mon_old;
927e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
93*7f226579Sghi
94*7f226579Sghi				$y_key = 'bez:report:year:'.$year;
95*7f226579Sghi				$data[$y_key] = array('id' => $y_key.$entity, 'type' => 'd', 'level' => 3, 'title' => $year);
96*7f226579Sghi
97*7f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
98*7f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
99*7f226579Sghi
1007e9a45a9Sghi					if ($year == $year_now)
1017e9a45a9Sghi						$mon_max = $mon_now;
1027e9a45a9Sghi					else
1037e9a45a9Sghi						$mon_max = 12;
1047e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
1057e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
106*7f226579Sghi						$data[$m_key] = array('id' => $m_key.$entity, 'type' => 'f', 'level' => 4,
1077e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
1087e9a45a9Sghi					}
109*7f226579Sghi				}
1107e9a45a9Sghi				$mon = 1;
1117e9a45a9Sghi			}
112*7f226579Sghi		}
1133cc1f839Sghi
11408e8ea12Sghi
115f01326efSghi
116*7f226579Sghi		if (isset($this->value['bez'])) {
117a42d0169Sghi			$data['bez:start']['open'] = true;
11808e8ea12Sghi		} else {
119a42d0169Sghi			$data['bez:start']['open'] = false;
12008e8ea12Sghi			array_splice($data, 1);
12108e8ea12Sghi		}
12208e8ea12Sghi
123*7f226579Sghi		if ($helper->user_admin() && $data['bez:start']['open'] == true)
124*7f226579Sghi			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
125*7f226579Sghi
12608e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
12708e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
12808e8ea12Sghi        $R->doc .= '</div>';
12908e8ea12Sghi
1305536eef6Sghi		return true;
13108e8ea12Sghi	}
132da9ebf75Sghi
13308e8ea12Sghi	function _bezlink($id, $title) {
134*7f226579Sghi		//$uri = wl($id);
135*7f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
136a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
13708e8ea12Sghi	}
13808e8ea12Sghi
13908e8ea12Sghi    function _list($item){
14008e8ea12Sghi
141*7f226579Sghi		$ex = explode(':', $item['id']);
142*7f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
143*7f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
144*7f226579Sghi
145*7f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
146*7f226579Sghi		$fields = array('bez');
147*7f226579Sghi		if ($item_value['bez'] == 'report') {
148*7f226579Sghi			$fields[] = 'month';
149*7f226579Sghi			$fields[] = 'year';
150*7f226579Sghi		}
151*7f226579Sghi
152*7f226579Sghi		$actual_page = true;
153*7f226579Sghi		foreach ($fields as $field)
154*7f226579Sghi			if ($item_value[$field] != $this->value[$field])
155*7f226579Sghi				$actual_page = false;
156*7f226579Sghi
157*7f226579Sghi
158*7f226579Sghi
159*7f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
16008e8ea12Sghi            return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>';
16108e8ea12Sghi        }else{
16208e8ea12Sghi            return $this->_bezlink($item['id'], $item['title']);
16308e8ea12Sghi        }
16408e8ea12Sghi
16508e8ea12Sghi    }
16608e8ea12Sghi
16708e8ea12Sghi    function _li($item){
16808e8ea12Sghi        if($item['type'] == "f"){
16908e8ea12Sghi            return '<li class="level'.$item['level'].'">';
17008e8ea12Sghi        }elseif($item['open']){
17108e8ea12Sghi            return '<li class="open">';
17208e8ea12Sghi        }else{
17308e8ea12Sghi            return '<li class="closed">';
17408e8ea12Sghi        }
17565cfcae3Sghi    }
17665cfcae3Sghi}
177