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 = ''; 21*15487902Sghi 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() { 33*15487902Sghi global $conf; 34*15487902Sghi 35*15487902Sghi $id = $_GET['id']; 36*15487902Sghi 37*15487902Sghi /*usuń : z początku id - link bezwzględny*/ 38*15487902Sghi if ($id[0] == ':') 39*15487902Sghi $id = substr($id, 1); 407f226579Sghi 417f226579Sghi $ex = explode(':', $_GET['id']); 42*15487902Sghi 4305c9d3bcSghi //wielojęzyczność 4405c9d3bcSghi if ($ex[1] == 'bez') { 45*15487902Sghi $this->lang_code = $ex[0]; 4605c9d3bcSghi $ex = array_slice($ex, 1); 47*15487902Sghi 48*15487902Sghi $old_lang = $conf['lang']; 49*15487902Sghi $conf['lang'] = $this->lang_code; 50*15487902Sghi $this->setupLocale(); 51*15487902Sghi $conf['lang'] = $old_lang; 52*15487902Sghi 53*15487902Sghi } else { 54*15487902Sghi $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 $entity = ''; 1007f226579Sghi if (array_key_exists('entity', $this->value)) { 1017f226579Sghi $entity = ':entity:'.urlencode($this->value['entity']); 1027e9a45a9Sghi } 1037e9a45a9Sghi 1047e9a45a9Sghi $mon = $mon_old; 1057e9a45a9Sghi for ($year = $year_old; $year <= $year_now; $year++) { 1067f226579Sghi 1077f226579Sghi $y_key = 'bez:report:year:'.$year; 1087f226579Sghi $data[$y_key] = array('id' => $y_key.$entity, 'type' => 'd', 'level' => 3, 'title' => $year); 1097f226579Sghi 1107f226579Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 1117f226579Sghi $data['bez:report:year:'.$year]['open'] = true; 1127f226579Sghi 1137e9a45a9Sghi if ($year == $year_now) 1147e9a45a9Sghi $mon_max = $mon_now; 1157e9a45a9Sghi else 1167e9a45a9Sghi $mon_max = 12; 1177e9a45a9Sghi for ( ; $mon <= $mon_max; $mon++) { 1187e9a45a9Sghi $m_key = $y_key.':month:'.$mon; 1197f226579Sghi $data[$m_key] = array('id' => $m_key.$entity, 'type' => 'f', 'level' => 4, 1207e9a45a9Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 1217e9a45a9Sghi } 1227f226579Sghi } 1237e9a45a9Sghi $mon = 1; 1247e9a45a9Sghi } 1257f226579Sghi } 1263cc1f839Sghi 12708e8ea12Sghi 128f01326efSghi 1297f226579Sghi if (isset($this->value['bez'])) { 130a42d0169Sghi $data['bez:start']['open'] = true; 13108e8ea12Sghi } else { 132a42d0169Sghi $data['bez:start']['open'] = false; 13308e8ea12Sghi array_splice($data, 1); 13408e8ea12Sghi } 13508e8ea12Sghi 1367f226579Sghi if ($helper->user_admin() && $data['bez:start']['open'] == true) 1377f226579Sghi $data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage')); 1387f226579Sghi 13908e8ea12Sghi $R->doc .= '<div class="plugin__bez">'; 14008e8ea12Sghi $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 14108e8ea12Sghi $R->doc .= '</div>'; 14208e8ea12Sghi 1435536eef6Sghi return true; 14408e8ea12Sghi } 145da9ebf75Sghi 14608e8ea12Sghi function _bezlink($id, $title) { 1477f226579Sghi //$uri = wl($id); 1487f226579Sghi $uri = DOKU_URL . 'doku.php?id='.$id; 149a6dcc2a9Sghi return '<a href="'.$uri.'">'.($title).'</a>'; 15008e8ea12Sghi } 15108e8ea12Sghi 15208e8ea12Sghi function _list($item){ 15308e8ea12Sghi 1547f226579Sghi $ex = explode(':', $item['id']); 15505c9d3bcSghi 1567f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 1577f226579Sghi $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 1587f226579Sghi 1597f226579Sghi //pola brane pod uwagę przy określaniu aktualnej strony 1607f226579Sghi $fields = array('bez'); 1617f226579Sghi if ($item_value['bez'] == 'report') { 1627f226579Sghi $fields[] = 'month'; 1637f226579Sghi $fields[] = 'year'; 1647f226579Sghi } 1657f226579Sghi 1667f226579Sghi $actual_page = true; 1677f226579Sghi foreach ($fields as $field) 1687f226579Sghi if ($item_value[$field] != $this->value[$field]) 1697f226579Sghi $actual_page = false; 1707f226579Sghi 1717f226579Sghi 1727f226579Sghi 1737f226579Sghi if(($item['type'] == 'd' && $item['open']) || $actual_page) { 174*15487902Sghi $id = $item['id']; 175*15487902Sghi if ($this->lang_code != $this->default_lang) 176*15487902Sghi $id = $this->lang_code.':'.$id; 177*15487902Sghi return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 17808e8ea12Sghi }else{ 179*15487902Sghi $id = $item['id']; 180*15487902Sghi if ($this->lang_code != $this->default_lang) 181*15487902Sghi $id = $this->lang_code.':'.$id; 182*15487902Sghi return $this->_bezlink($id, $item['title']); 18308e8ea12Sghi } 18408e8ea12Sghi 18508e8ea12Sghi } 18608e8ea12Sghi 18708e8ea12Sghi function _li($item){ 18808e8ea12Sghi if($item['type'] == "f"){ 18908e8ea12Sghi return '<li class="level'.$item['level'].'">'; 19008e8ea12Sghi }elseif($item['open']){ 19108e8ea12Sghi return '<li class="open">'; 19208e8ea12Sghi }else{ 19308e8ea12Sghi return '<li class="closed">'; 19408e8ea12Sghi } 19565cfcae3Sghi } 19665cfcae3Sghi} 197