views_handler_field_profile_date.inc

  1. 3.x modules/profile/views_handler_field_profile_date.inc
  2. 2.x modules/profile/views_handler_field_profile_date.inc

File

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