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