1
+ <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
2
+ /**
3
+ * Breadcrumb Class
4
+ *
5
+ * This class manages the breadcrumb object
6
+ *
7
+ * @author Richard Davey <info@richarddavey.com>
8
+ * @copyright Copyright (c) 2011, Richard Davey
9
+ * @package CodeIgniter
10
+ * @subpackage Libraries
11
+ * @link https://github.com/richarddavey/codeigniter-breadcrumb
12
+ */
13
+ class Breadcrumb {
14
+
15
+ /**
16
+ * Breadcrumbs stack
17
+ *
18
+ */
19
+ private $ breadcrumbs = array ();
20
+
21
+ /**
22
+ * Options
23
+ *
24
+ */
25
+ private $ divider = ' › ' ;
26
+ private $ tag_open = '<div id="breadcrumb"> ' ;
27
+ private $ tag_close = '</div> ' ;
28
+
29
+ /**
30
+ * Constructor
31
+ *
32
+ * @access public
33
+ * @param array initialization parameters
34
+ */
35
+ public function __construct ($ params = array ())
36
+ {
37
+ if (count ($ params ) > 0 )
38
+ {
39
+ $ this ->initialize ($ params );
40
+ }
41
+
42
+ log_message ('debug ' , "Breadcrumb Class Initialized " );
43
+ }
44
+
45
+ // --------------------------------------------------------------------
46
+
47
+ /**
48
+ * Initialize Preferences
49
+ *
50
+ * @access public
51
+ * @param array initialization parameters
52
+ * @return void
53
+ */
54
+ private function initialize ($ params = array ())
55
+ {
56
+ if (count ($ params ) > 0 )
57
+ {
58
+ foreach ($ params as $ key => $ val )
59
+ {
60
+ if (in_array ($ key , array ('divider ' , 'tag_open ' , 'tag_close ' )) AND isset ($ this ->$ key ))
61
+ {
62
+ $ this ->$ key = $ val ;
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ // --------------------------------------------------------------------
69
+
70
+ /**
71
+ * Append crumb to stack
72
+ *
73
+ * @access public
74
+ * @param string $title
75
+ * @param string $href
76
+ * @return void
77
+ */
78
+ function append_crumb ($ title , $ href )
79
+ {
80
+ // no title or href provided
81
+ if (!$ title OR !$ href ) return ;
82
+
83
+ // add to end
84
+ $ this ->breadcrumbs [] = array ('title ' => $ title , 'href ' => $ href );
85
+ }
86
+
87
+ // --------------------------------------------------------------------
88
+
89
+ /**
90
+ * Prepend crumb to stack
91
+ *
92
+ * @access public
93
+ * @param string $title
94
+ * @param string $href
95
+ * @return void
96
+ */
97
+ function prepend_crumb ($ title , $ href )
98
+ {
99
+ // no title or href provided
100
+ if (!$ title OR !$ href ) return ;
101
+
102
+ // add to start
103
+ array_unshift ($ this ->breadcrumbs , array ('title ' => $ title , 'href ' => $ href ));
104
+ }
105
+
106
+ // --------------------------------------------------------------------
107
+
108
+ /**
109
+ * Generate breadcrumb
110
+ *
111
+ * @access public
112
+ * @return string
113
+ */
114
+ function output ()
115
+ {
116
+ // breadcrumb found
117
+ if ($ this ->breadcrumbs ) {
118
+
119
+ // set output variable
120
+ $ output = $ this ->tag_open ;
121
+
122
+ // add html to output
123
+ foreach ($ this ->breadcrumbs as $ key => $ crumb ) {
124
+
125
+ // add divider
126
+ $ output .= $ this ->divider ;
127
+
128
+ // if last element
129
+ if (end (array_keys ($ this ->breadcrumbs )) == $ key ) {
130
+ $ output .= '<span> ' . $ crumb ['title ' ] . '</span> ' ;
131
+
132
+ // else add link and divider
133
+ } else {
134
+ $ output .= '<a href=" ' . $ crumb ['href ' ] . '"> ' . $ crumb ['title ' ] . '</a> ' ;
135
+ }
136
+ }
137
+
138
+ // return html
139
+ return $ output . $ this ->tag_close . PHP_EOL ;
140
+ }
141
+
142
+ // return blank string
143
+ return '' ;
144
+ }
145
+
146
+ }
147
+ // END Breadcrumb Class
148
+
149
+ /* End of file Breadcrumb.php */
150
+ /* Location: ./application/libraries/Breadcrumb.php */
0 commit comments