User Tools

Site Tools


dokuwikisnippets
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Last revision
dokuwikisnippets [2014/07/16 08:52] – created andi
Line 1: Line 1:
 +====== DokuWiki Snippets ======
  
 +Extract a list from instructions
 +
 +<code php>
 +    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
 +    }
 +</code>
dokuwikisnippets.txt · Last modified: 2019/07/08 08:57 by andi