aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2015-05-17 20:15:06 +0200
committerJoshyPHP <s9e.dev@gmail.com>2015-05-25 21:33:17 +0200
commit8a077e0e943d87ee1d26b0501f0b9bcc472ab904 (patch)
treefb99c7d9752338aca49c322428b5d1eab3fb2503 /phpBB
parent633740719218b72bac45bbcdff64def8da483851 (diff)
downloadforums-8a077e0e943d87ee1d26b0501f0b9bcc472ab904.tar
forums-8a077e0e943d87ee1d26b0501f0b9bcc472ab904.tar.gz
forums-8a077e0e943d87ee1d26b0501f0b9bcc472ab904.tar.bz2
forums-8a077e0e943d87ee1d26b0501f0b9bcc472ab904.tar.xz
forums-8a077e0e943d87ee1d26b0501f0b9bcc472ab904.zip
[ticket/13847] Move quote generation to text_formatter.utils
PHPBB3-13847
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/phpbb/textformatter/s9e/utils.php37
-rw-r--r--phpBB/phpbb/textformatter/utils_interface.php12
-rw-r--r--phpBB/posting.php6
3 files changed, 54 insertions, 1 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
diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php
index 6d3fd13021..41a6ba2345 100644
--- a/phpBB/phpbb/textformatter/utils_interface.php
+++ b/phpBB/phpbb/textformatter/utils_interface.php
@@ -29,6 +29,18 @@ interface utils_interface
public function clean_formatting($text);
/**
+ * Create a quote block for given text
+ *
+ * Possible attributes:
+ * - author
+ *
+ * @param string $text Quote's text
+ * @param array $attributes Quote's attributes
+ * @return string Quote block to be used in a new post/text
+ */
+ public function generate_quote($text, array $attributes = array());
+
+ /**
* Get a list of quote authors, limited to the outermost quotes
*
* @param string $text Parsed text
diff --git a/phpBB/posting.php b/phpBB/posting.php
index a4fb4d7a8d..4d52da2567 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -1597,7 +1597,11 @@ if ($generate_quote)
{
if ($config['allow_bbcode'])
{
- $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
+ $message_parser->message = $phpbb_container->get('text_formatter.utils')->generate_quote(
+ censor_text(trim($message_parser->message)),
+ array('author' => $post_data['quote_username'])
+ );
+ $message_parser->message .= "\n";
}
else
{