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

File

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