mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/16955] Clean up textformatter and textreparser
PHPBB3-16955
This commit is contained in:
parent
60c165c3d0
commit
6ad0b533d9
8 changed files with 42 additions and 35 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -243,7 +243,8 @@ abstract class base implements reparser_interface
|
|||
// generate_text_for_edit() and decode_message() actually return the text as HTML. It has to
|
||||
// be decoded to plain text before it can be reparsed
|
||||
$text = html_entity_decode($unparsed['text'], ENT_QUOTES, 'UTF-8');
|
||||
$bitfield = $flags = null;
|
||||
$bitfield = '';
|
||||
$flags = 0;
|
||||
generate_text_for_storage(
|
||||
$text,
|
||||
$unparsed['bbcode_uid'],
|
||||
|
|
|
@ -132,9 +132,9 @@ class manager
|
|||
* If there is no reparser with the specified name, null is returned.
|
||||
*
|
||||
* @param string $name Name of the reparser to look up.
|
||||
* @return string A reparser service name, or null.
|
||||
* @return string|null A reparser service name, or null.
|
||||
*/
|
||||
public function find_reparser($name)
|
||||
public function find_reparser(string $name)
|
||||
{
|
||||
foreach ($this->reparsers as $service => $reparser)
|
||||
{
|
||||
|
|
|
@ -24,21 +24,21 @@ class user_signature extends \phpbb\textreparser\row_based_plugin
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function add_missing_fields(array $row)
|
||||
protected function add_missing_fields(array $record)
|
||||
{
|
||||
if (!isset($this->keyoptions))
|
||||
{
|
||||
$this->save_keyoptions();
|
||||
}
|
||||
|
||||
$options = $row['user_options'];
|
||||
$row += array(
|
||||
$options = $record['user_options'];
|
||||
$record += array(
|
||||
'enable_bbcode' => phpbb_optionget($this->keyoptions['sig_bbcode'], $options),
|
||||
'enable_smilies' => phpbb_optionget($this->keyoptions['sig_smilies'], $options),
|
||||
'enable_magic_url' => phpbb_optionget($this->keyoptions['sig_links'], $options),
|
||||
);
|
||||
|
||||
return parent::add_missing_fields($row);
|
||||
return parent::add_missing_fields($record);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue