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