blob: 3fe2e0519bf73fcb0dae9c9d8f74d3784e4990a2 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, 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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * User Agent Class
31 *
cenk115e9982011-09-27 10:07:53 +030032 * Identifies the platform, browser, robot, or mobile device of the browsing agent
Derek Allard2067d1a2008-11-13 22:59:24 +000033 *
34 * @package CodeIgniter
35 * @subpackage Libraries
36 * @category User Agent
Derek Jonesf4a4bd82011-10-20 12:18:42 -050037 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000038 * @link http://codeigniter.com/user_guide/libraries/user_agent.html
39 */
40class CI_User_agent {
41
Timothy Warren0688ac92012-04-20 10:25:04 -040042 /**
43 * Current user-agent
44 *
45 * @var string
46 */
47 public $agent = NULL;
Barry Mienydd671972010-10-04 16:33:58 +020048
Timothy Warren0688ac92012-04-20 10:25:04 -040049 /**
50 * Flag for if the user-agent belongs to a browser
51 *
52 * @var bool
53 */
54 public $is_browser = FALSE;
Andrey Andreevca7d8222012-05-11 10:59:09 +030055
Timothy Warren0688ac92012-04-20 10:25:04 -040056 /**
57 * Flag for if the user-agent is a robot
58 *
59 * @var bool
60 */
61 public $is_robot = FALSE;
Andrey Andreevca7d8222012-05-11 10:59:09 +030062
Timothy Warren0688ac92012-04-20 10:25:04 -040063 /**
64 * Flag for if the user-agent is a mobile browser
65 *
66 * @var bool
67 */
68 public $is_mobile = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000069
Timothy Warren0688ac92012-04-20 10:25:04 -040070 /**
71 * Languages accepted by the current user agent
72 *
73 * @var array
74 */
75 public $languages = array();
Andrey Andreevca7d8222012-05-11 10:59:09 +030076
Timothy Warren0688ac92012-04-20 10:25:04 -040077 /**
78 * Character sets accepted by the current user agent
79 *
80 * @var array
81 */
82 public $charsets = array();
Barry Mienydd671972010-10-04 16:33:58 +020083
Timothy Warren0688ac92012-04-20 10:25:04 -040084 /**
85 * List of platforms to compare against current user agent
86 *
87 * @var array
88 */
89 public $platforms = array();
Andrey Andreevca7d8222012-05-11 10:59:09 +030090
Timothy Warren0688ac92012-04-20 10:25:04 -040091 /**
92 * List of browsers to compare against current user agent
93 *
94 * @var array
95 */
96 public $browsers = array();
Andrey Andreevca7d8222012-05-11 10:59:09 +030097
Timothy Warren0688ac92012-04-20 10:25:04 -040098 /**
99 * List of mobile browsers to compare against current user agent
100 *
101 * @var array
102 */
103 public $mobiles = array();
Andrey Andreevca7d8222012-05-11 10:59:09 +0300104
Timothy Warren0688ac92012-04-20 10:25:04 -0400105 /**
106 * List of robots to compare against current user agent
107 *
108 * @var array
109 */
110 public $robots = array();
Barry Mienydd671972010-10-04 16:33:58 +0200111
Timothy Warren0688ac92012-04-20 10:25:04 -0400112 /**
113 * Current user-agent platform
114 *
115 * @var string
116 */
117 public $platform = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300118
Timothy Warren0688ac92012-04-20 10:25:04 -0400119 /**
120 * Current user-agent browser
121 *
122 * @var string
123 */
124 public $browser = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300125
Timothy Warren0688ac92012-04-20 10:25:04 -0400126 /**
127 * Current user-agent version
128 *
129 * @var string
130 */
131 public $version = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300132
Timothy Warren0688ac92012-04-20 10:25:04 -0400133 /**
134 * Current user-agent mobile name
135 *
136 * @var string
137 */
138 public $mobile = '';
Andrey Andreevca7d8222012-05-11 10:59:09 +0300139
Timothy Warren0688ac92012-04-20 10:25:04 -0400140 /**
141 * Current user-agent robot name
142 *
143 * @var string
144 */
145 public $robot = '';
Barry Mienydd671972010-10-04 16:33:58 +0200146
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 /**
148 * Constructor
149 *
150 * Sets the User Agent and runs the compilation routine
151 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200153 */
Greg Akera9263282010-11-10 15:26:43 -0600154 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 {
156 if (isset($_SERVER['HTTP_USER_AGENT']))
157 {
158 $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
159 }
Barry Mienydd671972010-10-04 16:33:58 +0200160
vlakoff1228fe22013-01-14 01:30:09 +0100161 if ($this->agent !== NULL && $this->_load_agent_file())
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300163 $this->_compile_data();
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 }
Barry Mienydd671972010-10-04 16:33:58 +0200165
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300166 log_message('debug', 'User Agent Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 }
Barry Mienydd671972010-10-04 16:33:58 +0200168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200170
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 /**
172 * Compile the User Agent Data
173 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200175 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200176 protected function _load_agent_file()
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 {
Andrey Andreevdb529ca2013-01-28 11:00:02 +0200178 if (is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
Greg Akerd96f8822011-12-27 16:23:47 -0600179 {
180 include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
181 }
182 elseif (is_file(APPPATH.'config/user_agents.php'))
183 {
184 include(APPPATH.'config/user_agents.php');
185 }
186 else
bubbafoley0ea04142011-03-17 14:55:41 -0500187 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 return FALSE;
189 }
Barry Mienydd671972010-10-04 16:33:58 +0200190
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 $return = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200192
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 if (isset($platforms))
194 {
195 $this->platforms = $platforms;
196 unset($platforms);
197 $return = TRUE;
198 }
199
200 if (isset($browsers))
201 {
202 $this->browsers = $browsers;
203 unset($browsers);
204 $return = TRUE;
205 }
206
207 if (isset($mobiles))
208 {
209 $this->mobiles = $mobiles;
210 unset($mobiles);
211 $return = TRUE;
212 }
Barry Mienydd671972010-10-04 16:33:58 +0200213
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 if (isset($robots))
215 {
216 $this->robots = $robots;
217 unset($robots);
218 $return = TRUE;
219 }
220
221 return $return;
222 }
Barry Mienydd671972010-10-04 16:33:58 +0200223
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 /**
227 * Compile the User Agent Data
228 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200230 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200231 protected function _compile_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 {
233 $this->_set_platform();
Barry Mienydd671972010-10-04 16:33:58 +0200234
Phil Sturgeon2c547df2011-08-10 08:36:02 -0600235 foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 {
237 if ($this->$function() === TRUE)
238 {
239 break;
240 }
Barry Mienydd671972010-10-04 16:33:58 +0200241 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 }
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 /**
247 * Set the Platform
248 *
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300249 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200250 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200251 protected function _set_platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300253 if (is_array($this->platforms) && count($this->platforms) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 {
255 foreach ($this->platforms as $key => $val)
256 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300257 if (preg_match('|'.preg_quote($key).'|i', $this->agent))
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 {
259 $this->platform = $val;
260 return TRUE;
261 }
262 }
263 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300264
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 $this->platform = 'Unknown Platform';
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300266 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 }
268
269 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200270
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 /**
272 * Set the Browser
273 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200275 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200276 protected function _set_browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300278 if (is_array($this->browsers) && count($this->browsers) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 {
280 foreach ($this->browsers as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200281 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300282 if (preg_match('|'.preg_quote($key).'.*?([0-9\.]+)|i', $this->agent, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 {
284 $this->is_browser = TRUE;
285 $this->version = $match[1];
286 $this->browser = $val;
287 $this->_set_mobile();
288 return TRUE;
289 }
290 }
291 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300292
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 return FALSE;
294 }
Barry Mienydd671972010-10-04 16:33:58 +0200295
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200297
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 /**
299 * Set the Robot
300 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200302 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200303 protected function _set_robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300305 if (is_array($this->robots) && count($this->robots) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200306 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 foreach ($this->robots as $key => $val)
308 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300309 if (preg_match('|'.preg_quote($key).'|i', $this->agent))
Derek Allard2067d1a2008-11-13 22:59:24 +0000310 {
311 $this->is_robot = TRUE;
312 $this->robot = $val;
Eric Roberts001a7642012-04-14 16:41:13 -0500313 $this->_set_mobile();
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 return TRUE;
315 }
316 }
317 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300318
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 return FALSE;
320 }
321
322 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 /**
325 * Set the Mobile Device
326 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200328 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200329 protected function _set_mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300331 if (is_array($this->mobiles) && count($this->mobiles) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200332 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 foreach ($this->mobiles as $key => $val)
334 {
Andrey Andreevca7d8222012-05-11 10:59:09 +0300335 if (FALSE !== (stripos($this->agent, $key)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000336 {
337 $this->is_mobile = TRUE;
338 $this->mobile = $val;
339 return TRUE;
340 }
341 }
Barry Mienydd671972010-10-04 16:33:58 +0200342 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300343
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 return FALSE;
345 }
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200348
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 /**
350 * Set the accepted languages
351 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000352 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200353 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200354 protected function _set_languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300356 if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200358 $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 }
Barry Mienydd671972010-10-04 16:33:58 +0200360
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200361 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 {
363 $this->languages = array('Undefined');
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 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 /**
370 * Set the accepted character sets
371 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200373 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200374 protected function _set_charsets()
Barry Mienydd671972010-10-04 16:33:58 +0200375 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300376 if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200378 $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 }
Barry Mienydd671972010-10-04 16:33:58 +0200380
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200381 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 {
383 $this->charsets = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200384 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 }
386
387 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200388
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 /**
390 * Is Browser
391 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400392 * @param string $key
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200394 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000395 public function is_browser($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000397 if ( ! $this->is_browser)
398 {
399 return FALSE;
400 }
401
402 // No need to be specific, it's a browser
403 if ($key === NULL)
404 {
405 return TRUE;
406 }
407
408 // Check for a specific browser
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300409 return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 }
411
412 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200413
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 /**
415 * Is Robot
416 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400417 * @param string $key
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200419 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000420 public function is_robot($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000422 if ( ! $this->is_robot)
423 {
424 return FALSE;
425 }
426
427 // No need to be specific, it's a robot
428 if ($key === NULL)
429 {
430 return TRUE;
431 }
432
433 // Check for a specific robot
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300434 return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 }
436
437 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200438
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 /**
440 * Is Mobile
441 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400442 * @param string $key
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200444 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000445 public function is_mobile($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000447 if ( ! $this->is_mobile)
448 {
449 return FALSE;
450 }
451
452 // No need to be specific, it's a mobile
453 if ($key === NULL)
454 {
455 return TRUE;
456 }
457
458 // Check for a specific robot
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300459 return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]);
Barry Mienydd671972010-10-04 16:33:58 +0200460 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000461
462 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200463
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 /**
465 * Is this a referral from another site?
466 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200468 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000469 public function is_referral()
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 {
Andrey Andreeva0836b92012-10-24 22:03:42 +0300471 if (empty($_SERVER['HTTP_REFERER']))
472 {
473 return FALSE;
474 }
475
476 $referer = parse_url($_SERVER['HTTP_REFERER']);
477 return ! (empty($referer['host']) && strpos(config_item('base_url'), $referer['host']) !== FALSE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 }
479
480 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200481
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 /**
483 * Agent String
484 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200486 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000487 public function agent_string()
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 {
489 return $this->agent;
490 }
491
492 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200493
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 /**
495 * Get Platform
496 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000497 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200498 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000499 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 {
501 return $this->platform;
502 }
503
504 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200505
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 /**
507 * Get Browser Name
508 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200510 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000511 public function browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 {
513 return $this->browser;
514 }
515
516 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200517
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 /**
519 * Get the Browser Version
520 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200522 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000523 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 {
525 return $this->version;
526 }
527
528 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200529
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 /**
531 * Get The Robot Name
532 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200534 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000535 public function robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 {
537 return $this->robot;
538 }
539 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200540
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 /**
542 * Get the Mobile Device
543 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000544 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200545 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000546 public function mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 {
548 return $this->mobile;
549 }
Barry Mienydd671972010-10-04 16:33:58 +0200550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200552
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 /**
554 * Get the referrer
555 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000556 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200557 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000558 public function referrer()
Derek Allard2067d1a2008-11-13 22:59:24 +0000559 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300560 return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 }
562
563 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200564
Derek Allard2067d1a2008-11-13 22:59:24 +0000565 /**
566 * Get the accepted languages
567 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200569 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000570 public function languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200572 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 {
574 $this->_set_languages();
575 }
Barry Mienydd671972010-10-04 16:33:58 +0200576
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 return $this->languages;
578 }
579
580 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200581
Derek Allard2067d1a2008-11-13 22:59:24 +0000582 /**
583 * Get the accepted Character Sets
584 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200586 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000587 public function charsets()
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200589 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 {
591 $this->_set_charsets();
592 }
Barry Mienydd671972010-10-04 16:33:58 +0200593
Derek Allard2067d1a2008-11-13 22:59:24 +0000594 return $this->charsets;
595 }
Barry Mienydd671972010-10-04 16:33:58 +0200596
Derek Allard2067d1a2008-11-13 22:59:24 +0000597 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200598
Derek Allard2067d1a2008-11-13 22:59:24 +0000599 /**
600 * Test for a particular language
601 *
Timothy Warren0688ac92012-04-20 10:25:04 -0400602 * @param string $lang
Derek Allard2067d1a2008-11-13 22:59:24 +0000603 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200604 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000605 public function accept_lang($lang = 'en')
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300607 return in_array(strtolower($lang), $this->languages(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 }
Barry Mienydd671972010-10-04 16:33:58 +0200609
Derek Allard2067d1a2008-11-13 22:59:24 +0000610 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200611
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 /**
613 * Test for a particular character set
614 *
Andrey Andreevca7d8222012-05-11 10:59:09 +0300615 * @param string $charset
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200617 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000618 public function accept_charset($charset = 'utf-8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000619 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300620 return in_array(strtolower($charset), $this->charsets(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 }
Barry Mienydd671972010-10-04 16:33:58 +0200622
Derek Allard2067d1a2008-11-13 22:59:24 +0000623}
624
Derek Allard2067d1a2008-11-13 22:59:24 +0000625/* End of file User_agent.php */
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300626/* Location: ./system/libraries/User_agent.php */