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/syntax.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 62 63 function _list($item){ 64 global $INFO; 65 66 if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 67 return '<strong>'.html_wikilink(':'.$item['id']).'</strong>'; 68 }else{ 69 return html_wikilink(':'.$item['id']); 70 } 71 72 } 73 74 function _li($item){ 75 if($item['type'] == "f"){ 76 return '<li class="level'.$item['level'].'">'; 77 }elseif($item['open']){ 78 return '<li class="open">'; 79 }else{ 80 return '<li class="closed">'; 81 } 82 } 83 84 function _search(&$data,$base,$file,$type,$lvl,$opts){ 85 global $conf; 86 $return = true; 87 88 $item = array(); 89 90 $id = pathID($file); 91 92 if($type == 'd' && !( 93 preg_match('#^'.$id.'(:|$)#',$opts['ns']) || 94 preg_match('#^'.$id.'(:|$)#',getNS($opts['ns'])) 95 96 )){ 97 //add but don't recurse 98 $return = false; 99 }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){ 100 //don't add 101 return false; 102 } 103 104 if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){ 105 return false; 106 } 107 108 if($type == 'd'){ 109 // link directories to their start pages 110 $exists = false; 111 $id = "$id:"; 112 resolve_pageid('',$id,$exists); 113 $this->startpages[$id] = 1; 114 }elseif($this->startpages[$id]){ 115 // skip already shown start pages 116 return false; 117 }elseif(noNS($id) == $conf['start']){ 118 // skip the main start page 119 return false; 120 } 121 122 //check hidden 123 if(isHiddenPage($id)){ 124 return false; 125 } 126 127 //check ACL 128 if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){ 129 return false; 130 } 131 132 $data[]=array( 'id' => $id, 133 'type' => $type, 134 'level' => $lvl, 135 'open' => $return); 136 return $return; 137 } 138 139 140} 141 142// vim:ts=4:sw=4:et:enc=utf-8: 143