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 21 function getPType() { return 'block'; } 22 function getType() { return 'substition'; } 23 function getSort() { return 99; } 24 25 26 function connectTo($mode) { 27 $this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav'); 28 } 29 30 function __construct() { 31 32 $ex = explode(':', $_GET['id']); 33 for ($i = 0; $i < count($ex); $i += 2) 34 $this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 35 } 36 37 function handle($match, $state, $pos, &$handler) 38 { 39 return true; 40 } 41 42 function render($mode, &$R, $pass) { 43 global $INFO; 44 45 $helper = $this->loadHelper('bez'); 46 if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 47 48 $R->info['cache'] = false; 49 50 $data = array( 51 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 52 ); 53 54 if ($helper->user_editor()) 55 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report')); 56 57 $data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues')); 58 $data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 59 60 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 61 62 63 64 65 $isso = new Issues(); 66 if ($this->value['bez'] == 'report') { 67 $data['bez:report']['open'] = true; 68 69 $oldest = $isso->get_oldest_close_date(); 70 $year_old = (int)date('Y', $oldest); 71 $mon_old = (int)date('n', $oldest); 72 $year_now = (int)date('Y'); 73 $mon_now = (int)date('n'); 74 75 $entity = ''; 76 if (array_key_exists('entity', $this->value)) { 77 $entity = ':entity:'.urlencode($this->value['entity']); 78 } 79 80 $mon = $mon_old; 81 for ($year = $year_old; $year <= $year_now; $year++) { 82 83 $y_key = 'bez:report:year:'.$year; 84 $data[$y_key] = array('id' => $y_key.$entity, 'type' => 'd', 'level' => 3, 'title' => $year); 85 86 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 87 $data['bez:report:year:'.$year]['open'] = true; 88 89 if ($year == $year_now) 90 $mon_max = $mon_now; 91 else 92 $mon_max = 12; 93 for ( ; $mon <= $mon_max; $mon++) { 94 $m_key = $y_key.':month:'.$mon; 95 $data[$m_key] = array('id' => $m_key.$entity, 'type' => 'f', 'level' => 4, 96 'title' => $mon < 10 ? '0'.$mon : $mon); 97 } 98 } 99 $mon = 1; 100 } 101 } 102 103 104 105 if (isset($this->value['bez'])) { 106 $data['bez:start']['open'] = true; 107 } else { 108 $data['bez:start']['open'] = false; 109 array_splice($data, 1); 110 } 111 112 if ($helper->user_admin() && $data['bez:start']['open'] == true) 113 $data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage')); 114 115 $R->doc .= '<div class="plugin__bez">'; 116 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 117 $R->doc .= '</div>'; 118 119 return true; 120 } 121 122 function _bezlink($id, $title) { 123 //$uri = wl($id); 124 $uri = DOKU_URL . 'doku.php?id='.$id; 125 return '<a href="'.$uri.'">'.($title).'</a>'; 126 } 127 128 function _list($item){ 129 130 $ex = explode(':', $item['id']); 131 for ($i = 0; $i < count($ex); $i += 2) 132 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 133 134 //pola brane pod uwagę przy określaniu aktualnej strony 135 $fields = array('bez'); 136 if ($item_value['bez'] == 'report') { 137 $fields[] = 'month'; 138 $fields[] = 'year'; 139 } 140 141 $actual_page = true; 142 foreach ($fields as $field) 143 if ($item_value[$field] != $this->value[$field]) 144 $actual_page = false; 145 146 147 148 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 149 return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>'; 150 }else{ 151 return $this->_bezlink($item['id'], $item['title']); 152 } 153 154 } 155 156 function _li($item){ 157 if($item['type'] == "f"){ 158 return '<li class="level'.$item['level'].'">'; 159 }elseif($item['open']){ 160 return '<li class="open">'; 161 }else{ 162 return '<li class="closed">'; 163 } 164 } 165} 166