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