Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Andrey Andreev | 80500af | 2013-01-01 08:16:53 +0200 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
| 30 | * User Agent Class |
| 31 | * |
cenk | 115e998 | 2011-09-27 10:07:53 +0300 | [diff] [blame] | 32 | * Identifies the platform, browser, robot, or mobile device of the browsing agent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 33 | * |
| 34 | * @package CodeIgniter |
| 35 | * @subpackage Libraries |
| 36 | * @category User Agent |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 37 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | * @link http://codeigniter.com/user_guide/libraries/user_agent.html |
| 39 | */ |
| 40 | class CI_User_agent { |
| 41 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Current user-agent |
| 44 | * |
| 45 | * @var string |
| 46 | */ |
| 47 | public $agent = NULL; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 48 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 49 | /** |
| 50 | * Flag for if the user-agent belongs to a browser |
| 51 | * |
| 52 | * @var bool |
| 53 | */ |
| 54 | public $is_browser = FALSE; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 55 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 56 | /** |
| 57 | * Flag for if the user-agent is a robot |
| 58 | * |
| 59 | * @var bool |
| 60 | */ |
| 61 | public $is_robot = FALSE; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 62 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 63 | /** |
| 64 | * Flag for if the user-agent is a mobile browser |
| 65 | * |
| 66 | * @var bool |
| 67 | */ |
| 68 | public $is_mobile = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 70 | /** |
| 71 | * Languages accepted by the current user agent |
| 72 | * |
| 73 | * @var array |
| 74 | */ |
| 75 | public $languages = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 76 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 77 | /** |
| 78 | * Character sets accepted by the current user agent |
| 79 | * |
| 80 | * @var array |
| 81 | */ |
| 82 | public $charsets = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 83 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 84 | /** |
| 85 | * List of platforms to compare against current user agent |
| 86 | * |
| 87 | * @var array |
| 88 | */ |
| 89 | public $platforms = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 90 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 91 | /** |
| 92 | * List of browsers to compare against current user agent |
| 93 | * |
| 94 | * @var array |
| 95 | */ |
| 96 | public $browsers = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 97 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 98 | /** |
| 99 | * List of mobile browsers to compare against current user agent |
| 100 | * |
| 101 | * @var array |
| 102 | */ |
| 103 | public $mobiles = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 104 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 105 | /** |
| 106 | * List of robots to compare against current user agent |
| 107 | * |
| 108 | * @var array |
| 109 | */ |
| 110 | public $robots = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 112 | /** |
| 113 | * Current user-agent platform |
| 114 | * |
| 115 | * @var string |
| 116 | */ |
| 117 | public $platform = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 118 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 119 | /** |
| 120 | * Current user-agent browser |
| 121 | * |
| 122 | * @var string |
| 123 | */ |
| 124 | public $browser = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 125 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 126 | /** |
| 127 | * Current user-agent version |
| 128 | * |
| 129 | * @var string |
| 130 | */ |
| 131 | public $version = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 132 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 133 | /** |
| 134 | * Current user-agent mobile name |
| 135 | * |
| 136 | * @var string |
| 137 | */ |
| 138 | public $mobile = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 139 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 140 | /** |
| 141 | * Current user-agent robot name |
| 142 | * |
| 143 | * @var string |
| 144 | */ |
| 145 | public $robot = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 146 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 147 | /** |
| 148 | * Constructor |
| 149 | * |
| 150 | * Sets the User Agent and runs the compilation routine |
| 151 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 153 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 154 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | { |
| 156 | if (isset($_SERVER['HTTP_USER_AGENT'])) |
| 157 | { |
| 158 | $this->agent = trim($_SERVER['HTTP_USER_AGENT']); |
| 159 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 160 | |
vlakoff | 1228fe2 | 2013-01-14 01:30:09 +0100 | [diff] [blame] | 161 | if ($this->agent !== NULL && $this->_load_agent_file()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 163 | $this->_compile_data(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 164 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 165 | |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 166 | log_message('debug', 'User Agent Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 168 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 170 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | /** |
| 172 | * Compile the User Agent Data |
| 173 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 175 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 176 | protected function _load_agent_file() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 177 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 178 | if (($found = file_exists(APPPATH.'config/user_agents.php'))) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 179 | { |
| 180 | include(APPPATH.'config/user_agents.php'); |
| 181 | } |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 182 | |
| 183 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) |
| 184 | { |
| 185 | include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); |
| 186 | $found = TRUE; |
| 187 | } |
| 188 | |
| 189 | if ($found !== TRUE) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 190 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | return FALSE; |
| 192 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | $return = FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 195 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | if (isset($platforms)) |
| 197 | { |
| 198 | $this->platforms = $platforms; |
| 199 | unset($platforms); |
| 200 | $return = TRUE; |
| 201 | } |
| 202 | |
| 203 | if (isset($browsers)) |
| 204 | { |
| 205 | $this->browsers = $browsers; |
| 206 | unset($browsers); |
| 207 | $return = TRUE; |
| 208 | } |
| 209 | |
| 210 | if (isset($mobiles)) |
| 211 | { |
| 212 | $this->mobiles = $mobiles; |
| 213 | unset($mobiles); |
| 214 | $return = TRUE; |
| 215 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 216 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | if (isset($robots)) |
| 218 | { |
| 219 | $this->robots = $robots; |
| 220 | unset($robots); |
| 221 | $return = TRUE; |
| 222 | } |
| 223 | |
| 224 | return $return; |
| 225 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 226 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 227 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 228 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | /** |
| 230 | * Compile the User Agent Data |
| 231 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 234 | protected function _compile_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 235 | { |
| 236 | $this->_set_platform(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 237 | |
Phil Sturgeon | 2c547df | 2011-08-10 08:36:02 -0600 | [diff] [blame] | 238 | foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 239 | { |
| 240 | if ($this->$function() === TRUE) |
| 241 | { |
| 242 | break; |
| 243 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 244 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 246 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 247 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 248 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | /** |
| 250 | * Set the Platform |
| 251 | * |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 252 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 253 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 254 | protected function _set_platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 256 | if (is_array($this->platforms) && count($this->platforms) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | { |
| 258 | foreach ($this->platforms as $key => $val) |
| 259 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 260 | if (preg_match('|'.preg_quote($key).'|i', $this->agent)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | { |
| 262 | $this->platform = $val; |
| 263 | return TRUE; |
| 264 | } |
| 265 | } |
| 266 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 267 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | $this->platform = 'Unknown Platform'; |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 269 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 273 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 274 | /** |
| 275 | * Set the Browser |
| 276 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 277 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 278 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 279 | protected function _set_browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 281 | if (is_array($this->browsers) && count($this->browsers) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 282 | { |
| 283 | foreach ($this->browsers as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 284 | { |
Andrey Andreev | 10925d2 | 2014-01-09 00:16:46 +0200 | [diff] [blame^] | 285 | if (preg_match('|'.$key.'.*?([0-9\.]+)|i', $this->agent, $match)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | { |
| 287 | $this->is_browser = TRUE; |
| 288 | $this->version = $match[1]; |
| 289 | $this->browser = $val; |
| 290 | $this->_set_mobile(); |
| 291 | return TRUE; |
| 292 | } |
| 293 | } |
| 294 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 295 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 296 | return FALSE; |
| 297 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 298 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 299 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 300 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | /** |
| 302 | * Set the Robot |
| 303 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 305 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 306 | protected function _set_robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 308 | if (is_array($this->robots) && count($this->robots) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 309 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | foreach ($this->robots as $key => $val) |
| 311 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 312 | if (preg_match('|'.preg_quote($key).'|i', $this->agent)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | { |
| 314 | $this->is_robot = TRUE; |
| 315 | $this->robot = $val; |
Eric Roberts | 001a764 | 2012-04-14 16:41:13 -0500 | [diff] [blame] | 316 | $this->_set_mobile(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | return TRUE; |
| 318 | } |
| 319 | } |
| 320 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 321 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | return FALSE; |
| 323 | } |
| 324 | |
| 325 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 326 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | /** |
| 328 | * Set the Mobile Device |
| 329 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 331 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 332 | protected function _set_mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 334 | if (is_array($this->mobiles) && count($this->mobiles) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 335 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 336 | foreach ($this->mobiles as $key => $val) |
| 337 | { |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 338 | if (FALSE !== (stripos($this->agent, $key))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 339 | { |
| 340 | $this->is_mobile = TRUE; |
| 341 | $this->mobile = $val; |
| 342 | return TRUE; |
| 343 | } |
| 344 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 345 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 346 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | return FALSE; |
| 348 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 349 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 350 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 351 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 352 | /** |
| 353 | * Set the accepted languages |
| 354 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 356 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 357 | protected function _set_languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 359 | if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 360 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 361 | $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 363 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 364 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | { |
| 366 | $this->languages = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 367 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 368 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 369 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 370 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 371 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 372 | /** |
| 373 | * Set the accepted character sets |
| 374 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 375 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 376 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 377 | protected function _set_charsets() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 378 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 379 | if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 381 | $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 382 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 383 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 384 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | { |
| 386 | $this->charsets = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 387 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 391 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | /** |
| 393 | * Is Browser |
| 394 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 395 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 397 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 398 | public function is_browser($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 399 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 400 | if ( ! $this->is_browser) |
| 401 | { |
| 402 | return FALSE; |
| 403 | } |
| 404 | |
| 405 | // No need to be specific, it's a browser |
| 406 | if ($key === NULL) |
| 407 | { |
| 408 | return TRUE; |
| 409 | } |
| 410 | |
| 411 | // Check for a specific browser |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 412 | return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 416 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 417 | /** |
| 418 | * Is Robot |
| 419 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 420 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 421 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 422 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 423 | public function is_robot($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 424 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 425 | if ( ! $this->is_robot) |
| 426 | { |
| 427 | return FALSE; |
| 428 | } |
| 429 | |
| 430 | // No need to be specific, it's a robot |
| 431 | if ($key === NULL) |
| 432 | { |
| 433 | return TRUE; |
| 434 | } |
| 435 | |
| 436 | // Check for a specific robot |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 437 | return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 441 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | /** |
| 443 | * Is Mobile |
| 444 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 445 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 446 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 447 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 448 | public function is_mobile($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 450 | if ( ! $this->is_mobile) |
| 451 | { |
| 452 | return FALSE; |
| 453 | } |
| 454 | |
| 455 | // No need to be specific, it's a mobile |
| 456 | if ($key === NULL) |
| 457 | { |
| 458 | return TRUE; |
| 459 | } |
| 460 | |
| 461 | // Check for a specific robot |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 462 | return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 463 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 464 | |
| 465 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 466 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 467 | /** |
| 468 | * Is this a referral from another site? |
| 469 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 470 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 471 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 472 | public function is_referral() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | { |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 474 | static $result; |
| 475 | |
| 476 | if ( ! isset($result)) |
Andrey Andreev | a0836b9 | 2012-10-24 22:03:42 +0300 | [diff] [blame] | 477 | { |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 478 | if (empty($_SERVER['HTTP_REFERER'])) |
| 479 | { |
| 480 | $result = FALSE; |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); |
| 485 | $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); |
| 486 | |
| 487 | $result = ($referer_host && $referer_host !== $own_host); |
| 488 | } |
Andrey Andreev | a0836b9 | 2012-10-24 22:03:42 +0300 | [diff] [blame] | 489 | } |
| 490 | |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 491 | return $result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 495 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 496 | /** |
| 497 | * Agent String |
| 498 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 499 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 500 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 501 | public function agent_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 502 | { |
| 503 | return $this->agent; |
| 504 | } |
| 505 | |
| 506 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 507 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | /** |
| 509 | * Get Platform |
| 510 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 512 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 513 | public function platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 514 | { |
| 515 | return $this->platform; |
| 516 | } |
| 517 | |
| 518 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 519 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 520 | /** |
| 521 | * Get Browser Name |
| 522 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 523 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 524 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 525 | public function browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 526 | { |
| 527 | return $this->browser; |
| 528 | } |
| 529 | |
| 530 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 531 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 532 | /** |
| 533 | * Get the Browser Version |
| 534 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 535 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 536 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 537 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 538 | { |
| 539 | return $this->version; |
| 540 | } |
| 541 | |
| 542 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 543 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 544 | /** |
| 545 | * Get The Robot Name |
| 546 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 547 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 548 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 549 | public function robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 550 | { |
| 551 | return $this->robot; |
| 552 | } |
| 553 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 554 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 555 | /** |
| 556 | * Get the Mobile Device |
| 557 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 558 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 559 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 560 | public function mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | { |
| 562 | return $this->mobile; |
| 563 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 564 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 565 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 566 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 567 | /** |
| 568 | * Get the referrer |
| 569 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 570 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 571 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 572 | public function referrer() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 573 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 574 | return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 578 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 579 | /** |
| 580 | * Get the accepted languages |
| 581 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 582 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 583 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 584 | public function languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 586 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 587 | { |
| 588 | $this->_set_languages(); |
| 589 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 590 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | return $this->languages; |
| 592 | } |
| 593 | |
| 594 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 595 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 596 | /** |
| 597 | * Get the accepted Character Sets |
| 598 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 599 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 600 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 601 | public function charsets() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 602 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 603 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 604 | { |
| 605 | $this->_set_charsets(); |
| 606 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 607 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 608 | return $this->charsets; |
| 609 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 610 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 611 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 612 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 613 | /** |
| 614 | * Test for a particular language |
| 615 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 616 | * @param string $lang |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 617 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 618 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 619 | public function accept_lang($lang = 'en') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 621 | return in_array(strtolower($lang), $this->languages(), TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 623 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 624 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 625 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 626 | /** |
| 627 | * Test for a particular character set |
| 628 | * |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 629 | * @param string $charset |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 630 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 631 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 632 | public function accept_charset($charset = 'utf-8') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 633 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 634 | return in_array(strtolower($charset), $this->charsets(), TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 635 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 636 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 639 | /* End of file User_agent.php */ |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 640 | /* Location: ./system/libraries/User_agent.php */ |