mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 14:00:31 +02:00
Merge pull request #3578 from s9e/ticket/13801
[ticket/13801] Remove user dependency from text_formatter.s9e.parser
This commit is contained in:
@@ -41,7 +41,6 @@ services:
|
||||
arguments:
|
||||
- @cache.driver
|
||||
- %text_formatter.cache.parser.key%
|
||||
- @user
|
||||
- @text_formatter.s9e.factory
|
||||
- @dispatcher
|
||||
|
||||
|
@@ -1264,6 +1264,11 @@ class parse_message extends bbcode_firstpass
|
||||
$errors = $parser->get_errors();
|
||||
if ($errors)
|
||||
{
|
||||
foreach ($errors as $i => $args)
|
||||
{
|
||||
// Translate each error with $user->lang()
|
||||
$errors[$i] = call_user_func_array(array($user, 'lang'), $args);
|
||||
}
|
||||
$this->warn_msg = array_merge($this->warn_msg, $errors);
|
||||
|
||||
return (!$update_this_message) ? $return_message : $this->warn_msg;
|
||||
|
@@ -82,7 +82,8 @@ interface parser_interface
|
||||
/**
|
||||
* Get the list of errors that were generated during last parsing
|
||||
*
|
||||
* @return array
|
||||
* @return array[] Array of arrays. Each array contains a lang string at index 0 plus any number
|
||||
* of optional parameters
|
||||
*/
|
||||
public function get_errors();
|
||||
|
||||
|
@@ -31,21 +31,15 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* @var \phpbb\user User object, used for translating errors
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\cache\driver_interface $cache
|
||||
* @param string $key Cache key
|
||||
* @param \phpbb\user $user
|
||||
* @param factory $factory
|
||||
* @param \phpbb\event\dispatcher_interface $dispatcher
|
||||
*/
|
||||
public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory, \phpbb\event\dispatcher_interface $dispatcher)
|
||||
public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, factory $factory, \phpbb\event\dispatcher_interface $dispatcher)
|
||||
{
|
||||
$parser = $cache->get($key);
|
||||
if (!$parser)
|
||||
@@ -56,24 +50,21 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->parser = $parser;
|
||||
$this->user = $user;
|
||||
$parser = $this;
|
||||
|
||||
/**
|
||||
* Configure the parser service
|
||||
*
|
||||
* Can be used to:
|
||||
* - toggle features according to the user's preferences,
|
||||
* - toggle BBCodes according to the user's permissions,
|
||||
* - register variables or custom parsers in the s9e\TextFormatter
|
||||
* - configure the s9e\TextFormatter parser
|
||||
* - toggle features or BBCodes
|
||||
* - register variables or custom parsers in the s9e\TextFormatter parser
|
||||
* - configure the s9e\TextFormatter parser's runtime settings
|
||||
*
|
||||
* @event core.text_formatter_s9e_parser_setup
|
||||
* @var \phpbb\textformatter\s9e\parser parser This parser service
|
||||
* @var \phpbb\user user Current user
|
||||
* @since 3.2.0-a1
|
||||
*/
|
||||
$vars = array('parser', 'user');
|
||||
$vars = array('parser');
|
||||
extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars)));
|
||||
}
|
||||
|
||||
@@ -196,13 +187,12 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* This will translate the log entries found in s9e\TextFormatter's logger into phpBB error
|
||||
* This will convert the log entries found in s9e\TextFormatter's logger into phpBB error
|
||||
* messages
|
||||
*/
|
||||
public function get_errors()
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
foreach ($this->parser->getLogger()->get() as $entry)
|
||||
{
|
||||
list($type, $msg, $context) = $entry;
|
||||
@@ -211,29 +201,29 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
{
|
||||
if ($context['tagName'] === 'E')
|
||||
{
|
||||
$errors[] = $this->user->lang('TOO_MANY_SMILIES', $context['tagLimit']);
|
||||
$errors[] = array('TOO_MANY_SMILIES', $context['tagLimit']);
|
||||
}
|
||||
else if ($context['tagName'] === 'URL')
|
||||
{
|
||||
$errors[] = $this->user->lang('TOO_MANY_URLS', $context['tagLimit']);
|
||||
$errors[] = array('TOO_MANY_URLS', $context['tagLimit']);
|
||||
}
|
||||
}
|
||||
else if ($msg === 'MAX_FONT_SIZE_EXCEEDED')
|
||||
{
|
||||
$errors[] = $this->user->lang($msg, $context['max_size']);
|
||||
$errors[] = array($msg, $context['max_size']);
|
||||
}
|
||||
else if (preg_match('/^MAX_(?:FLASH|IMG)_(HEIGHT|WIDTH)_EXCEEDED$/D', $msg, $m))
|
||||
{
|
||||
$errors[] = $this->user->lang($msg, $context['max_' . strtolower($m[1])]);
|
||||
$errors[] = array($msg, $context['max_' . strtolower($m[1])]);
|
||||
}
|
||||
else if ($msg === 'Tag is disabled')
|
||||
{
|
||||
$name = strtolower($context['tag']->getName());
|
||||
$errors[] = $this->user->lang('UNAUTHORISED_BBCODE', '[' . $name . ']');
|
||||
$errors[] = array('UNAUTHORISED_BBCODE', '[' . $name . ']');
|
||||
}
|
||||
else if ($msg === 'UNABLE_GET_IMAGE_SIZE')
|
||||
{
|
||||
$errors[] = $this->user->lang($msg);
|
||||
$errors[] = array($msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user