1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-09 02:06:32 +02:00

Merge pull request #3616 from s9e/ticket/13847

[ticket/13847] Move quote generation to text_formatter.utils
This commit is contained in:
Tristan Darricau
2015-05-29 15:42:14 +02:00
7 changed files with 172 additions and 3 deletions

View File

@@ -947,7 +947,11 @@ function compose_pm($id, $mode, $action, $user_folders = array())
{
$message_link = '';
}
$message_parser->message = $message_link . '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
$quote_text = $phpbb_container->get('text_formatter.utils')->generate_quote(
censor_text(trim($message_parser->message)),
array('author' => $quote_username)
);
$message_parser->message = $message_link . $quote_text . "\n";
}
if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh)
@@ -975,7 +979,11 @@ function compose_pm($id, $mode, $action, $user_folders = array())
$forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
$forward_text[] = sprintf($user->lang['FWD_TO'], implode($user->lang['COMMA_SEPARATOR'], $fwd_to_field['to']));
$message_parser->message = implode("\n", $forward_text) . "\n\n[quote="{$quote_username}"]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
$quote_text = $phpbb_container->get('text_formatter.utils')->generate_quote(
censor_text(trim($message_parser->message)),
array('author' => $quote_username)
);
$message_parser->message = implode("\n", $forward_text) . "\n\n" . $quote_text;
$message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ? 'Fwd: ' : '') . censor_text($message_subject);
}

View File

@@ -34,6 +34,44 @@ 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 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
*

View File

@@ -28,6 +28,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
*

View File

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