views_handler_filter_history_user_timestamp.inc

  1. 3.x modules/node/views_handler_filter_history_user_timestamp.inc
  2. 2.x modules/node/views_handler_filter_history_user_timestamp.inc

Definition of views_handler_filter_history_user_timestamp.

File

modules/node/views_handler_filter_history_user_timestamp.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_filter_history_user_timestamp.
  5. */
  6. /**
  7. * Filter for new content.
  8. *
  9. * The handler is named history_user, because of compability reasons, the table
  10. * is history.
  11. *
  12. * @ingroup views_filter_handlers
  13. */
  14. class views_handler_filter_history_user_timestamp extends views_handler_filter {
  15. // Don't display empty space where the operator would be.
  16. var $no_operator = TRUE;
  17. function expose_form(&$form, &$form_state) {
  18. parent::expose_form($form, $form_state);
  19. // @todo There are better ways of excluding required and multiple (object flags)
  20. unset($form['expose']['required']);
  21. unset($form['expose']['multiple']);
  22. unset($form['expose']['remember']);
  23. }
  24. function value_form(&$form, &$form_state) {
  25. // Only present a checkbox for the exposed filter itself. There's no way
  26. // to tell the difference between not checked and the default value, so
  27. // specifying the default value via the views UI is meaningless.
  28. if (!empty($form_state['exposed'])) {
  29. if (isset($this->options['expose']['label'])) {
  30. $label = $this->options['expose']['label'];
  31. }
  32. else {
  33. $label = t('Has new content');
  34. }
  35. $form['value'] = array(
  36. '#type' => 'checkbox',
  37. '#title' => $label,
  38. '#default_value' => $this->value,
  39. );
  40. }
  41. }
  42. function query() {
  43. global $user;
  44. // This can only work if we're logged in.
  45. if (!$user || !$user->uid) {
  46. return;
  47. }
  48. // Don't filter if we're exposed and the checkbox isn't selected.
  49. if ((!empty($this->options['exposed'])) && empty($this->value)) {
  50. return;
  51. }
  52. // Hey, Drupal kills old history, so nodes that haven't been updated
  53. // since NODE_NEW_LIMIT are bzzzzzzzt outta here!
  54. $limit = REQUEST_TIME - NODE_NEW_LIMIT;
  55. $this->ensure_my_table();
  56. $field = "$this->table_alias.$this->real_field";
  57. $node = $this->query->ensure_table('node', $this->relationship);
  58. $clause = '';
  59. $clause2 = '';
  60. if (module_exists('comment')) {
  61. $ncs = $this->query->ensure_table('node_comment_statistics', $this->relationship);
  62. $clause = ("OR $ncs.last_comment_timestamp > (***CURRENT_TIME*** - $limit)");
  63. $clause2 = "OR $field < $ncs.last_comment_timestamp";
  64. }
  65. // NULL means a history record doesn't exist. That's clearly new content.
  66. // Unless it's very very old content. Everything in the query is already
  67. // type safe cause none of it is coming from outside here.
  68. $this->query->add_where_expression($this->options['group'], "($field IS NULL AND ($node.changed > (***CURRENT_TIME*** - $limit) $clause)) OR $field < $node.changed $clause2");
  69. }
  70. function admin_summary() {
  71. if (!empty($this->options['exposed'])) {
  72. return t('exposed');
  73. }
  74. }
  75. }