1<?php
2    /**
3    * simpleindex:  A simple navigation plugin adapted from dokuwiki's built-in index function
4    * @license:     GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
5    * @author:      lainme <lainme993@gmail.com>
6    */
7
8    if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
9    if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10    require_once(DOKU_PLUGIN.'syntax.php');
11    require_once (DOKU_INC.'inc/search.php');
12
13    class syntax_plugin_simpleindex extends DokuWiki_Syntax_Plugin {
14        function getInfo(){
15            return array(
16	        'author' => 'lainme',
17                'email'  => 'lainme993@gmail.com',
18                'date'   => '2010-05-16',
19                'name'   => 'simpleindex',
20                'desc'   => 'A simple navigation plugin adapted from dokuwiki\'s built-in index function',
21                'url'    => 'http://www.dokuwiki.org/plugin:simpleindex',
22            );
23        }
24        function getType() { return 'substition';}
25        function getSort() { return 705;}
26        function getPType(){return 'block';}
27
28        function connectTo($mode) {
29            $this->Lexer->addSpecialPattern('<simpleindex[^>]*>',$mode,'plugin_simpleindex');
30        }
31        function handle($match, $state, $pos, &$handler){
32            $return=array();
33            $match = mb_substr($match,13,-1);
34            if (!empty($match)){
35                $match=explode(",",$match);
36                    foreach ($match as $value)
37                        $return[]=$value;
38            }
39            return $return;
40        }
41        function render($mode, &$renderer, $data) {
42            if($mode == 'xhtml'){
43                global $conf;
44                global $ACT;
45                if( $ACT != 'index'){
46                    $ns = $_SERVER['PHP_SELF'];
47                    $ns = preg_replace('/.*doku.php\//','',$ns);
48                    $ns = preg_replace('/\/[^\/]*$/','',$ns);
49                    $renderer->doc.= '<div id="index__tree">';
50                    $result = array();
51                    search($result,$conf['datadir'],'search_index',array('ns' => $ns));
52                    simpleindex_del($result,$data);
53                    $renderer->doc.=html_buildlist($result,'idx','html_list_index','html_li_index');
54                    $renderer->doc.= '</div>';
55                }
56                return true;
57            }
58            return false;
59        }
60    }
61    function simpleindex_del(&$result,$dels){
62        foreach ($dels as $del){
63            $temp=$result;
64            $result=array();
65            foreach ($temp as $value)
66                if (stripos($value['id'],$del)!==0)
67                    $result[]=$value;
68        }
69    }
70?>
71
72