Révision b720ea3e
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/date/date.theme | ||
---|---|---|
77 | 77 |
$microdata = $variables['microdata']; |
78 | 78 |
$add_microdata = $variables['add_microdata']; |
79 | 79 |
$precision = date_granularity_precision($field['settings']['granularity']); |
80 |
$show_remaining_days = $variables['show_remaining_days']; |
|
80 | 81 |
|
81 | 82 |
$output = ''; |
82 | 83 |
|
... | ... | |
121 | 122 |
$date1 = $dates['value']['formatted']; |
122 | 123 |
$date2 = $date1; |
123 | 124 |
break; |
125 |
|
|
124 | 126 |
case 'value2': |
125 | 127 |
$date2 = $dates['value2']['formatted']; |
126 | 128 |
$date1 = $date2; |
127 | 129 |
break; |
130 |
|
|
128 | 131 |
default: |
129 | 132 |
$date1 = $dates['value']['formatted']; |
130 | 133 |
$date2 = $dates['value2']['formatted']; |
... | ... | |
151 | 154 |
$has_time_string = FALSE; |
152 | 155 |
} |
153 | 156 |
|
157 |
// Check remaining days. |
|
158 |
$show_remaining_days = ''; |
|
159 |
if (!empty($variables['show_remaining_days'])) { |
|
160 |
$remaining_days = floor((strtotime($variables['dates']['value']['formatted_iso']) |
|
161 |
- strtotime('now')) / (24 * 3600)); |
|
162 |
|
|
163 |
// Show remaining days only for future events. |
|
164 |
if ($remaining_days >= 0) { |
|
165 |
$show_remaining_days = theme('date_display_remaining', array( |
|
166 |
'remaining_days' => $remaining_days, |
|
167 |
)); |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
154 | 171 |
// No date values, display nothing. |
155 | 172 |
if (empty($date1) && empty($date2)) { |
156 | 173 |
$output .= ''; |
... | ... | |
167 | 184 |
'microdata' => $microdata, |
168 | 185 |
'add_microdata' => $add_microdata, |
169 | 186 |
'dates' => $dates, |
187 |
'show_remaining_days' => $show_remaining_days, |
|
170 | 188 |
)); |
171 | 189 |
} |
172 | 190 |
// Same day, different times, don't repeat the date but show both Start and |
... | ... | |
186 | 204 |
'microdata' => $microdata, |
187 | 205 |
'add_microdata' => $add_microdata, |
188 | 206 |
'dates' => $dates, |
207 |
'show_remaining_days' => $show_remaining_days, |
|
189 | 208 |
)); |
190 | 209 |
$replaced = str_replace($time1, $time, $date1); |
191 | 210 |
$output .= theme('date_display_single', array( |
... | ... | |
209 | 228 |
'microdata' => $microdata, |
210 | 229 |
'add_microdata' => $add_microdata, |
211 | 230 |
'dates' => $dates, |
231 |
'show_remaining_days' => $show_remaining_days, |
|
212 | 232 |
)); |
213 | 233 |
} |
214 | 234 |
|
... | ... | |
236 | 256 |
// Because the Entity API integration for Date has a variable data |
237 | 257 |
// structure depending on whether there is an end value, the attributes |
238 | 258 |
// could be attached to the field or to the value property. |
239 |
if(!empty($variables['microdata']['#attributes']['itemprop'])) { |
|
259 |
if (!empty($variables['microdata']['#attributes']['itemprop'])) {
|
|
240 | 260 |
$variables['microdata']['value']['#attributes'] = $variables['microdata']['#attributes']; |
241 | 261 |
} |
242 | 262 |
|
243 | 263 |
// Add the machine readable time using the content attribute. |
244 |
if(!empty($variables['microdata']['value']['#attributes'])) { |
|
264 |
if (!empty($variables['microdata']['value']['#attributes'])) {
|
|
245 | 265 |
$variables['microdata']['value']['#attributes']['content'] = $variables['dates']['value']['formatted_iso']; |
246 | 266 |
} |
247 | 267 |
else { |
... | ... | |
257 | 277 |
$date = $variables['date']; |
258 | 278 |
$timezone = $variables['timezone']; |
259 | 279 |
$attributes = $variables['attributes']; |
280 |
$show_remaining_days = isset($variables['show_remaining_days']) ? $variables['show_remaining_days'] : ''; |
|
260 | 281 |
|
261 | 282 |
// Wrap the result with the attributes. |
262 | 283 |
$output = '<span class="date-display-single"' . drupal_attributes($attributes) . '>' . $date . $timezone . '</span>'; |
... | ... | |
265 | 286 |
$output .= '<meta' . drupal_attributes($variables['microdata']['value']['#attributes']) . '/>'; |
266 | 287 |
} |
267 | 288 |
|
268 |
return $output; |
|
289 |
// Add remaining message and return. |
|
290 |
return $output . $show_remaining_days; |
|
269 | 291 |
} |
270 | 292 |
|
271 | 293 |
/** |
... | ... | |
314 | 336 |
$timezone = $variables['timezone']; |
315 | 337 |
$attributes_start = $variables['attributes_start']; |
316 | 338 |
$attributes_end = $variables['attributes_end']; |
339 |
$show_remaining_days = $variables['show_remaining_days']; |
|
317 | 340 |
|
318 | 341 |
$start_date = '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $date1 . '</span>'; |
319 | 342 |
$end_date = '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $date2 . $timezone . '</span>'; |
... | ... | |
326 | 349 |
} |
327 | 350 |
|
328 | 351 |
// Wrap the result with the attributes. |
329 |
return t('!start-date to !end-date', array(
|
|
352 |
$output = '<div class="date-display-range">' . t('!start-date to !end-date', array(
|
|
330 | 353 |
'!start-date' => $start_date, |
331 | 354 |
'!end-date' => $end_date, |
332 |
)); |
|
355 |
)) . '</div>'; |
|
356 |
|
|
357 |
// Add remaining message and return. |
|
358 |
return $output . $show_remaining_days; |
|
333 | 359 |
} |
334 | 360 |
|
335 | 361 |
/** |
... | ... | |
375 | 401 |
'#title' => field_filter_xss(t($element['#title'])) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''), |
376 | 402 |
'#value' => '', |
377 | 403 |
'#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '', |
378 |
'#attributes' => array(), |
|
404 |
'#attributes' => array('class' => array('date-combo')),
|
|
379 | 405 |
'#children' => $element['#children'], |
380 | 406 |
); |
381 | 407 |
// Add marker to required date fields. |
... | ... | |
396 | 422 |
$rows[] = drupal_render($element[$key]); |
397 | 423 |
} |
398 | 424 |
else { |
399 |
$rows[] = array($part, drupal_render($element[$key][0]), drupal_render($element[$key][1])); |
|
425 |
$rows[] = array( |
|
426 |
$part, |
|
427 |
drupal_render($element[$key][0]), |
|
428 |
drupal_render($element[$key][1]), |
|
429 |
); |
|
400 | 430 |
} |
401 | 431 |
} |
402 | 432 |
if ($element['year']['#type'] == 'hidden') { |
... | ... | |
408 | 438 |
} |
409 | 439 |
} |
410 | 440 |
|
441 |
/** |
|
442 |
* Render a date combo as a form element. |
|
443 |
*/ |
|
444 |
function theme_date_form_element($variables) { |
|
445 |
$element = &$variables['element']; |
|
446 |
|
|
447 |
// Detect whether element is multiline. |
|
448 |
$count = preg_match_all('`<(?:div|span)\b[^>]* class="[^"]*\b(?:date-no-float|date-clear)\b`', $element['#children'], $matches, PREG_OFFSET_CAPTURE); |
|
449 |
$multiline = FALSE; |
|
450 |
if ($count > 1) { |
|
451 |
$multiline = TRUE; |
|
452 |
} |
|
453 |
elseif ($count) { |
|
454 |
$before = substr($element['#children'], 0, $matches[0][0][1]); |
|
455 |
if (preg_match('`<(?:div|span)\b[^>]* class="[^"]*\bdate-float\b`', $before)) { |
|
456 |
$multiline = TRUE; |
|
457 |
} |
|
458 |
} |
|
459 |
|
|
460 |
// Detect if there is more than one subfield. |
|
461 |
$count = count(explode('<label', $element['#children'])) - 1; |
|
462 |
if ($count == 1) { |
|
463 |
$element['#title_display'] = 'none'; |
|
464 |
} |
|
465 |
|
|
466 |
// Wrap children with a div and add an extra class if element is multiline. |
|
467 |
$element['#children'] = '<div class="date-form-element-content'. ($multiline ? ' date-form-element-content-multiline' : '') .'">'. $element['#children'] .'</div>'; |
|
468 |
|
|
469 |
return theme('form_element', $variables); |
|
470 |
} |
|
471 |
|
|
472 |
/** |
|
473 |
* Returns HTML for remaining message. |
|
474 |
*/ |
|
475 |
function theme_date_display_remaining($variables) { |
|
476 |
$remaining_days = $variables['remaining_days']; |
|
477 |
$output = ''; |
|
478 |
$show_remaining_text = t('The upcoming date less then 1 day.'); |
|
479 |
if ($remaining_days) { |
|
480 |
$show_remaining_text = format_plural($remaining_days, 'To event remaining 1 day', 'To event remaining @count days'); |
|
481 |
} |
|
482 |
|
|
483 |
return '<div class="date-display-remaining"><span class="date-display-remaining">' . $show_remaining_text . '</span></div>'; |
|
484 |
} |
|
485 |
|
|
411 | 486 |
/** @} End of addtogroup themeable */ |
Formats disponibles : Unified diff
Weekly update of contrib modules