blob: b8e0d37fb33a57dbe751f82710812e70d790941b [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
Andrey Andreeve9ccf742011-12-25 17:30:10 +020041 public $agent = NULL;
Barry Mienydd671972010-10-04 16:33:58 +020042
Andrey Andreeve9ccf742011-12-25 17:30:10 +020043 public $is_browser = FALSE;
44 public $is_robot = FALSE;
45 public $is_mobile = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000046
Andrey Andreeve9ccf742011-12-25 17:30:10 +020047 public $languages = array();
48 public $charsets = array();
Barry Mienydd671972010-10-04 16:33:58 +020049
Andrey Andreeve9ccf742011-12-25 17:30:10 +020050 public $platforms = array();
51 public $browsers = array();
52 public $mobiles = array();
53 public $robots = array();
Barry Mienydd671972010-10-04 16:33:58 +020054
Andrey Andreeve9ccf742011-12-25 17:30:10 +020055 public $platform = '';
56 public $browser = '';
57 public $version = '';
58 public $mobile = '';
59 public $robot = '';
Barry Mienydd671972010-10-04 16:33:58 +020060
Derek Allard2067d1a2008-11-13 22:59:24 +000061 /**
62 * Constructor
63 *
64 * Sets the User Agent and runs the compilation routine
65 *
Derek Allard2067d1a2008-11-13 22:59:24 +000066 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020067 */
Greg Akera9263282010-11-10 15:26:43 -060068 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +000069 {
70 if (isset($_SERVER['HTTP_USER_AGENT']))
71 {
72 $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
73 }
Barry Mienydd671972010-10-04 16:33:58 +020074
Andrey Andreevd3bc53d2012-04-03 16:37:19 +030075 if ( ! is_null($this->agent) && $this->_load_agent_file())
Derek Allard2067d1a2008-11-13 22:59:24 +000076 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +030077 $this->_compile_data();
Derek Allard2067d1a2008-11-13 22:59:24 +000078 }
Barry Mienydd671972010-10-04 16:33:58 +020079
Andrey Andreevd3bc53d2012-04-03 16:37:19 +030080 log_message('debug', 'User Agent Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000081 }
Barry Mienydd671972010-10-04 16:33:58 +020082
Derek Allard2067d1a2008-11-13 22:59:24 +000083 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020084
Derek Allard2067d1a2008-11-13 22:59:24 +000085 /**
86 * Compile the User Agent Data
87 *
Derek Allard2067d1a2008-11-13 22:59:24 +000088 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020089 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +020090 protected function _load_agent_file()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +030092 if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
Greg Akerd96f8822011-12-27 16:23:47 -060093 {
94 include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
95 }
96 elseif (is_file(APPPATH.'config/user_agents.php'))
97 {
98 include(APPPATH.'config/user_agents.php');
99 }
100 else
bubbafoley0ea04142011-03-17 14:55:41 -0500101 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 return FALSE;
103 }
Barry Mienydd671972010-10-04 16:33:58 +0200104
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 $return = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 if (isset($platforms))
108 {
109 $this->platforms = $platforms;
110 unset($platforms);
111 $return = TRUE;
112 }
113
114 if (isset($browsers))
115 {
116 $this->browsers = $browsers;
117 unset($browsers);
118 $return = TRUE;
119 }
120
121 if (isset($mobiles))
122 {
123 $this->mobiles = $mobiles;
124 unset($mobiles);
125 $return = TRUE;
126 }
Barry Mienydd671972010-10-04 16:33:58 +0200127
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 if (isset($robots))
129 {
130 $this->robots = $robots;
131 unset($robots);
132 $return = TRUE;
133 }
134
135 return $return;
136 }
Barry Mienydd671972010-10-04 16:33:58 +0200137
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200139
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 /**
141 * Compile the User Agent Data
142 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200144 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200145 protected function _compile_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 {
147 $this->_set_platform();
Barry Mienydd671972010-10-04 16:33:58 +0200148
Phil Sturgeon2c547df2011-08-10 08:36:02 -0600149 foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 {
151 if ($this->$function() === TRUE)
152 {
153 break;
154 }
Barry Mienydd671972010-10-04 16:33:58 +0200155 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 }
Barry Mienydd671972010-10-04 16:33:58 +0200157
Derek Allard2067d1a2008-11-13 22:59:24 +0000158 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200159
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 /**
161 * Set the Platform
162 *
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300163 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200164 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200165 protected function _set_platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300167 if (is_array($this->platforms) && count($this->platforms) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 {
169 foreach ($this->platforms as $key => $val)
170 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300171 if (preg_match('|'.preg_quote($key).'|i', $this->agent))
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 {
173 $this->platform = $val;
174 return TRUE;
175 }
176 }
177 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300178
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 $this->platform = 'Unknown Platform';
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300180 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 }
182
183 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200184
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 /**
186 * Set the Browser
187 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200189 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200190 protected function _set_browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300192 if (is_array($this->browsers) && count($this->browsers) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 {
194 foreach ($this->browsers as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200195 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300196 if (preg_match('|'.preg_quote($key).'.*?([0-9\.]+)|i', $this->agent, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 {
198 $this->is_browser = TRUE;
199 $this->version = $match[1];
200 $this->browser = $val;
201 $this->_set_mobile();
202 return TRUE;
203 }
204 }
205 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 return FALSE;
208 }
Barry Mienydd671972010-10-04 16:33:58 +0200209
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200211
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 /**
213 * Set the Robot
214 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200216 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200217 protected function _set_robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300219 if (is_array($this->robots) && count($this->robots) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200220 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 foreach ($this->robots as $key => $val)
222 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300223 if (preg_match('|'.preg_quote($key).'|i', $this->agent))
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 {
225 $this->is_robot = TRUE;
226 $this->robot = $val;
227 return TRUE;
228 }
229 }
230 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300231
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 return FALSE;
233 }
234
235 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200236
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 /**
238 * Set the Mobile Device
239 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200241 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200242 protected function _set_mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300244 if (is_array($this->mobiles) && count($this->mobiles) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200245 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 foreach ($this->mobiles as $key => $val)
247 {
248 if (FALSE !== (strpos(strtolower($this->agent), $key)))
249 {
250 $this->is_mobile = TRUE;
251 $this->mobile = $val;
252 return TRUE;
253 }
254 }
Barry Mienydd671972010-10-04 16:33:58 +0200255 }
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300256
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 return FALSE;
258 }
Barry Mienydd671972010-10-04 16:33:58 +0200259
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200261
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 /**
263 * Set the accepted languages
264 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200266 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200267 protected function _set_languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300269 if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200271 $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 }
Barry Mienydd671972010-10-04 16:33:58 +0200273
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200274 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 {
276 $this->languages = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200277 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 }
Barry Mienydd671972010-10-04 16:33:58 +0200279
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200281
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 /**
283 * Set the accepted character sets
284 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200286 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200287 protected function _set_charsets()
Barry Mienydd671972010-10-04 16:33:58 +0200288 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300289 if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200291 $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 }
Barry Mienydd671972010-10-04 16:33:58 +0200293
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200294 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 {
296 $this->charsets = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200297 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 }
299
300 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200301
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 /**
303 * Is Browser
304 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200306 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000307 public function is_browser($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000309 if ( ! $this->is_browser)
310 {
311 return FALSE;
312 }
313
314 // No need to be specific, it's a browser
315 if ($key === NULL)
316 {
317 return TRUE;
318 }
319
320 // Check for a specific browser
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300321 return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 }
323
324 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 /**
327 * Is Robot
328 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200330 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000331 public function is_robot($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000333 if ( ! $this->is_robot)
334 {
335 return FALSE;
336 }
337
338 // No need to be specific, it's a robot
339 if ($key === NULL)
340 {
341 return TRUE;
342 }
343
344 // Check for a specific robot
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300345 return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 }
347
348 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200349
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 /**
351 * Is Mobile
352 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200354 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000355 public function is_mobile($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000357 if ( ! $this->is_mobile)
358 {
359 return FALSE;
360 }
361
362 // No need to be specific, it's a mobile
363 if ($key === NULL)
364 {
365 return TRUE;
366 }
367
368 // Check for a specific robot
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300369 return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]);
Barry Mienydd671972010-10-04 16:33:58 +0200370 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000371
372 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200373
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 /**
375 * Is this a referral from another site?
376 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200378 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000379 public function is_referral()
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300381 return ! empty($_SERVER['HTTP_REFERER']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 }
383
384 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200385
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 /**
387 * Agent String
388 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200390 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000391 public function agent_string()
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 {
393 return $this->agent;
394 }
395
396 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200397
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 /**
399 * Get Platform
400 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200402 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000403 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 {
405 return $this->platform;
406 }
407
408 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200409
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 /**
411 * Get Browser Name
412 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200414 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000415 public function browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 {
417 return $this->browser;
418 }
419
420 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200421
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 /**
423 * Get the Browser Version
424 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200426 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000427 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000428 {
429 return $this->version;
430 }
431
432 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200433
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 /**
435 * Get The Robot Name
436 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200438 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000439 public function robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 return $this->robot;
442 }
443 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 /**
446 * Get the Mobile Device
447 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200449 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000450 public function mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 {
452 return $this->mobile;
453 }
Barry Mienydd671972010-10-04 16:33:58 +0200454
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200456
Derek Allard2067d1a2008-11-13 22:59:24 +0000457 /**
458 * Get the referrer
459 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200461 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000462 public function referrer()
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300464 return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 }
466
467 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200468
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 /**
470 * Get the accepted languages
471 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200473 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000474 public function languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000475 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200476 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 {
478 $this->_set_languages();
479 }
Barry Mienydd671972010-10-04 16:33:58 +0200480
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 return $this->languages;
482 }
483
484 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 /**
487 * Get the accepted Character Sets
488 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200490 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000491 public function charsets()
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200493 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 {
495 $this->_set_charsets();
496 }
Barry Mienydd671972010-10-04 16:33:58 +0200497
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 return $this->charsets;
499 }
Barry Mienydd671972010-10-04 16:33:58 +0200500
Derek Allard2067d1a2008-11-13 22:59:24 +0000501 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200502
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 /**
504 * Test for a particular language
505 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200507 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000508 public function accept_lang($lang = 'en')
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300510 return in_array(strtolower($lang), $this->languages(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 }
Barry Mienydd671972010-10-04 16:33:58 +0200512
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200514
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 /**
516 * Test for a particular character set
517 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200519 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000520 public function accept_charset($charset = 'utf-8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 {
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300522 return in_array(strtolower($charset), $this->charsets(), TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 }
Barry Mienydd671972010-10-04 16:33:58 +0200524
Derek Allard2067d1a2008-11-13 22:59:24 +0000525}
526
Derek Allard2067d1a2008-11-13 22:59:24 +0000527/* End of file User_agent.php */
Andrey Andreevd3bc53d2012-04-03 16:37:19 +0300528/* Location: ./system/libraries/User_agent.php */