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[a-fA-F0-9]{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;
- }
复制代码
|