--- t3lib/class.t3lib_matchcondition.php 2005-02-01 14:25:40.000000000 +0100 +++ t3lib/class.t3lib_matchcondition.new.php 2005-02-01 14:26:26.000000000 +0100 @@ -80,6 +80,50 @@ var $altRootLine=array(); + /** + * Evaluates several TypoScript conditions given as input, eg. "[browser=net]&&[...(other conditions)...]" + * This allows you to combine them with either && (and) and || (or) + * ([XYZ][ZYX] is still interpreted as OR) + * + * @param string The conditions to match against its criterias. + * @return boolean Returns true or false based on the evaluation. + */ + function match($condition_line) { + if ($this->matchAll) { + return true; + } + if (count($this->matchAlternative)) { + return in_array($condition_line, $this->matchAlternative); + } + + // Getting the value from inside of the wrapping + // square brackets of the condition line: + $insideSqrBrackets = trim(ereg_replace('\]$','',substr($condition_line,1))); + + // The "weak" operator, OR, takes precedence: + // backwards compatible [XYZ][ZYX] does still work as OR + $ORparts = split('\][[:space:]]*(\|\|){0,1}[[:space:]]*\[',$insideSqrBrackets); + reset($ORparts); + foreach($ORparts as $andString) { + $resBool = false; + + // Splits by the "&&" and operator: + $ANDparts = split('\][[:space:]]*\&\&[[:space:]]*\[',$andString); + reset($ANDparts); + foreach($ANDparts as $condStr) { + $resBool = $this->evalConditionStr($condStr); + if (!$resBool) { + break; + } + } + + if ($resBool) { + break; + } + } + return $resBool; + } + /** * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]" * @@ -88,216 +132,205 @@ * @see t3lib_tsparser::parse() * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=292&cHash=c6c7d43d2f */ - function match($string) { - - if ($this->matchAll) return true; - if (count($this->matchAlternative)) { - return in_array($string,$this->matchAlternative); - } + function evalConditionStr($string) { if (!$this->browserInfoArray) { $this->browserInfoArray = $this->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT')); } $browserInfo = $this->browserInfoArray; - $string = trim($string); - $string = substr($string,1,strlen($string)-2); - $parts = explode('][',$string); - reset($parts); - while(list(,$val)=each($parts)) { - $pcs = explode('=',$val,2); - $switchKey = trim($pcs[0]); - switch($switchKey) { - case 'browser': - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - if (strstr($browserInfo['browser'].$browserInfo['version'],trim($test))) { - return true; - } + $pcs = explode('=',$string,2); + $switchKey = trim($pcs[0]); + switch($switchKey) { + case 'browser': + $values = explode(',',$pcs[1]); + while(list(,$test)=each($values)) { + if (strstr($browserInfo['browser'].$browserInfo['version'],trim($test))) { + return true; } - break; - case 'version': - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - if (strcspn($test,'=<>')==0) { - switch(substr($test,0,1)) { - case '=': - if (doubleval(substr($test,1))==$browserInfo['version']) return true; - break; - case '<': - if (doubleval(substr($test,1))>$browserInfo['version']) return true; - break; - case '>': - if (doubleval(substr($test,1))<$browserInfo['version']) return true; - break; - } - } else { - if (strpos(' '.$browserInfo['version'],$test)==1) {return true;} + } + break; + case 'version': + $values = explode(',',$pcs[1]); + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test) { + if (strcspn($test,'=<>')==0) { + switch(substr($test,0,1)) { + case '=': + if (doubleval(substr($test,1))==$browserInfo['version']) return true; + break; + case '<': + if (doubleval(substr($test,1))>$browserInfo['version']) return true; + break; + case '>': + if (doubleval(substr($test,1))<$browserInfo['version']) return true; + break; } + } else { + if (strpos(' '.$browserInfo['version'],$test)==1) {return true;} } } - break; - case 'system': - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - if (strpos(' '.$browserInfo['system'],$test)==1) {return true;} - } + } + break; + case 'system': + $values = explode(',',$pcs[1]); + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test) { + if (strpos(' '.$browserInfo['system'],$test)==1) {return true;} } - break; - case 'device': - $values = explode(',',$pcs[1]); - if (!isset($this->deviceInfo)) { - $this->deviceInfo = $this->whichDevice(t3lib_div::getIndpEnv('HTTP_USER_AGENT')); + } + break; + case 'device': + $values = explode(',',$pcs[1]); + if (!isset($this->deviceInfo)) { + $this->deviceInfo = $this->whichDevice(t3lib_div::getIndpEnv('HTTP_USER_AGENT')); + } + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test) { + if ($this->deviceInfo==$test) {return true;} } - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - if ($this->deviceInfo==$test) {return true;} + } + break; + case 'useragent': + $test = trim($pcs[1]); + if ($test) { + return $this->matchWild($browserInfo['useragent'],$test); + } + break; + case 'language': + $values = explode(',',$pcs[1]); + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test) { + if (ereg('^\*.+\*$',$test)) { + $allLanguages = split('[,;]',t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE')); + if (in_array(substr($test,1,-1), $allLanguages)) {return true;} + } else { + if (t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE') == $test) {return true;} } } - break; - case 'useragent': - $test = trim($pcs[1]); + } + break; + case 'IP': + if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $pcs[1])) {return true;} + break; + case 'hostname': + if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $pcs[1])) {return true;} + break; + // hour, minute, dayofweek, dayofmonth, month + case 'hour': + case 'minute': + case 'dayofweek': + case 'dayofmonth': + case 'month': + $theEvalTime = $GLOBALS['SIM_EXEC_TIME']; // In order to simulate time properly in templates. + switch($switchKey) { + case 'hour': $theTestValue = date('H',$theEvalTime); break; + case 'minute': $theTestValue = date('i',$theEvalTime); break; + case 'dayofweek': $theTestValue = date('w',$theEvalTime); break; + case 'dayofmonth': $theTestValue = date('d',$theEvalTime); break; + case 'month': $theTestValue = date('m',$theEvalTime); break; + } + $theTestValue = intval($theTestValue); + // comp + $values = explode(',',$pcs[1]); + reset($values); + while(list(,$test)=each($values)) { + $test = trim($test); + if (t3lib_div::testInt($test)) {$test='='.$test;} if ($test) { - return $this->matchWild($browserInfo['useragent'],$test); + if ($this->testNumber($test,$theTestValue)) {return true;} } - break; - case 'language': + } + break; + case 'usergroup': + if ($GLOBALS['TSFE']->gr_list!='0,-1') { // '0,-1' is the default usergroups when not logged in! $values = explode(',',$pcs[1]); while(list(,$test)=each($values)) { $test = trim($test); if ($test) { - if (ereg('^\*.+\*$',$test)) { - $allLanguages = split('[,;]',t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE')); - if (in_array(substr($test,1,-1), $allLanguages)) {return true;} - } else { - if (t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE') == $test) {return true;} - } + if ($test=='*' || t3lib_div::inList($GLOBALS['TSFE']->gr_list,$test)) {return true;} } } - break; - case 'IP': - if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $pcs[1])) {return true;} - break; - case 'hostname': - if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $pcs[1])) {return true;} - break; - // hour, minute, dayofweek, dayofmonth, month - case 'hour': - case 'minute': - case 'dayofweek': - case 'dayofmonth': - case 'month': - $theEvalTime = $GLOBALS['SIM_EXEC_TIME']; // In order to simulate time properly in templates. - switch($switchKey) { - case 'hour': $theTestValue = date('H',$theEvalTime); break; - case 'minute': $theTestValue = date('i',$theEvalTime); break; - case 'dayofweek': $theTestValue = date('w',$theEvalTime); break; - case 'dayofmonth': $theTestValue = date('d',$theEvalTime); break; - case 'month': $theTestValue = date('m',$theEvalTime); break; - } - $theTestValue = intval($theTestValue); - // comp + } + break; + case 'loginUser': + if ($GLOBALS['TSFE']->loginUser) { $values = explode(',',$pcs[1]); - reset($values); while(list(,$test)=each($values)) { $test = trim($test); - if (t3lib_div::testInt($test)) {$test='='.$test;} if ($test) { - if ($this->testNumber($test,$theTestValue)) {return true;} - } - } - break; - case 'usergroup': - if ($GLOBALS['TSFE']->gr_list!='0,-1') { // '0,-1' is the default usergroups when not logged in! - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - if ($test=='*' || t3lib_div::inList($GLOBALS['TSFE']->gr_list,$test)) {return true;} - } + if ($test=='*' || !strcmp($GLOBALS['TSFE']->fe_user->user['uid'],$test)) {return true;} } } - break; - case 'loginUser': - if ($GLOBALS['TSFE']->loginUser) { - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - if ($test=='*' || !strcmp($GLOBALS['TSFE']->fe_user->user['uid'],$test)) {return true;} - } - } - } - break; - case 'globalVar': - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - $point = strcspn($test,'=<>'); - $theVarName = substr($test,0,$point); - $nv = $this->getGP_ENV_TSFE(trim($theVarName)); - if ($this->testNumber(substr($test,$point) ,$nv)) {return true;} - } + } + break; + case 'globalVar': + $values = explode(',',$pcs[1]); + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test) { + $point = strcspn($test,'=<>'); + $theVarName = substr($test,0,$point); + $nv = $this->getGP_ENV_TSFE(trim($theVarName)); + if ($this->testNumber(substr($test,$point) ,$nv)) {return true;} } - break; - case 'globalString': - $values = explode(',',$pcs[1]); - while(list(,$test)=each($values)) { - $test = trim($test); - if ($test) { - $point = strcspn($test,'='); - $theVarName = substr($test,0,$point); - $nv = $this->getGP_ENV_TSFE(trim($theVarName)); - if ($this->matchWild($nv,trim(substr($test,$point+1)))) {return true;} - } + } + break; + case 'globalString': + $values = explode(',',$pcs[1]); + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test) { + $point = strcspn($test,'='); + $theVarName = substr($test,0,$point); + $nv = $this->getGP_ENV_TSFE(trim($theVarName)); + if ($this->matchWild($nv,trim(substr($test,$point+1)))) {return true;} } - break; - case 'treeLevel': - $values = explode(',',$pcs[1]); + } + break; + case 'treeLevel': + $values = explode(',',$pcs[1]); + $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine; + $theRLC = count($theRootLine)-1; + while(list(,$test)=each($values)) { + $test = trim($test); + if ($test==$theRLC) { return true; } + } + break; + case 'PIDupinRootline': + case 'PIDinRootline': + $values = explode(',',$pcs[1]); + if (($switchKey=='PIDinRootline') || (!in_array($GLOBALS['TSFE']->id,$values))) { $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine; - $theRLC = count($theRootLine)-1; + reset($values); while(list(,$test)=each($values)) { $test = trim($test); - if ($test==$theRLC) { return true; } - } - break; - case 'PIDupinRootline': - case 'PIDinRootline': - $values = explode(',',$pcs[1]); - if (($switchKey=='PIDinRootline') || (!in_array($GLOBALS['TSFE']->id,$values))) { - $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine; - reset($values); - while(list(,$test)=each($values)) { - $test = trim($test); - reset($theRootLine); - while(list($rl_key,$rl_dat)=each($theRootLine)) { - if ($rl_dat['uid']==$test) { return true; } - } + reset($theRootLine); + while(list($rl_key,$rl_dat)=each($theRootLine)) { + if ($rl_dat['uid']==$test) { return true; } } } - break; - case 'userFunc': - $values = split('\(|\)',$pcs[1]); - $funcName=trim($values[0]); - $funcValue = t3lib_div::trimExplode(',',$values[1]); - $pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix']; - if ($pre && - !t3lib_div::isFirstPartOfStr(trim($funcName),$pre) && - !t3lib_div::isFirstPartOfStr(trim($funcName),'tx_') - ) { - if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3); - return false; - } - if (function_exists($funcName) && call_user_func($funcName, $funcValue[0])) { - return true; - } - break; - } + } + break; + case 'userFunc': + $values = split('\(|\)',$pcs[1]); + $funcName=trim($values[0]); + $funcValue = t3lib_div::trimExplode(',',$values[1]); + $pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix']; + if ($pre && + !t3lib_div::isFirstPartOfStr(trim($funcName),$pre) && + !t3lib_div::isFirstPartOfStr(trim($funcName),'tx_') + ) { + if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3); + return false; + } + if (function_exists($funcName) && call_user_func($funcName, $funcValue[0])) { + return true; + } + break; } }