Sorry, My poor English. I am japanese.
Thanks for the great expansion.
I'm using this extension in a multi-byte language.
In japanese language, a word is not separated by a space.
When there are no spaces in $txt, strrpos($txt," ") will return the value FALSE.
Therefore,the modAiDaNews2Helper::shorten() method does not return the expected results.
modAiDaNews2Helper::shorten() code:
function shorten($txt, $cut, $type, $end){
if ($cut > 0) {
if ($type){
$cut += 5;
if (function_exists('mb_substr')) {
$txt = mb_substr($txt, 0, $cut, 'UTF-8');
$txt = mb_substr($txt, 0, mb_strrpos($txt," "), 'UTF-8');
}else{
$txt = substr($txt, 0, $cut);
$txt = substr($txt, 0, strrpos($txt," "));
}
$txt .= $end;
}else{
$array = explode(" ", $txt);
if (count($array)<= $cut) {
//Do nothing
}else{
array_splice($array, $cut);
$txt = implode(" ", $array) . $end;
}
}
}
$txt = str_replace('"', '"', $txt);
return $txt;
}
I have avoided this problem by modifying the code as follows.
function shorten($txt, $cut, $type, $end){
if ($cut > 0) {
if ($type){
$cut += 5;
if (function_exists('mb_substr')) {
$space_pos = mb_strrpos($txt," ");
} else {
$space_pos = strrpos($txt," ");
}
if ($space_pos && $space_pos < $cut){
$cut = $space_pos;
}
if (function_exists('mb_substr')) {
$txt = mb_substr($txt, 0, $cut, 'UTF-8');
}else{
$txt = substr($txt, 0, $cut);
}
$txt .= $end;
}else{
$array = explode(" ", $txt);
if (count($array)<= $cut) {
//Do nothing
}else{
array_splice($array, $cut);
$txt = implode(" ", $array) . $end;
}
}
}
$txt = str_replace('"', '"', $txt);
return $txt;
}
Thanks.