From 27e91a07ed66308ba02833b104ca8ca6a05e7be8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 01:00:48 +0200 Subject: Add CI_User_agent::parse() to allow parsing a custom user-agent string Based on PR #970 --- system/libraries/User_agent.php | 28 ++++++++++++++++++++++++++++ user_guide_src/source/changelog.rst | 6 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index e13bf8513..3a6b6bc98 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -634,6 +634,34 @@ class CI_User_agent { return in_array(strtolower($charset), $this->charsets(), TRUE); } + // -------------------------------------------------------------------- + + /** + * 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(); + } + } + } /* End of file User_agent.php */ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 67a2685da..cbc1c6656 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -369,7 +369,11 @@ Release Date: Not Released - Added the ability to use a proxy. - Added Basic HTTP authentication support. - - :doc:`User Agent Library ` will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions). + - :doc:`User Agent Library ` changes include: + + - Added check to detect if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions). + - Added method ``parse()`` to allow parsing a custom user-agent string, different from the current visitor's. + - Added support for setting :doc:`Table ` class defaults in a config file. - :doc:`Zip Library ` method ``read_file()`` can now also alter the original file path/name while adding files to an archive. -- cgit v1.2.3-24-g4f1b