Hi
I wanted more flexibility in the page trails feature and right now the
implementation is tightly coupled with the ouput. I modified the
existing functions and broke them out into one function to generate the
data and another to format it. Not shown here, but this makes it very
simple to override just the output to format things differently
Grateful if it could be accepted into core for a future release. Note,
I pasted the whole file for easy viewing - the changes only occur after
the ReadTrail function.
There are a couple of other changes I didn't make, but I would recommend:
Change the default trail separator to something more standard, eg "ยป"
(it looks like >> for those viewing in plain text):
SDV($TrailPathSep, ' » ');
Also at the end of the MakeTrailPath I would recommend that the trail is
always wrapped in a span, regardless of whether there is a trail or
not. Otherwise if the site owner has styled the trail then it will
suddenly jump to become an unstyled plain word when the trail is empty
(use another style even - that way it can be easily removed when the
trail is empty..)
return "<span class='wikitrail'>$trailname</span>";
After these changes it's easier to quickly override the formatting for
any of the wiki trails. Also there is now a prev and next link which
points only to items within the same level of the wiki trail (default
remains as before which is simply to jump to literally the next bullet
item, regardless of relative level
Ed W
> to be
used to build "trails" through wiki documents.
This feature is automatically included from stdconfig.php unless
disabled by $EnableWikiTrails = 0; . To explicitly include this feature,
execute
include_once("scripts/trails.php");
from config.php somewhere.
Once enabled, the <<|TrailPage|>> markup is replaced with
<< PrevPage | TrailPage | NextPage >> on output. TrailPage should
contain either a bullet or number list defining the sequence of pages
in the "trail".
The ^|TrailPage|^ markup uses the depth of the bullets to display
the ancestry of the TrailPage to the current one. The <|TrailPage|>
markup is like <<|TrailPage|>> except that "< PrevPage |" and
"| NextPage >" are omitted if at the beginning or end of the
trail respectively. Thanks to John Rankin for contributing these
markups and the original suggestion for WikiTrails.
*/
Markup('<<|','
<<|','/<\\|([^|]+|\\[\\[(.+?)\\]\\])\\|>/e',
"MakeTrailStopB(\$pagename,'$1')");
Markup('^|','>/' => '$1',
'/<\\|([^|]+|\\[\\[(.+?)\\]\\])\\|>/' => '$1',
'/\\^\\|([^|]+|\\[\\[(.+?)\\]\\])\\|\\^/' => '$1'));
$Conditions['ontrail'] = 'CondOnTrail($pagename, $condparm)';
function CondOnTrail($pagename, $condparm) {
@list($trailname, $pn) = preg_split('/\\s+/', $condparm, 2);
$trail = ReadTrail($pagename, $trailname);
if (!$trail) return false;
$pn = ($pn > '') ? MakePageName($pagename, $pn) : $pagename;
foreach($trail as $t)
if ($t['pagename'] == $pn) return true;
return false;
}
function ReadTrail($pagename, $trailname) {
global $RASPageName, $SuffixPattern, $GroupPattern, $WikiWordPattern,
$LinkWikiWords;
if (preg_match('/^\\[\\[(.+?)(->|\\|)(.+?)\\]\\]$/', $trailname, $m))
$trailname = ($m[2] == '|') ? $m[1] : $m[3];
$trailtext = RetrieveAuthSection($pagename, $trailname);
$trailname = $RASPageName;
$t = array();
$n = 0;
foreach(explode("\n", htmlspecialchars(@$trailtext, ENT_NOQUOTES))
as $x) {
$x = preg_replace("/\\[\\[([^\\]]*)->([^\\]]*)\\]\\]/",'[[$2|$1]]',$x);
if (!preg_match("/^([#*:]+) \\s*
(\\[\\[([^:#!|][^|:]*?)(\\|.*?)?\\]\\]($SuffixPattern)
| (($GroupPattern([\\/.]))?$WikiWordPattern)) (.*)/x",$x,$match))
continue;
if (@$match[6]) {
if (!$LinkWikiWords) continue;
$tgt = MakePageName($trailname, $match[6]);
} else $tgt = MakePageName($trailname,
preg_replace('/[#?].+/', '', $match[3]));
$t[$n]['depth'] = $depth = strlen($match[1]);
$t[$n]['pagename'] = $tgt;
$t[$n]['markup'] = $match[2];
$t[$n]['detail'] = $match[9];
for($i=$depth;$i<10;$i++) $d[$i]=$n;
if ($depth>1) $t[$n]['parent']...@$d[$depth-1];
$n++;
}
return $t;
}
/* Reads in the trail and returns an array of previous/next links
results['next'], results['prev'] are the direct next/prev items in the trail at any level
results['nextl'], results['prevl'] are the direct next/prev items at the SAME level as $pagename
*/
function FindNextPrev($pagename,$trailname) {
$t = ReadTrail($pagename,$trailname);
$results = array('prev'=>'', 'next'=>'', 'prevl'=>'', 'nextl'=>'');
# Loop looking for our page
for($i=0;$i0) {
$results['prev'] = $t[$i-1]['markup'];
# Skim back looking for next link in the same sub-tree level
for($j=$i-1;$j>=0;$j--) {
if ($t[$j]['parent'] == $t[$i]['parent']) {
$results['prevl'] = $t[$j]['markup'];
break;
}
if (!$t[$j]['parent']) break; // optimisation - bailout if we hit top level
}
}
# Is there a next (right) link
if ($i+1<< $prev | $trailname | $next >>";
}
function MakeTrailStopB($pagename,$trailname) {
$links = FindNextPrev($pagename,$trailname);
$prev=$links['prev'];
$next=$links['next'];
if ($prev) $prev = '< '.$prev.' | ';
if ($next) $next = ' | '.$next.' >';
return "$prev$trailname$next";
}
// Generates an array of all page items from root to pagename
function FindCrumbs($pagename,$trailname) {
$t = ReadTrail($pagename,$trailname);
$crumbs = array();
for($i=0;$i0) {
array_unshift($crumbs, $t[$i]['markup']);
$i = @$t[$i]['parent'];
}
break;
}
}
return $crumbs;
}
function MakeTrailPath($pagename,$trailname) {
global $TrailPathSep;
SDV($TrailPathSep,' | ');
$crumbs = FindCrumbs($pagename,$trailname);
if (count($crumbs)) {
return "$trailname$TrailPathSep" .
join($TrailPathSep, $crumbs) .
"";
} else {
return $trailname;
}
}
_______________________________________________
pmwiki-devel mailing list
pmwiki-devel@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel