forked from opendocman/opendocman
-
Notifications
You must be signed in to change notification settings - Fork 1
/
crumb.php
119 lines (101 loc) · 3.77 KB
/
crumb.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
// +--------------------------------------------------------------------------+
// | crumb version 0.1.0.1 - 2003/01/04 |
// | by Michael J. Pawlowsky <[email protected]> |
// +--------------------------------------------------------------------------+
// | Copyright (c) 2003 RC Online Canada |
// +--------------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html |
// +--------------------------------------------------------------------------+
// | Original release available on PHP Classes: |
// | http://www.phpclasses.org/ |
// | |
// +--------------------------------------------------------------------------+
//
// 2003/01/04 - 0.1.0.1 fixed undefined tstr in addCrumb
class crumb
{
/**
* @return void
* @param level int
* @param title string
* @param url string
* @param post boolean
* @desc Add a bread crumb to the session array. If post is true add the $_POST args to the URL.
*/
public function addCrumb($level, $title, $url, $post = false)
{
$tstr = "";
if (isset($_SESSION['crumbs'][$level])) {
unset($_SESSION['crumbs'][$level]);
}
if ($post) {
if (strpos($url, "?")) {
$tstr = "&";
} else {
$tstr = "?";
}
foreach ($_POST as $key => $value) {
$tstr.=$key."=".urlencode($value)."&";
}
// pop off the last &
$tstr = rtrim($tstr, "&");
}
$tmp = array("title" => $title, "url" => $url . $tstr);
$_SESSION['crumbs'][$level] = $tmp;
} //end addCrumb()
/**
* @return void
* @param level int
* @desc Deletes a bread crumb.
*/
public function delCrumb($level)
{
if (isset($_SESSION['crumbs'][$level])) {
unset($_SESSION['crumbs'][$level]);
}
} //end delCrumb()
/**
* @return string $trail
* @param cur_level int
* @desc Print out the current crumb trail from $cur_level on down.
*/
public function printTrail($cur_level)
{
$trail = "<span class=\"crumb\">";
for ($i=1; $i != $cur_level+1; $i++) {
if (isset($_SESSION['crumbs'][$i])) {
if ($i != $cur_level) {
$trail .= "<a class=\"statusbar\" href=\"". $_SESSION['crumbs'][$i]['url'] . '">';
$trail .= $_SESSION['crumbs'][$i]['title'];
$trail .= "</a>";
} else {
$trail .= '<span class="statusbar">' . $_SESSION['crumbs'][$i]['title'] . '</span>';
$trail .= "</span>";
}
if ($i != $cur_level) {
$trail .= "<FONT class=\"statusbar\"> > </FONT>";
}
}
}
$trail .= "</span>";
return $trail;
} // end printTrail()
} //end class crumb
// ################# Example #############################
//Page1
// $crumb = new crumb();
// $crumb->addCrumb(1, "Review", $_SERVER['REQUEST_URI']);
// $crumb->printTrail(1);
//Page2
// $crumb = new crumb();
// $crumb->addCrumb(2, "Review", $_SERVER['REQUEST_URI']);
// $crumb->printTrail(2);
//Page3 - Is the results from a POST form.
// $crumb = new crumb();
// $crumb->addCrumb(3, "Review", $_SERVER['REQUEST_URI']), 1;
// $crumb->printTrail(3);
//Page4
// $crumb = new crumb();
// $crumb->addCrumb(4, "Review", $_SERVER['REQUEST_URI']);
// $crumb->printTrail(4);