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