[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/t3lib/ -> class.t3lib_matchcondition.php (source)

   1  <?php
   2  /***************************************************************
   3  *  Copyright notice
   4  *
   5  *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
   6  *  All rights reserved
   7  *
   8  *  This script is part of the TYPO3 project. The TYPO3 project is
   9  *  free software; you can redistribute it and/or modify
  10  *  it under the terms of the GNU General Public License as published by
  11  *  the Free Software Foundation; either version 2 of the License, or
  12  *  (at your option) any later version.
  13  *
  14  *  The GNU General Public License can be found at
  15  *  http://www.gnu.org/copyleft/gpl.html.
  16  *  A copy is found in the textfile GPL.txt and important notices to the license
  17  *  from the author is found in LICENSE.txt distributed with these scripts.
  18  *
  19  *
  20  *  This script is distributed in the hope that it will be useful,
  21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23  *  GNU General Public License for more details.
  24  *
  25  *  This copyright notice MUST APPEAR in all copies of the script!
  26  ***************************************************************/
  27  /**
  28   * Contains class for Matching TypoScript conditions
  29   *
  30   * $Id: class.t3lib_matchcondition.php 2052 2007-02-20 17:00:18Z mundaun $
  31   * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
  32   *
  33   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  34   */
  35  /**
  36   * [CLASS/FUNCTION INDEX of SCRIPT]
  37   *
  38   *
  39   *
  40   *   80: class t3lib_matchCondition
  41   *   87:     function __construct()
  42   *  105:     function t3lib_matchCondition()
  43   *  115:     function match($condition_line)
  44   *  160:     function evalConditionStr($string)
  45   *  381:     function testNumber($test,$value)
  46   *  405:     function matchWild($haystack,$needle)
  47   *  429:     function whichDevice($useragent)
  48   *  498:     function browserInfo($useragent)
  49   *  611:     function browserInfo_version($tmp)
  50   *  624:     function getGlobal($var, $source=NULL)
  51   *  658:     function getGP_ENV_TSFE($var)
  52   *
  53   * TOTAL FUNCTIONS: 11
  54   * (This index is automatically created/updated by the extension "extdeveval")
  55   *
  56   */
  57  
  58  
  59  
  60  
  61  
  62  
  63  
  64  
  65  
  66  
  67  
  68  
  69  /**
  70   * Matching TypoScript conditions
  71   *
  72   * Used with the TypoScript parser.
  73   * Matches browserinfo, IPnumbers for use with templates
  74   *
  75   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  76   * @package TYPO3
  77   * @subpackage t3lib
  78   * @see t3lib_TStemplate::matching(), t3lib_TStemplate::generateConfig()
  79   */
  80  class t3lib_matchCondition {
  81      var $matchAlternative=array();        // If this array has elements, the matching returns true if a whole "matchline" is found in the array!
  82      var $matchAll=0;                    // If set all is matched!
  83  
  84      var $altRootLine=array();
  85      var $hookObjectsArr = array();
  86  
  87      /**
  88       * Constructor for this class
  89       *
  90       * @return    void
  91       */
  92  	function __construct()    {
  93          global $TYPO3_CONF_VARS;
  94  
  95          // Usage (ext_localconf.php):
  96          // $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][] =
  97          // 'EXT:my_ext/class.browserinfo.php:MyBrowserInfoClass';
  98          if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'])) {
  99              foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'] as $classRef) {
 100                  $this->hookObjectsArr[] = &t3lib_div::getUserObj($classRef, '');
 101              }
 102          }
 103      }
 104  
 105      /**
 106       * Constructor for this class
 107       *
 108       * @return    void
 109       */
 110  	function t3lib_matchCondition() {
 111          $this->__construct();
 112      }
 113  
 114      /**
 115       * Matching TS condition
 116       *
 117       * @param    string        Line to match
 118       * @return    boolean        True if matched
 119       */
 120  	function match($condition_line) {
 121          if ($this->matchAll) {
 122              return true;
 123          }
 124          if (count($this->matchAlternative))    {
 125              return in_array($condition_line, $this->matchAlternative);
 126          }
 127  
 128              // Getting the value from inside of the wrapping square brackets of the condition line:
 129          $insideSqrBrackets = substr(trim($condition_line), 1, strlen($condition_line) - 2);
 130          $insideSqrBrackets = preg_replace('/\]\s*OR\s*\[/i', ']||[', $insideSqrBrackets);
 131          $insideSqrBrackets = preg_replace('/\]\s*AND\s*\[/i', ']&&[', $insideSqrBrackets);
 132  
 133              // The "weak" operator "||" (OR) takes precedence: backwards compatible, [XYZ][ZYX] does still work as OR
 134          $orParts = preg_split('/\]\s*(\|\|){0,1}\s*\[/',$insideSqrBrackets);
 135  
 136          foreach ($orParts as $partString)    {
 137              $matches = false;
 138  
 139                  // Splits by the "&&" (AND) operator:
 140              $andParts = preg_split('/\]\s*&&\s*\[/',$partString);
 141              foreach ($andParts as $condStr)    {
 142                  $matches = $this->evalConditionStr($condStr);
 143                  if ($matches===false)    {
 144                      break;        // only true AND true = true, so we have to break here
 145                  }
 146              }
 147  
 148              if ($matches===true)    {
 149                  break;        // true OR false = true, so we break if we have a positive result
 150              }
 151          }
 152  
 153          return $matches;
 154      }
 155  
 156  
 157      /**
 158       * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
 159       *
 160       * @param    string        The condition to match against its criterias.
 161       * @return    boolean        Returns true or false based on the evaluation.
 162       * @see t3lib_tsparser::parse()
 163       * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=292&cHash=c6c7d43d2f
 164       */
 165  	function evalConditionStr($string)    {
 166          if (!is_array($this->altRootLine)) {
 167              $this->altRootLine = array();
 168          }
 169          list($key, $value) = explode('=', $string, 2);
 170          $key = trim($key);
 171          if (stristr(',browser,version,system,useragent,', ",$key,")) {
 172              $browserInfo = $this->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
 173          }
 174          $value = trim($value);
 175          switch ($key) {
 176              case 'browser':
 177                  $values = explode(',',$value);
 178                  while(list(,$test)=each($values))    {
 179                      if (strstr($browserInfo['browser'].$browserInfo['version'],trim($test)))    {
 180                          return true;
 181                      }
 182                  }
 183              break;
 184              case 'version':
 185                  $values = explode(',',$value);
 186                  while(list(,$test)=each($values))    {
 187                      $test = trim($test);
 188                      if (strlen($test)) {
 189                          if (strcspn($test,'=<>')==0)    {
 190                              switch(substr($test,0,1))    {
 191                                  case '=':
 192                                      if (doubleval(substr($test,1))==$browserInfo['version']) return true;
 193                                  break;
 194                                  case '<':
 195                                      if (doubleval(substr($test,1))>$browserInfo['version'])    return true;
 196                                  break;
 197                                  case '>':
 198                                      if (doubleval(substr($test,1))<$browserInfo['version'])    return true;
 199                                  break;
 200                              }
 201                          } else {
 202                              if (strpos(' '.$browserInfo['version'],$test)==1)    {return true;}
 203                          }
 204                      }
 205                  }
 206              break;
 207              case 'system':
 208                  $values = explode(',',$value);
 209                  while(list(,$test)=each($values))    {
 210                      $test = trim($test);
 211                      if (strlen($test)) {
 212                          if (strpos(' '.$browserInfo['system'],$test)==1)    {return true;}
 213                      }
 214                  }
 215              break;
 216              case 'device':
 217                  $values = explode(',',$value);
 218                  if (!isset($this->deviceInfo))    {
 219                      $this->deviceInfo = $this->whichDevice(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
 220                  }
 221                  while(list(,$test)=each($values))    {
 222                      $test = trim($test);
 223                      if (strlen($test)) {
 224                          if ($this->deviceInfo==$test)    {return true;}
 225                      }
 226                  }
 227              break;
 228              case 'useragent':
 229                  $test = trim($value);
 230                  if (strlen($test)) {
 231                      return $this->matchWild($browserInfo['useragent'],$test);
 232                  }
 233              break;
 234              case 'language':
 235                  $values = explode(',',$value);
 236                  while(list(,$test)=each($values))    {
 237                      $test = trim($test);
 238                      if (strlen($test)) {
 239                          if (preg_match('/^\*.+\*$/',$test))    {
 240                              $allLanguages = split('[,;]',t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
 241                              if (in_array(substr($test,1,-1), $allLanguages))    {return true;}
 242                          } else {
 243                              if (t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE') == $test)    {return true;}
 244                          }
 245                      }
 246                  }
 247              break;
 248              case 'IP':
 249                  if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value))    {return true;}
 250              break;
 251              case 'hostname':
 252                  if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value))  {return true;}
 253              break;
 254                  // hour, minute, dayofweek, dayofmonth, month
 255              case 'hour':
 256              case 'minute':
 257              case 'dayofweek':
 258              case 'dayofmonth':
 259              case 'month':
 260                  $theEvalTime = $GLOBALS['SIM_EXEC_TIME'];    // In order to simulate time properly in templates.
 261                  switch($key) {
 262                      case 'hour':        $theTestValue = date('H',$theEvalTime);    break;
 263                      case 'minute':        $theTestValue = date('i',$theEvalTime);    break;
 264                      case 'dayofweek':    $theTestValue = date('w',$theEvalTime);    break;
 265                      case 'dayofmonth':    $theTestValue = date('d',$theEvalTime);    break;
 266                      case 'month':        $theTestValue = date('m',$theEvalTime);    break;
 267                  }
 268                  $theTestValue = intval($theTestValue);
 269                      // comp
 270                  $values = explode(',',$value);
 271                  reset($values);
 272                  while(list(,$test)=each($values))    {
 273                      $test = trim($test);
 274                      if (t3lib_div::testInt($test))    {$test='='.$test;}
 275                      if (strlen($test)) {
 276                          if ($this->testNumber($test,$theTestValue)) {return true;}
 277                      }
 278                  }
 279              break;
 280              case 'usergroup':
 281                  if ($GLOBALS['TSFE']->gr_list!='0,-1')    {        // '0,-1' is the default usergroups when not logged in!
 282                      $values = explode(',',$value);
 283                      while(list(,$test)=each($values))    {
 284                          $test = trim($test);
 285                          if (strlen($test)) {
 286                              if ($test=='*' || t3lib_div::inList($GLOBALS['TSFE']->gr_list,$test))    {return true;}
 287                          }
 288                      }
 289                  }
 290              break;
 291              case 'loginUser':
 292                  if ($GLOBALS['TSFE']->loginUser)    {
 293                      $values = explode(',',$value);
 294                      while(list(,$test)=each($values))    {
 295                          $test = trim($test);
 296                          if (strlen($test)) {
 297                              if ($test=='*' || !strcmp($GLOBALS['TSFE']->fe_user->user['uid'],$test))    {return true;}
 298                          }
 299                      }
 300                  }
 301              break;
 302              case 'globalVar':
 303                  $values = explode(',',$value);
 304                  while(list(,$test)=each($values))    {
 305                      $test = trim($test);
 306                      if (strlen($test)) {
 307                          $point = strcspn($test,'=<>');
 308                          $theVarName = substr($test,0,$point);
 309                          $nv = $this->getGP_ENV_TSFE(trim($theVarName));
 310                          $testValue = substr($test,$point);
 311  
 312                          if ($this->testNumber($testValue,$nv)) {return true;}
 313                      }
 314                  }
 315              break;
 316              case 'globalString':
 317                  $values = explode(',',$value);
 318                  while(list(,$test)=each($values))    {
 319                      $test = trim($test);
 320                      if (strlen($test)) {
 321                          $point = strcspn($test,'=');
 322                          $theVarName = substr($test,0,$point);
 323                          $nv = $this->getGP_ENV_TSFE(trim($theVarName));
 324                          $testValue = substr($test,$point+1);
 325  
 326                          if ($this->matchWild($nv,trim($testValue))) {return true;}
 327                      }
 328                  }
 329              break;
 330              case 'treeLevel':
 331                  $values = explode(',',$value);
 332                  $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
 333                  $theRLC = count($theRootLine)-1;
 334                  while(list(,$test)=each($values))    {
 335                      $test = trim($test);
 336                      if ($test==$theRLC)    {    return true;    }
 337                  }
 338              break;
 339              case 'PIDupinRootline':
 340              case 'PIDinRootline':
 341                  $values = explode(',',$value);
 342                  if (($key=='PIDinRootline') || (!in_array($GLOBALS['TSFE']->id,$values))) {
 343                      $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
 344                      reset($values);
 345                      while(list(,$test)=each($values))    {
 346                          $test = trim($test);
 347                          reset($theRootLine);
 348                          while(list($rl_key,$rl_dat)=each($theRootLine))    {
 349                              if ($rl_dat['uid']==$test)    {    return true;    }
 350                          }
 351                      }
 352                  }
 353              break;
 354              case 'compatVersion':
 355                  { return t3lib_div::compat_version($value); }
 356              break;
 357              case 'userFunc':
 358                  $values = split('\(|\)',$value);
 359                  $funcName=trim($values[0]);
 360                  $funcValue = t3lib_div::trimExplode(',',$values[1]);
 361                  $pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
 362                  if ($pre &&
 363                      !t3lib_div::isFirstPartOfStr(trim($funcName),$pre) &&
 364                      !t3lib_div::isFirstPartOfStr(trim($funcName),'tx_')
 365                  )    {
 366                      if (is_object($GLOBALS['TT']))    $GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3);
 367                      return false;
 368                  }
 369                  if (function_exists($funcName) && call_user_func($funcName, $funcValue[0]))    {
 370                      return true;
 371                  }
 372              break;
 373          }
 374  
 375  
 376          return false;
 377      }
 378  
 379      /**
 380       * Will evaluate a $value based on an operator: "<", ">" or "=" (default)
 381       *
 382       * @param    string        The value to compare with on the form [operator][number]. Eg. "< 123"
 383       * @param    integer        The number
 384       * @return    boolean        If $value is "50" and $test is "< 123" then it will return true.
 385       */
 386  	function testNumber($test,$value) {
 387          $test = trim($test);
 388          switch(substr($test,0,1))    {
 389              case '<':
 390                  if (doubleval(substr($test,1))>$value)    return true;
 391              break;
 392              case '>':
 393                  if (doubleval(substr($test,1))<$value)    return true;
 394              break;
 395              default:
 396                  if (trim(substr($test,1))==$value)    return true;
 397              break;
 398          }
 399  
 400          return false;
 401      }
 402  
 403      /**
 404       * Matching two strings against each other, supporting a "*" wildcard or (if wrapped in "/") PCRE regular expressions
 405       *
 406       * @param    string        The string in which to find $needle.
 407       * @param    string        The string to find in $haystack
 408       * @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.
 409       */
 410  	function matchWild($haystack,$needle)    {
 411          if ($needle && $haystack)    {
 412              if (preg_match('/^\/.+\/$/', $needle))    {    // Regular expression, only "//" is allowed as delimiter
 413                  $regex = $needle;
 414              } else {
 415                  $needle = str_replace(array('*','?'), array('###MANY###','###ONE###'), $needle);
 416                  $regex = '/^'.preg_quote($needle,'/').'$/';
 417                  $regex = str_replace(array('###MANY###','###ONE###'), array('.*','.'), $regex);    // Replace the marker with .* to match anything (wildcard)
 418              }
 419  
 420              if (preg_match($regex, $haystack)) return true;
 421          }
 422  
 423          return false;
 424      }
 425  
 426      /**
 427       * Returns a code for a browsing device based on the input useragent string
 428       *
 429       * @param    string        User agent string from browser, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
 430       * @return    string        A code. See link.
 431       * @access private
 432       * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=296&cHash=a8ae66c7d6
 433       */
 434  	function whichDevice($useragent)    {
 435          foreach($this->hookObjectsArr as $hookObj)    {
 436              if (method_exists($hookObj, 'whichDevice')) {
 437                  $result = $hookObj->whichDevice($useragent);
 438                  if (strlen($result)) {
 439                      return $result;
 440                  }
 441              }
 442          }
 443  
 444          // deprecated, see above
 445          if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class']))    {
 446              foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef)    {
 447                  $_procObj = &t3lib_div::getUserObj($_classRef);
 448                  return $_procObj->whichDevice_ext($useragent);
 449              }
 450          }
 451          //
 452  
 453          $agent=strtolower(trim($useragent));
 454              // pda
 455          if(    strstr($agent, 'avantgo'))    {
 456              return 'pda';
 457          }
 458  
 459              // wap
 460          $browser=substr($agent,0,4);
 461          $wapviwer=substr(stristr($agent,'wap'),0,3);
 462          if(    $wapviwer=='wap' ||
 463              $browser=='noki' ||
 464              $browser== 'eric' ||
 465              $browser== 'r380' ||
 466              $browser== 'up.b' ||
 467              $browser== 'winw' ||
 468              $browser== 'wapa')    {
 469                  return 'wap';
 470          }
 471  
 472              // grabber
 473          if(    strstr($agent, 'g.r.a.b.') ||
 474              strstr($agent, 'utilmind httpget') ||
 475              strstr($agent, 'webcapture') ||
 476              strstr($agent, 'teleport') ||
 477              strstr($agent, 'webcopier'))    {
 478              return 'grabber';
 479          }
 480  
 481              // robots
 482          if(    strstr($agent, 'crawler') ||
 483              strstr($agent, 'spider') ||
 484              strstr($agent, 'googlebot') ||
 485              strstr($agent, 'searchbot') ||
 486              strstr($agent, 'infoseek') ||
 487              strstr($agent, 'altavista') ||
 488              strstr($agent, 'diibot'))    {
 489              return 'robot';
 490          }
 491  
 492      }
 493  
 494      /**
 495       * Generates an array with abstracted browser information
 496       * This method is used in the function match() in this class
 497       *
 498       * @param    string        The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
 499       * @return    array        Contains keys "browser", "version", "system"
 500       * @access private
 501       * @see match()
 502       */
 503  	function browserInfo($useragent)    {
 504          foreach($this->hookObjectsArr as $hookObj)    {
 505              if (method_exists($hookObj, 'browserInfo')) {
 506                  $result = $hookObj->browserInfo($useragent);
 507                  if (strlen($result)) {
 508                      return $result;
 509                  }
 510              }
 511          }
 512  
 513          $useragent = trim($useragent);
 514          $browserInfo=Array();
 515          $browserInfo['useragent']=$useragent;
 516          if ($useragent)    {
 517              // browser
 518              if (strstr($useragent,'MSIE'))    {
 519                  $browserInfo['browser']='msie';
 520              } elseif(strstr($useragent,'Konqueror'))    {
 521                  $browserInfo['browser']='konqueror';
 522              } elseif(strstr($useragent,'Opera'))    {
 523                  $browserInfo['browser']='opera';
 524              } elseif(strstr($useragent,'Lynx'))    {
 525                  $browserInfo['browser']='lynx';
 526              } elseif(strstr($useragent,'PHP'))    {
 527                  $browserInfo['browser']='php';
 528              } elseif(strstr($useragent,'AvantGo'))    {
 529                  $browserInfo['browser']='avantgo';
 530              } elseif(strstr($useragent,'WebCapture'))    {
 531                  $browserInfo['browser']='acrobat';
 532              } elseif(strstr($useragent,'IBrowse'))    {
 533                  $browserInfo['browser']='ibrowse';
 534              } elseif(strstr($useragent,'Teleport'))    {
 535                  $browserInfo['browser']='teleport';
 536              } elseif(strstr($useragent,'Mozilla'))    {
 537                  $browserInfo['browser']='netscape';
 538              } else {
 539                  $browserInfo['browser']='unknown';
 540              }
 541              // version
 542              switch($browserInfo['browser'])    {
 543                  case 'netscape':
 544                      $browserInfo['version'] = $this->browserInfo_version(substr($useragent,8));
 545                      if (strstr($useragent,'Netscape6')) {$browserInfo['version']=6;}
 546                  break;
 547                  case 'msie':
 548                      $tmp = strstr($useragent,'MSIE');
 549                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
 550                  break;
 551                  case 'opera':
 552                      $tmp = strstr($useragent,'Opera');
 553                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
 554                  break;
 555                  case 'lynx':
 556                      $tmp = strstr($useragent,'Lynx/');
 557                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
 558                  break;
 559                  case 'php':
 560                      $tmp = strstr($useragent,'PHP/');
 561                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
 562                  break;
 563                  case 'avantgo':
 564                      $tmp = strstr($useragent,'AvantGo');
 565                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,7));
 566                  break;
 567                  case 'acrobat':
 568                      $tmp = strstr($useragent,'WebCapture');
 569                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
 570                  break;
 571                  case 'ibrowse':
 572                      $tmp = strstr($useragent,'IBrowse/');
 573                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,8));
 574                  break;
 575                  case 'konqueror':
 576                      $tmp = strstr($useragent,'Konqueror/');
 577                      $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
 578                  break;
 579              }
 580              // system
 581              $browserInfo['system']='';
 582              if (strstr($useragent,'Win'))    {
 583                  // windows
 584                  if (strstr($useragent,'Win98') || strstr($useragent,'Windows 98'))    {
 585                      $browserInfo['system']='win98';
 586                  } elseif (strstr($useragent,'Win95') || strstr($useragent,'Windows 95'))    {
 587                      $browserInfo['system']='win95';
 588                  } elseif (strstr($useragent,'WinNT') || strstr($useragent,'Windows NT'))    {
 589                      $browserInfo['system']='winNT';
 590                  } elseif (strstr($useragent,'Win16') || strstr($useragent,'Windows 311'))    {
 591                      $browserInfo['system']='win311';
 592                  }
 593              } elseif (strstr($useragent,'Mac'))    {
 594                  $browserInfo['system']='mac';
 595                  // unixes
 596              } elseif (strstr($useragent,'Linux'))    {
 597                  $browserInfo['system']='linux';
 598              } elseif (strstr($useragent,'SGI') && strstr($useragent,' IRIX '))    {
 599                  $browserInfo['system']='unix_sgi';
 600              } elseif (strstr($useragent,' SunOS '))    {
 601                  $browserInfo['system']='unix_sun';
 602              } elseif (strstr($useragent,' HP-UX '))    {
 603                  $browserInfo['system']='unix_hp';
 604              }
 605          }
 606  
 607          return $browserInfo;
 608      }
 609  
 610      /**
 611       * 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.
 612       *
 613       * @param    string        A string with version number, eg. "/7.32 blablabla"
 614       * @return    double        Returns double value, eg. "7.32"
 615       */
 616  	function browserInfo_version($tmp)    {
 617          return doubleval(preg_replace('/^[^0-9]*/','',$tmp));
 618      }
 619  
 620      /**
 621       * Return global variable where the input string $var defines array keys separated by "|"
 622       * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
 623       *
 624       * @param    string        Global var key, eg. "HTTP_GET_VAR" or "HTTP_GET_VARS|id" to get the GET parameter "id" back.
 625       * @param    array        Alternative array than $GLOBAL to get variables from.
 626       * @return    mixed        Whatever value. If none, then blank string.
 627       * @access private
 628       */
 629  	function getGlobal($var, $source=NULL)    {
 630          $vars = explode('|',$var);
 631          $c = count($vars);
 632          $k = trim($vars[0]);
 633          $theVar = isset($source) ? $source[$k] : $GLOBALS[$k];
 634  
 635          for ($a=1;$a<$c;$a++)    {
 636              if (!isset($theVar))    { break; }
 637  
 638              $key = trim($vars[$a]);
 639              if (is_object($theVar))    {
 640                  $theVar = $theVar->$key;
 641              } elseif (is_array($theVar))    {
 642                  $theVar = $theVar[$key];
 643              } else {
 644                  return '';
 645              }
 646          }
 647  
 648          if (!is_array($theVar) && !is_object($theVar))    {
 649              return $theVar;
 650          } else {
 651              return '';
 652          }
 653      }
 654  
 655      /**
 656       * Returns GP / ENV / TSFE vars
 657       *
 658       * @param    string        Identifier
 659       * @return    mixed        The value of the variable pointed to.
 660       * @access private
 661       * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=311&cHash=487cbd5cdf
 662       */
 663  	function getGP_ENV_TSFE($var) {
 664          $vars = explode(':',$var,2);
 665          if (count($vars)==1)    {
 666              $val = $this->getGlobal($var);
 667          } else {
 668              $splitAgain=explode('|',$vars[1],2);
 669              $k=trim($splitAgain[0]);
 670              if ($k)    {
 671                  switch((string)trim($vars[0]))    {
 672                      case 'GP':
 673                          $val = t3lib_div::_GP($k);
 674                      break;
 675                      case 'TSFE':
 676                          $val = $this->getGlobal('TSFE|'.$vars[1]);
 677                          $splitAgain=0;    // getGlobal resolves all parts of the key, so no further splitting is needed
 678                      break;
 679                      case 'ENV':
 680                          $val = getenv($k);
 681                      break;
 682                      case 'IENV':
 683                          $val = t3lib_div::getIndpEnv($k);
 684                      break;
 685                      case 'LIT':
 686                          { return trim($vars[1]); }    // return litteral value...
 687                      break;
 688                  }
 689                      // If array:
 690                  if (count($splitAgain)>1)    {
 691                      if (is_array($val) && trim($splitAgain[1]))    {
 692                          $val=$this->getGlobal($splitAgain[1],$val);
 693                      } else {
 694                          $val='';
 695                      }
 696                  }
 697              }
 698          }
 699          return $val;
 700      }
 701  }
 702  
 703  
 704  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php'])    {
 705      include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']);
 706  }
 707  ?>


Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics