summaryrefslogtreecommitdiff
path: root/inc/display.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-06-21 16:41:39 -0400
committerczaks <marcin@6irc.net>2013-06-21 16:41:39 -0400
commit24a520485df30a85a68d02938256c4a8ac7af8e8 (patch)
tree8a93e590b715624cfa7e3812a413061fc252c1ab /inc/display.php
parentc073967600124568609d10a400039f017ad9dcf8 (diff)
parent9b0c31daa68c7ab96bc25e09b70ffea77ba23590 (diff)
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts: templates/page.html
Diffstat (limited to 'inc/display.php')
-rw-r--r--inc/display.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/inc/display.php b/inc/display.php
index 9be772e4..30560d3a 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 '<em>' . utf8tohtml($body) . ($strlen > $len ? '&hellip;' : '') . '</em>';
@@ -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 .= '<span class="toolong">Post too long. Click <a href="' . $url . '">here</a> to view the full text.</span>';
@@ -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>$explicits)|(?<pdf>$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;