diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 3869abd689..076fd4dc04 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -499,7 +499,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/includes/functions_content.php b/phpBB/includes/functions_content.php index 2763fbce6c..40d44cfe7b 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); diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php index eda774491c..eaeb529918 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); } diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 3f2e0ab8cb..b3616a3063 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -521,7 +521,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) diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index f92b04a6d2..46835676f8 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 %}