DiscuzX论坛短消息内容显示空白或不能正常显示中文的解决方案
适应版本:Discuz-x2.5问题描述:在PHP5.4x版本中论坛短消息内容显示空白或不能正常显示中文的解决方案
ucenter在php5.4里,中文短消息无法显示的问题主要是由于uccode.class.php中的htmlspecialchars函数没有经过编码转换,为了解决这个问题,需要对默认的htmlspecialchars进行自定义。
解决方案:
文件:/uc_client/lib/uccode.class.php
查找:
[*]function complie($message) {
复制代码
在前面加上:
[*]//解决PHP5.4x版本htmlspecialchars函数中文编码问题
[*] function cr180_dhtmlspecialchars($string, $flags = null) {
[*] if(is_array($string)) {
[*] foreach($string as $key => $val) {
[*] $string[$key] = dhtmlspecialchars($val, $flags);
[*] }
[*] } else {
[*] if($flags === null) {
[*] $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);
[*] if(strpos($string, '&#') !== false) {
[*] $string = preg_replace('/&((#(\d{3,5}|x{4}));)/', '&\\1', $string);
[*] }
[*] } else {
[*] if(PHP_VERSION < '5.4.0') {
[*] $string = htmlspecialchars($string, $flags);
[*] } else {
[*] if(strtolower(CHARSET) == 'utf-8') {
[*] $charset = 'UTF-8';
[*] } else {
[*] $charset = 'ISO-8859-1';
[*] }
[*] $string = htmlspecialchars($string, $flags, $charset);
[*] }
[*] }
[*] }
[*] return $string;
[*] }
复制代码
查找:
[*]$message = htmlspecialchars($message);
复制代码
替换为:
[*]$message = $this -> cr180_dhtmlspecialchars($message);
复制代码
另外,短消息首页无法显示消息内容的问题是由于ucenter函数【lastpm($uid)】里没有提前初始化变量造成的,所以还需要进行以下修改:
文件:/uc_client/model/pm.php
查找:
[*]function lastpm($uid) {
[*] $lastpm =
[*]$this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_members m
[*]LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE
[*]m.uid='$uid' ORDER BY m.lastdateline DESC LIMIT 1");
[*] $lastmessage = unserialize($lastpm['lastmessage']);
[*] if($lastmessage['lastauthorid']) {
[*] $lastpm['lastauthorid'] = $lastmessage['lastauthorid'];
[*] $lastpm['lastauthor'] = $lastmessage['lastauthor'];
[*] $lastpm['lastsummary'] = $lastmessage['lastsummary'];
[*] } else {
[*] $lastpm['lastauthorid'] = $lastmessage['firstauthorid'];
[*] $lastpm['lastauthor'] = $lastmessage['firstauthor'];
[*] $lastpm['lastsummary'] = $lastmessage['firstsummary'];
[*] }
[*]
[*] return $lastpm;
[*] }
复制代码
替换为:
[*]function lastpm($uid) {
[*] $lastpm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE m.uid='$uid' ORDER BY m.lastdateline DESC LIMIT 1");
[*] $lastmessage = array();//cr180修正 变量初始化 PHP高版本时可能会造成该变量异常
[*] $lastmessage = unserialize($lastpm['lastmessage']);
[*] if($lastmessage['lastauthorid']) {
[*] $lastpm['lastauthorid'] = $lastmessage['lastauthorid'];
[*] $lastpm['lastauthor'] = $lastmessage['lastauthor'];
[*] $lastpm['lastsummary'] = $lastmessage['lastsummary'];
[*] } else {
[*] $lastpm['lastauthorid'] = $lastmessage['firstauthorid'];
[*] $lastpm['lastauthor'] = $lastmessage['firstauthor'];
[*] $lastpm['lastsummary'] = $lastmessage['firstsummary'];
[*] }
[*]
[*] return $lastpm;
[*] }
复制代码
http://www.appcuz.com/thread-449-1-1.html PHP5.4 中 htmlspecialchars 这个函数造成的
他的默认是 UTF-8 转换, GBK的 DZ 需要修改 /uc_client/lib/uccode.class.php 中 30 行
$message = htmlspecialchars($message);
改为
$message = dhtmlspecialchars($message);
复制代码
看来是BUG了忘记使用 自己处理过的 d 开头函数
http://www.discuz.net/thread-2887225-1-1.html
页:
[1]