Fixed bug #11585: Faulty usage of t3lib_matchCondition in backend template
authorOliver Hader <oliver.hader@typo3.org>
Sat, 1 Aug 2009 22:56:35 +0000 (22:56 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 1 Aug 2009 22:56:35 +0000 (22:56 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5747 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_matchcondition.php
t3lib/core_autoload.php
t3lib/utility/class.t3lib_utility_client.php [new file with mode: 0644]
typo3/template.php

index 8a9b373..a433d31 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-08-02  Oliver Hader  <oliver@typo3.org>
+
+       * Fixed bug #11585: Faulty usage of t3lib_matchCondition in backend template
+
 2009-08-02  Christian Kuhn  <lollli@schwarzbu.ch>
 
        * Added feature #11500: Order fe_groups in select fields alphabetically (Thanks to Steffen Gebert)
index 03b1ed7..9bc1240 100644 (file)
@@ -534,99 +534,7 @@ class t3lib_matchCondition {
                        }
                }
 
-               $useragent = trim($useragent);
-               $browserInfo=Array();
-               $browserInfo['useragent']=$useragent;
-               if ($useragent) {
-                       // browser
-                       if (strstr($useragent,'MSIE'))  {
-                               $browserInfo['browser']='msie';
-                       } elseif(strstr($useragent,'Konqueror'))        {
-                               $browserInfo['browser']='konqueror';
-                       } elseif(strstr($useragent,'Opera'))    {
-                               $browserInfo['browser']='opera';
-                       } elseif(strstr($useragent,'Lynx'))     {
-                               $browserInfo['browser']='lynx';
-                       } elseif(strstr($useragent,'PHP'))      {
-                               $browserInfo['browser']='php';
-                       } elseif(strstr($useragent,'AvantGo'))  {
-                               $browserInfo['browser']='avantgo';
-                       } elseif(strstr($useragent,'WebCapture'))       {
-                               $browserInfo['browser']='acrobat';
-                       } elseif(strstr($useragent,'IBrowse'))  {
-                               $browserInfo['browser']='ibrowse';
-                       } elseif(strstr($useragent,'Teleport')) {
-                               $browserInfo['browser']='teleport';
-                       } elseif(strstr($useragent,'Mozilla'))  {
-                               $browserInfo['browser']='netscape';
-                       } else {
-                               $browserInfo['browser']='unknown';
-                       }
-                       // version
-                       switch($browserInfo['browser']) {
-                               case 'netscape':
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($useragent,8));
-                                       if (strstr($useragent,'Netscape6')) {$browserInfo['version']=6;}
-                               break;
-                               case 'msie':
-                                       $tmp = strstr($useragent,'MSIE');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
-                               break;
-                               case 'opera':
-                                       $tmp = strstr($useragent,'Opera');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
-                               break;
-                               case 'lynx':
-                                       $tmp = strstr($useragent,'Lynx/');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
-                               break;
-                               case 'php':
-                                       $tmp = strstr($useragent,'PHP/');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
-                               break;
-                               case 'avantgo':
-                                       $tmp = strstr($useragent,'AvantGo');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,7));
-                               break;
-                               case 'acrobat':
-                                       $tmp = strstr($useragent,'WebCapture');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
-                               break;
-                               case 'ibrowse':
-                                       $tmp = strstr($useragent,'IBrowse/');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,8));
-                               break;
-                               case 'konqueror':
-                                       $tmp = strstr($useragent,'Konqueror/');
-                                       $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
-                               break;
-                       }
-                       // system
-                       $browserInfo['system']='';
-                       if (strstr($useragent,'Win'))   {
-                               // windows
-                               if (strstr($useragent,'Win98') || strstr($useragent,'Windows 98'))      {
-                                       $browserInfo['system']='win98';
-                               } elseif (strstr($useragent,'Win95') || strstr($useragent,'Windows 95'))        {
-                                       $browserInfo['system']='win95';
-                               } elseif (strstr($useragent,'WinNT') || strstr($useragent,'Windows NT'))        {
-                                       $browserInfo['system']='winNT';
-                               } elseif (strstr($useragent,'Win16') || strstr($useragent,'Windows 311'))       {
-                                       $browserInfo['system']='win311';
-                               }
-                       } elseif (strstr($useragent,'Mac'))     {
-                               $browserInfo['system']='mac';
-                               // unixes
-                       } elseif (strstr($useragent,'Linux'))   {
-                               $browserInfo['system']='linux';
-                       } elseif (strstr($useragent,'SGI') && strstr($useragent,' IRIX '))      {
-                               $browserInfo['system']='unix_sgi';
-                       } elseif (strstr($useragent,' SunOS ')) {
-                               $browserInfo['system']='unix_sun';
-                       } elseif (strstr($useragent,' HP-UX ')) {
-                               $browserInfo['system']='unix_hp';
-                       }
-               }
+               $browserInfo = t3lib_utility_client::getBrowserInfo($useragent);
 
                return $browserInfo;
        }
@@ -636,9 +544,11 @@ class t3lib_matchCondition {
         *
         * @param       string          A string with version number, eg. "/7.32 blablabla"
         * @return      double          Returns double value, eg. "7.32"
+        * @deprecated  since TYPO3 4.3 - use t3lib_utility_client::getVersion() instead
         */
        function browserInfo_version($tmp)      {
-               return doubleval(preg_replace('/^[^0-9]*/','',$tmp));
+               t3lib_div::logDeprecatedFunction();
+               return t3lib_utility_client::getVersion($tmp);
        }
 
        /**
index 442aac4..082395c 100644 (file)
@@ -99,6 +99,7 @@ return array(
        't3lib_localrecordlistgettablehook' => PATH_t3lib . 'interfaces/interface.t3lib_localrecordlistgettablehook.php',
        't3lib_singleton' => PATH_t3lib . 'interfaces/interface.t3lib_singleton.php',
        't3lib_tceformsinlinehook' => PATH_t3lib . 'interfaces/interface.t3lib_tceformsinlinehook.php',
+       't3lib_utility_client' => PATH_t3lib . 'utility/class.t3lib_utility_client.php',
        'tslib_adminpanel' => PATH_tslib . 'class.tslib_adminpanel.php',
        'tslib_cobj' => PATH_tslib . 'class.tslib_content.php',
        'tslib_frameset' => PATH_tslib . 'class.tslib_content.php',
diff --git a/t3lib/utility/class.t3lib_utility_client.php b/t3lib/utility/class.t3lib_utility_client.php
new file mode 100644 (file)
index 0000000..8de341f
--- /dev/null
@@ -0,0 +1,174 @@
+<?php
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2009 Oliver Hader <oliver@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ * A copy is found in the textfile GPL.txt and important notices to the license
+ * from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Class to handle and determine browser specific information.
+ *
+ * $Id$
+ *
+ * @author     Oliver Hader <oliver@typo3.org>
+ */
+final class t3lib_utility_client {
+       /**
+        * Generates an array with abstracted browser information
+        * This method is used in the function match() in this class
+        *
+        * @param       string          $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
+        * @return      array           Contains keys "browser", "version", "system"
+        */
+       static public function getBrowserInfo($userAgent) {
+                       // Hook: $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/div/class.t3lib_utility_client.php']['getBrowserInfo']:
+               $getBrowserInfoHooks =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/div/class.t3lib_utility_client.php']['getBrowserInfo'];
+               if (is_array($getBrowserInfoHooks)) {
+                       foreach ($getBrowserInfoHooks as $hookFunction) {
+                               $returnResult = true;
+                               $hookParameters = array(
+                                       'userAgent' => &$userAgent,
+                                       'returnResult' => &$returnResult,
+                               );
+
+                               $hookResult = t3lib_div::callUserFunction($hookFunction, $hookParameters, NULL);
+                               if ($returnResult && is_array($hookResult) && count($hookResult)) {
+                                       return $hookResult;
+                               }
+                       }
+               }
+
+               $userAgent = trim($userAgent);
+               $browserInfo = array(
+                       'useragent' => $userAgent,
+               );
+
+               if ($userAgent) {
+                       // browser
+                       if (strstr($userAgent,'MSIE'))  {
+                               $browserInfo['browser']='msie';
+                       } elseif(strstr($userAgent,'Konqueror'))        {
+                               $browserInfo['browser']='konqueror';
+                       } elseif(strstr($userAgent,'Opera'))    {
+                               $browserInfo['browser']='opera';
+                       } elseif(strstr($userAgent,'Lynx'))     {
+                               $browserInfo['browser']='lynx';
+                       } elseif(strstr($userAgent,'PHP'))      {
+                               $browserInfo['browser']='php';
+                       } elseif(strstr($userAgent,'AvantGo'))  {
+                               $browserInfo['browser']='avantgo';
+                       } elseif(strstr($userAgent,'WebCapture'))       {
+                               $browserInfo['browser']='acrobat';
+                       } elseif(strstr($userAgent,'IBrowse'))  {
+                               $browserInfo['browser']='ibrowse';
+                       } elseif(strstr($userAgent,'Teleport')) {
+                               $browserInfo['browser']='teleport';
+                       } elseif(strstr($userAgent,'Mozilla'))  {
+                               $browserInfo['browser']='netscape';
+                       } else {
+                               $browserInfo['browser']='unknown';
+                       }
+
+                       // version
+                       switch($browserInfo['browser']) {
+                               case 'netscape':
+                                       $browserInfo['version'] = self::getVersion(substr($userAgent, 8));
+                                       if (strstr($userAgent, 'Netscape6')) {
+                                               $browserInfo['version'] = 6;
+                                       }
+                               break;
+                               case 'msie':
+                                       $tmp = strstr($userAgent, 'MSIE');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 4));
+                               break;
+                               case 'opera':
+                                       $tmp = strstr($userAgent, 'Opera');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 5));
+                               break;
+                               case 'lynx':
+                                       $tmp = strstr($userAgent, 'Lynx/');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 5));
+                               break;
+                               case 'php':
+                                       $tmp = strstr($userAgent, 'PHP/');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 4));
+                               break;
+                               case 'avantgo':
+                                       $tmp = strstr($userAgent, 'AvantGo');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 7));
+                               break;
+                               case 'acrobat':
+                                       $tmp = strstr($userAgent, 'WebCapture');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 10));
+                               break;
+                               case 'ibrowse':
+                                       $tmp = strstr($userAgent, 'IBrowse/');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp ,8));
+                               break;
+                               case 'konqueror':
+                                       $tmp = strstr($userAgent, 'Konqueror/');
+                                       $browserInfo['version'] = self::getVersion(substr($tmp, 10));
+                               break;
+                       }
+                       // system
+                       $browserInfo['system'] = '';
+                       if (strstr($userAgent, 'Win')) {
+                               // windows
+                               if (strstr($userAgent, 'Win98') || strstr($userAgent, 'Windows 98')) {
+                                       $browserInfo['system'] = 'win98';
+                               } elseif (strstr($userAgent, 'Win95') || strstr($userAgent, 'Windows 95')) {
+                                       $browserInfo['system'] = 'win95';
+                               } elseif (strstr($userAgent, 'WinNT') || strstr($userAgent, 'Windows NT')) {
+                                       $browserInfo['system'] = 'winNT';
+                               } elseif (strstr($userAgent, 'Win16') || strstr($userAgent, 'Windows 311')) {
+                                       $browserInfo['system'] = 'win311';
+                               }
+                       } elseif (strstr($userAgent,'Mac')) {
+                               $browserInfo['system'] = 'mac';
+                               // unixes
+                       } elseif (strstr($userAgent, 'Linux')) {
+                               $browserInfo['system'] = 'linux';
+                       } elseif (strstr($userAgent, 'SGI') && strstr($userAgent, ' IRIX ')) {
+                               $browserInfo['system'] = 'unix_sgi';
+                       } elseif (strstr($userAgent, ' SunOS ')) {
+                               $browserInfo['system'] = 'unix_sun';
+                       } elseif (strstr($userAgent, ' HP-UX ')) {
+                               $browserInfo['system'] = 'unix_hp';
+                       }
+               }
+
+               return $browserInfo;
+       }
+
+       /**
+        * Returns the version of a browser; Basically getting doubleval() of the input string,
+        * stripping of any non-numeric values in the beginning of the string first.
+        *
+        * @param       string          $version: A string with version number, eg. "/7.32 blablabla"
+        * @return      double          Returns double value, eg. "7.32"
+        */
+       static public function getVersion($version) {
+               return doubleval(preg_replace('/^[^0-9]*/', '', $version));
+       }
+}
+?>
\ No newline at end of file
index 8d381cd..061c772 100644 (file)
@@ -674,8 +674,7 @@ class template {
                }
 
                        // Get the browser info
-               $matchObject = t3lib_div::makeInstance('t3lib_matchCondition');
-               $browserInfo = $matchObject->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
+               $browserInfo = t3lib_utility_client::getBrowserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
 
                        // Set the XML prologue
                $xmlPrologue = '<?xml version="1.0" encoding="' . $this->charset . '"?>';