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'; 14 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 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 handle($match, $state, $pos, &$handler) 31 { 32 return true; 33 } 34 35 function render($mode, &$R, $pass) { 36 global $INFO; 37 38 $helper = $this->loadHelper('bez'); 39 if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 40 41 $R->info['cache'] = false; 42 43 $data = array( 44 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => 'bez'), 45 'bez:issues' => array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => 'bds_issues'), 46 ); 47 48 if ($helper->user_editor()) 49 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => 'bds_issue_report'); 50 51 if ($helper->user_admin()) 52 $data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => 'entity_manage'); 53 54 55 $id = $INFO['id']; 56 $ex = explode(':', $id); 57 $root = $ex[0]; 58 if ($root == 'bez') { 59 $data['bez:start']['open'] = true; 60 } else { 61 $data['bez:start']['open'] = false; 62 array_splice($data, 1); 63 } 64 65 $R->doc .= '<div class="plugin__bez">'; 66 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 67 $R->doc .= '</div>'; 68 69 return true; 70 } 71 72 function _bezlink($id, $title) { 73 $uri = wl($id); 74 return '<a href="'.$uri.'">'.$this->getLang($title).'</a>'; 75 } 76 77 function _list($item){ 78 global $INFO; 79 80 if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 81 return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>'; 82 }else{ 83 return $this->_bezlink($item['id'], $item['title']); 84 } 85 86 } 87 88 function _li($item){ 89 if($item['type'] == "f"){ 90 return '<li class="level'.$item['level'].'">'; 91 }elseif($item['open']){ 92 return '<li class="open">'; 93 }else{ 94 return '<li class="closed">'; 95 } 96 } 97} 98