class.t3lib_matchcondition.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Contains class for Matching TypoScript conditions
00029  *
00030  * $Id: class.t3lib_matchcondition.php 4432 2008-11-07 03:52:22Z flyguide $
00031  * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
00032  *
00033  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *   80: class t3lib_matchCondition
00041  *   87:     function __construct()
00042  *  105:     function t3lib_matchCondition()
00043  *  115:     function match($condition_line)
00044  *  160:     function evalConditionStr($string)
00045  *  381:     function testNumber($test,$value)
00046  *  405:     function matchWild($haystack,$needle)
00047  *  429:     function whichDevice($useragent)
00048  *  498:     function browserInfo($useragent)
00049  *  611:     function browserInfo_version($tmp)
00050  *  624:     function getGlobal($var, $source=NULL)
00051  *  658:     function getGP_ENV_TSFE($var)
00052  *
00053  * TOTAL FUNCTIONS: 11
00054  * (This index is automatically created/updated by the extension "extdeveval")
00055  *
00056  */
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 /**
00070  * Matching TypoScript conditions
00071  *
00072  * Used with the TypoScript parser.
00073  * Matches browserinfo, IPnumbers for use with templates
00074  *
00075  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00076  * @package TYPO3
00077  * @subpackage t3lib
00078  * @see t3lib_TStemplate::matching(), t3lib_TStemplate::generateConfig()
00079  */
00080 class t3lib_matchCondition {
00081     var $matchAlternative=array();      // If this array has elements, the matching returns true if a whole "matchline" is found in the array!
00082     var $matchAll=0;                    // If set all is matched!
00083 
00084     var $altRootLine=array();
00085     var $hookObjectsArr = array();
00086 
00087     /**
00088      * Constructor for this class
00089      *
00090      * @return  void
00091      */
00092     function __construct()  {
00093         global $TYPO3_CONF_VARS;
00094 
00095         // Usage (ext_localconf.php):
00096         // $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][] =
00097         // 'EXT:my_ext/class.browserinfo.php:MyBrowserInfoClass';
00098         if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'])) {
00099             foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'] as $classRef) {
00100                 $this->hookObjectsArr[] = &t3lib_div::getUserObj($classRef, '');
00101             }
00102         }
00103     }
00104 
00105     /**
00106      * Constructor for this class
00107      *
00108      * @return  void
00109      */
00110     function t3lib_matchCondition() {
00111         $this->__construct();
00112     }
00113 
00114     /**
00115      * Matching TS condition
00116      *
00117      * @param   string      Line to match
00118      * @return  boolean     True if matched
00119      */
00120     function match($condition_line) {
00121         if ($this->matchAll) {
00122             return true;
00123         }
00124         if (count($this->matchAlternative)) {
00125             return in_array($condition_line, $this->matchAlternative);
00126         }
00127 
00128             // Getting the value from inside of the wrapping square brackets of the condition line:
00129         $insideSqrBrackets = substr(trim($condition_line), 1, strlen($condition_line) - 2);
00130         $insideSqrBrackets = preg_replace('/\]\s*OR\s*\[/i', ']||[', $insideSqrBrackets);
00131         $insideSqrBrackets = preg_replace('/\]\s*AND\s*\[/i', ']&&[', $insideSqrBrackets);
00132 
00133             // The "weak" operator "||" (OR) takes precedence: backwards compatible, [XYZ][ZYX] does still work as OR
00134         $orParts = preg_split('/\]\s*(\|\|){0,1}\s*\[/',$insideSqrBrackets);
00135 
00136         foreach ($orParts as $partString)   {
00137             $matches = false;
00138 
00139                 // Splits by the "&&" (AND) operator:
00140             $andParts = preg_split('/\]\s*&&\s*\[/',$partString);
00141             foreach ($andParts as $condStr) {
00142                 $matches = $this->evalConditionStr($condStr);
00143                 if ($matches===false)   {
00144                     break;      // only true AND true = true, so we have to break here
00145                 }
00146             }
00147 
00148             if ($matches===true)    {
00149                 break;      // true OR false = true, so we break if we have a positive result
00150             }
00151         }
00152 
00153         return $matches;
00154     }
00155 
00156 
00157     /**
00158      * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
00159      *
00160      * @param   string      The condition to match against its criterias.
00161      * @return  boolean     Returns true or false based on the evaluation.
00162      * @see t3lib_tsparser::parse()
00163      * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=292&cHash=c6c7d43d2f
00164      */
00165     function evalConditionStr($string)  {
00166         if (!is_array($this->altRootLine)) {
00167             $this->altRootLine = array();
00168         }
00169         list($key, $value) = explode('=', $string, 2);
00170         $key = trim($key);
00171         if (stristr(',browser,version,system,useragent,', ",$key,")) {
00172             $browserInfo = $this->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
00173         }
00174         $value = trim($value);
00175         switch ($key) {
00176             case 'browser':
00177                 $values = explode(',',$value);
00178                 while(list(,$test)=each($values))   {
00179                     if (strstr($browserInfo['browser'].$browserInfo['version'],trim($test)))    {
00180                         return true;
00181                     }
00182                 }
00183             break;
00184             case 'version':
00185                 $values = explode(',',$value);
00186                 while(list(,$test)=each($values))   {
00187                     $test = trim($test);
00188                     if (strlen($test)) {
00189                         if (strcspn($test,'=<>')==0)    {
00190                             switch(substr($test,0,1))   {
00191                                 case '=':
00192                                     if (doubleval(substr($test,1))==$browserInfo['version']) return true;
00193                                 break;
00194                                 case '<':
00195                                     if (doubleval(substr($test,1))>$browserInfo['version']) return true;
00196                                 break;
00197                                 case '>':
00198                                     if (doubleval(substr($test,1))<$browserInfo['version']) return true;
00199                                 break;
00200                             }
00201                         } else {
00202                             if (strpos(' '.$browserInfo['version'],$test)==1)   {return true;}
00203                         }
00204                     }
00205                 }
00206             break;
00207             case 'system':
00208                 $values = explode(',',$value);
00209                 while(list(,$test)=each($values))   {
00210                     $test = trim($test);
00211                     if (strlen($test)) {
00212                         if (strpos(' '.$browserInfo['system'],$test)==1)    {return true;}
00213                     }
00214                 }
00215             break;
00216             case 'device':
00217                 $values = explode(',',$value);
00218                 if (!isset($this->deviceInfo))  {
00219                     $this->deviceInfo = $this->whichDevice(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
00220                 }
00221                 while(list(,$test)=each($values))   {
00222                     $test = trim($test);
00223                     if (strlen($test)) {
00224                         if ($this->deviceInfo==$test)   {return true;}
00225                     }
00226                 }
00227             break;
00228             case 'useragent':
00229                 $test = trim($value);
00230                 if (strlen($test)) {
00231                     return $this->matchWild($browserInfo['useragent'],$test);
00232                 }
00233             break;
00234             case 'language':
00235                 $values = explode(',',$value);
00236                 while(list(,$test)=each($values))   {
00237                     $test = trim($test);
00238                     if (strlen($test)) {
00239                         if (preg_match('/^\*.+\*$/',$test)) {
00240                             $allLanguages = split('[,;]',t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
00241                             if (in_array(substr($test,1,-1), $allLanguages))    {return true;}
00242                         } else {
00243                             if (t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE') == $test) {return true;}
00244                         }
00245                     }
00246                 }
00247             break;
00248             case 'IP':
00249                 if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value)) {return true;}
00250             break;
00251             case 'hostname':
00252                 if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value))  {return true;}
00253             break;
00254                 // hour, minute, dayofweek, dayofmonth, month, year, julianday
00255             case 'hour':
00256             case 'minute':
00257             case 'month':
00258             case 'year':
00259             case 'dayofweek':
00260             case 'dayofmonth':
00261             case 'dayofyear':
00262                 $theEvalTime = $GLOBALS['SIM_EXEC_TIME'];   // In order to simulate time properly in templates.
00263                 switch($key) {
00264                     case 'hour':        $theTestValue = date('H',$theEvalTime); break;
00265                     case 'minute':      $theTestValue = date('i',$theEvalTime); break;
00266                     case 'month':       $theTestValue = date('m',$theEvalTime); break;
00267                     case 'year':        $theTestValue = date('Y',$theEvalTime); break;
00268                     case 'dayofweek':   $theTestValue = date('w',$theEvalTime); break;
00269                     case 'dayofmonth':  $theTestValue = date('d',$theEvalTime); break;
00270                     case 'dayofyear':   $theTestValue = date('z',$theEvalTime); break;
00271                 }
00272                 $theTestValue = intval($theTestValue);
00273                     // comp
00274                 $values = explode(',',$value);
00275                 reset($values);
00276                 while(list(,$test)=each($values))   {
00277                     $test = trim($test);
00278                     if (t3lib_div::testInt($test))  {$test='='.$test;}
00279                     if (strlen($test)) {
00280                         if ($this->testNumber($test,$theTestValue)) {return true;}
00281                     }
00282                 }
00283             break;
00284             case 'usergroup':
00285                 if ($GLOBALS['TSFE']->gr_list!='0,-1')  {       // '0,-1' is the default usergroups when not logged in!
00286                     $values = explode(',',$value);
00287                     while(list(,$test)=each($values))   {
00288                         $test = trim($test);
00289                         if (strlen($test)) {
00290                             if ($test=='*' || t3lib_div::inList($GLOBALS['TSFE']->gr_list,$test))   {return true;}
00291                         }
00292                     }
00293                 }
00294             break;
00295             case 'loginUser':
00296                 if ($GLOBALS['TSFE']->loginUser)    {
00297                     $values = explode(',',$value);
00298                     while(list(,$test)=each($values))   {
00299                         $test = trim($test);
00300                         if (strlen($test)) {
00301                             if ($test=='*' || !strcmp($GLOBALS['TSFE']->fe_user->user['uid'],$test))    {return true;}
00302                         }
00303                     }
00304                 }
00305             break;
00306             case 'globalVar':
00307                 $values = explode(',', $value);
00308                 foreach ($values as $test) {
00309                     $test = trim($test);
00310                     if (strlen($test)) {
00311                         $point = strcspn($test, '!=<>');
00312                         $theVarName = substr($test,0,$point);
00313                         $nv = $this->getGP_ENV_TSFE(trim($theVarName));
00314                         $testValue = substr($test,$point);
00315 
00316                         if ($this->testNumber($testValue,$nv)) {return true;}
00317                     }
00318                 }
00319             break;
00320             case 'globalString':
00321                 $values = explode(',',$value);
00322                 while(list(,$test)=each($values))   {
00323                     $test = trim($test);
00324                     if (strlen($test)) {
00325                         $point = strcspn($test,'=');
00326                         $theVarName = substr($test,0,$point);
00327                         $nv = $this->getGP_ENV_TSFE(trim($theVarName));
00328                         $testValue = substr($test,$point+1);
00329 
00330                         if ($this->matchWild($nv,trim($testValue))) {return true;}
00331                     }
00332                 }
00333             break;
00334             case 'treeLevel':
00335                 $values = explode(',',$value);
00336                 $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
00337                 $theRLC = count($theRootLine)-1;
00338                 while(list(,$test)=each($values))   {
00339                     $test = trim($test);
00340                     if ($test==$theRLC) {   return true;    }
00341                 }
00342             break;
00343             case 'PIDupinRootline':
00344             case 'PIDinRootline':
00345                 $values = explode(',',$value);
00346                 if (($key=='PIDinRootline') || (!in_array($GLOBALS['TSFE']->id,$values))) {
00347                     $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
00348                     reset($values);
00349                     while(list(,$test)=each($values))   {
00350                         $test = trim($test);
00351                         reset($theRootLine);
00352                         while(list($rl_key,$rl_dat)=each($theRootLine)) {
00353                             if ($rl_dat['uid']==$test)  {   return true;    }
00354                         }
00355                     }
00356                 }
00357             break;
00358             case 'compatVersion':
00359                 { return t3lib_div::compat_version($value); }
00360             break;
00361             case 'userFunc':
00362                 $values = split('\(|\)',$value);
00363                 $funcName=trim($values[0]);
00364                 $funcValue = t3lib_div::trimExplode(',',$values[1]);
00365                 $pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
00366                 if ($pre &&
00367                     !t3lib_div::isFirstPartOfStr(trim($funcName),$pre) &&
00368                     !t3lib_div::isFirstPartOfStr(trim($funcName),'tx_')
00369                 )   {
00370                     if (is_object($GLOBALS['TT']))  $GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3);
00371                     return false;
00372                 }
00373                 if (function_exists($funcName) && call_user_func($funcName, $funcValue[0])) {
00374                     return true;
00375                 }
00376             break;
00377         }
00378 
00379 
00380         return false;
00381     }
00382 
00383     /**
00384      * Evaluates a $leftValue based on an operator: "<", ">", "<=", ">=", "!=" or "="
00385      *
00386      * @param   string      $test: The value to compare with on the form [operator][number]. Eg. "< 123"
00387      * @param   integer     $leftValue: The value on the left side
00388      * @return  boolean     If $value is "50" and $test is "< 123" then it will return true.
00389      */
00390     function testNumber($test, $leftValue) {
00391         $test = trim($test);
00392 
00393         if (preg_match('/^(!?=+|<=?|>=?)\s*([^\s]*)\s*$/', $test, $matches)) {
00394             $operator = $matches[1];
00395             $rightValue = $matches[2];
00396 
00397             switch ($operator) {
00398                 case '>=':
00399                     return ($leftValue >= doubleval($rightValue));
00400                     break;
00401                 case '<=':
00402                     return ($leftValue <= doubleval($rightValue));
00403                     break;
00404                 case '!=':
00405                     return ($leftValue != doubleval($rightValue));
00406                     break;
00407                 case '<':
00408                     return ($leftValue < doubleval($rightValue));
00409                     break;
00410                 case '>':
00411                     return ($leftValue > doubleval($rightValue));
00412                     break;
00413                 default:
00414                     // nothing valid found except '=', use '='
00415                     return ($leftValue == trim($rightValue));
00416                     break;
00417             }
00418         }
00419 
00420         return false;
00421     }
00422 
00423     /**
00424      * Matching two strings against each other, supporting a "*" wildcard or (if wrapped in "/") PCRE regular expressions
00425      *
00426      * @param   string      The string in which to find $needle.
00427      * @param   string      The string to find in $haystack
00428      * @return  boolean     Returns true if $needle matches or is found in (according to wildcards) in $haystack. Eg. if $haystack is "Netscape 6.5" and $needle is "Net*" or "Net*ape" then it returns true.
00429      */
00430     function matchWild($haystack, $needle) {
00431         $result = false;
00432 
00433         if ($needle) {
00434             if (preg_match('/^\/.+\/$/', $needle)) {
00435                 // Regular expression, only "//" is allowed as delimiter
00436                 $regex = $needle;
00437             } else {
00438                 $needle = str_replace(array('*', '?'), array('###MANY###', '###ONE###'), $needle);
00439                 $regex = '/^' . preg_quote($needle, '/') . '$/';
00440                 // Replace the marker with .* to match anything (wildcard)
00441                 $regex = str_replace(array('###MANY###', '###ONE###'), array('.*' , '.'), $regex);
00442             }
00443 
00444             $result = (boolean)preg_match($regex, (string)$haystack);
00445         }
00446 
00447         return $result;
00448     }
00449 
00450     /**
00451      * Returns a code for a browsing device based on the input useragent string
00452      *
00453      * @param   string      User agent string from browser, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
00454      * @return  string      A code. See link.
00455      * @access private
00456      * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=296&cHash=a8ae66c7d6
00457      */
00458     function whichDevice($useragent)    {
00459         foreach($this->hookObjectsArr as $hookObj)  {
00460             if (method_exists($hookObj, 'whichDevice')) {
00461                 $result = $hookObj->whichDevice($useragent);
00462                 if (strlen($result)) {
00463                     return $result;
00464                 }
00465             }
00466         }
00467 
00468         // deprecated, see above
00469         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class']))   {
00470             foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef)   {
00471                 $_procObj = &t3lib_div::getUserObj($_classRef);
00472                 return $_procObj->whichDevice_ext($useragent);
00473             }
00474         }
00475         //
00476 
00477         $agent=strtolower(trim($useragent));
00478             // pda
00479         if( strstr($agent, 'avantgo'))  {
00480             return 'pda';
00481         }
00482 
00483             // wap
00484         $browser=substr($agent,0,4);
00485         $wapviwer=substr(stristr($agent,'wap'),0,3);
00486         if( $wapviwer=='wap' ||
00487             $browser=='noki' ||
00488             $browser== 'eric' ||
00489             $browser== 'r380' ||
00490             $browser== 'up.b' ||
00491             $browser== 'winw' ||
00492             $browser== 'wapa')  {
00493                 return 'wap';
00494         }
00495 
00496             // grabber
00497         if( strstr($agent, 'g.r.a.b.') ||
00498             strstr($agent, 'utilmind httpget') ||
00499             strstr($agent, 'webcapture') ||
00500             strstr($agent, 'teleport') ||
00501             strstr($agent, 'webcopier'))    {
00502             return 'grabber';
00503         }
00504 
00505             // robots
00506         if( strstr($agent, 'crawler') ||
00507             strstr($agent, 'spider') ||
00508             strstr($agent, 'googlebot') ||
00509             strstr($agent, 'searchbot') ||
00510             strstr($agent, 'infoseek') ||
00511             strstr($agent, 'altavista') ||
00512             strstr($agent, 'diibot'))   {
00513             return 'robot';
00514         }
00515 
00516     }
00517 
00518     /**
00519      * Generates an array with abstracted browser information
00520      * This method is used in the function match() in this class
00521      *
00522      * @param   string      The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
00523      * @return  array       Contains keys "browser", "version", "system"
00524      * @access private
00525      * @see match()
00526      */
00527     function browserInfo($useragent)    {
00528         foreach($this->hookObjectsArr as $hookObj)  {
00529             if (method_exists($hookObj, 'browserInfo')) {
00530                 $result = $hookObj->browserInfo($useragent);
00531                 if (strlen($result)) {
00532                     return $result;
00533                 }
00534             }
00535         }
00536 
00537         $useragent = trim($useragent);
00538         $browserInfo=Array();
00539         $browserInfo['useragent']=$useragent;
00540         if ($useragent) {
00541             // browser
00542             if (strstr($useragent,'MSIE'))  {
00543                 $browserInfo['browser']='msie';
00544             } elseif(strstr($useragent,'Konqueror'))    {
00545                 $browserInfo['browser']='konqueror';
00546             } elseif(strstr($useragent,'Opera'))    {
00547                 $browserInfo['browser']='opera';
00548             } elseif(strstr($useragent,'Lynx')) {
00549                 $browserInfo['browser']='lynx';
00550             } elseif(strstr($useragent,'PHP'))  {
00551                 $browserInfo['browser']='php';
00552             } elseif(strstr($useragent,'AvantGo'))  {
00553                 $browserInfo['browser']='avantgo';
00554             } elseif(strstr($useragent,'WebCapture'))   {
00555                 $browserInfo['browser']='acrobat';
00556             } elseif(strstr($useragent,'IBrowse'))  {
00557                 $browserInfo['browser']='ibrowse';
00558             } elseif(strstr($useragent,'Teleport')) {
00559                 $browserInfo['browser']='teleport';
00560             } elseif(strstr($useragent,'Mozilla'))  {
00561                 $browserInfo['browser']='netscape';
00562             } else {
00563                 $browserInfo['browser']='unknown';
00564             }
00565             // version
00566             switch($browserInfo['browser']) {
00567                 case 'netscape':
00568                     $browserInfo['version'] = $this->browserInfo_version(substr($useragent,8));
00569                     if (strstr($useragent,'Netscape6')) {$browserInfo['version']=6;}
00570                 break;
00571                 case 'msie':
00572                     $tmp = strstr($useragent,'MSIE');
00573                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
00574                 break;
00575                 case 'opera':
00576                     $tmp = strstr($useragent,'Opera');
00577                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
00578                 break;
00579                 case 'lynx':
00580                     $tmp = strstr($useragent,'Lynx/');
00581                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
00582                 break;
00583                 case 'php':
00584                     $tmp = strstr($useragent,'PHP/');
00585                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
00586                 break;
00587                 case 'avantgo':
00588                     $tmp = strstr($useragent,'AvantGo');
00589                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,7));
00590                 break;
00591                 case 'acrobat':
00592                     $tmp = strstr($useragent,'WebCapture');
00593                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
00594                 break;
00595                 case 'ibrowse':
00596                     $tmp = strstr($useragent,'IBrowse/');
00597                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,8));
00598                 break;
00599                 case 'konqueror':
00600                     $tmp = strstr($useragent,'Konqueror/');
00601                     $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
00602                 break;
00603             }
00604             // system
00605             $browserInfo['system']='';
00606             if (strstr($useragent,'Win'))   {
00607                 // windows
00608                 if (strstr($useragent,'Win98') || strstr($useragent,'Windows 98'))  {
00609                     $browserInfo['system']='win98';
00610                 } elseif (strstr($useragent,'Win95') || strstr($useragent,'Windows 95'))    {
00611                     $browserInfo['system']='win95';
00612                 } elseif (strstr($useragent,'WinNT') || strstr($useragent,'Windows NT'))    {
00613                     $browserInfo['system']='winNT';
00614                 } elseif (strstr($useragent,'Win16') || strstr($useragent,'Windows 311'))   {
00615                     $browserInfo['system']='win311';
00616                 }
00617             } elseif (strstr($useragent,'Mac')) {
00618                 $browserInfo['system']='mac';
00619                 // unixes
00620             } elseif (strstr($useragent,'Linux'))   {
00621                 $browserInfo['system']='linux';
00622             } elseif (strstr($useragent,'SGI') && strstr($useragent,' IRIX '))  {
00623                 $browserInfo['system']='unix_sgi';
00624             } elseif (strstr($useragent,' SunOS ')) {
00625                 $browserInfo['system']='unix_sun';
00626             } elseif (strstr($useragent,' HP-UX ')) {
00627                 $browserInfo['system']='unix_hp';
00628             }
00629         }
00630 
00631         return $browserInfo;
00632     }
00633 
00634     /**
00635      * 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.
00636      *
00637      * @param   string      A string with version number, eg. "/7.32 blablabla"
00638      * @return  double      Returns double value, eg. "7.32"
00639      */
00640     function browserInfo_version($tmp)  {
00641         return doubleval(preg_replace('/^[^0-9]*/','',$tmp));
00642     }
00643 
00644     /**
00645      * Return global variable where the input string $var defines array keys separated by "|"
00646      * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
00647      *
00648      * @param   string      Global var key, eg. "HTTP_GET_VAR" or "HTTP_GET_VARS|id" to get the GET parameter "id" back.
00649      * @param   array       Alternative array than $GLOBAL to get variables from.
00650      * @return  mixed       Whatever value. If none, then blank string.
00651      * @access private
00652      */
00653     function getGlobal($var, $source=NULL)  {
00654         $vars = explode('|',$var);
00655         $c = count($vars);
00656         $k = trim($vars[0]);
00657         $theVar = isset($source) ? $source[$k] : $GLOBALS[$k];
00658 
00659         for ($a=1;$a<$c;$a++)   {
00660             if (!isset($theVar))    { break; }
00661 
00662             $key = trim($vars[$a]);
00663             if (is_object($theVar)) {
00664                 $theVar = $theVar->$key;
00665             } elseif (is_array($theVar))    {
00666                 $theVar = $theVar[$key];
00667             } else {
00668                 return '';
00669             }
00670         }
00671 
00672         if (!is_array($theVar) && !is_object($theVar))  {
00673             return $theVar;
00674         } else {
00675             return '';
00676         }
00677     }
00678 
00679     /**
00680      * Returns GP / ENV / TSFE vars
00681      *
00682      * @param   string      Identifier
00683      * @return  mixed       The value of the variable pointed to.
00684      * @access private
00685      * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=311&cHash=487cbd5cdf
00686      */
00687     function getGP_ENV_TSFE($var) {
00688         $vars = explode(':',$var,2);
00689         if (count($vars)==1)    {
00690             $val = $this->getGlobal($var);
00691         } else {
00692             $splitAgain=explode('|',$vars[1],2);
00693             $k=trim($splitAgain[0]);
00694             if ($k) {
00695                 switch((string)trim($vars[0]))  {
00696                     case 'GP':
00697                         $val = t3lib_div::_GP($k);
00698                     break;
00699                     case 'TSFE':
00700                         $val = $this->getGlobal('TSFE|'.$vars[1]);
00701                         $splitAgain=0;  // getGlobal resolves all parts of the key, so no further splitting is needed
00702                     break;
00703                     case 'ENV':
00704                         $val = getenv($k);
00705                     break;
00706                     case 'IENV':
00707                         $val = t3lib_div::getIndpEnv($k);
00708                     break;
00709                     case 'LIT':
00710                         { return trim($vars[1]); }  // return litteral value...
00711                     break;
00712                 }
00713                     // If array:
00714                 if (count($splitAgain)>1)   {
00715                     if (is_array($val) && trim($splitAgain[1])) {
00716                         $val=$this->getGlobal($splitAgain[1],$val);
00717                     } else {
00718                         $val='';
00719                     }
00720                 }
00721             }
00722         }
00723         return $val;
00724     }
00725 }
00726 
00727 
00728 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php'])    {
00729     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']);
00730 }
00731 
00732 ?>

Generated on Sat Jan 3 04:23:26 2009 for TYPO3 API by  doxygen 1.4.7