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 $no = count($isso->get_comment_issue()); 62 $title = str_replace('%d', $no, $this->getLang('menu_comment_issue')); 63 $data['bez:comment_issue'] = array('id' => 'bez:comment_issue', 'type' => 'f', 'level' => 2, 'title' => $title); 64 65 66 $data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues')); 67 68 if ($helper->user_admin()) 69 $data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage')); 70 71 72 $id = $INFO['id']; 73 $ex = explode(':', $id); 74 $root = $ex[0]; 75 if ($root == 'bez') { 76 $data['bez:start']['open'] = true; 77 } else { 78 $data['bez:start']['open'] = false; 79 array_splice($data, 1); 80 } 81 82 $R->doc .= '<div class="plugin__bez">'; 83 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 84 $R->doc .= '</div>'; 85 86 return true; 87 } 88 89 function _bezlink($id, $title) { 90 $uri = wl($id); 91 return '<a href="'.$uri.'">'.($title).'</a>'; 92 } 93 94 function _list($item){ 95 global $INFO; 96 97 if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 98 return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>'; 99 }else{ 100 return $this->_bezlink($item['id'], $item['title']); 101 } 102 103 } 104 105 function _li($item){ 106 if($item['type'] == "f"){ 107 return '<li class="level'.$item['level'].'">'; 108 }elseif($item['open']){ 109 return '<li class="open">'; 110 }else{ 111 return '<li class="closed">'; 112 } 113 } 114} 115