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'; 17e306992cSAndreas 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(); 52*db559ff9SMichael Große search($data,$conf['datadir'],array($this,'_search'),array('ns' => $INFO['id']),$ns,'natural'); 53*db559ff9SMichael Große if ($this->getConf('sort') == 'ascii') { 54ba93e3e3Slainme uksort($data, array($this, '_cmp')); 55*db559ff9SMichael Große } 561169a1acSAndreas Gohr 571169a1acSAndreas Gohr $R->doc .= '<div class="plugin__simplenavi">'; 581169a1acSAndreas Gohr $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 591169a1acSAndreas Gohr $R->doc .= '</div>'; 601169a1acSAndreas Gohr 611169a1acSAndreas Gohr return true; 621169a1acSAndreas Gohr } 631169a1acSAndreas Gohr 641169a1acSAndreas Gohr function _list($item){ 65492ddc4eSAndreas Gohr global $INFO; 66492ddc4eSAndreas Gohr 67492ddc4eSAndreas Gohr if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){ 680afc1916SAndreas Gohr return '<strong>'.html_wikilink(':'.$item['id'],$this->_title($item['id'])).'</strong>'; 69492ddc4eSAndreas Gohr }else{ 70e306992cSAndreas Gohr return html_wikilink(':'.$item['id'],$this->_title($item['id'])); 71492ddc4eSAndreas Gohr } 721169a1acSAndreas Gohr 731169a1acSAndreas Gohr } 741169a1acSAndreas Gohr 751169a1acSAndreas Gohr function _li($item){ 761169a1acSAndreas Gohr if($item['type'] == "f"){ 771169a1acSAndreas Gohr return '<li class="level'.$item['level'].'">'; 781169a1acSAndreas Gohr }elseif($item['open']){ 791169a1acSAndreas Gohr return '<li class="open">'; 801169a1acSAndreas Gohr }else{ 811169a1acSAndreas Gohr return '<li class="closed">'; 821169a1acSAndreas Gohr } 831169a1acSAndreas Gohr } 841169a1acSAndreas Gohr 851169a1acSAndreas Gohr function _search(&$data,$base,$file,$type,$lvl,$opts){ 861169a1acSAndreas Gohr global $conf; 871169a1acSAndreas Gohr $return = true; 881169a1acSAndreas Gohr 891169a1acSAndreas Gohr $item = array(); 901169a1acSAndreas Gohr 911169a1acSAndreas Gohr $id = pathID($file); 921169a1acSAndreas Gohr 931169a1acSAndreas Gohr if($type == 'd' && !( 941169a1acSAndreas Gohr preg_match('#^'.$id.'(:|$)#',$opts['ns']) || 951169a1acSAndreas Gohr preg_match('#^'.$id.'(:|$)#',getNS($opts['ns'])) 961169a1acSAndreas Gohr 971169a1acSAndreas Gohr )){ 981169a1acSAndreas Gohr //add but don't recurse 991169a1acSAndreas Gohr $return = false; 1001169a1acSAndreas Gohr }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){ 1011169a1acSAndreas Gohr //don't add 1021169a1acSAndreas Gohr return false; 1031169a1acSAndreas Gohr } 1041169a1acSAndreas Gohr 1051169a1acSAndreas Gohr if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){ 1061169a1acSAndreas Gohr return false; 1071169a1acSAndreas Gohr } 1081169a1acSAndreas Gohr 1091169a1acSAndreas Gohr if($type == 'd'){ 1101169a1acSAndreas Gohr // link directories to their start pages 1111169a1acSAndreas Gohr $exists = false; 1121169a1acSAndreas Gohr $id = "$id:"; 1131169a1acSAndreas Gohr resolve_pageid('',$id,$exists); 1141169a1acSAndreas Gohr $this->startpages[$id] = 1; 1151169a1acSAndreas Gohr }elseif($this->startpages[$id]){ 1161169a1acSAndreas Gohr // skip already shown start pages 1171169a1acSAndreas Gohr return false; 1181169a1acSAndreas Gohr }elseif(noNS($id) == $conf['start']){ 1191169a1acSAndreas Gohr // skip the main start page 1201169a1acSAndreas Gohr return false; 1211169a1acSAndreas Gohr } 1221169a1acSAndreas Gohr 1231169a1acSAndreas Gohr //check hidden 1241169a1acSAndreas Gohr if(isHiddenPage($id)){ 1251169a1acSAndreas Gohr return false; 1261169a1acSAndreas Gohr } 1271169a1acSAndreas Gohr 1281169a1acSAndreas Gohr //check ACL 1291169a1acSAndreas Gohr if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){ 1301169a1acSAndreas Gohr return false; 1311169a1acSAndreas Gohr } 1321169a1acSAndreas Gohr 1334591df21Slainme $data[$id]=array( 'id' => $id, 1341169a1acSAndreas Gohr 'type' => $type, 1351169a1acSAndreas Gohr 'level' => $lvl, 1361169a1acSAndreas Gohr 'open' => $return); 1371169a1acSAndreas Gohr return $return; 1381169a1acSAndreas Gohr } 1391169a1acSAndreas Gohr 140e306992cSAndreas Gohr function _title($id) { 141e306992cSAndreas Gohr global $conf; 142e306992cSAndreas Gohr 143e306992cSAndreas Gohr if(useHeading('navigation')){ 144e306992cSAndreas Gohr $p = p_get_first_heading($id); 145e306992cSAndreas Gohr } 146e306992cSAndreas Gohr if($p) return $p; 147e306992cSAndreas Gohr 148e306992cSAndreas Gohr $p = noNS($id); 149e306992cSAndreas Gohr if ($p == $conf['start'] || $p == false) { 150e306992cSAndreas Gohr $p = noNS(getNS($id)); 151e306992cSAndreas Gohr if ($p == false) { 152e306992cSAndreas Gohr return $conf['start']; 153e306992cSAndreas Gohr } 154e306992cSAndreas Gohr } 155e306992cSAndreas Gohr return $p; 156e306992cSAndreas Gohr } 1571169a1acSAndreas Gohr 1584591df21Slainme function _cmp($a, $b) { 1594591df21Slainme global $conf; 1604591df21Slainme 161489d7cb7Slainme $a = preg_replace('/:'.preg_quote($conf['start'], '/').'$/', '', $a); 162489d7cb7Slainme $b = preg_replace('/:'.preg_quote($conf['start'], '/').'$/', '', $b); 1634591df21Slainme 1644591df21Slainme return strcmp($a, $b); 1654591df21Slainme } 1661169a1acSAndreas Gohr} 1671169a1acSAndreas Gohr 1684591df21Slainme// vim:ts=4:sw=4:et: 169