1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/15531] Log malformed BBCodes

PHPBB3-15531
This commit is contained in:
JoshyPHP
2018-01-22 03:34:47 +01:00
parent d0143bec88
commit 531d9dfa1f
6 changed files with 84 additions and 15 deletions

View File

@@ -13,6 +13,7 @@
namespace phpbb\textformatter\s9e;
use Exception;
use s9e\TextFormatter\Configurator;
use s9e\TextFormatter\Configurator\Items\AttributeFilters\RegexpFilter;
use s9e\TextFormatter\Configurator\Items\UnsafeTemplate;
@@ -131,6 +132,11 @@ class factory implements \phpbb\textformatter\cache_interface
*/
protected $dispatcher;
/**
* @var \phpbb\log\log_interface
*/
protected $log;
/**
* Constructor
*
@@ -139,11 +145,12 @@ class factory implements \phpbb\textformatter\cache_interface
* @param \phpbb\event\dispatcher_interface $dispatcher
* @param \phpbb\config\config $config
* @param \phpbb\textformatter\s9e\link_helper $link_helper
* @param \phpbb\log\log_interface $log
* @param string $cache_dir Path to the cache dir
* @param string $cache_key_parser Cache key used for the parser
* @param string $cache_key_renderer Cache key used for the renderer
*/
public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\config $config, \phpbb\textformatter\s9e\link_helper $link_helper, $cache_dir, $cache_key_parser, $cache_key_renderer)
public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\config $config, \phpbb\textformatter\s9e\link_helper $link_helper, \phpbb\log\log_interface $log, $cache_dir, $cache_key_parser, $cache_key_renderer)
{
$this->link_helper = $link_helper;
$this->cache = $cache;
@@ -153,6 +160,7 @@ class factory implements \phpbb\textformatter\cache_interface
$this->config = $config;
$this->data_access = $data_access;
$this->dispatcher = $dispatcher;
$this->log = $log;
}
/**
@@ -272,7 +280,7 @@ class factory implements \phpbb\textformatter\cache_interface
// Add default BBCodes
foreach ($this->get_default_bbcodes($configurator) as $bbcode)
{
$configurator->BBCodes->addCustom($bbcode['usage'], new UnsafeTemplate($bbcode['template']));
$this->add_bbcode($configurator, $bbcode['usage'], $bbcode['template']);
}
if (isset($configurator->tags['QUOTE']))
{
@@ -299,17 +307,7 @@ class factory implements \phpbb\textformatter\cache_interface
},
$row['bbcode_tpl']
);
try
{
$configurator->BBCodes->addCustom($row['bbcode_match'], new UnsafeTemplate($tpl));
}
catch (\Exception $e)
{
/**
* @todo log an error?
*/
}
$this->add_bbcode($configurator, $row['bbcode_match'], $tpl);
}
// Load smilies
@@ -418,6 +416,26 @@ class factory implements \phpbb\textformatter\cache_interface
return array('parser' => $parser, 'renderer' => $renderer);
}
/**
* Add a BBCode to given configurator
*
* @param Configurator $configurator
* @param string $usage
* @param string $template
* @return void
*/
protected function add_bbcode(Configurator $configurator, $usage, $template)
{
try
{
$configurator->BBCodes->addCustom($usage, new UnsafeTemplate($template));
}
catch (Exception $e)
{
$this->log->add('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]);
}
}
/**
* Configure the Autolink / Autoemail plugins used to linkify text
*