- Patch #9884 by Bart Jansens:
+ The 'previous topic' / 'next topic' links skipped topic without comments (changed one inner join back to a left join). + The default order setting in admin/settings/forum had no effect. + The 'first new topic' link jumped to the first unread topic ever instead of the first unread topic since NODE_NEW_LIMIT. + This also removes the unused $offset param from theme_forum_display and theme_forum_topic_list, so any themes using these functions should be updated (i checked the core themes but none of them used these functions).4.5.x
parent
4cad8d5c31
commit
d6a91bddcf
|
@ -111,7 +111,6 @@ function forum_load($node) {
|
|||
* most recently added forum topics.
|
||||
*/
|
||||
function forum_block($op = 'list', $delta = 0) {
|
||||
global $user;
|
||||
|
||||
if ($op == 'list') {
|
||||
$blocks[0]['info'] = t('Forum topics');
|
||||
|
@ -149,7 +148,7 @@ function forum_link($type, $node = 0, $main = 0) {
|
|||
if (!$main && $type == 'node' && $node->type == 'forum') {
|
||||
// get previous and next topic
|
||||
|
||||
$result = db_query('SELECT DISTINCT(n.nid), n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n '. node_access_join_sql() .' INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 AND '. node_access_where_sql() .' GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '. _forum_get_topic_order(isset($user->sortby) ? $user->sortby : variable_get('forum_order', 1)), $node->tid);
|
||||
$result = db_query('SELECT DISTINCT(n.nid), n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort FROM {node} n '. node_access_join_sql() .' INNER JOIN {forum} f ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 AND '. node_access_where_sql() .' GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '. _forum_get_topic_order_sql(variable_get('forum_order', 1)), $node->tid);
|
||||
|
||||
while ($topic = db_fetch_object($result)) {
|
||||
if ($stop == 1) {
|
||||
|
@ -321,8 +320,6 @@ function _forum_format($topic) {
|
|||
}
|
||||
|
||||
function forum_get_forums($tid = 0) {
|
||||
global $user;
|
||||
|
||||
if (!$tid) {
|
||||
$tid = 0;
|
||||
}
|
||||
|
@ -332,7 +329,6 @@ function forum_get_forums($tid = 0) {
|
|||
if (empty($cache)) {
|
||||
$forums = array();
|
||||
$_forums = taxonomy_get_tree(variable_get('forum_nav_vocabulary', ''), $tid);
|
||||
$n = 0;
|
||||
foreach ($_forums as $forum) {
|
||||
if (in_array($forum->tid, variable_get('forum_containers', array()))) {
|
||||
$forum->container = 1;
|
||||
|
@ -341,7 +337,6 @@ function forum_get_forums($tid = 0) {
|
|||
$forum->num_posts = _forum_num_replies($forum->tid) + $forum->num_topics;
|
||||
$forum->last_post = _forum_last_post($forum->tid);
|
||||
$forums[$forum->tid] = $forum;
|
||||
$n++;
|
||||
}
|
||||
|
||||
cache_set("forum:$tid", serialize($forums), 1);
|
||||
|
@ -390,40 +385,37 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
|
|||
array('data' => t('Topic'), 'field' => 'n.title'),
|
||||
array('data' => t('Replies'), 'field' => 'num_comments'),
|
||||
array('data' => t('Created'), 'field' => 'n.created'),
|
||||
array('data' => t('Last reply'), 'field' => 'date_sort', 'sort' => 'desc'),
|
||||
array('data' => t('Last reply'), 'field' => 'date_sort'),
|
||||
);
|
||||
|
||||
$sql_sortby = _forum_get_topic_order($sortby);
|
||||
$order = _forum_get_topic_order($sortby);
|
||||
for ($i = 0; $i < count($forum_topic_list_header); $i++) {
|
||||
if ($forum_topic_list_header[$i]['field'] == $sql_sortby) {
|
||||
$forum_topic_list_header[$i]['order'] = $sql_sortby;
|
||||
if ($forum_topic_list_header[$i]['field'] == $order['field']) {
|
||||
$forum_topic_list_header[$i]['sort'] = $order['sort'];
|
||||
}
|
||||
}
|
||||
|
||||
$term = taxonomy_get_term($tid);
|
||||
$voc = taxonomy_get_vocabulary($term->vid);
|
||||
$check_tid = $tid ? "'". check_query($tid) ."'" : 'NULL';
|
||||
|
||||
// show topics with the correct tid, or in the forum but with shadow = 1
|
||||
// @TODO: this is not ANSI SQL! ("user error: 'n.created' isn't in GROUP BY")
|
||||
// @TODO: timestamp is a sql reserved word. are there more?
|
||||
$sql = "SELECT DISTINCT(n.nid), n.title, n.sticky, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n ". node_access_join_sql() ." INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
|
||||
$sql = "SELECT DISTINCT(n.nid), n.title, n.sticky, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n ". node_access_join_sql() ." INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
|
||||
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
|
||||
|
||||
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum'";
|
||||
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum'";
|
||||
|
||||
$result = pager_query($sql, $forum_per_page, 0, $sql_count);
|
||||
$topic_num = db_num_rows($result);
|
||||
|
||||
$n = 0;
|
||||
while ($topic = db_fetch_object($result)) {
|
||||
if ($user->uid) {
|
||||
$history = _forum_user_last_visit($topic->nid);
|
||||
// folder is new if topic is new or there are new comments since last visit
|
||||
if ($topic->shadow > 0) {
|
||||
$topic->new = 0;
|
||||
}
|
||||
else {
|
||||
$history = _forum_user_last_visit($topic->nid);
|
||||
$topic->new_replies = db_result(db_query('SELECT COUNT(DISTINCT(c.nid)) FROM {node} n '. node_access_join_sql() .' INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND n.status = 1 AND '. node_access_where_sql() .' AND c.status = 0 AND c.timestamp > %d', $topic->nid, $history));
|
||||
$topic->new = $topic->new_replies || ($topic->timestamp > $history);
|
||||
}
|
||||
|
@ -448,7 +440,7 @@ function _forum_new($tid) {
|
|||
$read[] = $r->nid;
|
||||
}
|
||||
|
||||
$nid = db_result(db_query_range("SELECT DISTINCT(n.nid) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND ". node_access_where_sql() ." AND f.tid = %d ". ($read ? 'AND NOT (n.nid IN ('. implode(',', $read) .')) ' : '') .'ORDER BY created', $tid, 0, 1));
|
||||
$nid = db_result(db_query_range("SELECT DISTINCT(n.nid) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND ". node_access_where_sql() ." AND f.tid = %d AND n.created > %d ". ($read ? 'AND NOT (n.nid IN ('. implode(',', $read) .')) ' : '') .'ORDER BY created', $tid, NODE_NEW_LIMIT, 0, 1));
|
||||
|
||||
return $nid ? $nid : 0;
|
||||
}
|
||||
|
@ -457,9 +449,7 @@ function _forum_new($tid) {
|
|||
* Menu callback; prints a forum listing.
|
||||
*/
|
||||
function forum_page($tid = 0, $display = 'all') {
|
||||
global $sortby, $forum_per_page, $from, $user;
|
||||
|
||||
$op = $_POST['op'];
|
||||
global $user;
|
||||
|
||||
if (module_exist('taxonomy')) {
|
||||
if ($display == 'new') {
|
||||
|
@ -468,15 +458,8 @@ function forum_page($tid = 0, $display = 'all') {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (empty($sortby)) {
|
||||
$sortby = isset($user->sortby) ? $user->sortby : variable_get('forum_order', 1);
|
||||
}
|
||||
|
||||
if (empty($forum_per_page)) {
|
||||
$forum_per_page = isset($user->forum_per_page) ? $user->forum_per_page : variable_get('forum_per_page', 25);
|
||||
}
|
||||
|
||||
$offset = ($from / $forum_per_page) + 1;
|
||||
$forum_per_page = variable_get('forum_per_page', 25);
|
||||
$sortby = variable_get('forum_order', 1);
|
||||
|
||||
$forums = forum_get_forums($tid);
|
||||
$parents = taxonomy_get_parents_all($tid);
|
||||
|
@ -484,7 +467,7 @@ function forum_page($tid = 0, $display = 'all') {
|
|||
$topics = forum_get_topics($tid, $sortby, $forum_per_page);
|
||||
}
|
||||
|
||||
print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page, $offset);
|
||||
print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -506,11 +489,10 @@ function forum_page($tid = 0, $display = 'all') {
|
|||
* @param tid
|
||||
* @param sortby
|
||||
* @param forum_per_page
|
||||
* @param offset
|
||||
*
|
||||
* @return the output for the forum body.
|
||||
*/
|
||||
function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page, $offset) {
|
||||
function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page) {
|
||||
global $user;
|
||||
// forum list, topics list, topic browser and 'add new topic' link
|
||||
|
||||
|
@ -563,7 +545,7 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
|
|||
$output .= theme('forum_list', $forums, $parents, $tid);
|
||||
|
||||
if ($tid && !in_array($tid, variable_get('forum_containers', array()))) {
|
||||
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page, $offset);
|
||||
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page);
|
||||
}
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
@ -612,17 +594,12 @@ function theme_forum_list($forums, $parents, $tid) {
|
|||
$new_topics = 0;
|
||||
}
|
||||
|
||||
$links = array();
|
||||
|
||||
$description = '<div style="margin-left: '. ($forum->depth * 30) ."px;\">\n";
|
||||
$description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n";
|
||||
|
||||
if ($forum->description) {
|
||||
$description .= " <div class=\"description\">$forum->description</div>\n";
|
||||
}
|
||||
if ($links) {
|
||||
$description .= ' <div class="links">'. t('Jump to: %links', array('%links' => implode(', ', $links))) .".</div>\n";
|
||||
}
|
||||
$description .= "</div>\n";
|
||||
|
||||
$rows[] = array(
|
||||
|
@ -644,12 +621,11 @@ function theme_forum_list($forums, $parents, $tid) {
|
|||
* @param topics
|
||||
* @param sortby
|
||||
* @param forum_per_page
|
||||
* @param offset
|
||||
*
|
||||
* @return output for the topic list.
|
||||
*/
|
||||
function theme_forum_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) {
|
||||
global $id, $status, $pager_total, $forum_topic_list_header;
|
||||
function theme_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
|
||||
global $forum_topic_list_header;
|
||||
|
||||
if ($topics) {
|
||||
|
||||
|
@ -736,18 +712,23 @@ function _forum_user_last_visit($nid) {
|
|||
function _forum_get_topic_order($sortby) {
|
||||
switch ($sortby) {
|
||||
case 1:
|
||||
return 'date_sort DESC';
|
||||
return array('field' => 'date_sort', 'sort' => 'desc');
|
||||
break;
|
||||
case 2:
|
||||
return 'date_sort ASC';
|
||||
return array('field' => 'date_sort', 'sort' => 'asc');
|
||||
break;
|
||||
case 3:
|
||||
return 'num_comments DESC';
|
||||
return array('field' => 'num_comments', 'sort' => 'desc');
|
||||
break;
|
||||
case 4:
|
||||
return 'num_comments ASC';
|
||||
return array('field' => 'num_comments', 'sort' => 'asc');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function _forum_get_topic_order_sql($sortby) {
|
||||
$order = _forum_get_topic_order($sortby);
|
||||
return $order['field'] .' '. $order['sort'];
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -111,7 +111,6 @@ function forum_load($node) {
|
|||
* most recently added forum topics.
|
||||
*/
|
||||
function forum_block($op = 'list', $delta = 0) {
|
||||
global $user;
|
||||
|
||||
if ($op == 'list') {
|
||||
$blocks[0]['info'] = t('Forum topics');
|
||||
|
@ -149,7 +148,7 @@ function forum_link($type, $node = 0, $main = 0) {
|
|||
if (!$main && $type == 'node' && $node->type == 'forum') {
|
||||
// get previous and next topic
|
||||
|
||||
$result = db_query('SELECT DISTINCT(n.nid), n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n '. node_access_join_sql() .' INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 AND '. node_access_where_sql() .' GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '. _forum_get_topic_order(isset($user->sortby) ? $user->sortby : variable_get('forum_order', 1)), $node->tid);
|
||||
$result = db_query('SELECT DISTINCT(n.nid), n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort FROM {node} n '. node_access_join_sql() .' INNER JOIN {forum} f ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 AND '. node_access_where_sql() .' GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '. _forum_get_topic_order_sql(variable_get('forum_order', 1)), $node->tid);
|
||||
|
||||
while ($topic = db_fetch_object($result)) {
|
||||
if ($stop == 1) {
|
||||
|
@ -321,8 +320,6 @@ function _forum_format($topic) {
|
|||
}
|
||||
|
||||
function forum_get_forums($tid = 0) {
|
||||
global $user;
|
||||
|
||||
if (!$tid) {
|
||||
$tid = 0;
|
||||
}
|
||||
|
@ -332,7 +329,6 @@ function forum_get_forums($tid = 0) {
|
|||
if (empty($cache)) {
|
||||
$forums = array();
|
||||
$_forums = taxonomy_get_tree(variable_get('forum_nav_vocabulary', ''), $tid);
|
||||
$n = 0;
|
||||
foreach ($_forums as $forum) {
|
||||
if (in_array($forum->tid, variable_get('forum_containers', array()))) {
|
||||
$forum->container = 1;
|
||||
|
@ -341,7 +337,6 @@ function forum_get_forums($tid = 0) {
|
|||
$forum->num_posts = _forum_num_replies($forum->tid) + $forum->num_topics;
|
||||
$forum->last_post = _forum_last_post($forum->tid);
|
||||
$forums[$forum->tid] = $forum;
|
||||
$n++;
|
||||
}
|
||||
|
||||
cache_set("forum:$tid", serialize($forums), 1);
|
||||
|
@ -390,40 +385,37 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
|
|||
array('data' => t('Topic'), 'field' => 'n.title'),
|
||||
array('data' => t('Replies'), 'field' => 'num_comments'),
|
||||
array('data' => t('Created'), 'field' => 'n.created'),
|
||||
array('data' => t('Last reply'), 'field' => 'date_sort', 'sort' => 'desc'),
|
||||
array('data' => t('Last reply'), 'field' => 'date_sort'),
|
||||
);
|
||||
|
||||
$sql_sortby = _forum_get_topic_order($sortby);
|
||||
$order = _forum_get_topic_order($sortby);
|
||||
for ($i = 0; $i < count($forum_topic_list_header); $i++) {
|
||||
if ($forum_topic_list_header[$i]['field'] == $sql_sortby) {
|
||||
$forum_topic_list_header[$i]['order'] = $sql_sortby;
|
||||
if ($forum_topic_list_header[$i]['field'] == $order['field']) {
|
||||
$forum_topic_list_header[$i]['sort'] = $order['sort'];
|
||||
}
|
||||
}
|
||||
|
||||
$term = taxonomy_get_term($tid);
|
||||
$voc = taxonomy_get_vocabulary($term->vid);
|
||||
$check_tid = $tid ? "'". check_query($tid) ."'" : 'NULL';
|
||||
|
||||
// show topics with the correct tid, or in the forum but with shadow = 1
|
||||
// @TODO: this is not ANSI SQL! ("user error: 'n.created' isn't in GROUP BY")
|
||||
// @TODO: timestamp is a sql reserved word. are there more?
|
||||
$sql = "SELECT DISTINCT(n.nid), n.title, n.sticky, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n ". node_access_join_sql() ." INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
|
||||
$sql = "SELECT DISTINCT(n.nid), n.title, n.sticky, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n ". node_access_join_sql() ." INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
|
||||
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
|
||||
|
||||
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum'";
|
||||
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ". node_access_where_sql() ." AND n.type = 'forum'";
|
||||
|
||||
$result = pager_query($sql, $forum_per_page, 0, $sql_count);
|
||||
$topic_num = db_num_rows($result);
|
||||
|
||||
$n = 0;
|
||||
while ($topic = db_fetch_object($result)) {
|
||||
if ($user->uid) {
|
||||
$history = _forum_user_last_visit($topic->nid);
|
||||
// folder is new if topic is new or there are new comments since last visit
|
||||
if ($topic->shadow > 0) {
|
||||
$topic->new = 0;
|
||||
}
|
||||
else {
|
||||
$history = _forum_user_last_visit($topic->nid);
|
||||
$topic->new_replies = db_result(db_query('SELECT COUNT(DISTINCT(c.nid)) FROM {node} n '. node_access_join_sql() .' INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND n.status = 1 AND '. node_access_where_sql() .' AND c.status = 0 AND c.timestamp > %d', $topic->nid, $history));
|
||||
$topic->new = $topic->new_replies || ($topic->timestamp > $history);
|
||||
}
|
||||
|
@ -448,7 +440,7 @@ function _forum_new($tid) {
|
|||
$read[] = $r->nid;
|
||||
}
|
||||
|
||||
$nid = db_result(db_query_range("SELECT DISTINCT(n.nid) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND ". node_access_where_sql() ." AND f.tid = %d ". ($read ? 'AND NOT (n.nid IN ('. implode(',', $read) .')) ' : '') .'ORDER BY created', $tid, 0, 1));
|
||||
$nid = db_result(db_query_range("SELECT DISTINCT(n.nid) FROM {node} n ". node_access_join_sql() ." INNER JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND ". node_access_where_sql() ." AND f.tid = %d AND n.created > %d ". ($read ? 'AND NOT (n.nid IN ('. implode(',', $read) .')) ' : '') .'ORDER BY created', $tid, NODE_NEW_LIMIT, 0, 1));
|
||||
|
||||
return $nid ? $nid : 0;
|
||||
}
|
||||
|
@ -457,9 +449,7 @@ function _forum_new($tid) {
|
|||
* Menu callback; prints a forum listing.
|
||||
*/
|
||||
function forum_page($tid = 0, $display = 'all') {
|
||||
global $sortby, $forum_per_page, $from, $user;
|
||||
|
||||
$op = $_POST['op'];
|
||||
global $user;
|
||||
|
||||
if (module_exist('taxonomy')) {
|
||||
if ($display == 'new') {
|
||||
|
@ -468,15 +458,8 @@ function forum_page($tid = 0, $display = 'all') {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (empty($sortby)) {
|
||||
$sortby = isset($user->sortby) ? $user->sortby : variable_get('forum_order', 1);
|
||||
}
|
||||
|
||||
if (empty($forum_per_page)) {
|
||||
$forum_per_page = isset($user->forum_per_page) ? $user->forum_per_page : variable_get('forum_per_page', 25);
|
||||
}
|
||||
|
||||
$offset = ($from / $forum_per_page) + 1;
|
||||
$forum_per_page = variable_get('forum_per_page', 25);
|
||||
$sortby = variable_get('forum_order', 1);
|
||||
|
||||
$forums = forum_get_forums($tid);
|
||||
$parents = taxonomy_get_parents_all($tid);
|
||||
|
@ -484,7 +467,7 @@ function forum_page($tid = 0, $display = 'all') {
|
|||
$topics = forum_get_topics($tid, $sortby, $forum_per_page);
|
||||
}
|
||||
|
||||
print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page, $offset);
|
||||
print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -506,11 +489,10 @@ function forum_page($tid = 0, $display = 'all') {
|
|||
* @param tid
|
||||
* @param sortby
|
||||
* @param forum_per_page
|
||||
* @param offset
|
||||
*
|
||||
* @return the output for the forum body.
|
||||
*/
|
||||
function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page, $offset) {
|
||||
function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page) {
|
||||
global $user;
|
||||
// forum list, topics list, topic browser and 'add new topic' link
|
||||
|
||||
|
@ -563,7 +545,7 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
|
|||
$output .= theme('forum_list', $forums, $parents, $tid);
|
||||
|
||||
if ($tid && !in_array($tid, variable_get('forum_containers', array()))) {
|
||||
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page, $offset);
|
||||
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page);
|
||||
}
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
@ -612,17 +594,12 @@ function theme_forum_list($forums, $parents, $tid) {
|
|||
$new_topics = 0;
|
||||
}
|
||||
|
||||
$links = array();
|
||||
|
||||
$description = '<div style="margin-left: '. ($forum->depth * 30) ."px;\">\n";
|
||||
$description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n";
|
||||
|
||||
if ($forum->description) {
|
||||
$description .= " <div class=\"description\">$forum->description</div>\n";
|
||||
}
|
||||
if ($links) {
|
||||
$description .= ' <div class="links">'. t('Jump to: %links', array('%links' => implode(', ', $links))) .".</div>\n";
|
||||
}
|
||||
$description .= "</div>\n";
|
||||
|
||||
$rows[] = array(
|
||||
|
@ -644,12 +621,11 @@ function theme_forum_list($forums, $parents, $tid) {
|
|||
* @param topics
|
||||
* @param sortby
|
||||
* @param forum_per_page
|
||||
* @param offset
|
||||
*
|
||||
* @return output for the topic list.
|
||||
*/
|
||||
function theme_forum_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) {
|
||||
global $id, $status, $pager_total, $forum_topic_list_header;
|
||||
function theme_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
|
||||
global $forum_topic_list_header;
|
||||
|
||||
if ($topics) {
|
||||
|
||||
|
@ -736,18 +712,23 @@ function _forum_user_last_visit($nid) {
|
|||
function _forum_get_topic_order($sortby) {
|
||||
switch ($sortby) {
|
||||
case 1:
|
||||
return 'date_sort DESC';
|
||||
return array('field' => 'date_sort', 'sort' => 'desc');
|
||||
break;
|
||||
case 2:
|
||||
return 'date_sort ASC';
|
||||
return array('field' => 'date_sort', 'sort' => 'asc');
|
||||
break;
|
||||
case 3:
|
||||
return 'num_comments DESC';
|
||||
return array('field' => 'num_comments', 'sort' => 'desc');
|
||||
break;
|
||||
case 4:
|
||||
return 'num_comments ASC';
|
||||
return array('field' => 'num_comments', 'sort' => 'asc');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function _forum_get_topic_order_sql($sortby) {
|
||||
$order = _forum_get_topic_order($sortby);
|
||||
return $order['field'] .' '. $order['sort'];
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue