Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Theme files for Date Pager.
6
 */
7
/**
8
 * Jump in and move the pager.
9
 */
10
function date_views_preprocess_views_view(&$vars) {
11
  $view = $vars['view'];
12
  if (!empty($view->date_info) && !empty($view->date_info->date_pager_position)) {
13
    switch ($view->date_info->date_pager_position) {
14
      case 'top':
15
        $vars['header'] .= $vars['pager'];
16
        $vars['pager'] = '';
17
        break;
18
      case 'both':
19
        $vars['header'] .= $vars['pager'];
20
        break;
21
      default:
22
        // Already on the bottom.
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
61
  // will force 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 = clone($min_date);
70
    date_modify($prev_date, '-1 ' . $granularity);
71
    $next_date = clone($min_date);
72
    date_modify($next_date, '+1 ' . $granularity);
73
    $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d');
74
    switch ($granularity) {
75
      case 'week':
76
        $next_week = date_week(date_format($next_date, 'Y-m-d'));
77
        $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
78
        $next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
79
        $prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
80
        break;
81
      default:
82
        $next_arg = date_format($next_date, $format[$granularity]);
83
        $prev_arg = date_format($prev_date, $format[$granularity]);
84
    }
85
    $next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
86
    $prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
87
    $next_args[$pos] = $next_arg;
88
    $prev_args[$pos] = $prev_arg;
89
    $vars['next_url'] = date_pager_url($view, NULL, $next_arg);
90
    $vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
91
    $vars['next_options'] = $vars['prev_options'] = array();
92
  }
93
  else {
94
    $next_path = '';
95
    $prev_path = '';
96
    $vars['next_url'] = '';
97
    $vars['prev_url'] = '';
98
    $vars['next_options'] = $vars['prev_options'] = array();
99
  }
100

    
101
  // Check whether navigation links would point to
102
  // a date outside the allowed range.
103
  if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
104
    $vars['next_url'] = '';
105
  }
106
  if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
107
    $vars['prev_url'] = '';
108
  }
109
  $vars['prev_options'] += array('attributes' => array());
110
  $vars['next_options'] += array('attributes' => array());
111
  $prev_title = '';
112
  $next_title = '';
113

    
114
  // Build next/prev link titles.
115
  switch ($granularity) {
116
    case 'year':
117
      $prev_title = t('Navigate to previous year');
118
      $next_title = t('Navigate to next year');
119
      break;
120
    case 'month':
121
      $prev_title = t('Navigate to previous month');
122
      $next_title = t('Navigate to next month');
123
      break;
124
    case 'week':
125
      $prev_title = t('Navigate to previous week');
126
      $next_title = t('Navigate to next week');
127
      break;
128
    case 'day':
129
      $prev_title = t('Navigate to previous day');
130
      $next_title = t('Navigate to next day');
131
      break;
132
  }
133
  $vars['prev_options']['attributes'] += array('title' => $prev_title);
134
  $vars['next_options']['attributes'] += array('title' => $next_title);
135

    
136
  // Add nofollow for next/prev links.
137
  $vars['prev_options']['attributes'] += array('rel' => 'nofollow');
138
  $vars['next_options']['attributes'] += array('rel' => 'nofollow');
139

    
140
  // Need this so we can use '&laquo;' or images in the links.
141
  $vars['prev_options'] += array('html' => TRUE);
142
  $vars['next_options'] += array('html' => TRUE);
143

    
144
  $link = FALSE;
145
  // Month navigation titles are used as links in the block view.
146
  if (!empty($date_info->mini) && $granularity == 'month') {
147
    $link = TRUE;
148
  }
149
  $params = array(
150
    'granularity' => $granularity,
151
    'view' => $view,
152
    'link' => $link,
153
  );
154
  $nav_title = theme('date_nav_title', $params);
155
  $vars['nav_title'] = $nav_title;
156
  $vars['mini'] = !empty($date_info->mini);
157
}
158

    
159
/**
160
 * Theme the calendar title
161
 */
162
function theme_date_nav_title($params) {
163
  $granularity = $params['granularity'];
164
  $view = $params['view'];
165
  $date_info = $view->date_info;
166
  $link = !empty($params['link']) ? $params['link'] : FALSE;
167
  $format = !empty($params['format']) ? $params['format'] : NULL;
168
  $format_with_year = variable_get('date_views_' . $granularity . 'format_with_year', 'l, F j, Y');
169
  $format_without_year = variable_get('date_views_' . $granularity . 'format_without_year', 'l, F j');
170
  switch ($granularity) {
171
    case 'year':
172
      $title = $date_info->year;
173
      $date_arg = $date_info->year;
174
      break;
175
    case 'month':
176
      $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
177
      $title = date_format_date($date_info->min_date, 'custom', $format);
178
      $date_arg = $date_info->year . '-' . date_pad($date_info->month);
179
      break;
180
    case 'day':
181
      $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
182
      $title = date_format_date($date_info->min_date, 'custom', $format);
183
      $date_arg = $date_info->year . '-' . date_pad($date_info->month) . '-' . date_pad($date_info->day);
184
      break;
185
    case 'week':
186
      $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
187
      $title = t('Week of @date', array('@date' => date_format_date($date_info->min_date, 'custom', $format)));
188
      $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
189
      break;
190
  }
191
  if (!empty($date_info->mini) || $link) {
192
    // Month navigation titles are used as links in the mini view.
193
    $attributes = array('title' => t('View full page month'));
194
    $url = date_pager_url($view, $granularity, $date_arg, TRUE);
195
    return l($title, $url, array('attributes' => $attributes));
196
  }
197
  else {
198
    return $title;
199
  }
200
}
201

    
202
/**
203
 * Preprocessor for Date Views filter form.
204
 */
205
function template_preprocess_date_views_filter_form(&$vars) {
206
  $form = $vars['form'];
207
  $vars['date'] = drupal_render($form['valuedate']);
208
  $vars['mindate'] = drupal_render($form['mindate']);
209
  $vars['maxdate'] = drupal_render($form['maxdate']);
210
  $vars['adjustment'] = drupal_render($form['valueadjustment']);
211
  $vars['minadjustment'] = drupal_render($form['minadjustment']);
212
  $vars['maxadjustment'] = drupal_render($form['maxadjustment']);
213
  $vars['description'] = drupal_render($form['description']) . drupal_render($form);
214
}