diff options
Diffstat (limited to 'phpBB/phpbb/textformatter/s9e/utils.php')
-rw-r--r-- | phpBB/phpbb/textformatter/s9e/utils.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index e21dedecc4..fe33c04da3 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -35,6 +35,43 @@ class utils implements \phpbb\textformatter\utils_interface } /** + * 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 * * @param string $xml Parsed text |