‪TYPO3CMS  9.5
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 
27 {
28  /************************************************************
29  * USER ACCESS
30  *
31  *
32  ************************************************************/
41  public static function ‪checkAccess($table, $row)
42  {
43  $backendUser = static::getBackendUser();
44 
45  if ($backendUser->isAdmin()) {
46  return true;
47  }
48 
49  if (!$backendUser->check('tables_modify', $table)) {
50  return false;
51  }
52 
53  // 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...)
54  // First, resetting flags.
55  $hasAccess = false;
56  $calcPRec = $row;
57  ‪BackendUtility::fixVersioningPid($table, $calcPRec);
58  if (is_array($calcPRec)) {
59  if ($table === 'pages') {
60  $calculatedPermissions = $backendUser->calcPerms($calcPRec);
61  $hasAccess = (bool)($calculatedPermissions & ‪Permission::PAGE_EDIT);
62  } else {
63  $calculatedPermissions = $backendUser->calcPerms(‪BackendUtility::getRecord('pages', $calcPRec['pid']));
64  // Fetching pid-record first.
65  $hasAccess = (bool)($calculatedPermissions & ‪Permission::CONTENT_EDIT);
66  }
67  // Check internals regarding access:
68  if ($hasAccess) {
69  $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
70  }
71  }
72  return $hasAccess;
73  }
74 
83  public static function ‪getRecordPath($uid)
84  {
85  $uid = (int)$uid;
86  ‪$output = '/';
87  if ($uid === 0) {
88  return ‪$output;
89  }
90  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
91  $queryBuilder->getRestrictions()->removeAll();
92 
93  $loopCheck = 100;
94  while ($loopCheck > 0) {
95  $loopCheck--;
96 
97  $queryBuilder
98  ->select('uid', 'pid', 'title', 'deleted', 't3ver_oid', 't3ver_wsid')
99  ->from('pages')
100  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)));
101  $row = $queryBuilder->execute()->fetch();
102  if ($row !== false) {
103  ‪BackendUtility::workspaceOL('pages', $row);
104  if (is_array($row)) {
106  $uid = (int)$row['pid'];
107  ‪$output = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], 1000)) . ‪$output;
108  if ($row['deleted']) {
109  ‪$output = '<span class="text-danger">' . ‪$output . '</span>';
110  }
111  } else {
112  break;
113  }
114  } else {
115  break;
116  }
117  }
118  return ‪$output;
119  }
120 
127  public static function ‪getDeletedField($tableName)
128  {
129  $TCA = ‪self::getTableTCA($tableName);
130  if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
131  return $TCA['ctrl']['delete'];
132  }
133  return '';
134  }
135 
142  public static function ‪isParentPageDeleted($pid)
143  {
144  if ((int)$pid === 0) {
145  return false;
146  }
147  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
148  $queryBuilder->getRestrictions()->removeAll();
149 
150  $deleted = $queryBuilder
151  ->select('deleted')
152  ->from('pages')
153  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)))
154  ->execute()
155  ->fetchColumn();
156 
157  return (bool)$deleted;
158  }
159 
167  public static function ‪getPidOfUid($uid, $table)
168  {
169  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
170  $queryBuilder->getRestrictions()->removeAll();
171 
172  $pid = $queryBuilder
173  ->select('pid')
174  ->from($table)
175  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
176  ->execute()
177  ->fetchColumn();
178 
179  return (int)$pid;
180  }
181 
188  public static function ‪getTableTCA($tableName)
189  {
190  $TCA = false;
191  if (isset(‪$GLOBALS['TCA'][$tableName])) {
192  $TCA = ‪$GLOBALS['TCA'][$tableName];
193  }
194  return $TCA;
195  }
196 
202  protected static function ‪getBackendUser()
203  {
204  return ‪$GLOBALS['BE_USER'];
205  }
206 
212  protected static function ‪getLanguageService()
213  {
214  return ‪$GLOBALS['LANG'];
215  }
216 
220  public static function ‪getModifyableTables()
221  {
222  if (‪$GLOBALS['BE_USER']->isAdmin()) {
223  $tables = array_keys(‪$GLOBALS['TCA']);
224  } else {
225  $tables = explode(',', ‪$GLOBALS['BE_USER']->groupData['tables_modify']);
226  }
227  return $tables;
228  }
229 }
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getRecordPath
‪static string getRecordPath($uid)
Definition: RecyclerUtility.php:83
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getTableTCA
‪static array false getTableTCA($tableName)
Definition: RecyclerUtility.php:188
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getDeletedField
‪static string getDeletedField($tableName)
Definition: RecyclerUtility.php:127
‪TYPO3\CMS\Backend\Utility\BackendUtility\fixVersioningPid
‪static fixVersioningPid($table, &$rr, $ignoreWorkspaceMatch=false)
Definition: BackendUtility.php:3986
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getModifyableTables
‪static getModifyableTables()
Definition: RecyclerUtility.php:220
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getPidOfUid
‪static int getPidOfUid($uid, $table)
Definition: RecyclerUtility.php:167
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\checkAccess
‪static bool checkAccess($table, $row)
Definition: RecyclerUtility.php:41
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:52
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\isParentPageDeleted
‪static bool isParentPageDeleted($pid)
Definition: RecyclerUtility.php:142
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility
Definition: RecyclerUtility.php:27
‪$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:4048
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:37
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getBackendUser
‪static TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: RecyclerUtility.php:202
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Recycler\Utility
Definition: RecyclerUtility.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getLanguageService
‪static TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: RecyclerUtility.php:212