1 | <?php |
||
7 | class Carbon_Breadcrumb_Trail_Renderer { |
||
8 | |||
9 | /** |
||
10 | * String used between the breadcrumb items when displaying the breadcrumbs. |
||
11 | * |
||
12 | * @access protected |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $glue = ' > '; |
||
16 | |||
17 | /** |
||
18 | * String before the opening link tag. |
||
19 | * |
||
20 | * @access protected |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $link_before = ''; |
||
24 | |||
25 | /** |
||
26 | * String after the closing link tag. |
||
27 | * |
||
28 | * @access protected |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $link_after = ''; |
||
32 | |||
33 | /** |
||
34 | * String before all breadcrumb items. |
||
35 | * |
||
36 | * @access protected |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $wrapper_before = ''; |
||
40 | |||
41 | /** |
||
42 | * String after all breadcrumb items. |
||
43 | * |
||
44 | * @access protected |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $wrapper_after = ''; |
||
48 | |||
49 | /** |
||
50 | * String before the title of a breadcrumb item. |
||
51 | * |
||
52 | * @access protected |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $title_before = ''; |
||
56 | |||
57 | /** |
||
58 | * String before the title of a breadcrumb item. |
||
59 | * |
||
60 | * @access protected |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $title_after = ''; |
||
64 | |||
65 | /** |
||
66 | * Minimum items necessary to display the breadcrumb trail. |
||
67 | * |
||
68 | * @access protected |
||
69 | * @var int |
||
70 | */ |
||
71 | protected $min_items = 2; |
||
72 | |||
73 | /** |
||
74 | * Whether to display the last item as link. |
||
75 | * |
||
76 | * @access protected |
||
77 | * @var bool |
||
78 | */ |
||
79 | protected $last_item_link = true; |
||
80 | |||
81 | /** |
||
82 | * Whether to display the home item. |
||
83 | * |
||
84 | * @access protected |
||
85 | * @var bool |
||
86 | */ |
||
87 | protected $display_home_item = true; |
||
88 | |||
89 | /** |
||
90 | * The title of the home item. |
||
91 | * |
||
92 | * @access protected |
||
93 | * @var string |
||
94 | */ |
||
95 | protected $home_item_title = ''; |
||
96 | |||
97 | /** |
||
98 | * Constructor. |
||
99 | * |
||
100 | * Creates and configures a new breadcrumb trail with the provided settings. |
||
101 | * |
||
102 | * @access public |
||
103 | * |
||
104 | * @param array $args Configuration options to modify the breadcrumb trail output. |
||
105 | */ |
||
106 | 5 | public function __construct( $args = array() ) { |
|
107 | |||
108 | // default configuration options |
||
109 | $defaults = array( |
||
110 | 5 | 'home_item_title' => __( 'Home', 'carbon_breadcrumbs' ), |
|
111 | 5 | ); |
|
112 | |||
113 | // allow default options to be filtered |
||
114 | 5 | $defaults = apply_filters( 'carbon_breadcrumbs_renderer_default_options', $defaults ); |
|
115 | |||
116 | // parse configuration options |
||
117 | 5 | $args = wp_parse_args( $args, $defaults ); |
|
118 | |||
119 | // set configuration options |
||
120 | 5 | foreach ( $args as $arg_name => $arg_value ) { |
|
121 | 5 | $method = 'set_' . $arg_name; |
|
122 | 5 | if ( method_exists( $this, $method ) ) { |
|
123 | 5 | call_user_func( array( $this, $method ), $arg_value ); |
|
124 | 5 | } |
|
125 | 5 | } |
|
126 | |||
127 | 5 | } |
|
128 | |||
129 | /** |
||
130 | * Retrieve the string, used for concatenating the breadcrumb items. |
||
131 | * |
||
132 | * @access public |
||
133 | * |
||
134 | * @return string $glue String, used for concatenating the breadcrumb items. |
||
135 | */ |
||
136 | 1 | public function get_glue() { |
|
139 | |||
140 | /** |
||
141 | * Modify the string, used for concatenating the breadcrumb items. |
||
142 | * |
||
143 | * @access public |
||
144 | * |
||
145 | * @param string $glue String, used for concatenating the breadcrumb items. |
||
146 | */ |
||
147 | 1 | public function set_glue( $glue = '' ) { |
|
150 | |||
151 | /** |
||
152 | * Retrieve the string before the opening link tag of a breadcrumb item. |
||
153 | * |
||
154 | * @access public |
||
155 | * |
||
156 | * @return string $link_before String before the opening link tag of a breadcrumb item. |
||
157 | */ |
||
158 | 1 | public function get_link_before() { |
|
161 | |||
162 | /** |
||
163 | * Modify the string before the opening link tag of a breadcrumb item. |
||
164 | * |
||
165 | * @access public |
||
166 | * |
||
167 | * @param string $link_before String before the opening link tag of a breadcrumb item. |
||
168 | */ |
||
169 | 1 | public function set_link_before( $link_before = '' ) { |
|
172 | |||
173 | /** |
||
174 | * Retrieve the string after the closing link tag of a breadcrumb item. |
||
175 | * |
||
176 | * @access public |
||
177 | * |
||
178 | * @return string $link_after String after the closing link tag of a breadcrumb item. |
||
179 | */ |
||
180 | 1 | public function get_link_after() { |
|
183 | |||
184 | /** |
||
185 | * Modify the string after the closing link tag of a breadcrumb item. |
||
186 | * |
||
187 | * @access public |
||
188 | * |
||
189 | * @param string $link_after String after the closing link tag of a breadcrumb item. |
||
190 | */ |
||
191 | 1 | public function set_link_after( $link_after = '' ) { |
|
194 | |||
195 | /** |
||
196 | * Retrieve the string before the breadcrumb items. |
||
197 | * |
||
198 | * @access public |
||
199 | * |
||
200 | * @return string $wrapper_before String before the breadcrumb items. |
||
201 | */ |
||
202 | 1 | public function get_wrapper_before() { |
|
205 | |||
206 | /** |
||
207 | * Modify the string before the breadcrumb items. |
||
208 | * |
||
209 | * @access public |
||
210 | * |
||
211 | * @param string $wrapper_before String before the breadcrumb items. |
||
212 | */ |
||
213 | 1 | public function set_wrapper_before( $wrapper_before = '' ) { |
|
216 | |||
217 | /** |
||
218 | * Retrieve the string after the breadcrumb items. |
||
219 | * |
||
220 | * @access public |
||
221 | * |
||
222 | * @return string $wrapper_after String after the breadcrumb items. |
||
223 | */ |
||
224 | 1 | public function get_wrapper_after() { |
|
227 | |||
228 | /** |
||
229 | * Modify the string after the breadcrumb items. |
||
230 | * |
||
231 | * @access public |
||
232 | * |
||
233 | * @param string $wrapper_after String after the breadcrumb items. |
||
234 | */ |
||
235 | 1 | public function set_wrapper_after( $wrapper_after = '' ) { |
|
238 | |||
239 | /** |
||
240 | * Retrieve the string before the title of a breadcrumb item. |
||
241 | * |
||
242 | * @access public |
||
243 | * |
||
244 | * @return string $title_before String before the title of a breadcrumb item. |
||
245 | */ |
||
246 | 1 | public function get_title_before() { |
|
249 | |||
250 | /** |
||
251 | * Modify the string before the title of a breadcrumb item. |
||
252 | * |
||
253 | * @access public |
||
254 | * |
||
255 | * @param string $title_before String before the title of a breadcrumb item. |
||
256 | */ |
||
257 | 1 | public function set_title_before( $title_before = '' ) { |
|
260 | |||
261 | /** |
||
262 | * Retrieve the string after the title of a breadcrumb item. |
||
263 | * |
||
264 | * @access public |
||
265 | * |
||
266 | * @return string $title_after String after the title of a breadcrumb item. |
||
267 | */ |
||
268 | 1 | public function get_title_after() { |
|
271 | |||
272 | /** |
||
273 | * Modify the string after the title of a breadcrumb item. |
||
274 | * |
||
275 | * @access public |
||
276 | * |
||
277 | * @param string $title_after String after the title of a breadcrumb item. |
||
278 | */ |
||
279 | 1 | public function set_title_after( $title_after = '' ) { |
|
282 | |||
283 | /** |
||
284 | * Retrieve the minimum number of items, necessary to display the trail. |
||
285 | * |
||
286 | * @access public |
||
287 | * |
||
288 | * @return int $min_items Minimum number of items, necessary to display the trail |
||
289 | */ |
||
290 | 1 | public function get_min_items() { |
|
293 | |||
294 | /** |
||
295 | * Modify the minimum number of items, necessary to display the trail. |
||
296 | * |
||
297 | * @access public |
||
298 | * |
||
299 | * @param int $min_items Minimum number of items, necessary to display the trail. |
||
300 | */ |
||
301 | 1 | public function set_min_items( $min_items ) { |
|
304 | |||
305 | /** |
||
306 | * Whether the last item will be displayed as a link. |
||
307 | * |
||
308 | * @access public |
||
309 | * |
||
310 | * @return bool $last_item_link Whether the last item will be displayed as a link. |
||
311 | */ |
||
312 | 1 | public function get_last_item_link() { |
|
315 | |||
316 | /** |
||
317 | * Change whether the last item will be displayed as a link. |
||
318 | * |
||
319 | * @access public |
||
320 | * |
||
321 | * @param bool $last_item_link Whether the last item will be displayed as a link. |
||
322 | */ |
||
323 | 1 | public function set_last_item_link($last_item_link) { |
|
326 | |||
327 | /** |
||
328 | * Whether the home item will be displayed. |
||
329 | * |
||
330 | * @access public |
||
331 | * |
||
332 | * @return bool $display_home_item Whether the home item will be displayed. |
||
333 | */ |
||
334 | 1 | public function get_display_home_item() { |
|
337 | |||
338 | /** |
||
339 | * Change whether the home item will be displayed. |
||
340 | * |
||
341 | * @access public |
||
342 | * |
||
343 | * @param bool $display_home_item Whether the home item will be displayed. |
||
344 | */ |
||
345 | 1 | public function set_display_home_item( $display_home_item ) { |
|
348 | |||
349 | /** |
||
350 | * Retrieve the title of the home item. |
||
351 | * |
||
352 | * @access public |
||
353 | * |
||
354 | * @return string $home_item_title The title of the home item. |
||
355 | */ |
||
356 | 1 | public function get_home_item_title() { |
|
359 | |||
360 | /** |
||
361 | * Modify the title of the home item. |
||
362 | * |
||
363 | * @access public |
||
364 | * |
||
365 | * @param string $home_item_title The title of the home item. |
||
366 | */ |
||
367 | 1 | public function set_home_item_title( $home_item_title = '' ) { |
|
370 | |||
371 | /** |
||
372 | * Prepare for rendering. |
||
373 | * Allows renderer to be modified in the last second. |
||
374 | * Also autosorts the trail items, if autosorting is enabled. |
||
375 | * |
||
376 | * @access public |
||
377 | * |
||
378 | * @param Carbon_Breadcrumb_Trail $trail Trail object. |
||
379 | */ |
||
380 | 3 | public function prepare_for_rendering( $trail ) { |
|
390 | |||
391 | /** |
||
392 | * Render the given breadcrumb trail. |
||
393 | * |
||
394 | * @access public |
||
395 | * |
||
396 | * @param Carbon_Breadcrumb_Trail $trail The trail object. |
||
397 | * @param bool $return Whether to return the output. |
||
398 | * @return string|void $output The output HTML if $return is true. |
||
399 | */ |
||
400 | 4 | public function render( Carbon_Breadcrumb_Trail $trail, $return = false ) { |
|
423 | |||
424 | /** |
||
425 | * Render the breadcrumb trail items. |
||
426 | * |
||
427 | * @access public |
||
428 | * |
||
429 | * @param Carbon_Breadcrumb_Trail $trail The trail object. |
||
430 | * @return array $output The output elements. |
||
431 | */ |
||
432 | 2 | public function render_items( $trail ) { |
|
454 | |||
455 | } |