‪TYPO3CMS  10.4
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 
22 
28 {
29  /************************************************************
30  * USER ACCESS
31  *
32  *
33  ************************************************************/
42  public static function ‪checkAccess($table, $row)
43  {
44  $backendUser = static::getBackendUser();
45 
46  if ($backendUser->isAdmin()) {
47  return true;
48  }
49 
50  if (!$backendUser->check('tables_modify', $table)) {
51  return false;
52  }
53 
54  // 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...)
55  // First, resetting flags.
56  $hasAccess = false;
57  $calcPRec = $row;
58  ‪BackendUtility::fixVersioningPid($table, $calcPRec);
59  if (is_array($calcPRec)) {
60  if ($table === 'pages') {
61  $calculatedPermissions = $backendUser->calcPerms($calcPRec);
62  $hasAccess = (bool)($calculatedPermissions & ‪Permission::PAGE_EDIT);
63  } else {
64  $calculatedPermissions = $backendUser->calcPerms(‪BackendUtility::getRecord('pages', $calcPRec['pid']));
65  // Fetching pid-record first.
66  $hasAccess = (bool)($calculatedPermissions & ‪Permission::CONTENT_EDIT);
67  }
68  // Check internals regarding access:
69  if ($hasAccess) {
70  $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
71  }
72  }
73  return $hasAccess;
74  }
75 
84  public static function ‪getRecordPath($uid)
85  {
86  $uid = (int)$uid;
87  ‪$output = '/';
88  if ($uid === 0) {
89  return ‪$output;
90  }
91  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
92  $queryBuilder->getRestrictions()->removeAll();
93 
94  $loopCheck = 100;
95  while ($loopCheck > 0) {
96  $loopCheck--;
97 
98  $queryBuilder
99  ->select('uid', 'pid', 'title', 'deleted', 't3ver_oid', 't3ver_wsid')
100  ->from('pages')
101  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)));
102  $row = $queryBuilder->execute()->fetch();
103  if ($row !== false) {
104  ‪BackendUtility::workspaceOL('pages', $row);
105  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, \PDO::PARAM_INT)))
155  ->execute()
156  ->fetchColumn();
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, \PDO::PARAM_INT)))
177  ->execute()
178  ->fetchColumn();
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\Recycler\Utility\RecyclerUtility\getRecordPath
‪static string getRecordPath($uid)
Definition: RecyclerUtility.php:84
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getTableTCA
‪static array false getTableTCA($tableName)
Definition: RecyclerUtility.php:189
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getDeletedField
‪static string getDeletedField($tableName)
Definition: RecyclerUtility.php:128
‪TYPO3\CMS\Backend\Utility\BackendUtility\fixVersioningPid
‪static fixVersioningPid($table, &$rr, $ignoreWorkspaceMatch=false)
Definition: BackendUtility.php:3511
‪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
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\checkAccess
‪static bool checkAccess($table, $row)
Definition: RecyclerUtility.php:42
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:53
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\isParentPageDeleted
‪static bool isParentPageDeleted($pid)
Definition: RecyclerUtility.php:143
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility
Definition: RecyclerUtility.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Utility\BackendUtility\workspaceOL
‪static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
Definition: BackendUtility.php:3586
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:38
‪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:46
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getLanguageService
‪static TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: RecyclerUtility.php:213