1 |
77885877
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Theme files for Date API.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
use Drupal\Core\Template\Attribute;
|
9 |
|
|
use Drupal\Core\Datetime\DrupalDateTime;
|
10 |
|
|
|
11 |
|
|
/**
|
12 |
|
|
* Returns HTML for a date timezone element.
|
13 |
|
|
*/
|
14 |
|
|
function theme_date_timezone($variables) {
|
15 |
|
|
$element = $variables['element'];
|
16 |
|
|
$attributes = $element['#attributes'];
|
17 |
|
|
$wrapper_attributes = array();
|
18 |
|
|
// Add a wrapper to mimic the way a single value field works, for ease in
|
19 |
|
|
// using #states.
|
20 |
|
|
if (isset($element['#children'])) {
|
21 |
|
|
$element['#children'] = '<div id="' . $element['#id'] . '" ' . new Attribute($wrapper_attributes) . '>' . $element['#children'] . '</div>';
|
22 |
|
|
}
|
23 |
|
|
return '<div ' . new Attribute($attributes) . '>' . theme('form_element', $element) . '</div>';
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* Returns HTML for a date select element.
|
28 |
|
|
*/
|
29 |
|
|
function theme_date_select($variables) {
|
30 |
|
|
$element = $variables['element'];
|
31 |
|
|
$attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array());
|
32 |
|
|
$attributes['class'][] = 'container-inline-date';
|
33 |
|
|
$wrapper_attributes = array('class' => array('date-padding'));
|
34 |
|
|
$wrapper_attributes['class'][] = 'clearfix';
|
35 |
|
|
// Add a wrapper to mimic the way a single value field works, for ease in
|
36 |
|
|
// using #states.
|
37 |
|
|
if (isset($element['#children'])) {
|
38 |
|
|
$element['#children'] = '<div id="' . $element['#id'] . '" ' . new Attribute($wrapper_attributes) . '>' . $element['#children'] . '</div>';
|
39 |
|
|
}
|
40 |
|
|
return '<div ' . new Attribute($attributes) . '>' . theme('form_element', $element) . '</div>';
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* Returns HTML for a date select input form element.
|
45 |
|
|
*/
|
46 |
|
|
function theme_date_select_element($variables) {
|
47 |
|
|
$element = $variables['element'];
|
48 |
|
|
$parents = $element['#parents'];
|
49 |
|
|
$part = array_pop($parents);
|
50 |
|
|
return '<div class="date-' . $part . '">' . theme('select', $element) . '</div>';
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Returns HTML for a date block that looks like a mini calendar day.
|
55 |
|
|
*
|
56 |
|
|
* Pass in a date object already set to the right timezone, format as a calendar
|
57 |
|
|
* page date. The calendar styling is created in CSS.
|
58 |
|
|
*/
|
59 |
|
|
function theme_date_calendar_day($variables) {
|
60 |
|
|
$output = '';
|
61 |
|
|
$date = $variables['date'];
|
62 |
|
|
if (!empty($date)) {
|
63 |
|
|
$output .= '<div class="date-calendar-day">';
|
64 |
|
|
$output .= '<span class="month">' . $date->format('M') . '</span>';
|
65 |
|
|
$output .= '<span class="day">' . $date->format('j') . '</span>';
|
66 |
|
|
$output .= '<span class="year">' . $date->format('Y') . '</span>';
|
67 |
|
|
$output .= '</div>';
|
68 |
|
|
}
|
69 |
|
|
return $output;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Returns HTML for a date in the format 'time ago'.
|
74 |
|
|
*/
|
75 |
|
|
function theme_date_time_ago($variables) {
|
76 |
|
|
$start_date = $variables['start_date'];
|
77 |
|
|
$end_date = $variables['end_date'];
|
78 |
|
|
$interval = !empty($variables['interval']) ? $variables['interval'] : 2;
|
79 |
|
|
$display = isset($variables['interval_display']) ? $variables['interval_display'] : 'time ago';
|
80 |
|
|
|
81 |
|
|
// If no date is sent, then return nothing.
|
82 |
|
|
if (empty($start_date) || empty($end_date)) {
|
83 |
|
|
return;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
// Time to compare dates to.
|
87 |
|
|
$now = date_format(new DrupalDateTime(), DATE_FORMAT_UNIX);
|
88 |
|
|
$start = date_format($start_date, DATE_FORMAT_UNIX);
|
89 |
|
|
|
90 |
|
|
// will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
|
91 |
|
|
$time_diff = $now - $start;
|
92 |
|
|
|
93 |
|
|
// Uses the same options used by Views format_interval.
|
94 |
|
|
switch ($display) {
|
95 |
|
|
case 'raw time ago':
|
96 |
|
|
return format_interval($time_diff, $interval);
|
97 |
|
|
case 'time ago':
|
98 |
|
|
return t('%time ago', array('%time' => format_interval($time_diff, $interval)));
|
99 |
|
|
case 'raw time hence':
|
100 |
|
|
return format_interval(-$time_diff, $interval);
|
101 |
|
|
case 'time hence':
|
102 |
|
|
return t('%time hence', array('%time' => format_interval(-$time_diff, $interval)));
|
103 |
|
|
case 'raw time span':
|
104 |
|
|
return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
|
105 |
|
|
case 'inverse time span':
|
106 |
|
|
return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
|
107 |
|
|
case 'time span':
|
108 |
|
|
return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), $interval)));
|
109 |
|
|
}
|
110 |
|
|
} |