1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-01-19 01:24:05 +01:00

#458 - Issue Added RTL support for Arabic writers.

Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
8n-tech 2015-04-17 04:02:11 +10:00
parent 80c312b7e3
commit 62380bfbde
4 changed files with 75 additions and 4 deletions

View File

@ -2266,8 +2266,27 @@ function markup(&$body, $track_cites = false, $op = false) {
if ($config['strip_superfluous_returns'])
$body = preg_replace('/\s+$/', '', $body);
$body = preg_replace("/\n/", '<br/>', $body);
if ($config['markup_paragraphs']) {
$paragraphs = explode("\n", $body);
$bodyNew = "";
foreach ($paragraphs as $paragraph) {
if (strlen(trim($paragraph)) > 0) {
$paragraphDirection = is_rtl($paragraph) ? "rtl" : "ltr";
}
else {
$paragraphDirection = "empty";
}
$bodyNew .= "<p class=\"body-line {$paragraphDirection}\">" . $paragraph . "</p>";
}
$body = $bodyNew;
}
else {
$body = preg_replace("/\n/", '<br/>', $body);
}
if ($config['markup_repair_tidy']) {
$tidy = new tidy();
@ -2324,6 +2343,40 @@ function ordutf8($string, &$offset) {
return $code;
}
function uniord($u) {
$k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
$k1 = ord(substr($k, 0, 1));
$k2 = ord(substr($k, 1, 1));
return $k2 * 256 + $k1;
}
function is_rtl($str) {
if(mb_detect_encoding($str) !== 'UTF-8') {
$str = mb_convert_encoding($str, mb_detect_encoding($str),'UTF-8');
}
preg_match_all('/[^\n\s]+/', $str, $matches);
preg_match_all('/.|\n\s/u', $str, $matches);
$chars = $matches[0];
$arabic_count = 0;
$latin_count = 0;
$total_count = 0;
foreach ($chars as $char) {
$pos = uniord($char);
if ($pos >= 1536 && $pos <= 1791) {
$arabic_count++;
}
else if ($pos > 123 && $pos < 123) {
$latin_count++;
}
$total_count++;
}
return (($arabic_count/$total_count) > 0.5);
}
function strip_combining_chars($str) {
$chars = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
$str = '';

View File

@ -140,6 +140,7 @@
$config['additional_javascript'][] = 'js/auto-scroll.js';
$config['additional_javascript'][] = 'js/twemoji/twemoji.js';
$config['additional_javascript'][] = 'js/file-selector.js';
$config['additional_javascript'][] = 'js/board-directory.js';
// Oekaki (now depends on config.oekaki so can be in all scripts)
$config['additional_javascript'][] = 'js/jquery-ui.custom.min.js';
$config['additional_javascript'][] = 'js/wPaint/8ch.js';
@ -160,6 +161,9 @@
$config['markup'][] = array("/__(.+?)__/", "<u>\$1</u>");
$config['markup'][] = array("/###([^\s']+)###/", "<a href='/boards.html#\$1'>###\$1###</a>");
$config['markup_paragraphs'] = true;
$config['markup_rtl'] = true;
$config['boards'] = array(array('<i class="fa fa-home" title="Home"></i>' => '/', '<i class="fa fa-tags" title="Boards"></i>' => '/boards.html', '<i class="fa fa-question" title="FAQ"></i>' => '/faq.html', '<i class="fa fa-random" title="Random"></i>' => '/random.php', '<i class="fa fa-plus" title="New board"></i>' => '/create.php', '<i class="fa fa-ban" title="Public ban list"></i>' => '/bans.html', '<i class="fa fa-search" title="Search"></i>' => '/search.php', '<i class="fa fa-cog" title="Manage board"></i>' => '/mod.php', '<i class="fa fa-quote-right" title="Chat"></i>' => 'https://qchat.rizon.net/?channels=#8chan'), array('b', 'news+', 'boards'), array('operate', 'meta'), array('<i class="fa fa-twitter" title="Twitter"></i>'=>'https://twitter.com/infinitechan'));
//$config['boards'] = array(array('<i class="fa fa-home" title="Home"></i>' => '/', '<i class="fa fa-tags" title="Boards"></i>' => '/boards.html', '<i class="fa fa-question" title="FAQ"></i>' => '/faq.html', '<i class="fa fa-random" title="Random"></i>' => '/random.php', '<i class="fa fa-plus" title="New board"></i>' => '/create.php', '<i class="fa fa-search" title="Search"></i>' => '/search.php', '<i class="fa fa-cog" title="Manage board"></i>' => '/mod.php', '<i class="fa fa-quote-right" title="Chat"></i>' => 'https://qchat.rizon.net/?channels=#8chan'), array('b', 'meta', 'int'), array('v', 'a', 'tg', 'fit', 'pol', 'tech', 'mu', 'co', 'sp', 'boards'), array('<i class="fa fa-twitter" title="Twitter"></i>'=>'https://twitter.com/infinitechan'));

View File

@ -643,7 +643,8 @@ elseif (isset($_POST['post'])) {
if (mysql_version() >= 50503) {
$post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset
} else {
}
else {
// MySQL's `utf8` charset only supports up to 3-byte symbols
// Remove anything >= 0x010000

View File

@ -368,7 +368,12 @@ div.delete {
}
div.post.reply p {
margin: 0.3em 0 0 0;
display: block;
margin: 0;
line-height: 1.16em;
font-size: 13px;
min-height: 1.16em;
}
div.post.reply div.body {
@ -1070,6 +1075,14 @@ span.pln {
min-width: 48px;
}
/* Text and accessibility */
.ltr {
direction: ltr;
}
.rtl {
direction: rtl;
font-family: Tahoma;
}
/* Responsive helpers */
.col {