2 namespace TYPO3\CMS\Recycler\Utility
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Database\ConnectionPool
;
19 use TYPO3\CMS\Core\Type\Bitmask\Permission
;
20 use TYPO3\CMS\Core\Utility\GeneralUtility
;
23 * Helper class for the 'recycler' extension.
27 /************************************************************
31 ************************************************************/
33 * Checks the page access rights (Code for access check mostly taken from FormEngine)
34 * as well as the table access rights of the user.
36 * @param string $table The table to check access for
37 * @param string $row Record array
38 * @return bool Returns TRUE is the user has access, or FALSE if not
40 public static function checkAccess($table, $row)
42 $backendUser = static::getBackendUser();
44 // 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...)
45 // First, resetting flags.
48 BackendUtility
::fixVersioningPid($table, $calcPRec);
49 if (is_array($calcPRec)) {
50 if ($table === 'pages') {
51 $calculatedPermissions = $backendUser->calcPerms($calcPRec);
52 $hasAccess = (bool
)($calculatedPermissions & Permission
::PAGE_EDIT
);
54 $calculatedPermissions = $backendUser->calcPerms(BackendUtility
::getRecord('pages', $calcPRec['pid']));
55 // Fetching pid-record first.
56 $hasAccess = (bool
)($calculatedPermissions & Permission
::CONTENT_EDIT
);
58 // Check internals regarding access:
60 $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
63 if (!$backendUser->check('tables_modify', $table)) {
70 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
71 * Each part of the path will be limited to $titleLimit characters
72 * Deleted pages are filtered out.
74 * @param int $uid Page uid for which to create record path
75 * @param string $clause is additional where clauses, eg.
76 * @param int $titleLimit Title limit
77 * @param int $fullTitleLimit Title limit of Full title (typ. set to 1000 or so)
78 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
80 public static function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0)
82 if ($clause !== '' ||
(int)$titleLimit !== 1000 ||
(int)$fullTitleLimit !== 0) {
83 GeneralUtility
::deprecationLog('The arguments "clause", "tileLimit" and "fullTitleLimit" ' .
84 'have been deprecated since TYPO3 CMS 8 and will be removed in TYPO3 CMS 9');
87 $output = ($fullOutput = '/');
91 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)->getQueryBuilderForTable('pages');
92 $queryBuilder->getRestrictions()->removeAll();
94 $clause = trim($clause);
96 while ($loopCheck > 0) {
100 ->select('uid', 'pid', 'title', 'deleted', 't3ver_oid', 't3ver_wsid')
102 ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO
::PARAM_INT
)));
103 if (!empty($clause)) {
104 $queryBuilder->andWhere($clause);
106 $row = $queryBuilder->execute()->fetch();
107 if ($row !== false
) {
108 BackendUtility
::workspaceOL('pages', $row);
109 if (is_array($row)) {
110 BackendUtility
::fixVersioningPid('pages', $row);
111 $uid = (int)$row['pid'];
112 $output = '/' . htmlspecialchars(GeneralUtility
::fixed_lgd_cs($row['title'], $titleLimit)) . $output;
113 if ($row['deleted']) {
114 $output = '<span class="text-danger">' . $output . '</span>';
116 if ($fullTitleLimit) {
117 $fullOutput = '/' . htmlspecialchars(GeneralUtility
::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput;
126 if ($fullTitleLimit) {
127 return [$output, $fullOutput];
133 * Gets the name of the field with the information whether a record is deleted.
135 * @param string $tableName Name of the table to get the deleted field for
136 * @return string Name of the field with the information whether a record is deleted
138 public static function getDeletedField($tableName)
140 $TCA = self
::getTableTCA($tableName);
141 if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
142 return $TCA['ctrl']['delete'];
148 * Check if parent record is deleted
153 public static function isParentPageDeleted($pid)
155 if ((int)$pid === 0) {
158 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)->getQueryBuilderForTable('pages');
159 $queryBuilder->getRestrictions()->removeAll();
161 $deleted = $queryBuilder
164 ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pid, \PDO
::PARAM_INT
)))
168 return (bool
)$deleted;
175 * @param string $table
178 public static function getPidOfUid($uid, $table)
180 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)->getQueryBuilderForTable($table);
181 $queryBuilder->getRestrictions()->removeAll();
186 ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO
::PARAM_INT
)))
194 * Gets the TCA of the table used in the current context.
196 * @param string $tableName Name of the table to get TCA for
197 * @return array|false TCA of the table used in the current context
199 public static function getTableTCA($tableName)
202 if (isset($GLOBALS['TCA'][$tableName])) {
203 $TCA = $GLOBALS['TCA'][$tableName];
209 * Returns the BackendUser
211 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
213 protected static function getBackendUser()
215 return $GLOBALS['BE_USER'];
219 * Returns an instance of LanguageService
221 * @return \TYPO3\CMS\Lang\LanguageService
223 protected static function getLanguageService()
225 return $GLOBALS['LANG'];
229 * Returns the modifyable tables of the current user
231 public static function getModifyableTables()
233 if ((bool
)$GLOBALS['BE_USER']->user
['admin']) {
234 $tables = array_keys($GLOBALS['TCA']);
236 $tables = explode(',', $GLOBALS['BE_USER']->groupData
['tables_modify']);