Projet

Général

Profil

Paste
Télécharger (7,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date_views / theme / theme.inc @ b720ea3e

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
      default:
25
        // Already on the bottom.
26
    }
27
  }
28
}
29

    
30
/**
31
 * Preprocess function for Date pager template.
32
 */
33
function template_preprocess_date_views_pager(&$vars) {
34
  ctools_add_css('date_views', 'date_views');
35

    
36
  $plugin = $vars['plugin'];
37
  $input = $vars['input'];
38
  $view = $plugin->view;
39

    
40
  $vars['nav_title'] = '';
41
  $vars['next_url'] = '';
42
  $vars['prev_url'] = '';
43

    
44
  if (empty($view->date_info) || empty($view->date_info->min_date)) {
45
    return;
46
  }
47
  $date_info = $view->date_info;
48
  // Make sure we have some sort of granularity.
49
  $granularity = !empty($date_info->granularity) ? $date_info->granularity : 'month';
50
  $pos = $date_info->date_arg_pos;
51
  if (!empty($input)) {
52
    $id = $plugin->options['date_id'];
53
    if (array_key_exists($id, $input) && !empty($input[$id])) {
54
      $view->args[$pos] = $input[$id];
55
    }
56
  }
57

    
58
  $next_args = $view->args;
59
  $prev_args = $view->args;
60
  $min_date = $date_info->min_date;
61
  $max_date = $date_info->max_date;
62

    
63
  // Set up the pager link format. Setting the block identifier
64
  // will force pager style links.
65
  if ((isset($date_info->date_pager_format) && $date_info->date_pager_format != 'clean') || !empty($date_info->mini)) {
66
    if (empty($date_info->block_identifier)) {
67
      $date_info->block_identifier = $date_info->pager_id;
68
    }
69
  }
70

    
71
  if (empty($date_info->hide_nav)) {
72
    $prev_date = $date_info->prev_date;
73
    $next_date = $date_info->next_date;
74

    
75
    $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d', 'hour' => 'Y-m-d\TH');
76
    if (!empty($prev_date)) {
77
      switch ($granularity) {
78
        case 'week':
79
          $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
80
          $prev_arg = date_format($prev_date, 'Y-\W') . date_pad($prev_week);
81
          break;
82
        default:
83
          $prev_arg = date_format($prev_date, $format[$granularity]);
84
      }
85
      $prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
86
      $prev_args[$pos] = $prev_arg;
87
      $vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
88
    }
89
    if (!empty($next_date)) {
90
      switch ($granularity) {
91
        case 'week':
92
          $next_week = date_week(date_format($next_date, 'Y-m-d'));
93
          $next_arg = date_format($next_date, 'Y-\W') . date_pad($next_week);
94
          break;
95
        default:
96
          $next_arg = date_format($next_date, $format[$granularity]);
97
      }
98
      $next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
99
      $next_args[$pos] = $next_arg;
100
      $vars['next_url'] = date_pager_url($view, NULL, $next_arg);
101
    }
102

    
103
    $vars['next_options'] = $vars['prev_options'] = array();
104
  }
105
  else {
106
    $next_path = '';
107
    $prev_path = '';
108
    $vars['next_url'] = '';
109
    $vars['prev_url'] = '';
110
    $vars['next_options'] = $vars['prev_options'] = array();
111
  }
112

    
113
  // Check whether navigation links would point to
114
  // a date outside the allowed range.
115
  if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
116
    $vars['next_url'] = '';
117
  }
118
  if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
119
    $vars['prev_url'] = '';
120
  }
121
  $vars['prev_options'] += array('attributes' => array());
122
  $vars['next_options'] += array('attributes' => array());
123
  $prev_title = '';
124
  $next_title = '';
125

    
126
  // Build next/prev link titles.
127
  switch ($granularity) {
128
    case 'year':
129
      $prev_title = t('Navigate to previous year');
130
      $next_title = t('Navigate to next year');
131
      break;
132

    
133
    case 'month':
134
      $prev_title = t('Navigate to previous month');
135
      $next_title = t('Navigate to next month');
136
      break;
137

    
138
    case 'week':
139
      $prev_title = t('Navigate to previous week');
140
      $next_title = t('Navigate to next week');
141
      break;
142

    
143
    case 'day':
144
      $prev_title = t('Navigate to previous day');
145
      $next_title = t('Navigate to next day');
146
      break;
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 '&laquo;' 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
  switch ($granularity) {
187
    case 'year':
188
      $title = $date_info->year;
189
      $date_arg = $date_info->year;
190
      break;
191

    
192
    case 'month':
193
      $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
194
      $title = date_format_date($date_info->min_date, 'custom', $format);
195
      $date_arg = $date_info->year . '-' . date_pad($date_info->month);
196
      break;
197

    
198
    case 'day':
199
      $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
200
      $title = date_format_date($date_info->min_date, 'custom', $format);
201
      $date_arg = $date_info->year;
202
      $date_arg .= '-';
203
      $date_arg .= date_pad($date_info->month);
204
      $date_arg .= '-';
205
      $date_arg .= date_pad($date_info->day);
206
      break;
207

    
208
    case 'week':
209
      $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
210
      $title = t('Week of @date', array(
211
        '@date' => date_format_date($date_info->min_date, 'custom', $format),
212
      ));
213
      $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
214
      break;
215
  }
216
  if (!empty($date_info->mini) || $link) {
217
    // Month navigation titles are used as links in the mini view.
218
    $attributes = array('title' => t('View full page month'));
219
    $url = date_pager_url($view, $granularity, $date_arg, TRUE);
220
    return l($title, $url, array('attributes' => $attributes));
221
  }
222
  else {
223
    return $title;
224
  }
225
}
226

    
227
/**
228
 * Preprocessor for Date Views filter form.
229
 */
230
function template_preprocess_date_views_filter_form(&$vars) {
231
  $form = $vars['form'];
232
  $vars['date'] = drupal_render($form['valuedate']);
233
  $vars['mindate'] = drupal_render($form['mindate']);
234
  $vars['maxdate'] = drupal_render($form['maxdate']);
235
  $vars['adjustment'] = drupal_render($form['valueadjustment']);
236
  $vars['minadjustment'] = drupal_render($form['minadjustment']);
237
  $vars['maxadjustment'] = drupal_render($form['maxadjustment']);
238
  $vars['description'] = drupal_render($form['description']) . drupal_render($form);
239
}