From 184d24bb166b754b571bd7ef49b7cfacf1c8381d Mon Sep 17 00:00:00 2001 From: MikelAlejoBR Date: Tue, 31 Jul 2018 16:06:49 +0200 Subject: [PATCH] [ticket/15622] Extract duplicated code PHPBB3-15622 --- phpBB/includes/functions_content.php | 52 +++++++++++++++++++++++++++ phpBB/includes/ucp/ucp_pm_compose.php | 24 +------------ phpBB/posting.php | 35 ++++-------------- 3 files changed, 60 insertions(+), 51 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 40d44cfe7b..aee90aab99 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1758,3 +1758,55 @@ class bitfield $this->data = $this->data | $bitfield->get_blob(); } } + +/** + * Formats the quote according to the given BBCode status setting + * + * @param bool $bbcode_status The status of the BBCode setting + * @param array $quote_attributes The attributes of the quoted post + * @param phpbb\textformatter\utils $text_formatter_utils Text formatter utilities + * @param parse_message $message_parser Message parser class + * @param string $message_link Link of the original quoted post + * @since 3.2.4-RC1 + */ +function format_quote($bbcode_status, $quote_attributes, $text_formatter_utils, $message_parser, $message_link = '') +{ + if ($bbcode_status) + { + $quote_text = $text_formatter_utils->generate_quote( + censor_text($message_parser->message), + $quote_attributes + ); + + if($message_link) + { + $message_parser->message = $message_link . $quote_text . "\n\n"; + } + else + { + $message_parser->message = $quote_text . "\n\n"; + } + } + else + { + $offset = 0; + $quote_string = "> "; + $message = censor_text(trim($message_parser->message)); + // see if we are nesting. It's easily tricked but should work for one level of nesting + if (strpos($message, ">") !== false) + { + $offset = 10; + } + $message = utf8_wordwrap($message, 75 + $offset, "\n"); + + $message = $quote_string . $message; + $message = str_replace("\n", "\n" . $quote_string, $message); + + $message_parser->message = $quote_attributes['author'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n"; + + if($message_link) + { + $message_parser->message = $message_link . $message_parser->message; + } + } +} diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php index e108356584..48bb9bf21f 100644 --- a/phpBB/includes/ucp/ucp_pm_compose.php +++ b/phpBB/includes/ucp/ucp_pm_compose.php @@ -974,30 +974,8 @@ function compose_pm($id, $mode, $action, $user_folders = array()) { $quote_attributes['post_id'] = $post['msg_id']; } - $quote_text = $phpbb_container->get('text_formatter.utils')->generate_quote( - censor_text($message_parser->message), - $quote_attributes - ); - if ($bbcode_status) - { - $message_parser->message = $message_link . $quote_text . "\n\n"; - } - else - { - $offset = 0; - $quote_string = "> "; - $message = censor_text(trim($message_parser->message)); - // see if we are nesting. It's easily tricked but should work for one level of nesting - if (strpos($message, ">") !== false) - { - $offset = 10; - } - $message = utf8_wordwrap($message, 75 + $offset, "\n"); - $message = $quote_string . $message; - $message = str_replace("\n", "\n" . $quote_string, $message); - $message_parser->message = $quote_username . " " . $user->lang['WROTE'] . ":\n" . $message . "\n"; - } + format_quote($bbcode_status, $quote_attributes, $phpbb_container->get('text_formatter.utils'), $message_parser, $message_link); } if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh) diff --git a/phpBB/posting.php b/phpBB/posting.php index 3530bb5048..de399068bc 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1630,35 +1630,14 @@ if ($generate_quote) // Remove attachment bbcode tags from the quoted message to avoid mixing with the new post attachments if any $message_parser->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#uis', '\\2', $message_parser->message); - if ($config['allow_bbcode']) - { - $message_parser->message = $bbcode_utils->generate_quote( - censor_text($message_parser->message), - array( - 'author' => $post_data['quote_username'], - 'post_id' => $post_data['post_id'], - 'time' => $post_data['post_time'], - 'user_id' => $post_data['poster_id'], - ) - ); - $message_parser->message .= "\n\n"; - } - else - { - $offset = 0; - $quote_string = "> "; - $message = censor_text(trim($message_parser->message)); - // see if we are nesting. It's easily tricked but should work for one level of nesting - if (strpos($message, ">") !== false) - { - $offset = 10; - } - $message = utf8_wordwrap($message, 75 + $offset, "\n"); + $quote_attributes = array( + 'author' => $post_data['quote_username'], + 'post_id' => $post_data['post_id'], + 'time' => $post_data['post_time'], + 'user_id' => $post_data['poster_id'], + ); - $message = $quote_string . $message; - $message = str_replace("\n", "\n" . $quote_string, $message); - $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n"; - } + format_quote($config['allow_bbcode'], $quote_attributes, $bbcode_utils, $message_parser); } if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)