1<?php 2/** 3 * DokuWiki Plugin simplenavi (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr <gohr@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 15 16require_once DOKU_PLUGIN.'syntax.php'; 17require_once DOKU_INC.'inc/search.php'; 18 19class syntax_plugin_simplenavi extends DokuWiki_Syntax_Plugin { 20 function getType() { 21 return 'substition'; 22 } 23 24 function getPType() { 25 return 'block'; 26 } 27 28 function getSort() { 29 return 155; 30 } 31 32 33 function connectTo($mode) { 34 $this->Lexer->addSpecialPattern('{{simplenavi>[^}]*}}',$mode,'plugin_simplenavi'); 35 } 36 37 function handle($match, $state, $pos, &$handler){ 38 $data = array(cleanID(substr($match,13,-2))); 39 40 return $data; 41 } 42 43 function render($mode, &$R, $pass) { 44 if($mode != 'xhtml') return false; 45 46 global $conf; 47 global $INFO; 48 $R->info['cache'] = false; 49 50 $ns = utf8_encodeFN(str_replace(':','/',$pass[0])); 51 $data = array(); 52 search($data,$conf['datadir'],array($this,'_search'),array('ns' => $INFO['id']),$ns); 53 54 $R->doc .= '<div class="plugin__simplenavi">'; 55 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 56 $R->doc .= '</div>'; 57 58 return true; 59 } 60 61 function _list($item){ 62 global $INFO; 63 64 if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 65 return '<strong>'.html_wikilink(':'.$item['id'],$this->_title($item['id'])).'</strong>'; 66 }else{ 67 return html_wikilink(':'.$item['id'],$this->_title($item['id'])); 68 } 69 70 } 71 72 function _li($item){ 73 if($item['type'] == "f"){ 74 return '<li class="level'.$item['level'].'">'; 75 }elseif($item['open']){ 76 return '<li class="open">'; 77 }else{ 78 return '<li class="closed">'; 79 } 80 } 81 82 function _search(&$data,$base,$file,$type,$lvl,$opts){ 83 global $conf; 84 $return = true; 85 86 $item = array(); 87 88 $id = pathID($file); 89 90 if($type == 'd' && !( 91 preg_match('#^'.$id.'(:|$)#',$opts['ns']) || 92 preg_match('#^'.$id.'(:|$)#',getNS($opts['ns'])) 93 94 )){ 95 //add but don't recurse 96 $return = false; 97 }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){ 98 //don't add 99 return false; 100 } 101 102 if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){ 103 return false; 104 } 105 106 if($type == 'd'){ 107 // link directories to their start pages 108 $exists = false; 109 $id = "$id:"; 110 resolve_pageid('',$id,$exists); 111 $this->startpages[$id] = 1; 112 }elseif($this->startpages[$id]){ 113 // skip already shown start pages 114 return false; 115 }elseif(noNS($id) == $conf['start']){ 116 // skip the main start page 117 return false; 118 } 119 120 //check hidden 121 if(isHiddenPage($id)){ 122 return false; 123 } 124 125 //check ACL 126 if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){ 127 return false; 128 } 129 130 $data[]=array( 'id' => $id, 131 'type' => $type, 132 'level' => $lvl, 133 'open' => $return); 134 return $return; 135 } 136 137 function _title($id) { 138 global $conf; 139 140 if(useHeading('navigation')){ 141 $p = p_get_first_heading($id); 142 } 143 if($p) return $p; 144 145 $p = noNS($id); 146 if ($p == $conf['start'] || $p == false) { 147 $p = noNS(getNS($id)); 148 if ($p == false) { 149 return $conf['start']; 150 } 151 } 152 return $p; 153 } 154 155} 156 157// vim:ts=4:sw=4:et:enc=utf-8: 158