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"> - </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 ' ';
|
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
|
/**
|
173
|
* Returns HTML for a date block that looks like a mini calendar day.
|
174
|
*
|
175
|
* Pass in a date object already set to the right timezone, format as a calendar
|
176
|
* page date. The calendar styling is created in CSS.
|
177
|
*/
|
178
|
function theme_date_calendar_day($variables) {
|
179
|
$output = '';
|
180
|
$date = $variables['date'];
|
181
|
if (!empty($date)) {
|
182
|
$output .= '<div class="date-calendar-day">';
|
183
|
$output .= '<span class="month">' . date_format_date($date, 'custom', 'M') . '</span>';
|
184
|
$output .= '<span class="day">' . date_format_date($date, 'custom', 'j') . '</span>';
|
185
|
$output .= '<span class="year">' . date_format_date($date, 'custom', 'Y') . '</span>';
|
186
|
$output .= '</div>';
|
187
|
}
|
188
|
return $output;
|
189
|
}
|
190
|
|
191
|
/**
|
192
|
* Returns HTML for a date in the format 'time ago'.
|
193
|
*/
|
194
|
function theme_date_time_ago($variables) {
|
195
|
$start_date = $variables['start_date'];
|
196
|
$end_date = $variables['end_date'];
|
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
|
// Time to compare dates to.
|
206
|
$now = date_format(date_now(), DATE_FORMAT_UNIX);
|
207
|
$start = date_format($start_date, DATE_FORMAT_UNIX);
|
208
|
|
209
|
// Will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence).
|
210
|
$time_diff = $now - $start;
|
211
|
|
212
|
// Uses the same options used by Views format_interval.
|
213
|
switch ($display) {
|
214
|
case 'raw time ago':
|
215
|
return format_interval($time_diff, $interval);
|
216
|
|
217
|
case 'time ago':
|
218
|
return t('%time ago', array('%time' => format_interval($time_diff, $interval)));
|
219
|
|
220
|
case 'raw time hence':
|
221
|
return format_interval(-$time_diff, $interval);
|
222
|
|
223
|
case 'time hence':
|
224
|
return t('%time hence', array('%time' => format_interval(-$time_diff, $interval)));
|
225
|
|
226
|
case 'raw time span':
|
227
|
return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
|
228
|
|
229
|
case 'inverse time span':
|
230
|
return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
|
231
|
|
232
|
case 'time span':
|
233
|
return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), $interval)));
|
234
|
|
235
|
}
|
236
|
}
|