1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | class name: GPCUserAgent |
---|
4 | class version : 1.0.1 |
---|
5 | plugin version : 3.5.4 |
---|
6 | date : 2012-09-04 |
---|
7 | ------------------------------------------------------------------------------ |
---|
8 | author: grum at piwog.org |
---|
9 | << May the Little SpaceFrog be with you >> |
---|
10 | ------------------------------------------------------------------------------ |
---|
11 | |
---|
12 | |
---|
13 | | release | date | |
---|
14 | | 1.0.1 | 2012/09/04 | * Fix some bot definition |
---|
15 | | | | |
---|
16 | | | | |
---|
17 | |
---|
18 | ---------------------------------------------------------------------- */ |
---|
19 | |
---|
20 | require_once('GPCUserAgent.const.inc.php'); |
---|
21 | |
---|
22 | class GPCUserAgent |
---|
23 | { |
---|
24 | /** |
---|
25 | * parse a user agent string and return an array of normalized informations |
---|
26 | * |
---|
27 | * returned: |
---|
28 | * array( |
---|
29 | * 'os' => (integer) |
---|
30 | * 'os_version' => (string) |
---|
31 | * 'browser' => (integer) |
---|
32 | * 'browser_name' => (string) |
---|
33 | * 'browser_type' => (integer) |
---|
34 | * 'browser_version' => (string) |
---|
35 | * 'engine' => (integer) |
---|
36 | * 'engine_version' => (string) |
---|
37 | * ) |
---|
38 | * |
---|
39 | * @param String $userAgent |
---|
40 | * @return Array |
---|
41 | */ |
---|
42 | static public function parse($userAgent) |
---|
43 | { |
---|
44 | $returned=array( |
---|
45 | UA_DATA_OS => UA_OS_UNKNOWN, |
---|
46 | UA_DATA_OS_VERSION => '', |
---|
47 | |
---|
48 | UA_DATA_BROWSER => UA_BOT_UNKNOWN, |
---|
49 | UA_DATA_BROWSER_NAME => '', |
---|
50 | UA_DATA_BROWSER_TYPE => UA_BROWSER_TYPE_UNKNOWN, |
---|
51 | UA_DATA_BROWSER_VERSION => '', |
---|
52 | |
---|
53 | UA_DATA_ENGINE => UA_ENGINE_UNKNOWN, |
---|
54 | UA_DATA_ENGINE_VERSION => '' |
---|
55 | ); |
---|
56 | |
---|
57 | $bot=self::getBot($userAgent); |
---|
58 | if($bot[UA_DATA_BROWSER]!=='') |
---|
59 | { |
---|
60 | $returned[UA_DATA_BROWSER]=$bot[UA_DATA_BROWSER]; |
---|
61 | $returned[UA_DATA_BROWSER_TYPE]=UA_BROWSER_TYPE_CRAWLER; |
---|
62 | $returned[UA_DATA_BROWSER_VERSION]=str_replace(array(';', '(', ')'), array('', '', ''), $bot[UA_DATA_BROWSER_VERSION]); |
---|
63 | return($returned); |
---|
64 | } |
---|
65 | |
---|
66 | $tmp=self::getBrowser($userAgent); |
---|
67 | $returned[UA_DATA_BROWSER]=$tmp[UA_DATA_BROWSER]; |
---|
68 | $returned[UA_DATA_BROWSER_TYPE]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER][$tmp[UA_DATA_BROWSER]][UA_PROP_TYPE]; |
---|
69 | $returned[UA_DATA_BROWSER_VERSION]=str_replace(array(';', '(', ')'), array('', '', ''), $tmp[UA_DATA_BROWSER_VERSION]); |
---|
70 | |
---|
71 | $tmp=self::getOs($userAgent); |
---|
72 | $returned[UA_DATA_OS]=$tmp[UA_DATA_OS]; |
---|
73 | $returned[UA_DATA_OS_VERSION]=str_replace(array(';', '(', ')'), array('', '', ''), $tmp[UA_DATA_OS_VERSION]); |
---|
74 | |
---|
75 | $tmp=self::getEngine($userAgent); |
---|
76 | $returned[UA_DATA_ENGINE]=$tmp[UA_DATA_ENGINE]; |
---|
77 | $returned[UA_DATA_ENGINE_VERSION]=str_replace(array(';', '(', ')'), array('', '', ''), $tmp[UA_DATA_ENGINE_VERSION]); |
---|
78 | |
---|
79 | // explicit OS for mobile device override the browser type |
---|
80 | if($returned[UA_DATA_OS]==UA_OS_BLACKBERRY or |
---|
81 | $returned[UA_DATA_OS]==UA_OS_SYMBIAN_OS or |
---|
82 | $returned[UA_DATA_OS]==UA_OS_SYMBOS or |
---|
83 | $returned[UA_DATA_OS]==UA_OS_ANDROID or |
---|
84 | $returned[UA_DATA_OS]==UA_OS_IOS) $returned[UA_DATA_BROWSER_TYPE]=UA_BROWSER_TYPE_MOBILE; |
---|
85 | |
---|
86 | // explicit OS for console device override the browser type |
---|
87 | if($returned[UA_DATA_OS]==UA_OS_NINTENDO_DS or |
---|
88 | $returned[UA_DATA_OS]==UA_OS_NINTENDO_WII or |
---|
89 | $returned[UA_DATA_OS]==UA_OS_SONY_PS3 or |
---|
90 | $returned[UA_DATA_OS]==UA_OS_SONY_PSP) $returned[UA_DATA_BROWSER_TYPE]=UA_BROWSER_TYPE_CONSOLE; |
---|
91 | |
---|
92 | return($returned); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | /** |
---|
97 | * from a user agent array properties, return an array completed with associated |
---|
98 | * properties |
---|
99 | * |
---|
100 | * @param Array $userAgent |
---|
101 | * @return Array |
---|
102 | */ |
---|
103 | static public function getProperties($userAgent) |
---|
104 | { |
---|
105 | $returned=array(); |
---|
106 | if(isset($userAgent[UA_DATA_BROWSER]) and isset(GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER][$userAgent[UA_DATA_BROWSER]])) |
---|
107 | { |
---|
108 | $returned[UA_DATA_BROWSER]=$userAgent[UA_DATA_BROWSER]; |
---|
109 | $returned[UA_DATA_BROWSER_NAME]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER][$userAgent[UA_DATA_BROWSER]][UA_PROP_NAME]; |
---|
110 | $returned[UA_DATA_BROWSER_URL]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER][$userAgent[UA_DATA_BROWSER]][UA_PROP_URL]; |
---|
111 | } |
---|
112 | |
---|
113 | if(!isset($userAgent[UA_DATA_BROWSER_TYPE]) and isset($userAgent[UA_DATA_BROWSER])) |
---|
114 | $userAgent[UA_DATA_BROWSER_TYPE]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER][$userAgent[UA_DATA_BROWSER]][UA_PROP_TYPE]; |
---|
115 | |
---|
116 | if(isset($userAgent[UA_DATA_BROWSER_TYPE]) and isset(GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER_TYPE][$userAgent[UA_DATA_BROWSER_TYPE]])) |
---|
117 | { |
---|
118 | $returned[UA_DATA_BROWSER_TYPE]=$userAgent[UA_DATA_BROWSER_TYPE]; |
---|
119 | $returned[UA_DATA_BROWSER_TYPE_NAME]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_BROWSER_TYPE][$userAgent[UA_DATA_BROWSER_TYPE]]; |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | if(isset($userAgent[UA_DATA_OS]) and isset(GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_OS][$userAgent[UA_DATA_OS]])) |
---|
124 | { |
---|
125 | $returned[UA_DATA_OS]=$userAgent[UA_DATA_OS]; |
---|
126 | $returned[UA_DATA_OS_NAME]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_OS][$userAgent[UA_DATA_OS]][UA_PROP_NAME]; |
---|
127 | $returned[UA_DATA_OS_URL]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_OS][$userAgent[UA_DATA_OS]][UA_PROP_URL]; |
---|
128 | } |
---|
129 | |
---|
130 | if(isset($userAgent[UA_DATA_ENGINE]) and isset(GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_ENGINE][$userAgent[UA_DATA_ENGINE]])) |
---|
131 | { |
---|
132 | $returned[UA_DATA_ENGINE]=$userAgent[UA_DATA_ENGINE]; |
---|
133 | $returned[UA_DATA_ENGINE_NAME]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_ENGINE][$userAgent[UA_DATA_ENGINE]][UA_PROP_NAME]; |
---|
134 | $returned[UA_DATA_ENGINE_URL]=GPCUserAgentValues::$UA_BrowserInfo[UA_DATA_ENGINE][$userAgent[UA_DATA_ENGINE]][UA_PROP_URL]; |
---|
135 | } |
---|
136 | |
---|
137 | return($returned); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | /** |
---|
142 | * return bot properties |
---|
143 | * if user agent is not a bot, properties are filled with string |
---|
144 | * |
---|
145 | * @param String $userAgent : user agent string to parse |
---|
146 | * @return Array |
---|
147 | */ |
---|
148 | static private function getBot($userAgent) |
---|
149 | { |
---|
150 | $botList=array( |
---|
151 | '(008)\/(\S*)[\;]' => UA_BOT_008, |
---|
152 | '(abachobot)' => UA_BOT_ABACHOBOT, |
---|
153 | '(accoona-ai-agent)(?:\/(\S*))*' => UA_BOT_ACCOONA_AI_AGENT, |
---|
154 | '(arachmo)' => UA_BOT_ARACHMO, |
---|
155 | '(b-l-i-t-z-b-o-t)' => UA_BOT_BLITZBOT, |
---|
156 | '(blitzbot)' => UA_BOT_BLITZBOT, |
---|
157 | '(bingbot)\/(\S*)[\;]' => UA_BOT_MICROSOFT_BING, |
---|
158 | '(bingbot)(?:\/(\S*))*' => UA_BOT_MICROSOFT_BING, |
---|
159 | '(charlotte)\/(\S*)[\;]' => UA_BOT_CHARLOTTE, |
---|
160 | '(charlotte)(?:\/(\S*))*' => UA_BOT_CHARLOTTE, |
---|
161 | '(cerberian drtrs)\sversion-(\S*)[\)]' => UA_BOT_CERBERIAN_DRTRS, |
---|
162 | '(cosmos)\/(\S*)[\_]' => UA_BOT_COSMOS, |
---|
163 | '(covario-ids)(?:\/(\S*))*' => UA_BOT_COVARIO_IDS, |
---|
164 | '(dataparksearch)\/(\S*)[\-]' => UA_BOT_DATAPARKSEARCH, |
---|
165 | '(dataparksearch)(?:\/(\S*))*' => UA_BOT_DATAPARKSEARCH, |
---|
166 | '(gaisbot)\/(\S*)[\(\s]' => UA_BOT_GAISBOT, |
---|
167 | '(google)(?:\/(\S*))*' => UA_BOT_GOOGLE, |
---|
168 | '(googlebot)\/(\S*);' => UA_BOT_GOOGLE, |
---|
169 | '(googlebot)(?:\/(\S*))*' => UA_BOT_GOOGLE, |
---|
170 | '(googlebot-image)(?:\/(\S*))*' => UA_BOT_GOOGLE, |
---|
171 | '(gurujibot)\/(\S*);' => UA_BOT_GURUJIBOT, |
---|
172 | '(gurujibot)(?:\/(\S*))*' => UA_BOT_GURUJIBOT, |
---|
173 | '(holmes)(?:\/(\S*))*' => UA_BOT_HOLMES, |
---|
174 | '(htdig)(?:\/(\S*))*' => UA_BOT_HTDIG, |
---|
175 | '(ia_archiver)\/(\S*)' => UA_BOT_IA_ARCHIVER, |
---|
176 | '(ia_archiver)' => UA_BOT_IA_ARCHIVER, |
---|
177 | '(iccrawler)' => UA_BOT_ICCRAWLER, |
---|
178 | '(ichiro)\/(\S*)\(' => UA_BOT_ICHIRO, |
---|
179 | '(ichiro)(?:\/(\S*))*' => UA_BOT_ICHIRO, |
---|
180 | '(l.webis)(?:\/(\S*))*' => UA_BOT_LWEBIS, |
---|
181 | '(larbin)' => UA_BOT_LARBIN, |
---|
182 | '(linkwalker)(?:\/(\S*))*' => UA_BOT_LINKWALKER, |
---|
183 | '(lwp-trivial)(?:\/(\S*))*' => UA_BOT_LWPTRIVIAL, |
---|
184 | '(mabontland)' => UA_BOT_MABONLAND, |
---|
185 | '(mnogosearch)' => UA_BOT_MNOGOSEARCH, |
---|
186 | '(mogimogi)(?:\/(\S*))*' => UA_BOT_MOGIMOGI, |
---|
187 | '(morning\spaper)' => UA_BOT_MORNINGPAPER, |
---|
188 | '(netresearchserver)\/(\S*)\(' => UA_BOT_NETRESEARCHSERVER, |
---|
189 | '(netresearchserver)(?:\/(\S*))*' => UA_BOT_NETRESEARCHSERVER, |
---|
190 | '(newsgator)(?:\/(\S*))*' => UA_BOT_NEWSGATOR, |
---|
191 | '(ng-search)(?:\/(\S*))*' => UA_BOT_NGSEARCH, |
---|
192 | '(nymesis)(?:\/(\S*))*' => UA_BOT_NYMESIS, |
---|
193 | '(oegp)' => UA_BOT_OEGP, |
---|
194 | '(pompos)(?:\/(\S*))*' => UA_BOT_POMPOS, |
---|
195 | '(pycurl)(?:\/(\S*))*' => UA_BOT_PYCURL, |
---|
196 | '(qseero)' => UA_BOT_QSEERO, |
---|
197 | '(sbider)(?:\/(\S*))*' => UA_BOT_SBIDER, |
---|
198 | '(scoutjet)' => UA_BOT_SCOUTJET, |
---|
199 | '(scrubby)(?:\/(\S*))*' => UA_BOT_SCRUBBY, |
---|
200 | '(searchsight)(?:\/(\S*))*' => UA_BOT_SEARCHSIGHT, |
---|
201 | '(semanticdiscovery)(?:\/(\S*))*' => UA_BOT_SEMANTICDISCOVERY, |
---|
202 | |
---|
203 | '(shoula)' => UA_BOT_SHOULA, |
---|
204 | '(snappy)(?:\/(\S*))*' => UA_BOT_SNAPPY, |
---|
205 | '(stackrambler)(?:\/(\S*))*' => UA_BOT_STACKRAMBLER, |
---|
206 | '(silk)(?:\/(\S*))*' => UA_BOT_SILK, |
---|
207 | '(teoma)' => UA_BOT_TEOMA, |
---|
208 | '(tineye)(?:\/(\S*))*' => UA_BOT_TINEYE, |
---|
209 | '(truwogps)(?:\/(\S*))*' => UA_BOT_TRUWOGPS, |
---|
210 | '(updated)(?:\/(\S*))*' => UA_BOT_UPDATED, |
---|
211 | '(voyager)(?:\/(\S*))*' => UA_BOT_VOYAGER, |
---|
212 | '(vyu2)' => UA_BOT_VYU2, |
---|
213 | '(webcollage)(?:\/(\S*))*' => UA_BOT_WEBCOLLAGE, |
---|
214 | '(yooglifetchagent)(?:\/(\S*))*' => UA_BOT_YOOGLIFETCHAGENT, |
---|
215 | '(zao)(?:\/(\S*))*' => UA_BOT_ZAO, |
---|
216 | '(zealbot)' => UA_BOT_ZEALBOT, |
---|
217 | '(baiduspider)' => UA_BOT_BAIDU, |
---|
218 | '(msnbot)\/(\d+(?:\.\d+)*)' => UA_BOT_MSN_SEARCH, |
---|
219 | '(msnbot)\s(\d+(?:\.\d+)*)' => UA_BOT_MSN_SEARCH, |
---|
220 | '(exabot)\/(\d+(?:\.\d+)*)' => UA_BOT_EXALEAD, |
---|
221 | '(gamespyhttp)\/(\d+(?:\.\d+)*)' => UA_BOT_GAMESPY, |
---|
222 | '(gigabot)\/(\d+(?:\.\d+)*)' => UA_BOT_GIGABLAST, |
---|
223 | '(inktomi)' => UA_BOT_INKTOMI, |
---|
224 | '(Yahoo! Slurp)' => UA_BOT_YAHOO_SEARCH, |
---|
225 | '(yahooseeker)' => UA_BOT_YAHOO_SEARCH, |
---|
226 | '\s*([a-z]*(?:bot|spyder|crawl|crawler|spider)[a-z]*)' => UA_BOT_UNKNOWN |
---|
227 | ); |
---|
228 | |
---|
229 | $returned=array( |
---|
230 | UA_DATA_BROWSER => '', |
---|
231 | //'name' => '', |
---|
232 | UA_DATA_BROWSER_VERSION => '' |
---|
233 | ); |
---|
234 | |
---|
235 | $result=array(); |
---|
236 | foreach($botList as $regExp => $crawler) |
---|
237 | { |
---|
238 | if(preg_match('/'.$regExp.'/i',$userAgent,$result)) |
---|
239 | { |
---|
240 | // exclude some case |
---|
241 | if($crawler==UA_BOT_UNKNOWN and preg_match('/(?:msiecrawler)/i', $userAgent)) |
---|
242 | return($returned); |
---|
243 | |
---|
244 | $returned=array( |
---|
245 | UA_DATA_BROWSER => $crawler, |
---|
246 | //'name' => $result[1], #retrieved from the code |
---|
247 | UA_DATA_BROWSER_VERSION => isset($result[2])?$result[2]:'' |
---|
248 | ); |
---|
249 | return($returned); |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | return($returned); |
---|
254 | } |
---|
255 | |
---|
256 | |
---|
257 | /** |
---|
258 | * return browser properties |
---|
259 | * |
---|
260 | * @param String $userAgent : user agent string to parse |
---|
261 | * @return Array |
---|
262 | */ |
---|
263 | static private function getBrowser($userAgent) |
---|
264 | { |
---|
265 | $browserList=array( |
---|
266 | '(android).*applewebkit.*(?:version\/(\S*))(?:safari)?' => UA_BROWSER_ANDROID_WEBKIT, |
---|
267 | '(opera mini)\/(\S*)\/' => UA_BROWSER_OPERA_MINI, |
---|
268 | '(opera mini)\/(\S*)' => UA_BROWSER_OPERA_MINI, |
---|
269 | '(opera mobi).*(?:version\/(\S*))' => UA_BROWSER_OPERA_MOBILE, |
---|
270 | '(opera mobi)' => UA_BROWSER_OPERA_MOBILE, |
---|
271 | '(blackberry).*version\/(\S*)' => UA_BROWSER_BLACKBERRY, |
---|
272 | '(blackberry\d*)\/(\S*)' => UA_BROWSER_BLACKBERRY, |
---|
273 | '(blackberry)' => UA_BROWSER_BLACKBERRY, |
---|
274 | '(bunjalloo)\/(\S*)[\;\(]' => UA_BROWSER_BUNJALLOO, |
---|
275 | '(Fennec)\/(\S*)' => UA_BROWSER_FENNEC, |
---|
276 | '(gobrowser)\/(\S*)' => UA_BROWSER_GOBROWSER, |
---|
277 | '(gobrowser)' => UA_BROWSER_GOBROWSER, |
---|
278 | '(iemobile)\/(\S*)[\;\)]' => UA_BROWSER_IEMOBILE, |
---|
279 | '(iemobile)\s(\S*)[\;\)]' => UA_BROWSER_IEMOBILE, |
---|
280 | '(iris)\/(\S*)' => UA_BROWSER_IRIS, |
---|
281 | '(maemo browser)\s(\S*)' => UA_BROWSER_MAEMO_BROWSER, |
---|
282 | '(mib)\/(\S*)' => UA_BROWSER_MIB, |
---|
283 | '(minimo)\/(\S*)' => UA_BROWSER_MINIMO, |
---|
284 | '(netfront)\/(\S*)' => UA_BROWSER_NETFRONT, |
---|
285 | '(SEMC-Browser)\/(\S*)' => UA_BROWSER_SEMC, |
---|
286 | '(teashark)\/(\S*)' => UA_BROWSER_TEASHARK, |
---|
287 | |
---|
288 | '(playstation 3);\s*(\S*)[\;\)]' => UA_BROWSER_PS3, |
---|
289 | '(playstation 3)' => UA_BROWSER_PS3, |
---|
290 | '(PSP \(PlayStation Portable\));\s*(\S*)[\;\)]' => UA_BROWSER_PSP, |
---|
291 | '(PSP \(PlayStation Portable\));\s*(\S*)' => UA_BROWSER_PSP, |
---|
292 | |
---|
293 | '(opera)\/(\S*)\s.*(?:nintendo)' => UA_BROWSER_OPERA_WII, |
---|
294 | '(opera).*(?:version\/(\S*))' => UA_BROWSER_OPERA, |
---|
295 | '(opera)\/(\S*)' => UA_BROWSER_OPERA, |
---|
296 | '(opera)\s(\S*)' => UA_BROWSER_OPERA, |
---|
297 | '(shiira)\/(\S*)' => UA_BROWSER_SHIIRA, |
---|
298 | '(shiira)' => UA_BROWSER_SHIIRA, |
---|
299 | '(skyfire)\/(\S*)' => UA_BROWSER_SKYFIRE, |
---|
300 | '(thunderbird)\/(\S*)' => UA_BROWSER_THUNDERBIRD, |
---|
301 | '(namoroka)\/(\S*)' => UA_BROWSER_NAMOROKA, |
---|
302 | '(minefield)\/(\S*)' => UA_BROWSER_MINEFIELD, |
---|
303 | '(lunascape)\/(\S*)' => UA_BROWSER_LUNASCAPE, |
---|
304 | '(lunascape)\s(\S*)[\;\)]' => UA_BROWSER_LUNASCAPE, |
---|
305 | '(lunascape)\s(.*)[\;\)]' => UA_BROWSER_LUNASCAPE, |
---|
306 | '(lunascape)' => UA_BROWSER_LUNASCAPE, |
---|
307 | '(arora)\/(\S*)' => UA_BROWSER_ARORA, |
---|
308 | '(camino)\/(\S*)' => UA_BROWSER_CAMINO, |
---|
309 | '(kapiko)\/(\S*)' => UA_BROWSER_KAPIKO, |
---|
310 | '(kazehakase)\/(\S*)' => UA_BROWSER_KAZEHAKAZE, |
---|
311 | '(chromeplus)\/(\S*)' => UA_BROWSER_CHROMEPLUS, |
---|
312 | '(chrome)\/(\S*)' => UA_BROWSER_CHROME, |
---|
313 | '(epiphany)\/(\S*)' => UA_BROWSER_EPIPHANY, |
---|
314 | '(epiphany)' => UA_BROWSER_EPIPHANY, |
---|
315 | '(galeon)\/(\S*)' => UA_BROWSER_GALEON, |
---|
316 | '(orca)\/(\S*)' => UA_BROWSER_ORCA, |
---|
317 | '(lobo)\/(\S*)' => UA_BROWSER_LOBO, |
---|
318 | '(seamonkey)\/(\S*)' => UA_BROWSER_SEAMONKEY, |
---|
319 | '(midori)\/(\S*)' => UA_BROWSER_MIDORI, |
---|
320 | '(midori)' => UA_BROWSER_MIDORI, |
---|
321 | '(maxthon)\/(\S*)' => UA_BROWSER_MAXTHON, |
---|
322 | '(maxthon)\s?(\S*)[\);]' => UA_BROWSER_MAXTHON, |
---|
323 | '(iceape)\/(\S*)' => UA_BROWSER_ICEAPE, |
---|
324 | '(iceweasel)\/(\S*)' => UA_BROWSER_ICEWEASEL, |
---|
325 | '(netscape\d?)\/(\S*)' => UA_BROWSER_NETSCAPE, |
---|
326 | '(navigator)\/(\S*)' => UA_BROWSER_NETSCAPE, |
---|
327 | '(firebird)\/(\S*)' => UA_BROWSER_FIREBIRD, |
---|
328 | '(firefox)\/(\S*)' => UA_BROWSER_FIREFOX, |
---|
329 | '(msie)\s?(\S*)[\);]' => UA_BROWSER_INTERNET_EXPLORER, |
---|
330 | '(konqueror)\/(\S*)[\);]' => UA_BROWSER_KONQUEROR, |
---|
331 | '(links)\s?\((\S*)[\);]' => UA_BROWSER_LINKS, |
---|
332 | '(lynx)\/(\S*)' => UA_BROWSER_LYNX, |
---|
333 | '(safari)|version\/(\S*)' => UA_BROWSER_SAFARI, |
---|
334 | '(mozilla)\/(\S*)' => UA_BROWSER_NETSCAPE |
---|
335 | ); |
---|
336 | |
---|
337 | $returned=array( |
---|
338 | UA_DATA_BROWSER => UA_BROWSER_UNKNOWN, |
---|
339 | //'name' => '', |
---|
340 | UA_DATA_BROWSER_VERSION => '' |
---|
341 | ); |
---|
342 | |
---|
343 | $result=array(); |
---|
344 | foreach($browserList as $regExp => $browser) |
---|
345 | { |
---|
346 | if(preg_match('/'.$regExp.'/i',$userAgent,$result)) |
---|
347 | { |
---|
348 | //echo print_r($userAgent, true).print_r($result, true); |
---|
349 | if(is_array($result) and count($result)>=2) |
---|
350 | { |
---|
351 | if($browser==UA_BROWSER_SAFARI and preg_match('/iphone|ipad|ipod/i', $userAgent)) |
---|
352 | $browser=UA_BROWSER_SAFARI_MOBILE; |
---|
353 | |
---|
354 | $returned=array( |
---|
355 | UA_DATA_BROWSER => $browser, |
---|
356 | //'name' => $result[1], |
---|
357 | UA_DATA_BROWSER_VERSION => isset($result[2])?$result[2]:'' |
---|
358 | ); |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | $returned=array( |
---|
363 | UA_DATA_BROWSER => UA_BROWSER_UNKNOWN, |
---|
364 | //'name' => '', |
---|
365 | UA_DATA_BROWSER_VERSION => '' |
---|
366 | ); |
---|
367 | } |
---|
368 | return($returned); |
---|
369 | } |
---|
370 | } |
---|
371 | return($returned); |
---|
372 | } |
---|
373 | |
---|
374 | |
---|
375 | /** |
---|
376 | * return OS properties |
---|
377 | * |
---|
378 | * @param String $userAgent : user agent string to parse |
---|
379 | * @return Array |
---|
380 | */ |
---|
381 | static private function getOs($userAgent) |
---|
382 | { |
---|
383 | $osList=array( |
---|
384 | '(android)\s?(\S*)[\;\)]' => UA_OS_ANDROID, |
---|
385 | '(android)\s?(\S*)' => UA_OS_ANDROID, |
---|
386 | '(linux)' => UA_OS_LINUX, |
---|
387 | '(freebsd)' => UA_OS_FREEBSD, |
---|
388 | '(openbsd)' => UA_OS_OPENBSD, |
---|
389 | '(netbsd)' => UA_OS_NETBSD, |
---|
390 | '(sunos)' => UA_OS_SUNOS, |
---|
391 | '(blackberry)\s?([^;.]*);' => UA_OS_BLACKBERRY, |
---|
392 | '(blackberry)' => UA_OS_BLACKBERRY, |
---|
393 | '(symbianos)' => UA_OS_SYMBIAN_OS, |
---|
394 | '(symbos)' => UA_OS_SYMBOS, |
---|
395 | '(windows)\s?(phone\sos\s\S*)[\;\)]' => UA_OS_WINDOWS, |
---|
396 | '(windows)\s?(phone\sos\s\S*)' => UA_OS_WINDOWS, |
---|
397 | '(windows)\s?(ce\s?\S*)[\;\)]' => UA_OS_WINDOWS, |
---|
398 | '(windows)\s?(ce\s?\S*)' => UA_OS_WINDOWS, |
---|
399 | '(windows)\s?(NT\s?\S*)[\;\)]' => UA_OS_WINDOWS, |
---|
400 | '(windows)\s?(NT\s?\S*)' => UA_OS_WINDOWS, |
---|
401 | '(windows)\s?(\S*)[\;\)]' => UA_OS_WINDOWS, |
---|
402 | '(windows)\s?(\S*)' => UA_OS_WINDOWS, |
---|
403 | '(winnt)' => UA_OS_WINDOWS, |
---|
404 | '(win98)' => UA_OS_WINDOWS, |
---|
405 | '(win95)' => UA_OS_WINDOWS, |
---|
406 | '(mac_powerpc)' => UA_OS_MACINTOSH, |
---|
407 | '(cpu\siphone\sos)\s?(\S*)' => UA_OS_IOS, |
---|
408 | '(iphone|ipad|ipod);.*(?:cpu\sos\s(\S*))' => UA_OS_IOS, |
---|
409 | '(mac\sos\sx)\s(\S*)[\;\)]' => UA_OS_MAC_OS_X, |
---|
410 | '(mac\sos\sx)\s(\S*)' => UA_OS_MAC_OS_X, |
---|
411 | '(mac\sos\sx)' => UA_OS_MAC_OS_X, |
---|
412 | '(nintendo\swii).*;\s([0-9\-]*);' => UA_OS_NINTENDO_WII, |
---|
413 | '(playstation\s3)' => UA_OS_SONY_PS3, |
---|
414 | '(playstation\sportable)' => UA_OS_SONY_PSP, |
---|
415 | '(nintendo\sds)' => UA_OS_NINTENDO_DS, |
---|
416 | '(cros)(?:\s*i\d*)(?:\s(\S*))' => UA_OS_CHROME_OS, |
---|
417 | '(cros)' => UA_OS_CHROME_OS, |
---|
418 | '(beos)' => UA_OS_BE_OS, |
---|
419 | '(dragonfly)' => UA_OS_DRAGONFLY, |
---|
420 | '(unix)' => UA_OS_UNIX, |
---|
421 | '(darwin)' => UA_OS_DARWIN, |
---|
422 | '(macintosh)' => UA_OS_MACINTOSH, |
---|
423 | '(fedora)' => UA_OS_LINUX, |
---|
424 | '(os\/2).*(warp(?:\s\S*));' => UA_OS_OS2, |
---|
425 | '(os\/2)' => UA_OS_OS2, |
---|
426 | '(amigaos)(?:\s(\S*))' => UA_OS_AMIGAOS, |
---|
427 | '(amigaos)' => UA_OS_AMIGAOS |
---|
428 | ); |
---|
429 | |
---|
430 | $returned=array( |
---|
431 | UA_DATA_OS => UA_OS_UNKNOWN, |
---|
432 | //'name' => '', |
---|
433 | UA_DATA_OS_VERSION => '' |
---|
434 | ); |
---|
435 | |
---|
436 | $result=array(); |
---|
437 | foreach($osList as $regExp => $os) |
---|
438 | { |
---|
439 | if(preg_match('/'.$regExp.'/i',$userAgent,$result)) |
---|
440 | { |
---|
441 | $returned=array( |
---|
442 | UA_DATA_OS => $os, |
---|
443 | //'name' => $result[1], |
---|
444 | UA_DATA_OS_VERSION => isset($result[2])?$result[2]:'' |
---|
445 | ); |
---|
446 | switch($os) |
---|
447 | { |
---|
448 | case UA_OS_WINDOWS: |
---|
449 | switch($returned[UA_DATA_OS_VERSION]) |
---|
450 | { |
---|
451 | case 'NT 5.0': |
---|
452 | $returned['version']='2000'; |
---|
453 | break; |
---|
454 | case 'NT 5.1': |
---|
455 | $returned['version']='XP'; |
---|
456 | break; |
---|
457 | case 'NT 5.2': |
---|
458 | $returned['version']='Server 2003'; |
---|
459 | break; |
---|
460 | case 'NT 6.0': |
---|
461 | $returned['version']='Vista'; |
---|
462 | break; |
---|
463 | case 'NT 6.1': |
---|
464 | $returned['version']='Seven'; |
---|
465 | break; |
---|
466 | default; |
---|
467 | break; |
---|
468 | } |
---|
469 | break; |
---|
470 | } |
---|
471 | |
---|
472 | return($returned); |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | return($returned); |
---|
477 | } |
---|
478 | |
---|
479 | /** |
---|
480 | * return engine properties |
---|
481 | * |
---|
482 | * @param String $userAgent : user agent string to parse |
---|
483 | * @return Array |
---|
484 | */ |
---|
485 | static private function getEngine($userAgent) |
---|
486 | { |
---|
487 | $engineList=array( |
---|
488 | '(presto)(?:\/(\S*))*' => UA_ENGINE_PRESTO, |
---|
489 | '(applewebkit)(?:\/(\S*))*' => UA_ENGINE_APPLEWEBKIT, |
---|
490 | '(webkit)(?:\/(\S*))*' => UA_ENGINE_WEBKIT, |
---|
491 | '(khtml)(?:\/(\S*))*' => UA_ENGINE_KHTML, |
---|
492 | '(gecko)(?:\/(\S*))*' => UA_ENGINE_GECKO, |
---|
493 | '(trident)(?:\/(\S*))*' => UA_ENGINE_TRIDENT |
---|
494 | ); |
---|
495 | |
---|
496 | $returned=array( |
---|
497 | UA_DATA_ENGINE => UA_ENGINE_UNKNOWN, |
---|
498 | //'name' => '', |
---|
499 | UA_DATA_ENGINE_VERSION => '' |
---|
500 | ); |
---|
501 | |
---|
502 | $result=array(); |
---|
503 | foreach($engineList as $regExp => $engine) |
---|
504 | { |
---|
505 | if(preg_match('/'.$regExp.'/i',$userAgent,$result)) |
---|
506 | { |
---|
507 | $returned=array( |
---|
508 | UA_DATA_ENGINE => $engine, |
---|
509 | //'name' => $result[1], |
---|
510 | UA_DATA_ENGINE_VERSION => isset($result[2])?$result[2]:'' |
---|
511 | ); |
---|
512 | return($returned); |
---|
513 | } |
---|
514 | } |
---|
515 | |
---|
516 | return($returned); |
---|
517 | } |
---|
518 | } // GPCUserAgent class |
---|
519 | |
---|
520 | |
---|
521 | ?> |
---|