TYPO3  7.6
frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
27 {
37  protected function evaluateCondition($string)
38  {
39  list($key, $value) = GeneralUtility::trimExplode('=', $string, false, 2);
40  $result = $this->evaluateConditionCommon($key, $value);
41 
42  if (is_bool($result)) {
43  return $result;
44  } else {
45  switch ($key) {
46  case 'usergroup':
47  $groupList = $this->getGroupList();
48  // '0,-1' is the default usergroups when not logged in!
49  if ($groupList != '0,-1') {
50  $values = GeneralUtility::trimExplode(',', $value, true);
51  foreach ($values as $test) {
52  if ($test == '*' || GeneralUtility::inList($groupList, $test)) {
53  return true;
54  }
55  }
56  }
57  break;
58  case 'treeLevel':
59  $values = GeneralUtility::trimExplode(',', $value, true);
60  $treeLevel = count($this->rootline) - 1;
61  foreach ($values as $test) {
62  if ($test == $treeLevel) {
63  return true;
64  }
65  }
66  break;
67  case 'PIDupinRootline':
68  case 'PIDinRootline':
69  $values = GeneralUtility::trimExplode(',', $value, true);
70  if ($key == 'PIDinRootline' || !in_array($this->pageId, $values)) {
71  foreach ($values as $test) {
72  foreach ($this->rootline as $rlDat) {
73  if ($rlDat['uid'] == $test) {
74  return true;
75  }
76  }
77  }
78  }
79  break;
80  default:
81  $conditionResult = $this->evaluateCustomDefinedCondition($string);
82  if ($conditionResult !== null) {
83  return $conditionResult;
84  }
85  }
86  }
87 
88  return false;
89  }
90 
97  protected function getVariable($var)
98  {
99  $vars = explode(':', $var, 2);
100  $val = $this->getVariableCommon($vars);
101  if (is_null($val)) {
102  $splitAgain = explode('|', $vars[1], 2);
103  $k = trim($splitAgain[0]);
104  if ($k) {
105  switch ((string)trim($vars[0])) {
106  case 'TSFE':
107  $val = $this->getGlobal('TSFE|' . $vars[1]);
108  break;
109  default:
110  }
111  }
112  }
113  return $val;
114  }
115 
121  protected function getGroupList()
122  {
123  return $this->getTypoScriptFrontendController()->gr_list;
124  }
125 
131  protected function determinePageId()
132  {
133  return (int)$this->getTypoScriptFrontendController()->id;
134  }
135 
141  protected function getPage()
142  {
143  return $this->getTypoScriptFrontendController()->page;
144  }
145 
151  protected function determineRootline()
152  {
153  return (array)$this->getTypoScriptFrontendController()->tmpl->rootLine;
154  }
155 
161  protected function getUserId()
162  {
163  return $this->getTypoScriptFrontendController()->fe_user->user['uid'];
164  }
165 
171  protected function isUserLoggedIn()
172  {
173  return (bool)$this->getTypoScriptFrontendController()->loginUser;
174  }
175 
182  protected function log($message)
183  {
184  if ($this->getTimeTracker() !== null) {
185  $this->getTimeTracker()->setTSlogMessage($message, 3);
186  }
187  }
188 
192  protected function getTypoScriptFrontendController()
193  {
194  return $GLOBALS['TSFE'];
195  }
196 
200  protected function getTimeTracker()
201  {
202  return $GLOBALS['TT'];
203  }
204 }