Skip to content

Commit

Permalink
Merge pull request #4 from daviddelon/fd16162572806fb7a26dfd6c1de4b62…
Browse files Browse the repository at this point in the history
…8bbb3271f

fil d'ariane
  • Loading branch information
Florian committed May 22, 2012
2 parents 9c60cd7 + fd16162 commit d86c5d5
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tools/templates/actions/ariane.php
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);
?>

0 comments on commit d86c5d5

Please sign in to comment.