From 1d808931f687b0307127d6f8165c9c75956c8e20 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 12 Aug 2017 17:01:34 +0700 Subject: [PATCH 1/7] [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/7] [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/7] [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)); } /** From a6c9119dfa1cf812292fffe1131f3b9f3bfebfc7 Mon Sep 17 00:00:00 2001 From: Jagoba Los Arcos Date: Sun, 13 Aug 2017 22:49:24 +0200 Subject: [PATCH 4/7] [ticket/15320] Redis cache does not save keys withouth expiration In some functions like sql_save in cache/memory.php, code try to save a key/value in cache with ttl = 0 so key should never expire. In current redis.php cache driver, it fails so key never get cached. This cause for example that when you create a subforum, it not appear in the forum box in the admincp. To solve, if ttl is 0, we use redis->set instead of setex --- phpBB/phpbb/cache/driver/redis.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php index eda774491c..8c9cd933a5 100644 --- a/phpBB/phpbb/cache/driver/redis.php +++ b/phpBB/phpbb/cache/driver/redis.php @@ -137,6 +137,10 @@ class redis extends \phpbb\cache\driver\memory */ function _write($var, $data, $ttl = 2592000) { + if($ttl == 0) + { + return $this->redis->set($var, $data); + } return $this->redis->setex($var, $ttl, $data); } From 4e5fd9a6e925487fe424538f4a2e6905f00da43d Mon Sep 17 00:00:00 2001 From: Jagoba Los Arcos Date: Mon, 14 Aug 2017 13:00:54 +0200 Subject: [PATCH 5/7] [ticket/15320] Fix to accomplish coding guidelines --- phpBB/phpbb/cache/driver/redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php index 8c9cd933a5..eaeb529918 100644 --- a/phpBB/phpbb/cache/driver/redis.php +++ b/phpBB/phpbb/cache/driver/redis.php @@ -137,7 +137,7 @@ class redis extends \phpbb\cache\driver\memory */ function _write($var, $data, $ttl = 2592000) { - if($ttl == 0) + if ($ttl == 0) { return $this->redis->set($var, $data); } From aabb9d2e488e465d48d9910f98a861ab96f55f74 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 15 Aug 2017 15:41:56 +0700 Subject: [PATCH 6/7] [ticket/15323] Allow Twig syntax in bbcode.html PHPBB3-15323 --- phpBB/includes/bbcode.php | 5 ++++- phpBB/phpbb/textformatter/s9e/factory.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index e8492a82a3..6572c0ad2c 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -501,7 +501,10 @@ class bbcode // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl.. $this->bbcode_template = array(); - $matches = preg_match_all('#(.*?)#', $tpl, $match); + // Capture the BBCode template matches + // Allow phpBB template or the Twig syntax + $matches = (preg_match_all('#(.*?)#', $tpl, $match)) ?: + preg_match_all('#{% for (.*?) in .*? %}(.*?){% endfor %}#s', $tpl, $match); for ($i = 0; $i < $matches; $i++) { diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 7719ce5afa..13bfc7b5e9 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -518,7 +518,9 @@ class factory implements \phpbb\textformatter\cache_interface protected function extract_templates($template) { // Capture the template fragments - preg_match_all('#(.*?)#s', $template, $matches, PREG_SET_ORDER); + // Allow either phpBB template or the Twig syntax + preg_match_all('#(.*?)#s', $template, $matches, PREG_SET_ORDER) ?: + preg_match_all('#{% for (.*?) in .*? %}(.*?){% endfor %}#s', $template, $matches, PREG_SET_ORDER); $fragments = array(); foreach ($matches as $match) From e67d2ae3b9d71bfd9aa82ec250c13d1186b1e280 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 15 Aug 2017 16:57:30 +0700 Subject: [PATCH 7/7] [ticket/15323] Run s9e configurator tests on twigified bbcode.html PHPBB3-15323 --- tests/text_formatter/s9e/factory_test.php | 25 +++++-- .../styles/prosilver/template/bbcode.html | 75 +++++++++++++++++++ 2 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 tests/text_formatter/s9e/fixtures/styles/prosilver/template/bbcode.html diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 3d3ea8b794..82b1b0043b 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -32,9 +32,15 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case return __DIR__ . '/../../tmp/'; } - public function get_factory() + public function get_factory($styles_path = null) { global $config, $phpbb_root_path, $request, $user; + + if (!isset($styles_path)) + { + $styles_path = $phpbb_root_path . 'styles/'; + } + $this->cache = new phpbb_mock_cache; $dal = new \phpbb\textformatter\data_access( $this->new_dbal(), @@ -42,7 +48,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case 'phpbb_smilies', 'phpbb_styles', 'phpbb_words', - $phpbb_root_path . 'styles/' + $styles_path ); $factory = new \phpbb\textformatter\s9e\factory( $dal, @@ -68,10 +74,8 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case return $factory; } - public function test_get_configurator() + public function run_configurator_assertions($configurator) { - $configurator = $this->get_factory()->get_configurator(); - $this->assertInstanceOf('s9e\\TextFormatter\\Configurator', $configurator); $this->assertTrue(isset($configurator->plugins['Autoemail'])); @@ -97,6 +101,17 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $this->assertTrue(isset($configurator->Emoticons[':D'])); } + public function test_get_configurator() + { + $configurator = $this->get_factory()->get_configurator(); + $this->run_configurator_assertions($configurator); + + // Test with twigified bbcode.html + $configurator = $this->get_factory(__DIR__ . '/fixtures/styles/')->get_configurator(); + $this->run_configurator_assertions($configurator); + + } + public function test_regenerate() { extract($this->get_factory()->regenerate()); diff --git a/tests/text_formatter/s9e/fixtures/styles/prosilver/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/prosilver/template/bbcode.html new file mode 100644 index 0000000000..22be395499 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/prosilver/template/bbcode.html @@ -0,0 +1,75 @@ +{% for ulist_open in loops.ulist_open %}
    {% endfor %} +{% for ulist_open_default in loops.ulist_open_default %}
      {% endfor %} +{% for ulist_close in loops.ulist_close %}
    {% endfor %} + +{% for olist_open in loops.olist_open %}
      {% endfor %} +{% for olist_close in loops.olist_close %}
    {% endfor %} + +{% for listitem in loops.listitem %}
  • {% endfor %} +{% for listitem_close in loops.listitem_close %}
  • {% endfor %} + +{% for quote_username_open in loops.quote_username_open %}
    {{ USERNAME }} {{ lang('WROTE') }}{{ lang('COLON') }}{% endfor %} +{% for quote_open in loops.quote_open %}
    {% endfor %} +{% for quote_close in loops.quote_close %}
    {% endfor %} +{% for quote_extended in loops.quote_extended %} +
    + + uncited + +
    + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    +
    +{% endfor %} + +{% for code_open in loops.code_open %}

    {{ lang('CODE') }}{{ lang('COLON') }} {{ lang('SELECT_ALL_CODE') }}

    {% endfor %}
    +{% for code_close in loops.code_close %}
    {% endfor %} + +{% for inline_attachment_open in loops.inline_attachment_open %}
    {% endfor %} +{% for inline_attachment_close in loops.inline_attachment_close %}
    {% endfor %} + +{% for b_open in loops.b_open %}{% endfor %} +{% for b_close in loops.b_close %}{% endfor %} + +{% for u_open in loops.u_open %}{% endfor %} +{% for u_close in loops.u_close %}{% endfor %} + +{% for i_open in loops.i_open %}{% endfor %} +{% for i_close in loops.i_close %}{% endfor %} + +{% for color in loops.color %}{{ TEXT }}{% endfor %} + +{% for size in loops.size %}{{ TEXT }}{% endfor %} + +{% for img in loops.img %}{{ lang('IMAGE') }}{% endfor %} + +{% for url in loops.url %}{{ DESCRIPTION }}{% endfor %} + +{% for email in loops.email %}{{ DESCRIPTION }}{% endfor %} + +{% for flash in loops.flash %}{% endfor %}