From baf51dd5fd4cf054c9ef27627e345c4a1cb4f520 Mon Sep 17 00:00:00 2001 From: PayBas Date: Sun, 6 Apr 2014 22:05:25 +0200 Subject: [PATCH 1/6] [ticket/12366] Add Event core.search_get_posts_data PHPBB3-12366 --- phpBB/search.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/phpBB/search.php b/phpBB/search.php index dfb53c6896..2dc65a194d 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -635,11 +635,26 @@ if ($keywords || $author || $author_id || $search_id || $submit) } $db->sql_freeresult($result); - $sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour - FROM ' . POSTS_TABLE . ' p + $sql_from = POSTS_TABLE . ' p LEFT JOIN ' . TOPICS_TABLE . ' t ON (p.topic_id = t.topic_id) LEFT JOIN ' . FORUMS_TABLE . ' f ON (p.forum_id = f.forum_id) - LEFT JOIN ' . USERS_TABLE . " u ON (p.poster_id = u.user_id) + LEFT JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id) '; + $sql_select = 'p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour'; + + /** + * Event to modify the SQL query before the posts data is retrieved + * + * @event core.search_get_posts_data + * @var string sql_select The SQL SELECT string used by search to get posts data + * @var string sql_from The SQL FROM string used by search to get posts data + * @var string sql_where The SQL WHERE string used by search to get posts data + * @since 3.1.0-b3 + */ + $vars = array('sql_select', 'sql_from', 'sql_where'); + extract($phpbb_dispatcher->trigger_event('core.search_get_posts_data', compact($vars))); + + $sql = "SELECT $sql_select + FROM $sql_from WHERE $sql_where"; } else From 03e081df26daed6c5e93594a80eec31fe1debb91 Mon Sep 17 00:00:00 2001 From: PayBas Date: Sun, 6 Apr 2014 23:25:17 +0200 Subject: [PATCH 2/6] [ticket/12366] Changed to sql_build_query PHPBB3-12366 --- phpBB/search.php | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/phpBB/search.php b/phpBB/search.php index 2dc65a194d..3314328b62 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -635,27 +635,39 @@ if ($keywords || $author || $author_id || $search_id || $submit) } $db->sql_freeresult($result); - $sql_from = POSTS_TABLE . ' p - LEFT JOIN ' . TOPICS_TABLE . ' t ON (p.topic_id = t.topic_id) - LEFT JOIN ' . FORUMS_TABLE . ' f ON (p.forum_id = f.forum_id) - LEFT JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id) '; - $sql_select = 'p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour'; + $sql_array = array( + 'SELECT' => 'p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour', + 'FROM' => array( + POSTS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't'), + 'ON' => 'p.topic_id = t.topic_id', + ), + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'p.forum_id = f.forum_id', + ), + array( + 'FROM' => array(USERS_TABLE => 'u'), + 'ON' => 'p.poster_id = u.user_id', + ), + ), + 'WHERE' => $sql_where, + ); /** * Event to modify the SQL query before the posts data is retrieved * * @event core.search_get_posts_data - * @var string sql_select The SQL SELECT string used by search to get posts data - * @var string sql_from The SQL FROM string used by search to get posts data - * @var string sql_where The SQL WHERE string used by search to get posts data + * @var array sql_array The SQL array * @since 3.1.0-b3 */ - $vars = array('sql_select', 'sql_from', 'sql_where'); + $vars = array('sql_array'); extract($phpbb_dispatcher->trigger_event('core.search_get_posts_data', compact($vars))); - $sql = "SELECT $sql_select - FROM $sql_from - WHERE $sql_where"; + $sql = $db->sql_build_query('SELECT', $sql_array); } else { From fadbd2345676fa519a4995a203682fb1f3375011 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 7 Apr 2014 23:06:09 +0200 Subject: [PATCH 3/6] [ticket/12366] Include ORDER BY into the query builder PHPBB3-12366 --- phpBB/search.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/search.php b/phpBB/search.php index 3314328b62..0469f07840 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -655,6 +655,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) ), ), 'WHERE' => $sql_where, + 'ORDER_BY' => $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'), ); /** @@ -716,8 +717,8 @@ if ($keywords || $author || $author_id || $search_id || $submit) $sql = "SELECT $sql_select FROM $sql_from WHERE $sql_where"; + $sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); } - $sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); $result = $db->sql_query($sql); $result_topic_id = 0; From 573ec0dbe9a1ed9c4b17cfe910b3cd017dbeb63b Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 14 Apr 2014 21:44:46 +0200 Subject: [PATCH 4/6] [ticket/12366] Expanded event vars PHPBB3-12366 --- phpBB/search.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/phpBB/search.php b/phpBB/search.php index 0469f07840..d32183b80d 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -663,9 +663,21 @@ if ($keywords || $author || $author_id || $search_id || $submit) * * @event core.search_get_posts_data * @var array sql_array The SQL array + * @var array zebra Array of zebra data for the current user + * @var int total_match_count The total number of search matches + * @var string keywords String of the specified keywords + * @var array sort_by_sql Array of SQL sorting instructions + * @var string s_sort_dir The sort direction + * @var string s_sort_key The sort key + * @var string s_limit_days Limit the age of results + * @var array ex_fid_ary Array of excluded forum ids + * @var array author_id_ary Array of exclusive author ids + * @var string search_fields The data fields to search in + * @var int search_id The id of the search request + * @var int start The starting id of the results * @since 3.1.0-b3 */ - $vars = array('sql_array'); + $vars = array('sql_array', 'zebra', 'total_match_count', 'keywords', 'sort_by_sql', 's_sort_dir', 's_sort_key', 's_limit_days', 'ex_fid_ary', 'author_id_ary', 'search_fields', 'search_id', 'start'); extract($phpbb_dispatcher->trigger_event('core.search_get_posts_data', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_array); From c63f2656a80a49a6f27aa38c460420087e7fa066 Mon Sep 17 00:00:00 2001 From: PayBas Date: Fri, 2 May 2014 14:12:01 +0200 Subject: [PATCH 5/6] [ticket/12366] Conform to new event coding guidelines PHPBB3-12366 --- phpBB/search.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/phpBB/search.php b/phpBB/search.php index d32183b80d..301c29cd44 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -677,7 +677,21 @@ if ($keywords || $author || $author_id || $search_id || $submit) * @var int start The starting id of the results * @since 3.1.0-b3 */ - $vars = array('sql_array', 'zebra', 'total_match_count', 'keywords', 'sort_by_sql', 's_sort_dir', 's_sort_key', 's_limit_days', 'ex_fid_ary', 'author_id_ary', 'search_fields', 'search_id', 'start'); + $vars = array( + 'sql_array', + 'zebra', + 'total_match_count', + 'keywords', + 'sort_by_sql', + 's_sort_dir', + 's_sort_key', + 's_limit_days', + 'ex_fid_ary', + 'author_id_ary', + 'search_fields', + 'search_id', + 'start' + ); extract($phpbb_dispatcher->trigger_event('core.search_get_posts_data', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_array); From 3c936b055d3eebe2555534f77f838c92c461861f Mon Sep 17 00:00:00 2001 From: PayBas Date: Fri, 2 May 2014 17:01:59 +0200 Subject: [PATCH 6/6] [ticket/12366] Fixed missing comma PHPBB3-12366 --- phpBB/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/search.php b/phpBB/search.php index 301c29cd44..7583cd9e10 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -690,7 +690,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'author_id_ary', 'search_fields', 'search_id', - 'start' + 'start', ); extract($phpbb_dispatcher->trigger_event('core.search_get_posts_data', compact($vars)));