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 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
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 | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, 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 |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 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 |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 49 | * @link https://codeigniter.com/user_guide/libraries/user_agent.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | { |
Andrey Andreev | b010475 | 2016-07-19 14:36:20 +0300 | [diff] [blame] | 176 | $this->_load_agent_file(); |
| 177 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 178 | if (isset($_SERVER['HTTP_USER_AGENT'])) |
| 179 | { |
| 180 | $this->agent = trim($_SERVER['HTTP_USER_AGENT']); |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 181 | $this->_compile_data(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 183 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 184 | log_message('info', 'User Agent Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 186 | |
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 | /** |
| 190 | * Compile the User Agent Data |
| 191 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 192 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 194 | protected function _load_agent_file() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 196 | if (($found = file_exists(APPPATH.'config/user_agents.php'))) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 197 | { |
| 198 | include(APPPATH.'config/user_agents.php'); |
| 199 | } |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 200 | |
| 201 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) |
| 202 | { |
| 203 | include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); |
| 204 | $found = TRUE; |
| 205 | } |
| 206 | |
| 207 | if ($found !== TRUE) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 208 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | return FALSE; |
| 210 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 211 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | $return = FALSE; |
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 | if (isset($platforms)) |
| 215 | { |
| 216 | $this->platforms = $platforms; |
| 217 | unset($platforms); |
| 218 | $return = TRUE; |
| 219 | } |
| 220 | |
| 221 | if (isset($browsers)) |
| 222 | { |
| 223 | $this->browsers = $browsers; |
| 224 | unset($browsers); |
| 225 | $return = TRUE; |
| 226 | } |
| 227 | |
| 228 | if (isset($mobiles)) |
| 229 | { |
| 230 | $this->mobiles = $mobiles; |
| 231 | unset($mobiles); |
| 232 | $return = TRUE; |
| 233 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 234 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 235 | if (isset($robots)) |
| 236 | { |
| 237 | $this->robots = $robots; |
| 238 | unset($robots); |
| 239 | $return = TRUE; |
| 240 | } |
| 241 | |
| 242 | return $return; |
| 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 | /** |
| 248 | * Compile the User Agent Data |
| 249 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 251 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 252 | protected function _compile_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | { |
| 254 | $this->_set_platform(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 255 | |
Phil Sturgeon | 2c547df | 2011-08-10 08:36:02 -0600 | [diff] [blame] | 256 | foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | { |
| 258 | if ($this->$function() === TRUE) |
| 259 | { |
| 260 | break; |
| 261 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 262 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | /** |
| 268 | * Set the Platform |
| 269 | * |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 270 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 271 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 272 | protected function _set_platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 273 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 274 | if (is_array($this->platforms) && count($this->platforms) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | { |
| 276 | foreach ($this->platforms as $key => $val) |
| 277 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 278 | if (preg_match('|'.preg_quote($key).'|i', $this->agent)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | { |
| 280 | $this->platform = $val; |
| 281 | return TRUE; |
| 282 | } |
| 283 | } |
| 284 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 285 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | $this->platform = 'Unknown Platform'; |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 287 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 291 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | /** |
| 293 | * Set the Browser |
| 294 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 295 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 296 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 297 | protected function _set_browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 299 | if (is_array($this->browsers) && count($this->browsers) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | { |
| 301 | foreach ($this->browsers as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 302 | { |
Andrey Andreev | 10925d2 | 2014-01-09 00:16:46 +0200 | [diff] [blame] | 303 | if (preg_match('|'.$key.'.*?([0-9\.]+)|i', $this->agent, $match)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | { |
| 305 | $this->is_browser = TRUE; |
| 306 | $this->version = $match[1]; |
| 307 | $this->browser = $val; |
| 308 | $this->_set_mobile(); |
| 309 | return TRUE; |
| 310 | } |
| 311 | } |
| 312 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 313 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 314 | return FALSE; |
| 315 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 316 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | /** |
| 320 | * Set the Robot |
| 321 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 323 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 324 | protected function _set_robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 326 | if (is_array($this->robots) && count($this->robots) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 327 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 328 | foreach ($this->robots as $key => $val) |
| 329 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 330 | if (preg_match('|'.preg_quote($key).'|i', $this->agent)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 331 | { |
| 332 | $this->is_robot = TRUE; |
| 333 | $this->robot = $val; |
Eric Roberts | 001a764 | 2012-04-14 16:41:13 -0500 | [diff] [blame] | 334 | $this->_set_mobile(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | return TRUE; |
| 336 | } |
| 337 | } |
| 338 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 339 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 340 | return FALSE; |
| 341 | } |
| 342 | |
| 343 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 344 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | /** |
| 346 | * Set the Mobile Device |
| 347 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 348 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 349 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 350 | protected function _set_mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 351 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 352 | if (is_array($this->mobiles) && count($this->mobiles) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 353 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 354 | foreach ($this->mobiles as $key => $val) |
| 355 | { |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 356 | if (FALSE !== (stripos($this->agent, $key))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | { |
| 358 | $this->is_mobile = TRUE; |
| 359 | $this->mobile = $val; |
| 360 | return TRUE; |
| 361 | } |
| 362 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 363 | } |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 364 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | return FALSE; |
| 366 | } |
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 | /** |
| 371 | * Set the accepted languages |
| 372 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 373 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 374 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 375 | protected function _set_languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 376 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 377 | if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 378 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 379 | $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] | 380 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 381 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 382 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | { |
| 384 | $this->languages = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 385 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | } |
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 | /** |
| 391 | * Set the accepted character sets |
| 392 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 393 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 394 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 395 | protected function _set_charsets() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 396 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 397 | if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 399 | $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] | 400 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 401 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 402 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | { |
| 404 | $this->charsets = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 409 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | /** |
| 411 | * Is Browser |
| 412 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 413 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 415 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 416 | public function is_browser($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 417 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 418 | if ( ! $this->is_browser) |
| 419 | { |
| 420 | return FALSE; |
| 421 | } |
| 422 | |
| 423 | // No need to be specific, it's a browser |
| 424 | if ($key === NULL) |
| 425 | { |
| 426 | return TRUE; |
| 427 | } |
| 428 | |
| 429 | // Check for a specific browser |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 430 | return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 434 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 435 | /** |
| 436 | * Is Robot |
| 437 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 438 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 440 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 441 | public function is_robot($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 443 | if ( ! $this->is_robot) |
| 444 | { |
| 445 | return FALSE; |
| 446 | } |
| 447 | |
| 448 | // No need to be specific, it's a robot |
| 449 | if ($key === NULL) |
| 450 | { |
| 451 | return TRUE; |
| 452 | } |
| 453 | |
| 454 | // Check for a specific robot |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 455 | return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 459 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | /** |
| 461 | * Is Mobile |
| 462 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 463 | * @param string $key |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 464 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 465 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 466 | public function is_mobile($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 467 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 468 | if ( ! $this->is_mobile) |
| 469 | { |
| 470 | return FALSE; |
| 471 | } |
| 472 | |
| 473 | // No need to be specific, it's a mobile |
| 474 | if ($key === NULL) |
| 475 | { |
| 476 | return TRUE; |
| 477 | } |
| 478 | |
| 479 | // Check for a specific robot |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 480 | return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 481 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 482 | |
| 483 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 484 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 485 | /** |
| 486 | * Is this a referral from another site? |
| 487 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 489 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 490 | public function is_referral() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 491 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 492 | if ( ! isset($this->referer)) |
Andrey Andreev | a0836b9 | 2012-10-24 22:03:42 +0300 | [diff] [blame] | 493 | { |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 494 | if (empty($_SERVER['HTTP_REFERER'])) |
| 495 | { |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 496 | $this->referer = FALSE; |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 497 | } |
| 498 | else |
| 499 | { |
| 500 | $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); |
| 501 | $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); |
| 502 | |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 503 | $this->referer = ($referer_host && $referer_host !== $own_host); |
vlakoff | c05ab73 | 2013-07-20 20:27:57 +0200 | [diff] [blame] | 504 | } |
Andrey Andreev | a0836b9 | 2012-10-24 22:03:42 +0300 | [diff] [blame] | 505 | } |
| 506 | |
Andrey Andreev | a9938a0 | 2014-01-17 14:55:56 +0200 | [diff] [blame] | 507 | return $this->referer; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 511 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | /** |
| 513 | * Agent String |
| 514 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 516 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 517 | public function agent_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 518 | { |
| 519 | return $this->agent; |
| 520 | } |
| 521 | |
| 522 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 523 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 524 | /** |
| 525 | * Get Platform |
| 526 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 527 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 528 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 529 | public function platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 530 | { |
| 531 | return $this->platform; |
| 532 | } |
| 533 | |
| 534 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 535 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 536 | /** |
| 537 | * Get Browser Name |
| 538 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 539 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 540 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 541 | public function browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 542 | { |
| 543 | return $this->browser; |
| 544 | } |
| 545 | |
| 546 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 547 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 548 | /** |
| 549 | * Get the Browser Version |
| 550 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 552 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 553 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 554 | { |
| 555 | return $this->version; |
| 556 | } |
| 557 | |
| 558 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 559 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 560 | /** |
| 561 | * Get The Robot Name |
| 562 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 563 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 564 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 565 | public function robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 566 | { |
| 567 | return $this->robot; |
| 568 | } |
| 569 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 570 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 571 | /** |
| 572 | * Get the Mobile Device |
| 573 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 574 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 575 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 576 | public function mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 577 | { |
| 578 | return $this->mobile; |
| 579 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 580 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | /** |
| 584 | * Get the referrer |
| 585 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 586 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 587 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 588 | public function referrer() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 589 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 590 | return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 594 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 595 | /** |
| 596 | * Get the accepted languages |
| 597 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 598 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 599 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 600 | public function languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 601 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 602 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | { |
| 604 | $this->_set_languages(); |
| 605 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 606 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 607 | return $this->languages; |
| 608 | } |
| 609 | |
| 610 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 611 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 612 | /** |
| 613 | * Get the accepted Character Sets |
| 614 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 615 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 616 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 617 | public function charsets() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 618 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 619 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | { |
| 621 | $this->_set_charsets(); |
| 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 | return $this->charsets; |
| 625 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 626 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | /** |
| 630 | * Test for a particular language |
| 631 | * |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 632 | * @param string $lang |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 633 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 634 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 635 | public function accept_lang($lang = 'en') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 637 | return in_array(strtolower($lang), $this->languages(), TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 638 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 639 | |
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 | /** |
| 643 | * Test for a particular character set |
| 644 | * |
Andrey Andreev | ca7d822 | 2012-05-11 10:59:09 +0300 | [diff] [blame] | 645 | * @param string $charset |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 646 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 647 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 648 | public function accept_charset($charset = 'utf-8') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 649 | { |
Andrey Andreev | d3bc53d | 2012-04-03 16:37:19 +0300 | [diff] [blame] | 650 | return in_array(strtolower($charset), $this->charsets(), TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 651 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 652 | |
Andrey Andreev | 27e91a0 | 2014-01-09 01:00:48 +0200 | [diff] [blame] | 653 | // -------------------------------------------------------------------- |
| 654 | |
| 655 | /** |
| 656 | * Parse a custom user-agent string |
| 657 | * |
| 658 | * @param string $string |
| 659 | * @return void |
| 660 | */ |
| 661 | public function parse($string) |
| 662 | { |
| 663 | // Reset values |
| 664 | $this->is_browser = FALSE; |
| 665 | $this->is_robot = FALSE; |
| 666 | $this->is_mobile = FALSE; |
| 667 | $this->browser = ''; |
| 668 | $this->version = ''; |
| 669 | $this->mobile = ''; |
| 670 | $this->robot = ''; |
| 671 | |
| 672 | // Set the new user-agent string and parse it, unless empty |
| 673 | $this->agent = $string; |
| 674 | |
| 675 | if ( ! empty($string)) |
| 676 | { |
| 677 | $this->_compile_data(); |
| 678 | } |
| 679 | } |
| 680 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 681 | } |