| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * CodeIgniter | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * An open source application development framework for PHP | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * This content is released under the MIT License (MIT) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-11-07 03:05:55 +08:00
										 |  |  |  * Copyright (c) 2014 - 2019, British Columbia Institute of Technology | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package	CodeIgniter | 
					
						
							|  |  |  |  * @author	EllisLab Dev Team | 
					
						
							|  |  |  |  * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) | 
					
						
							| 
									
										
										
										
											2021-11-07 03:05:55 +08:00
										 |  |  |  * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) | 
					
						
							|  |  |  |  * @license	https://opensource.org/licenses/MIT	MIT License | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * @link	https://codeigniter.com | 
					
						
							|  |  |  |  * @since	Version 1.0.0 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  * @filesource | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | defined('BASEPATH') OR exit('No direct script access allowed'); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * User Agent Class | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * Identifies the platform, browser, robot, or mobile device of the browsing agent | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @package		CodeIgniter | 
					
						
							|  |  |  |  * @subpackage	Libraries | 
					
						
							|  |  |  |  * @category	User Agent | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * @author		EllisLab Dev Team | 
					
						
							| 
									
										
										
										
											2021-11-07 03:05:55 +08:00
										 |  |  |  * @link		https://codeigniter.com/userguide3/libraries/user_agent.html | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | class CI_User_agent { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Current user-agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $agent = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Flag for if the user-agent belongs to a browser | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $is_browser = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Flag for if the user-agent is a robot | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $is_robot = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Flag for if the user-agent is a mobile browser | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $is_mobile = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Languages accepted by the current user agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $languages = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Character sets accepted by the current user agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $charsets = array(); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * List of platforms to compare against current user agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $platforms = array(); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * List of browsers to compare against current user agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $browsers = array(); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * List of mobile browsers to compare against current user agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $mobiles = array(); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * List of robots to compare against current user agent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $robots = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Current user-agent platform | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $platform = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Current user-agent browser | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $browser = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Current user-agent version | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $version = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Current user-agent mobile name | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $mobile = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Current user-agent robot name | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $robot = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * HTTP Referer | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var	mixed | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public $referer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Constructor | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Sets the User Agent and runs the compilation routine | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	void | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function __construct() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		$this->_load_agent_file(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		if (isset($_SERVER['HTTP_USER_AGENT'])) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->agent = trim($_SERVER['HTTP_USER_AGENT']); | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			$this->_compile_data(); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		log_message('info', 'User Agent Class Initialized'); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile the User Agent Data | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _load_agent_file() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (($found = file_exists(APPPATH.'config/user_agents.php'))) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			include(APPPATH.'config/user_agents.php'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); | 
					
						
							|  |  |  | 			$found = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($found !== TRUE) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$return = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (isset($platforms)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->platforms = $platforms; | 
					
						
							|  |  |  | 			unset($platforms); | 
					
						
							|  |  |  | 			$return = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (isset($browsers)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->browsers = $browsers; | 
					
						
							|  |  |  | 			unset($browsers); | 
					
						
							|  |  |  | 			$return = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (isset($mobiles)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->mobiles = $mobiles; | 
					
						
							|  |  |  | 			unset($mobiles); | 
					
						
							|  |  |  | 			$return = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (isset($robots)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->robots = $robots; | 
					
						
							|  |  |  | 			unset($robots); | 
					
						
							|  |  |  | 			$return = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile the User Agent Data | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _compile_data() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		$this->_set_platform(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			if ($this->$function() === TRUE) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the Platform | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	 * @return	bool | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _set_platform() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (is_array($this->platforms) && count($this->platforms) > 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			foreach ($this->platforms as $key => $val) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				if (preg_match('|'.preg_quote($key).'|i', $this->agent)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					$this->platform = $val; | 
					
						
							|  |  |  | 					return TRUE; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		$this->platform = 'Unknown Platform'; | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the Browser | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _set_browser() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (is_array($this->browsers) && count($this->browsers) > 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			foreach ($this->browsers as $key => $val) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				if (preg_match('|'.$key.'.*?([0-9\.]+)|i', $this->agent, $match)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					$this->is_browser = TRUE; | 
					
						
							|  |  |  | 					$this->version = $match[1]; | 
					
						
							|  |  |  | 					$this->browser = $val; | 
					
						
							|  |  |  | 					$this->_set_mobile(); | 
					
						
							|  |  |  | 					return TRUE; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		return FALSE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the Robot | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _set_robot() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (is_array($this->robots) && count($this->robots) > 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			foreach ($this->robots as $key => $val) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				if (preg_match('|'.preg_quote($key).'|i', $this->agent)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					$this->is_robot = TRUE; | 
					
						
							|  |  |  | 					$this->robot = $val; | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 					$this->_set_mobile(); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 					return TRUE; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		return FALSE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the Mobile Device | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _set_mobile() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (is_array($this->mobiles) && count($this->mobiles) > 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			foreach ($this->mobiles as $key => $val) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				if (FALSE !== (stripos($this->agent, $key))) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					$this->is_mobile = TRUE; | 
					
						
							|  |  |  | 					$this->mobile = $val; | 
					
						
							|  |  |  | 					return TRUE; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		return FALSE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the accepted languages | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	void | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _set_languages() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			$this->languages = explode(',', preg_replace('/(;\s?q=[0-9\.]+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (count($this->languages) === 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$this->languages = array('Undefined'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the accepted character sets | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	void | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	protected function _set_charsets() | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET'])) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			$this->charsets = explode(',', preg_replace('/(;\s?q=.+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (count($this->charsets) === 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$this->charsets = array('Undefined'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is Browser | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	 * @param	string	$key | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function is_browser($key = NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ( ! $this->is_browser) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// No need to be specific, it's a browser
 | 
					
						
							|  |  |  | 		if ($key === NULL) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Check for a specific browser
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is Robot | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	 * @param	string	$key | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function is_robot($key = NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ( ! $this->is_robot) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// No need to be specific, it's a robot
 | 
					
						
							|  |  |  | 		if ($key === NULL) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Check for a specific robot
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is Mobile | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	 * @param	string	$key | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function is_mobile($key = NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ( ! $this->is_mobile) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// No need to be specific, it's a mobile
 | 
					
						
							|  |  |  | 		if ($key === NULL) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Check for a specific robot
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is this a referral from another site? | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function is_referral() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if ( ! isset($this->referer)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			if (empty($_SERVER['HTTP_REFERER'])) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				$this->referer = FALSE; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				$referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); | 
					
						
							|  |  |  | 				$own_host = parse_url(config_item('base_url'), PHP_URL_HOST); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				$this->referer = ($referer_host && $referer_host !== $own_host); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return $this->referer; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Agent String | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function agent_string() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->agent; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get Platform | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function platform() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->platform; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get Browser Name | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function browser() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->browser; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get the Browser Version | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function version() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->version; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get The Robot Name | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function robot() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->robot; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get the Mobile Device | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function mobile() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->mobile; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get the referrer | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function referrer() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get the accepted languages | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function languages() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (count($this->languages) === 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$this->_set_languages(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->languages; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get the accepted Character Sets | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function charsets() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (count($this->charsets) === 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$this->_set_charsets(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->charsets; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Test for a particular language | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	 * @param	string	$lang | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function accept_lang($lang = 'en') | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return in_array(strtolower($lang), $this->languages(), TRUE); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Test for a particular character set | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	 * @param	string	$charset | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	 * @return	bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function accept_charset($charset = 'utf-8') | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return in_array(strtolower($charset), $this->charsets(), TRUE); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	// --------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Parse a custom user-agent string | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	string	$string | 
					
						
							|  |  |  | 	 * @return	void | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function parse($string) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Reset values
 | 
					
						
							|  |  |  | 		$this->is_browser = FALSE; | 
					
						
							|  |  |  | 		$this->is_robot = FALSE; | 
					
						
							|  |  |  | 		$this->is_mobile = FALSE; | 
					
						
							|  |  |  | 		$this->browser = ''; | 
					
						
							|  |  |  | 		$this->version = ''; | 
					
						
							|  |  |  | 		$this->mobile = ''; | 
					
						
							|  |  |  | 		$this->robot = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Set the new user-agent string and parse it, unless empty
 | 
					
						
							|  |  |  | 		$this->agent = $string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ( ! empty($string)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->_compile_data(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | } |