xref: /plugin/simplenavi/syntax.php (revision 492ddc4e56f02a8f1bad2a6fff64a187b268db61)
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';
171169a1acSAndreas Gohr
181169a1acSAndreas Gohrclass syntax_plugin_simplenavi extends DokuWiki_Syntax_Plugin {
191169a1acSAndreas Gohr    function getType() {
201169a1acSAndreas Gohr        return 'substition';
211169a1acSAndreas Gohr    }
221169a1acSAndreas Gohr
231169a1acSAndreas Gohr    function getPType() {
241169a1acSAndreas Gohr        return 'block';
251169a1acSAndreas Gohr    }
261169a1acSAndreas Gohr
271169a1acSAndreas Gohr    function getSort() {
281169a1acSAndreas Gohr        return 155;
291169a1acSAndreas Gohr    }
301169a1acSAndreas Gohr
311169a1acSAndreas Gohr
321169a1acSAndreas Gohr    function connectTo($mode) {
331169a1acSAndreas Gohr        $this->Lexer->addSpecialPattern('{{simplenavi>[^}]*}}',$mode,'plugin_simplenavi');
341169a1acSAndreas Gohr    }
351169a1acSAndreas Gohr
361169a1acSAndreas Gohr    function handle($match, $state, $pos, &$handler){
371169a1acSAndreas Gohr        $data = array(cleanID(substr($match,13,-2)));
381169a1acSAndreas Gohr
391169a1acSAndreas Gohr        return $data;
401169a1acSAndreas Gohr    }
411169a1acSAndreas Gohr
421169a1acSAndreas Gohr    function render($mode, &$R, $pass) {
431169a1acSAndreas Gohr        if($mode != 'xhtml') return false;
441169a1acSAndreas Gohr
451169a1acSAndreas Gohr        global $conf;
461169a1acSAndreas Gohr        global $INFO;
471169a1acSAndreas Gohr        $R->info['cache'] = false;
481169a1acSAndreas Gohr
491169a1acSAndreas Gohr        $ns = utf8_encodeFN(str_replace(':','/',$pass[0]));
501169a1acSAndreas Gohr        $data = array();
511169a1acSAndreas Gohr        search($data,$conf['datadir'],array($this,'_search'),array('ns' => $INFO['id']),$ns);
521169a1acSAndreas Gohr
531169a1acSAndreas Gohr        $R->doc .= '<div class="plugin__simplenavi">';
541169a1acSAndreas Gohr        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
551169a1acSAndreas Gohr        $R->doc .= '</div>';
561169a1acSAndreas Gohr
571169a1acSAndreas Gohr        return true;
581169a1acSAndreas Gohr    }
591169a1acSAndreas Gohr
601169a1acSAndreas Gohr
611169a1acSAndreas Gohr
621169a1acSAndreas Gohr    function _list($item){
63*492ddc4eSAndreas Gohr        global $INFO;
64*492ddc4eSAndreas Gohr
65*492ddc4eSAndreas Gohr        if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){
66*492ddc4eSAndreas Gohr            return '<strong>'.html_wikilink(':'.$item['id']).'</strong>';
67*492ddc4eSAndreas Gohr        }else{
681169a1acSAndreas Gohr            return html_wikilink(':'.$item['id']);
69*492ddc4eSAndreas Gohr        }
701169a1acSAndreas Gohr
711169a1acSAndreas Gohr    }
721169a1acSAndreas Gohr
731169a1acSAndreas Gohr    function _li($item){
741169a1acSAndreas Gohr        if($item['type'] == "f"){
751169a1acSAndreas Gohr            return '<li class="level'.$item['level'].'">';
761169a1acSAndreas Gohr        }elseif($item['open']){
771169a1acSAndreas Gohr            return '<li class="open">';
781169a1acSAndreas Gohr        }else{
791169a1acSAndreas Gohr            return '<li class="closed">';
801169a1acSAndreas Gohr        }
811169a1acSAndreas Gohr    }
821169a1acSAndreas Gohr
831169a1acSAndreas Gohr    function _search(&$data,$base,$file,$type,$lvl,$opts){
841169a1acSAndreas Gohr        global $conf;
851169a1acSAndreas Gohr        $return = true;
861169a1acSAndreas Gohr
871169a1acSAndreas Gohr        $item = array();
881169a1acSAndreas Gohr
891169a1acSAndreas Gohr        $id = pathID($file);
901169a1acSAndreas Gohr
911169a1acSAndreas Gohr        if($type == 'd' && !(
921169a1acSAndreas Gohr            preg_match('#^'.$id.'(:|$)#',$opts['ns']) ||
931169a1acSAndreas Gohr            preg_match('#^'.$id.'(:|$)#',getNS($opts['ns']))
941169a1acSAndreas Gohr
951169a1acSAndreas Gohr        )){
961169a1acSAndreas Gohr            //add but don't recurse
971169a1acSAndreas Gohr            $return = false;
981169a1acSAndreas Gohr        }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){
991169a1acSAndreas Gohr            //don't add
1001169a1acSAndreas Gohr            return false;
1011169a1acSAndreas Gohr        }
1021169a1acSAndreas Gohr
1031169a1acSAndreas Gohr        if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){
1041169a1acSAndreas Gohr            return false;
1051169a1acSAndreas Gohr        }
1061169a1acSAndreas Gohr
1071169a1acSAndreas Gohr        if($type == 'd'){
1081169a1acSAndreas Gohr            // link directories to their start pages
1091169a1acSAndreas Gohr            $exists = false;
1101169a1acSAndreas Gohr            $id = "$id:";
1111169a1acSAndreas Gohr            resolve_pageid('',$id,$exists);
1121169a1acSAndreas Gohr            $this->startpages[$id] = 1;
1131169a1acSAndreas Gohr        }elseif($this->startpages[$id]){
1141169a1acSAndreas Gohr            // skip already shown start pages
1151169a1acSAndreas Gohr            return false;
1161169a1acSAndreas Gohr        }elseif(noNS($id) == $conf['start']){
1171169a1acSAndreas Gohr            // skip the main start page
1181169a1acSAndreas Gohr            return false;
1191169a1acSAndreas Gohr        }
1201169a1acSAndreas Gohr
1211169a1acSAndreas Gohr        //check hidden
1221169a1acSAndreas Gohr        if(isHiddenPage($id)){
1231169a1acSAndreas Gohr            return false;
1241169a1acSAndreas Gohr        }
1251169a1acSAndreas Gohr
1261169a1acSAndreas Gohr        //check ACL
1271169a1acSAndreas Gohr        if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
1281169a1acSAndreas Gohr            return false;
1291169a1acSAndreas Gohr        }
1301169a1acSAndreas Gohr
1311169a1acSAndreas Gohr        $data[]=array( 'id'    => $id,
1321169a1acSAndreas Gohr                       'type'  => $type,
1331169a1acSAndreas Gohr                       'level' => $lvl,
1341169a1acSAndreas Gohr                       'open'  => $return);
1351169a1acSAndreas Gohr        return $return;
1361169a1acSAndreas Gohr    }
1371169a1acSAndreas Gohr
1381169a1acSAndreas Gohr
1391169a1acSAndreas Gohr}
1401169a1acSAndreas Gohr
1411169a1acSAndreas Gohr// vim:ts=4:sw=4:et:enc=utf-8:
142