最新文章:

首页 Web技术

emlog程序获取评论用户操作系统与浏览器信息

发布时间:2015年06月05日 评论数:3 阅读数:12751

    今天在重写DUX主题的时候加了用户操作系统与浏览器信息显示的功能,以前通常都是使用得插件实现,那现在可以不用插件即可实现,如果你是喜欢折腾您的博客的可以来尝试改动一下,下面是改动步骤

    首先打开include/model/comment_model.php文件,

    找到while ($row = $this->db->fetch_array($ret)) {(即第45行)在这里增加一个获取useragent的信息,代码$row['useragent'] = htmlspecialchars($row['useragent']);

    其次在249行的评论提交中增加一个useragent的信息到数据库里,修改代码如下:

    function addComment($name, $content, $mail, $url, $imgcode, $blogId, $pid)
    {
    $ipaddr = getIp();
    $useragent = $_SERVER['HTTP_USER_AGENT'];
    $utctimestamp = time();
     
    if($pid != 0) {
    $comment = $this->getOneComment($pid);
    $content = '@' . addslashes($comment['poster']) . ':' . $content;
    }
     
    $ischkcomment = Option::get('ischkcomment');
    $hide = ROLE == ROLE_VISITOR ? $ischkcomment : 'n';
     
    $sql = 'INSERT INTO '.DB_PREFIX."comment (date,poster,gid,comment,mail,url,hide,ip,pid,useragent)
    VALUES ('$utctimestamp','$name','$blogId','$content','$mail','$url','$hide','$ipaddr','$pid','$useragent')";
    $ret = $this->db->query($sql);
    $cid = $this->db->insert_id();
    $CACHE = Cache::getInstance();
     
    if ($hide == 'n') {
    $this->db->query('UPDATE '.DB_PREFIX."blog SET comnum = comnum + 1 WHERE gid='$blogId'");
    $CACHE->updateCache(array('sta', 'comment'));
    doAction('comment_saved', $cid);
    emDirect(Url::log($blogId).'#'.$cid);
    } else {
    $CACHE->updateCache('sta');
    doAction('comment_saved', $cid);
    emMsg('评论发表成功,请等待管理员审核', Url::log($blogId));
    }
    }


    将以上代码覆盖到function addComment(){}中就可以了

    <?php
    //获取评论用户操作系统、浏览器等信息
    function useragent($info){
    require_once 'useragent.class.php';
    $useragent = UserAgentFactory::analyze($info);
    ?>
    <img src="<?php echo TEMPLATE_URL.$useragent->platform['image']?>">&nbsp;<?php echo $useragent->platform['title']; ?>&nbsp;
    <img src="<?php echo TEMPLATE_URL.$useragent->browser['image']?>">&nbsp;<?php echo $useragent->browser['title']; ?>
    <?php
    }
    ?>


    调用格式:<?php echo useragent($comment['useragent']); ?> 将这段写如到您的评论列表与子评论列表适当位置即可


    剩余一些文件的下载地址:http://pan.baidu.com/s/1ntij0WL 密码: sqrt

二维码加载中...
本文作者:Mr.linus      文章标题: emlog程序获取评论用户操作系统与浏览器信息
本文地址:http://www.90qj.com/164.html  本文已经被百度收录,点击查看详情
版权声明:若无注明,本文皆为“挨踢 Blog”原创,转载请保留文章出处。
天虎博客
天虎博客2017-02-08 23:11回复
#3
挺好的.6666
Arlene 凉夏
Arlene 凉夏2016-08-19 18:24回复
#2
围观
森七
森七2016-06-27 00:43回复
#1
前来围观