From 09e431d318c7cf86a1fa7411e38e4cea6426c5f1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Jan 2015 20:06:13 +0100 Subject: [PATCH] [ticket/432] Simplify get_posts() method further B3P-432 --- portal/fetch_posts.php | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/portal/fetch_posts.php b/portal/fetch_posts.php index e975feb7..1ec2ad01 100644 --- a/portal/fetch_posts.php +++ b/portal/fetch_posts.php @@ -170,19 +170,9 @@ class fetch_posts $attachments = $this->get_post_attachments($row); $posts[$i]['bbcode_uid'] = $row['bbcode_uid']; - $len_check = $row['post_text']; - $maxlen = $text_length; - if (($text_length != 0) && (strlen($len_check) > $text_length)) - { - $message = str_replace(array("\n", "\r"), array('
', "\n"), $row['post_text']); - $message = get_sub_taged_string($message, $row['bbcode_uid'], $maxlen); - $posts[$i]['striped'] = true; - } - else - { - $message = str_replace("\n", '
', $row['post_text']); - } + // Format message + $message = $this->format_message($row, $text_length, $posts[$i]['striped']); $row['bbcode_options'] = $this->get_setting_based_data($row['enable_bbcode'], OPTION_FLAG_BBCODE, 0) + $this->get_setting_based_data($row['enable_smilies'], OPTION_FLAG_SMILIES, 0) + $this->get_setting_based_data($row['enable_magic_url'], OPTION_FLAG_LINKS, 0); $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']); @@ -603,4 +593,29 @@ class fetch_posts { return $this->auth->acl_get('u_download') && ($this->auth->acl_get('f_download', $forum_id) || $forum_id == 0); } + + /** + * Format message for display + * + * @param array $row Database row + * @param int $text_length Length of text + * @param bool $posts_striped Whether post is striped + * + * @return mixed|string + */ + protected function format_message($row, $text_length, &$posts_striped) + { + if (($text_length !== 0) && (strlen($row['post_text']) > $text_length)) + { + $message = str_replace(array("\n", "\r"), array('
', "\n"), $row['post_text']); + $message = get_sub_taged_string($message, $row['bbcode_uid'], $text_length); + $posts_striped = true; + } + else + { + $message = str_replace("\n", '
', $row['post_text']); + } + + return $message; + } }