mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11768] Replaced the Censor plugin
...with something that is run at rendering time. PHPBB3-11768
This commit is contained in:
parent
6578e1c6ec
commit
f721b85a78
5 changed files with 50 additions and 37 deletions
8
phpBB/composer.lock
generated
8
phpBB/composer.lock
generated
|
@ -169,12 +169,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/s9e/TextFormatter.git",
|
||||
"reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab"
|
||||
"reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/s9e/TextFormatter/zipball/6d0fad50f73f386a45ec6fefdc8d039df93637ab",
|
||||
"reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab",
|
||||
"url": "https://api.github.com/repos/s9e/TextFormatter/zipball/0a6bfe116bf348acf209e0d50bd3b3fad86d219e",
|
||||
"reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -219,7 +219,7 @@
|
|||
"parser",
|
||||
"shortcodes"
|
||||
],
|
||||
"time": "2015-02-16 09:55:05"
|
||||
"time": "2015-02-19 04:58:59"
|
||||
},
|
||||
{
|
||||
"name": "symfony/config",
|
||||
|
|
|
@ -264,25 +264,15 @@ class factory implements \phpbb\textformatter\cache
|
|||
}
|
||||
|
||||
// Load the censored words
|
||||
foreach ($this->dal->get_words() as $row)
|
||||
$censor = $this->dal->get_words();
|
||||
if (!empty($censor))
|
||||
{
|
||||
$configurator->Censor->add($row['word'], $row['replacement']);
|
||||
}
|
||||
|
||||
if (isset($configurator->Censor))
|
||||
{
|
||||
// Replace the template with a template that applies only when $S_VIEWCENSORS is set
|
||||
$tag = $configurator->Censor->getTag();
|
||||
$tag->template =
|
||||
'<xsl:choose>
|
||||
<xsl:when test="not($S_VIEWCENSORS)">
|
||||
<xsl:value-of select="."/>
|
||||
</xsl:when>
|
||||
<xsl:when test="@with">
|
||||
<xsl:value-of select="@with"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>****</xsl:otherwise>
|
||||
</xsl:choose>';
|
||||
// Use a namespaced tag to avoid collisions
|
||||
$configurator->plugins->load('Censor', array('tagName' => 'censor:tag'));
|
||||
foreach ($censor as $row)
|
||||
{
|
||||
$configurator->Censor->add($row['word'], $row['replacement']);
|
||||
}
|
||||
}
|
||||
|
||||
// Load the magic links plugins. We do that after BBCodes so that they use the same tags
|
||||
|
@ -307,6 +297,14 @@ class factory implements \phpbb\textformatter\cache
|
|||
{
|
||||
$configurator = $this->get_configurator();
|
||||
|
||||
// Get the censor helper and remove the Censor plugin if applicable
|
||||
if (isset($configurator->Censor))
|
||||
{
|
||||
$censor = $configurator->Censor->getHelper();
|
||||
unset($configurator->Censor);
|
||||
unset($configurator->tags['censor:tag']);
|
||||
}
|
||||
|
||||
// Create $parser and $renderer
|
||||
extract($configurator->finalize());
|
||||
|
||||
|
@ -320,6 +318,10 @@ class factory implements \phpbb\textformatter\cache
|
|||
'class' => get_class($renderer),
|
||||
'renderer' => serialize($renderer)
|
||||
);
|
||||
if (isset($censor))
|
||||
{
|
||||
$renderer_data['censor'] = $censor;
|
||||
}
|
||||
$this->cache->put($this->cache_key_renderer, $renderer_data);
|
||||
|
||||
return array('parser' => $parser, 'renderer' => $renderer);
|
||||
|
|
|
@ -19,6 +19,11 @@ namespace phpbb\textformatter\s9e;
|
|||
*/
|
||||
class renderer extends \phpbb\textformatter\renderer
|
||||
{
|
||||
/**
|
||||
* @var s9e\TextFormatter\Plugins\Censor\Helper
|
||||
*/
|
||||
protected $censor;
|
||||
|
||||
/**
|
||||
* @var s9e\TextFormatter\Renderer
|
||||
*/
|
||||
|
@ -56,7 +61,6 @@ class renderer extends \phpbb\textformatter\renderer
|
|||
public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory)
|
||||
{
|
||||
$renderer_data = $cache->get($key);
|
||||
|
||||
if ($renderer_data)
|
||||
{
|
||||
$class = $renderer_data['class'];
|
||||
|
@ -76,6 +80,11 @@ class renderer extends \phpbb\textformatter\renderer
|
|||
{
|
||||
$renderer = unserialize($renderer_data['renderer']);
|
||||
}
|
||||
|
||||
if (isset($renderer_data['censor']))
|
||||
{
|
||||
$censor = $renderer_data['censor'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($renderer))
|
||||
|
@ -83,6 +92,11 @@ class renderer extends \phpbb\textformatter\renderer
|
|||
extract($factory->regenerate());
|
||||
}
|
||||
|
||||
if (isset($censor))
|
||||
{
|
||||
$this->censor = $censor;
|
||||
}
|
||||
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
|
||||
|
@ -146,6 +160,11 @@ class renderer extends \phpbb\textformatter\renderer
|
|||
{
|
||||
$html = $this->renderer->render($text);
|
||||
|
||||
if (isset($this->censor) && $this->viewcensors)
|
||||
{
|
||||
$html = $this->censor->censorHtml($html, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see bbcode::bbcode_second_pass_code()
|
||||
*/
|
||||
|
|
|
@ -138,10 +138,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
|||
'disable_bbcodes', null,
|
||||
'disablePlugin', 'BBCodes'
|
||||
),
|
||||
array(
|
||||
'disable_censor', null,
|
||||
'disablePlugin', 'Censor'
|
||||
),
|
||||
array(
|
||||
'disable_magic_url', null,
|
||||
'disablePlugin', array('Autoemail', 'Autolink')
|
||||
|
@ -158,10 +154,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
|||
'enable_bbcodes', null,
|
||||
'enablePlugin', 'BBCodes'
|
||||
),
|
||||
array(
|
||||
'enable_censor', null,
|
||||
'enablePlugin', 'Censor'
|
||||
),
|
||||
array(
|
||||
'enable_magic_url', null,
|
||||
'enablePlugin', array('Autoemail', 'Autolink')
|
||||
|
|
|
@ -93,12 +93,12 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
|||
{
|
||||
return array(
|
||||
array(
|
||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
||||
'<t>apple</t>',
|
||||
'banana',
|
||||
array('set_viewcensors' => true)
|
||||
),
|
||||
array(
|
||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
||||
'<t>apple</t>',
|
||||
'apple',
|
||||
array('set_viewcensors' => false)
|
||||
),
|
||||
|
@ -146,11 +146,11 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
|||
{
|
||||
return array(
|
||||
array(
|
||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
||||
'<t>apple</t>',
|
||||
'banana'
|
||||
),
|
||||
array(
|
||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
||||
'<t>apple</t>',
|
||||
'banana',
|
||||
function ($phpbb_container)
|
||||
{
|
||||
|
@ -161,7 +161,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
|||
}
|
||||
),
|
||||
array(
|
||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
||||
'<t>apple</t>',
|
||||
'banana',
|
||||
function ($phpbb_container)
|
||||
{
|
||||
|
@ -175,7 +175,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
|||
}
|
||||
),
|
||||
array(
|
||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
||||
'<t>apple</t>',
|
||||
'apple',
|
||||
function ($phpbb_container, $test)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue