From a92bb182d91ae98b2a2bc7787d5650050868f1f1 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Tue, 2 Apr 2013 17:28:04 +0800 Subject: Fix display issues with RTL control characters in post names, subjects, and filenames. --- inc/display.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'inc/display.php') diff --git a/inc/display.php b/inc/display.php index 57110224..ab96eb26 100644 --- a/inc/display.php +++ b/inc/display.php @@ -213,6 +213,39 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { return $body; } +function bidi_cleanup($str){ + # Closes all embedded RTL and LTR unicode formatting blocks in a string so that + # it can be used inside another without controlling its direction. + # More info: http://www.iamcal.com/understanding-bidirectional-text/ + # + # LRE - U+202A - 0xE2 0x80 0xAA + # RLE - U+202B - 0xE2 0x80 0xAB + # LRO - U+202D - 0xE2 0x80 0xAD + # RLO - U+202E - 0xE2 0x80 0xAE + # + # PDF - U+202C - 0xE2 0x80 0xAC + # + $explicits = '\xE2\x80\xAA|\xE2\x80\xAB|\xE2\x80\xAD|\xE2\x80\xAE'; + $pdf = '\xE2\x80\xAC'; + + $stack = 0; + $str = preg_replace_callback("!(?$explicits)|(?$pdf)!", function($match) use (&$stack) { + if (isset($match['explicits']) && $match['explicits']) { + $stack++; + } else { + if ($stack) + $stack--; + else + return ''; + } + return $match[0]; + }, $str); + for ($i=0; $i<$stack; $i++){ + $str .= "\xE2\x80\xAC"; + } + return $str; +} + function secure_link_confirm($text, $title, $confirm_message, $href) { global $config; -- cgit v1.3 From 1d4fced75acc7a39abdceaf7ea563c2b5d131839 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Fri, 1 Mar 2013 08:42:38 +0800 Subject: pm_snippet() should probably use mb_substr if it's using mb_strlen. --- inc/display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/display.php') diff --git a/inc/display.php b/inc/display.php index 57110224..6d8cf366 100644 --- a/inc/display.php +++ b/inc/display.php @@ -118,7 +118,7 @@ function pm_snippet($body, $len=null) { // calculate strlen() so we can add "..." after if needed $strlen = mb_strlen($body); - $body = substr($body, 0, $len); + $body = mb_substr($body, 0, $len); // Re-escape the characters. return '' . utf8tohtml($body) . ($strlen > $len ? '…' : '') . ''; -- cgit v1.3 From b6fc7ca89d8ac0fea48fc4f3b7862cb9ea1e0687 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Mon, 18 Mar 2013 03:14:30 +0800 Subject: Fix broken entity removal in post truncation. --- inc/display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/display.php') diff --git a/inc/display.php b/inc/display.php index 6d8cf366..90764b43 100644 --- a/inc/display.php +++ b/inc/display.php @@ -204,7 +204,7 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { } } else { // remove broken HTML entity at the end (if existent) - $body = preg_replace('/&[^;]+$/', '', $body); + $body = preg_replace('/&[^;]*$/', '', $body); } $body .= 'Post too long. Click here to view the full text.'; -- cgit v1.3