1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Date archive breadcrumb item locator |
4
|
|
|
* |
5
|
|
|
* @package carbon-breadcrumbs |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Date archive breadcrumb item locator class. |
10
|
|
|
* |
11
|
|
|
* Used to locate the breadcrumb items for date archives. |
12
|
|
|
*/ |
13
|
|
|
class Carbon_Breadcrumb_Locator_Date extends Carbon_Breadcrumb_Locator { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Whether this the items of this locator should be included in the trail. |
17
|
|
|
* |
18
|
|
|
* @access public |
19
|
|
|
* |
20
|
|
|
* @return bool $is_included Whether the found items should be included. |
21
|
|
|
*/ |
22
|
|
|
public function is_included() { |
23
|
|
|
return is_date(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Retrieve the items, found by this locator. |
28
|
|
|
* |
29
|
|
|
* @access public |
30
|
|
|
* |
31
|
|
|
* @param int $priority The priority of the located items. |
32
|
|
|
* @param int $id Not used. |
33
|
|
|
* @return array $items The items, found by this locator. |
34
|
|
|
*/ |
35
|
|
|
public function get_items( $priority = 1000, $id = 0 ) { |
36
|
|
|
$items = array(); |
37
|
|
|
|
38
|
|
|
// Prepare the date archive item details. |
39
|
|
|
$date_archives = $this->get_archive_item_details(); |
40
|
|
|
|
41
|
|
|
// Add the associated date archive breadcrumb items. |
42
|
|
|
foreach ( $date_archives as $archive_name => $archive_details ) { |
43
|
|
|
if ( $archive_details['condition'] ) { |
44
|
|
|
$item = Carbon_Breadcrumb_Item::factory( 'custom', $priority ); |
45
|
|
|
$item->set_title( get_the_time( $archive_details['title_format'] ) ); |
46
|
|
|
$item->set_link( $archive_details['link'] ); |
47
|
|
|
$item->setup(); |
48
|
|
|
$items[] = $item; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $items; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Prepare the date archive conditions, with the corresponding title format and link. |
57
|
|
|
* |
58
|
|
|
* @access public |
59
|
|
|
* |
60
|
|
|
* @return array $details Date archive details. |
61
|
|
|
*/ |
62
|
|
|
public function get_archive_item_details() { |
63
|
|
|
return array( |
64
|
|
|
'year' => array( |
65
|
|
|
'condition' => is_year() || is_month() || is_day(), |
66
|
|
|
'title_format' => 'Y', |
67
|
|
|
'link' => get_year_link( get_query_var( 'year' ) ), |
68
|
|
|
), |
69
|
|
|
'month' => array( |
70
|
|
|
'condition' => is_month() || is_day(), |
71
|
|
|
'title_format' => 'F', |
72
|
|
|
'link' => get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ), |
73
|
|
|
), |
74
|
|
|
'day' => array( |
75
|
|
|
'condition' => is_day(), |
76
|
|
|
'title_format' => 'd', |
77
|
|
|
'link' => get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) ), |
78
|
|
|
), |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Generate a set of breadcrumb items that found by this locator type and any subtype. |
84
|
|
|
* The date archive locator has no subtypes, so this method wraps around get_items(). |
85
|
|
|
* |
86
|
|
|
* @access public |
87
|
|
|
* |
88
|
|
|
* @return array $items The items, generated by this locator. |
89
|
|
|
*/ |
90
|
|
|
public function generate_items() { |
91
|
|
|
if ( ! $this->is_included() ) { |
92
|
|
|
return array(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $this->get_items(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|