123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php if (!defined('PmWiki')) exit();
- $TrailLinkPattern =
- "(?:($GroupNamePattern)([\\/.]))?(($WikiWordPattern)|($FreeLinkPattern))";
- $DoubleBrackets["/<<\\|($TrailLinkPattern)\\|>>/e"]
- = 'MakeTrailStop("$1");';
- $DoubleBrackets["/<\\|($TrailLinkPattern)\\|>/e"]
- = 'MakeTrailStopB("$1");';
- $DoubleBrackets["/\\^\\|($TrailLinkPattern)\\|\\^/e"]
- = 'MakeTrailPath("$1");';
- SDV($TrailPathSep,' | ');
- function MakeTrailStop($link) {
- global $pagename;
- $t = ReadTrail($link);
- $prev = ''; $next = '';
- for($i=0;$i<count($t);$i++) {
- if ($t[$i]['name']==$pagename) {
- if ($i>0) $prev = $t[$i-1]['link'];
- if ($i+1<count($t)) $next = $t[$i+1]['link'];
- }
- }
- return
- "<span class='wikitrail'><< $prev | $link | $next >></span>";
- }
- function MakeTrailStopB($link) {
- global $pagename;
- $t = ReadTrail($link);
- $prev = ''; $next = '';
- for($i=0;$i<count($t);$i++) {
- if ($t[$i]['name']==$pagename) {
- if ($i>0) $prev = '< '.$t[$i-1]['link'].' | ';
- if ($i+1<count($t)) $next = ' | '.$t[$i+1]['link'].' >';
- }
- }
- return "<span class='wikitrail'>$prev$link$next</span>";
- }
- function MakeTrailPath($link) {
- global $pagename,$TrailPathSep;
- $t = ReadTrail($link);
- for($i=0;$i<count($t);$i++) {
- if ($t[$i]['name']==$pagename) {
- while ($t[$i]['depth']>0) {
- $crumbs = $TrailPathSep.$t[$i]['link'].$crumbs;
- $i = $t[$i]['parent'];
- }
- return "<span class='wikitrail'>$link$crumbs</span>";
- }
- }
- return $link;
- }
- function ReadTrail($link) {
- global $pagename,$TrailLinkPattern;
- $trailname = FmtWikiLink('',$link,NULL,'PageName');
- $trailpage = ReadPage($trailname);
- if ($trailpage) {
- $trailgroup = FmtPageName('$Group',$trailname);
- $n = 0;
- foreach(explode("\n",$trailpage['text']) as $x) {
- if (preg_match("/([#*]+)\\s*(\\[\\[)?($TrailLinkPattern)/",$x,$match)) {
- $t[$n]['depth'] = $depth = strlen($match[1]);
- $link = $match[3];
- if (!preg_match('![./]!',$link)) $link="$trailgroup/$link";
- $t[$n]['link'] = $link;
- $t[$n]['name'] = FmtWikiLink('',$link,NULL,'PageName',$trailname);
- if ($match[2]>'' &&
- preg_match("/^[#*]+\\s*\\[\\[($TrailLinkPattern)((?:\\s.*?)?\\]\\])/",$x,$dbm))
- $t[$n]['link'] = "[[$link".array_pop($dbm);
- for($i=$depth;$i<10;$i++) $d[$i] = $n;
- if ($depth>1) $t[$n]['parent']=@$d[$depth-1];
- $n++;
- }
- }
- }
- return $t;
- }
- ?>
|