TYPO3 CMS  TYPO3_8-7
ConditionMatcher.php
Go to the documentation of this file.
1 <?php
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 
20 
28 {
38  protected function evaluateCondition($string)
39  {
40  list($key, $value) = GeneralUtility::trimExplode('=', $string, false, 2);
41  $result = $this->evaluateConditionCommon($key, $value);
42 
43  if (is_bool($result)) {
44  return $result;
45  }
46  switch ($key) {
47  case 'usergroup':
48  $groupList = $this->getGroupList();
49  // '0,-1' is the default usergroups when not logged in!
50  if ($groupList !== '0,-1') {
51  $values = GeneralUtility::trimExplode(',', $value, true);
52  foreach ($values as $test) {
53  if ($test === '*' || GeneralUtility::inList($groupList, $test)) {
54  return true;
55  }
56  }
57  }
58  break;
59  case 'treeLevel':
60  $values = GeneralUtility::trimExplode(',', $value, true);
61  $treeLevel = count($this->rootline) - 1;
62  foreach ($values as $test) {
63  if ($test == $treeLevel) {
64  return true;
65  }
66  }
67  break;
68  case 'PIDupinRootline':
69  case 'PIDinRootline':
70  $values = GeneralUtility::trimExplode(',', $value, true);
71  if ($key === 'PIDinRootline' || !in_array($this->pageId, $values)) {
72  foreach ($values as $test) {
73  foreach ($this->rootline as $rlDat) {
74  if ($rlDat['uid'] == $test) {
75  return true;
76  }
77  }
78  }
79  }
80  break;
81  default:
82  $conditionResult = $this->evaluateCustomDefinedCondition($string);
83  if ($conditionResult !== null) {
84  return $conditionResult;
85  }
86  }
87 
88  return false;
89  }
90 
102  protected function getVariable($var)
103  {
104  $vars = explode(':', $var, 2);
105  $val = $this->getVariableCommon($vars);
106  if (is_null($val)) {
107  $splitAgain = explode('|', $vars[1], 2);
108  $k = trim($splitAgain[0]);
109  if ($k) {
110  switch ((string)trim($vars[0])) {
111  case 'TSFE':
112  if (strpos($vars[1], 'fe_user|sesData|') === 0) {
113  $val = $this->getSessionVariable(substr($vars[1], 16));
114  } else {
115  $val = $this->getGlobal('TSFE|' . $vars[1]);
116  }
117  break;
118  default:
119  }
120  }
121  }
122  return $val;
123  }
124 
131  protected function getSessionVariable(string $var)
132  {
133  $retVal = null;
134  $keyParts = explode('|', $var);
135  $sessionKey = array_shift($keyParts);
136  $tsfe = $this->getTypoScriptFrontendController();
137  if ($tsfe && is_object($tsfe->fe_user)) {
138  $retVal = $tsfe->fe_user->getSessionData($sessionKey);
139  foreach ($keyParts as $keyPart) {
140  if (is_object($retVal)) {
141  $retVal = $retVal->{$keyPart};
142  } elseif (is_array($retVal)) {
143  $retVal = $retVal[$keyPart];
144  } else {
145  break;
146  }
147  }
148  }
149  return $retVal;
150  }
151 
157  protected function getGroupList()
158  {
159  return $this->getTypoScriptFrontendController()->gr_list;
160  }
161 
167  protected function determinePageId()
168  {
169  return (int)$this->getTypoScriptFrontendController()->id;
170  }
171 
177  protected function getPage()
178  {
179  return $this->getTypoScriptFrontendController()->page;
180  }
181 
187  protected function determineRootline()
188  {
189  return (array)$this->getTypoScriptFrontendController()->tmpl->rootLine;
190  }
191 
197  protected function getUserId()
198  {
199  return $this->getTypoScriptFrontendController()->fe_user->user['uid'];
200  }
201 
207  protected function isUserLoggedIn()
208  {
209  return (bool)$this->getTypoScriptFrontendController()->loginUser;
210  }
211 
217  protected function log($message)
218  {
219  if ($this->getTimeTracker() !== null) {
220  $this->getTimeTracker()->setTSlogMessage($message, 3);
221  }
222  }
223 
227  protected function getTypoScriptFrontendController()
228  {
229  return $GLOBALS['TSFE'];
230  }
231 
235  protected function getTimeTracker()
236  {
237  return GeneralUtility::makeInstance(TimeTracker::class);
238  }
239 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']