44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
# 20200707 bkw: this breadcrumbs() function is loosely based on one
|
|
# from stackoverflow, but it's been simplified some.
|
|
function breadcrumbs($sep = ' » ', $home = 'Home') {
|
|
$pages = explode("/", $_SERVER['REQUEST_URI']);
|
|
|
|
# get rid of leading empty element, which will always be
|
|
# present since we split (exploded) on "/" and the URI
|
|
# always starts with a /. shift removes & returns the
|
|
# first (leftmost) element.
|
|
array_shift($pages);
|
|
|
|
# last dir shouldn't be a link, handled separately below.
|
|
# pop removes & returns the last (rightmost) element.
|
|
$last = array_pop($pages);
|
|
if($last == "") {
|
|
# if we got an empty $last, it means the URL ended
|
|
# with a /, so get the last non-empty path element
|
|
$last = array_pop($pages);
|
|
}
|
|
|
|
# links are server-relative, e.g. "/foo/bar" without the
|
|
# protocol or domain name. Build them in $url.
|
|
$url = "";
|
|
|
|
# home link is always visible and always a link. Doesn't
|
|
# matter on slackware.uk because the home page doesn't
|
|
# include breadcrumbs (no use for them there anyway).
|
|
$result = Array("<a href=\"/\">" . $home . "</a> ");
|
|
|
|
# PHP syntax note: $foo[] = "bar" is the same as Perl's
|
|
# push @foo, "bar".
|
|
foreach($pages as $dir) {
|
|
$url = $url . "/" . $dir;
|
|
$result[] = "<a href=\"" . $url . "\">" . $dir . "</a> ";
|
|
}
|
|
|
|
# add last (current) dir, but not as a link.
|
|
$result[] = $last;
|
|
|
|
# perl: return join($sep, @result);
|
|
return implode($sep, $result);
|
|
}
|
|
?>
|