date.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Elgg date input
  4. * Displays a text field with a popup date picker.
  5. *
  6. * The elgg.ui JavaScript library initializes the jQueryUI datepicker based
  7. * on the CSS class .elgg-input-date. It uses the ISO 8601 standard for date
  8. * representation: yyyy-mm-dd.
  9. *
  10. * Unix timestamps are supported by setting the 'timestamp' parameter to true.
  11. * The date is still displayed to the user in a text format but is submitted as
  12. * a unix timestamp in seconds.
  13. *
  14. * @uses $vars['value'] The current value, if any (as a unix timestamp)
  15. * @uses $vars['class'] Additional CSS class
  16. * @uses $vars['timestamp'] Store as a Unix timestamp in seconds. Default = false
  17. * Note: you cannot use an id with the timestamp option.
  18. */
  19. $vars['class'] = (array) elgg_extract('class', $vars, []);
  20. $vars['class'][] = 'elgg-input-date';
  21. //@todo popup_calendar deprecated in 1.8. Remove in 2.0
  22. $vars['class'][] = 'popup_calendar';
  23. $defaults = array(
  24. 'value' => '',
  25. 'disabled' => false,
  26. 'timestamp' => false,
  27. 'type' => 'text'
  28. );
  29. $vars = array_merge($defaults, $vars);
  30. $timestamp = $vars['timestamp'];
  31. unset($vars['timestamp']);
  32. if ($timestamp) {
  33. echo elgg_view('input/hidden', ['name' => $vars['name'], 'value' => $vars['value']]);
  34. $vars['class'][] = 'elgg-input-timestamp';
  35. $vars['id'] = $vars['name'];
  36. unset($vars['name']);
  37. }
  38. // convert timestamps to text for display
  39. if (is_numeric($vars['value'])) {
  40. $vars['value'] = gmdate('Y-m-d', $vars['value']);
  41. }
  42. echo elgg_format_element('input', $vars);
  43. if (elgg_is_xhr()) {
  44. echo elgg_format_element('script', null, 'elgg.ui.initDatePicker();');
  45. }