summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael <savetheinternet@tinyboard.org>2013-06-18 10:41:31 -0700
committerMichael <savetheinternet@tinyboard.org>2013-06-18 10:41:31 -0700
commitcbc3bd0c0a13463dbdbc3d53a03dd9b2080496c4 (patch)
treec86346d76ed556e85ddbefb0e2eed6b90c0046d0 /inc
parent68c6a749f2219d0248a1a8ba7e4c115b053367b6 (diff)
parenta92bb182d91ae98b2a2bc7787d5650050868f1f1 (diff)
Merge pull request #114 from Macil/rtlfix
Fix display issues with RTL control characters in post names, subjects, ...
Diffstat (limited to 'inc')
-rw-r--r--inc/display.php33
-rw-r--r--inc/lib/Twig/Extensions/Extension/Tinyboard.php1
2 files changed, 34 insertions, 0 deletions
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>$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;
diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php
index 67d63684..61cf9fc9 100644
--- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php
+++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php
@@ -25,6 +25,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
'until' => new Twig_Filter_Function('until'),
'split' => new Twig_Filter_Function('twig_split_filter'),
'push' => new Twig_Filter_Function('twig_push_filter'),
+ 'bidi_cleanup' => new Twig_Filter_Function('bidi_cleanup'),
'addslashes' => new Twig_Filter_Function('addslashes')
);
}