[ticket/10532] Fix $start out of range for pre-made searches

PHPBB3-10532
This commit is contained in:
rxu 2011-12-18 16:28:35 +08:00
parent 51f8f642de
commit c9733ad719

View file

@ -471,26 +471,33 @@ if ($keywords || $author || $author_id || $search_id || $submit)
if ($search_id) if ($search_id)
{ {
if ($sql) if ($sql || $search_id == 'unreadposts')
{ {
// only return up to 1000 ids (the last one will be removed later) if ($sql)
$result = $db->sql_query_limit($sql, 1001 - $start, $start);
while ($row = $db->sql_fetchrow($result))
{ {
$id_ary[] = (int) $row[$field]; // only return up to 1000 ids (the last one will be removed later)
$result = $db->sql_query_limit($sql, 1001);
while ($row = $db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
$db->sql_freeresult($result);
}
else if ($search_id == 'unreadposts')
{
$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001));
} }
$db->sql_freeresult($result);
$total_match_count = sizeof($id_ary) + $start; if ($total_match_count = sizeof($id_ary))
$id_ary = array_slice($id_ary, 0, $per_page); {
} // Make sure $start is set to the last page if it exceeds the amount
else if ($search_id == 'unreadposts') if ($start < 0 || $start >= $total_match_count)
{ {
$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $start, $start)); $start = ($start < 0) ? 0 : floor(($total_match_count - 1) / $per_page) * $per_page;
}
$total_match_count = sizeof($id_ary) + $start; $id_ary = array_slice($id_ary, $start, $per_page);
$id_ary = array_slice($id_ary, 0, $per_page); }
} }
else else
{ {