blob: 0ac605fa40cfe5e571c0a66f86c031d6151d8529 [file] [log] [blame]
Andrey Andreeve9ccf742011-12-25 17:30:10 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreeve9ccf742011-12-25 17:30:10 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreeve9ccf742011-12-25 17:30:10 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * User Agent Class
30 *
cenk115e9982011-09-27 10:07:53 +030031 * Identifies the platform, browser, robot, or mobile device of the browsing agent
Derek Allard2067d1a2008-11-13 22:59:24 +000032 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category User Agent
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/libraries/user_agent.html
38 */
39class CI_User_agent {
40
Timothy Warren0688ac92012-04-20 10:25:04 -040041 /**
42 * Current user-agent
43 *
44 * @var string
45 */
46 public $agent = NULL;
Barry Mienydd671972010-10-04 16:33:58 +020047
Timothy Warren0688ac92012-04-20 10:25:04 -040048 /**
49 * Flag for if the user-agent belongs to a browser
50 *
51 * @var bool
52 */
53 public $is_browser = FALSE;
54
55 /**
56 * Flag for if the user-agent is a robot
57 *
58 * @var bool
59 */
60 public $is_robot = FALSE;
61
62 /**
63 * Flag for if the user-agent is a mobile browser
64 *
65 * @var bool
66 */
67 public $is_mobile = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000068
Timothy Warren0688ac92012-04-20 10:25:04 -040069 /**
70 * Languages accepted by the current user agent
71 *
72 * @var array
73 */
74 public $languages = array();
75
76 /**
77 * Character sets accepted by the current user agent
78 *
79 * @var array
80 */
81 public $charsets = array();
Barry Mienydd671972010-10-04 16:33:58 +020082
Timothy Warren0688ac92012-04-20 10:25:04 -040083 /**
84 * List of platforms to compare against current user agent
85 *
86 * @var array
87 */
88 public $platforms = array();
89
90 /**
91 * List of browsers to compare against current user agent
92 *
93 * @var array
94 */
95 public $browsers = array();
96
97 /**
98 * List of mobile browsers to compare against current user agent
99 *
100 * @var array
101 */
102 public $mobiles = array();
103
104 /**
105 * List of robots to compare against current user agent
106 *
107 * @var array
108 */
109 public $robots = array();
Barry Mienydd671972010-10-04 16:33:58 +0200110
Timothy Warren0688ac92012-04-20 10:25:04 -0400111 /**
112 * Current user-agent platform
113 *
114 * @var string
115 */
116 public $platform = '';
117
118 /**
119 * Current user-agent browser
120 *
121 * @var string
122 */
123 public $browser = '';
124
125 /**
126 * Current user-agent version
127 *
128 * @var string
129 */
130 public $version = '';
131
132 /**
133 * Current user-agent mobile name
134 *
135 * @var string
136 */
137 public $mobile = '';
138
139 /**
140 * Current user-agent robot name
141 *
142 * @var string
143 */
144 public $robot = '';
Barry Mienydd671972010-10-04 16:33:58 +0200145
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 /**
147 * Constructor
148 *
149 * Sets the User Agent and runs the compilation routine
150 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200152 */
Greg Akera9263282010-11-10 15:26:43 -0600153 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 {
155 if (isset($_SERVER['HTTP_USER_AGENT']))
156 {
157 $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
158 }
Barry Mienydd671972010-10-04 16:33:58 +0200159
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300160 if ( ! is_null($this->agent) && $this->_load_agent_file())
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300162 $this->_compile_data();
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 }
Barry Mienydd671972010-10-04 16:33:58 +0200164
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300165 log_message('debug', 'User Agent Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 }
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 /**
171 * Compile the User Agent Data
172 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200174 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200175 protected function _load_agent_file()
Derek Allard2067d1a2008-11-13 22:59:24 +0000176 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300177 if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
Greg Akerd96f8822011-12-27 16:23:47 -0600178 {
179 include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
180 }
181 elseif (is_file(APPPATH.'config/user_agents.php'))
182 {
183 include(APPPATH.'config/user_agents.php');
184 }
185 else
bubbafoley0ea04142011-03-17 14:55:41 -0500186 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000187 return FALSE;
188 }
Barry Mienydd671972010-10-04 16:33:58 +0200189
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 $return = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 if (isset($platforms))
193 {
194 $this->platforms = $platforms;
195 unset($platforms);
196 $return = TRUE;
197 }
198
199 if (isset($browsers))
200 {
201 $this->browsers = $browsers;
202 unset($browsers);
203 $return = TRUE;
204 }
205
206 if (isset($mobiles))
207 {
208 $this->mobiles = $mobiles;
209 unset($mobiles);
210 $return = TRUE;
211 }
Barry Mienydd671972010-10-04 16:33:58 +0200212
Derek Allard2067d1a2008-11-13 22:59:24 +0000213 if (isset($robots))
214 {
215 $this->robots = $robots;
216 unset($robots);
217 $return = TRUE;
218 }
219
220 return $return;
221 }
Barry Mienydd671972010-10-04 16:33:58 +0200222
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200224
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 /**
226 * Compile the User Agent Data
227 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000228 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200229 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200230 protected function _compile_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 {
232 $this->_set_platform();
Barry Mienydd671972010-10-04 16:33:58 +0200233
Phil Sturgeon2c547df2011-08-10 08:36:02 -0600234 foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 {
236 if ($this->$function() === TRUE)
237 {
238 break;
239 }
Barry Mienydd671972010-10-04 16:33:58 +0200240 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 }
Barry Mienydd671972010-10-04 16:33:58 +0200242
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200244
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 /**
246 * Set the Platform
247 *
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300248 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200249 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200250 protected function _set_platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300252 if (is_array($this->platforms) && count($this->platforms) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 {
254 foreach ($this->platforms as $key => $val)
255 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300256 if (preg_match('|'.preg_quote($key).'|i', $this->agent))
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 {
258 $this->platform = $val;
259 return TRUE;
260 }
261 }
262 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300263
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 $this->platform = 'Unknown Platform';
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300265 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 }
267
268 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200269
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 /**
271 * Set the Browser
272 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200274 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200275 protected function _set_browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300277 if (is_array($this->browsers) && count($this->browsers) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 {
279 foreach ($this->browsers as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200280 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300281 if (preg_match('|'.preg_quote($key).'.*?([0-9\.]+)|i', $this->agent, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 {
283 $this->is_browser = TRUE;
284 $this->version = $match[1];
285 $this->browser = $val;
286 $this->_set_mobile();
287 return TRUE;
288 }
289 }
290 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300291
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 return FALSE;
293 }
Barry Mienydd671972010-10-04 16:33:58 +0200294
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200296
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 /**
298 * Set the Robot
299 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200301 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200302 protected function _set_robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300304 if (is_array($this->robots) && count($this->robots) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200305 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 foreach ($this->robots as $key => $val)
307 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300308 if (preg_match('|'.preg_quote($key).'|i', $this->agent))
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 {
310 $this->is_robot = TRUE;
311 $this->robot = $val;
312 return TRUE;
313 }
314 }
315 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300316
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 return FALSE;
318 }
319
320 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200321
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 /**
323 * Set the Mobile Device
324 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200326 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200327 protected function _set_mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300329 if (is_array($this->mobiles) && count($this->mobiles) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200330 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 foreach ($this->mobiles as $key => $val)
332 {
333 if (FALSE !== (strpos(strtolower($this->agent), $key)))
334 {
335 $this->is_mobile = TRUE;
336 $this->mobile = $val;
337 return TRUE;
338 }
339 }
Barry Mienydd671972010-10-04 16:33:58 +0200340 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300341
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 return FALSE;
343 }
Barry Mienydd671972010-10-04 16:33:58 +0200344
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 /**
348 * Set the accepted languages
349 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200351 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200352 protected function _set_languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300354 if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200356 $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 }
Barry Mienydd671972010-10-04 16:33:58 +0200358
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200359 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 {
361 $this->languages = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200362 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 }
Barry Mienydd671972010-10-04 16:33:58 +0200364
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200366
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 /**
368 * Set the accepted character sets
369 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200371 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200372 protected function _set_charsets()
Barry Mienydd671972010-10-04 16:33:58 +0200373 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300374 if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000375 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200376 $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 }
Barry Mienydd671972010-10-04 16:33:58 +0200378
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200379 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
381 $this->charsets = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200382 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 }
384
385 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200386
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 /**
388 * Is Browser
389 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400390 * @param string $key
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200392 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000393 public function is_browser($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000395 if ( ! $this->is_browser)
396 {
397 return FALSE;
398 }
399
400 // No need to be specific, it's a browser
401 if ($key === NULL)
402 {
403 return TRUE;
404 }
405
406 // Check for a specific browser
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300407 return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 }
409
410 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 /**
413 * Is Robot
414 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400415 * @param string $key
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200417 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000418 public function is_robot($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000420 if ( ! $this->is_robot)
421 {
422 return FALSE;
423 }
424
425 // No need to be specific, it's a robot
426 if ($key === NULL)
427 {
428 return TRUE;
429 }
430
431 // Check for a specific robot
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300432 return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 }
434
435 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200436
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 /**
438 * Is Mobile
439 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400440 * @param string $key
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200442 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000443 public function is_mobile($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000445 if ( ! $this->is_mobile)
446 {
447 return FALSE;
448 }
449
450 // No need to be specific, it's a mobile
451 if ($key === NULL)
452 {
453 return TRUE;
454 }
455
456 // Check for a specific robot
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300457 return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]);
Barry Mienydd671972010-10-04 16:33:58 +0200458 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000459
460 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200461
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 /**
463 * Is this a referral from another site?
464 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200466 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000467 public function is_referral()
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300469 return ! empty($_SERVER['HTTP_REFERER']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 }
471
472 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200473
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 /**
475 * Agent String
476 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200478 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000479 public function agent_string()
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 {
481 return $this->agent;
482 }
483
484 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 /**
487 * Get Platform
488 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200490 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000491 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 {
493 return $this->platform;
494 }
495
496 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200497
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 /**
499 * Get Browser Name
500 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000501 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200502 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000503 public function browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 {
505 return $this->browser;
506 }
507
508 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200509
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 /**
511 * Get the Browser Version
512 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200514 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000515 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 {
517 return $this->version;
518 }
519
520 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200521
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 /**
523 * Get The Robot Name
524 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200526 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000527 public function robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 {
529 return $this->robot;
530 }
531 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200532
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 /**
534 * Get the Mobile Device
535 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200537 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000538 public function mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 {
540 return $this->mobile;
541 }
Barry Mienydd671972010-10-04 16:33:58 +0200542
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200544
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 /**
546 * Get the referrer
547 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000548 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200549 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000550 public function referrer()
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300552 return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 }
554
555 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200556
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 /**
558 * Get the accepted languages
559 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200561 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000562 public function languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200564 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000565 {
566 $this->_set_languages();
567 }
Barry Mienydd671972010-10-04 16:33:58 +0200568
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 return $this->languages;
570 }
571
572 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200573
Derek Allard2067d1a2008-11-13 22:59:24 +0000574 /**
575 * Get the accepted Character Sets
576 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200578 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000579 public function charsets()
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200581 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000582 {
583 $this->_set_charsets();
584 }
Barry Mienydd671972010-10-04 16:33:58 +0200585
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 return $this->charsets;
587 }
Barry Mienydd671972010-10-04 16:33:58 +0200588
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200590
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 /**
592 * Test for a particular language
593 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400594 * @param string $lang
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200596 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000597 public function accept_lang($lang = 'en')
Derek Allard2067d1a2008-11-13 22:59:24 +0000598 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300599 return in_array(strtolower($lang), $this->languages(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000600 }
Barry Mienydd671972010-10-04 16:33:58 +0200601
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200603
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 /**
605 * Test for a particular character set
606 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400607 * @param string $charset
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200609 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000610 public function accept_charset($charset = 'utf-8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300612 return in_array(strtolower($charset), $this->charsets(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 }
Barry Mienydd671972010-10-04 16:33:58 +0200614
Derek Allard2067d1a2008-11-13 22:59:24 +0000615}
616
Derek Allard2067d1a2008-11-13 22:59:24 +0000617/* End of file User_agent.php */
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300618/* Location: ./system/libraries/User_agent.php */