xref: /plugin/bez/syntax/nav.php (revision 38b5c5c45972fa0048c81dcc35b60fc2e2b49a6f)
165cfcae3Sghi<?php
265cfcae3Sghi/**
365cfcae3Sghi * Plugin Now: Inserts a timestamp.
465cfcae3Sghi *
565cfcae3Sghi * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
665cfcae3Sghi */
765cfcae3Sghi
865cfcae3Sghi// must be run within DokuWiki
965cfcae3Sghiif(!defined('DOKU_INC')) die();
1065cfcae3Sghi
1165cfcae3Sghiif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
1265cfcae3Sghirequire_once DOKU_PLUGIN.'syntax.php';
13a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/issues.php";
1465cfcae3Sghi/**
1565cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
1665cfcae3Sghi * need to inherit from this class
1765cfcae3Sghi */
1865cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
197f226579Sghi	private $value = array();
2005c9d3bcSghi	private $lang_code = '';
2115487902Sghi	private $default_lang = 'pl';
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
327f226579Sghi	function __construct() {
3315487902Sghi		global $conf;
3415487902Sghi
3515487902Sghi		$id = $_GET['id'];
3615487902Sghi
3715487902Sghi		/*usuń : z początku id - link bezwzględny*/
3815487902Sghi		if ($id[0] == ':')
3915487902Sghi			$id = substr($id, 1);
407f226579Sghi
417f226579Sghi		$ex = explode(':', $_GET['id']);
4215487902Sghi
4305c9d3bcSghi		//wielojęzyczność
4405c9d3bcSghi		if ($ex[1] == 'bez') {
4515487902Sghi			$this->lang_code = $ex[0];
4605c9d3bcSghi			$ex = array_slice($ex, 1);
4715487902Sghi
4815487902Sghi			$old_lang = $conf['lang'];
4915487902Sghi			$conf['lang'] = $this->lang_code;
5015487902Sghi			$this->setupLocale();
5115487902Sghi			$conf['lang'] = $old_lang;
5215487902Sghi
5315487902Sghi		} else {
5415487902Sghi			$this->lang_code = $conf['lang'];
5505c9d3bcSghi		}
5605c9d3bcSghi
577f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
587f226579Sghi			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
597f226579Sghi	}
607f226579Sghi
6165cfcae3Sghi    function handle($match, $state, $pos, &$handler)
6265cfcae3Sghi    {
6365cfcae3Sghi		return true;
6465cfcae3Sghi    }
6565cfcae3Sghi
6608e8ea12Sghi    function render($mode, &$R, $pass) {
6708e8ea12Sghi		global $INFO;
6865cfcae3Sghi
695536eef6Sghi		$helper = $this->loadHelper('bez');
7008e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
7165cfcae3Sghi
7208e8ea12Sghi        $R->info['cache'] = false;
7308e8ea12Sghi
7408e8ea12Sghi		$data = array(
75a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
7608e8ea12Sghi		);
7765cfcae3Sghi
785536eef6Sghi		if ($helper->user_editor())
79a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
80a6dcc2a9Sghi
81bb615297Sghi		$data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
82bb615297Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
8365cfcae3Sghi
84d21fa58cSghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
85f01326efSghi
867e9a45a9Sghi
877e9a45a9Sghi
887e9a45a9Sghi
897f853d3aSghi		$isso = new Issues();
907f226579Sghi		if ($this->value['bez'] == 'report') {
917f226579Sghi			$data['bez:report']['open'] = true;
927f226579Sghi
93bb615297Sghi			$oldest = $isso->get_oldest_close_date();
947e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
957e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
967e9a45a9Sghi			$year_now = (int)date('Y');
977e9a45a9Sghi			$mon_now = (int)date('n');
987e9a45a9Sghi
997e9a45a9Sghi			$mon = $mon_old;
1007e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
1017f226579Sghi
1027f226579Sghi				$y_key = 'bez:report:year:'.$year;
103*38b5c5c4Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
1047f226579Sghi
1057f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
1067f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
1077f226579Sghi
1087e9a45a9Sghi					if ($year == $year_now)
1097e9a45a9Sghi						$mon_max = $mon_now;
1107e9a45a9Sghi					else
1117e9a45a9Sghi						$mon_max = 12;
1127e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
1137e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
114*38b5c5c4Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
1157e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
1167e9a45a9Sghi					}
1177f226579Sghi				}
1187e9a45a9Sghi				$mon = 1;
1197e9a45a9Sghi			}
1207f226579Sghi		}
1213cc1f839Sghi
12208e8ea12Sghi
123f01326efSghi
1247f226579Sghi		if (isset($this->value['bez'])) {
125a42d0169Sghi			$data['bez:start']['open'] = true;
12608e8ea12Sghi		} else {
127a42d0169Sghi			$data['bez:start']['open'] = false;
12808e8ea12Sghi			array_splice($data, 1);
12908e8ea12Sghi		}
13008e8ea12Sghi
1317f226579Sghi		if ($helper->user_admin() && $data['bez:start']['open'] == true)
132*38b5c5c4Sghi			$data['bez:types'] = array('id' => 'bez:tpes', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('types_manage'));
1337f226579Sghi
13408e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
13508e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
13608e8ea12Sghi        $R->doc .= '</div>';
13708e8ea12Sghi
1385536eef6Sghi		return true;
13908e8ea12Sghi	}
140da9ebf75Sghi
14108e8ea12Sghi	function _bezlink($id, $title) {
1427f226579Sghi		//$uri = wl($id);
1437f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
144a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
14508e8ea12Sghi	}
14608e8ea12Sghi
14708e8ea12Sghi    function _list($item){
14808e8ea12Sghi
1497f226579Sghi		$ex = explode(':', $item['id']);
15005c9d3bcSghi
1517f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
1527f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
1537f226579Sghi
1547f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
1557f226579Sghi		$fields = array('bez');
1567f226579Sghi		if ($item_value['bez'] == 'report') {
1577f226579Sghi			$fields[] = 'month';
1587f226579Sghi			$fields[] = 'year';
1597f226579Sghi		}
1607f226579Sghi
1617f226579Sghi		$actual_page = true;
1627f226579Sghi		foreach ($fields as $field)
1637f226579Sghi			if ($item_value[$field] != $this->value[$field])
1647f226579Sghi				$actual_page = false;
1657f226579Sghi
1667f226579Sghi
1677f226579Sghi
1687f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
16915487902Sghi			$id = $item['id'];
17015487902Sghi			if ($this->lang_code != $this->default_lang)
17115487902Sghi				$id = $this->lang_code.':'.$id;
17215487902Sghi            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
17308e8ea12Sghi        }else{
17415487902Sghi			$id = $item['id'];
17515487902Sghi			if ($this->lang_code != $this->default_lang)
17615487902Sghi				$id = $this->lang_code.':'.$id;
17715487902Sghi            return $this->_bezlink($id, $item['title']);
17808e8ea12Sghi        }
17908e8ea12Sghi
18008e8ea12Sghi    }
18108e8ea12Sghi
18208e8ea12Sghi    function _li($item){
18308e8ea12Sghi        if($item['type'] == "f"){
18408e8ea12Sghi            return '<li class="level'.$item['level'].'">';
18508e8ea12Sghi        }elseif($item['open']){
18608e8ea12Sghi            return '<li class="open">';
18708e8ea12Sghi        }else{
18808e8ea12Sghi            return '<li class="closed">';
18908e8ea12Sghi        }
19065cfcae3Sghi    }
19165cfcae3Sghi}
192