blob: d55fc3e1415e698bce9bd211adaf200b5e033348 [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 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 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
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @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
28// ------------------------------------------------------------------------
29
30/**
31 * User Agent Class
32 *
cenk115e9982011-09-27 10:07:53 +030033 * Identifies the platform, browser, robot, or mobile device of the browsing agent
Derek Allard2067d1a2008-11-13 22:59:24 +000034 *
35 * @package CodeIgniter
36 * @subpackage Libraries
37 * @category User Agent
Derek Jonesf4a4bd82011-10-20 12:18:42 -050038 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000039 * @link http://codeigniter.com/user_guide/libraries/user_agent.html
40 */
41class CI_User_agent {
42
Andrey Andreeve9ccf742011-12-25 17:30:10 +020043 public $agent = NULL;
Barry Mienydd671972010-10-04 16:33:58 +020044
Andrey Andreeve9ccf742011-12-25 17:30:10 +020045 public $is_browser = FALSE;
46 public $is_robot = FALSE;
47 public $is_mobile = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000048
Andrey Andreeve9ccf742011-12-25 17:30:10 +020049 public $languages = array();
50 public $charsets = array();
Barry Mienydd671972010-10-04 16:33:58 +020051
Andrey Andreeve9ccf742011-12-25 17:30:10 +020052 public $platforms = array();
53 public $browsers = array();
54 public $mobiles = array();
55 public $robots = array();
Barry Mienydd671972010-10-04 16:33:58 +020056
Andrey Andreeve9ccf742011-12-25 17:30:10 +020057 public $platform = '';
58 public $browser = '';
59 public $version = '';
60 public $mobile = '';
61 public $robot = '';
Barry Mienydd671972010-10-04 16:33:58 +020062
Derek Allard2067d1a2008-11-13 22:59:24 +000063 /**
64 * Constructor
65 *
66 * Sets the User Agent and runs the compilation routine
67 *
68 * @access public
69 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020070 */
Greg Akera9263282010-11-10 15:26:43 -060071 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +000072 {
73 if (isset($_SERVER['HTTP_USER_AGENT']))
74 {
75 $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 if ( ! is_null($this->agent))
79 {
80 if ($this->_load_agent_file())
81 {
82 $this->_compile_data();
83 }
84 }
Barry Mienydd671972010-10-04 16:33:58 +020085
Derek Allard2067d1a2008-11-13 22:59:24 +000086 log_message('debug', "User Agent Class Initialized");
87 }
Barry Mienydd671972010-10-04 16:33:58 +020088
Derek Allard2067d1a2008-11-13 22:59:24 +000089 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020090
Derek Allard2067d1a2008-11-13 22:59:24 +000091 /**
92 * Compile the User Agent Data
93 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +020094 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +000095 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020096 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +020097 protected function _load_agent_file()
Derek Allard2067d1a2008-11-13 22:59:24 +000098 {
Greg Aker3a746652011-04-19 10:59:47 -050099 if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
bubbafoley0ea04142011-03-17 14:55:41 -0500100 {
Greg Aker3a746652011-04-19 10:59:47 -0500101 include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
Eric Barnesfdd5b112011-03-21 21:28:58 -0400102 }
Greg Aker3a746652011-04-19 10:59:47 -0500103 elseif (is_file(APPPATH.'config/user_agents.php'))
Eric Barnesfdd5b112011-03-21 21:28:58 -0400104 {
Greg Aker3a746652011-04-19 10:59:47 -0500105 include(APPPATH.'config/user_agents.php');
bubbafoley0ea04142011-03-17 14:55:41 -0500106 }
107 else
108 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 return FALSE;
110 }
Barry Mienydd671972010-10-04 16:33:58 +0200111
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 $return = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200113
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 if (isset($platforms))
115 {
116 $this->platforms = $platforms;
117 unset($platforms);
118 $return = TRUE;
119 }
120
121 if (isset($browsers))
122 {
123 $this->browsers = $browsers;
124 unset($browsers);
125 $return = TRUE;
126 }
127
128 if (isset($mobiles))
129 {
130 $this->mobiles = $mobiles;
131 unset($mobiles);
132 $return = TRUE;
133 }
Barry Mienydd671972010-10-04 16:33:58 +0200134
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 if (isset($robots))
136 {
137 $this->robots = $robots;
138 unset($robots);
139 $return = TRUE;
140 }
141
142 return $return;
143 }
Barry Mienydd671972010-10-04 16:33:58 +0200144
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200146
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 /**
148 * Compile the User Agent Data
149 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200150 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200152 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200153 protected function _compile_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 {
155 $this->_set_platform();
Barry Mienydd671972010-10-04 16:33:58 +0200156
Phil Sturgeon2c547df2011-08-10 08:36:02 -0600157 foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000158 {
159 if ($this->$function() === TRUE)
160 {
161 break;
162 }
Barry Mienydd671972010-10-04 16:33:58 +0200163 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 }
Barry Mienydd671972010-10-04 16:33:58 +0200165
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 /**
169 * Set the Platform
170 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200171 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200173 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200174 protected function _set_platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 {
176 if (is_array($this->platforms) AND count($this->platforms) > 0)
177 {
178 foreach ($this->platforms as $key => $val)
179 {
180 if (preg_match("|".preg_quote($key)."|i", $this->agent))
181 {
182 $this->platform = $val;
183 return TRUE;
184 }
185 }
186 }
187 $this->platform = 'Unknown Platform';
188 }
189
190 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 /**
193 * Set the Browser
194 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200195 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200197 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200198 protected function _set_browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 {
200 if (is_array($this->browsers) AND count($this->browsers) > 0)
201 {
202 foreach ($this->browsers as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200203 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match))
205 {
206 $this->is_browser = TRUE;
207 $this->version = $match[1];
208 $this->browser = $val;
209 $this->_set_mobile();
210 return TRUE;
211 }
212 }
213 }
214 return FALSE;
215 }
Barry Mienydd671972010-10-04 16:33:58 +0200216
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 /**
220 * Set the Robot
221 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200222 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200224 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200225 protected function _set_robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 {
227 if (is_array($this->robots) AND count($this->robots) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200228 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 foreach ($this->robots as $key => $val)
230 {
231 if (preg_match("|".preg_quote($key)."|i", $this->agent))
232 {
233 $this->is_robot = TRUE;
234 $this->robot = $val;
235 return TRUE;
236 }
237 }
238 }
239 return FALSE;
240 }
241
242 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 /**
245 * Set the Mobile Device
246 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200247 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200249 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200250 protected function _set_mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 {
252 if (is_array($this->mobiles) AND count($this->mobiles) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200253 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 foreach ($this->mobiles as $key => $val)
255 {
256 if (FALSE !== (strpos(strtolower($this->agent), $key)))
257 {
258 $this->is_mobile = TRUE;
259 $this->mobile = $val;
260 return TRUE;
261 }
262 }
Barry Mienydd671972010-10-04 16:33:58 +0200263 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 return FALSE;
265 }
Barry Mienydd671972010-10-04 16:33:58 +0200266
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 /**
270 * Set the accepted languages
271 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200272 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200274 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200275 protected function _set_languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200277 if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200279 $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 }
Barry Mienydd671972010-10-04 16:33:58 +0200281
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200282 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 {
284 $this->languages = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200285 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 }
Barry Mienydd671972010-10-04 16:33:58 +0200287
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200289
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 /**
291 * Set the accepted character sets
292 *
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200293 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200295 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200296 protected function _set_charsets()
Barry Mienydd671972010-10-04 16:33:58 +0200297 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200298 if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200300 $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200303 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 {
305 $this->charsets = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200306 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 }
308
309 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200310
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 /**
312 * Is Browser
313 *
314 * @access public
315 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200316 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000317 public function is_browser($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000319 if ( ! $this->is_browser)
320 {
321 return FALSE;
322 }
323
324 // No need to be specific, it's a browser
325 if ($key === NULL)
326 {
327 return TRUE;
328 }
329
330 // Check for a specific browser
331 return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 }
333
334 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200335
Derek Allard2067d1a2008-11-13 22:59:24 +0000336 /**
337 * Is Robot
338 *
339 * @access public
340 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200341 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000342 public function is_robot($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000344 if ( ! $this->is_robot)
345 {
346 return FALSE;
347 }
348
349 // No need to be specific, it's a robot
350 if ($key === NULL)
351 {
352 return TRUE;
353 }
354
355 // Check for a specific robot
356 return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 }
358
359 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200360
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 /**
362 * Is Mobile
363 *
364 * @access public
365 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200366 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000367 public function is_mobile($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000369 if ( ! $this->is_mobile)
370 {
371 return FALSE;
372 }
373
374 // No need to be specific, it's a mobile
375 if ($key === NULL)
376 {
377 return TRUE;
378 }
379
380 // Check for a specific robot
381 return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key];
Barry Mienydd671972010-10-04 16:33:58 +0200382 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000383
384 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200385
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 /**
387 * Is this a referral from another site?
388 *
389 * @access public
390 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200391 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000392 public function is_referral()
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200394 return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 }
396
397 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200398
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 /**
400 * Agent String
401 *
402 * @access public
403 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200404 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000405 public function agent_string()
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 {
407 return $this->agent;
408 }
409
410 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 /**
413 * Get Platform
414 *
415 * @access public
416 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200417 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000418 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 {
420 return $this->platform;
421 }
422
423 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 /**
426 * Get Browser Name
427 *
428 * @access public
429 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200430 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000431 public function browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 {
433 return $this->browser;
434 }
435
436 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200437
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 /**
439 * Get the Browser Version
440 *
441 * @access public
442 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200443 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000444 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 {
446 return $this->version;
447 }
448
449 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200450
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 /**
452 * Get The Robot Name
453 *
454 * @access public
455 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200456 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000457 public function robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 {
459 return $this->robot;
460 }
461 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200462
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 /**
464 * Get the Mobile Device
465 *
466 * @access public
467 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200468 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000469 public function mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 {
471 return $this->mobile;
472 }
Barry Mienydd671972010-10-04 16:33:58 +0200473
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200475
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 /**
477 * Get the referrer
478 *
479 * @access public
480 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200481 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000482 public function referrer()
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 {
484 return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
485 }
486
487 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200488
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 /**
490 * Get the accepted languages
491 *
492 * @access public
493 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200494 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000495 public function languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200497 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 {
499 $this->_set_languages();
500 }
Barry Mienydd671972010-10-04 16:33:58 +0200501
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 return $this->languages;
503 }
504
505 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200506
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 /**
508 * Get the accepted Character Sets
509 *
510 * @access public
511 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200512 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000513 public function charsets()
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200515 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 {
517 $this->_set_charsets();
518 }
Barry Mienydd671972010-10-04 16:33:58 +0200519
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 return $this->charsets;
521 }
Barry Mienydd671972010-10-04 16:33:58 +0200522
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 * Test for a particular language
527 *
528 * @access public
529 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200530 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000531 public function accept_lang($lang = 'en')
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000533 return (in_array(strtolower($lang), $this->languages(), TRUE));
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 }
Barry Mienydd671972010-10-04 16:33:58 +0200535
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200537
Derek Allard2067d1a2008-11-13 22:59:24 +0000538 /**
539 * Test for a particular character set
540 *
541 * @access public
542 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200543 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000544 public function accept_charset($charset = 'utf-8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000546 return (in_array(strtolower($charset), $this->charsets(), TRUE));
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 }
Barry Mienydd671972010-10-04 16:33:58 +0200548
Derek Allard2067d1a2008-11-13 22:59:24 +0000549}
550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551/* End of file User_agent.php */
cenk115e9982011-09-27 10:07:53 +0300552/* Location: ./system/libraries/User_agent.php */