Projet

Général

Profil

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

root / drupal7 / sites / all / modules / date / date_api / theme / theme.inc @ 599a39cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Theme files for Date API.
6
 */
7

    
8
/**
9
 * Returns HTML for a date timezone element.
10
 */
11
function theme_date_timezone($variables) {
12
  $element = $variables['element'];
13
  $attributes = $element['#attributes'];
14
  $wrapper_attributes = array();
15
  // Add an wrapper to mimic the way a single value field works, for ease in
16
  // using #states.
17
  if (isset($element['#children'])) {
18
    $element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) . '>' . $element['#children'] . '</div>';
19
  }
20
  return '<div ' . drupal_attributes($attributes) . '>' . theme('form_element', $element) . '</div>';
21
}
22

    
23
/**
24
 * Returns HTML for a date select element.
25
 */
26
function theme_date_select($variables) {
27
  $element = $variables['element'];
28
  $attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array());
29
  $attributes['class'][] = 'container-inline-date';
30
  $wrapper_attributes = array('class' => array('date-padding'));
31
  $wrapper_attributes['class'][] = 'clearfix';
32
  // Add an wrapper to mimic the way a single value field works, for ease in
33
  // using #states.
34
  if (isset($element['#children'])) {
35
    $element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) . '>' . $element['#children'] . '</div>';
36
  }
37
  return '<div ' . drupal_attributes($attributes) . '>' . theme('form_element', $element) . '</div>';
38
}
39

    
40
/**
41
 * Returns HTML for a date text element.
42
 */
43
function theme_date_text($variables) {
44
  $element = $variables['element'];
45
  $attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array());
46
  $attributes['class'][] = 'container-inline-date';
47
  // If there is no description, the floating date elements need some extra
48
  // padding below them.
49
  $wrapper_attributes = array('class' => array('date-padding'));
50
  if (empty($element['date']['#description'])) {
51
    $wrapper_attributes['class'][] = 'clearfix';
52
  }
53
  // Add an wrapper to mimic the way a single value field works, for ease in
54
  // using #states.
55
  if (isset($element['#children'])) {
56
    $element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) . '>' . $element['#children'] . '</div>';
57
  }
58
  return '<div ' . drupal_attributes($attributes) . '>' . theme('form_element', $element) . '</div>';
59
}
60

    
61
/**
62
 * Returns HTML for a date select input form element.
63
 */
64
function theme_date_select_element($variables) {
65
  $element = $variables['element'];
66
  $parents = $element['#parents'];
67
  $part = array_pop($parents);
68
  return '<div class="date-' . $part . '">' . theme('select', $element) . '</div>';
69
}
70

    
71
/**
72
 * Returns HTML for a date textfield input form element.
73
 */
74
function theme_date_textfield_element($variables) {
75
  $element = $variables['element'];
76
  $parents = $element['#parents'];
77
  $part = array_pop($parents);
78
  return '<div class="date-' . $part . '">' . theme('textfield', $element) . '</div>';
79
}
80

    
81
/**
82
 * Returns HTML for a 'hour' date part prefix.
83
 */
84
function theme_date_part_hour_prefix($variables) {
85
  $element = $variables['element'];
86
  if ($element['#date_label_position'] != 'above') {
87
    return '<span class="form-item date-spacer">&nbsp;-&nbsp;</span>';
88
  }
89
}
90

    
91
/**
92
 * Returns HTML for a 'minutes and seconds' date part prefix.
93
 */
94
function theme_date_part_minsec_prefix($variables) {
95
  $element = $variables['element'];
96
  if ($element['#date_label_position'] != 'above') {
97
    return '<span class="form-item date-spacer">:</span>';
98
  }
99
}
100

    
101
/**
102
 * Returns HTML for a date_select 'year' label.
103
 */
104
function theme_date_part_label_year($variables) {
105
  return t('Year', array(), array('context' => 'datetime'));
106
}
107

    
108
/**
109
 * Returns HTML for a date_select 'month' label.
110
 */
111
function theme_date_part_label_month($variables) {
112
  return t('Month', array(), array('context' => 'datetime'));
113
}
114

    
115
/**
116
 * Returns HTML for a date_select 'day' label.
117
 */
118
function theme_date_part_label_day($variables) {
119
  return t('Day', array(), array('context' => 'datetime'));
120
}
121

    
122
/**
123
 * Returns HTML for a date_select 'hour' label.
124
 */
125
function theme_date_part_label_hour($variables) {
126
  return t('Hour', array(), array('context' => 'datetime'));
127
}
128

    
129
/**
130
 * Returns HTML for a date_select 'minute' label.
131
 */
132
function theme_date_part_label_minute($variables) {
133
  return t('Minute', array(), array('context' => 'datetime'));
134
}
135

    
136
/**
137
 * Returns HTML for a date_select 'second' label.
138
 */
139
function theme_date_part_label_second($variables) {
140
  return t('Second', array(), array('context' => 'datetime'));
141
}
142

    
143
/**
144
 * Returns HTML for a date_select 'ampm' label.
145
 */
146
function theme_date_part_label_ampm($variables) {
147
  return '&nbsp;';
148
}
149

    
150
/**
151
 * Returns HTML for a date_select 'timezone' label.
152
 */
153
function theme_date_part_label_timezone($variables) {
154
  return t('Timezone');
155
}
156

    
157
/**
158
 * Returns HTML for a date_select 'date' label.
159
 */
160
function theme_date_part_label_date($variables) {
161
  return t('Date', array(), array('context' => 'datetime'));
162
}
163

    
164
/**
165
 * Returns HTML for a date_select 'time' label.
166
 */
167
function theme_date_part_label_time($variables) {
168
  return t('Time', array(), array('context' => 'datetime'));
169
}
170

    
171
/**
172
 * Returns HTML for a date block that looks like a mini calendar day.
173
 *
174
 * Pass in a date object already set to the right timezone, format as a calendar
175
 * page date. The calendar styling is created in CSS.
176
 */
177
function theme_date_calendar_day($variables) {
178
  $output = '';
179
  $date = $variables['date'];
180
  if (!empty($date)) {
181
    $output .= '<div class="date-calendar-day">';
182
    $output .= '<span class="month">' . date_format_date($date, 'custom', 'M') . '</span>';
183
    $output .= '<span class="day">' . date_format_date($date, 'custom', 'j') . '</span>';
184
    $output .= '<span class="year">' . date_format_date($date, 'custom', 'Y') . '</span>';
185
    $output .= '</div>';
186
  }
187
  return $output;
188
}
189

    
190
/**
191
 * Returns HTML for a date in the format 'time ago'.
192
 */
193
function theme_date_time_ago($variables) {
194
  $start_date = $variables['start_date'];
195
  $end_date = $variables['end_date'];
196
  $use_end_date = isset($variables['use_end_date']) ? $variables['use_end_date'] : FALSE;
197
  $interval = !empty($variables['interval']) ? $variables['interval'] : 2;
198
  $display = isset($variables['interval_display']) ? $variables['interval_display'] : 'time ago';
199

    
200
  // If no date is sent, then return nothing.
201
  if (empty($start_date) || empty($end_date)) {
202
    return;
203
  }
204

    
205
  // We use the end date only when the option is checked.
206
  if ($use_end_date) {
207
    $date = date_format($end_date, DATE_FORMAT_UNIX);
208
  }
209
  else {
210
    $date = date_format($start_date, DATE_FORMAT_UNIX);
211
  }
212

    
213
  // Time to compare dates to.
214
  $now = date_format(date_now(), DATE_FORMAT_UNIX);
215

    
216
  // Will be positive for a datetime in the past (ago), and negative for a
217
  // datetime in the future (hence).
218
  $time_diff = $now - $date;
219

    
220
  // Uses the same options used by Views format_interval.
221
  switch ($display) {
222
    case 'raw time ago':
223
      return format_interval($time_diff, $interval);
224

    
225
    case 'time ago':
226
      return t('%time ago', array('%time' => format_interval($time_diff, $interval)));
227

    
228
    case 'raw time hence':
229
      return format_interval(-$time_diff, $interval);
230

    
231
    case 'time hence':
232
      return t('%time hence', array('%time' => format_interval(-$time_diff, $interval)));
233

    
234
    case 'raw time span':
235
      return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
236

    
237
    case 'inverse time span':
238
      return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
239

    
240
    case 'time span':
241
      return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), $interval)));
242
  }
243
}