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'; 17 18class syntax_plugin_simplenavi extends DokuWiki_Syntax_Plugin { 19 function getType() { 20 return 'substition'; 21 } 22 23 function getPType() { 24 return 'block'; 25 } 26 27 function getSort() { 28 return 155; 29 } 30 31 32 function connectTo($mode) { 33 $this->Lexer->addSpecialPattern('{{simplenavi>[^}]*}}',$mode,'plugin_simplenavi'); 34 } 35 36 function handle($match, $state, $pos, &$handler){ 37 $data = array(cleanID(substr($match,13,-2))); 38 39 return $data; 40 } 41 42 function render($mode, &$R, $pass) { 43 if($mode != 'xhtml') return false; 44 45 global $conf; 46 global $INFO; 47 $R->info['cache'] = false; 48 49 $ns = utf8_encodeFN(str_replace(':','/',$pass[0])); 50 $data = array(); 51 search($data,$conf['datadir'],array($this,'_search'),array('ns' => $INFO['id']),$ns); 52 53 $R->doc .= '<div class="plugin__simplenavi">'; 54 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 55 $R->doc .= '</div>'; 56 57 return true; 58 } 59 60 61 62 function _list($item){ 63 return html_wikilink(':'.$item['id']); 64 65 } 66 67 function _li($item){ 68 if($item['type'] == "f"){ 69 return '<li class="level'.$item['level'].'">'; 70 }elseif($item['open']){ 71 return '<li class="open">'; 72 }else{ 73 return '<li class="closed">'; 74 } 75 } 76 77 function _search(&$data,$base,$file,$type,$lvl,$opts){ 78 global $conf; 79 $return = true; 80 81 $item = array(); 82 83 $id = pathID($file); 84 85 if($type == 'd' && !( 86 preg_match('#^'.$id.'(:|$)#',$opts['ns']) || 87 preg_match('#^'.$id.'(:|$)#',getNS($opts['ns'])) 88 89 )){ 90 //add but don't recurse 91 $return = false; 92 }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){ 93 //don't add 94 return false; 95 } 96 97 if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){ 98 return false; 99 } 100 101 if($type == 'd'){ 102 // link directories to their start pages 103 $exists = false; 104 $id = "$id:"; 105 resolve_pageid('',$id,$exists); 106 $this->startpages[$id] = 1; 107 }elseif($this->startpages[$id]){ 108 // skip already shown start pages 109 return false; 110 }elseif(noNS($id) == $conf['start']){ 111 // skip the main start page 112 return false; 113 } 114 115 //check hidden 116 if(isHiddenPage($id)){ 117 return false; 118 } 119 120 //check ACL 121 if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){ 122 return false; 123 } 124 125 $data[]=array( 'id' => $id, 126 'type' => $type, 127 'level' => $lvl, 128 'open' => $return); 129 return $return; 130 } 131 132 133} 134 135// vim:ts=4:sw=4:et:enc=utf-8: 136