From 6a3347221469ead07520d82225b3210f3c43dd06 Mon Sep 17 00:00:00 2001
From: blitze <dachebodt@gmail.com>
Date: Sun, 21 Sep 2014 07:39:50 +0000
Subject: [PATCH] [ticket/13071] Only use total_match_count after event
 dispatcher

PHPBB3-13071
---
 phpBB/search.php | 96 ++++++++++++++++++++++++------------------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/phpBB/search.php b/phpBB/search.php
index 93f12f4310..c20df27058 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -553,16 +553,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)
 	// Grab icons
 	$icons = $cache->obtain_icons();
 
-	// Output header
-	if ($found_more_search_matches)
-	{
-		$l_search_matches = $user->lang('FOUND_MORE_SEARCH_MATCHES', (int) $total_match_count);
-	}
-	else
-	{
-		$l_search_matches = $user->lang('FOUND_SEARCH_MATCHES', (int) $total_match_count);
-	}
-
 	// define some vars for urls
 	// A single wildcard will make the search results look ugly
 	$hilit = phpbb_clean_search_string(str_replace(array('+', '-', '|', '(', ')', '&quot;'), ' ', $keywords));
@@ -584,44 +574,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)
 	$u_search .= ($search_fields != 'all') ? '&amp;sf=' . $search_fields : '';
 	$u_search .= ($return_chars != 300) ? '&amp;ch=' . $return_chars : '';
 
-	// Check if search backend supports phrase search or not
-	$phrase_search_disabled = '';
-	if (strpos(html_entity_decode($keywords), '"') !== false && method_exists($search, 'supports_phrase_search'))
-	{
-		$phrase_search_disabled = $search->supports_phrase_search() ? false : true;
-	}
-
-	$pagination->generate_template_pagination($u_search, 'pagination', 'start', $total_match_count, $per_page, $start);
-
-	$template->assign_vars(array(
-		'SEARCH_TITLE'		=> $l_search_title,
-		'SEARCH_MATCHES'	=> $l_search_matches,
-		'SEARCH_WORDS'		=> $keywords,
-		'SEARCHED_QUERY'	=> $search->get_search_query(),
-		'IGNORED_WORDS'		=> (!empty($common_words)) ? implode(' ', $common_words) : '',
-
-		'PHRASE_SEARCH_DISABLED'		=> $phrase_search_disabled,
-
-		'TOTAL_MATCHES'		=> $total_match_count,
-		'SEARCH_IN_RESULTS'	=> ($search_id) ? false : true,
-
-		'S_SELECT_SORT_DIR'		=> $s_sort_dir,
-		'S_SELECT_SORT_KEY'		=> $s_sort_key,
-		'S_SELECT_SORT_DAYS'	=> $s_limit_days,
-		'S_SEARCH_ACTION'		=> $u_search,
-		'S_SHOW_TOPICS'			=> ($show_results == 'posts') ? false : true,
-
-		'GOTO_PAGE_IMG'		=> $user->img('icon_post_target', 'GOTO_PAGE'),
-		'NEWEST_POST_IMG'	=> $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
-		'REPORTED_IMG'		=> $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
-		'UNAPPROVED_IMG'	=> $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
-		'DELETED_IMG'		=> $user->img('icon_topic_deleted', 'TOPIC_DELETED'),
-		'POLL_IMG'			=> $user->img('icon_topic_poll', 'TOPIC_POLL'),
-		'LAST_POST_IMG'		=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
-
-		'U_SEARCH_WORDS'	=> $u_search,
-	));
-
 	if ($sql_where)
 	{
 		if ($show_results == 'posts')
@@ -1149,6 +1101,54 @@ if ($keywords || $author || $author_id || $search_id || $submit)
 	}
 	unset($rowset);
 
+	// Output header
+	if ($found_more_search_matches)
+	{
+		$l_search_matches = $user->lang('FOUND_MORE_SEARCH_MATCHES', (int) $total_match_count);
+	}
+	else
+	{
+		$l_search_matches = $user->lang('FOUND_SEARCH_MATCHES', (int) $total_match_count);
+	}
+
+	// Check if search backend supports phrase search or not
+	$phrase_search_disabled = '';
+	if (strpos(html_entity_decode($keywords), '"') !== false && method_exists($search, 'supports_phrase_search'))
+	{
+		$phrase_search_disabled = $search->supports_phrase_search() ? false : true;
+	}
+
+	$pagination->generate_template_pagination($u_search, 'pagination', 'start', $total_match_count, $per_page, $start);
+
+	$template->assign_vars(array(
+		'SEARCH_TITLE'		=> $l_search_title,
+		'SEARCH_MATCHES'	=> $l_search_matches,
+		'SEARCH_WORDS'		=> $keywords,
+		'SEARCHED_QUERY'	=> $search->get_search_query(),
+		'IGNORED_WORDS'		=> (!empty($common_words)) ? implode(' ', $common_words) : '',
+
+		'PHRASE_SEARCH_DISABLED'		=> $phrase_search_disabled,
+
+		'TOTAL_MATCHES'		=> $total_match_count,
+		'SEARCH_IN_RESULTS'	=> ($search_id) ? false : true,
+
+		'S_SELECT_SORT_DIR'		=> $s_sort_dir,
+		'S_SELECT_SORT_KEY'		=> $s_sort_key,
+		'S_SELECT_SORT_DAYS'	=> $s_limit_days,
+		'S_SEARCH_ACTION'		=> $u_search,
+		'S_SHOW_TOPICS'			=> ($show_results == 'posts') ? false : true,
+
+		'GOTO_PAGE_IMG'		=> $user->img('icon_post_target', 'GOTO_PAGE'),
+		'NEWEST_POST_IMG'	=> $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
+		'REPORTED_IMG'		=> $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
+		'UNAPPROVED_IMG'	=> $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
+		'DELETED_IMG'		=> $user->img('icon_topic_deleted', 'TOPIC_DELETED'),
+		'POLL_IMG'			=> $user->img('icon_topic_poll', 'TOPIC_POLL'),
+		'LAST_POST_IMG'		=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
+
+		'U_SEARCH_WORDS'	=> $u_search,
+	));
+
 	/**
 	* Modify the title and/or load data for the search results page
 	*