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 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014, British Columbia Institute of Technology |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) |
| 33 | * @license http://opensource.org/licenses/MIT MIT License |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * User Agent Class |
| 42 | * |
cenk | 115e998 | 2011-09-27 10:07:53 +0300 | [diff] [blame] | 43 | * Identifies the platform, browser, robot, or mobile device of the browsing agent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 44 | * |
| 45 | * @package CodeIgniter |
| 46 | * @subpackage Libraries |
| 47 | * @category User Agent |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 48 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | * @link http://codeigniter.com/user_guide/libraries/user_agent.html |
| 50 | */ |
| 51 | class CI_User_agent { |
| 52 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 53 | /** |
| 54 | * Current user-agent |
| 55 | * |
| 56 | * @var string |
| 57 | */ |
| 58 | public $agent = NULL; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 59 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 60 | /** |
| 61 | * Flag for if the user-agent belongs to a browser |
| 62 | * |
| 63 | * @var bool |
| 64 | */ |
| 65 | public $is_browser = FALSE; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 66 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 67 | /** |
| 68 | * Flag for if the user-agent is a robot |
| 69 | * |
| 70 | * @var bool |
| 71 | */ |
| 72 | public $is_robot = FALSE; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 73 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 74 | /** |
| 75 | * Flag for if the user-agent is a mobile browser |
| 76 | * |
| 77 | * @var bool |
| 78 | */ |
| 79 | public $is_mobile = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 81 | /** |
| 82 | * Languages accepted by the current user agent |
| 83 | * |
| 84 | * @var array |
| 85 | */ |
| 86 | public $languages = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 87 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 88 | /** |
| 89 | * Character sets accepted by the current user agent |
| 90 | * |
| 91 | * @var array |
| 92 | */ |
| 93 | public $charsets = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 94 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 95 | /** |
| 96 | * List of platforms to compare against current user agent |
| 97 | * |
| 98 | * @var array |
| 99 | */ |
| 100 | public $platforms = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 101 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 102 | /** |
| 103 | * List of browsers to compare against current user agent |
| 104 | * |
| 105 | * @var array |
| 106 | */ |
| 107 | public $browsers = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 108 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 109 | /** |
| 110 | * List of mobile browsers to compare against current user agent |
| 111 | * |
| 112 | * @var array |
| 113 | */ |
| 114 | public $mobiles = array(); |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 115 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 116 | /** |
| 117 | * List of robots to compare against current user agent |
| 118 | * |
| 119 | * @var array |
| 120 | */ |
| 121 | public $robots = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 122 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 123 | /** |
| 124 | * Current user-agent platform |
| 125 | * |
| 126 | * @var string |
| 127 | */ |
| 128 | public $platform = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 129 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 130 | /** |
| 131 | * Current user-agent browser |
| 132 | * |
| 133 | * @var string |
| 134 | */ |
| 135 | public $browser = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 136 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 137 | /** |
| 138 | * Current user-agent version |
| 139 | * |
| 140 | * @var string |
| 141 | */ |
| 142 | public $version = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 143 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 144 | /** |
| 145 | * Current user-agent mobile name |
| 146 | * |
| 147 | * @var string |
| 148 | */ |
| 149 | public $mobile = ''; |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 150 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 151 | /** |
| 152 | * Current user-agent robot name |
| 153 | * |
| 154 | * @var string |
| 155 | */ |
| 156 | public $robot = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 157 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 158 | /** |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 159 | * HTTP Referer |
| 160 | * |
| 161 | * @var mixed |
| 162 | */ |
| 163 | public $referer; |
| 164 | |
| 165 | // -------------------------------------------------------------------- |
| 166 | |
| 167 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | * Constructor |
| 169 | * |
| 170 | * Sets the User Agent and runs the compilation routine |
| 171 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 173 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 174 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 175 | { |
| 176 | if (isset($_SERVER['HTTP_USER_AGENT'])) |
| 177 | { |
| 178 | $this->agent = trim($_SERVER['HTTP_USER_AGENT']); |
| 179 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 180 | |
vlakoff | 1228fe2 | 2013-01-14 01:30:09 +0100 | [diff] [blame] | 181 | if ($this->agent !== NULL && $this->_load_agent_file()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 183 | $this->_compile_data(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 184 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 185 | |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 186 | log_message('debug', 'User Agent Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 187 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 188 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 189 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 190 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | /** |
| 192 | * Compile the User Agent Data |
| 193 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 195 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 196 | protected function _load_agent_file() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 198 | if (($found = file_exists(APPPATH.'config/user_agents.php'))) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 199 | { |
| 200 | include(APPPATH.'config/user_agents.php'); |
| 201 | } |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 202 | |
| 203 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) |
| 204 | { |
| 205 | include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); |
| 206 | $found = TRUE; |
| 207 | } |
| 208 | |
| 209 | if ($found !== TRUE) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 210 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | return FALSE; |
| 212 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | $return = FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 215 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 216 | if (isset($platforms)) |
| 217 | { |
| 218 | $this->platforms = $platforms; |
| 219 | unset($platforms); |
| 220 | $return = TRUE; |
| 221 | } |
| 222 | |
| 223 | if (isset($browsers)) |
| 224 | { |
| 225 | $this->browsers = $browsers; |
| 226 | unset($browsers); |
| 227 | $return = TRUE; |
| 228 | } |
| 229 | |
| 230 | if (isset($mobiles)) |
| 231 | { |
| 232 | $this->mobiles = $mobiles; |
| 233 | unset($mobiles); |
| 234 | $return = TRUE; |
| 235 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 236 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | if (isset($robots)) |
| 238 | { |
| 239 | $this->robots = $robots; |
| 240 | unset($robots); |
| 241 | $return = TRUE; |
| 242 | } |
| 243 | |
| 244 | return $return; |
| 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 | * Compile the User Agent Data |
| 251 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [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 _compile_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | { |
| 256 | $this->_set_platform(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 257 | |
Phil Sturgeon | 2c547df | 2011-08-10 08:36:02 -0600 | [diff] [blame] | 258 | foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 259 | { |
| 260 | if ($this->$function() === TRUE) |
| 261 | { |
| 262 | break; |
| 263 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 264 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 266 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 267 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 268 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 269 | /** |
| 270 | * Set the Platform |
| 271 | * |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 272 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 273 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 274 | protected function _set_platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 276 | if (is_array($this->platforms) && count($this->platforms) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 277 | { |
| 278 | foreach ($this->platforms as $key => $val) |
| 279 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 280 | if (preg_match('|'.preg_quote($key).'|i', $this->agent)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 281 | { |
| 282 | $this->platform = $val; |
| 283 | return TRUE; |
| 284 | } |
| 285 | } |
| 286 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 287 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | $this->platform = 'Unknown Platform'; |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 289 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 293 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 294 | /** |
| 295 | * Set the Browser |
| 296 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 297 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 298 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 299 | protected function _set_browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 301 | if (is_array($this->browsers) && count($this->browsers) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | { |
| 303 | foreach ($this->browsers as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 304 | { |
Andrey Andreev | 10925d2 | 2014-01-09 00:16:46 +0200 | [diff] [blame] | 305 | if (preg_match('|'.$key.'.*?([0-9\.]+)|i', $this->agent, $match)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | { |
| 307 | $this->is_browser = TRUE; |
| 308 | $this->version = $match[1]; |
| 309 | $this->browser = $val; |
| 310 | $this->_set_mobile(); |
| 311 | return TRUE; |
| 312 | } |
| 313 | } |
| 314 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 315 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | return FALSE; |
| 317 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 318 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 320 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 321 | /** |
| 322 | * Set the Robot |
| 323 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 324 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 325 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 326 | protected function _set_robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 328 | if (is_array($this->robots) && count($this->robots) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 329 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | foreach ($this->robots as $key => $val) |
| 331 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 332 | if (preg_match('|'.preg_quote($key).'|i', $this->agent)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | { |
| 334 | $this->is_robot = TRUE; |
| 335 | $this->robot = $val; |
Eric Roberts | 001a764 | 2012-04-14 16:41:13 -0500 | [diff] [blame] | 336 | $this->_set_mobile(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | return TRUE; |
| 338 | } |
| 339 | } |
| 340 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 341 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 342 | return FALSE; |
| 343 | } |
| 344 | |
| 345 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 346 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | /** |
| 348 | * Set the Mobile Device |
| 349 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 350 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 351 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 352 | protected function _set_mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 353 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 354 | if (is_array($this->mobiles) && count($this->mobiles) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 355 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | foreach ($this->mobiles as $key => $val) |
| 357 | { |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 358 | if (FALSE !== (stripos($this->agent, $key))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 359 | { |
| 360 | $this->is_mobile = TRUE; |
| 361 | $this->mobile = $val; |
| 362 | return TRUE; |
| 363 | } |
| 364 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 365 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 366 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | return FALSE; |
| 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 languages |
| 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_languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 378 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 379 | if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 381 | $this->languages = explode(',', preg_replace('/(;\s?q=[0-9\.]+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); |
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->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | { |
| 386 | $this->languages = 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 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 389 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | * Set the accepted character sets |
| 394 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 395 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 396 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 397 | protected function _set_charsets() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 398 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 399 | if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 400 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 401 | $this->charsets = explode(',', preg_replace('/(;\s?q=.+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 402 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 403 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 404 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 405 | { |
| 406 | $this->charsets = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 407 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 411 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | /** |
| 413 | * Is Browser |
| 414 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 415 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 417 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 418 | public function is_browser($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 420 | if ( ! $this->is_browser) |
| 421 | { |
| 422 | return FALSE; |
| 423 | } |
| 424 | |
| 425 | // No need to be specific, it's a browser |
| 426 | if ($key === NULL) |
| 427 | { |
| 428 | return TRUE; |
| 429 | } |
| 430 | |
| 431 | // Check for a specific browser |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 432 | return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 437 | /** |
| 438 | * Is Robot |
| 439 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 440 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 441 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 442 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 443 | public function is_robot($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 444 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 445 | if ( ! $this->is_robot) |
| 446 | { |
| 447 | return FALSE; |
| 448 | } |
| 449 | |
| 450 | // No need to be specific, it's a robot |
| 451 | if ($key === NULL) |
| 452 | { |
| 453 | return TRUE; |
| 454 | } |
| 455 | |
| 456 | // Check for a specific robot |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 457 | return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 461 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 462 | /** |
| 463 | * Is Mobile |
| 464 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 465 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 467 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 468 | public function is_mobile($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 470 | if ( ! $this->is_mobile) |
| 471 | { |
| 472 | return FALSE; |
| 473 | } |
| 474 | |
| 475 | // No need to be specific, it's a mobile |
| 476 | if ($key === NULL) |
| 477 | { |
| 478 | return TRUE; |
| 479 | } |
| 480 | |
| 481 | // Check for a specific robot |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 482 | return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 483 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 484 | |
| 485 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 486 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 487 | /** |
| 488 | * Is this a referral from another site? |
| 489 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 491 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 492 | public function is_referral() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 493 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 494 | if ( ! isset($this->referer)) |
Andrey Andreev | a0836b9 | 2012-10-24 22:03:42 +0300 | [diff] [blame] | 495 | { |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 496 | if (empty($_SERVER['HTTP_REFERER'])) |
| 497 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 498 | $this->referer = FALSE; |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 499 | } |
| 500 | else |
| 501 | { |
| 502 | $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); |
| 503 | $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); |
| 504 | |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 505 | $this->referer = ($referer_host && $referer_host !== $own_host); |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 506 | } |
Andrey Andreev | a0836b9 | 2012-10-24 22:03:42 +0300 | [diff] [blame] | 507 | } |
| 508 | |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 509 | return $this->referer; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 513 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 514 | /** |
| 515 | * Agent String |
| 516 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 518 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 519 | public function agent_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 520 | { |
| 521 | return $this->agent; |
| 522 | } |
| 523 | |
| 524 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 525 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 526 | /** |
| 527 | * Get Platform |
| 528 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 529 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 530 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 531 | public function platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 532 | { |
| 533 | return $this->platform; |
| 534 | } |
| 535 | |
| 536 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 537 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 538 | /** |
| 539 | * Get Browser Name |
| 540 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 541 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 542 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 543 | public function browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 544 | { |
| 545 | return $this->browser; |
| 546 | } |
| 547 | |
| 548 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 549 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 550 | /** |
| 551 | * Get the Browser Version |
| 552 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 553 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 554 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 555 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 556 | { |
| 557 | return $this->version; |
| 558 | } |
| 559 | |
| 560 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 561 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 562 | /** |
| 563 | * Get The Robot Name |
| 564 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 565 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 566 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 567 | public function robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 568 | { |
| 569 | return $this->robot; |
| 570 | } |
| 571 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 572 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 573 | /** |
| 574 | * Get the Mobile Device |
| 575 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 576 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 577 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 578 | public function mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 579 | { |
| 580 | return $this->mobile; |
| 581 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 582 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 583 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 584 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | /** |
| 586 | * Get the referrer |
| 587 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 588 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 589 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 590 | public function referrer() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 592 | return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 596 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 597 | /** |
| 598 | * Get the accepted languages |
| 599 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 600 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 601 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 602 | public function languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 604 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 605 | { |
| 606 | $this->_set_languages(); |
| 607 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 608 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | return $this->languages; |
| 610 | } |
| 611 | |
| 612 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 613 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 614 | /** |
| 615 | * Get the accepted Character Sets |
| 616 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 617 | * @return array |
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 charsets() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 621 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | { |
| 623 | $this->_set_charsets(); |
| 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 | return $this->charsets; |
| 627 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 628 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 629 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 630 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 631 | /** |
| 632 | * Test for a particular language |
| 633 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 634 | * @param string $lang |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 635 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 636 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 637 | public function accept_lang($lang = 'en') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 638 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 639 | return in_array(strtolower($lang), $this->languages(), TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 640 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 641 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 642 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 643 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 644 | /** |
| 645 | * Test for a particular character set |
| 646 | * |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 647 | * @param string $charset |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 648 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 649 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 650 | public function accept_charset($charset = 'utf-8') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 651 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 652 | return in_array(strtolower($charset), $this->charsets(), TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 653 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 654 | |
Andrey Andreev | 27e91a0 | 2014-01-09 01:00:48 +0200 | [diff] [blame] | 655 | // -------------------------------------------------------------------- |
| 656 | |
| 657 | /** |
| 658 | * Parse a custom user-agent string |
| 659 | * |
| 660 | * @param string $string |
| 661 | * @return void |
| 662 | */ |
| 663 | public function parse($string) |
| 664 | { |
| 665 | // Reset values |
| 666 | $this->is_browser = FALSE; |
| 667 | $this->is_robot = FALSE; |
| 668 | $this->is_mobile = FALSE; |
| 669 | $this->browser = ''; |
| 670 | $this->version = ''; |
| 671 | $this->mobile = ''; |
| 672 | $this->robot = ''; |
| 673 | |
| 674 | // Set the new user-agent string and parse it, unless empty |
| 675 | $this->agent = $string; |
| 676 | |
| 677 | if ( ! empty($string)) |
| 678 | { |
| 679 | $this->_compile_data(); |
| 680 | } |
| 681 | } |
| 682 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 685 | /* End of file User_agent.php */ |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 686 | /* Location: ./system/libraries/User_agent.php */ |