Browse Source

Unicode bi-directional text: Finally a working fix

pull/40/head
Michael Foster 9 years ago
parent
commit
abfdd38e59
  1. 45
      inc/display.php
  2. 7
      stylesheets/style.css
  3. 2
      templates/post_reply.html
  4. 2
      templates/post_thread.html

45
inc/display.php

@ -218,11 +218,50 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) {
return $body;
}
function bidi_cleanup($str) {
// Removes all embedded RTL and LTR unicode formatting blocks in a string so that
function bidi_cleanup($data) {
// Closes all embedded RTL and LTR unicode formatting blocks in a string so that
// it can be used inside another without controlling its direction.
return "<bdi>$str</bdi>";
$explicits = '\xE2\x80\xAA|\xE2\x80\xAB|\xE2\x80\xAD|\xE2\x80\xAE';
$pdf = '\xE2\x80\xAC';
preg_match_all("!$explicits!", $data, $m1, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
preg_match_all("!$pdf!", $data, $m2, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
if (count($m1) || count($m2)){
$p = array();
foreach ($m1 as $m){ $p[$m[0][1]] = 'push'; }
foreach ($m2 as $m){ $p[$m[0][1]] = 'pop'; }
ksort($p);
$offset = 0;
$stack = 0;
foreach ($p as $pos => $type){
if ($type == 'push'){
$stack++;
}else{
if ($stack){
$stack--;
}else{
# we have a pop without a push - remove it
$data = substr($data, 0, $pos-$offset)
.substr($data, $pos+3-$offset);
$offset += 3;
}
}
}
# now add some pops if your stack is bigger than 0
for ($i=0; $i<$stack; $i++){
$data .= "\xE2\x80\xAC";
}
return $data;
}
return $data;
}
function secure_link_confirm($text, $title, $confirm_message, $href) {

7
stylesheets/style.css

@ -37,6 +37,10 @@ p.intro a.email:hover span.name {
p.intro label {
display: inline;
}
p.intro time, p.intro a.ip-link, p.intro a.capcode {
direction: ltr;
unicode-bidi: embed;
}
h2 {
color: #AF0A0F;
font-size: 11pt;
@ -406,5 +410,4 @@ table.mod.config-editor input[type="text"] {
p.intro.thread-hidden {
margin: 0px;
padding: 0px;
}
}

2
templates/post_reply.html

@ -26,7 +26,7 @@
{{ capcode.cap }}
{% endif %}
{% if post.mod and post.mod|hasPermission(config.mod.show_ip, board.uri) %}
[<a style="margin:0;" href="?/IP/{{ post.ip }}">{{ post.ip }}</a>]
[<a class="ip-link" style="margin:0;" href="?/IP/{{ post.ip }}">{{ post.ip }}</a>]
{% endif %}
{% if config.display_flags and post.modifiers.flag %}
<img class="flag" src="{{ config.uri_flags|sprintf(post.modifiers.flag) }}"

2
templates/post_thread.html

@ -80,7 +80,7 @@
{{ capcode.cap }}
{% endif %}
{% if post.mod and post.mod|hasPermission(config.mod.show_ip, board.uri) %}
[<a style="margin:0;" href="?/IP/{{ post.ip }}">{{ post.ip }}</a>]
[<a class="ip-link" style="margin:0;" href="?/IP/{{ post.ip }}">{{ post.ip }}</a>]
{% endif %}
{% if config.display_flags and post.modifiers.flag %}
<img class="flag" src="{{ config.uri_flags|sprintf(post.modifiers.flag) }}"

Loading…
Cancel
Save