admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * User Agent Class |
| 20 | * |
| 21 | * Identifies the platform, browser, robot, or mobile devise of the browsing agent |
| 22 | * |
| 23 | * @package CodeIgniter |
| 24 | * @subpackage Libraries |
| 25 | * @category User Agent |
| 26 | * @author Rick Ellis |
| 27 | * @link http://www.codeigniter.com/user_guide/libraries/uri.html |
| 28 | */ |
| 29 | class CI_User_agent { |
| 30 | |
| 31 | var $agent = NULL; |
| 32 | |
| 33 | var $is_browser = FALSE; |
| 34 | var $is_robot = FALSE; |
| 35 | var $is_mobile = FALSE; |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 36 | |
| 37 | var $languages = array(); |
| 38 | var $charsets = array(); |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 39 | |
| 40 | var $platform = ''; |
| 41 | var $browser = ''; |
| 42 | var $version = ''; |
| 43 | var $moble = ''; |
| 44 | var $robot = ''; |
| 45 | |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 46 | var $platforms = array ( |
| 47 | 'windows nt 6.0' => 'Windows Longhorn', |
| 48 | 'windows nt 5.2' => 'Windows 2003', |
| 49 | 'windows nt 5.0' => 'Windows 2000', |
| 50 | 'windows nt 5.1' => 'Windows XP', |
| 51 | 'windows nt 4.0' => 'Windows NT 4.0', |
| 52 | 'winnt4.0' => 'Windows NT 4.0', |
| 53 | 'winnt 4.0' => 'Windows NT', |
| 54 | 'winnt' => 'Windows NT', |
| 55 | 'windows 98' => 'Windows 98', |
| 56 | 'win98' => 'Windows 98', |
| 57 | 'windows 95' => 'Windows 95', |
| 58 | 'win95' => 'Windows 95', |
| 59 | 'windows' => 'Unknown Windows OS', |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 60 | 'os x' => 'Mac OS X', |
| 61 | 'ppc mac' => 'Power PC Mac', |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 62 | 'freebsd' => 'FreeBSD', |
| 63 | 'ppc' => 'Macintosh', |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 64 | 'linux' => 'Linux', |
| 65 | 'debian' => 'Debian', |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 66 | 'sunos' => 'Sun Solaris', |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 67 | 'beos' => 'BeOS', |
| 68 | 'apachebench' => 'ApacheBench', |
| 69 | 'aix' => 'AIX', |
| 70 | 'irix' => 'Irix', |
| 71 | 'osf' => 'DEC OSF', |
| 72 | 'hp-ux' => 'HP-UX', |
| 73 | 'netbsd' => 'NetBSD', |
| 74 | 'bsdi' => 'BSDi', |
| 75 | 'openbsd' => 'OpenBSD', |
| 76 | 'gnu' => 'GNU/Linux', |
| 77 | 'unix' => 'Unknown Unix OS' |
| 78 | ); |
| 79 | |
| 80 | var $browsers = array( |
| 81 | 'Opera' => 'Opera', |
| 82 | 'MSIE' => 'Internet Explorer', |
| 83 | 'Internet Explorer' => 'Internet Explorer', |
| 84 | 'Shiira' => 'Shiira', |
| 85 | 'Firefox' => 'Firefox', |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 86 | 'Chimera' => 'Chimera', |
| 87 | 'Phoenix' => 'Phoenix', |
| 88 | 'Firebird' => 'Firebird', |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 89 | 'Camino' => 'Camino', |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 90 | 'Netscape' => 'Netscape', |
| 91 | 'OmniWeb' => 'OmniWeb', |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 92 | 'Mozilla' => 'Mozilla', |
| 93 | 'Safari' => 'Safari', |
| 94 | 'Konqueror' => 'Konqueror', |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 95 | 'icab' => 'iCab', |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 96 | 'Lynx' => 'Lynx', |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 97 | 'Links' => 'Links', |
| 98 | 'hotjava' => 'HotJava', |
| 99 | 'amaya' => 'Amaya', |
| 100 | 'IBrowse' => 'IBrowse' |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 101 | ); |
| 102 | |
| 103 | var $mobiles = array( |
| 104 | 'mobileexplorer' => 'Mobile Explorer', |
| 105 | 'openwave' => 'Open Wave', |
| 106 | 'opera mini' => 'Opera Mini', |
| 107 | 'operamini' => 'Opera Mini', |
| 108 | 'elaine' => 'Palm', |
| 109 | 'palmsource' => 'Palm', |
| 110 | 'digital paths' => 'Palm', |
| 111 | 'avantgo' => 'Avantgo', |
| 112 | 'xiino' => 'Xiino', |
| 113 | 'palmscape' => 'Palmscape', |
| 114 | 'nokia' => 'Nokia', |
| 115 | 'ericsson' => 'Ericsson', |
| 116 | 'blackBerry' => 'BlackBerry', |
| 117 | 'motorola' => 'Motorola' |
| 118 | ); |
| 119 | |
| 120 | var $robots = array( |
| 121 | |
| 122 | 'googlebot' => 'Googlebot', |
| 123 | 'msnbot' => 'MSNBot', |
| 124 | 'slurp' => 'Inktomi Slurp', |
| 125 | 'yahoo' => 'Yahoo', |
| 126 | 'askjeeves' => 'AskJeeves', |
| 127 | 'fastcrawler' => 'FastCrawler', |
| 128 | 'infoseek' => 'InfoSeek Robot 1.0', |
| 129 | 'lycos' => 'Lycos', |
| 130 | 'abcdatos' => 'ABCdatos BotLink', |
| 131 | 'Acme.Spider' => 'Acme.Spider', |
| 132 | 'ahoythehomepagefinder' => 'Ahoy! The Homepage Finder', |
| 133 | 'Alkaline' => 'Alkaline', |
| 134 | 'anthill' => 'Anthill', |
| 135 | 'appie' => 'Walhello appie', |
| 136 | 'arachnophilia' => 'Arachnophilia', |
| 137 | 'arale' => 'Arale', |
| 138 | 'araneo' => 'Araneo', |
| 139 | 'araybot' => 'AraybOt', |
| 140 | 'architext' => 'ArchitextSpider', |
| 141 | 'aretha' => 'Aretha', |
| 142 | 'ariadne' => 'ARIADNE', |
| 143 | 'arks' => 'arks', |
| 144 | 'aspider' => 'ASpider (Associative Spider)', |
| 145 | 'atn.txt' => 'ATN Worldwide', |
| 146 | 'atomz' => 'Atomz.com Search Robot', |
| 147 | 'auresys' => 'AURESYS', |
| 148 | 'backrub' => 'BackRub', |
| 149 | 'bbot' => 'BBot', |
| 150 | 'bigbrother' => 'Big Brother', |
| 151 | 'bjaaland' => 'Bjaaland', |
| 152 | 'blackwidow' => 'BlackWidow', |
| 153 | 'blindekuh' => 'Die Blinde Kuh', |
| 154 | 'Bloodhound' => 'Bloodhound', |
| 155 | 'borg-bot' => 'Borg-Bot', |
| 156 | 'boxseabot' => 'BoxSeaBot', |
| 157 | 'brightnet' => 'bright.net caching robot', |
| 158 | 'bspider' => 'BSpider', |
| 159 | 'cactvschemistryspider' => 'CACTVS Chemistry Spider', |
| 160 | 'calif' => 'Calif', |
| 161 | 'cassandra' => 'Cassandra', |
| 162 | 'cgireader' => 'Digimarc Marcspider/CGI', |
| 163 | 'checkbot' => 'Checkbot', |
| 164 | 'christcrawler' => 'ChristCrawler.com', |
| 165 | 'churl' => 'churl', |
| 166 | 'cienciaficcion' => 'cIeNcIaFiCcIoN.nEt', |
| 167 | 'cmc' => 'CMC/0.01', |
| 168 | 'Collective' => 'Collective', |
| 169 | 'combine' => 'Combine System', |
| 170 | 'confuzzledbot' => 'ConfuzzledBot', |
| 171 | 'coolbot' => 'CoolBot', |
| 172 | 'core' => 'Web Core / Roots', |
| 173 | 'cosmos' => 'XYLEME Robot', |
| 174 | 'cruiser' => 'Internet Cruiser Robot', |
| 175 | 'cusco' => 'Cusco', |
| 176 | 'cyberspyder' => 'CyberSpyder Link Test', |
| 177 | 'cydralspider' => 'CydralSpider', |
| 178 | 'desertrealm' => 'Desert Realm Spider', |
| 179 | 'deweb' => 'DeWeb(c) Katalog/Index', |
| 180 | 'dienstspider' => 'DienstSpider', |
| 181 | 'digger' => 'Digger', |
| 182 | 'diibot' => 'Digital Integrity Robot', |
| 183 | 'directhit' => 'Direct Hit Grabber', |
| 184 | 'dnabot' => 'DNAbot', |
| 185 | 'download_express' => 'DownLoad Express', |
| 186 | 'dragonbot' => 'DragonBot', |
| 187 | 'e-collector' => 'e-collector', |
| 188 | 'ebiness' => 'EbiNess', |
| 189 | 'eit' => 'EIT Link Verifier Robot', |
| 190 | 'elfinbot' => 'ELFINBOT', |
| 191 | 'emacs' => 'Emacs-w3 Search Engine', |
| 192 | 'emcspider' => 'ananzi', |
| 193 | 'esculapio' => 'esculapio', |
| 194 | 'esther' => 'Esther', |
| 195 | 'evliyacelebi' => 'Evliya Celebi', |
| 196 | 'nzexplorer' => 'nzexplorer', |
| 197 | 'fdse' => 'Fluid Dynamics Search Engine robot', |
| 198 | 'felix' => 'Felix IDE', |
| 199 | 'ferret' => 'Wild Ferret Web Hopper #1, #2, #3', |
| 200 | 'fetchrover' => 'FetchRover', |
| 201 | 'fido' => 'fido', |
| 202 | 'finnish' => 'Hämähäkki', |
| 203 | 'fireball' => 'KIT-Fireball', |
| 204 | 'fish' => 'Fish search', |
| 205 | 'fouineur' => 'Fouineur', |
| 206 | 'francoroute' => 'Robot Francoroute', |
| 207 | 'freecrawl' => 'Freecrawl', |
| 208 | 'funnelweb' => 'FunnelWeb', |
| 209 | 'gama' => 'gammaSpider, FocusedCrawler', |
| 210 | 'gazz' => 'gazz', |
| 211 | 'gcreep' => 'GCreep', |
| 212 | 'getbot' => 'GetBot', |
| 213 | 'geturl' => 'GetURL', |
| 214 | 'golem' => 'Golem', |
| 215 | 'grapnel' => 'Grapnel/0.01 Experiment', |
| 216 | 'griffon' => 'Griffon ', |
| 217 | 'gromit' => 'Gromit', |
| 218 | 'gulliver' => 'Northern Light Gulliver', |
| 219 | 'gulperbot' => 'Gulper Bot', |
| 220 | 'hambot' => 'HamBot', |
| 221 | 'harvest' => 'Harvest', |
| 222 | 'havindex' => 'havIndex', |
| 223 | 'hi' => 'HI (HTML Index) Search', |
| 224 | 'hometown' => 'Hometown Spider Pro', |
| 225 | 'wired-digital' => 'Wired Digital', |
| 226 | 'htdig' => 'ht://Dig', |
| 227 | 'htmlgobble' => 'HTMLgobble', |
| 228 | 'hyperdecontextualizer' => 'Hyper-Decontextualizer', |
| 229 | 'iajabot' => 'iajaBot', |
| 230 | 'ibm' => 'IBM_Planetwide', |
| 231 | 'iconoclast' => 'Popular Iconoclast', |
| 232 | 'Ilse' => 'Ingrid', |
| 233 | 'imagelock' => 'Imagelock ', |
| 234 | 'incywincy' => 'IncyWincy', |
| 235 | 'informant' => 'Informant', |
| 236 | 'infoseeksidewinder' => 'Infoseek Sidewinder', |
| 237 | 'infospider' => 'InfoSpiders', |
| 238 | 'inspectorwww' => 'Inspector Web', |
| 239 | 'intelliagent' => 'IntelliAgent', |
| 240 | 'irobot' => 'I, Robot', |
| 241 | 'iron33' => 'Iron33', |
| 242 | 'israelisearch' => 'Israeli-search', |
| 243 | 'javabee' => 'JavaBee', |
| 244 | 'JBot' => 'JBot Java Web Robot', |
| 245 | 'jcrawler' => 'JCrawler', |
| 246 | 'jobo' => 'JoBo Java Web Robot', |
| 247 | 'jobot' => 'Jobot', |
| 248 | 'joebot' => 'JoeBot', |
| 249 | 'jubii' => 'The Jubii Indexing Robot', |
| 250 | 'jumpstation' => 'JumpStation', |
| 251 | 'kapsi' => 'image.kapsi.net', |
| 252 | 'katipo' => 'Katipo', |
| 253 | 'kdd' => 'KDD-Explorer', |
| 254 | 'kilroy' => 'Kilroy', |
| 255 | 'ko_yappo_robot' => 'KO_Yappo_Robot', |
| 256 | 'labelgrabber.txt' => 'LabelGrabber', |
| 257 | 'larbin' => 'larbin', |
| 258 | 'legs' => 'legs', |
| 259 | 'linkidator' => 'Link Validator', |
| 260 | 'linkscan' => 'LinkScan', |
| 261 | 'linkwalker' => 'LinkWalker', |
| 262 | 'lockon' => 'Lockon', |
| 263 | 'logo_gif' => 'logo.gif Crawler', |
| 264 | 'magpie' => 'Magpie', |
| 265 | 'marvin' => 'marvin/infoseek', |
| 266 | 'mattie' => 'Mattie', |
| 267 | 'mediafox' => 'MediaFox', |
| 268 | 'merzscope' => 'MerzScope', |
| 269 | 'meshexplorer' => 'NEC-MeshExplorer', |
| 270 | 'MindCrawler' => 'MindCrawler', |
| 271 | 'mnogosearch' => 'mnoGoSearch search engine software', |
| 272 | 'moget' => 'moget', |
| 273 | 'momspider' => 'MOMspider', |
| 274 | 'monster' => 'Monster', |
| 275 | 'motor' => 'Motor', |
| 276 | 'muncher' => 'Muncher', |
| 277 | 'muninn' => 'Muninn', |
| 278 | 'muscatferret' => 'Muscat Ferret', |
| 279 | 'mwdsearch' => 'Mwd.Search', |
| 280 | 'myweb' => 'Internet Shinchakubin', |
| 281 | 'NDSpider' => 'NDSpider', |
| 282 | 'netcarta' => 'NetCarta WebMap Engine', |
| 283 | 'netmechanic' => 'NetMechanic', |
| 284 | 'netscoop' => 'NetScoop', |
| 285 | 'newscan-online' => 'newscan-online', |
| 286 | 'nhse' => 'NHSE Web Forager', |
| 287 | 'nomad' => 'Nomad', |
| 288 | 'northstar' => 'The NorthStar Robot', |
| 289 | 'objectssearch' => 'ObjectsSearch', |
| 290 | 'occam' => 'Occam', |
| 291 | 'octopus' => 'HKU WWW Octopus', |
| 292 | 'OntoSpider' => 'OntoSpider', |
| 293 | 'openfind' => 'Openfind data gatherer', |
| 294 | 'orb_search' => 'Orb Search', |
| 295 | 'packrat' => 'Pack Rat', |
| 296 | 'pageboy' => 'PageBoy', |
| 297 | 'parasite' => 'ParaSite', |
| 298 | 'patric' => 'Patric', |
| 299 | 'pegasus' => 'pegasus', |
| 300 | 'perignator' => 'The Peregrinator', |
| 301 | 'perlcrawler' => 'PerlCrawler 1.0', |
| 302 | 'phantom' => 'Phantom', |
| 303 | 'phpdig' => 'PhpDig', |
| 304 | 'pitkow' => 'html_analyzer', |
| 305 | 'pjspider' => 'Portal Juice Spider', |
| 306 | 'pka' => 'PGP Key Agent', |
| 307 | 'poppi' => 'Poppi', |
| 308 | 'portalb' => 'PortalB Spider', |
| 309 | 'psbot' => 'psbot', |
| 310 | 'Puu' => 'GetterroboPlus Puu', |
| 311 | 'python' => 'The Python Robot', |
| 312 | 'raven ' => 'Raven Search', |
| 313 | 'rbse' => 'RBSE Spider', |
| 314 | 'resumerobot' => 'Resume Robot', |
| 315 | 'rhcs' => 'RoadHouse Crawling System', |
| 316 | 'rixbot' => 'RixBot', |
| 317 | 'roadrunner' => 'Road Runner: The ImageScape Robot', |
| 318 | 'robbie' => 'Robbie the Robot', |
| 319 | 'robi' => 'ComputingSite Robi/1.0', |
| 320 | 'robocrawl' => 'RoboCrawl Spider', |
| 321 | 'robofox' => 'RoboFox', |
| 322 | 'robozilla' => 'Robozilla', |
| 323 | 'roverbot' => 'Roverbot', |
| 324 | 'rules' => 'RuLeS', |
| 325 | 'safetynetrobot' => 'SafetyNet Robot', |
| 326 | 'scooter' => 'Scooter', |
| 327 | 'search_au' => 'Search.Aus-AU.COM', |
| 328 | 'search-info' => 'Sleek', |
| 329 | 'searchprocess' => 'SearchProcess', |
| 330 | 'senrigan' => 'Senrigan', |
| 331 | 'sgscout' => 'SG-Scout', |
| 332 | 'shaggy' => 'ShagSeeker', |
| 333 | 'sift' => 'Sift', |
| 334 | 'simbot' => 'Simmany Robot Ver1.0', |
| 335 | 'site-valet' => 'Site Valet', |
| 336 | 'sitetech' => 'SiteTech-Rover', |
| 337 | 'skymob' => 'Skymob.com', |
| 338 | 'slcrawler' => 'SLCrawler', |
| 339 | 'smartspider' => 'Smart Spider', |
| 340 | 'snooper' => 'Snooper', |
| 341 | 'solbot' => 'Solbot', |
| 342 | 'speedy' => 'Speedy Spider', |
| 343 | 'spider_monkey' => 'spider_monkey', |
| 344 | 'spiderbot' => 'SpiderBot', |
| 345 | 'spiderline' => 'Spiderline Crawler', |
| 346 | 'spiderman' => 'SpiderMan', |
| 347 | 'spiderview' => 'SpiderView(tm)', |
| 348 | 'spry' => 'Spry Wizard Robot', |
| 349 | 'ssearcher' => 'Site Searcher', |
| 350 | 'suke' => 'Suke', |
| 351 | 'suntek' => 'suntek search engine', |
| 352 | 'sven' => 'Sven', |
| 353 | 'sygol' => 'Sygol ', |
| 354 | 'tach_bw' => 'TACH Black Widow', |
| 355 | 'tarantula' => 'Tarantula', |
| 356 | 'tarspider' => 'tarspider', |
| 357 | 'tcl' => 'Tcl W3 Robot', |
| 358 | 'techbot' => 'TechBOT', |
| 359 | 'templeton' => 'Templeton', |
| 360 | 'titin' => 'TitIn', |
| 361 | 'titan' => 'TITAN', |
| 362 | 'tkwww' => 'The TkWWW Robot', |
| 363 | 'tlspider' => 'TLSpider', |
| 364 | 'ucsd' => 'UCSD Crawl', |
| 365 | 'udmsearch' => 'UdmSearch', |
| 366 | 'ultraseek' => 'Ultraseek', |
| 367 | 'uptimebot' => 'UptimeBot', |
| 368 | 'urlck' => 'URL Check', |
| 369 | 'valkyrie' => 'Valkyrie', |
| 370 | 'verticrawl' => 'Verticrawl', |
| 371 | 'victoria' => 'Victoria', |
| 372 | 'visionsearch' => 'vision-search', |
| 373 | 'voidbot' => 'void-bot', |
| 374 | 'voyager' => 'Voyager', |
| 375 | 'vwbot' => 'VWbot', |
| 376 | 'w3index' => 'The NWI Robot', |
| 377 | 'w3m2' => 'W3M2', |
| 378 | 'wallpaper' => 'WallPaper (alias crawlpaper)', |
| 379 | 'wanderer' => 'the World Wide Web Wanderer', |
| 380 | 'wapspider' => 'w@pSpider by wap4.com', |
| 381 | 'webbandit' => 'WebBandit Web Spider', |
| 382 | 'webcatcher' => 'WebCatcher', |
| 383 | 'webcopy' => 'WebCopy', |
| 384 | 'webfetcher' => 'webfetcher', |
| 385 | 'webfoot' => 'The Webfoot Robot', |
| 386 | 'webinator' => 'Webinator', |
| 387 | 'weblayers' => 'weblayers', |
| 388 | 'weblinker' => 'WebLinker', |
| 389 | 'webmirror' => 'WebMirror', |
| 390 | 'webmoose' => 'The Web Moose', |
| 391 | 'webquest' => 'WebQuest', |
| 392 | 'webreader' => 'Digimarc MarcSpider', |
| 393 | 'webreaper' => 'WebReaper', |
| 394 | 'webs' => 'webs', |
| 395 | 'websnarf' => 'Websnarf', |
| 396 | 'webspider' => 'WebSpider', |
| 397 | 'webvac' => 'WebVac', |
| 398 | 'webwalk' => 'webwalk', |
| 399 | 'webwalker' => 'WebWalker', |
| 400 | 'webwatch' => 'WebWatch', |
| 401 | 'wget' => 'Wget', |
| 402 | 'whatuseek' => 'whatUseek Winona', |
| 403 | 'whowhere' => 'WhoWhere Robot', |
| 404 | 'wlm' => 'Weblog Monitor', |
| 405 | 'wmir' => 'w3mir', |
| 406 | 'wolp' => 'WebStolperer', |
| 407 | 'wombat' => 'The Web Wombat ', |
| 408 | 'worm' => 'The World Wide Web Worm', |
| 409 | 'wwwc' => 'WWWC Ver 0.2.5', |
| 410 | 'wz101' => 'WebZinger', |
| 411 | 'xget' => 'XGET', |
| 412 | ); |
| 413 | |
| 414 | |
| 415 | |
| 416 | /** |
| 417 | * Constructor |
| 418 | * |
| 419 | * Sets the User Agent and runs the compilation routine |
| 420 | * |
| 421 | * @access public |
| 422 | * @return void |
| 423 | */ |
| 424 | function CI_User_agent() |
| 425 | { |
| 426 | if (isset($_SERVER['HTTP_USER_AGENT'])) |
| 427 | { |
| 428 | $this->agent = trim($_SERVER['HTTP_USER_AGENT']); |
| 429 | } |
| 430 | |
| 431 | if ( ! is_null($this->agent)) |
| 432 | { |
| 433 | $this->_compile_data(); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | // -------------------------------------------------------------------- |
| 438 | |
| 439 | /** |
| 440 | * Compile the User Agent Data |
| 441 | * |
| 442 | * @access private |
| 443 | * @return bool |
| 444 | */ |
| 445 | function _compile_data() |
| 446 | { |
| 447 | $this->_set_platform(); |
| 448 | |
| 449 | foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) |
| 450 | { |
| 451 | if ($this->$function() === TRUE) |
| 452 | { |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | // -------------------------------------------------------------------- |
| 459 | |
| 460 | /** |
| 461 | * Set the Platform |
| 462 | * |
| 463 | * @access private |
| 464 | * @return mixed |
| 465 | */ |
| 466 | function _set_platform() |
| 467 | { |
| 468 | foreach ($this->platforms as $key => $val) |
| 469 | { |
| 470 | if (preg_match("|$key|i", $this->agent)) |
| 471 | { |
| 472 | $this->platform = $val; |
| 473 | return TRUE; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | $this->platform = 'Unknown Platform'; |
| 478 | } |
| 479 | |
| 480 | // -------------------------------------------------------------------- |
| 481 | |
| 482 | /** |
| 483 | * Set the Browser |
| 484 | * |
| 485 | * @access private |
| 486 | * @return bool |
| 487 | */ |
| 488 | function _set_browser() |
| 489 | { |
| 490 | foreach ($this->browsers as $key => $val) |
| 491 | { |
| 492 | if (preg_match("|".$key.".*?([0-9\.]+)|i", $this->agent, $match)) |
| 493 | { |
| 494 | $this->is_browser = TRUE; |
| 495 | $this->version = $match[1]; |
| 496 | $this->browser = $val; |
| 497 | return TRUE; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | return FALSE; |
| 502 | } |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 503 | |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 504 | // -------------------------------------------------------------------- |
| 505 | |
| 506 | /** |
| 507 | * Set the Robot |
| 508 | * |
| 509 | * @access private |
| 510 | * @return bool |
| 511 | */ |
| 512 | function _set_robot() |
| 513 | { |
| 514 | foreach ($this->robots as $key => $val) |
| 515 | { |
| 516 | if (preg_match("|$key|i", $this->agent)) |
| 517 | { |
| 518 | $this->is_robot = TRUE; |
| 519 | $this->robot = $val; |
| 520 | return TRUE; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return FALSE; |
| 525 | } |
| 526 | |
| 527 | // -------------------------------------------------------------------- |
| 528 | |
| 529 | /** |
| 530 | * Set the Mobile Devise |
| 531 | * |
| 532 | * @access private |
| 533 | * @return bool |
| 534 | */ |
| 535 | function _set_mobile() |
| 536 | { |
| 537 | foreach ($this->mobiles as $key => $val) |
| 538 | { |
| 539 | if (FALSE !== (strpos(strtolower($this->agent), $key))) |
| 540 | { |
| 541 | $this->is_mobile = TRUE; |
| 542 | $this->mobile = $val; |
| 543 | return TRUE; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return FALSE; |
| 548 | } |
| 549 | |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 550 | // -------------------------------------------------------------------- |
| 551 | |
| 552 | /** |
| 553 | * Set the accepted languages |
| 554 | * |
| 555 | * @access private |
| 556 | * @return void |
| 557 | */ |
| 558 | function _set_languages() |
| 559 | { |
| 560 | if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') |
| 561 | { |
| 562 | $languages = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']); |
| 563 | |
| 564 | $this->languages = explode(',', $languages); |
| 565 | } |
| 566 | |
| 567 | if (count($this->languages) == 0) |
| 568 | { |
| 569 | $this->languages = array('Undefined'); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | // -------------------------------------------------------------------- |
| 574 | |
| 575 | /** |
| 576 | * Set the accepted character sets |
| 577 | * |
| 578 | * @access private |
| 579 | * @return void |
| 580 | */ |
| 581 | function _set_charsets() |
| 582 | { |
| 583 | if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') |
| 584 | { |
| 585 | $charsets = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_CHARSET']); |
| 586 | |
| 587 | $this->charsets = explode(',', $charsets); |
| 588 | } |
| 589 | |
| 590 | if (count($this->charsets) == 0) |
| 591 | { |
| 592 | $this->charsets = array('Undefined'); |
| 593 | } |
| 594 | } |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 595 | |
| 596 | // -------------------------------------------------------------------- |
| 597 | |
| 598 | /** |
| 599 | * Is Browser |
| 600 | * |
| 601 | * @access public |
| 602 | * @return bool |
| 603 | */ |
| 604 | function is_browser() |
| 605 | { |
| 606 | return $this->is_browser; |
| 607 | } |
| 608 | |
| 609 | // -------------------------------------------------------------------- |
| 610 | |
| 611 | /** |
| 612 | * Is Robot |
| 613 | * |
| 614 | * @access public |
| 615 | * @return bool |
| 616 | */ |
| 617 | function is_robot() |
| 618 | { |
| 619 | return $this->is_robot; |
| 620 | } |
| 621 | |
| 622 | // -------------------------------------------------------------------- |
| 623 | |
| 624 | /** |
| 625 | * Is Mobile |
| 626 | * |
| 627 | * @access public |
| 628 | * @return bool |
| 629 | */ |
| 630 | function is_mobile() |
| 631 | { |
| 632 | return $this->is_mobile; |
| 633 | } |
| 634 | |
| 635 | // -------------------------------------------------------------------- |
| 636 | |
| 637 | /** |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 638 | * Is this a referral from another site? |
| 639 | * |
| 640 | * @access public |
| 641 | * @return bool |
| 642 | */ |
| 643 | function is_referral() |
| 644 | { |
| 645 | return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; |
| 646 | } |
| 647 | |
| 648 | // -------------------------------------------------------------------- |
| 649 | |
| 650 | /** |
| 651 | * Agent String |
| 652 | * |
| 653 | * @access public |
| 654 | * @return string |
| 655 | */ |
| 656 | function agent() |
| 657 | { |
| 658 | return $this->agent; |
| 659 | } |
| 660 | |
| 661 | // -------------------------------------------------------------------- |
| 662 | |
| 663 | /** |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 664 | * Get Platform |
| 665 | * |
| 666 | * @access public |
| 667 | * @return string |
| 668 | */ |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 669 | function platform() |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 670 | { |
| 671 | return $this->platform; |
| 672 | } |
| 673 | |
| 674 | // -------------------------------------------------------------------- |
| 675 | |
| 676 | /** |
| 677 | * Get Browser Name |
| 678 | * |
| 679 | * @access public |
| 680 | * @return string |
| 681 | */ |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 682 | function browser() |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 683 | { |
| 684 | return $this->browser; |
| 685 | } |
| 686 | |
| 687 | // -------------------------------------------------------------------- |
| 688 | |
| 689 | /** |
| 690 | * Get the Browser Version |
| 691 | * |
| 692 | * @access public |
| 693 | * @return string |
| 694 | */ |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 695 | function version() |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 696 | { |
| 697 | return $this->version; |
| 698 | } |
| 699 | |
| 700 | // -------------------------------------------------------------------- |
| 701 | |
| 702 | /** |
| 703 | * Get The Robot Name |
| 704 | * |
| 705 | * @access public |
| 706 | * @return string |
| 707 | */ |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 708 | function robot() |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 709 | { |
| 710 | return $this->robot; |
| 711 | } |
| 712 | // -------------------------------------------------------------------- |
| 713 | |
| 714 | /** |
| 715 | * Get the Mobile Devise |
| 716 | * |
| 717 | * @access public |
| 718 | * @return string |
| 719 | */ |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 720 | function mobile() |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 721 | { |
| 722 | return $this->mobile; |
| 723 | } |
| 724 | |
admin | 6c9f736 | 2006-10-09 03:33:48 +0000 | [diff] [blame^] | 725 | // -------------------------------------------------------------------- |
| 726 | |
| 727 | /** |
| 728 | * Get the referrer |
| 729 | * |
| 730 | * @access public |
| 731 | * @return bool |
| 732 | */ |
| 733 | function referrer() |
| 734 | { |
| 735 | return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : $_SERVER['HTTP_REFERER']; |
| 736 | } |
| 737 | |
| 738 | // -------------------------------------------------------------------- |
| 739 | |
| 740 | /** |
| 741 | * Get the accepted languages |
| 742 | * |
| 743 | * @access public |
| 744 | * @return array |
| 745 | */ |
| 746 | function languages() |
| 747 | { |
| 748 | if (count($this->languages) == 0) |
| 749 | { |
| 750 | $this->_set_languages(); |
| 751 | } |
| 752 | |
| 753 | return $this->languages; |
| 754 | } |
| 755 | |
| 756 | // -------------------------------------------------------------------- |
| 757 | |
| 758 | /** |
| 759 | * Get the accepted Character Sets |
| 760 | * |
| 761 | * @access public |
| 762 | * @return array |
| 763 | */ |
| 764 | function charsets() |
| 765 | { |
| 766 | if (count($this->charsets) == 0) |
| 767 | { |
| 768 | $this->_set_charsets(); |
| 769 | } |
| 770 | |
| 771 | return $this->charsets; |
| 772 | } |
| 773 | |
| 774 | // -------------------------------------------------------------------- |
| 775 | |
| 776 | /** |
| 777 | * Test for a particular language |
| 778 | * |
| 779 | * @access public |
| 780 | * @return bool |
| 781 | */ |
| 782 | function accept_lang($lang = 'en') |
| 783 | { |
| 784 | return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; |
| 785 | } |
| 786 | |
| 787 | // -------------------------------------------------------------------- |
| 788 | |
| 789 | /** |
| 790 | * Test for a particular character set |
| 791 | * |
| 792 | * @access public |
| 793 | * @return bool |
| 794 | */ |
| 795 | function accept_charset($charset = 'utf-8') |
| 796 | { |
| 797 | return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; |
| 798 | } |
| 799 | |
admin | df752b2 | 2006-10-08 07:17:13 +0000 | [diff] [blame] | 800 | |
| 801 | } |
| 802 | |
| 803 | ?> |