/**
  * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
  *
  * @param string $string The condition to match against its criterias.
  * @return boolean Whether the condition matched
  * @see t3lib_tsparser::parse()
  */
 protected function evaluateCondition($string)
 {
     list($key, $value) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('=', $string, FALSE, 2);
     $result = parent::evaluateConditionCommon($key, $value);
     if (is_bool($result)) {
         return $result;
     } else {
         switch ($key) {
             case 'usergroup':
                 $groupList = $this->getGroupList();
                 $values = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value, TRUE);
                 foreach ($values as $test) {
                     if ($test == '*' || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($groupList, $test)) {
                         return TRUE;
                     }
                 }
                 break;
             case 'adminUser':
                 if ($this->isUserLoggedIn()) {
                     $result = !((bool) $value xor $this->isAdminUser());
                     return $result;
                 }
                 break;
             case 'treeLevel':
                 $values = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value, TRUE);
                 $treeLevel = count($this->rootline) - 1;
                 // If a new page is being edited or saved the treeLevel is higher by one:
                 if ($this->isNewPageWithPageId($this->pageId)) {
                     $treeLevel++;
                 }
                 foreach ($values as $test) {
                     if ($test == $treeLevel) {
                         return TRUE;
                     }
                 }
                 break;
             case 'PIDupinRootline':
             case 'PIDinRootline':
                 $values = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value, TRUE);
                 if ($key == 'PIDinRootline' || !in_array($this->pageId, $values) || $this->isNewPageWithPageId($this->pageId)) {
                     foreach ($values as $test) {
                         foreach ($this->rootline as $rl_dat) {
                             if ($rl_dat['uid'] == $test) {
                                 return TRUE;
                             }
                         }
                     }
                 }
                 break;
         }
     }
     return FALSE;
 }
Example #2
0
 /**
  * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
  *
  * @param string $string The condition to match against its criterias.
  * @return boolean Whether the condition matched
  * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::parse()
  */
 protected function evaluateCondition($string)
 {
     list($key, $value) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('=', $string, FALSE, 2);
     $result = parent::evaluateConditionCommon($key, $value);
     if (is_bool($result)) {
         return $result;
     } else {
         switch ($key) {
             case 'usergroup':
                 $groupList = $this->getGroupList();
                 // '0,-1' is the default usergroups when not logged in!
                 if ($groupList != '0,-1') {
                     $values = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value, TRUE);
                     foreach ($values as $test) {
                         if ($test == '*' || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($groupList, $test)) {
                             return TRUE;
                         }
                     }
                 }
                 break;
             case 'treeLevel':
                 $values = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value, TRUE);
                 $treeLevel = count($this->rootline) - 1;
                 foreach ($values as $test) {
                     if ($test == $treeLevel) {
                         return TRUE;
                     }
                 }
                 break;
             case 'PIDupinRootline':
             case 'PIDinRootline':
                 $values = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value, TRUE);
                 if ($key == 'PIDinRootline' || !in_array($this->pageId, $values)) {
                     foreach ($values as $test) {
                         foreach ($this->rootline as $rl_dat) {
                             if ($rl_dat['uid'] == $test) {
                                 return TRUE;
                             }
                         }
                     }
                 }
                 break;
         }
     }
     return FALSE;
 }