diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 79ea8978ee..f5e494ae4c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1649,12 +1649,13 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis * * @param int $user_id User ID (or false for current user) * @param string $sql_extra Extra WHERE SQL statement -* @param string $sql_limit Limits the size of unread topics list +* @param string $sql_sort ORDER BY SQL sorting statement +* @param string $sql_limit Limits the size of unread topics list, 0 for unlimited query * * @return array[int][int] Topic ids as keys, mark_time of topic as value * @author rxu */ -function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_limit = 1001) +function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001) { global $config, $db, $user; @@ -1663,6 +1664,11 @@ function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_limit = $user_id = (int) $user->data['user_id']; } + if (empty($sql_sort)) + { + $sql_sort = 'ORDER BY t.topic_last_post_time DESC'; + } + $tracked_topics_list = $unread_topics_list = $read_topics_list = array(); $tracked_forums_list = $mark_time = array(); @@ -1674,7 +1680,7 @@ function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_limit = WHERE t.topic_id = tt.topic_id AND tt.user_id = $user_id $sql_extra - ORDER BY t.topic_last_post_time DESC"; + $sql_sort"; $result = $db->sql_query_limit($sql, $sql_limit); while ($row = $db->sql_fetchrow($result)) @@ -1706,7 +1712,7 @@ function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_limit = AND ' . $db->sql_in_set('t.topic_id', $tracked_topics_list, true, true) . " AND ft.user_id = $user_id $sql_extra - ORDER BY t.topic_last_post_time DESC"; + $sql_sort"; $result = $db->sql_query_limit($sql, ($sql_limit - $unread_list_count)); while ($row = $db->sql_fetchrow($result)) @@ -1742,7 +1748,7 @@ function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_limit = AND ' . $db->sql_in_set('t.topic_id', $tracked_topics_list, true, true) . ' AND ' . $db->sql_in_set('t.forum_id', $tracked_forums_list, true, true) . " $sql_extra - ORDER BY t.topic_last_post_time DESC"; + $sql_sort"; $result = $db->sql_query_limit($sql, ($sql_limit - $unread_list_count)); while ($row = $db->sql_fetchrow($result)) @@ -1776,9 +1782,9 @@ function get_unread_topics_list($user_id = false, $sql_extra = '', $sql_limit = FROM ' . TOPICS_TABLE . ' t WHERE t.topic_last_post_time > ' . $user_lastmark . " $sql_extra - ORDER BY t.topic_last_post_time DESC"; + $sql_sort"; - $result = $db->sql_query_limit($sql, 1000); + $result = $db->sql_query_limit($sql, $sql_limit); while ($row = $db->sql_fetchrow($result)) { diff --git a/phpBB/search.php b/phpBB/search.php index f991e8e023..66323e5d1d 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -376,24 +376,23 @@ if ($keywords || $author || $author_id || $search_id || $submit) // force sorting $show_results = 'topics'; $sort_key = 't'; - $sort_dir = 'd'; $sort_by_sql['t'] = 't.topic_last_post_time'; $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); + $sql_where = 'AND t.topic_moved_id = 0 + ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' + ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : ''); gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); $s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = ''; $unread_list = array(); - $unread_list = get_unread_topics_list(); + $unread_list = get_unread_topics_list($user->data['user_id'], $sql_where, $sql_sort); if (!empty($unread_list)) { $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t - WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . ' - AND t.topic_moved_id = 0 - ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' - ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . " + WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . " $sql_sort"; $field = 'topic_id'; }