diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-05-29 15:42:14 +0200 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-05-29 15:42:14 +0200 |
commit | f5dbc3b6f269cb3841c20ad0096fcedb3dac7492 (patch) | |
tree | 5ca32d171af32f236d82cbf11cedfe3735c5fa3d /phpBB/phpbb/textformatter/s9e | |
parent | 3c3b099f88471e05358fe3c01bb74caac69e89e7 (diff) | |
parent | 64e1824abdb2a9c860e049f10ecc81c051160ff5 (diff) | |
download | forums-f5dbc3b6f269cb3841c20ad0096fcedb3dac7492.tar forums-f5dbc3b6f269cb3841c20ad0096fcedb3dac7492.tar.gz forums-f5dbc3b6f269cb3841c20ad0096fcedb3dac7492.tar.bz2 forums-f5dbc3b6f269cb3841c20ad0096fcedb3dac7492.tar.xz forums-f5dbc3b6f269cb3841c20ad0096fcedb3dac7492.zip |
Merge pull request #3616 from s9e/ticket/13847
[ticket/13847] Move quote generation to text_formatter.utils
Diffstat (limited to 'phpBB/phpbb/textformatter/s9e')
-rw-r--r-- | phpBB/phpbb/textformatter/s9e/utils.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index e21dedecc4..04df589930 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -35,6 +35,44 @@ class utils implements \phpbb\textformatter\utils_interface } /** + * Return given string between quotes + * + * Will use either single- or double- quotes depending on whichever requires less escaping. + * Quotes and backslashes are escaped with backslashes where necessary + * + * @param string $str Original string + * @return string Escaped string within quotes + */ + protected function enquote($str) + { + $singleQuoted = "'" . addcslashes($str, "\\'") . "'"; + $doubleQuoted = '"' . addcslashes($str, '\\"') . '"'; + + return (strlen($singleQuoted) < strlen($doubleQuoted)) ? $singleQuoted : $doubleQuoted; + } + + /** + * {@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 |