-
Notifications
You must be signed in to change notification settings - Fork 0
/
indxr_breadcrumbs.php
47 lines (40 loc) · 1.93 KB
/
indxr_breadcrumbs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// Create an array to store breadcrumb links and titles
$breadcrumb = array();
$currentDir = getcwd();
$scriptDir = dirname(__FILE__);
$relativePath = '/' . ltrim(substr($currentDir, strlen($scriptDir)), '/');
$dirComponents = explode('/', $relativePath);
$link = '/';
// Loop through each directory component and build the breadcrumb
foreach ($dirComponents as $component) {
if ($component !== "") {
$link .= $component . '/';
$breadcrumb[] = array(
'link' => $link,
'title' => htmlspecialchars($component)
);
}
}
// Make the "Home" link always point to the root of the domain
$baseUrl = "http://cored.org/";
// Filter out empty components before building the trail
$breadcrumb = array_filter($breadcrumb, function ($component) {
return !empty(trim($component['title']));
});
// Construct the hierarchical breadcrumb trail for the Home link
echo '<strong>Navigate:</strong> <a href="' . htmlspecialchars($baseUrl) . '"> <i class="fi-home"></i> Home</a>';
// Construct the hierarchical breadcrumb trail
// echo 'Navigate: <a href="' . htmlspecialchars($baseUrl) . '">Home</a>';
// Iterate through directory components and display them with icons
$breadcrumbCount = count($breadcrumb);
foreach ($breadcrumb as $index => $component) {
echo '<span class="separator"> » </span>';
// Check if this is the last breadcrumb item
if ($index === $breadcrumbCount - 1) {
echo '<a href="' . htmlspecialchars($component['link']) . '"> <i class="fi-folder"></i> <strong>' . $component['title'] . '</strong></a>';
} else {
echo '<a href="' . htmlspecialchars($component['link']) . '"> <i class="fi-folder"></i> ' . $component['title'] . '</a>';
}
}
?>