DiscuzX论坛短消息内容显示空白或不能正常显示中文的解决方案

问题描述:在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('&amp;', '&quot;', '&lt;', '&gt;'), $string);
                    if(strpos($string, '&amp;#') !== false) {
                        $string = preg_replace('/&amp;((#(\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");
            <font color="Red"><b>$lastmessage = array();//cr180修正 变量初始化 PHP高版本时可能会造成该变量异常</b></font>
            $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;
        }

posted on 2014-03-13 17:12 无心之源 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wuxinzhiyuan/p/3598968.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值