User Tools

Site Tools


dokuwikisnippets

DokuWiki Snippets

Extract a list from instructions

    public function parseList($page) {
        $instructions = p_cached_instructions(wikiFN($page),false,$page);
        $max = count($instructions);
 
        $list = $this->subList($instructions, $i = 0, $max, 1);
 
        dbg($list);
    }
 
 
    function subList(&$instructions, &$i, $max, $lvl) {
        $count = 0;
        $list = array();
 
 
        for(; $i<$max; $i++){
            if($instructions[$i][0] == 'listu_open'){
                $i++;
                if($count) {
                    $list[$count-1]['sub'] = $this->subList($instructions, $i, $max, $lvl+1);
                }
            }elseif($instructions[$i][0] == 'listu_close'){
                return $list;
            }elseif($instructions[$i][0] == 'listitem_close'){
 
            }elseif($instructions[$i][0] == 'internallink'){
                $page = $instructions[$i][1][0];
                $list[$count] = array(
                    'link'     => $page,
                    'type'     => 'internal',
                    'title'    => $instructions[$i][1][1],
                    'lvl'      => $lvl
                );
                $count++;
            }
        }
 
        return $list; // shouldn't be reached
    }
dokuwikisnippets.txt · Last modified: 2014/07/16 10:52 by andi