Permalink
Browse files

issue #623 : Add support for detection of Internet Explorer running i…

…n compatibility mode.
  • Loading branch information...
1 parent 16c26ff commit 14aadfb09d71d89e38c530943b74af0640b40d8a @AndrewPodner committed Dec 25, 2012
@@ -104,6 +104,13 @@
'IBrowse' => 'IBrowse'
);
+// Internet Explorer Trident engines used to determine IE7 compatibility mode
+$msie_compatibility_modes = array(
+ '8.0' => 'Trident/4',
+ '9.0' => 'Trident/5',
+ '10.0' => 'Trident/6'
+);
+
$mobiles = array(
// legacy array, old values commented out
'mobileexplorer' => 'Mobile Explorer',
@@ -54,6 +54,13 @@ class CI_User_agent {
public $is_browser = FALSE;
/**
+ * Flag for if the user agent is MSIE in compatibility mode
+ *
+ * @var bool
+ */
+ public $is_compatibility_mode = FALSE;
+
+ /**
* Flag for if the user-agent is a robot
*
* @var bool
@@ -96,6 +103,13 @@ class CI_User_agent {
public $browsers = array();
/**
+ * List of MSIE trident engines to determine compatibility mode
+ *
+ * @var array
+ */
+ public $msie_compatibility_modes = array();
+
+ /**
* List of mobile browsers to compare against current user agent
*
* @var array
@@ -204,6 +218,13 @@ protected function _load_agent_file()
$return = TRUE;
}
+ if (isset($msie_compatibility_modes))
+ {
+ $this->msie_compatibility_modes = $msie_compatibility_modes;
+ unset($msie_compatibility_modes);
+ $return = TRUE;
+ }
+
if (isset($mobiles))
{
$this->mobiles = $mobiles;
@@ -285,6 +306,7 @@ protected function _set_browser()
$this->version = $match[1];
$this->browser = $val;
$this->_set_mobile();
+ $this->_set_msie_compatibility();
return TRUE;
}
}
@@ -345,6 +367,32 @@ protected function _set_mobile()
}
// --------------------------------------------------------------------
+ /**
+ * Detect MSIE Compatibility Mode (IE8, IE9, IE10)
+ *
+ * @return void
+ */
+ protected function _set_msie_compatibility()
+ {
+ // Check for any possible IE7 compatibility mode
+ if (strstr($this->agent, 'MSIE 7'))
+ {
+ // Iterate Trident engines, and look for a match
+ foreach ($this->msie_compatibility_modes as $version => $engine)
+ {
+ // If a match is found change to the real version and append
+ // browser name to show it is running in compatibility mode
+ if (strstr($this->agent, $engine))
+ {
+ $this->is_compatibility_mode = TRUE;
+ $this->browser .= ' (Compatibility Mode)';
+ $this->version = $version;
+ }
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
/**
* Set the accepted languages
@@ -516,6 +564,18 @@ public function browser()
// --------------------------------------------------------------------
/**
+ * Get whether browser is MSIE in compatibility mode
+ *
+ * @return bool
+ */
+ public function compatibility_mode()
+ {
+ return $this->is_compatibility_mode;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get the Browser Version
*
* @return string
@@ -267,8 +267,9 @@ Release Date: Not Released
- :doc:`Migration Library <libraries/migration>` changes include:
- Added support for timestamp-based migrations (enabled by default).
- Added ``$config['migration_type']`` to allow switching between *sequential* and *timestamp* migrations.
- - :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:
+ - Will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions).
+ - Will detect Internet Explorer 8,9,10 running in IE7 compatibility mode
- Core
- :doc:`URI Library <libraries/uri>` changes include:
@@ -127,6 +127,14 @@ $this->agent->browser()
Returns a string containing the name of the web browser viewing your
site.
+$this->agent->compatibility_mode()
+==================================
+
+Returns a boolean identifying whether or not Internet Explorer running
+in compatibility mode was detected in the user agent string. This is
+based on comparing the reported browser version to the Trident engine
+version in the user agent string.
+
$this->agent->version()
=======================

0 comments on commit 14aadfb

Please sign in to comment.