xref: /plugin/bez/syntax/nav.php (revision 7b8eec59bce0fd83d1672aa77ec5144d71021338)
1<?php
2/**
3 * Plugin Now: Inserts a timestamp.
4 *
5 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
6 */
7
8// must be run within DokuWiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once DOKU_PLUGIN.'syntax.php';
13include_once DOKU_PLUGIN."bez/models/issues.php";
14/**
15 * All DokuWiki plugins to extend the parser/rendering mechanism
16 * need to inherit from this class
17 */
18class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
19	private $value = array();
20	private $lang_code = '';
21	private $default_lang = 'pl';
22
23    function getPType() { return 'block'; }
24    function getType() { return 'substition'; }
25    function getSort() { return 99; }
26
27
28    function connectTo($mode) {
29		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
30    }
31
32	function __construct() {
33		global $conf;
34
35		$id = $_GET['id'];
36
37		/*usuń : z początku id - link bezwzględny*/
38		if ($id[0] == ':')
39			$id = substr($id, 1);
40
41		$ex = explode(':', $_GET['id']);
42
43		//wielojęzyczność
44		if ($ex[1] == 'bez') {
45			$this->lang_code = $ex[0];
46			$ex = array_slice($ex, 1);
47
48			$old_lang = $conf['lang'];
49			$conf['lang'] = $this->lang_code;
50			$this->setupLocale();
51			$conf['lang'] = $old_lang;
52
53		} else {
54			$this->lang_code = $conf['lang'];
55		}
56
57		for ($i = 0; $i < count($ex); $i += 2)
58			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
59	}
60
61    function handle($match, $state, $pos, &$handler)
62    {
63		return true;
64    }
65
66    function render($mode, &$R, $pass) {
67		global $INFO;
68
69		$helper = $this->loadHelper('bez');
70		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
71
72        $R->info['cache'] = false;
73
74		$data = array(
75			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
76		);
77
78		if ($helper->user_editor())
79			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
80
81		$data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
82		$data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
83
84		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
85
86
87
88
89		$isso = new Issues();
90		if ($this->value['bez'] == 'report') {
91			$data['bez:report']['open'] = true;
92
93			$oldest = $isso->get_oldest_close_date();
94			$year_old = (int)date('Y', $oldest);
95			$mon_old = (int)date('n', $oldest);
96			$year_now = (int)date('Y');
97			$mon_now = (int)date('n');
98
99			$entity = '';
100			if (array_key_exists('entity', $this->value)) {
101				$entity = ':entity:'.urlencode($this->value['entity']);
102			}
103
104			$mon = $mon_old;
105			for ($year = $year_old; $year <= $year_now; $year++) {
106
107				$y_key = 'bez:report:year:'.$year;
108				$data[$y_key] = array('id' => $y_key.$entity, 'type' => 'd', 'level' => 3, 'title' => $year);
109
110				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
111					$data['bez:report:year:'.$year]['open'] = true;
112
113					if ($year == $year_now)
114						$mon_max = $mon_now;
115					else
116						$mon_max = 12;
117					for ( ; $mon <= $mon_max; $mon++) {
118						$m_key = $y_key.':month:'.$mon;
119						$data[$m_key] = array('id' => $m_key.$entity, 'type' => 'f', 'level' => 4,
120						'title' => $mon < 10 ? '0'.$mon : $mon);
121					}
122				}
123				$mon = 1;
124			}
125		}
126
127
128
129		if (isset($this->value['bez'])) {
130			$data['bez:start']['open'] = true;
131		} else {
132			$data['bez:start']['open'] = false;
133			array_splice($data, 1);
134		}
135
136		if ($helper->user_admin() && $data['bez:start']['open'] == true)
137			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
138
139        $R->doc .= '<div class="plugin__bez">';
140        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
141        $R->doc .= '</div>';
142
143		return true;
144	}
145
146	function _bezlink($id, $title) {
147		//$uri = wl($id);
148		$uri = DOKU_URL . 'doku.php?id='.$id;
149		return '<a href="'.$uri.'">'.($title).'</a>';
150	}
151
152    function _list($item){
153
154		$ex = explode(':', $item['id']);
155
156		for ($i = 0; $i < count($ex); $i += 2)
157			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
158
159		//pola brane pod uwagę przy określaniu aktualnej strony
160		$fields = array('bez');
161		if ($item_value['bez'] == 'report') {
162			$fields[] = 'month';
163			$fields[] = 'year';
164		}
165
166		$actual_page = true;
167		foreach ($fields as $field)
168			if ($item_value[$field] != $this->value[$field])
169				$actual_page = false;
170
171
172
173        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
174			$id = $item['id'];
175			if ($this->lang_code != $this->default_lang)
176				$id = $this->lang_code.':'.$id;
177            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
178        }else{
179			$id = $item['id'];
180			if ($this->lang_code != $this->default_lang)
181				$id = $this->lang_code.':'.$id;
182            return $this->_bezlink($id, $item['title']);
183        }
184
185    }
186
187    function _li($item){
188        if($item['type'] == "f"){
189            return '<li class="level'.$item['level'].'">';
190        }elseif($item['open']){
191            return '<li class="open">';
192        }else{
193            return '<li class="closed">';
194        }
195    }
196}
197