今天在重写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']?>"> <?php echo $useragent->platform['title']; ?> <img src="<?php echo TEMPLATE_URL.$useragent->browser['image']?>"> <?php echo $useragent->browser['title']; ?> <?php } ?>
调用格式:<?php echo useragent($comment['useragent']); ?> 将这段写如到您的评论列表与子评论列表适当位置即可
剩余一些文件的下载地址:http://pan.baidu.com/s/1ntij0WL 密码: sqrt
!评论内容需包含中文