From 1d808931f687b0307127d6f8165c9c75956c8e20 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 12 Aug 2017 17:01:34 +0700 Subject: [PATCH 1/3] [ticket/15318] Make user option to disable word censoring effective again PHPBB3-15318 --- phpBB/includes/functions_content.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index c3e7a7ceb7..06223027d8 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -557,6 +557,7 @@ function strip_bbcode(&$text, $uid = '') function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true) { static $bbcode; + global $auth, $config, $user; global $phpbb_dispatcher, $phpbb_container; if ($text === '') @@ -584,6 +585,13 @@ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text // Temporarily switch off viewcensors if applicable $old_censor = $renderer->get_viewcensors(); + + // Check here if the user is having viewing censors disabled (and also allowed to do so). + if (!$user->optionget('viewcensors') && $config['allow_nocensors'] && $auth->acl_get('u_chgcensors')) + { + $censor_text = false; + } + if ($old_censor !== $censor_text) { $renderer->set_viewcensors($censor_text); From a86cff313fd573745c96d822ce6ac0b83d01a8bb Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 12 Aug 2017 17:48:47 +0700 Subject: [PATCH 2/3] [ticket/15318] Fix tests PHPBB3-15318 --- tests/text_processing/generate_text_for_display_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php index 9c7152a008..468c902347 100644 --- a/tests/text_processing/generate_text_for_display_test.php +++ b/tests/text_processing/generate_text_for_display_test.php @@ -29,7 +29,7 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca */ public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true) { - global $cache, $user; + global $auth, $cache, $config, $user; global $phpbb_root_path, $phpEx; @@ -63,7 +63,7 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca public function test_censor_is_restored() { - global $phpbb_container; + global $auth, $user, $config, $phpbb_container; $phpbb_container = new phpbb_mock_container_builder; @@ -109,7 +109,7 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca */ public function test_text_formatter($original, $expected, $censor_text = true, $setup = null) { - global $phpbb_container; + global $auth, $user, $config, $phpbb_container; $phpbb_container = new phpbb_mock_container_builder; From de6a0a7dc1e0e52f05e7b5ced085ef8f17650ff1 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 12 Aug 2017 19:46:02 +0700 Subject: [PATCH 3/3] [ticket/15318] Add UCP censoring switch testing PHPBB3-15318 --- .../generate_text_for_display_test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php index 468c902347..86bc803c98 100644 --- a/tests/text_processing/generate_text_for_display_test.php +++ b/tests/text_processing/generate_text_for_display_test.php @@ -72,7 +72,8 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang = new \phpbb\language\language($lang_loader); $user = new \phpbb\user($lang, '\phpbb\datetime'); - $user->optionset('viewcensors', false); + // Do not ignore word censoring by user (switch censoring on in UCP) + $user->optionset('viewcensors', true); $config = new \phpbb\config\config(array('allow_nocensors' => true)); @@ -102,6 +103,14 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca $this->assertSame('apple', $renderer->render($original)); $this->assertSame('banana', generate_text_for_display($original, '', '', 0, true)); $this->assertSame('apple', $renderer->render($original), 'The original setting was not restored'); + + // Test user option switch to ignore censoring + $renderer->set_viewcensors(true); + // 1st: censoring is still on in UCP + $this->assertSame('banana', generate_text_for_display($original, '', '', 0, true)); + // 2nd: switch censoring off in UCP + $user->optionset('viewcensors', false); + $this->assertSame('apple', generate_text_for_display($original, '', '', 0, true)); } /**