blob: 5288525cbed4ee7bff6434459a78b427a5fec611 [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 *
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 Aker5c1aa632011-12-25 01:24:29 -060097 load_environ_config('user_agents');
98
99 // Return FALSE if we still have no mimes after trying to load them up.
100 if (count($this->mimes) === 0)
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 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 * @return mixed
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 {
167 if (is_array($this->platforms) AND count($this->platforms) > 0)
168 {
169 foreach ($this->platforms as $key => $val)
170 {
171 if (preg_match("|".preg_quote($key)."|i", $this->agent))
172 {
173 $this->platform = $val;
174 return TRUE;
175 }
176 }
177 }
178 $this->platform = 'Unknown Platform';
179 }
180
181 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200182
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 /**
184 * Set the Browser
185 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200187 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200188 protected function _set_browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 {
190 if (is_array($this->browsers) AND count($this->browsers) > 0)
191 {
192 foreach ($this->browsers as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200193 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match))
195 {
196 $this->is_browser = TRUE;
197 $this->version = $match[1];
198 $this->browser = $val;
199 $this->_set_mobile();
200 return TRUE;
201 }
202 }
203 }
204 return FALSE;
205 }
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200208
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 /**
210 * Set the Robot
211 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200213 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200214 protected function _set_robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 {
216 if (is_array($this->robots) AND count($this->robots) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200217 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 foreach ($this->robots as $key => $val)
219 {
220 if (preg_match("|".preg_quote($key)."|i", $this->agent))
221 {
222 $this->is_robot = TRUE;
223 $this->robot = $val;
224 return TRUE;
225 }
226 }
227 }
228 return FALSE;
229 }
230
231 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200232
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 /**
234 * Set the Mobile Device
235 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200237 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200238 protected function _set_mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 {
240 if (is_array($this->mobiles) AND count($this->mobiles) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200241 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 foreach ($this->mobiles as $key => $val)
243 {
244 if (FALSE !== (strpos(strtolower($this->agent), $key)))
245 {
246 $this->is_mobile = TRUE;
247 $this->mobile = $val;
248 return TRUE;
249 }
250 }
Barry Mienydd671972010-10-04 16:33:58 +0200251 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 return FALSE;
253 }
Barry Mienydd671972010-10-04 16:33:58 +0200254
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200256
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 /**
258 * Set the accepted languages
259 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200261 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200262 protected function _set_languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200264 if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200266 $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 }
Barry Mienydd671972010-10-04 16:33:58 +0200268
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200269 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 {
271 $this->languages = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200272 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 }
Barry Mienydd671972010-10-04 16:33:58 +0200274
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200276
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 /**
278 * Set the accepted character sets
279 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200281 */
Andrey Andreev75c5efb2011-12-26 16:28:40 +0200282 protected function _set_charsets()
Barry Mienydd671972010-10-04 16:33:58 +0200283 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200284 if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200286 $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 }
Barry Mienydd671972010-10-04 16:33:58 +0200288
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200289 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 {
291 $this->charsets = array('Undefined');
Barry Mienydd671972010-10-04 16:33:58 +0200292 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 }
294
295 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200296
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 /**
298 * Is Browser
299 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200301 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000302 public function is_browser($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000304 if ( ! $this->is_browser)
305 {
306 return FALSE;
307 }
308
309 // No need to be specific, it's a browser
310 if ($key === NULL)
311 {
312 return TRUE;
313 }
314
315 // Check for a specific browser
316 return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 }
318
319 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 /**
322 * Is Robot
323 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200325 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000326 public function is_robot($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000328 if ( ! $this->is_robot)
329 {
330 return FALSE;
331 }
332
333 // No need to be specific, it's a robot
334 if ($key === NULL)
335 {
336 return TRUE;
337 }
338
339 // Check for a specific robot
340 return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 }
342
343 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200344
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 /**
346 * Is Mobile
347 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200349 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000350 public function is_mobile($key = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000352 if ( ! $this->is_mobile)
353 {
354 return FALSE;
355 }
356
357 // No need to be specific, it's a mobile
358 if ($key === NULL)
359 {
360 return TRUE;
361 }
362
363 // Check for a specific robot
364 return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key];
Barry Mienydd671972010-10-04 16:33:58 +0200365 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000366
367 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 /**
370 * Is this a referral from another site?
371 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200373 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000374 public function is_referral()
Derek Allard2067d1a2008-11-13 22:59:24 +0000375 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200376 return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 }
378
379 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200380
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 /**
382 * Agent String
383 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200385 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000386 public function agent_string()
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 {
388 return $this->agent;
389 }
390
391 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200392
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 /**
394 * Get Platform
395 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200397 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000398 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 {
400 return $this->platform;
401 }
402
403 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200404
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 /**
406 * Get Browser Name
407 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200409 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000410 public function browser()
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 {
412 return $this->browser;
413 }
414
415 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200416
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 /**
418 * Get the Browser Version
419 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200421 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000422 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 {
424 return $this->version;
425 }
426
427 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200428
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 /**
430 * Get The Robot Name
431 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200433 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000434 public function robot()
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 {
436 return $this->robot;
437 }
438 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200439
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 /**
441 * Get the Mobile Device
442 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200444 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000445 public function mobile()
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 {
447 return $this->mobile;
448 }
Barry Mienydd671972010-10-04 16:33:58 +0200449
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200451
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 /**
453 * Get the referrer
454 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200456 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000457 public function referrer()
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 {
459 return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
460 }
461
462 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200463
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 /**
465 * Get the accepted languages
466 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200468 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000469 public function languages()
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200471 if (count($this->languages) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 {
473 $this->_set_languages();
474 }
Barry Mienydd671972010-10-04 16:33:58 +0200475
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 return $this->languages;
477 }
478
479 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200480
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 /**
482 * Get the accepted Character Sets
483 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200485 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000486 public function charsets()
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 {
Andrey Andreeve9ccf742011-12-25 17:30:10 +0200488 if (count($this->charsets) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 {
490 $this->_set_charsets();
491 }
Barry Mienydd671972010-10-04 16:33:58 +0200492
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 return $this->charsets;
494 }
Barry Mienydd671972010-10-04 16:33:58 +0200495
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200497
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 /**
499 * Test for a particular language
500 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000501 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200502 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000503 public function accept_lang($lang = 'en')
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000505 return (in_array(strtolower($lang), $this->languages(), TRUE));
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 }
Barry Mienydd671972010-10-04 16:33:58 +0200507
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200509
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 /**
511 * Test for a particular character set
512 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200514 */
Phil Sturgeondac1b462011-01-06 17:40:10 +0000515 public function accept_charset($charset = 'utf-8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 {
Phil Sturgeondac1b462011-01-06 17:40:10 +0000517 return (in_array(strtolower($charset), $this->charsets(), TRUE));
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 }
Barry Mienydd671972010-10-04 16:33:58 +0200519
Derek Allard2067d1a2008-11-13 22:59:24 +0000520}
521
Derek Allard2067d1a2008-11-13 22:59:24 +0000522/* End of file User_agent.php */
cenk115e9982011-09-27 10:07:53 +0300523/* Location: ./system/libraries/User_agent.php */