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