mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[ticket/13847] Move quote generation to text_formatter.utils
PHPBB3-13847
This commit is contained in:
@@ -34,6 +34,43 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||
return \s9e\TextFormatter\Utils::removeFormatting($xml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return given string between quotes
|
||||
*
|
||||
* Will use either single- or double- quotes depending on whichever requires to be escaped.
|
||||
* Quotes and backslashes are escaped with backslashes where necessary
|
||||
*
|
||||
* @param string $str Original string
|
||||
* @return string Escaped string within quotes
|
||||
*/
|
||||
protected function enquote($str)
|
||||
{
|
||||
$quote = (strpos($str, '"') === false || strpos($str, "'") !== false) ? '"' : "'";
|
||||
|
||||
return $quote . addcslashes($str, '\\' . $quote) . $quote;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate_quote($text, array $attributes = array())
|
||||
{
|
||||
$quote = '[quote';
|
||||
if (isset($attributes['author']))
|
||||
{
|
||||
// Add the author as the BBCode's default attribute
|
||||
$quote .= '=' . $this->enquote($attributes['author']);
|
||||
unset($attributes['author']);
|
||||
}
|
||||
foreach ($attributes as $name => $value)
|
||||
{
|
||||
$quote .= ' ' . $name . '=' . $this->enquote($value);
|
||||
}
|
||||
$quote .= ']' . $text . '[/quote]';
|
||||
|
||||
return $quote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of quote authors, limited to the outermost quotes
|
||||
*
|
||||
|
Reference in New Issue
Block a user