-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalttracker.pages.inc
138 lines (120 loc) · 3.8 KB
/
alttracker.pages.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @file
* User page callbacks for tracker.module.
*/
function alttracker_page_my(){
global $user;
return alttracker_page($user);
}
/**
* Page callback: prints a listing of active nodes on the site.
*
* Queries the database for info, adds RDFa info if applicable, and generates
* the render array that will be used to render the page.
*/
function alttracker_page($account = NULL, $set_title = FALSE) {
altpager_items_elements(array(
60 => 60,
100 => 100,
200 => 200,
400 => 400,
600 => 600,
800 => 800,
1000 => 1000,
));
if ($account) {
$query = db_select('alttracker_user', 't')->extend('AltPager');
$query->condition('t.uid', $account->uid);
if ($set_title) {
// When viewed from user/%user/track, display the name of the user
// as page title -- the tab title remains Track so this needs to be done
// here and not in the menu definition.
drupal_set_title(format_username($account));
}
}
else {
$query = db_select('alttracker_node', 't', array('target' => 'slave'))->extend('AltPager');
}
if($types = variable_get('alttracker_node_type')){
$in_types = array();
foreach($types as $type => $val){
if($val){
$in_types[] = $type;
}
}
if(!empty($in_types)){
$query->leftJoin('node', 'n', 'n.nid = t.nid');
$query->condition('n.type', $in_types, 'IN');
}
}
if($ignore_terms = variable_get('alttracker_ignore_terms')){
$not_nids = db_select('taxonomy_index', 't')
-> fields('t', array('nid'))
-> condition('tid', $ignore_terms , 'IN')
-> execute()
->fetchCol();
$query->condition('n.nid', $not_nids, 'NOT IN');
}
$nids = $query
->addTag('alttracker_nodes_condition')
->fields('t', array('nid', 'changed'))
->condition('t.published', 1)
->orderBy('t.changed', 'DESC')
->execute()
->fetchCol();
$max = variable_get('alttracker_max_count', 1000);
$current = altpager_count_all_items();
if($current > $max){
altpager_count_all_items($max);
}
$page['first-pager'] = array(
'#theme' => 'altpager',
'#weight' => -10,
);
$nodes = alttracker_nodes_load($nids);
foreach($nodes as $nid => $node){
$history = _forum_user_last_visit($node->nid);
$node->new_replies = comment_num_new($node->nid, $history);
$node->new = $node->new_replies || (isset($node->last_comment_timestamp) && $node->last_comment_timestamp > $history);
if($node->new){
$node->url = url("node/$node->nid", array('query' => comment_new_page_count($node->comment_count, $node->new_replies, $node), 'fragment' => 'new'));
}else{
$node->url = url("node/$node->nid");
}
if(variable_get('alttracker_taxonomy')){
$tids = db_select('taxonomy_index', 't', array('target' => 'slave'))
->fields('t', array('tid'))
->condition('t.nid', $node->nid)
->execute()
->fetchCol();
$node->terms = taxonomy_term_load_multiple($tids, array());
}
$nodes[$nid] = $node;
}
$page['alttracker'] = array(
'#theme' => 'alttracker',
'#nodes' => $nodes,
);
$page['last-pager'] = array(
'#theme' => 'altpager',
'#weight' => 10,
);
$page['#sorted'] = TRUE;
return $page;
}
function alttracker_nodes_load($nids){
$query = db_select('node', 'n', array('target' => 'slave'));
$query->addTag('alttracker_nodes_load');
$query->join('alttracker_node', 't', 't.nid = n.nid');
$query->join('node_comment_statistics', 'l', 'l.nid = n.nid');
$query->join('users', 'u', 'n.uid = u.uid');
$query->condition('n.nid', $nids, 'IN')
->fields('n')
->fields('t', array('changed'))
->fields('l', array('comment_count'))
->fields('u', array('name'))
->orderBy('t.changed', 'DESC');
$result = $query->execute();
return $result->fetchAll();
}