From a0f774a15e9c2122b61aa934986f67ed59496ded Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Thu, 23 Aug 2007 16:01:01 +0000 Subject: [PATCH] - Patch #169426 by Crell: split tracker module. --- modules/tracker/tracker.module | 79 +--------------------------- modules/tracker/tracker.pages.inc | 85 +++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 77 deletions(-) create mode 100644 modules/tracker/tracker.pages.inc diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index bfad4bf35589..e5fc308b234e 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -28,6 +28,7 @@ function tracker_menu() { 'page callback' => 'tracker_page', 'access arguments' => array('access content'), 'weight' => 1, + 'file' => 'tracker.pages.inc', ); $items['tracker/all'] = array( @@ -48,6 +49,7 @@ function tracker_menu() { 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_LOCAL_TASK, + 'file' => 'tracker.pages.inc', ); $items['user/%user/track/posts'] = array( 'title' => 'Track posts', @@ -55,80 +57,3 @@ function tracker_menu() { ); return $items; } - -/** - * Menu callback. Prints a listing of active nodes on the site. - */ -function tracker_track_user() { - if ($account = user_load(array('uid' => arg(1)))) { - if ($account->status || user_access('administer users')) { - drupal_set_title(check_plain($account->name)); - return tracker_page($account->uid); - } - else { - drupal_access_denied(); - } - } - else { - drupal_not_found(); - } -} - -/** - * Menu callback. Prints a listing of active nodes on the site. - */ -function tracker_page($uid = 0) { - // Add CSS - drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE); - - // TODO: These queries are very expensive, see http://drupal.org/node/105639 - if ($uid) { - $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_updated DESC'; - $sql = db_rewrite_sql($sql); - $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)'; - $sql_count = db_rewrite_sql($sql_count); - $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid); - } - else { - $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 ORDER BY last_updated DESC'; - $sql = db_rewrite_sql($sql); - $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1'; - $sql_count = db_rewrite_sql($sql_count); - $result = pager_query($sql, 25, 0, $sql_count); - } - - $rows = array(); - while ($node = db_fetch_object($result)) { - // Determine the number of comments: - $comments = 0; - if ($node->comment_count) { - $comments = $node->comment_count; - - if ($new = comment_num_new($node->nid)) { - $comments .= '<br />'; - $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('fragment' => 'new')); - } - } - - $rows[] = array( - node_get_types('name', $node->type), - l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), - theme('username', $node), - array('class' => 'replies', 'data' => $comments), - t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) - ); - } - - if (!$rows) { - $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5')); - } - - $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated')); - - $output = '<div id="tracker">'; - $output .= theme('table', $header, $rows); - $output .= theme('pager', NULL, 25, 0); - $output .= '</div>'; - - return $output; -} diff --git a/modules/tracker/tracker.pages.inc b/modules/tracker/tracker.pages.inc new file mode 100644 index 000000000000..68877ad1b554 --- /dev/null +++ b/modules/tracker/tracker.pages.inc @@ -0,0 +1,85 @@ +<?php +// $Id$ + +/** + * @file + * User page callbacks for the tracker module. + */ + + +/** + * Menu callback. Prints a listing of active nodes on the site. + */ +function tracker_track_user() { + if ($account = user_load(array('uid' => arg(1)))) { + if ($account->status || user_access('administer users')) { + drupal_set_title(check_plain($account->name)); + return tracker_page($account->uid); + } + else { + drupal_access_denied(); + } + } + else { + drupal_not_found(); + } +} + +/** + * Menu callback. Prints a listing of active nodes on the site. + */ +function tracker_page($uid = 0) { + // Add CSS + drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE); + + // TODO: These queries are very expensive, see http://drupal.org/node/105639 + if ($uid) { + $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_updated DESC'; + $sql = db_rewrite_sql($sql); + $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)'; + $sql_count = db_rewrite_sql($sql_count); + $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid); + } + else { + $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 ORDER BY last_updated DESC'; + $sql = db_rewrite_sql($sql); + $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1'; + $sql_count = db_rewrite_sql($sql_count); + $result = pager_query($sql, 25, 0, $sql_count); + } + + $rows = array(); + while ($node = db_fetch_object($result)) { + // Determine the number of comments: + $comments = 0; + if ($node->comment_count) { + $comments = $node->comment_count; + + if ($new = comment_num_new($node->nid)) { + $comments .= '<br />'; + $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('fragment' => 'new')); + } + } + + $rows[] = array( + node_get_types('name', $node->type), + l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), + theme('username', $node), + array('class' => 'replies', 'data' => $comments), + t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) + ); + } + + if (!$rows) { + $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5')); + } + + $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated')); + + $output = '<div id="tracker">'; + $output .= theme('table', $header, $rows); + $output .= theme('pager', NULL, 25, 0); + $output .= '</div>'; + + return $output; +} -- GitLab