Typecho 博客评论显示 UserAgent (UA)
将下面的样式表外链加入到header.php的head部分,当然也可通过主题设置界面添加
ua图标下载:https://i.veimoz.com/2021/04/3424062869.gz
这里建议大伙把css中的图片下载到本地,以便将来…………。
.ua-icon {
display: inline-block;
width: 1pc;
height: 1pc;
background-size: cover;
background-repeat: no-repeat;
vertical-align: text-top
}
.icon-360 {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/360.png)
}
.icon-android {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/android.png);
height: 19px
}
.icon-apple {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/apple.png)
}
.icon-baidu {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/baidu.png)
}
.icon-chrome {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/chrome.png)
}
.icon-edge {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/edge.png)
}
.icon-firefox {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/firefox.png)
}
.icon-google {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/google.png)
}
.icon-ie {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/ie.png)
}
.icon-liebao {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/liebao.png)
}
.icon-linux {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/linux.png)
}
.icon-mac {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/mac.png)
}
.icon-opera {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/opera.png)
}
.icon-qq {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/qq.png)
}
.icon-quark {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/quark.png)
}
.icon-safari {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/safari.png)
}
.icon-ubuntu {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/ubuntu.png)
}
.icon-uc {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/uc.png)
}
.icon-win1 {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/win1.png)
}
.icon-win2 {
background-image: url(https://cdn.zrahh.com:4433/usr/uploads/2019/03/win2.png)
}
将以下代码加入到function.php
// 获取浏览器信息
function getBrowser($agent)
{
if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
$outputer = '<i class="ua-icon icon-ie"></i> Internet Explore';
} else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Firefox/', $regs[0]);
$FireFox_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-firefox"></i> FireFox';
} else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Maxthon/', $agent);
$Maxthon_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-edge"></i> MicroSoft Edge';
} else if (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) {
$outputer = '<i class="ua-icon icon-360"></i> 360极速浏览器';
} else if (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Edge/', $regs[0]);
$Edge_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-edge"></i> MicroSoft Edge';
} else if (preg_match('/UC/i', $agent)) {
$str1 = explode('rowser/', $agent);
$UCBrowser_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-uc"></i> UC浏览器';
} else if (preg_match('/QQ/i', $agent, $regs)||preg_match('/QQBrowser\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('rowser/', $agent);
$QQ_vern = explode('.', $str1[1]);
$outputer = '<i class= "ua-icon icon-qq"></i> QQ浏览器';
} else if (preg_match('/UBrowser/i', $agent, $regs)) {
$str1 = explode('rowser/', $agent);
$UCBrowser_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-uc"></i> UC浏览器';
} else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
$outputer = '<i class= "ua-icon icon-opera"></i> Opera';
} else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Chrome/', $agent);
$chrome_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-chrome"></i> Google Chrome';
} else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Version/', $agent);
$safari_vern = explode('.', $str1[1]);
$outputer = '<i class="ua-icon icon-safari"></i> Safari';
} else{
$outputer = '<i class="ua-icon icon-chrome"></i> Google Chrome';
}
echo $outputer;
}
// 获取操作系统信息
function getOs($agent)
{
$os = false;
if (preg_match('/win/i', $agent)) {
if (preg_match('/nt 6.0/i', $agent)) {
$os = ' <i class= "ua-icon icon-win1"></i> Windows Vista / ';
} else if (preg_match('/nt 6.1/i', $agent)) {
$os = ' <i class= "ua-icon icon-win1"></i> Windows 7 / ';
} else if (preg_match('/nt 6.2/i', $agent)) {
$os = ' <i class="ua-icon icon-win2"></i> Windows 8 / ';
} else if(preg_match('/nt 6.3/i', $agent)) {
$os = ' <i class= "ua-icon icon-win2"></i> Windows 8.1 / ';
} else if(preg_match('/nt 5.1/i', $agent)) {
$os = ' <i class="ua-icon icon-win1"></i> Windows XP / ';
} else if (preg_match('/nt 10.0/i', $agent)) {
$os = ' <i class="ua-icon icon-win2"></i> Windows 10 / ';
} else{
$os = ' <i class="ua-icon icon-win2"></i> Windows X64 / ';
}
} else if (preg_match('/android/i', $agent)) {
if (preg_match('/android 9/i', $agent)) {
$os = ' <i class="ua-icon icon-android"></i> Android Pie / ';
}
else if (preg_match('/android 8/i', $agent)) {
$os = ' <i class="ua-icon icon-android"></i> Android Oreo / ';
}
else{
$os = ' <i class="ua-icon icon-android"></i> Android / ';
}
}
else if (preg_match('/ubuntu/i', $agent)) {
$os = ' <i class="ua-icon icon-ubuntu"></i> Ubuntu / ';
} else if (preg_match('/linux/i', $agent)) {
$os = ' <i class= "ua-icon icon-linux"></i> Linux / ';
} else if (preg_match('/iPhone/i', $agent)) {
$os = ' <i class="ua-icon icon-apple"></i> iPhone / ';
} else if (preg_match('/mac/i', $agent)) {
$os = ' <i class="ua-icon icon-mac"></i> MacOS / ';
}else if (preg_match('/fusion/i', $agent)) {
$os = ' <i class="ua-icon icon-android"></i> Android / ';
} else {
$os = ' <i class="ua-icon icon-linux"></i> Linux / ';
}
echo $os;
}
将以下代码添加到comments.php中122行所在的div中
<span class="comment-ua">
<?php getOs($this->agent); ?>
<?php getBrowser($this->agent); ?>
</span>
这里注意一下$this
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/182
2 条评论
4.9k
发表评论
已有 2 条评论
热门文章
自媒体博客Spimes主题34w 阅读
Spimes主题专为博客、自媒体、资讯类的网站设计....
vCard主题个人简历主题13w 阅读
一款个人简历主题,可以简单搭建一下,具体也比较简单....
Splity博客双栏主题11w 阅读
仿制主题,Typecho博客主题,昼夜双版设计,可....
Spzac个人资讯下载类主题11w 阅读
用于作品展示、资源下载,行业垂直性网站、个人博客,....
热评文章
自媒体博客Spimes主题418 评论
Splity博客双栏主题187 评论
Spzac个人资讯下载类主题89 评论
Splinx博客图片主题35 评论
Spzhi知识付费社区主题34 评论
三栏清新博客S_blog主题30 评论
vCard主题个人简历主题29 评论
Pure轻简主题28 评论
已经弄好了谢谢:滑稽:
@sqqzy
:真棒::真棒: