summaryrefslogtreecommitdiffstats
path: root/system/libraries/User_agent.php
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-01-06 18:40:10 +0100
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-01-06 18:40:10 +0100
commitdac1b468d5432ff9166fe221ac520b5050a65f0e (patch)
tree6e3d80bf9d37347ede0244b480f08f8a330a1957 /system/libraries/User_agent.php
parentc2e9225eec976326df36b666d6baf6db29eee831 (diff)
Altered User agent library so that is_browser(), is_mobile() and is_robot() can optionally check for a specific browser or mobile device.
Diffstat (limited to 'system/libraries/User_agent.php')
-rw-r--r--system/libraries/User_agent.php95
1 files changed, 65 insertions, 30 deletions
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index c1fb0231a..53cd7b2fd 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -82,7 +82,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _load_agent_file()
+ private function _load_agent_file()
{
if ( ! @include(APPPATH.'config/user_agents'.EXT))
{
@@ -130,7 +130,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _compile_data()
+ private function _compile_data()
{
$this->_set_platform();
@@ -151,7 +151,7 @@ class CI_User_agent {
* @access private
* @return mixed
*/
- function _set_platform()
+ private function _set_platform()
{
if (is_array($this->platforms) AND count($this->platforms) > 0)
{
@@ -175,7 +175,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _set_browser()
+ private function _set_browser()
{
if (is_array($this->browsers) AND count($this->browsers) > 0)
{
@@ -202,7 +202,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _set_robot()
+ private function _set_robot()
{
if (is_array($this->robots) AND count($this->robots) > 0)
{
@@ -227,7 +227,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _set_mobile()
+ private function _set_mobile()
{
if (is_array($this->mobiles) AND count($this->mobiles) > 0)
{
@@ -252,7 +252,7 @@ class CI_User_agent {
* @access private
* @return void
*/
- function _set_languages()
+ private function _set_languages()
{
if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
{
@@ -275,7 +275,7 @@ class CI_User_agent {
* @access private
* @return void
*/
- function _set_charsets()
+ private function _set_charsets()
{
if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '')
{
@@ -298,9 +298,21 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_browser()
+ public function is_browser($key = NULL)
{
- return $this->is_browser;
+ 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
+ return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key];
}
// --------------------------------------------------------------------
@@ -311,9 +323,21 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_robot()
+ public function is_robot($key = NULL)
{
- return $this->is_robot;
+ 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
+ return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key];
}
// --------------------------------------------------------------------
@@ -324,9 +348,21 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_mobile()
+ public function is_mobile($key = NULL)
{
- return $this->is_mobile;
+ 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
+ return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key];
}
// --------------------------------------------------------------------
@@ -337,9 +373,9 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_referral()
+ public function is_referral()
{
- return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE;
+ return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '');
}
// --------------------------------------------------------------------
@@ -350,7 +386,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function agent_string()
+ public function agent_string()
{
return $this->agent;
}
@@ -363,7 +399,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function platform()
+ public function platform()
{
return $this->platform;
}
@@ -376,7 +412,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function browser()
+ public function browser()
{
return $this->browser;
}
@@ -389,7 +425,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function version()
+ public function version()
{
return $this->version;
}
@@ -402,7 +438,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function robot()
+ public function robot()
{
return $this->robot;
}
@@ -414,7 +450,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function mobile()
+ public function mobile()
{
return $this->mobile;
}
@@ -427,7 +463,7 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function referrer()
+ public function referrer()
{
return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
}
@@ -440,7 +476,7 @@ class CI_User_agent {
* @access public
* @return array
*/
- function languages()
+ public function languages()
{
if (count($this->languages) == 0)
{
@@ -458,7 +494,7 @@ class CI_User_agent {
* @access public
* @return array
*/
- function charsets()
+ public function charsets()
{
if (count($this->charsets) == 0)
{
@@ -476,9 +512,9 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function accept_lang($lang = 'en')
+ public function accept_lang($lang = 'en')
{
- return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE;
+ return (in_array(strtolower($lang), $this->languages(), TRUE));
}
// --------------------------------------------------------------------
@@ -489,12 +525,11 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function accept_charset($charset = 'utf-8')
+ public function accept_charset($charset = 'utf-8')
{
- return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE;
+ return (in_array(strtolower($charset), $this->charsets(), TRUE));
}
-
}