-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from daviddelon/fd16162572806fb7a26dfd6c1de4b62…
…8bbb3271f fil d'ariane
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
// WikiTrails code V2.1 based on copyrighted code by G. M. Bowen & Andrew Somerville, 2005. | ||
// Version 2 stores the crumbs in the $_SESSION variable. This makes this feature usable for all users. | ||
// Originally Prepared for a SSHRC funded research project extended by Roland Stens, 2006. Licensed under GPL. | ||
// Please keep attributions if distributing code. | ||
|
||
# Define the maximum breadcrumbs shown. | ||
if ($max = $this->GetParameter("nb")) { | ||
$max = (int) $max; | ||
} | ||
else { | ||
$max=4; | ||
} | ||
|
||
|
||
$crumbs=Array(); | ||
|
||
# Just get the PageTage, no use in doing that more times than 1 | ||
|
||
$wikireq = $_REQUEST['wiki']; | ||
// remove leading slash | ||
$wikireq = preg_replace("/^\//", "", $wikireq); | ||
// split into page/method, checking wiki name & method name (XSS proof) | ||
if (preg_match('`^' . '(' . "[A-Za-z0-9]+" . ')/(' . "[A-Za-z0-9_-]" . '*)' . '$`', $wikireq, $matches)) { | ||
list(, $PageTag, $method) = $matches; | ||
} | ||
elseif (preg_match('`^' . "[A-Za-z0-9]+" . '$`', $wikireq)) { | ||
$PageTag = $wikireq; | ||
} | ||
|
||
# Find out if the breadcrumbs were already stored. | ||
if (!isset($_SESSION['breadcrumbs'])) { | ||
# Not stored yet, so set the current page name in the crumbs array. | ||
$crumbs[0]=$PageTag; | ||
} else { | ||
# The crumbs are already stored, so get them and put them in the crumbs array. | ||
$crumbs=$_SESSION['breadcrumbs']; | ||
|
||
if ($crumbs[count($crumbs)-1] != $this->GetPageTag() ) { | ||
# Test for the maximum amount of crumbs and if the last pagetag is not | ||
# the same as the last stored tag. If it is a duplicate we'll get rid of it later. | ||
if (count($crumbs) >= $max and $PageTag != $crumbs[$max - 1]) { | ||
# Drop the first element in the crumbs array. | ||
array_shift($crumbs); | ||
# Add the new page name to the last position in the array. | ||
$crumbs[$max - 1]= $PageTag; | ||
} | ||
else { | ||
# Not at the maximum yet, then just add to page to the end of the array. | ||
$crumbs[count($crumbs)]= $PageTag; | ||
} | ||
} | ||
} | ||
|
||
# Get rid of duplicates, but only if they are in subsequent array locations. | ||
$count=1; | ||
$temp = Array(); | ||
$target= Array(); | ||
# Only do this, if you have 3 or more entries in the array | ||
if (count($crumbs) > 2) { | ||
while ($count <= (count($crumbs) - 1)) { | ||
$temp[$count - 1] = $crumbs[$count - 1]; | ||
$temp[$count] = $crumbs[$count]; | ||
$temp = array_unique($temp); | ||
$target= $target + $temp; | ||
$temp = ""; | ||
$count++; | ||
} | ||
$crumbs = $target; | ||
} | ||
else { | ||
$crumbs = array_unique($crumbs); | ||
} | ||
|
||
|
||
# Save the breadcrumbs. | ||
$_SESSION['breadcrumbs'] = $crumbs; | ||
|
||
# Create the trail by walking through the array of page names. | ||
$separator = "\"\"<li>\"\""; | ||
$page_trail = "\"\"<ul class=\"breadcrumb\">\"\""; | ||
foreach ($crumbs as $this_crumb) { | ||
$page_trail .= $separator."[[".$this_crumb."]]"; | ||
$separator = "\"\"</li><span class=\"divider\">/</span><li>\"\""; | ||
} | ||
$page_trail .= "\"\"</ul>\"\""; | ||
|
||
echo $this->format($page_trail); | ||
?> |