From c003611f0535bd783b6fe06ce4529ab3e55d9e25 Mon Sep 17 00:00:00 2001 From: Richard McGirr Date: Wed, 23 Mar 2016 21:30:30 -0400 Subject: [PATCH 1/3] [ticket/14051] Replace sql array of viewforum sort topics function PHPBB3-14051 --- phpBB/viewforum.php | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 6607f24833..682aa283fc 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -274,16 +274,41 @@ if ($sort_days) { $min_post_time = time() - ($sort_days * 86400); - $sql = 'SELECT COUNT(topic_id) AS num_topics - FROM ' . TOPICS_TABLE . " - WHERE forum_id = $forum_id - AND (topic_last_post_time >= $min_post_time - OR topic_type = " . POST_ANNOUNCE . ' - OR topic_type = ' . POST_GLOBAL . ') - AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id); - $result = $db->sql_query($sql); - $topics_count = (int) $db->sql_fetchfield('num_topics'); - $db->sql_freeresult($result); + $sql_array = array( + 'SELECT' => 'COUNT(t.topic_id) AS num_topics', + 'FROM' => array( + TOPICS_TABLE => 't', + ), + 'WHERE' => 't.forum_id = ' . $forum_id . ' + AND (t.topic_last_post_time >= ' . $min_post_time . ' + OR t.topic_type = ' . POST_ANNOUNCE . ' + OR t.topic_type = ' . POST_GLOBAL . ') + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id), + ); + + /** + * Modify the sort data SQL query for getting additional fields if needed + * + * @event core.viewforum_modify_sort_data_sql + * @var int forum_id The forum_id whose topics are being listed + * @var int start Variable containing start for pagination + * @var array sort_days The oldest topic displayable in elapsed days + * @var array sort_key The sorting by. It is one of the first character of (in low case): + * Author, Post time, Replies, Subject, Views + * @var array sort_dir Either "a" for ascending or "d" for descending + * @var array sql_array The SQL array to get the data of all topics + * @since 3.1.9-RC1 + */ + $vars = array( + 'forum_id', + 'start', + 'sort_days', + 'sort_key', + 'sort_dir', + 'sql_array', + ); + extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_sort_data_sql', compact($vars))); + $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array)); if (isset($_POST['sort'])) { From d9ad14e4c5abcef68b7f4c271034b27768d17e2c Mon Sep 17 00:00:00 2001 From: Richard McGirr Date: Wed, 23 Mar 2016 21:46:45 -0400 Subject: [PATCH 2/3] [ticket/14051] Fix whitespace PHPBB3-14051 --- phpBB/viewforum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 682aa283fc..b3b903c96b 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -295,7 +295,7 @@ if ($sort_days) * @var array sort_days The oldest topic displayable in elapsed days * @var array sort_key The sorting by. It is one of the first character of (in low case): * Author, Post time, Replies, Subject, Views - * @var array sort_dir Either "a" for ascending or "d" for descending + * @var array sort_dir Either "a" for ascending or "d" for descending * @var array sql_array The SQL array to get the data of all topics * @since 3.1.9-RC1 */ From 78bf53587a7974ed6c5e3897bb17a231e51a661d Mon Sep 17 00:00:00 2001 From: Richard McGirr Date: Thu, 24 Mar 2016 07:01:57 -0400 Subject: [PATCH 3/3] [ticket/14051] Add table alias and fix types of property PHPBB3-14051 --- phpBB/viewforum.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index b3b903c96b..5733410bb9 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -283,7 +283,7 @@ if ($sort_days) AND (t.topic_last_post_time >= ' . $min_post_time . ' OR t.topic_type = ' . POST_ANNOUNCE . ' OR t.topic_type = ' . POST_GLOBAL . ') - AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id), + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'), ); /** @@ -292,10 +292,10 @@ if ($sort_days) * @event core.viewforum_modify_sort_data_sql * @var int forum_id The forum_id whose topics are being listed * @var int start Variable containing start for pagination - * @var array sort_days The oldest topic displayable in elapsed days - * @var array sort_key The sorting by. It is one of the first character of (in low case): + * @var int sort_days The oldest topic displayable in elapsed days + * @var string sort_key The sorting by. It is one of the first character of (in low case): * Author, Post time, Replies, Subject, Views - * @var array sort_dir Either "a" for ascending or "d" for descending + * @var string sort_dir Either "a" for ascending or "d" for descending * @var array sql_array The SQL array to get the data of all topics * @since 3.1.9-RC1 */