1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Theme files for Date Pager.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Jump in and move the pager.
|
10
|
*/
|
11
|
function date_views_preprocess_views_view(&$vars) {
|
12
|
$view = $vars['view'];
|
13
|
if (!empty($view->date_info) && !empty($view->date_info->date_pager_position)) {
|
14
|
switch ($view->date_info->date_pager_position) {
|
15
|
case 'top':
|
16
|
$vars['header'] .= $vars['pager'];
|
17
|
$vars['pager'] = '';
|
18
|
break;
|
19
|
|
20
|
case 'both':
|
21
|
$vars['header'] .= $vars['pager'];
|
22
|
break;
|
23
|
}
|
24
|
}
|
25
|
}
|
26
|
|
27
|
/**
|
28
|
* Preprocess function for Date pager template.
|
29
|
*/
|
30
|
function template_preprocess_date_views_pager(&$vars) {
|
31
|
ctools_add_css('date_views', 'date_views');
|
32
|
|
33
|
$plugin = $vars['plugin'];
|
34
|
$input = $vars['input'];
|
35
|
$view = $plugin->view;
|
36
|
|
37
|
$vars['nav_title'] = '';
|
38
|
$vars['next_url'] = '';
|
39
|
$vars['prev_url'] = '';
|
40
|
|
41
|
if (empty($view->date_info) || empty($view->date_info->min_date)) {
|
42
|
return;
|
43
|
}
|
44
|
$date_info = $view->date_info;
|
45
|
// Make sure we have some sort of granularity.
|
46
|
$granularity = !empty($date_info->granularity) ? $date_info->granularity : 'month';
|
47
|
$pos = $date_info->date_arg_pos;
|
48
|
if (!empty($input)) {
|
49
|
$id = $plugin->options['date_id'];
|
50
|
if (array_key_exists($id, $input) && !empty($input[$id])) {
|
51
|
$view->args[$pos] = $input[$id];
|
52
|
}
|
53
|
}
|
54
|
|
55
|
$next_args = $view->args;
|
56
|
$prev_args = $view->args;
|
57
|
$min_date = $date_info->min_date;
|
58
|
$max_date = $date_info->max_date;
|
59
|
|
60
|
// Set up the pager link format. Setting the block identifier will force
|
61
|
// pager style links.
|
62
|
if ((isset($date_info->date_pager_format) && $date_info->date_pager_format != 'clean') || !empty($date_info->mini)) {
|
63
|
if (empty($date_info->block_identifier)) {
|
64
|
$date_info->block_identifier = $date_info->pager_id;
|
65
|
}
|
66
|
}
|
67
|
|
68
|
if (empty($date_info->hide_nav)) {
|
69
|
$prev_date = $date_info->prev_date;
|
70
|
$next_date = $date_info->next_date;
|
71
|
|
72
|
$format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d', 'hour' => 'Y-m-d\TH');
|
73
|
if (!empty($prev_date)) {
|
74
|
switch ($granularity) {
|
75
|
case 'week':
|
76
|
$prev_week = date_week(date_format($prev_date, 'Y-m-d'));
|
77
|
$prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
|
78
|
break;
|
79
|
|
80
|
default:
|
81
|
$prev_arg = date_format($prev_date, $format[$granularity]);
|
82
|
}
|
83
|
$prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
|
84
|
$prev_args[$pos] = $prev_arg;
|
85
|
$vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
|
86
|
}
|
87
|
if (!empty($next_date)) {
|
88
|
switch ($granularity) {
|
89
|
case 'week':
|
90
|
$next_week = date_week(date_format($next_date, 'Y-m-d'));
|
91
|
$next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
|
92
|
break;
|
93
|
|
94
|
default:
|
95
|
$next_arg = date_format($next_date, $format[$granularity]);
|
96
|
}
|
97
|
$next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
|
98
|
$next_args[$pos] = $next_arg;
|
99
|
$vars['next_url'] = date_pager_url($view, NULL, $next_arg);
|
100
|
}
|
101
|
|
102
|
$vars['next_options'] = $vars['prev_options'] = array();
|
103
|
}
|
104
|
else {
|
105
|
$next_path = '';
|
106
|
$prev_path = '';
|
107
|
$vars['next_url'] = '';
|
108
|
$vars['prev_url'] = '';
|
109
|
$vars['next_options'] = $vars['prev_options'] = array();
|
110
|
}
|
111
|
|
112
|
// Check whether navigation links would point to a date outside the allowed
|
113
|
// range.
|
114
|
if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
|
115
|
$vars['next_url'] = '';
|
116
|
}
|
117
|
if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
|
118
|
$vars['prev_url'] = '';
|
119
|
}
|
120
|
$vars['prev_options'] += array('attributes' => array());
|
121
|
$vars['next_options'] += array('attributes' => array());
|
122
|
$prev_title = '';
|
123
|
$next_title = '';
|
124
|
|
125
|
// Build next/prev link titles.
|
126
|
switch ($granularity) {
|
127
|
case 'year':
|
128
|
$prev_title = t('Navigate to previous year');
|
129
|
$next_title = t('Navigate to next year');
|
130
|
break;
|
131
|
|
132
|
case 'month':
|
133
|
$prev_title = t('Navigate to previous month');
|
134
|
$next_title = t('Navigate to next month');
|
135
|
break;
|
136
|
|
137
|
case 'week':
|
138
|
$prev_title = t('Navigate to previous week');
|
139
|
$next_title = t('Navigate to next week');
|
140
|
break;
|
141
|
|
142
|
case 'day':
|
143
|
$prev_title = t('Navigate to previous day');
|
144
|
$next_title = t('Navigate to next day');
|
145
|
break;
|
146
|
}
|
147
|
|
148
|
$vars['prev_options']['attributes'] += array('title' => $prev_title);
|
149
|
$vars['next_options']['attributes'] += array('title' => $next_title);
|
150
|
|
151
|
// Add nofollow for next/prev links.
|
152
|
$vars['prev_options']['attributes'] += array('rel' => 'nofollow');
|
153
|
$vars['next_options']['attributes'] += array('rel' => 'nofollow');
|
154
|
|
155
|
// Need this so we can use '«' or images in the links.
|
156
|
$vars['prev_options'] += array('html' => TRUE);
|
157
|
$vars['next_options'] += array('html' => TRUE);
|
158
|
|
159
|
$link = FALSE;
|
160
|
// Month navigation titles are used as links in the block view.
|
161
|
if (!empty($date_info->mini) && $granularity == 'month') {
|
162
|
$link = TRUE;
|
163
|
}
|
164
|
$params = array(
|
165
|
'granularity' => $granularity,
|
166
|
'view' => $view,
|
167
|
'link' => $link,
|
168
|
);
|
169
|
$nav_title = theme('date_nav_title', $params);
|
170
|
$vars['nav_title'] = $nav_title;
|
171
|
$vars['mini'] = !empty($date_info->mini);
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* Theme the calendar title.
|
176
|
*/
|
177
|
function theme_date_nav_title($params) {
|
178
|
$title = '';
|
179
|
$granularity = $params['granularity'];
|
180
|
$view = $params['view'];
|
181
|
$date_info = $view->date_info;
|
182
|
$link = !empty($params['link']) ? $params['link'] : FALSE;
|
183
|
$format = !empty($params['format']) ? $params['format'] : NULL;
|
184
|
$format_with_year = variable_get('date_views_' . $granularity . '_format_with_year', 'l, F j, Y');
|
185
|
$format_without_year = variable_get('date_views_' . $granularity . '_format_without_year', 'l, F j');
|
186
|
|
187
|
switch ($granularity) {
|
188
|
case 'year':
|
189
|
$title = $date_info->year;
|
190
|
$date_arg = $date_info->year;
|
191
|
break;
|
192
|
|
193
|
case 'month':
|
194
|
$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
|
195
|
$title = date_format_date($date_info->min_date, 'custom', $format);
|
196
|
$date_arg = $date_info->year . '-' . date_pad($date_info->month);
|
197
|
break;
|
198
|
|
199
|
case 'day':
|
200
|
$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
|
201
|
$title = date_format_date($date_info->min_date, 'custom', $format);
|
202
|
$date_arg = $date_info->year;
|
203
|
$date_arg .= '-';
|
204
|
$date_arg .= date_pad($date_info->month);
|
205
|
$date_arg .= '-';
|
206
|
$date_arg .= date_pad($date_info->day);
|
207
|
break;
|
208
|
|
209
|
case 'week':
|
210
|
$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
|
211
|
$title = t('Week of @date', array(
|
212
|
'@date' => date_format_date($date_info->min_date, 'custom', $format),
|
213
|
));
|
214
|
$date_arg = $date_info->year . '-W' . date_pad($date_info->week);
|
215
|
break;
|
216
|
}
|
217
|
|
218
|
if (!empty($date_info->mini) || $link) {
|
219
|
// Month navigation titles are used as links in the mini view.
|
220
|
$attributes = array('title' => t('View full page month'));
|
221
|
$url = date_pager_url($view, $granularity, $date_arg, TRUE);
|
222
|
return l($title, $url, array('attributes' => $attributes));
|
223
|
}
|
224
|
else {
|
225
|
return $title;
|
226
|
}
|
227
|
}
|
228
|
|
229
|
/**
|
230
|
* Preprocessor for Date Views filter form.
|
231
|
*/
|
232
|
function template_preprocess_date_views_filter_form(&$vars) {
|
233
|
$form = $vars['form'];
|
234
|
$vars['date'] = drupal_render($form['valuedate']);
|
235
|
$vars['mindate'] = drupal_render($form['mindate']);
|
236
|
$vars['maxdate'] = drupal_render($form['maxdate']);
|
237
|
$vars['adjustment'] = drupal_render($form['valueadjustment']);
|
238
|
$vars['minadjustment'] = drupal_render($form['minadjustment']);
|
239
|
$vars['maxadjustment'] = drupal_render($form['maxadjustment']);
|
240
|
$vars['description'] = drupal_render($form['description']) . drupal_render($form);
|
241
|
drupal_add_css(drupal_get_path('module', 'date_api') . '/date.css');
|
242
|
}
|