| 1 |
<?php |
<?php |
| 2 |
// $Id: xtracker.module,v 1.8 2007/04/13 20:08:09 kbahey Exp $ |
// $Id: xtracker.module,v 1.7.2.2 2007/04/13 20:12:41 kbahey Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 161 |
$type = 'uid'; |
$type = 'uid'; |
| 162 |
} |
} |
| 163 |
|
|
| 164 |
|
$sql_where = ' WHERE n.status = 1 '; |
| 165 |
|
|
| 166 |
if (module_exists('nodevote')) { |
if (module_exists('nodevote')) { |
| 167 |
$score = true; // Flag we use later |
$score = TRUE; // Flag we use later |
| 168 |
$score_column = ',AVG(v.vote) AS score'; |
$score_column = ',AVG(v.vote) AS score'; |
| 169 |
$nv_join = ' LEFT JOIN {nodevote} v ON n.nid = v.nid '; |
$extra_join = ' LEFT JOIN {nodevote} v ON n.nid = v.nid '; |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
switch($type) { |
switch($type) { |
| 173 |
case 'uid': |
case 'uid': |
| 174 |
$id = (int)$id; |
$id = (int)$id; |
| 175 |
$sql_where = " AND (n.uid = '$id' OR c.uid = '$id') "; |
$sql_where .= " AND (n.uid = $id OR c.uid = $id) "; |
| 176 |
break; |
break; |
| 177 |
|
|
| 178 |
case 'tid': |
case 'tid': |
| 179 |
$id = (int)$id; |
$id = (int)$id; |
| 180 |
$sql_where = " AND t.tid = '$id' "; |
$extra_join .= ' INNER JOIN {term_node} t ON t.nid = n.nid '; |
| 181 |
|
$sql_where .= " AND t.tid = $id "; |
| 182 |
break; |
break; |
| 183 |
|
|
| 184 |
case 'type': |
case 'type': |
| 185 |
$id = db_escape_string($id); |
$id = db_escape_string($id); |
| 186 |
$sql_where = " AND n.type = '$id' "; |
$sql_where .= " AND n.type = '$id' "; |
| 187 |
break; |
break; |
| 188 |
|
|
| 189 |
case 'all': |
case 'all': |
| 190 |
default: |
default: |
|
$sql_where = ' '; |
|
| 191 |
break; |
break; |
| 192 |
} |
} |
| 193 |
|
|
| 194 |
$header = array( |
$header = array( |
| 195 |
array('data' => t('Type'), 'field' => 'type'), |
array('data' => t('Type'), 'field' => 'type'), |
| 196 |
array('data' => t('Post'), 'field' => 'title'), |
array('data' => t('Post'), 'field' => 'title'), |
| 197 |
array('data' => t('Author'), 'field' => 'name',), |
array('data' => t('Author'), 'field' => 'uid',), |
| 198 |
array('data' => t('Replies'), 'field' => 'comment_count'), |
array('data' => t('Replies'), 'field' => 'comment_count'), |
| 199 |
array('data' => t('Last Post'), 'field' => 'last_post', 'sort' => 'desc') |
array('data' => t('Last Post'), 'field' => 'last_update', 'sort' => 'desc') |
| 200 |
); |
); |
| 201 |
|
|
|
|
|
|
|
|
| 202 |
if ($score) { |
if ($score) { |
| 203 |
$header = array_merge($header, array( |
$header = array_merge($header, array( |
| 204 |
array('data' => t('Score'), 'field' => 'score') |
array('data' => t('Score'), 'field' => 'score') |
| 205 |
)); |
)); |
| 206 |
} |
} |
| 207 |
|
|
| 208 |
$sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_post, l.comment_count ' . $score_column . ' FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ' . $nv_join . 'LEFT JOIN {term_node} t ON t.nid = n.nid LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 ' . $sql_where . ' GROUP BY n.nid '; |
$sql_from = ' FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid LEFT JOIN {comments} c ON n.nid = c.nid' . $extra_join; |
| 209 |
|
|
| 210 |
$sql_count = 'SELECT COUNT(t.nid) FROM {node} n LEFT JOIN {term_node} t USING (nid) LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = t.nid AND n.status = 1 ' . $sql_where; |
$sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, GREATEST(n.changed, l.last_comment_timestamp) AS last_update, l.comment_count '. $score_column . $sql_from . $sql_where .' GROUP BY n.nid '; |
| 211 |
|
|
| 212 |
|
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) '. $sql_from . $sql_where; |
| 213 |
|
|
| 214 |
$sql .= tablesort_sql($header); |
$sql .= tablesort_sql($header); |
| 215 |
$result = pager_query($sql, variable_get(XTRACKER_PAGE_COUNT, 10), 0, $sql_count); |
$result = pager_query($sql, variable_get(XTRACKER_PAGE_COUNT, 10), 0, $sql_count); |
| 226 |
} |
} |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
|
$result2 = db_query('SELECT uid, name FROM {users} WHERE uid = %d', $node->uid); |
| 230 |
|
$author = db_fetch_object($result2); |
| 231 |
|
$author_name = theme_username($author); |
| 232 |
|
|
| 233 |
$row = array( |
$row = array( |
| 234 |
node_get_types('name',$node), |
node_get_types('name',$node), |
| 235 |
l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), |
l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), |
| 236 |
theme_username($node), |
$author_name, |
| 237 |
array('class' => 'replies', 'data' => $comments), |
array('class' => 'replies', 'data' => $comments), |
| 238 |
t('@time ago', array('@time' => format_interval(time() - $node->last_post))), |
t('@time ago', array('@time' => format_interval(time() - $node->last_update))), |
| 239 |
); |
); |
| 240 |
|
|
| 241 |
if ($score) { |
if ($score) { |
| 271 |
} |
} |
| 272 |
} |
} |
| 273 |
return $data; |
return $data; |
|
} |
|
|
?> |
|
| 274 |
|
} |