TYPO3 CMS  TYPO3_6-2
ConditionMatcher.php
Go to the documentation of this file.
1 <?php
3 
19 
29 
33  public function __construct() {}
34 
42  protected function evaluateCondition($string) {
43  list($key, $value) = GeneralUtility::trimExplode('=', $string, FALSE, 2);
44  $result = $this->evaluateConditionCommon($key, $value);
45  if (is_bool($result)) {
46  return $result;
47  } else {
48  switch ($key) {
49  case 'usergroup':
50  $groupList = $this->getGroupList();
51  $values = GeneralUtility::trimExplode(',', $value, TRUE);
52  foreach ($values as $test) {
53  if ($test == '*' || GeneralUtility::inList($groupList, $test)) {
54  return TRUE;
55  }
56  }
57  break;
58  case 'adminUser':
59  if ($this->isUserLoggedIn()) {
60  $result = !((bool) $value xor $this->isAdminUser());
61  return $result;
62  }
63  break;
64  case 'treeLevel':
65  $values = GeneralUtility::trimExplode(',', $value, TRUE);
66  $treeLevel = count($this->rootline) - 1;
67  // If a new page is being edited or saved the treeLevel is higher by one:
68  if ($this->isNewPageWithPageId($this->pageId)) {
69  $treeLevel++;
70  }
71  foreach ($values as $test) {
72  if ($test == $treeLevel) {
73  return TRUE;
74  }
75  }
76  break;
77  case 'PIDupinRootline':
78 
79  case 'PIDinRootline':
80  $values = GeneralUtility::trimExplode(',', $value, TRUE);
81  if ($key == 'PIDinRootline' || !in_array($this->pageId, $values) || $this->isNewPageWithPageId($this->pageId)) {
82  foreach ($values as $test) {
83  foreach ($this->rootline as $rl_dat) {
84  if ($rl_dat['uid'] == $test) {
85  return TRUE;
86  }
87  }
88  }
89  }
90  break;
91  }
92  }
93  return FALSE;
94  }
95 
103  protected function getVariable($var) {
104  $vars = explode(':', $var, 2);
105  return $this->getVariableCommon($vars);
106  }
107 
113  protected function getGroupList() {
114  $groupList = $GLOBALS['BE_USER']->groupList;
115  return $groupList;
116  }
117 
126  protected function determinePageId() {
127  $pageId = 0;
128  $editStatement = GeneralUtility::_GP('edit');
129  $commandStatement = GeneralUtility::_GP('cmd');
130  // Determine id from module that was called with an id:
131  if ($id = (int)GeneralUtility::_GP('id')) {
132  $pageId = $id;
133  } elseif (is_array($editStatement)) {
134  list($table, $uidAndAction) = each($editStatement);
135  list($uid, $action) = each($uidAndAction);
136  if ($action === 'edit') {
137  $pageId = $this->getPageIdByRecord($table, $uid);
138  } elseif ($action === 'new') {
139  $pageId = $this->getPageIdByRecord($table, $uid, TRUE);
140  }
141  } elseif (is_array($commandStatement)) {
142  list($table, $uidActionAndTarget) = each($commandStatement);
143  list($uid, $actionAndTarget) = each($uidActionAndTarget);
144  list($action, $target) = each($actionAndTarget);
145  if ($action === 'delete') {
146  $pageId = $this->getPageIdByRecord($table, $uid);
147  } elseif ($action === 'copy' || $action === 'move') {
148  $pageId = $this->getPageIdByRecord($table, $target, TRUE);
149  }
150  }
151  return $pageId;
152  }
153 
159  protected function getPage() {
160  $pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
161  return BackendUtility::getRecord('pages', $pageId);
162  }
163 
172  protected function getPageIdByRecord($table, $id, $ignoreTable = FALSE) {
173  $pageId = 0;
174  $id = (int)$id;
175  if ($table && $id) {
176  if (($ignoreTable || $table === 'pages') && $id >= 0) {
177  $pageId = $id;
178  } else {
179  $record = BackendUtility::getRecordWSOL($table, abs($id), '*', '', FALSE);
180  $pageId = $record['pid'];
181  }
182  }
183  return $pageId;
184  }
185 
193  protected function isNewPageWithPageId($pageId) {
194  if (isset($GLOBALS['SOBE']) && $GLOBALS['SOBE'] instanceof \TYPO3\CMS\Backend\Controller\EditDocumentController) {
195  $pageId = (int)$pageId;
196  $elementsData = $GLOBALS['SOBE']->elementsData;
197  $data = $GLOBALS['SOBE']->data;
198  // If saving a new page record:
199  if (is_array($data) && isset($data['pages']) && is_array($data['pages'])) {
200  foreach ($data['pages'] as $uid => $fields) {
201  if (strpos($uid, 'NEW') === 0 && $fields['pid'] == $pageId) {
202  return TRUE;
203  }
204  }
205  }
206  // If editing a new page record (not saved yet):
207  if (is_array($elementsData)) {
208  foreach ($elementsData as $element) {
209  if ($element['cmd'] == 'new' && $element['table'] == 'pages') {
210  if ($element['pid'] < 0) {
211  $pageRecord = BackendUtility::getRecord('pages', abs($element['pid']), 'pid');
212  $element['pid'] = $pageRecord['pid'];
213  }
214  if ($element['pid'] == $pageId) {
215  return TRUE;
216  }
217  }
218  }
219  }
220  }
221  return FALSE;
222  }
223 
229  protected function determineRootline() {
230  $pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
232  return $rootline;
233  }
234 
240  protected function getUserId() {
241  $userId = $GLOBALS['BE_USER']->user['uid'];
242  return $userId;
243  }
244 
250  protected function isUserLoggedIn() {
251  $userLoggedIn = FALSE;
252  if ($GLOBALS['BE_USER']->user['uid']) {
253  $userLoggedIn = TRUE;
254  }
255  return $userLoggedIn;
256  }
257 
263  protected function isAdminUser() {
264  $isAdminUser = FALSE;
265  if ($GLOBALS['BE_USER']->user['admin']) {
266  $isAdminUser = TRUE;
267  }
268  return $isAdminUser;
269  }
270 
277  protected function log($message) {
278  if (is_object($GLOBALS['BE_USER'])) {
279  $GLOBALS['BE_USER']->writelog(3, 0, 1, 0, $message, array());
280  }
281  }
282 
283 }
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
$uid
Definition: server.php:36
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]