1
0
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:
JoshyPHP
2015-05-17 20:15:06 +02:00
parent 6337407192
commit 8a077e0e94
5 changed files with 119 additions and 1 deletions

View File

@@ -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
*