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": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/s9e/TextFormatter.git",
|
"url": "https://github.com/s9e/TextFormatter.git",
|
||||||
"reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab"
|
"reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/s9e/TextFormatter/zipball/6d0fad50f73f386a45ec6fefdc8d039df93637ab",
|
"url": "https://api.github.com/repos/s9e/TextFormatter/zipball/0a6bfe116bf348acf209e0d50bd3b3fad86d219e",
|
||||||
"reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab",
|
"reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -219,7 +219,7 @@
|
||||||
"parser",
|
"parser",
|
||||||
"shortcodes"
|
"shortcodes"
|
||||||
],
|
],
|
||||||
"time": "2015-02-16 09:55:05"
|
"time": "2015-02-19 04:58:59"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/config",
|
"name": "symfony/config",
|
||||||
|
|
|
@ -264,25 +264,15 @@ class factory implements \phpbb\textformatter\cache
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the censored words
|
// 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']);
|
// Use a namespaced tag to avoid collisions
|
||||||
}
|
$configurator->plugins->load('Censor', array('tagName' => 'censor:tag'));
|
||||||
|
foreach ($censor as $row)
|
||||||
if (isset($configurator->Censor))
|
{
|
||||||
{
|
$configurator->Censor->add($row['word'], $row['replacement']);
|
||||||
// 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>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the magic links plugins. We do that after BBCodes so that they use the same tags
|
// 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();
|
$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
|
// Create $parser and $renderer
|
||||||
extract($configurator->finalize());
|
extract($configurator->finalize());
|
||||||
|
|
||||||
|
@ -320,6 +318,10 @@ class factory implements \phpbb\textformatter\cache
|
||||||
'class' => get_class($renderer),
|
'class' => get_class($renderer),
|
||||||
'renderer' => serialize($renderer)
|
'renderer' => serialize($renderer)
|
||||||
);
|
);
|
||||||
|
if (isset($censor))
|
||||||
|
{
|
||||||
|
$renderer_data['censor'] = $censor;
|
||||||
|
}
|
||||||
$this->cache->put($this->cache_key_renderer, $renderer_data);
|
$this->cache->put($this->cache_key_renderer, $renderer_data);
|
||||||
|
|
||||||
return array('parser' => $parser, 'renderer' => $renderer);
|
return array('parser' => $parser, 'renderer' => $renderer);
|
||||||
|
|
|
@ -19,6 +19,11 @@ namespace phpbb\textformatter\s9e;
|
||||||
*/
|
*/
|
||||||
class renderer extends \phpbb\textformatter\renderer
|
class renderer extends \phpbb\textformatter\renderer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var s9e\TextFormatter\Plugins\Censor\Helper
|
||||||
|
*/
|
||||||
|
protected $censor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var s9e\TextFormatter\Renderer
|
* @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)
|
public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory)
|
||||||
{
|
{
|
||||||
$renderer_data = $cache->get($key);
|
$renderer_data = $cache->get($key);
|
||||||
|
|
||||||
if ($renderer_data)
|
if ($renderer_data)
|
||||||
{
|
{
|
||||||
$class = $renderer_data['class'];
|
$class = $renderer_data['class'];
|
||||||
|
@ -76,6 +80,11 @@ class renderer extends \phpbb\textformatter\renderer
|
||||||
{
|
{
|
||||||
$renderer = unserialize($renderer_data['renderer']);
|
$renderer = unserialize($renderer_data['renderer']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($renderer_data['censor']))
|
||||||
|
{
|
||||||
|
$censor = $renderer_data['censor'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($renderer))
|
if (!isset($renderer))
|
||||||
|
@ -83,6 +92,11 @@ class renderer extends \phpbb\textformatter\renderer
|
||||||
extract($factory->regenerate());
|
extract($factory->regenerate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($censor))
|
||||||
|
{
|
||||||
|
$this->censor = $censor;
|
||||||
|
}
|
||||||
|
|
||||||
$this->renderer = $renderer;
|
$this->renderer = $renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +160,11 @@ class renderer extends \phpbb\textformatter\renderer
|
||||||
{
|
{
|
||||||
$html = $this->renderer->render($text);
|
$html = $this->renderer->render($text);
|
||||||
|
|
||||||
|
if (isset($this->censor) && $this->viewcensors)
|
||||||
|
{
|
||||||
|
$html = $this->censor->censorHtml($html, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see bbcode::bbcode_second_pass_code()
|
* @see bbcode::bbcode_second_pass_code()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -138,10 +138,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
'disable_bbcodes', null,
|
'disable_bbcodes', null,
|
||||||
'disablePlugin', 'BBCodes'
|
'disablePlugin', 'BBCodes'
|
||||||
),
|
),
|
||||||
array(
|
|
||||||
'disable_censor', null,
|
|
||||||
'disablePlugin', 'Censor'
|
|
||||||
),
|
|
||||||
array(
|
array(
|
||||||
'disable_magic_url', null,
|
'disable_magic_url', null,
|
||||||
'disablePlugin', array('Autoemail', 'Autolink')
|
'disablePlugin', array('Autoemail', 'Autolink')
|
||||||
|
@ -158,10 +154,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
'enable_bbcodes', null,
|
'enable_bbcodes', null,
|
||||||
'enablePlugin', 'BBCodes'
|
'enablePlugin', 'BBCodes'
|
||||||
),
|
),
|
||||||
array(
|
|
||||||
'enable_censor', null,
|
|
||||||
'enablePlugin', 'Censor'
|
|
||||||
),
|
|
||||||
array(
|
array(
|
||||||
'enable_magic_url', null,
|
'enable_magic_url', null,
|
||||||
'enablePlugin', array('Autoemail', 'Autolink')
|
'enablePlugin', array('Autoemail', 'Autolink')
|
||||||
|
|
|
@ -93,12 +93,12 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
'<t>apple</t>',
|
||||||
'banana',
|
'banana',
|
||||||
array('set_viewcensors' => true)
|
array('set_viewcensors' => true)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
'<t>apple</t>',
|
||||||
'apple',
|
'apple',
|
||||||
array('set_viewcensors' => false)
|
array('set_viewcensors' => false)
|
||||||
),
|
),
|
||||||
|
@ -146,11 +146,11 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
'<t>apple</t>',
|
||||||
'banana'
|
'banana'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
'<t>apple</t>',
|
||||||
'banana',
|
'banana',
|
||||||
function ($phpbb_container)
|
function ($phpbb_container)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
'<t>apple</t>',
|
||||||
'banana',
|
'banana',
|
||||||
function ($phpbb_container)
|
function ($phpbb_container)
|
||||||
{
|
{
|
||||||
|
@ -175,7 +175,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'<r><CENSOR with="banana">apple</CENSOR></r>',
|
'<t>apple</t>',
|
||||||
'apple',
|
'apple',
|
||||||
function ($phpbb_container, $test)
|
function ($phpbb_container, $test)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue