summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-01-09 00:00:48 +0100
committerAndrey Andreev <narf@devilix.net>2014-01-09 00:00:48 +0100
commit27e91a07ed66308ba02833b104ca8ca6a05e7be8 (patch)
treee7c7f0b258052afe1be45e3d35f2d1a3a492b7cb
parent10925d27adac84634cc527d7298b1add0d54ba7c (diff)
Add CI_User_agent::parse() to allow parsing a custom user-agent string
Based on PR #970
-rw-r--r--system/libraries/User_agent.php28
-rw-r--r--user_guide_src/source/changelog.rst6
2 files changed, 33 insertions, 1 deletions
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 <libraries/user_agent>` will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions).
+ - :doc:`User Agent Library <libraries/user_agent>` 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 <libraries/table>` class defaults in a config file.
- :doc:`Zip Library <libraries/zip>` method ``read_file()`` can now also alter the original file path/name while adding files to an archive.