[TASK] Deprecate not used arguments of RecyclerUtility::getRecordPath
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Utility / RecyclerUtility.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Utility;
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
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;
21
22 /**
23 * Helper class for the 'recycler' extension.
24 */
25 class RecyclerUtility
26 {
27 /************************************************************
28 * USER ACCESS
29 *
30 *
31 ************************************************************/
32 /**
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.
35 *
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
39 */
40 public static function checkAccess($table, $row)
41 {
42 $backendUser = static::getBackendUser();
43
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.
46 $hasAccess = false;
47 $calcPRec = $row;
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);
53 } else {
54 $calculatedPermissions = $backendUser->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
55 // Fetching pid-record first.
56 $hasAccess = (bool)($calculatedPermissions & Permission::CONTENT_EDIT);
57 }
58 // Check internals regarding access:
59 if ($hasAccess) {
60 $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
61 }
62 }
63 if (!$backendUser->check('tables_modify', $table)) {
64 $hasAccess = false;
65 }
66 return $hasAccess;
67 }
68
69 /**
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.
73 *
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.
79 */
80 public static function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0)
81 {
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');
85 }
86 $uid = (int)$uid;
87 $output = ($fullOutput = '/');
88 if ($uid === 0) {
89 return $output;
90 }
91 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
92 $queryBuilder->getRestrictions()->removeAll();
93
94 $clause = trim($clause);
95 $loopCheck = 100;
96 while ($loopCheck > 0) {
97 $loopCheck--;
98
99 $queryBuilder
100 ->select('uid', 'pid', 'title', 'deleted', 't3ver_oid', 't3ver_wsid')
101 ->from('pages')
102 ->where($queryBuilder->expr()->eq('uid', (int)$uid));
103 if (!empty($clause)) {
104 $queryBuilder->andWhere($clause);
105 }
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>';
115 }
116 if ($fullTitleLimit) {
117 $fullOutput = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput;
118 }
119 } else {
120 break;
121 }
122 } else {
123 break;
124 }
125 }
126 if ($fullTitleLimit) {
127 return [$output, $fullOutput];
128 } else {
129 return $output;
130 }
131 }
132
133 /**
134 * Gets the name of the field with the information whether a record is deleted.
135 *
136 * @param string $tableName Name of the table to get the deleted field for
137 * @return string Name of the field with the information whether a record is deleted
138 */
139 public static function getDeletedField($tableName)
140 {
141 $TCA = self::getTableTCA($tableName);
142 if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
143 return $TCA['ctrl']['delete'];
144 }
145 return '';
146 }
147
148 /**
149 * Check if parent record is deleted
150 *
151 * @param int $pid
152 * @return bool
153 */
154 public static function isParentPageDeleted($pid)
155 {
156 if ((int)$pid === 0) {
157 return false;
158 }
159 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
160 $queryBuilder->getRestrictions()->removeAll();
161
162 $deleted = $queryBuilder
163 ->select('deleted')
164 ->from('pages')
165 ->where($queryBuilder->expr()->eq('uid', (int)$pid))
166 ->execute()
167 ->fetchColumn();
168
169 return (bool)$deleted;
170 }
171
172 /**
173 * Get pid of uid
174 *
175 * @param int $uid
176 * @param string $table
177 * @return int
178 */
179 public static function getPidOfUid($uid, $table)
180 {
181 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
182 $queryBuilder->getRestrictions()->removeAll();
183
184 $pid = $queryBuilder
185 ->select('pid')
186 ->from($table)
187 ->where($queryBuilder->expr()->eq('uid', (int)$uid))
188 ->execute()
189 ->fetchColumn();
190
191 return (int)$pid;
192 }
193
194 /**
195 * Gets the TCA of the table used in the current context.
196 *
197 * @param string $tableName Name of the table to get TCA for
198 * @return array|FALSE TCA of the table used in the current context
199 */
200 public static function getTableTCA($tableName)
201 {
202 $TCA = false;
203 if (isset($GLOBALS['TCA'][$tableName])) {
204 $TCA = $GLOBALS['TCA'][$tableName];
205 }
206 return $TCA;
207 }
208
209 /**
210 * Returns the BackendUser
211 *
212 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
213 */
214 protected static function getBackendUser()
215 {
216 return $GLOBALS['BE_USER'];
217 }
218
219 /**
220 * Returns an instance of LanguageService
221 *
222 * @return \TYPO3\CMS\Lang\LanguageService
223 */
224 protected static function getLanguageService()
225 {
226 return $GLOBALS['LANG'];
227 }
228
229 /**
230 * Returns the modifyable tables of the current user
231 */
232 public static function getModifyableTables()
233 {
234 if ((bool)$GLOBALS['BE_USER']->user['admin']) {
235 $tables = array_keys($GLOBALS['TCA']);
236 } else {
237 $tables = explode(',', $GLOBALS['BE_USER']->groupData['tables_modify']);
238 }
239 return $tables;
240 }
241 }