Commit 856ae39d authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#186903 by marcingy, Rob Loach and chx: (regression) restore my recent posts...

#186903 by marcingy, Rob Loach and chx: (regression) restore my recent posts functionality in tracker
parent 73d88aa9
...@@ -30,24 +30,22 @@ function tracker_menu() { ...@@ -30,24 +30,22 @@ function tracker_menu() {
'weight' => 1, 'weight' => 1,
'file' => 'tracker.pages.inc', 'file' => 'tracker.pages.inc',
); );
$items['tracker/all'] = array( $items['tracker/all'] = array(
'title' => 'All recent posts', 'title' => 'All recent posts',
'type' => MENU_DEFAULT_LOCAL_TASK, 'type' => MENU_DEFAULT_LOCAL_TASK,
'access callback' => 'user_is_logged_in', 'access callback' => 'user_is_logged_in',
); );
$items['tracker/%user_current'] = array( $items['tracker/%user_current'] = array(
'title' => 'My recent posts', 'title' => 'My recent posts',
'type' => MENU_LOCAL_TASK,
'access callback' => 'user_is_logged_in', 'access callback' => 'user_is_logged_in',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK,
); );
$items['user/%user/track'] = array( $items['user/%user/track'] = array(
'title' => 'Track', 'title' => 'Track',
'page callback' => 'tracker_track_user', 'page callback' => 'tracker_page',
'access callback' => 'user_access', 'page arguments' => array(1, TRUE),
'access arguments' => array('access content'),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'file' => 'tracker.pages.inc', 'file' => 'tracker.pages.inc',
); );
......
...@@ -10,35 +10,23 @@ ...@@ -10,35 +10,23 @@
/** /**
* Menu callback. Prints a listing of active nodes on the site. * Menu callback. Prints a listing of active nodes on the site.
*/ */
function tracker_track_user() { function tracker_page($account = NULL, $set_title = FALSE) {
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 // Add CSS
drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE); drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE);
if ($account) {
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 definiton.
drupal_set_title(check_plain($account->name));
}
// TODO: These queries are very expensive, see http://drupal.org/node/105639 // 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 = '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 = 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 = '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); $sql_count = db_rewrite_sql($sql_count);
$result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid); $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $account->uid, $account->uid);
} }
else { 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 = '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';
......
...@@ -1076,15 +1076,17 @@ function user_init() { ...@@ -1076,15 +1076,17 @@ function user_init() {
} }
function user_current_load($arg) { function user_current_load($arg) {
return $arg ? user_load($arg) : FALSE; return user_load($arg ? $arg : $GLOBALS['user']->uid);
} }
/**
* Returns the user id of the currently logged in user.
*/
function user_current_to_arg($arg) { function user_current_to_arg($arg) {
// Give back the current user uid when called from eg. tracker, aka.
if (is_numeric($arg)) { // with an empty arg. Also use the current user uid when called from
return $arg; // the menu with a % for the current account link.
} return empty($arg) || $arg == '%' ? $GLOBALS['user']->uid : $arg;
return $GLOBALS['user']->uid;
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment