往wordpress评论useragent图标添加win8.1的支持
前不久往我的评论区域添加了useragent图标,代码来自牧风提取插件的精简版,然后最近又把我的老爷机升级到win8.1了,然后在自己博客的评论区域中发现我的系统图标是个问号,看得很不爽,就动动手往里面添加一个win8.1吧。
usergent.php代码如下
- <?php
- /** Get Browser Infomations */
- function get_browsers($ua){
- $title = 'unknow';
- $icon = 'unknow';
- if (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'Internet Explorer '. $matches[1];
- if ( strpos($matches[1], '7') !== false || strpos($matches[1], '8') !== false)
- $icon = 'ie8';
- elseif ( strpos($matches[1], '9') !== false)
- $icon = 'ie9';
- elseif ( strpos($matches[1], '10') !== false)
- $icon = 'ie10';
- else
- $icon = 'ie';
- }elseif (preg_match('#Firefox/([a-zA-Z0-9.]+)#i', $ua, $matches)){
- $title = 'Firefox '. $matches[1];
- $icon = 'firefox';
- }elseif (preg_match('#CriOS/([a-zA-Z0-9.]+)#i', $ua, $matches)){
- $title = 'Chrome for iOS '. $matches[1];
- $icon = 'crios';
- }elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'Google Chrome '. $matches[1];
- $icon = 'chrome';
- if (preg_match('#OPR/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'Opera '. $matches[1];
- $icon = 'opera15';
- if (preg_match('#opera mini#i', $ua)) $title = 'Opera Mini'. $matches[1];
- }
- }elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'Safari '. $matches[1];
- $icon = 'safari';
- }elseif (preg_match('#Opera.(.*)Version[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'Opera '. $matches[2];
- $icon = 'opera';
- if (preg_match('#opera mini#i', $ua)) $title = 'Opera Mini'. $matches[2];
- }elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua,$matches)) {
- $title = 'Maxthon '. $matches[2];
- $icon = 'maxthon';
- }elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = '360 Browser '. $matches[1];
- $icon = '360se';
- }elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'SouGou Browser 2'.$matches[1];
- $icon = 'sogou';
- }elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $title = 'UCWEB '. $matches[1];
- $icon = 'ucweb';
- }elseif(preg_match('#wp-(iphone|android)/([a-zA-Z0-9.]+)#i', $ua, $matches)){
- $title = 'wordpress '. $matches[2];
- $icon = 'wordpress';
- }
- return array(
- $title,
- $icon
- );
- }
- function get_os($ua){
- $title = 'unknow';
- $icon = 'unknow';
- if (preg_match('/win/i', $ua)) {
- if (preg_match('/Windows NT 6.1/i', $ua)) {
- $title = "Windows 7";
- $icon = "windows_win7";
- }elseif (preg_match('/Windows NT 5.1/i', $ua)) {
- $title = "Windows XP";
- $icon = "windows";
- }elseif (preg_match('/Windows NT 6.2/i', $ua)) {
- $title = "Windows 8";
- $icon = "windows_win8";
- }elseif (preg_match('/Windows NT 6.3/i', $ua)) {// 2013.11.4 添加win8.1支持 https://huilang.me
- $title = "Windows 8.1";
- $icon = "windows_win8.1";
- }elseif (preg_match('/Windows NT 6.0/i', $ua)) {
- $title = "Windows Vista";
- $icon = "windows_vista";
- }elseif (preg_match('/Windows NT 5.2/i', $ua)) {
- if (preg_match('/Win64/i', $ua)) {
- $title = "Windows XP 64 bit";
- } else {
- $title = "Windows Server 2003";
- }
- $icon = 'windows';
- }elseif (preg_match('/Windows Phone/i', $ua)) {
- $matches = explode(';',$ua);
- $title = $matches[2];
- $icon = "windows_phone";
- }
- }elseif (preg_match('#iPod.*.CPU.([a-zA-Z0-9.( _)]+)#i', $ua, $matches)) {
- $title = "iPod ".$matches[1];
- $icon = "iphone";
- } elseif (preg_match('#iPhone OS ([a-zA-Z0-9.( _)]+)#i', $ua, $matches)) {
- $title = "Iphone ".$matches[1];
- $icon = "iphone";
- } elseif (preg_match('#iPad.*.CPU.([a-zA-Z0-9.( _)]+)#i', $ua, $matches)) {
- $title = "iPad ".$matches[1];
- $icon = "ipad";
- } elseif (preg_match('/Mac OS X.([0-9. _]+)/i', $ua, $matches)) {
- if(count(explode(7,$matches[1]))>1) $matches[1] = 'Lion '.$matches[1];
- elseif(count(explode(8,$matches[1]))>1) $matches[1] = 'Mountain Lion '.$matches[1];
- $title = "Mac OSX ".$matches[1];
- $icon = "macos";
- } elseif (preg_match('/Macintosh/i', $ua)) {
- $title = "Mac OS";
- $icon = "macos";
- } elseif (preg_match('/CrOS/i', $ua)){
- $title = "Google Chrome OS";
- $icon = "chrome";
- }elseif (preg_match('/Linux/i', $ua)) {
- $title = 'Linux';
- $icon = 'linux';
- if (preg_match('/Android.([0-9. _]+)/i',$ua, $matches)) {
- $title= $matches[0];
- $icon = "android";
- }elseif (preg_match('#Ubuntu#i', $ua)) {
- $title = "Ubuntu Linux";
- $icon = "ubuntu";
- }elseif(preg_match('#Debian#i', $ua)) {
- $title = "Debian GNU/Linux";
- $icon = "debian";
- }elseif (preg_match('#Fedora#i', $ua)) {
- $title = "Fedora Linux";
- $icon = "fedora";
- }
- }
- return array(
- $title,
- $icon
- );
- }
- function get_useragent($ua){
- $url = get_bloginfo('template_directory') . '/img/browsers/';
- $browser = get_browsers($ua);
- $os = get_os($ua);
- echo '<img src="'.$url.$browser[1].'.png" title="'.$browser[0].'" class="useragent" alt="'.$browser[0].'"><img src="'.$url.$os[1].'.png" title="'.$os[0].'" class="useragent" alt="'.$os[0].'">';
- }
其实操作非常简单,就是查找下win8.1的版本号还是啥的(百度得知为Windows NT 6.3),然后按照win8的形式添加一个即可。
调用
- <?php get_useragent($comment->comment_agent);?>
别忘了往主题的img文件夹下放置 useragen图标 图标自己在 百度网盘 提取吧,我没心思去弄win8.1的新图标,就复制了一份win8的改名为win8.1的而已...
发布于记忆碎片-网络技术分享 https://huilang.me
文章地址:https://huilang.me/add-useragent-icon-with-win8-1-in-wordpress/
这是什么…PS.最近你更新真勤快…
话说你指的是wp更新还是windows版本更新
呃 我指的是wp更新~
看到你也是win8.1了
呵呵 早就是了~只是公司的是win7,win8.1对于一些工作上用的软件不兼容啊~~~
我也是自己电脑win8.1的 软件兼容还好吧,至少我目前用到的软件都兼容呢
可惜不能显示国家。 :x