From e9ccf74554266bf8122359d4221a228725c54218 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 17:30:10 +0200 Subject: Improve the User agent library --- system/libraries/User_agent.php | 63 ++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index a007acec8..060de695f 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,13 +1,13 @@ -languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') + if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { - $languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); - - $this->languages = explode(',', $languages); + $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); } - if (count($this->languages) == 0) + if (count($this->languages) === 0) { $this->languages = array('Undefined'); } @@ -297,14 +295,12 @@ class CI_User_agent { */ private function _set_charsets() { - if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') + if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { - $charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); - - $this->charsets = explode(',', $charsets); + $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); } - if (count($this->charsets) == 0) + if (count($this->charsets) === 0) { $this->charsets = array('Undefined'); } @@ -395,11 +391,7 @@ class CI_User_agent { */ public function is_referral() { - if ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') - { - return FALSE; - } - return TRUE; + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -502,7 +494,7 @@ class CI_User_agent { */ public function languages() { - if (count($this->languages) == 0) + if (count($this->languages) === 0) { $this->_set_languages(); } @@ -520,7 +512,7 @@ class CI_User_agent { */ public function charsets() { - if (count($this->charsets) == 0) + if (count($this->charsets) === 0) { $this->_set_charsets(); } @@ -556,6 +548,5 @@ class CI_User_agent { } - /* End of file User_agent.php */ /* Location: ./system/libraries/User_agent.php */ -- cgit v1.2.3-24-g4f1b From 75c5efbc6abf6a789bedaf6a0cb5fa41b36a31eb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Dec 2011 16:28:40 +0200 Subject: Replace private with protected, so the class can be easily extended --- system/libraries/User_agent.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 060de695f..d55fc3e14 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -91,10 +91,10 @@ class CI_User_agent { /** * Compile the User Agent Data * - * @access private + * @access protected * @return bool */ - private function _load_agent_file() + protected function _load_agent_file() { if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) { @@ -147,10 +147,10 @@ class CI_User_agent { /** * Compile the User Agent Data * - * @access private + * @access protected * @return bool */ - private function _compile_data() + protected function _compile_data() { $this->_set_platform(); @@ -168,10 +168,10 @@ class CI_User_agent { /** * Set the Platform * - * @access private + * @access protected * @return mixed */ - private function _set_platform() + protected function _set_platform() { if (is_array($this->platforms) AND count($this->platforms) > 0) { @@ -192,10 +192,10 @@ class CI_User_agent { /** * Set the Browser * - * @access private + * @access protected * @return bool */ - private function _set_browser() + protected function _set_browser() { if (is_array($this->browsers) AND count($this->browsers) > 0) { @@ -219,10 +219,10 @@ class CI_User_agent { /** * Set the Robot * - * @access private + * @access protected * @return bool */ - private function _set_robot() + protected function _set_robot() { if (is_array($this->robots) AND count($this->robots) > 0) { @@ -244,10 +244,10 @@ class CI_User_agent { /** * Set the Mobile Device * - * @access private + * @access protected * @return bool */ - private function _set_mobile() + protected function _set_mobile() { if (is_array($this->mobiles) AND count($this->mobiles) > 0) { @@ -269,10 +269,10 @@ class CI_User_agent { /** * Set the accepted languages * - * @access private + * @access protected * @return void */ - private function _set_languages() + protected function _set_languages() { if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { @@ -290,10 +290,10 @@ class CI_User_agent { /** * Set the accepted character sets * - * @access private + * @access protected * @return void */ - private function _set_charsets() + protected function _set_charsets() { if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { -- cgit v1.2.3-24-g4f1b From 394ae12c0512ac5b376fd26b022c760ca8661e95 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Dec 2011 02:40:41 +0200 Subject: Remove access lines from method descriptions --- system/libraries/User_agent.php | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index d55fc3e14..c31ff2646 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -65,7 +65,6 @@ class CI_User_agent { * * Sets the User Agent and runs the compilation routine * - * @access public * @return void */ public function __construct() @@ -91,7 +90,6 @@ class CI_User_agent { /** * Compile the User Agent Data * - * @access protected * @return bool */ protected function _load_agent_file() @@ -147,7 +145,6 @@ class CI_User_agent { /** * Compile the User Agent Data * - * @access protected * @return bool */ protected function _compile_data() @@ -168,7 +165,6 @@ class CI_User_agent { /** * Set the Platform * - * @access protected * @return mixed */ protected function _set_platform() @@ -192,7 +188,6 @@ class CI_User_agent { /** * Set the Browser * - * @access protected * @return bool */ protected function _set_browser() @@ -219,7 +214,6 @@ class CI_User_agent { /** * Set the Robot * - * @access protected * @return bool */ protected function _set_robot() @@ -244,7 +238,6 @@ class CI_User_agent { /** * Set the Mobile Device * - * @access protected * @return bool */ protected function _set_mobile() @@ -269,7 +262,6 @@ class CI_User_agent { /** * Set the accepted languages * - * @access protected * @return void */ protected function _set_languages() @@ -290,7 +282,6 @@ class CI_User_agent { /** * Set the accepted character sets * - * @access protected * @return void */ protected function _set_charsets() @@ -311,7 +302,6 @@ class CI_User_agent { /** * Is Browser * - * @access public * @return bool */ public function is_browser($key = NULL) @@ -336,7 +326,6 @@ class CI_User_agent { /** * Is Robot * - * @access public * @return bool */ public function is_robot($key = NULL) @@ -361,7 +350,6 @@ class CI_User_agent { /** * Is Mobile * - * @access public * @return bool */ public function is_mobile($key = NULL) @@ -386,7 +374,6 @@ class CI_User_agent { /** * Is this a referral from another site? * - * @access public * @return bool */ public function is_referral() @@ -399,7 +386,6 @@ class CI_User_agent { /** * Agent String * - * @access public * @return string */ public function agent_string() @@ -412,7 +398,6 @@ class CI_User_agent { /** * Get Platform * - * @access public * @return string */ public function platform() @@ -425,7 +410,6 @@ class CI_User_agent { /** * Get Browser Name * - * @access public * @return string */ public function browser() @@ -438,7 +422,6 @@ class CI_User_agent { /** * Get the Browser Version * - * @access public * @return string */ public function version() @@ -451,7 +434,6 @@ class CI_User_agent { /** * Get The Robot Name * - * @access public * @return string */ public function robot() @@ -463,7 +445,6 @@ class CI_User_agent { /** * Get the Mobile Device * - * @access public * @return string */ public function mobile() @@ -476,7 +457,6 @@ class CI_User_agent { /** * Get the referrer * - * @access public * @return bool */ public function referrer() @@ -489,7 +469,6 @@ class CI_User_agent { /** * Get the accepted languages * - * @access public * @return array */ public function languages() @@ -507,7 +486,6 @@ class CI_User_agent { /** * Get the accepted Character Sets * - * @access public * @return array */ public function charsets() @@ -525,7 +503,6 @@ class CI_User_agent { /** * Test for a particular language * - * @access public * @return bool */ public function accept_lang($lang = 'en') @@ -538,7 +515,6 @@ class CI_User_agent { /** * Test for a particular character set * - * @access public * @return bool */ public function accept_charset($charset = 'utf-8') -- cgit v1.2.3-24-g4f1b