Backport r1846
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 30 May 2007 21:14:30 +0000 (21:14 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 30 May 2007 21:14:30 +0000 (21:14 +0000)
 classes/miniwiki.php       |   31 ++++++++++++++++---------------
 include/globals.inc.php.in |    1 +
 include/newsletter.inc.php |    2 +-
 3 files changed, 18 insertions(+), 16 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1847 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/miniwiki.php
include/globals.inc.php.in
include/newsletter.inc.php

index 5af1364..70f5d3d 100644 (file)
@@ -30,7 +30,7 @@ class MiniWiki
         MiniWiki::Markup("/(\r\n|\r([^\n]))/", "\n$2", "\n$2");
                 
         // retours à la ligne avec \\
-        MiniWiki::Markup("/\\\\(?".">(\\\\*))\n/e", "str_repeat('<br />\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))", "ligne1\\\\\nligne2");
+        MiniWiki::Markup("/\\\\(?".">(\\\\*))\n/e", "str_repeat('<br />\n',mb_strlen('$1'))", "str_repeat('\n',mb_strlen('$1'))", "ligne1\\\\\nligne2");
         
         // * unordered list 
         MiniWiki::Markup("/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "'<ul><li>'.str_replace(\"\\n*\",'</li><li>','$2').'</li></ul>'", "'$0'", "* element1\n* element2\n* element3"); 
@@ -58,12 +58,12 @@ class MiniWiki
         MiniWiki::Markup("/%([a-z]+|\#[0-9a-f]{3,6})%(.*?)%%/i", "<span style='color: $1;'>$2</span>", "$2",
                          "%red% texte en rouge %%\\\\\n%#ff0% texte en jaune %%\\\\\n%#0000ff% texte en bleu %%");
         // [+ big +] [++ bigger ++] [+++ even bigger +++] ...
-        MiniWiki::Markup("/\\[(([-+])+)(.*?)\\1\\]/e","'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'", "[+ grand +]\n\n[++ plus grand ++]\n\n[+++ encore plus grand +++]");
+        MiniWiki::Markup("/\\[(([-+])+)(.*?)\\1\\]/e","'<span style=\'font-size:'.(round(pow(6/5,$2mb_strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'", "[+ grand +]\n\n[++ plus grand ++]\n\n[+++ encore plus grand +++]");
         
         // ----- <hr/>
         MiniWiki::Markup("/(\n|^)--(--+| \n)/s", '$1<hr/>', '$1-- '."\n", "----\n");
         // titles
-        MiniWiki::$title_index = MiniWiki::Markup('/(\n|^)(!+)([^\n]*)/se', "'$1<h'.strlen('$2').'>$3</h'.strlen('$2').'>'",
+        MiniWiki::$title_index = MiniWiki::Markup('/(\n|^)(!+)([^\n]*)/se', "'$1<h'.mb_strlen('$2').'>$3</h'.mb_strlen('$2').'>'",
                                                   "'$1$3'", "!titre1\n\n!!titre2\n\n!!!titre3");
         
         // links
@@ -93,35 +93,35 @@ class MiniWiki
         return $html;
     }
     
-    private static function justify($text,$n)
+    private static function justify($text, $n)
     {
-        $arr = explode("\n",wordwrap($text,$n));
-        $arr = array_map('trim',$arr);
+        $arr = explode("\n", wordwrap($text, $n));
+        $arr = array_map('trim', $arr);
         $res = '';
         foreach ($arr as $key => $line) {
             $nxl       = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
-            $nxl_split = preg_split('! +!',$nxl);
-            $nxw_len   = count($nxl_split) ? strlen($nxl_split[0]) : 0;
+            $nxl_split = preg_split('! +!u', $nxl);
+            $nxw_len   = count($nxl_split) ? mb_strlen($nxl_split[0]) : 0;
             $line      = trim($line);
         
-            if (strlen($line)+1+$nxw_len < $n) {
+            if (mb_strlen($line)+1+$nxw_len < $n) {
                 $res .= "$line\n";
                 continue;
             }
             
-            if (preg_match('![.:;]$!',$line)) {
+            if (preg_match('![.:;]$!u',$line)) {
                 $res .= "$line\n";
                 continue;
             }
         
-            $tmp   = preg_split('! +!',trim($line));
+            $tmp   = preg_split('! +!u', trim($line));
             $words = count($tmp);
             if ($words <= 1) {
                 $res .= "$line\n";
                 continue;
             }
         
-            $len   = array_sum(array_map('strlen',$tmp));
+            $len   = array_sum(array_map('mb_strlen', $tmp));
             $empty = $n - $len;
             $sw    = floatval($empty) / floatval($words-1);
             
@@ -129,8 +129,9 @@ class MiniWiki
             $l   = '';
             foreach ($tmp as $word) {
                 $l   .= $word;
-                $cur += $sw + strlen($word);
-                $l    = str_pad($l,intval($cur+0.5));
+                $cur += $sw + strlen($word); // Use strlen here instead of mb_strlen because it is used by str_pad
+                                             // which is not multibyte compatible
+                $l   = str_pad($l, intval($cur + 0.5));
             }
             $res .= trim($l)."\n";
         }
@@ -153,7 +154,7 @@ class MiniWiki
         if (!$title) {
             MiniWiki::$replacementHTML[MiniWiki::$title_index] = $oldrule12;
         }
-        $text = $just ? MiniWiki::justify($text,$width-$indent) : wordwrap($text,$width-$indent);
+        $text = $just ? MiniWiki::justify($text, $width - $indent) :  wordwrap($text, $width - $indent);
         if($indent) {
             $ind = str_pad('',$indent);
             $text = $ind.str_replace("\n","\n$ind",$text);
index 82d2500..1c2661b 100644 (file)
@@ -86,6 +86,7 @@ class PlatalGlobals
         setlocale(LC_TIME,     $this->locale);
         setlocale(LC_CTYPE,    $this->locale);
         date_default_timezone_set($this->timezone);
+        mb_internal_encoding("UTF-8");
     }
 
     public function asso($key=null)
index 63025a3..9840775 100644 (file)
@@ -226,7 +226,7 @@ class NLArticle
     public function toText()
     {
         $title = '*'.$this->title().'*';
-        $body  = MiniWiki::WikiToText($this->_body,true);
+        $body  = MiniWiki::WikiToText($this->_body, true);
         $app   = MiniWiki::WikiToText($this->_append,false,4);
         return trim("$title\n\n$body\n\n$app")."\n";
     }