blob: 9109edd0f6d38df2669085e9ee27c74dbc9579e3 [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
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 *
Derek Allard2067d1a2008-11-13 22:59:24 +000068 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020069 */
Greg Akera9263282010-11-10 15:26:43 -060070 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +000071 {
72 if (isset($_SERVER['HTTP_USER_AGENT']))
73 {
74 $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
75 }
Barry Mienydd671972010-10-04 16:33:58 +020076
Derek Allard2067d1a2008-11-13 22:59:24 +000077 if ( ! is_null($this->agent))
78 {
79 if ($this->_load_agent_file())
80 {
81 $this->_compile_data();
82 }
83 }
Barry Mienydd671972010-10-04 16:33:58 +020084
Derek Allard2067d1a2008-11-13 22:59:24 +000085 log_message('debug', "User Agent Class Initialized");
86 }
Barry Mienydd671972010-10-04 16:33:58 +020087
Derek Allard2067d1a2008-11-13 22:59:24 +000088 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020089
Derek Allard2067d1a2008-11-13 22:59:24 +000090 /**
91 * Compile the User Agent Data
92 *
Derek Allard2067d1a2008-11-13 22:59:24 +000093 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020094 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +020095 protected function _load_agent_file()
Derek Allard2067d1a2008-11-13 22:59:24 +000096 {
Greg Akerd96f8822011-12-27 16:23:47 -060097 if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
98 {
99 include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
100 }
101 elseif (is_file(APPPATH.'config/user_agents.php'))
102 {
103 include(APPPATH.'config/user_agents.php');
104 }
105 else
bubbafoley0ea04142011-03-17 14:55:41 -0500106 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 return FALSE;
108 }
Barry Mienydd671972010-10-04 16:33:58 +0200109
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 $return = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200111
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 if (isset($platforms))
113 {
114 $this->platforms = $platforms;
115 unset($platforms);
116 $return = TRUE;
117 }
118
119 if (isset($browsers))
120 {
121 $this->browsers = $browsers;
122 unset($browsers);
123 $return = TRUE;
124 }
125
126 if (isset($mobiles))
127 {
128 $this->mobiles = $mobiles;
129 unset($mobiles);
130 $return = TRUE;
131 }
Barry Mienydd671972010-10-04 16:33:58 +0200132
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 if (isset($robots))
134 {
135 $this->robots = $robots;
136 unset($robots);
137 $return = TRUE;
138 }
139
140 return $return;
141 }
Barry Mienydd671972010-10-04 16:33:58 +0200142
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200144
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 /**
146 * Compile the User Agent Data
147 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200149 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200150 protected function _compile_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 {
152 $this->_set_platform();
Barry Mienydd671972010-10-04 16:33:58 +0200153
Phil Sturgeon2c547df2011-08-10 08:36:02 -0600154 foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 {
156 if ($this->$function() === TRUE)
157 {
158 break;
159 }
Barry Mienydd671972010-10-04 16:33:58 +0200160 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 }
Barry Mienydd671972010-10-04 16:33:58 +0200162
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200164
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 /**
166 * Set the Platform
167 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200169 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200170 protected function _set_platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 {
172 if (is_array($this->platforms) AND count($this->platforms) > 0)
173 {
174 foreach ($this->platforms as $key => $val)
175 {
176 if (preg_match("|".preg_quote($key)."|i", $this->agent))
177 {
178 $this->platform = $val;
179 return TRUE;
180 }
181 }
182 }
183 $this->platform = 'Unknown Platform';
184 }
185
186 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200187
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 /**
189 * Set the Browser
190 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200192 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200193 protected function _set_browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 {
195 if (is_array($this->browsers) AND count($this->browsers) > 0)
196 {
197 foreach ($this->browsers as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200198 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match))
200 {
201 $this->is_browser = TRUE;
202 $this->version = $match[1];
203 $this->browser = $val;
204 $this->_set_mobile();
205 return TRUE;
206 }
207 }
208 }
209 return FALSE;
210 }
Barry Mienydd671972010-10-04 16:33:58 +0200211
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200213
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 /**
215 * Set the Robot
216 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200218 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200219 protected function _set_robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 {
221 if (is_array($this->robots) AND count($this->robots) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200222 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 foreach ($this->robots as $key => $val)
224 {
225 if (preg_match("|".preg_quote($key)."|i", $this->agent))
226 {
227 $this->is_robot = TRUE;
228 $this->robot = $val;
229 return TRUE;
230 }
231 }
232 }
233 return FALSE;
234 }
235
236 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200237
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 /**
239 * Set the Mobile Device
240 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200242 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200243 protected function _set_mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 {
245 if (is_array($this->mobiles) AND count($this->mobiles) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200246 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 foreach ($this->mobiles as $key => $val)
248 {
249 if (FALSE !== (strpos(strtolower($this->agent), $key)))
250 {
251 $this->is_mobile = TRUE;
252 $this->mobile = $val;
253 return TRUE;
254 }
255 }
Barry Mienydd671972010-10-04 16:33:58 +0200256 }
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 Andreeve9ccf742011-12-25 17:30:10 +0200269 if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_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 Andreeve9ccf742011-12-25 17:30:10 +0200289 if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_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
321 return array_key_exists($key, $this->browsers) AND $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
345 return array_key_exists($key, $this->robots) AND $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
369 return array_key_exists($key, $this->mobiles) AND $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 Andreeve9ccf742011-12-25 17:30:10 +0200381 return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE;
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 {
464 return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
465 }
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 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000510 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 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000522 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 */
cenk115e9982011-09-27 10:07:53 +0300528/* Location: ./system/libraries/User_agent.php */