webmaster@1: name)); webmaster@1: } webmaster@1: // TODO: These queries are very expensive, see http://drupal.org/node/105639 webmaster@1: $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'; webmaster@1: $sql = db_rewrite_sql($sql); webmaster@1: $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)'; webmaster@1: $sql_count = db_rewrite_sql($sql_count); webmaster@1: $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $account->uid, $account->uid); webmaster@1: } webmaster@1: else { webmaster@1: $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'; webmaster@1: $sql = db_rewrite_sql($sql); webmaster@1: $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1'; webmaster@1: $sql_count = db_rewrite_sql($sql_count); webmaster@1: $result = pager_query($sql, 25, 0, $sql_count); webmaster@1: } webmaster@1: webmaster@1: $rows = array(); webmaster@1: while ($node = db_fetch_object($result)) { webmaster@1: // Determine the number of comments: webmaster@1: $comments = 0; webmaster@1: if ($node->comment_count) { webmaster@1: $comments = $node->comment_count; webmaster@1: webmaster@1: if ($new = comment_num_new($node->nid)) { webmaster@1: $comments .= '
'; webmaster@1: $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('query' => comment_new_page_count($node->comment_count, $new, $node), 'fragment' => 'new')); webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: $rows[] = array( webmaster@1: check_plain(node_get_types('name', $node->type)), webmaster@1: l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), webmaster@1: theme('username', $node), webmaster@1: array('class' => 'replies', 'data' => $comments), webmaster@1: t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) webmaster@1: ); webmaster@1: } webmaster@1: webmaster@1: if (!$rows) { webmaster@1: $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5')); webmaster@1: } webmaster@1: webmaster@1: $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated')); webmaster@1: webmaster@1: $output = '
'; webmaster@1: $output .= theme('table', $header, $rows); webmaster@1: $output .= theme('pager', NULL, 25, 0); webmaster@1: $output .= '
'; webmaster@1: webmaster@1: return $output; webmaster@1: }