aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/search.php
diff options
context:
space:
mode:
authorrxu <rxu@mail.ru>2011-12-18 16:28:35 +0800
committerrxu <rxu@mail.ru>2012-01-14 15:55:23 +0800
commitc9733ad7195995a9f28ecbbc8aa3e94a05527114 (patch)
tree3a1f3378f34c2f4a28de7e32d51e3dcfa4f57ad0 /phpBB/search.php
parent51f8f642de537ee826a1da07b6b06374df9fc236 (diff)
downloadforums-c9733ad7195995a9f28ecbbc8aa3e94a05527114.tar
forums-c9733ad7195995a9f28ecbbc8aa3e94a05527114.tar.gz
forums-c9733ad7195995a9f28ecbbc8aa3e94a05527114.tar.bz2
forums-c9733ad7195995a9f28ecbbc8aa3e94a05527114.tar.xz
forums-c9733ad7195995a9f28ecbbc8aa3e94a05527114.zip
[ticket/10532] Fix $start out of range for pre-made searches
PHPBB3-10532
Diffstat (limited to 'phpBB/search.php')
-rw-r--r--phpBB/search.php37
1 files changed, 22 insertions, 15 deletions
diff --git a/phpBB/search.php b/phpBB/search.php
index 2aa61401cf..07be438ab4 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -471,26 +471,33 @@ if ($keywords || $author || $author_id || $search_id || $submit)
if ($search_id)
{
- if ($sql)
+ if ($sql || $search_id == 'unreadposts')
{
- // only return up to 1000 ids (the last one will be removed later)
- $result = $db->sql_query_limit($sql, 1001 - $start, $start);
+ if ($sql)
+ {
+ // 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))
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $id_ary[] = (int) $row[$field];
+ }
+ $db->sql_freeresult($result);
+ }
+ else if ($search_id == 'unreadposts')
{
- $id_ary[] = (int) $row[$field];
+ $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;
- $id_ary = array_slice($id_ary, 0, $per_page);
- }
- else if ($search_id == 'unreadposts')
- {
- $id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $start, $start));
-
- $total_match_count = sizeof($id_ary) + $start;
- $id_ary = array_slice($id_ary, 0, $per_page);
+ if ($total_match_count = sizeof($id_ary))
+ {
+ // Make sure $start is set to the last page if it exceeds the amount
+ if ($start < 0 || $start >= $total_match_count)
+ {
+ $start = ($start < 0) ? 0 : floor(($total_match_count - 1) / $per_page) * $per_page;
+ }
+ $id_ary = array_slice($id_ary, $start, $per_page);
+ }
}
else
{