11169a1acSAndreas Gohr<?php 21169a1acSAndreas Gohr/** 31169a1acSAndreas Gohr * DokuWiki Plugin simplenavi (Syntax Component) 41169a1acSAndreas Gohr * 51169a1acSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 61169a1acSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 71169a1acSAndreas Gohr */ 81169a1acSAndreas Gohr 91169a1acSAndreas Gohr// must be run within Dokuwiki 101169a1acSAndreas Gohrif (!defined('DOKU_INC')) die(); 111169a1acSAndreas Gohr 121169a1acSAndreas Gohrif (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 131169a1acSAndreas Gohrif (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 141169a1acSAndreas Gohrif (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 151169a1acSAndreas Gohr 161169a1acSAndreas Gohrrequire_once DOKU_PLUGIN.'syntax.php'; 17*e306992cSAndreas Gohrrequire_once DOKU_INC.'inc/search.php'; 181169a1acSAndreas Gohr 191169a1acSAndreas Gohrclass syntax_plugin_simplenavi extends DokuWiki_Syntax_Plugin { 201169a1acSAndreas Gohr function getType() { 211169a1acSAndreas Gohr return 'substition'; 221169a1acSAndreas Gohr } 231169a1acSAndreas Gohr 241169a1acSAndreas Gohr function getPType() { 251169a1acSAndreas Gohr return 'block'; 261169a1acSAndreas Gohr } 271169a1acSAndreas Gohr 281169a1acSAndreas Gohr function getSort() { 291169a1acSAndreas Gohr return 155; 301169a1acSAndreas Gohr } 311169a1acSAndreas Gohr 321169a1acSAndreas Gohr 331169a1acSAndreas Gohr function connectTo($mode) { 341169a1acSAndreas Gohr $this->Lexer->addSpecialPattern('{{simplenavi>[^}]*}}',$mode,'plugin_simplenavi'); 351169a1acSAndreas Gohr } 361169a1acSAndreas Gohr 371169a1acSAndreas Gohr function handle($match, $state, $pos, &$handler){ 381169a1acSAndreas Gohr $data = array(cleanID(substr($match,13,-2))); 391169a1acSAndreas Gohr 401169a1acSAndreas Gohr return $data; 411169a1acSAndreas Gohr } 421169a1acSAndreas Gohr 431169a1acSAndreas Gohr function render($mode, &$R, $pass) { 441169a1acSAndreas Gohr if($mode != 'xhtml') return false; 451169a1acSAndreas Gohr 461169a1acSAndreas Gohr global $conf; 471169a1acSAndreas Gohr global $INFO; 481169a1acSAndreas Gohr $R->info['cache'] = false; 491169a1acSAndreas Gohr 501169a1acSAndreas Gohr $ns = utf8_encodeFN(str_replace(':','/',$pass[0])); 511169a1acSAndreas Gohr $data = array(); 521169a1acSAndreas Gohr search($data,$conf['datadir'],array($this,'_search'),array('ns' => $INFO['id']),$ns); 531169a1acSAndreas Gohr 541169a1acSAndreas Gohr $R->doc .= '<div class="plugin__simplenavi">'; 551169a1acSAndreas Gohr $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 561169a1acSAndreas Gohr $R->doc .= '</div>'; 571169a1acSAndreas Gohr 581169a1acSAndreas Gohr return true; 591169a1acSAndreas Gohr } 601169a1acSAndreas Gohr 611169a1acSAndreas Gohr function _list($item){ 62492ddc4eSAndreas Gohr global $INFO; 63492ddc4eSAndreas Gohr 64492ddc4eSAndreas Gohr if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 65492ddc4eSAndreas Gohr return '<strong>'.html_wikilink(':'.$item['id']).'</strong>'; 66492ddc4eSAndreas Gohr }else{ 67*e306992cSAndreas Gohr return html_wikilink(':'.$item['id'],$this->_title($item['id'])); 68492ddc4eSAndreas Gohr } 691169a1acSAndreas Gohr 701169a1acSAndreas Gohr } 711169a1acSAndreas Gohr 721169a1acSAndreas Gohr function _li($item){ 731169a1acSAndreas Gohr if($item['type'] == "f"){ 741169a1acSAndreas Gohr return '<li class="level'.$item['level'].'">'; 751169a1acSAndreas Gohr }elseif($item['open']){ 761169a1acSAndreas Gohr return '<li class="open">'; 771169a1acSAndreas Gohr }else{ 781169a1acSAndreas Gohr return '<li class="closed">'; 791169a1acSAndreas Gohr } 801169a1acSAndreas Gohr } 811169a1acSAndreas Gohr 821169a1acSAndreas Gohr function _search(&$data,$base,$file,$type,$lvl,$opts){ 831169a1acSAndreas Gohr global $conf; 841169a1acSAndreas Gohr $return = true; 851169a1acSAndreas Gohr 861169a1acSAndreas Gohr $item = array(); 871169a1acSAndreas Gohr 881169a1acSAndreas Gohr $id = pathID($file); 891169a1acSAndreas Gohr 901169a1acSAndreas Gohr if($type == 'd' && !( 911169a1acSAndreas Gohr preg_match('#^'.$id.'(:|$)#',$opts['ns']) || 921169a1acSAndreas Gohr preg_match('#^'.$id.'(:|$)#',getNS($opts['ns'])) 931169a1acSAndreas Gohr 941169a1acSAndreas Gohr )){ 951169a1acSAndreas Gohr //add but don't recurse 961169a1acSAndreas Gohr $return = false; 971169a1acSAndreas Gohr }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){ 981169a1acSAndreas Gohr //don't add 991169a1acSAndreas Gohr return false; 1001169a1acSAndreas Gohr } 1011169a1acSAndreas Gohr 1021169a1acSAndreas Gohr if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){ 1031169a1acSAndreas Gohr return false; 1041169a1acSAndreas Gohr } 1051169a1acSAndreas Gohr 1061169a1acSAndreas Gohr if($type == 'd'){ 1071169a1acSAndreas Gohr // link directories to their start pages 1081169a1acSAndreas Gohr $exists = false; 1091169a1acSAndreas Gohr $id = "$id:"; 1101169a1acSAndreas Gohr resolve_pageid('',$id,$exists); 1111169a1acSAndreas Gohr $this->startpages[$id] = 1; 1121169a1acSAndreas Gohr }elseif($this->startpages[$id]){ 1131169a1acSAndreas Gohr // skip already shown start pages 1141169a1acSAndreas Gohr return false; 1151169a1acSAndreas Gohr }elseif(noNS($id) == $conf['start']){ 1161169a1acSAndreas Gohr // skip the main start page 1171169a1acSAndreas Gohr return false; 1181169a1acSAndreas Gohr } 1191169a1acSAndreas Gohr 1201169a1acSAndreas Gohr //check hidden 1211169a1acSAndreas Gohr if(isHiddenPage($id)){ 1221169a1acSAndreas Gohr return false; 1231169a1acSAndreas Gohr } 1241169a1acSAndreas Gohr 1251169a1acSAndreas Gohr //check ACL 1261169a1acSAndreas Gohr if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){ 1271169a1acSAndreas Gohr return false; 1281169a1acSAndreas Gohr } 1291169a1acSAndreas Gohr 1301169a1acSAndreas Gohr $data[]=array( 'id' => $id, 1311169a1acSAndreas Gohr 'type' => $type, 1321169a1acSAndreas Gohr 'level' => $lvl, 1331169a1acSAndreas Gohr 'open' => $return); 1341169a1acSAndreas Gohr return $return; 1351169a1acSAndreas Gohr } 1361169a1acSAndreas Gohr 137*e306992cSAndreas Gohr function _title($id) { 138*e306992cSAndreas Gohr global $conf; 139*e306992cSAndreas Gohr 140*e306992cSAndreas Gohr if(useHeading('navigation')){ 141*e306992cSAndreas Gohr $p = p_get_first_heading($id); 142*e306992cSAndreas Gohr } 143*e306992cSAndreas Gohr if($p) return $p; 144*e306992cSAndreas Gohr 145*e306992cSAndreas Gohr $p = noNS($id); 146*e306992cSAndreas Gohr if ($p == $conf['start'] || $p == false) { 147*e306992cSAndreas Gohr $p = noNS(getNS($id)); 148*e306992cSAndreas Gohr if ($p == false) { 149*e306992cSAndreas Gohr return $conf['start']; 150*e306992cSAndreas Gohr } 151*e306992cSAndreas Gohr } 152*e306992cSAndreas Gohr return $p; 153*e306992cSAndreas Gohr } 1541169a1acSAndreas Gohr 1551169a1acSAndreas Gohr} 1561169a1acSAndreas Gohr 1571169a1acSAndreas Gohr// vim:ts=4:sw=4:et:enc=utf-8: 158