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/tasks.php"; 15include_once DOKU_PLUGIN."bez/models/issues.php"; 16/** 17 * All DokuWiki plugins to extend the parser/rendering mechanism 18 * need to inherit from this class 19 */ 20class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin { 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 handle($match, $state, $pos, &$handler) 32 { 33 return true; 34 } 35 36 function render($mode, &$R, $pass) { 37 global $INFO; 38 39 $helper = $this->loadHelper('bez'); 40 if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 41 42 $R->info['cache'] = false; 43 44 $data = array( 45 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 46 ); 47 48 if ($helper->user_editor()) 49 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report')); 50 51 $isso = new Issues(); 52 $no = count($isso->get_close_issue()); 53 $title = str_replace('%d', $no, $this->getLang('menu_close_issue')); 54 $data['bez:close_issue'] = array('id' => 'bez:close_issue', 'type' => 'f', 'level' => 2, 'title' => $title); 55 56 $tasko = new Tasks(); 57 $no = count($tasko->get_close_task()); 58 $title = str_replace('%d', $no, $this->getLang('menu_close_task')); 59 $data['bez:close_task'] = array('id' => 'bez:close_task', 'type' => 'f', 'level' => 2, 'title' => $title); 60 61 $data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues')); 62 $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 63 64 $data['bez:reports'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_reports')); 65 66 if ($helper->user_admin()) 67 $data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage')); 68 69 70 71 $id = $INFO['id']; 72 $ex = explode(':', $id); 73 $root = $ex[0]; 74 if ($root == 'bez') { 75 $data['bez:start']['open'] = true; 76 } else { 77 $data['bez:start']['open'] = false; 78 array_splice($data, 1); 79 } 80 81 $R->doc .= '<div class="plugin__bez">'; 82 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 83 $R->doc .= '</div>'; 84 85 return true; 86 } 87 88 function _bezlink($id, $title) { 89 $uri = wl($id); 90 return '<a href="'.$uri.'">'.($title).'</a>'; 91 } 92 93 function _list($item){ 94 global $INFO; 95 96 if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 97 return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>'; 98 }else{ 99 return $this->_bezlink($item['id'], $item['title']); 100 } 101 102 } 103 104 function _li($item){ 105 if($item['type'] == "f"){ 106 return '<li class="level'.$item['level'].'">'; 107 }elseif($item['open']){ 108 return '<li class="open">'; 109 }else{ 110 return '<li class="closed">'; 111 } 112 } 113} 114