Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
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 |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, 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 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * User Agent Class |
| 32 | * |
cenk | 115e998 | 2011-09-27 10:07:53 +0300 | [diff] [blame] | 33 | * Identifies the platform, browser, robot, or mobile device of the browsing agent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 34 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Libraries |
| 37 | * @category User Agent |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 38 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | * @link http://codeigniter.com/user_guide/libraries/user_agent.html |
| 40 | */ |
| 41 | class CI_User_agent { |
| 42 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 43 | public $agent = NULL; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 44 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 45 | public $is_browser = FALSE; |
| 46 | public $is_robot = FALSE; |
| 47 | public $is_mobile = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 48 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 49 | public $languages = array(); |
| 50 | public $charsets = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 51 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 52 | public $platforms = array(); |
| 53 | public $browsers = array(); |
| 54 | public $mobiles = array(); |
| 55 | public $robots = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 56 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 57 | public $platform = ''; |
| 58 | public $browser = ''; |
| 59 | public $version = ''; |
| 60 | public $mobile = ''; |
| 61 | public $robot = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 62 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | /** |
| 64 | * Constructor |
| 65 | * |
| 66 | * Sets the User Agent and runs the compilation routine |
| 67 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 68 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 69 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 70 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | { |
| 72 | if (isset($_SERVER['HTTP_USER_AGENT'])) |
| 73 | { |
| 74 | $this->agent = trim($_SERVER['HTTP_USER_AGENT']); |
| 75 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 76 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | if ( ! is_null($this->agent)) |
| 78 | { |
| 79 | if ($this->_load_agent_file()) |
| 80 | { |
| 81 | $this->_compile_data(); |
| 82 | } |
| 83 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 84 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | log_message('debug', "User Agent Class Initialized"); |
| 86 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 87 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 89 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 90 | /** |
| 91 | * Compile the User Agent Data |
| 92 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 94 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 95 | protected function _load_agent_file() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | { |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 97 | if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) |
| 98 | { |
| 99 | include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); |
| 100 | } |
| 101 | elseif (is_file(APPPATH.'config/user_agents.php')) |
| 102 | { |
| 103 | include(APPPATH.'config/user_agents.php'); |
| 104 | } |
| 105 | else |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 106 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | return FALSE; |
| 108 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 109 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | $return = FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | if (isset($platforms)) |
| 113 | { |
| 114 | $this->platforms = $platforms; |
| 115 | unset($platforms); |
| 116 | $return = TRUE; |
| 117 | } |
| 118 | |
| 119 | if (isset($browsers)) |
| 120 | { |
| 121 | $this->browsers = $browsers; |
| 122 | unset($browsers); |
| 123 | $return = TRUE; |
| 124 | } |
| 125 | |
| 126 | if (isset($mobiles)) |
| 127 | { |
| 128 | $this->mobiles = $mobiles; |
| 129 | unset($mobiles); |
| 130 | $return = TRUE; |
| 131 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 132 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | if (isset($robots)) |
| 134 | { |
| 135 | $this->robots = $robots; |
| 136 | unset($robots); |
| 137 | $return = TRUE; |
| 138 | } |
| 139 | |
| 140 | return $return; |
| 141 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 142 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 144 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | /** |
| 146 | * Compile the User Agent Data |
| 147 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 149 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 150 | protected function _compile_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | { |
| 152 | $this->_set_platform(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 153 | |
Phil Sturgeon | 2c547df | 2011-08-10 08:36:02 -0600 | [diff] [blame] | 154 | foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | { |
| 156 | if ($this->$function() === TRUE) |
| 157 | { |
| 158 | break; |
| 159 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 160 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 162 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 163 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 164 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | /** |
| 166 | * Set the Platform |
| 167 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | * @return mixed |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 170 | protected function _set_platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | { |
| 172 | if (is_array($this->platforms) AND count($this->platforms) > 0) |
| 173 | { |
| 174 | foreach ($this->platforms as $key => $val) |
| 175 | { |
| 176 | if (preg_match("|".preg_quote($key)."|i", $this->agent)) |
| 177 | { |
| 178 | $this->platform = $val; |
| 179 | return TRUE; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | $this->platform = 'Unknown Platform'; |
| 184 | } |
| 185 | |
| 186 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 187 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | /** |
| 189 | * Set the Browser |
| 190 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 192 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 193 | protected function _set_browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | { |
| 195 | if (is_array($this->browsers) AND count($this->browsers) > 0) |
| 196 | { |
| 197 | foreach ($this->browsers as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 198 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 199 | if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) |
| 200 | { |
| 201 | $this->is_browser = TRUE; |
| 202 | $this->version = $match[1]; |
| 203 | $this->browser = $val; |
| 204 | $this->_set_mobile(); |
| 205 | return TRUE; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | return FALSE; |
| 210 | } |
Barry 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 | // -------------------------------------------------------------------- |
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 | /** |
| 215 | * Set the Robot |
| 216 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 218 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 219 | protected function _set_robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | { |
| 221 | if (is_array($this->robots) AND count($this->robots) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 222 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | foreach ($this->robots as $key => $val) |
| 224 | { |
| 225 | if (preg_match("|".preg_quote($key)."|i", $this->agent)) |
| 226 | { |
| 227 | $this->is_robot = TRUE; |
| 228 | $this->robot = $val; |
| 229 | return TRUE; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | return FALSE; |
| 234 | } |
| 235 | |
| 236 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 237 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 238 | /** |
| 239 | * Set the Mobile Device |
| 240 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 241 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 242 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 243 | protected function _set_mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | { |
| 245 | if (is_array($this->mobiles) AND count($this->mobiles) > 0) |
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 | foreach ($this->mobiles as $key => $val) |
| 248 | { |
| 249 | if (FALSE !== (strpos(strtolower($this->agent), $key))) |
| 250 | { |
| 251 | $this->is_mobile = TRUE; |
| 252 | $this->mobile = $val; |
| 253 | return TRUE; |
| 254 | } |
| 255 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 256 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | return FALSE; |
| 258 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 259 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 261 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | /** |
| 263 | * Set the accepted languages |
| 264 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 266 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 267 | protected function _set_languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 269 | if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 271 | $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] | 272 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 273 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 274 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | { |
| 276 | $this->languages = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 279 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 281 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 282 | /** |
| 283 | * Set the accepted character sets |
| 284 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 285 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 286 | */ |
Andrey Andreev | 75c5efb | 2011-12-26 16:28:40 +0200 | [diff] [blame] | 287 | protected function _set_charsets() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 288 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 289 | if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 291 | $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] | 292 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 293 | |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 294 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 295 | { |
| 296 | $this->charsets = array('Undefined'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 297 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 301 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | /** |
| 303 | * Is Browser |
| 304 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 307 | public function is_browser($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 309 | if ( ! $this->is_browser) |
| 310 | { |
| 311 | return FALSE; |
| 312 | } |
| 313 | |
| 314 | // No need to be specific, it's a browser |
| 315 | if ($key === NULL) |
| 316 | { |
| 317 | return TRUE; |
| 318 | } |
| 319 | |
| 320 | // Check for a specific browser |
| 321 | return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 325 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | /** |
| 327 | * Is Robot |
| 328 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 330 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 331 | public function is_robot($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 333 | if ( ! $this->is_robot) |
| 334 | { |
| 335 | return FALSE; |
| 336 | } |
| 337 | |
| 338 | // No need to be specific, it's a robot |
| 339 | if ($key === NULL) |
| 340 | { |
| 341 | return TRUE; |
| 342 | } |
| 343 | |
| 344 | // Check for a specific robot |
| 345 | return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 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 | /** |
| 351 | * Is Mobile |
| 352 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 353 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 354 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 355 | public function is_mobile($key = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 357 | if ( ! $this->is_mobile) |
| 358 | { |
| 359 | return FALSE; |
| 360 | } |
| 361 | |
| 362 | // No need to be specific, it's a mobile |
| 363 | if ($key === NULL) |
| 364 | { |
| 365 | return TRUE; |
| 366 | } |
| 367 | |
| 368 | // Check for a specific robot |
| 369 | return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 370 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | |
| 372 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 373 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 374 | /** |
| 375 | * Is this a referral from another site? |
| 376 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 378 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 379 | public function is_referral() |
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 | return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // -------------------------------------------------------------------- |
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 | /** |
| 387 | * Agent String |
| 388 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 390 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 391 | public function agent_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | { |
| 393 | return $this->agent; |
| 394 | } |
| 395 | |
| 396 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 397 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | /** |
| 399 | * Get Platform |
| 400 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 402 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 403 | public function platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | { |
| 405 | return $this->platform; |
| 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 | * Get Browser Name |
| 412 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 413 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 414 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 415 | public function browser() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | { |
| 417 | return $this->browser; |
| 418 | } |
| 419 | |
| 420 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 421 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 422 | /** |
| 423 | * Get the Browser Version |
| 424 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 425 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 426 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 427 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | { |
| 429 | return $this->version; |
| 430 | } |
| 431 | |
| 432 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 433 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 434 | /** |
| 435 | * Get The Robot Name |
| 436 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 437 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 438 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 439 | public function robot() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 440 | { |
| 441 | return $this->robot; |
| 442 | } |
| 443 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 444 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 445 | /** |
| 446 | * Get the Mobile Device |
| 447 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 448 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 449 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 450 | public function mobile() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 451 | { |
| 452 | return $this->mobile; |
| 453 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 454 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 455 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 456 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 457 | /** |
| 458 | * Get the referrer |
| 459 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 461 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 462 | public function referrer() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | { |
| 464 | return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); |
| 465 | } |
| 466 | |
| 467 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 468 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | /** |
| 470 | * Get the accepted languages |
| 471 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 472 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 473 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 474 | public function languages() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 475 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 476 | if (count($this->languages) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | { |
| 478 | $this->_set_languages(); |
| 479 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 480 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | return $this->languages; |
| 482 | } |
| 483 | |
| 484 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 485 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 486 | /** |
| 487 | * Get the accepted Character Sets |
| 488 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 489 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 490 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 491 | public function charsets() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | { |
Andrey Andreev | e9ccf74 | 2011-12-25 17:30:10 +0200 | [diff] [blame] | 493 | if (count($this->charsets) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | { |
| 495 | $this->_set_charsets(); |
| 496 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 497 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 498 | return $this->charsets; |
| 499 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 500 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 502 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 503 | /** |
| 504 | * Test for a particular language |
| 505 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 507 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 508 | public function accept_lang($lang = 'en') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 509 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 510 | return (in_array(strtolower($lang), $this->languages(), TRUE)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 512 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 513 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 514 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | /** |
| 516 | * Test for a particular character set |
| 517 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 518 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 519 | */ |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 520 | public function accept_charset($charset = 'utf-8') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | { |
Phil Sturgeon | dac1b46 | 2011-01-06 17:40:10 +0000 | [diff] [blame] | 522 | return (in_array(strtolower($charset), $this->charsets(), TRUE)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 523 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 524 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 527 | /* End of file User_agent.php */ |
cenk | 115e998 | 2011-09-27 10:07:53 +0300 | [diff] [blame] | 528 | /* Location: ./system/libraries/User_agent.php */ |