-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
174 lines (167 loc) · 6.56 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Typecho 版 User-Agent
*
* @package UserAgent
* @author Unique
* @version 1.0.0
* @link http://blog.hiunique.com
*/
class UserAgent_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form)
{
}
/**
* 获取浏览器名称
* @access public
* @param $us => $comments->agent
* @return $title => 返回名称
*/
public static function getBrowserName($ua)
{
$title = 'unknow';
if (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Internet Explorer ' . $matches[1];
} elseif (preg_match('#Firefox/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Firefox ' . $matches[1];
} elseif (preg_match('#CriOS/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Chrome for iOS ' . $matches[1];
} elseif (preg_match('#LBBROWSER#i', $ua, $matches)) {
$title = '猎豹安全浏览器';
} elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Google Chrome ' . $matches[1];
if (preg_match('#OPR/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Opera ' . $matches[1];
if (preg_match('#opera mini#i', $ua))
$title = 'Opera Mini' . $matches[1];
}
} elseif (preg_match('#UCWEB/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'UCWEB ' . $matches[1];
} elseif (preg_match('#UCBrowser/([a-zA-Z0-9.]+) U([0-9])/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'UCBrowser ' . $matches[1] . ' U' . $matches[2] . ' ' . $matches[3];
} elseif (preg_match('#UCBrowser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'UCBrowser ' . $matches[1];
} elseif (preg_match('#MQQBrowser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'QQBrowser ' . $matches[1];
} elseif (preg_match('#LieBaoFast/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'LieBaoFast ' . $matches[1];
} elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Safari ' . $matches[1];
} elseif (preg_match('#Opera.(.*)Version[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Opera ' . $matches[2];
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];
} elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = '360 Browser ' . $matches[1];
} elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'SouGou Browser 2' . $matches[1];
} elseif (preg_match('#rv:([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Internet Explorer ' . $matches[1];
}
echo $title;
}
/**
* 获取操作系统名称
* @access public
* @param $us => $comments->agent
* @return $title => 返回名称
*/
public static function getOSName($ua)
{
$title = 'unknow';
if (preg_match('/win/i', $ua)) {
if (preg_match('/Windows NT 6.1/i', $ua)) {
$title = "Windows 7";
if (preg_match('/WOW64/i', $ua)) {
$title .= ' x64';
}
} elseif (preg_match('/Windows NT 5.1/i', $ua)) {
$title = "Windows XP";
} elseif (preg_match('/Windows NT 6.2/i', $ua)) {
$title = "Windows 8";
} elseif (preg_match('/Windows NT 6.3/i', $ua)) {
$title = "Windows 8.1";
} elseif (preg_match('/Windows NT 6.0/i', $ua)) {
$title = "Windows Vista/Windows Server 2008";
} 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";
}
} elseif (preg_match('/Windows Phone/i', $ua)) {
$matches = explode(';', $ua);
$title = $matches[2];
}
} elseif (preg_match('#iPod.*.CPU.([a-zA-Z0-9.( _)]+)#i', $ua, $matches)) {
$title = "iPod" . $matches[1];
} elseif (preg_match('#iPhone.*.CPU.([a-zA-Z0-9.( _)]+)#i', $ua, $matches)) {
$title = $matches[1];
} elseif (preg_match('#iPad.*.CPU.([a-zA-Z0-9. _]+)#i', $ua, $matches)) {
$title = "iPad" . $matches[1];
} 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];
} elseif (preg_match('/Macintosh/i', $ua)) {
$title = "Mac OS";
} elseif (preg_match('/CrOS/i', $ua)) {
$title = "Google Chrome OS";
} elseif (preg_match('/Linux/i', $ua)) {
$title = 'Linux';
if (preg_match('/Android.([0-9. _]+)/i', $ua, $matches)) {
$title = $matches[0];
} elseif (preg_match('#Ubuntu#i', $ua)) {
$title = "Ubuntu Linux";
} elseif (preg_match('#Debian#i', $ua)) {
$title = "Debian GNU/Linux";
} elseif (preg_match('#Fedora#i', $ua)) {
$title = "Fedora Linux";
}
}
echo $title;
}
}