主要是因為truncate對於中文的辨識不太正確
以至於會把中文拆解錯誤,因此需要修改 modifier.truncate.php
參考了網路上的文章:讓 Smarty 的 truncate 支援 UTF-8 的方法
就開始來動手吧
vim /var/www/html/includes/templatelib/plugins/modifier.truncate.php
這裡主要是要把function smarty_modifier_truncate這個function的內容整個置換掉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
if ($length == 0) return ''; $string = html_entity_decode(trim(strip_tags($string)), ENT_QUOTES, 'utf-8'); for($i = 0, $j = 0; $i < strlen($string); $i++) { if($j >= $length) { for($x = 0, $y = 0; $x < strlen($etc); $x++) { if($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0')) { $x += $number - 1; $y++; } else $y += 0.5; } $length -= $y; break; } if($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0')) { $i += $number - 1; $j++; } else $j += 0.5; } for($i = 0; (($i < strlen($string)) && ($length > 0)); $i++) { if($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0')) { if($length < 1.0) break; $result .= substr($string, $i, $number); $length -= 1.0; $i += $number - 1; } else { $result .= substr($string, $i, 1); $length -= 0.5; } } $result = htmlentities($result, ENT_QUOTES, 'utf-8'); if($i < strlen($string)) $result .= $etc; return $result; |
然後就可以了~
記得要順便修改video.html
不然會發現他怎麼把所有的中文字都叫出來了
vim /var/www/html/styles/cbv2new/layout/blocks/video.html
1 2 3 4 |
#大約第19行 <h2 class="title truncatedtitle"><a href="{videoLink vdetails=$video}" title="{$video.title}">{$video.title|truncate:40}</a></h2> #將40修改成15 <h2 class="title truncatedtitle"><a href="{videoLink vdetails=$video}" title="{$video.title}">{$video.title|truncate:15}</a></h2> |