TYPO3 CMS  TYPO3_8-7
RecyclerUtility.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 
26 {
27  /************************************************************
28  * USER ACCESS
29  *
30  *
31  ************************************************************/
40  public static function checkAccess($table, $row)
41  {
42  $backendUser = static::getBackendUser();
43 
44  if ($backendUser->isAdmin()) {
45  return true;
46  }
47 
48  if (!$backendUser->check('tables_modify', $table)) {
49  return false;
50  }
51 
52  // Checking if the user has permissions? (Only working as a precaution, because the final permission check is always down in TCE. But it's good to notify the user on beforehand...)
53  // First, resetting flags.
54  $hasAccess = false;
55  $calcPRec = $row;
56  BackendUtility::fixVersioningPid($table, $calcPRec);
57  if (is_array($calcPRec)) {
58  if ($table === 'pages') {
59  $calculatedPermissions = $backendUser->calcPerms($calcPRec);
60  $hasAccess = (bool)($calculatedPermissions & Permission::PAGE_EDIT);
61  } else {
62  $calculatedPermissions = $backendUser->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
63  // Fetching pid-record first.
64  $hasAccess = (bool)($calculatedPermissions & Permission::CONTENT_EDIT);
65  }
66  // Check internals regarding access:
67  if ($hasAccess) {
68  $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
69  }
70  }
71  return $hasAccess;
72  }
73 
85  public static function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0)
86  {
87  if ($clause !== '' || (int)$titleLimit !== 1000 || (int)$fullTitleLimit !== 0) {
88  GeneralUtility::deprecationLog('The arguments "clause", "tileLimit" and "fullTitleLimit" ' .
89  'have been deprecated since TYPO3 CMS 8 and will be removed in TYPO3 CMS 9');
90  }
91  $uid = (int)$uid;
92  $output = ($fullOutput = '/');
93  if ($uid === 0) {
94  return $output;
95  }
96  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
97  $queryBuilder->getRestrictions()->removeAll();
98 
99  $clause = trim($clause);
100  $loopCheck = 100;
101  while ($loopCheck > 0) {
102  $loopCheck--;
103 
104  $queryBuilder
105  ->select('uid', 'pid', 'title', 'deleted', 't3ver_oid', 't3ver_wsid')
106  ->from('pages')
107  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)));
108  if (!empty($clause)) {
109  $queryBuilder->andWhere($clause);
110  }
111  $row = $queryBuilder->execute()->fetch();
112  if ($row !== false) {
113  BackendUtility::workspaceOL('pages', $row);
114  if (is_array($row)) {
115  BackendUtility::fixVersioningPid('pages', $row);
116  $uid = (int)$row['pid'];
117  $output = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output;
118  if ($row['deleted']) {
119  $output = '<span class="text-danger">' . $output . '</span>';
120  }
121  if ($fullTitleLimit) {
122  $fullOutput = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput;
123  }
124  } else {
125  break;
126  }
127  } else {
128  break;
129  }
130  }
131  if ($fullTitleLimit) {
132  return [$output, $fullOutput];
133  }
134  return $output;
135  }
136 
143  public static function getDeletedField($tableName)
144  {
145  $TCA = self::getTableTCA($tableName);
146  if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
147  return $TCA['ctrl']['delete'];
148  }
149  return '';
150  }
151 
158  public static function isParentPageDeleted($pid)
159  {
160  if ((int)$pid === 0) {
161  return false;
162  }
163  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
164  $queryBuilder->getRestrictions()->removeAll();
165 
166  $deleted = $queryBuilder
167  ->select('deleted')
168  ->from('pages')
169  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)))
170  ->execute()
171  ->fetchColumn();
172 
173  return (bool)$deleted;
174  }
175 
183  public static function getPidOfUid($uid, $table)
184  {
185  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
186  $queryBuilder->getRestrictions()->removeAll();
187 
188  $pid = $queryBuilder
189  ->select('pid')
190  ->from($table)
191  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
192  ->execute()
193  ->fetchColumn();
194 
195  return (int)$pid;
196  }
197 
204  public static function getTableTCA($tableName)
205  {
206  $TCA = false;
207  if (isset($GLOBALS['TCA'][$tableName])) {
208  $TCA = $GLOBALS['TCA'][$tableName];
209  }
210  return $TCA;
211  }
212 
218  protected static function getBackendUser()
219  {
220  return $GLOBALS['BE_USER'];
221  }
222 
228  protected static function getLanguageService()
229  {
230  return $GLOBALS['LANG'];
231  }
232 
236  public static function getModifyableTables()
237  {
238  if ((bool)$GLOBALS['BE_USER']->user['admin']) {
239  $tables = array_keys($GLOBALS['TCA']);
240  } else {
241  $tables = explode(',', $GLOBALS['BE_USER']->groupData['tables_modify']);
242  }
243  return $tables;
244  }
245 }
static getRecordPath($uid, $clause='', $titleLimit=1000, $fullTitleLimit=0)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
static makeInstance($className,... $constructorArguments)
static fixVersioningPid($table, &$rr, $ignoreWorkspaceMatch=false)
static fixed_lgd_cs($string, $chars, $appendString='...')
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']