fmt=dyntrailmenu:) Copyright 2008 Bianka Martinovic http://www.webbird.de */ SDV($RecipeInfo['DynTrailMenu']['Version'], '2014-10-29'); SDV($FPLFunctions['dyntrailmenu'], 'DynTrailMenu'); function DynTrailMenu($pagename, &$matches, $opt) { list( $id, $t ) = DynReadTrail( $pagename, $opt['trail'] ); $depth = $t[$id]['depth']; $out = array(); $paths = array(); ## create a path mapping if ( $t[$id]['path'] ) { foreach ( array_keys( $t[$id]['path'] ) as $item ) { $current .= '#'.$item; $paths[$current]++; } } $n = 0; foreach( $t as $current ) { ## it's not a root page, so we have to check the path if ( $current['path'] ) { $page_path = '#'.implode( '#', array_keys( $current['path'] ) ); ## current item is not a child of the currently shown page ## and it's not in the path if ( $current['parent'] != $id && ! array_key_exists( $page_path, $paths ) ) { continue; } } if ( $current['spacer'] ) { $out[ $n-1 ] .= "\\\\\n"; continue; } ## add current item to the list $out[$n] = str_repeat('*', $current['depth']) . " {$current['markup']}"; $n++; } $return = implode("\n", $out); return $return; } /* Filter out the list items */ function DynReadTrail( $pagename, $trailname ) { global $SuffixPattern, $GroupPattern, $WikiWordPattern; $trailname = MakePageName($pagename,$trailname); $trailpage = ReadPage($trailname, READPAGE_CURRENT); if (!$trailpage) return false; $t = array(); $n = 0; $listitems = array(); $pattern = "(\\[\\[([^|\\]]*)\\|?\\s*(.*?)\\s*\\]\\])($SuffixPattern) (.*) | ($GroupPattern([\\/.])?$WikiWordPattern) (.*)"; foreach( preg_split( "/\r?\n/", $trailpage['text'] ) as $x) { #$x = htmlspecialchars($x, ENT_NOQUOTES); ## leave blank lines as spacer if ( preg_match( "/^\s*$/", $x, $match ) ) { if ( $n == 0 ) { continue; } $listitems[$n]['id'] = $n; $listitems[$n]['spacer']++; $n++; continue; } ## is it a list item? if ( !preg_match( '/^([#*:]+)\s*(.*)/x', $x, $match ) ) { continue; } $item = ltrim(rtrim($match[2])); $listitems[$n]['id'] = $n; ## is it a wiki link? if ( preg_match( "/$pattern/x", $item, $wikilink) ) { $listitems[$n]['pagename'] = preg_replace( '#/#', '.', ltrim(rtrim($wikilink[2])) ); $listitems[$n]['markup'] = preg_replace( "/\\\\(?>(\\\\*))$/", "\n", ltrim(rtrim($wikilink[1])) ); $listitems[$n]['wikilink']++; #if ( $listitems[$n]['pagename'] == $pagename ) { if ( ! strcasecmp( $listitems[$n]['pagename'], $pagename ) ) { $id = $n; } } ## is it a free link? elseif ( preg_match( "/(\\[\\[\\s*(.*?)\\]\\])($SuffixPattern)(.*)/x", $item, $freelink ) ) { $listitems[$n]['markup'] = preg_replace( "/\\\\(?>(\\\\*))$/", "\n", ltrim(rtrim($freelink[1])) ); $listitems[$n]['freelink']++; } ## something else else { $text = ltrim(rtrim($match[2])); $listitems[$n]['markup'] = preg_replace( "/\\\\(?>(\\\\*))$/", "\n", $text ); } $depth = strlen( $match[1] ); $listitems[$n]['depth'] = $depth; for( $i=$depth;$i<10;$i++) { $d[$i] = $n; } if ( $depth > 1 ) { $parent = @$d[$depth-1]; $listitems[$n]['parent'] = $parent; $listitems[$n]['path'] = $listitems[$parent]['path']; $listitems[$n]['path'][$parent]++; $listitems[$parent]['children']++; } $n++; } return array( $id, $listitems ); }