|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Abstract breadcrumb item class. |
|
4
|
|
|
* |
|
5
|
|
|
* Used as a base for all breadcrumb item types. |
|
6
|
|
|
*/ |
|
7
|
|
|
abstract class Carbon_Breadcrumb_Item extends Carbon_Breadcrumb_Factory { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Breadcrumb item title. |
|
11
|
|
|
* |
|
12
|
|
|
* @access protected |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $title; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Breadcrumb item link URL. |
|
19
|
|
|
* |
|
20
|
|
|
* @access protected |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $link; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Breadcrumb item link additional attributes. |
|
27
|
|
|
* |
|
28
|
|
|
* @access protected |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $attributes = array( |
|
32
|
|
|
'target' => '_self', |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Breadcrumb item priority. |
|
37
|
|
|
* |
|
38
|
|
|
* @access protected |
|
39
|
|
|
* @var int |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $priority = 1000; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Breadcrumb item type. |
|
45
|
|
|
* |
|
46
|
|
|
* @access protected |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $type = ''; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Breadcrumb item subtype. |
|
53
|
|
|
* |
|
54
|
|
|
* @access protected |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $subtype = ''; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Build a new breadcrumb item of the selected type. |
|
61
|
|
|
* |
|
62
|
|
|
* @static |
|
63
|
|
|
* @access public |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $type Type of the breadcrumb item. |
|
66
|
|
|
* @param int $priority Priority of this breadcrumb item. |
|
67
|
|
|
* @return Carbon_Breadcrumb_Item $item The new breadcrumb item. |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public static function factory( $type = 'custom', $priority = 1000 ) { |
|
70
|
1 |
|
$class = self::verify_class_name( __CLASS__ . '_' . $type, 'Unexisting breadcrumb item type: "' . $type . '".' ); |
|
71
|
|
|
|
|
72
|
|
|
$item = new $class( $priority ); |
|
73
|
|
|
$item->set_type( $type ); |
|
74
|
|
|
|
|
75
|
|
|
return $item; |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Constructor. |
|
80
|
|
|
* |
|
81
|
|
|
* Creates and configures a new breadcrumb item with the provided settings. |
|
82
|
|
|
* |
|
83
|
|
|
* @access public |
|
84
|
|
|
* |
|
85
|
|
|
* @param int $priority Priority of this breadcrumb item. |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function __construct( $priority = 1000 ) { |
|
88
|
|
|
$this->set_priority( $priority ); |
|
89
|
1 |
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Retrieve the breadcrumb item title. |
|
93
|
|
|
* |
|
94
|
|
|
* @access public |
|
95
|
|
|
* |
|
96
|
|
|
* @return string $title The title of this breadcrumb item. |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function get_title() { |
|
99
|
1 |
|
return $this->title; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Modify the title of this breadcrumb item. |
|
104
|
|
|
* |
|
105
|
|
|
* @access public |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $title The new title. |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function set_title( $title ) { |
|
110
|
1 |
|
$this->title = $title; |
|
111
|
1 |
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Retrieve the breadcrumb item link URL. |
|
115
|
|
|
* |
|
116
|
|
|
* @access public |
|
117
|
|
|
* |
|
118
|
|
|
* @return string $link The link URL of this breadcrumb item. |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public function get_link() { |
|
121
|
1 |
|
return $this->link; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Modify the link URL of this breadcrumb item. |
|
126
|
|
|
* |
|
127
|
|
|
* @access public |
|
128
|
|
|
* |
|
129
|
|
|
* @param string $link The new link URL. |
|
130
|
|
|
*/ |
|
131
|
1 |
|
public function set_link( $link = '' ) { |
|
132
|
1 |
|
$this->link = $link; |
|
133
|
1 |
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Retrieve the breadcrumb item link attributes. |
|
137
|
|
|
* |
|
138
|
|
|
* @access public |
|
139
|
|
|
* |
|
140
|
|
|
* @return array $attributes The link attributes of this breadcrumb item. |
|
141
|
|
|
*/ |
|
142
|
1 |
|
public function get_attributes() { |
|
143
|
1 |
|
return $this->attributes; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Modify the link attributes of this breadcrumb item. |
|
148
|
|
|
* |
|
149
|
|
|
* @access public |
|
150
|
|
|
* |
|
151
|
|
|
* @param array $attributes The new link attributes. |
|
152
|
|
|
*/ |
|
153
|
1 |
|
public function set_attributes( $attributes = array() ) { |
|
154
|
1 |
|
$this->attributes = $attributes; |
|
155
|
1 |
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Retrieve the breadcrumb item priority. |
|
159
|
|
|
* |
|
160
|
|
|
* @access public |
|
161
|
|
|
* |
|
162
|
|
|
* @return int $priority The priority of this breadcrumb item. |
|
163
|
|
|
*/ |
|
164
|
1 |
|
public function get_priority() { |
|
165
|
1 |
|
return $this->priority; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Modify the priority of this breadcrumb item. |
|
170
|
|
|
* |
|
171
|
|
|
* @access public |
|
172
|
|
|
* |
|
173
|
|
|
* @param int $priority The new priority. |
|
174
|
|
|
*/ |
|
175
|
|
|
public function set_priority( $priority ) { |
|
176
|
|
|
$this->priority = $priority; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Retrieve the type of this breadcrumb item. |
|
181
|
|
|
* |
|
182
|
|
|
* @access public |
|
183
|
|
|
* |
|
184
|
|
|
* @return string $type The type of this breadcrumb item. |
|
185
|
|
|
*/ |
|
186
|
1 |
|
public function get_type() { |
|
187
|
1 |
|
return $this->type; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Modify the type of this breadcrumb item. |
|
192
|
|
|
* |
|
193
|
|
|
* @access public |
|
194
|
|
|
* |
|
195
|
|
|
* @param string $type The new breadcrumb item type. |
|
196
|
|
|
*/ |
|
197
|
1 |
|
public function set_type( $type ) { |
|
198
|
1 |
|
$this->type = $type; |
|
199
|
1 |
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Retrieve the subtype of this breadcrumb item. |
|
203
|
|
|
* |
|
204
|
|
|
* @access public |
|
205
|
|
|
* |
|
206
|
|
|
* @return string $subtype The subtype of this breadcrumb item. |
|
207
|
|
|
*/ |
|
208
|
1 |
|
public function get_subtype() { |
|
209
|
1 |
|
return $this->subtype; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Modify the subtype of this breadcrumb item. |
|
214
|
|
|
* |
|
215
|
|
|
* @access public |
|
216
|
|
|
* |
|
217
|
|
|
* @param string $subtype The new breadcrumb item subtype. |
|
218
|
|
|
*/ |
|
219
|
1 |
|
public function set_subtype( $subtype ) { |
|
220
|
1 |
|
$this->subtype = $subtype; |
|
221
|
1 |
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Setup this breadcrumb item. |
|
225
|
|
|
* |
|
226
|
|
|
* This method can be used to automatically set this item's title, link |
|
227
|
|
|
* and other settings in the child class. |
|
228
|
|
|
* |
|
229
|
|
|
* @abstract |
|
230
|
|
|
* @access public |
|
231
|
|
|
*/ |
|
232
|
|
|
abstract public function setup(); |
|
233
|
|
|
|
|
234
|
|
|
} |