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 $mon = $mon_old; 100 for ($year = $year_old; $year <= $year_now; $year++) { 101 102 $y_key = 'bez:report:year:'.$year; 103 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 104 105 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 106 $data['bez:report:year:'.$year]['open'] = true; 107 108 if ($year == $year_now) 109 $mon_max = $mon_now; 110 else 111 $mon_max = 12; 112 for ( ; $mon <= $mon_max; $mon++) { 113 $m_key = $y_key.':month:'.$mon; 114 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 115 'title' => $mon < 10 ? '0'.$mon : $mon); 116 } 117 } 118 $mon = 1; 119 } 120 } 121 122 123 124 if (isset($this->value['bez'])) { 125 $data['bez:start']['open'] = true; 126 } else { 127 $data['bez:start']['open'] = false; 128 array_splice($data, 1); 129 } 130 131 if ($helper->user_admin() && $data['bez:start']['open'] == true) 132 $data['bez:types'] = array('id' => 'bez:tpes', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('types_manage')); 133 134 $R->doc .= '<div class="plugin__bez">'; 135 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 136 $R->doc .= '</div>'; 137 138 return true; 139 } 140 141 function _bezlink($id, $title) { 142 //$uri = wl($id); 143 $uri = DOKU_URL . 'doku.php?id='.$id; 144 return '<a href="'.$uri.'">'.($title).'</a>'; 145 } 146 147 function _list($item){ 148 149 $ex = explode(':', $item['id']); 150 151 for ($i = 0; $i < count($ex); $i += 2) 152 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 153 154 //pola brane pod uwagę przy określaniu aktualnej strony 155 $fields = array('bez'); 156 if ($item_value['bez'] == 'report') { 157 $fields[] = 'month'; 158 $fields[] = 'year'; 159 } 160 161 $actual_page = true; 162 foreach ($fields as $field) 163 if ($item_value[$field] != $this->value[$field]) 164 $actual_page = false; 165 166 167 168 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 169 $id = $item['id']; 170 if ($this->lang_code != $this->default_lang) 171 $id = $this->lang_code.':'.$id; 172 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 173 }else{ 174 $id = $item['id']; 175 if ($this->lang_code != $this->default_lang) 176 $id = $this->lang_code.':'.$id; 177 return $this->_bezlink($id, $item['title']); 178 } 179 180 } 181 182 function _li($item){ 183 if($item['type'] == "f"){ 184 return '<li class="level'.$item['level'].'">'; 185 }elseif($item['open']){ 186 return '<li class="open">'; 187 }else{ 188 return '<li class="closed">'; 189 } 190 } 191} 192