TYPO3 CMS  TYPO3_7-6
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 
21 
29 {
33  public function __construct()
34  {
35  }
36 
44  protected function evaluateCondition($string)
45  {
46  list($key, $value) = GeneralUtility::trimExplode('=', $string, false, 2);
47  $result = $this->evaluateConditionCommon($key, $value);
48  if (is_bool($result)) {
49  return $result;
50  } else {
51  switch ($key) {
52  case 'usergroup':
53  $groupList = $this->getGroupList();
54  $values = GeneralUtility::trimExplode(',', $value, true);
55  foreach ($values as $test) {
56  if ($test === '*' || GeneralUtility::inList($groupList, $test)) {
57  return true;
58  }
59  }
60  break;
61  case 'adminUser':
62  if ($this->isUserLoggedIn()) {
63  return !((bool)$value xor $this->isAdminUser());
64  }
65  break;
66  case 'treeLevel':
67  $values = GeneralUtility::trimExplode(',', $value, true);
68  $treeLevel = count($this->rootline) - 1;
69  // If a new page is being edited or saved the treeLevel is higher by one:
70  if ($this->isNewPageWithPageId($this->pageId)) {
71  $treeLevel++;
72  }
73  foreach ($values as $test) {
74  if ($test == $treeLevel) {
75  return true;
76  }
77  }
78  break;
79  case 'PIDupinRootline':
80  case 'PIDinRootline':
81  $values = GeneralUtility::trimExplode(',', $value, true);
82  if ($key == 'PIDinRootline' || !in_array($this->pageId, $values) || $this->isNewPageWithPageId($this->pageId)) {
83  foreach ($values as $test) {
84  foreach ($this->rootline as $rl_dat) {
85  if ($rl_dat['uid'] == $test) {
86  return true;
87  }
88  }
89  }
90  }
91  break;
92  default:
93  $conditionResult = $this->evaluateCustomDefinedCondition($string);
94  if ($conditionResult !== null) {
95  return $conditionResult;
96  }
97  }
98  }
99  return false;
100  }
101 
109  protected function getVariable($var)
110  {
111  $vars = explode(':', $var, 2);
112  return $this->getVariableCommon($vars);
113  }
114 
120  protected function getGroupList()
121  {
122  return $this->getBackendUserAuthentication()->groupList;
123  }
124 
133  protected function determinePageId()
134  {
135  $pageId = 0;
136  $editStatement = GeneralUtility::_GP('edit');
137  $commandStatement = GeneralUtility::_GP('cmd');
138  // Determine id from module that was called with an id:
139  if ($id = (int)GeneralUtility::_GP('id')) {
140  $pageId = $id;
141  } elseif (is_array($editStatement)) {
142  $table = key($editStatement);
143  $uidAndAction = current($editStatement);
144  $uid = key($uidAndAction);
145  $action = current($uidAndAction);
146  if ($action === 'edit') {
147  $pageId = $this->getPageIdByRecord($table, $uid);
148  } elseif ($action === 'new') {
149  $pageId = $this->getPageIdByRecord($table, $uid, true);
150  }
151  } elseif (is_array($commandStatement)) {
152  $table = key($commandStatement);
153  $uidActionAndTarget = current($commandStatement);
154  $uid = key($uidActionAndTarget);
155  $actionAndTarget = current($uidActionAndTarget);
156  $action = key($actionAndTarget);
157  $target = current($actionAndTarget);
158  if ($action === 'delete') {
159  $pageId = $this->getPageIdByRecord($table, $uid);
160  } elseif ($action === 'copy' || $action === 'move') {
161  $pageId = $this->getPageIdByRecord($table, $target, true);
162  }
163  }
164  return $pageId;
165  }
166 
172  protected function getPage()
173  {
174  $pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
175  return BackendUtility::getRecord('pages', $pageId);
176  }
177 
186  protected function getPageIdByRecord($table, $id, $ignoreTable = false)
187  {
188  $pageId = 0;
189  $id = (int)$id;
190  if ($table && $id) {
191  if (($ignoreTable || $table === 'pages') && $id >= 0) {
192  $pageId = $id;
193  } else {
194  $record = BackendUtility::getRecordWSOL($table, abs($id), '*', '', false);
195  $pageId = $record['pid'];
196  }
197  }
198  return $pageId;
199  }
200 
208  protected function isNewPageWithPageId($pageId)
209  {
210  if (isset($GLOBALS['SOBE']) && $GLOBALS['SOBE'] instanceof EditDocumentController) {
211  $pageId = (int)$pageId;
212  $elementsData = $GLOBALS['SOBE']->elementsData;
213  $data = $GLOBALS['SOBE']->data;
214  // If saving a new page record:
215  if (is_array($data) && isset($data['pages']) && is_array($data['pages'])) {
216  foreach ($data['pages'] as $uid => $fields) {
217  if (strpos($uid, 'NEW') === 0 && $fields['pid'] == $pageId) {
218  return true;
219  }
220  }
221  }
222  // If editing a new page record (not saved yet):
223  if (is_array($elementsData)) {
224  foreach ($elementsData as $element) {
225  if ($element['cmd'] === 'new' && $element['table'] === 'pages') {
226  if ($element['pid'] < 0) {
227  $pageRecord = BackendUtility::getRecord('pages', abs($element['pid']), 'pid');
228  $element['pid'] = $pageRecord['pid'];
229  }
230  if ($element['pid'] == $pageId) {
231  return true;
232  }
233  }
234  }
235  }
236  }
237  return false;
238  }
239 
245  protected function determineRootline()
246  {
247  $pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
248  return BackendUtility::BEgetRootLine($pageId, '', true);
249  }
250 
256  protected function getUserId()
257  {
258  return $this->getBackendUserAuthentication()->user['uid'];
259  }
260 
266  protected function isUserLoggedIn()
267  {
268  return (bool)$this->getBackendUserAuthentication()->user['uid'];
269  }
270 
276  protected function isAdminUser()
277  {
278  return $this->getBackendUserAuthentication()->isAdmin();
279  }
280 
287  protected function log($message)
288  {
289  if (is_object($this->getBackendUserAuthentication())) {
290  $this->getBackendUserAuthentication()->writelog(3, 0, 1, 0, $message, []);
291  }
292  }
293 
297  protected function getBackendUserAuthentication()
298  {
299  return $GLOBALS['BE_USER'];
300  }
301 }
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
$uid
Definition: server.php:38
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)