‪TYPO3CMS  11.5
RecyclerUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 
29 {
30  /************************************************************
31  * USER ACCESS
32  *
33  *
34  ************************************************************/
43  public static function ‪checkAccess($table, $row)
44  {
45  $backendUser = static::getBackendUser();
46 
47  if ($backendUser->isAdmin()) {
48  return true;
49  }
50 
51  if (!$backendUser->check('tables_modify', $table)) {
52  return false;
53  }
54 
55  // 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...)
56  // First, resetting flags.
57  $hasAccess = false;
58  $calcPRec = $row;
59  BackendUtility::workspaceOL($table, $calcPRec, $backendUser->workspace);
60  if (is_array($calcPRec)) {
61  if ($table === 'pages') {
62  $calculatedPermissions = new ‪Permission($backendUser->calcPerms($calcPRec));
63  $hasAccess = $calculatedPermissions->editPagePermissionIsGranted();
64  } else {
65  $calculatedPermissions = new ‪Permission($backendUser->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid'])));
66  // Fetching pid-record first.
67  $hasAccess = $calculatedPermissions->editContentPermissionIsGranted();
68  }
69  // Check internals regarding access:
70  if ($hasAccess) {
71  $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
72  }
73  }
74  return $hasAccess;
75  }
76 
85  public static function ‪getRecordPath($uid)
86  {
87  $uid = (int)$uid;
88  ‪$output = '/';
89  if ($uid === 0) {
90  return ‪$output;
91  }
92  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
93  $queryBuilder->getRestrictions()->removeAll();
94 
95  $loopCheck = 100;
96  while ($loopCheck > 0) {
97  $loopCheck--;
98 
99  $queryBuilder
100  ->select('uid', 'pid', 'title', 'deleted', 't3ver_oid', 't3ver_wsid', 't3ver_state')
101  ->from('pages')
102  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, ‪Connection::PARAM_INT)));
103  $row = $queryBuilder->executeQuery()->fetchAssociative();
104  if ($row !== false) {
105  BackendUtility::workspaceOL('pages', $row);
106  if (is_array($row)) {
107  $uid = (int)$row['pid'];
108  ‪$output = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], 1000)) . ‪$output;
109  if ($row['deleted']) {
110  ‪$output = '<span class="text-danger">' . ‪$output . '</span>';
111  }
112  } else {
113  break;
114  }
115  } else {
116  break;
117  }
118  }
119  return ‪$output;
120  }
121 
128  public static function ‪getDeletedField($tableName)
129  {
130  $TCA = ‪self::getTableTCA($tableName);
131  if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
132  return $TCA['ctrl']['delete'];
133  }
134  return '';
135  }
136 
143  public static function ‪isParentPageDeleted($pid)
144  {
145  if ((int)$pid === 0) {
146  return false;
147  }
148  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
149  $queryBuilder->getRestrictions()->removeAll();
150 
151  $deleted = $queryBuilder
152  ->select('deleted')
153  ->from('pages')
154  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pid, ‪Connection::PARAM_INT)))
155  ->executeQuery()
156  ->fetchOne();
157 
158  return (bool)$deleted;
159  }
160 
168  public static function ‪getPidOfUid($uid, $table)
169  {
170  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
171  $queryBuilder->getRestrictions()->removeAll();
172 
173  $pid = $queryBuilder
174  ->select('pid')
175  ->from($table)
176  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, ‪Connection::PARAM_INT)))
177  ->executeQuery()
178  ->fetchOne();
179 
180  return (int)$pid;
181  }
182 
189  public static function ‪getTableTCA($tableName)
190  {
191  $TCA = false;
192  if (isset(‪$GLOBALS['TCA'][$tableName])) {
193  $TCA = ‪$GLOBALS['TCA'][$tableName];
194  }
195  return $TCA;
196  }
197 
203  protected static function ‪getBackendUser()
204  {
205  return ‪$GLOBALS['BE_USER'];
206  }
207 
213  protected static function ‪getLanguageService()
214  {
215  return ‪$GLOBALS['LANG'];
216  }
217 
221  public static function ‪getModifyableTables()
222  {
223  if (‪$GLOBALS['BE_USER']->isAdmin()) {
224  $tables = array_keys(‪$GLOBALS['TCA']);
225  } else {
226  $tables = explode(',', ‪$GLOBALS['BE_USER']->groupData['tables_modify']);
227  }
228  return $tables;
229  }
230 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getRecordPath
‪static string getRecordPath($uid)
Definition: RecyclerUtility.php:85
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getTableTCA
‪static array false getTableTCA($tableName)
Definition: RecyclerUtility.php:189
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getDeletedField
‪static string getDeletedField($tableName)
Definition: RecyclerUtility.php:128
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getModifyableTables
‪static getModifyableTables()
Definition: RecyclerUtility.php:221
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getPidOfUid
‪static int getPidOfUid($uid, $table)
Definition: RecyclerUtility.php:168
‪$output
‪$output
Definition: annotationChecker.php:122
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\checkAccess
‪static bool checkAccess($table, $row)
Definition: RecyclerUtility.php:43
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\isParentPageDeleted
‪static bool isParentPageDeleted($pid)
Definition: RecyclerUtility.php:143
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility
Definition: RecyclerUtility.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getBackendUser
‪static TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: RecyclerUtility.php:203
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Recycler\Utility
Definition: RecyclerUtility.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getLanguageService
‪static TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: RecyclerUtility.php:213