1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_profile_date.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler display a profile date
|
10
|
*
|
11
|
* The dates are stored serialized, which makes them mostly useless from
|
12
|
* SQL. About all we can do is unserialize and display them.
|
13
|
*
|
14
|
* @ingroup views_field_handlers
|
15
|
*/
|
16
|
class views_handler_field_profile_date extends views_handler_field_date {
|
17
|
function options_form(&$form, &$form_state) {
|
18
|
parent::options_form($form, $form_state);
|
19
|
// we can't do "time ago" so remove it from the form.
|
20
|
unset($form['date_format']['#options']['time ago']);
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* Display a profile field of type 'date'
|
25
|
*/
|
26
|
function render($values) {
|
27
|
$value = $this->get_value($values);
|
28
|
if (!$value) {
|
29
|
return;
|
30
|
}
|
31
|
$value = unserialize($value);
|
32
|
$format = $this->options['date_format'];
|
33
|
switch ($format) {
|
34
|
case 'custom':
|
35
|
$format = $this->options['custom_date_format'];
|
36
|
break;
|
37
|
case 'small':
|
38
|
$format = variable_get('date_format_short', 'm/d/Y - H:i');
|
39
|
break;
|
40
|
case 'medium':
|
41
|
$format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
|
42
|
break;
|
43
|
case 'large':
|
44
|
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
|
45
|
break;
|
46
|
}
|
47
|
|
48
|
// Note: Avoid PHP's date() because it does not handle dates before
|
49
|
// 1970 on Windows. This would make the date field useless for e.g.
|
50
|
// birthdays.
|
51
|
|
52
|
// But we *can* deal with non-year stuff:
|
53
|
$date = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
|
54
|
|
55
|
$replace = array(
|
56
|
// day
|
57
|
'd' => sprintf('%02d', $value['day']),
|
58
|
'D' => NULL,
|
59
|
'l' => NULL,
|
60
|
'N' => NULL,
|
61
|
'S' => gmdate('S', $date),
|
62
|
'w' => NULL,
|
63
|
'j' => $value['day'],
|
64
|
// month
|
65
|
'F' => gmdate('F', $date),
|
66
|
'm' => sprintf('%02d', $value['month']),
|
67
|
'M' => gmdate('M', $date),
|
68
|
'n' => gmdate('n', $date),
|
69
|
|
70
|
'Y' => $value['year'],
|
71
|
'y' => substr($value['year'], 2, 2),
|
72
|
|
73
|
// kill time stuff
|
74
|
'a' => NULL,
|
75
|
'A' => NULL,
|
76
|
'g' => NULL,
|
77
|
'G' => NULL,
|
78
|
'h' => NULL,
|
79
|
'H' => NULL,
|
80
|
'i' => NULL,
|
81
|
's' => NULL,
|
82
|
':' => NULL,
|
83
|
'T' => NULL,
|
84
|
' - ' => NULL,
|
85
|
':' => NULL,
|
86
|
);
|
87
|
|
88
|
return strtr($format, $replace);
|
89
|
}
|
90
|
}
|