[BUGFIX] Fix @param in phpdoc
[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-2011 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 * Helper class for the 'recycler' extension.
28 *
29 * @author Julian Kleinhans <typo3@kj187.de>
30 * @package TYPO3
31 * @subpackage tx_recycler
32 */
33 class RecyclerUtility {
34
35 /************************************************************
36 * USER ACCESS
37 *
38 *
39 ************************************************************/
40 /**
41 * Checks the page access rights (Code for access check mostly taken from alt_doc.php)
42 * as well as the table access rights of the user.
43 *
44 * @param string $table The table to check access for
45 * @param string $row Record array
46 * @return boolean Returns TRUE is the user has access, or FALSE if not
47 */
48 static public function checkAccess($table, $row) {
49 // 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...)
50 // First, resetting flags.
51 $hasAccess = 0;
52 $calcPRec = $row;
53 \TYPO3\CMS\Backend\Utility\BackendUtility::fixVersioningPid($table, $calcPRec);
54 if (is_array($calcPRec)) {
55 if ($table == 'pages') {
56 // If pages:
57 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
58 $hasAccess = $CALC_PERMS & 2 ? 1 : 0;
59 } else {
60 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $calcPRec['pid']));
61 // Fetching pid-record first.
62 $hasAccess = $CALC_PERMS & 16 ? 1 : 0;
63 }
64 // Check internals regarding access:
65 if ($hasAccess) {
66 $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
67 }
68 }
69 if (!$GLOBALS['BE_USER']->check('tables_modify', $table)) {
70 $hasAccess = 0;
71 }
72 return $hasAccess ? TRUE : FALSE;
73 }
74
75 /**
76 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
77 * Each part of the path will be limited to $titleLimit characters
78 * Deleted pages are filtered out.
79 *
80 * @param integer Page uid for which to create record path
81 * @param string $clause is additional where clauses, eg.
82 * @param integer Title limit
83 * @param integer Title limit of Full title (typ. set to 1000 or so)
84 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
85 */
86 static public function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0) {
87 $loopCheck = 100;
88 $output = ($fullOutput = '/');
89 while ($uid != 0 && $loopCheck > 0) {
90 $loopCheck--;
91 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,title,deleted,t3ver_oid,t3ver_wsid', 'pages', 'uid=' . intval($uid) . (strlen(trim($clause)) ? ' AND ' . $clause : ''));
92 if (is_resource($res)) {
93 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
94 $GLOBALS['TYPO3_DB']->sql_free_result($res);
95 \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL('pages', $row);
96 if (is_array($row)) {
97 \TYPO3\CMS\Backend\Utility\BackendUtility::fixVersioningPid('pages', $row);
98 $uid = $row['pid'];
99 $output = '/' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output;
100 if ($row['deleted']) {
101 $output = '<span class="deletedPath">' . $output . '</span>';
102 }
103 if ($fullTitleLimit) {
104 $fullOutput = '/' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput;
105 }
106 } else {
107 break;
108 }
109 } else {
110 break;
111 }
112 }
113 if ($fullTitleLimit) {
114 return array($output, $fullOutput);
115 } else {
116 return $output;
117 }
118 }
119
120 /**
121 * Gets the name of the field with the information whether a record is deleted.
122 *
123 * @param string $tableName: Name of the table to get the deleted field for
124 * @return string Name of the field with the information whether a record is deleted
125 */
126 static public function getDeletedField($tableName) {
127 $TCA = self::getTableTCA($tableName);
128 if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
129 return $TCA['ctrl']['delete'];
130 }
131 }
132
133 /**
134 * Gets the TCA of the table used in the current context.
135 *
136 * @param string $tableName: Name of the table to get TCA for
137 * @return mixed TCA of the table used in the current context (array)
138 */
139 static public function getTableTCA($tableName) {
140 $TCA = FALSE;
141 if (isset($GLOBALS['TCA'][$tableName])) {
142 $TCA = $GLOBALS['TCA'][$tableName];
143 }
144 return $TCA;
145 }
146
147 /**
148 * Gets the current backend charset.
149 *
150 * @return string The current backend charset
151 */
152 static public function getCurrentCharset() {
153 return $GLOBALS['LANG']->csConvObj->parse_charset($GLOBALS['LANG']->charSet);
154 }
155
156 /**
157 * Determines whether the current charset is not UTF-8
158 *
159 * @return boolean Whether the current charset is not UTF-8
160 */
161 static public function isNotUtf8Charset() {
162 return self::getCurrentCharset() !== 'utf-8';
163 }
164
165 /**
166 * Gets an UTF-8 encoded string (only if the current charset is not UTF-8!).
167 *
168 * @param string $string: String to be converted to UTF-8 if required
169 * @return string UTF-8 encoded string
170 */
171 static public function getUtf8String($string) {
172 if (self::isNotUtf8Charset()) {
173 $string = $GLOBALS['LANG']->csConvObj->utf8_encode($string, self::getCurrentCharset());
174 }
175 return $string;
176 }
177
178 }
179
180
181 ?>