[TASK] Make use of "use"-statement for BackendUtility
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Utility / RecyclerUtility.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Julian Kleinhans <typo3@kj187.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Backend\Utility\BackendUtility;
28
29 /**
30 * Helper class for the 'recycler' extension.
31 *
32 * @author Julian Kleinhans <typo3@kj187.de>
33 */
34 class RecyclerUtility {
35
36 /************************************************************
37 * USER ACCESS
38 *
39 *
40 ************************************************************/
41 /**
42 * Checks the page access rights (Code for access check mostly taken from alt_doc.php)
43 * as well as the table access rights of the user.
44 *
45 * @param string $table The table to check access for
46 * @param string $row Record array
47 * @return boolean Returns TRUE is the user has access, or FALSE if not
48 */
49 static public function checkAccess($table, $row) {
50 // 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...)
51 // First, resetting flags.
52 $hasAccess = 0;
53 $calcPRec = $row;
54 BackendUtility::fixVersioningPid($table, $calcPRec);
55 if (is_array($calcPRec)) {
56 if ($table == 'pages') {
57 // If pages:
58 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
59 $hasAccess = $CALC_PERMS & 2 ? 1 : 0;
60 } else {
61 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
62 // Fetching pid-record first.
63 $hasAccess = $CALC_PERMS & 16 ? 1 : 0;
64 }
65 // Check internals regarding access:
66 if ($hasAccess) {
67 $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
68 }
69 }
70 if (!$GLOBALS['BE_USER']->check('tables_modify', $table)) {
71 $hasAccess = 0;
72 }
73 return $hasAccess ? TRUE : FALSE;
74 }
75
76 /**
77 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
78 * Each part of the path will be limited to $titleLimit characters
79 * Deleted pages are filtered out.
80 *
81 * @param integer Page uid for which to create record path
82 * @param string $clause is additional where clauses, eg.
83 * @param integer Title limit
84 * @param integer Title limit of Full title (typ. set to 1000 or so)
85 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
86 */
87 static public function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0) {
88 $loopCheck = 100;
89 $output = ($fullOutput = '/');
90 while ($uid != 0 && $loopCheck > 0) {
91 $loopCheck--;
92 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,title,deleted,t3ver_oid,t3ver_wsid', 'pages', 'uid=' . intval($uid) . (strlen(trim($clause)) ? ' AND ' . $clause : ''));
93 if (is_resource($res)) {
94 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
95 $GLOBALS['TYPO3_DB']->sql_free_result($res);
96 BackendUtility::workspaceOL('pages', $row);
97 if (is_array($row)) {
98 BackendUtility::fixVersioningPid('pages', $row);
99 $uid = $row['pid'];
100 $output = '/' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output;
101 if ($row['deleted']) {
102 $output = '<span class="deletedPath">' . $output . '</span>';
103 }
104 if ($fullTitleLimit) {
105 $fullOutput = '/' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput;
106 }
107 } else {
108 break;
109 }
110 } else {
111 break;
112 }
113 }
114 if ($fullTitleLimit) {
115 return array($output, $fullOutput);
116 } else {
117 return $output;
118 }
119 }
120
121 /**
122 * Gets the name of the field with the information whether a record is deleted.
123 *
124 * @param string $tableName: Name of the table to get the deleted field for
125 * @return string Name of the field with the information whether a record is deleted
126 */
127 static public function getDeletedField($tableName) {
128 $TCA = self::getTableTCA($tableName);
129 if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
130 return $TCA['ctrl']['delete'];
131 }
132 }
133
134 /**
135 * Gets the TCA of the table used in the current context.
136 *
137 * @param string $tableName: Name of the table to get TCA for
138 * @return mixed TCA of the table used in the current context (array)
139 */
140 static public function getTableTCA($tableName) {
141 $TCA = FALSE;
142 if (isset($GLOBALS['TCA'][$tableName])) {
143 $TCA = $GLOBALS['TCA'][$tableName];
144 }
145 return $TCA;
146 }
147
148 /**
149 * Gets the current backend charset.
150 *
151 * @return string The current backend charset
152 */
153 static public function getCurrentCharset() {
154 return $GLOBALS['LANG']->csConvObj->parse_charset($GLOBALS['LANG']->charSet);
155 }
156
157 /**
158 * Determines whether the current charset is not UTF-8
159 *
160 * @return boolean Whether the current charset is not UTF-8
161 */
162 static public function isNotUtf8Charset() {
163 return self::getCurrentCharset() !== 'utf-8';
164 }
165
166 /**
167 * Gets an UTF-8 encoded string (only if the current charset is not UTF-8!).
168 *
169 * @param string $string: String to be converted to UTF-8 if required
170 * @return string UTF-8 encoded string
171 */
172 static public function getUtf8String($string) {
173 if (self::isNotUtf8Charset()) {
174 $string = $GLOBALS['LANG']->csConvObj->utf8_encode($string, self::getCurrentCharset());
175 }
176 return $string;
177 }
178
179 }
180
181
182 ?>