blob: 3387d4aa6a4eb1df7fc42ae3fd0a0e177979797c [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;
Andrey Andreevca7d8222012-05-11 10:59:09 +030054
Timothy Warren0688ac92012-04-20 10:25:04 -040055 /**
56 * Flag for if the user-agent is a robot
57 *
58 * @var bool
59 */
60 public $is_robot = FALSE;
Andrey Andreevca7d8222012-05-11 10:59:09 +030061
Timothy Warren0688ac92012-04-20 10:25:04 -040062 /**
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();
Andrey Andreevca7d8222012-05-11 10:59:09 +030075
Timothy Warren0688ac92012-04-20 10:25:04 -040076 /**
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();
Andrey Andreevca7d8222012-05-11 10:59:09 +030089
Timothy Warren0688ac92012-04-20 10:25:04 -040090 /**
91 * List of browsers to compare against current user agent
92 *
93 * @var array
94 */
95 public $browsers = array();
Andrey Andreevca7d8222012-05-11 10:59:09 +030096
Timothy Warren0688ac92012-04-20 10:25:04 -040097 /**
98 * List of mobile browsers to compare against current user agent
99 *
100 * @var array
101 */
102 public $mobiles = array();
Andrey Andreevca7d8222012-05-11 10:59:09 +0300103
Timothy Warren0688ac92012-04-20 10:25:04 -0400104 /**
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 = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300117
Timothy Warren0688ac92012-04-20 10:25:04 -0400118 /**
119 * Current user-agent browser
120 *
121 * @var string
122 */
123 public $browser = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300124
Timothy Warren0688ac92012-04-20 10:25:04 -0400125 /**
126 * Current user-agent version
127 *
128 * @var string
129 */
130 public $version = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300131
Timothy Warren0688ac92012-04-20 10:25:04 -0400132 /**
133 * Current user-agent mobile name
134 *
135 * @var string
136 */
137 public $mobile = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300138
Timothy Warren0688ac92012-04-20 10:25:04 -0400139 /**
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 {
Andrey Andreevca7d8222012-05-11 10:59:09 +0300333 if (FALSE !== (stripos($this->agent, $key)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 {
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 Andreeva0836b92012-10-24 22:03:42 +0300469 if (empty($_SERVER['HTTP_REFERER']))
470 {
471 return FALSE;
472 }
473
474 $referer = parse_url($_SERVER['HTTP_REFERER']);
475 return ! (empty($referer['host']) && strpos(config_item('base_url'), $referer['host']) !== FALSE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 }
477
478 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200479
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 /**
481 * Agent String
482 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200484 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000485 public function agent_string()
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 {
487 return $this->agent;
488 }
489
490 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200491
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 /**
493 * Get Platform
494 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200496 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000497 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 {
499 return $this->platform;
500 }
501
502 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200503
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 /**
505 * Get Browser Name
506 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200508 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000509 public function browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 {
511 return $this->browser;
512 }
513
514 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200515
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 /**
517 * Get the Browser Version
518 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200520 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000521 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 {
523 return $this->version;
524 }
525
526 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200527
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 /**
529 * Get The Robot Name
530 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000531 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200532 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000533 public function robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 {
535 return $this->robot;
536 }
537 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200538
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 /**
540 * Get the Mobile Device
541 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200543 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000544 public function mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 {
546 return $this->mobile;
547 }
Barry Mienydd671972010-10-04 16:33:58 +0200548
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 /**
552 * Get the referrer
553 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200555 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000556 public function referrer()
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300558 return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000559 }
560
561 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 /**
564 * Get the accepted languages
565 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200567 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000568 public function languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200570 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 {
572 $this->_set_languages();
573 }
Barry Mienydd671972010-10-04 16:33:58 +0200574
Derek Allard2067d1a2008-11-13 22:59:24 +0000575 return $this->languages;
576 }
577
578 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200579
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 /**
581 * Get the accepted Character Sets
582 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000583 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200584 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000585 public function charsets()
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200587 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 {
589 $this->_set_charsets();
590 }
Barry Mienydd671972010-10-04 16:33:58 +0200591
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 return $this->charsets;
593 }
Barry Mienydd671972010-10-04 16:33:58 +0200594
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200596
Derek Allard2067d1a2008-11-13 22:59:24 +0000597 /**
598 * Test for a particular language
599 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400600 * @param string $lang
Derek Allard2067d1a2008-11-13 22:59:24 +0000601 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200602 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000603 public function accept_lang($lang = 'en')
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300605 return in_array(strtolower($lang), $this->languages(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 }
Barry Mienydd671972010-10-04 16:33:58 +0200607
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200609
Derek Allard2067d1a2008-11-13 22:59:24 +0000610 /**
611 * Test for a particular character set
612 *
Andrey Andreevca7d8222012-05-11 10:59:09 +0300613 * @param string $charset
Derek Allard2067d1a2008-11-13 22:59:24 +0000614 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200615 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000616 public function accept_charset($charset = 'utf-8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000617 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300618 return in_array(strtolower($charset), $this->charsets(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000619 }
Barry Mienydd671972010-10-04 16:33:58 +0200620
Derek Allard2067d1a2008-11-13 22:59:24 +0000621}
622
Derek Allard2067d1a2008-11-13 22:59:24 +0000623/* End of file User_agent.php */
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300624/* Location: ./system/libraries/User_agent.php */