From 46f50248f01c03bb4fefd181c5e5ac594fac4774 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Thu, 16 Aug 2012 09:05:19 -0500 Subject: [PATCH 1/3] Don't require closing tag for tags that don't need it. --- inc/display.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/display.php b/inc/display.php index 264fde60..6394c711 100644 --- a/inc/display.php +++ b/inc/display.php @@ -190,9 +190,12 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { // remove broken HTML entity at the end (if existent) $body = preg_replace('/&[^;]+$/', '', $body); + $tags_no_close_needed = array("colgroup", "dd", "dt", "li", "optgroup", "option", "p", "tbody", "td", "tfoot", "th", "thead", "tr", "br", "img"); + // Close any open tags foreach ($tags as &$tag) { - $body .= ""; + if (!in_array($tag, $tags_no_close_needed)) + $body .= ""; } } else { // remove broken HTML entity at the end (if existent) From 948dfe8555e06b2f900a92678faff918c2ab95b6 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Mon, 14 Jan 2013 19:11:55 -0600 Subject: [PATCH 2/3] Don't truncate inside an HTML comment! --- inc/display.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/display.php b/inc/display.php index 6394c711..f4e1151e 100644 --- a/inc/display.php +++ b/inc/display.php @@ -155,6 +155,11 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { $max_lines = $config['body_truncate']; if ($max_chars === false) $max_chars = $config['body_truncate_char']; + + // We don't want to risk truncating in the middle of an HTML comment. + // It's easiest just to remove them all first. + $body = preg_replace('//s', '', $body); + $original_body = $body; $lines = substr_count($body, '
'); From b63d94838da090cddb98f1b7f19268a32c6a75d8 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Fri, 18 Jan 2013 18:10:14 -0600 Subject: [PATCH 3/3] Do truncation by actual character count. Using substr can cut a multi-byte character in half. Also, if a long post with many multi-byte characters was reported, then the mod interface would temporarily extend the body_truncate_char setting to be sure to cover all of the *characters* in the report, but this function would interpret body_truncate_char as a number of *bytes*, so sometimes the end of the report's appended html would be cut off. --- inc/display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/display.php b/inc/display.php index f4e1151e..85c21e7c 100644 --- a/inc/display.php +++ b/inc/display.php @@ -170,7 +170,7 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { $body = $m[0]; } - $body = substr($body, 0, $max_chars); + $body = mb_substr($body, 0, $max_chars); if ($body != $original_body) { // Remove any corrupt tags at the end