From 6ccffec90695becd92d1144f6cbd9ef72f0d9b51 Mon Sep 17 00:00:00 2001 From: PayBas Date: Sat, 17 May 2014 11:20:37 +0200 Subject: [PATCH 1/7] [ticket/12559] Add forum setting to limit subforum legend Squashed all commits, they were basically just typos and errors PHPBB3-12559 --- phpBB/adm/style/acp_forums.html | 5 +++ phpBB/includes/acp/acp_forums.php | 3 ++ phpBB/includes/functions_display.php | 4 +- phpBB/language/en/acp/forums.php | 2 + .../data/v310/forums_legend_limit.php | 45 +++++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html index 20bcd2e9f9..f51ce98776 100644 --- a/phpBB/adm/style/acp_forums.html +++ b/phpBB/adm/style/acp_forums.html @@ -210,6 +210,11 @@
+
+

{L_LIMIT_SUBFORUMS_EXPLAIN}
+
+
+

{L_LIST_INDEX_EXPLAIN}
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 572ae3692a..ba3901f67a 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -132,6 +132,7 @@ class acp_forums 'forum_image' => $request->variable('forum_image', ''), 'forum_style' => $request->variable('forum_style', 0), 'display_subforum_list' => $request->variable('display_subforum_list', true), + 'display_subforum_limit'=> $request->variable('display_subforum_limit', false), 'display_on_index' => $request->variable('display_on_index', true), 'forum_topics_per_page' => $request->variable('topics_per_page', 0), 'enable_indexing' => $request->variable('enable_indexing', true), @@ -454,6 +455,7 @@ class acp_forums 'forum_image' => '', 'forum_style' => 0, 'display_subforum_list' => true, + 'display_subforum_limit' => false, 'display_on_index' => true, 'forum_topics_per_page' => 0, 'enable_indexing' => true, @@ -676,6 +678,7 @@ class acp_forums 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false, 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false, 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false, + 'S_DISPLAY_SUBFORUM_LIMIT' => ($forum_data['display_subforum_limit']) ? true : false, 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false, 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false, 'S_PRUNE_SHADOW_ENABLE' => ($forum_data['enable_shadow_prune']) ? true : false, diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1ac18fd3f8..1311148e8d 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -30,6 +30,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; + $parent_subforum_limit = false; // Mark forums read? $mark_read = $request->variable('mark', ''); @@ -266,6 +267,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Direct child of current branch $parent_id = $forum_id; + $parent_subforum_limit = $row['display_subforum_limit']; $forum_rows[$forum_id] = $row; if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) @@ -278,7 +280,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } else if ($row['forum_type'] != FORUM_CAT) { - $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false; + $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index'] && !($parent_subforum_limit && $parent_id !== $row['parent_id'])) ? true : false; $subforums[$parent_id][$forum_id]['name'] = $row['forum_name']; $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; $subforums[$parent_id][$forum_id]['children'] = array(); diff --git a/phpBB/language/en/acp/forums.php b/phpBB/language/en/acp/forums.php index d92d3f8c9e..3ab152345c 100644 --- a/phpBB/language/en/acp/forums.php +++ b/phpBB/language/en/acp/forums.php @@ -129,6 +129,8 @@ $lang = array_merge($lang, array( 'GENERAL_FORUM_SETTINGS' => 'General forum settings', 'LINK' => 'Link', + 'LIMIT_SUBFORUMS' => 'Limit legend to direct child-subforums', + 'LIMIT_SUBFORUMS_EXPLAIN' => 'Limits the subforums to be displayed to subforums that are direct descendants (children) of the current forum. Disabling this will display all subforums with the “List subforums in legend” option enabled, regardless of depth.', 'LIST_INDEX' => 'List subforum in parent-forum’s legend', 'LIST_INDEX_EXPLAIN' => 'Displays this forum on the index and elsewhere as a link within the legend of its parent-forum if the parent-forum’s “List subforums in legend” option is enabled.', 'LIST_SUBFORUMS' => 'List subforums in legend', diff --git a/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php b/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php new file mode 100644 index 0000000000..9bc8ad9044 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php @@ -0,0 +1,45 @@ +db_tools->sql_column_exists($this->table_prefix . 'forums', 'display_subforum_limit'); + } + + static public function depends_on() + { + return array('\phpbb\db\migration\data\v310\beta3'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_limit' => array('BOOL', 0, 'after' => 'display_subforum_list'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_limit', + ), + ), + ); + } +} From c2997ada7aa4d8f63880ea68723266d7cedb4899 Mon Sep 17 00:00:00 2001 From: PayBas Date: Wed, 28 May 2014 23:16:38 +0200 Subject: [PATCH 2/7] [ticket/12559] Applied DeMorgan and removed unnecessary true:false PHPBB3-12559 --- phpBB/includes/functions_display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1311148e8d..73281b88a1 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -280,7 +280,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } else if ($row['forum_type'] != FORUM_CAT) { - $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index'] && !($parent_subforum_limit && $parent_id !== $row['parent_id'])) ? true : false; + $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index'] && (!$parent_subforum_limit || $parent_id == $row['parent_id'])); $subforums[$parent_id][$forum_id]['name'] = $row['forum_name']; $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; $subforums[$parent_id][$forum_id]['children'] = array(); From b14c7c351104634990c80e64f58e3e28ea5826e0 Mon Sep 17 00:00:00 2001 From: PayBas Date: Fri, 30 May 2014 16:51:16 +0200 Subject: [PATCH 3/7] [ticket/12559] Updated copyright information PHPBB3-12559 --- .../db/migration/data/v310/forums_legend_limit.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php b/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php index 9bc8ad9044..c37fc7d3df 100644 --- a/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php +++ b/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ From e2de342d3ac53909a5c78f08100152d03a58f3bf Mon Sep 17 00:00:00 2001 From: PayBas Date: Tue, 10 Feb 2015 15:02:36 +0100 Subject: [PATCH 4/7] [ticket/12559] Update migration dependencies PHPBB3-12559 --- .../db/migration/data/{v310 => v31x}/forums_legend_limit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename phpBB/phpbb/db/migration/data/{v310 => v31x}/forums_legend_limit.php (90%) diff --git a/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php b/phpBB/phpbb/db/migration/data/v31x/forums_legend_limit.php similarity index 90% rename from phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php rename to phpBB/phpbb/db/migration/data/v31x/forums_legend_limit.php index c37fc7d3df..f2024bdaf9 100644 --- a/phpBB/phpbb/db/migration/data/v310/forums_legend_limit.php +++ b/phpBB/phpbb/db/migration/data/v31x/forums_legend_limit.php @@ -11,7 +11,7 @@ * */ -namespace phpbb\db\migration\data\v310; +namespace phpbb\db\migration\data\v31x; class forums_legend_limit extends \phpbb\db\migration\migration { @@ -22,7 +22,7 @@ class forums_legend_limit extends \phpbb\db\migration\migration static public function depends_on() { - return array('\phpbb\db\migration\data\v310\beta3'); + return array('\phpbb\db\migration\data\v31x\v313'); } public function update_schema() From 729e2f5d0865d843e804d1a97205df1e5f273bbd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 1 Nov 2019 16:52:02 +0100 Subject: [PATCH 5/7] [ticket/12559] Move migration to v330 folder PHPBB3-12559 --- .../db/migration/data/{v31x => v330}/forums_legend_limit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename phpBB/phpbb/db/migration/data/{v31x => v330}/forums_legend_limit.php (90%) diff --git a/phpBB/phpbb/db/migration/data/v31x/forums_legend_limit.php b/phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php similarity index 90% rename from phpBB/phpbb/db/migration/data/v31x/forums_legend_limit.php rename to phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php index f2024bdaf9..45b6547ede 100644 --- a/phpBB/phpbb/db/migration/data/v31x/forums_legend_limit.php +++ b/phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php @@ -11,7 +11,7 @@ * */ -namespace phpbb\db\migration\data\v31x; +namespace phpbb\db\migration\data\v330; class forums_legend_limit extends \phpbb\db\migration\migration { @@ -22,7 +22,7 @@ class forums_legend_limit extends \phpbb\db\migration\migration static public function depends_on() { - return array('\phpbb\db\migration\data\v31x\v313'); + return array('\phpbb\db\migration\data\v330\v330b1'); } public function update_schema() From 7df08fe12ef25bf3e5feba9aeb0cdface6411227 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 1 Nov 2019 18:12:38 +0100 Subject: [PATCH 6/7] [ticket/12559] Add functional test for limiting subforums in legend PHPBB3-12559 --- tests/functional/subforum_test.php | 113 +++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/functional/subforum_test.php diff --git a/tests/functional/subforum_test.php b/tests/functional/subforum_test.php new file mode 100644 index 0000000000..6686e347c5 --- /dev/null +++ b/tests/functional/subforum_test.php @@ -0,0 +1,113 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +/** + * @group functional + */ +class phpbb_functional_subforum_test extends phpbb_functional_test_case +{ + public function test_setup_forums() + { + $this->login(); + $this->admin_login(); + + $forum_name = 'Subforum Test #1'; + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => $forum_name, + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + $forum_id = self::get_forum_id($forum_name); + + // 'Feeds #1.1' is a sub-forum of 'Feeds #1' + $forum_name = 'Subforum Test #1.1'; + $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$forum_id}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => $forum_name, + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + $forum_id = self::get_forum_id('Subforum Test #1.1'); + + // 'Feeds #news' will be used for feed.php?mode=news + $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$forum_id}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Subforum Test #1.1.1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + } + + /** + * @depends test_setup_forums + */ + public function test_display_subforums() + { + $crawler = self::request('GET', "index.php?sid={$this->sid}"); + $this->assertContains('Subforum Test #1.1', $crawler->html()); + $this->assertContains('Subforum Test #1.1.1', $crawler->html()); + } + + /** + * @depends test_display_subforums + */ + public function test_display_subforums_limit() + { + $this->login(); + $this->admin_login(); + + // Disable listing subforums + $forum_id = $this->get_forum_id('Subforum Test #1'); + $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=7&mode=manage&parent_id=0&f={$forum_id}&action=edit"); + $form = $crawler->selectButton('submit')->form([ + 'display_subforum_limit' => 1, + ]); + self::submit($form); + + $crawler = self::request('GET', "index.php?sid={$this->sid}"); + $this->assertContains('Subforum Test #1.1', $crawler->html()); + $this->assertNotContains('Subforum Test #1.1.1', $crawler->html()); + } + + protected function get_forum_id($forum_name) + { + $this->db = $this->get_db(); + $forum_id = 0; + + $sql = 'SELECT * + FROM ' . FORUMS_TABLE . ' + WHERE ' . $this->db->sql_in_set('forum_name', $forum_name); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if ($row['forum_name'] == $forum_name) + { + $forum_id = (int) $row['forum_id']; + break; + } + } + $this->db->sql_freeresult($result); + + return $forum_id; + } +} From 85837d48b20c63f86050d0125942b25928deb1a5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Nov 2019 17:31:18 +0100 Subject: [PATCH 7/7] [ticket/12559] Use short array syntax PHPBB3-12559 --- .../data/v330/forums_legend_limit.php | 28 +++++++++---------- tests/functional/subforum_test.php | 24 ++++++++-------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php b/phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php index 45b6547ede..c5a4beef38 100644 --- a/phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php +++ b/phpBB/phpbb/db/migration/data/v330/forums_legend_limit.php @@ -22,28 +22,28 @@ class forums_legend_limit extends \phpbb\db\migration\migration static public function depends_on() { - return array('\phpbb\db\migration\data\v330\v330b1'); + return ['\phpbb\db\migration\data\v330\v330b1']; } public function update_schema() { - return array( - 'add_columns' => array( - $this->table_prefix . 'forums' => array( - 'display_subforum_limit' => array('BOOL', 0, 'after' => 'display_subforum_list'), - ), - ), - ); + return [ + 'add_columns' => [ + $this->table_prefix . 'forums' => [ + 'display_subforum_limit' => ['BOOL', 0, 'after' => 'display_subforum_list'], + ], + ], + ]; } public function revert_schema() { - return array( - 'drop_columns' => array( - $this->table_prefix . 'forums' => array( + return [ + 'drop_columns' => [ + $this->table_prefix . 'forums' => [ 'display_subforum_limit', - ), - ), - ); + ], + ], + ]; } } diff --git a/tests/functional/subforum_test.php b/tests/functional/subforum_test.php index 6686e347c5..6ce4f53c20 100644 --- a/tests/functional/subforum_test.php +++ b/tests/functional/subforum_test.php @@ -23,38 +23,38 @@ class phpbb_functional_subforum_test extends phpbb_functional_test_case $forum_name = 'Subforum Test #1'; $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); - $form = $crawler->selectButton('addforum')->form(array( + $form = $crawler->selectButton('addforum')->form([ 'forum_name' => $forum_name, - )); + ]); $crawler = self::submit($form); - $form = $crawler->selectButton('update')->form(array( + $form = $crawler->selectButton('update')->form([ 'forum_perm_from' => 2, - )); + ]); self::submit($form); $forum_id = self::get_forum_id($forum_name); // 'Feeds #1.1' is a sub-forum of 'Feeds #1' $forum_name = 'Subforum Test #1.1'; $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$forum_id}"); - $form = $crawler->selectButton('addforum')->form(array( + $form = $crawler->selectButton('addforum')->form([ 'forum_name' => $forum_name, - )); + ]); $crawler = self::submit($form); - $form = $crawler->selectButton('update')->form(array( + $form = $crawler->selectButton('update')->form([ 'forum_perm_from' => 2, - )); + ]); self::submit($form); $forum_id = self::get_forum_id('Subforum Test #1.1'); // 'Feeds #news' will be used for feed.php?mode=news $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$forum_id}"); - $form = $crawler->selectButton('addforum')->form(array( + $form = $crawler->selectButton('addforum')->form([ 'forum_name' => 'Subforum Test #1.1.1', - )); + ]); $crawler = self::submit($form); - $form = $crawler->selectButton('update')->form(array( + $form = $crawler->selectButton('update')->form([ 'forum_perm_from' => 2, - )); + ]); self::submit($form); }