diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 79b6dc6c8..f2f6b4077 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -114,8 +114,8 @@ class TextHelper extends AppHelper { function autoLinkUrls($text, $htmlOptions = array()) { $options = 'array('; foreach ($htmlOptions as $option => $value) { - $value = var_export($value, true); - $options .= "'$option' => $value, "; + $value = var_export($value, true); + $options .= "'$option' => $value, "; } $options .= ')'; @@ -138,7 +138,8 @@ class TextHelper extends AppHelper { $options = 'array('; foreach ($htmlOptions as $option => $value) { - $options .= "'$option' => '$value', "; + $value = var_export($value, true); + $options .= "'$option' => $value, "; } $options .= ')'; @@ -226,7 +227,7 @@ class TextHelper extends AppHelper { if (mb_strlen($text) <= $length) { return $text; } else { - $truncate = mb_substr($text, 0, $length - strlen($ending)); + $truncate = mb_substr($text, 0, $length - mb_strlen($ending)); } } if (!$exact) { @@ -265,6 +266,7 @@ class TextHelper extends AppHelper { * @access public */ function trim() { + trigger_error('TextHelper::trim() is deprecated. Use TextHelper::truncate() instead', E_USER_WARNING); $args = func_get_args(); return call_user_func_array(array(&$this, 'truncate'), $args); } @@ -284,26 +286,26 @@ class TextHelper extends AppHelper { return $this->truncate($text, $radius * 2, $ending); } - $phraseLen = strlen($phrase); + $phraseLen = mb_strlen($phrase); if ($radius < $phraseLen) { $radius = $phraseLen; } - $pos = strpos(strtolower($text), strtolower($phrase)); + $pos = mb_strpos(mb_strtolower($text), mb_strtolower($phrase)); $startPos = 0; if ($pos > $radius) { $startPos = $pos - $radius; } - $textLen = strlen($text); + $textLen = mb_strlen($text); $endPos = $pos + $phraseLen + $radius; if ($endPos >= $textLen) { $endPos = $textLen; } - $excerpt = substr($text, $startPos, $endPos - $startPos); + $excerpt = mb_substr($text, $startPos, $endPos - $startPos); if ($startPos != 0) { $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); } diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index d036352b2..ab3068d04 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -70,10 +70,7 @@ class TextHelperTest extends CakeTestCase { * @return void */ function testTruncate() { - if (!isset($this->method)) { - $this->method = 'truncate'; - } - $m = $this->method; + $m = 'truncate'; $text1 = 'The quick brown fox jumps over the lazy dog'; $text2 = 'Heizölrückstoßabdämpfung'; $text3 = '© 2005-2007, Cake Software Foundation, Inc.
written by Alexander Wegener'; @@ -106,11 +103,6 @@ class TextHelperTest extends CakeTestCase { $this->assertIdentical($this->Text->{$m}($text7, 255), $text7); $this->assertIdentical($this->Text->{$m}($text7, 15), 'El moño está...'); $this->assertIdentical($this->Text->{$m}($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...'); - - if ($this->method == 'truncate') { - $this->method = 'trim'; - $this->testTruncate(); - } } /**