From dcdcd18aeb2b29ddfa7768317b14ca0a277dd654 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Wed, 30 May 2007 21:14:30 +0000 Subject: [PATCH] Backport r1846 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 | 31 ++++++++++++++++--------------- include/globals.inc.php.in | 1 + include/newsletter.inc.php | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/classes/miniwiki.php b/classes/miniwiki.php index 5af1364..70f5d3d 100644 --- a/classes/miniwiki.php +++ b/classes/miniwiki.php @@ -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('
\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))", "ligne1\\\\\nligne2"); + MiniWiki::Markup("/\\\\(?".">(\\\\*))\n/e", "str_repeat('
\n',mb_strlen('$1'))", "str_repeat('\n',mb_strlen('$1'))", "ligne1\\\\\nligne2"); // * unordered list MiniWiki::Markup("/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "''", "'$0'", "* element1\n* element2\n* element3"); @@ -58,12 +58,12 @@ class MiniWiki MiniWiki::Markup("/%([a-z]+|\#[0-9a-f]{3,6})%(.*?)%%/i", "$2", "$2", "%red% texte en rouge %%\\\\\n%#ff0% texte en jaune %%\\\\\n%#0000ff% texte en bleu %%"); // [+ big +] [++ bigger ++] [+++ even bigger +++] ... - MiniWiki::Markup("/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'", "[+ grand +]\n\n[++ plus grand ++]\n\n[+++ encore plus grand +++]"); + MiniWiki::Markup("/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'", "[+ grand +]\n\n[++ plus grand ++]\n\n[+++ encore plus grand +++]"); // -----
MiniWiki::Markup("/(\n|^)--(--+| \n)/s", '$1
', '$1-- '."\n", "----\n"); // titles - MiniWiki::$title_index = MiniWiki::Markup('/(\n|^)(!+)([^\n]*)/se', "'$1$3'", + MiniWiki::$title_index = MiniWiki::Markup('/(\n|^)(!+)([^\n]*)/se', "'$1$3'", "'$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); diff --git a/include/globals.inc.php.in b/include/globals.inc.php.in index 82d2500..1c2661b 100644 --- a/include/globals.inc.php.in +++ b/include/globals.inc.php.in @@ -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) diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 63025a3..9840775 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -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"; } -- 2.1.4