japanese lang fixes by deminy
authorgarvinhicking <garvinhicking>
Fri, 23 Jun 2006 08:49:59 +0000 (08:49 +0000)
committergarvinhicking <garvinhicking>
Fri, 23 Jun 2006 08:49:59 +0000 (08:49 +0000)
docs/NEWS
include/lang.inc.php
plugins/serendipity_plugin_comments/serendipity_plugin_comments.php

index 2d85b29361a19e7bbac509573c6396fca7d35d95..ebde8f7ad5cf09ceca621500ec9a3606e9e1254a 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 1.1-alpha7()
 ------------------------------------------------------------------------
 
+    * Patch mb-functions to better work on foreign/japanese charsets
+      (thanks to deminy!)
+
     * Replaced core smarty assign() calls to assign_by_ref() where
       appropriate. (Falk Döring, garvinhicking)
       TODO: This might introduce oddities! Check thoroughly.
index 80a56ae4c814a811376bcb8c0e94a33ce822bf82..a788808ee2b72a77de98a644ca5f24c80df174dc 100644 (file)
@@ -65,7 +65,8 @@ if (!defined('serendipity_MB_LOADED') && defined('serendipity_LANG_LOADED')) {
             case 'ucfirst':
                 // there's no mb_ucfirst, so emulate it
                 if ($mbstring === 2) {
-                    return mb_strtoupper(mb_substr($args[1], 0, 1)) . mb_substr($args[1], 1);
+                    $enc = mb_detect_encoding($args[1]);
+                    return mb_strtoupper(mb_substr($args[1], 0, 1, $enc), $enc) . mb_substr($args[1], 1, mb_strlen($args[1], $enc), $enc);
                 } else {
                     return ucfirst($args[1]);
                 }
index 03c6808e1dd1421e838ef3429558a94969614641..5ad5603c6c8989bacb10d8a7962723ae224dba6c 100644 (file)
@@ -150,8 +150,8 @@ class serendipity_plugin_comments extends serendipity_plugin
 
         if ($sql && is_array($sql)) {
             foreach($sql AS $key => $row) {
-                if ( $serendipity['lang'] == "ja" && function_exists( 'mb_strimwidth')) {
-                    $comment = mb_strimwidth( strip_tags($row['comment']), 0, $max_chars, " [...]");
+                if (function_exists('mb_strimwidth')) {
+                    $comment = mb_strimwidth(strip_tags($row['comment']), 0, $max_chars, " [...]", mb_detect_encoding($row['comment']));
                 } else {
                     $comments = wordwrap(strip_tags($row['comment']), $max_chars, '@@@', 1);
                     $aComment = explode('@@@', $comments);
@@ -173,13 +173,14 @@ class serendipity_plugin_comments extends serendipity_plugin
                     $user = PLUGIN_COMMENTS_ANONYMOUS;
                 }
 
-                if ( $serendipity['lang'] == "ja" && function_exists( 'mb_strimwidth')) {
+                if (function_exists( 'mb_strimwidth')) {
                     $pos = 0;
                     $parts = array();
-                    $comment_len = mb_strlen( $comment);
-                    while ( $pos < $comment_len) {
-                        $part = mb_strimwidth( $comment, $pos, $wordwrap);
-                        $pos += mb_strlen( $part);
+                    $enc = mb_detect_encoding($comment);
+                    $comment_len = mb_strlen($comment, $enc);
+                    while ($pos < $comment_len) {
+                        $part = mb_strimwidth($comment, $pos, $wordwrap, '', $enc);
+                        $pos += mb_strlen($part, $enc);
                         $parts[] = $part;
                     }
                     $comment = implode( "\n", $parts);