mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[ticket/16955] Clean up textformatter and textreparser
PHPBB3-16955
This commit is contained in:
@@ -37,8 +37,8 @@ class bbcode_merger
|
||||
*
|
||||
* All of the arrays contain a "usage" element and a "template" element
|
||||
*
|
||||
* @throws InvalidArgumentException if a definition cannot be interpreted
|
||||
* @throws RuntimeException if something unexpected occurs
|
||||
* @throws \InvalidArgumentException if a definition cannot be interpreted
|
||||
* @throws \RuntimeException if something unexpected occurs
|
||||
*
|
||||
* @param array $without BBCode definition without an attribute
|
||||
* @param array $with BBCode definition with an attribute
|
||||
|
@@ -226,8 +226,9 @@ class factory implements \phpbb\textformatter\cache_interface
|
||||
* @event core.text_formatter_s9e_configure_before
|
||||
* @var Configurator configurator Configurator instance
|
||||
* @since 3.2.0-a1
|
||||
* @psalm-ignore-var
|
||||
*/
|
||||
$vars = array('configurator');
|
||||
$vars = ['configurator'];
|
||||
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_before', compact($vars)));
|
||||
|
||||
// Reset the list of allowed schemes
|
||||
@@ -375,8 +376,9 @@ class factory implements \phpbb\textformatter\cache_interface
|
||||
* @event core.text_formatter_s9e_configure_after
|
||||
* @var Configurator configurator Configurator instance
|
||||
* @since 3.2.0-a1
|
||||
* @psalm-ignore-var
|
||||
*/
|
||||
$vars = array('configurator');
|
||||
$vars = ['configurator'];
|
||||
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_after', compact($vars)));
|
||||
|
||||
return $configurator;
|
||||
@@ -444,7 +446,7 @@ class factory implements \phpbb\textformatter\cache_interface
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->log->add('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]);
|
||||
$this->log->add('critical', ANONYMOUS, '', 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -65,8 +65,9 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
* @event core.text_formatter_s9e_parser_setup
|
||||
* @var \phpbb\textformatter\s9e\parser parser This parser service
|
||||
* @since 3.2.0-a1
|
||||
* @psalm-ignore-var
|
||||
*/
|
||||
$vars = array('parser');
|
||||
$vars = ['parser'];
|
||||
extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars)));
|
||||
}
|
||||
|
||||
|
@@ -117,8 +117,9 @@ class renderer implements \phpbb\textformatter\renderer_interface
|
||||
* @event core.text_formatter_s9e_renderer_setup
|
||||
* @var \phpbb\textformatter\s9e\renderer renderer This renderer service
|
||||
* @since 3.2.0-a1
|
||||
* @psalm-ignore-var
|
||||
*/
|
||||
$vars = array('renderer');
|
||||
$vars = ['renderer'];
|
||||
extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars)));
|
||||
}
|
||||
|
||||
@@ -234,16 +235,16 @@ class renderer implements \phpbb\textformatter\renderer_interface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($xml)
|
||||
public function render($text)
|
||||
{
|
||||
if (isset($this->mention_helper))
|
||||
{
|
||||
$xml = $this->mention_helper->inject_metadata($xml);
|
||||
$text = $this->mention_helper->inject_metadata($text);
|
||||
}
|
||||
|
||||
if (isset($this->quote_helper))
|
||||
{
|
||||
$xml = $this->quote_helper->inject_metadata($xml);
|
||||
$text = $this->quote_helper->inject_metadata($text);
|
||||
}
|
||||
|
||||
$renderer = $this;
|
||||
@@ -253,13 +254,14 @@ class renderer implements \phpbb\textformatter\renderer_interface
|
||||
*
|
||||
* @event core.text_formatter_s9e_render_before
|
||||
* @var \phpbb\textformatter\s9e\renderer renderer This renderer service
|
||||
* @var string xml The parsed text, in its XML form
|
||||
* @var string text The parsed text, in its XML form
|
||||
* @since 3.2.0-a1
|
||||
* @psalm-ignore-var
|
||||
*/
|
||||
$vars = array('renderer', 'xml');
|
||||
$vars = ['renderer', 'text'];
|
||||
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_before', compact($vars)));
|
||||
|
||||
$html = $this->renderer->render($xml);
|
||||
$html = $this->renderer->render($text);
|
||||
if (isset($this->censor) && $this->viewcensors)
|
||||
{
|
||||
$html = $this->censor->censorHtml($html, true);
|
||||
@@ -272,8 +274,9 @@ class renderer implements \phpbb\textformatter\renderer_interface
|
||||
* @var string html The rendered text's HTML
|
||||
* @var \phpbb\textformatter\s9e\renderer renderer This renderer service
|
||||
* @since 3.2.0-a1
|
||||
* @psalm-ignore-var
|
||||
*/
|
||||
$vars = array('html', 'renderer');
|
||||
$vars = ['html', 'renderer'];
|
||||
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_after', compact($vars)));
|
||||
|
||||
return $html;
|
||||
|
@@ -26,15 +26,15 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||
*
|
||||
* NOTE: preserves smilies as text
|
||||
*
|
||||
* @param string $xml Parsed text
|
||||
* @param string $text Parsed text
|
||||
* @return string Plain text
|
||||
*/
|
||||
public function clean_formatting($xml)
|
||||
public function clean_formatting($text)
|
||||
{
|
||||
// Insert a space before <s> and <e> then remove formatting
|
||||
$xml = preg_replace('#<[es]>#', ' $0', $xml);
|
||||
$text = preg_replace('#<[es]>#', ' $0', $text);
|
||||
|
||||
return \s9e\TextFormatter\Utils::removeFormatting($xml);
|
||||
return \s9e\TextFormatter\Utils::removeFormatting($text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,19 +94,19 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||
/**
|
||||
* Get a list of quote authors, limited to the outermost quotes
|
||||
*
|
||||
* @param string $xml Parsed text
|
||||
* @param string $text Parsed text
|
||||
* @return string[] List of authors
|
||||
*/
|
||||
public function get_outermost_quote_authors($xml)
|
||||
public function get_outermost_quote_authors($text)
|
||||
{
|
||||
$authors = array();
|
||||
if (strpos($xml, '<QUOTE ') === false)
|
||||
if (strpos($text, '<QUOTE ') === false)
|
||||
{
|
||||
return $authors;
|
||||
}
|
||||
|
||||
$dom = new \DOMDocument;
|
||||
$dom->loadXML($xml);
|
||||
$dom->loadXML($text);
|
||||
$xpath = new \DOMXPath($dom);
|
||||
foreach ($xpath->query('//QUOTE[not(ancestor::QUOTE)]/@author') as $author)
|
||||
{
|
||||
@@ -119,25 +119,25 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||
/**
|
||||
* Remove given BBCode and its content, at given nesting depth
|
||||
*
|
||||
* @param string $xml Parsed text
|
||||
* @param string $text Parsed text
|
||||
* @param string $bbcode_name BBCode's name
|
||||
* @param integer $depth Minimum nesting depth (number of parents of the same name)
|
||||
* @return string Parsed text
|
||||
*/
|
||||
public function remove_bbcode($xml, $bbcode_name, $depth = 0)
|
||||
public function remove_bbcode($text, $bbcode_name, $depth = 0)
|
||||
{
|
||||
return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth);
|
||||
return \s9e\TextFormatter\Utils::removeTag($text, strtoupper($bbcode_name), $depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a parsed text to its original form
|
||||
*
|
||||
* @param string $xml Parsed text
|
||||
* @param string $text Parsed text
|
||||
* @return string Original plain text
|
||||
*/
|
||||
public function unparse($xml)
|
||||
public function unparse($text)
|
||||
{
|
||||
return \s9e\TextFormatter\Unparser::unparse($xml);
|
||||
return \s9e\TextFormatter\Unparser::unparse($text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user