Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / classes / helper / class.tx_recycler_helper.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Julian Kleinhans <typo3@kj187.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Helper class for the 'recycler' extension.
26 *
27 * @author Julian Kleinhans <typo3@kj187.de>
28 * @package TYPO3
29 * @subpackage tx_recycler
30 * @version $Id$
31 */
32 class tx_recycler_helper {
33
34 /************************************************************
35 * USER ACCESS
36 *
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 $cmd: The command that sould be performed ('new' or 'edit')
45 * @param string $table: The table to check access for
46 * @param string $theUid: The record uid of the table
47 * @return boolean Returns true is the user has access, or false if not
48 */
49 public static 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 $deniedAccessReason = '';
54
55 $calcPRec = $row;
56 t3lib_BEfunc::fixVersioningPid($table,$calcPRec);
57 if (is_array($calcPRec)) {
58 if ($table=='pages') { // If pages:
59 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
60 $hasAccess = $CALC_PERMS & 2 ? 1 : 0;
61 } else {
62 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$calcPRec['pid'])); // 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
71
72 if (!$GLOBALS['BE_USER']->check('tables_modify', $table)) {
73 $hasAccess = 0;
74 }
75
76 if (!$hasAccess) {
77 $deniedAccessReason = $GLOBALS['BE_USER']->errorMsg;
78 if ($deniedAccessReason) {
79 //fb($deniedAccessReason);
80 }
81 }
82
83 return $hasAccess ? true : false;
84 }
85
86 /**
87 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
88 * Each part of the path will be limited to $titleLimit characters
89 * Deleted pages are filtered out.
90 *
91 * @param integer Page uid for which to create record path
92 * @param string $clause is additional where clauses, eg. "
93 * @param integer Title limit
94 * @param integer Title limit of Full title (typ. set to 1000 or so)
95 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
96 */
97 public static function getRecordPath($uid, $clause='', $titleLimit=1000, $fullTitleLimit = 0) {
98 $loopCheck = 100;
99 $output = $fullOutput = '/';
100
101 while ($uid != 0 && $loopCheck > 0) {
102 $loopCheck--;
103 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
104 'uid,pid,title,deleted,t3ver_oid,t3ver_wsid,t3ver_swapmode',
105 'pages',
106 'uid=' . intval($uid) . (strlen(trim($clause)) ? ' AND ' . $clause : '')
107 );
108
109 if (is_resource($res)) {
110 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
111 $GLOBALS['TYPO3_DB']->sql_free_result($res);
112
113 t3lib_BEfunc::workspaceOL('pages', $row);
114 if (is_array($row)) {
115 t3lib_BEfunc::fixVersioningPid('pages', $row);
116
117 if ($row['_ORIG_pid'] && $row['t3ver_swapmode'] > 0) { // Branch points
118 $output = ' [#VEP#]' . $output; // Adding visual token - Versioning Entry Point - that tells that THIS position was where the versionized branch got connected to the main tree. I will have to find a better name or something...
119 }
120 $uid = $row['pid'];
121 $output = '/' . t3lib_div::fixed_lgd_cs(strip_tags($row['title']), $titleLimit) . $output;
122
123 if ($row['deleted']) {
124 $output = '<span class="deletedPath">' . $output . '</span>';
125 }
126
127 if ($fullTitleLimit) $fullOutput = '/' . t3lib_div::fixed_lgd_cs(strip_tags($row['title']), $fullTitleLimit) . $fullOutput;
128 } else {
129 break;
130 }
131 } else {
132 break;
133 }
134 }
135
136 if ($fullTitleLimit) {
137 return array($output, $fullOutput);
138 } else {
139 return $output;
140 }
141 }
142
143 /**
144 * Gets the name of the field with the information whether a record is deleted.
145 *
146 * @param string $tableName: Name of the table to get the deleted field for
147 * @return string Name of the field with the information whether a record is deleted
148 */
149 public static function getDeletedField($tableName) {
150 $TCA = self::getTableTCA($tableName);
151 if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
152 return $TCA['ctrl']['delete'];
153 }
154 }
155
156 /**
157 * Gets the TCA of the table used in the current context.
158 *
159 * @param string $tableName: Name of the table to get TCA for
160 * @return mixed TCA of the table used in the current context (array)
161 * or false (boolean) if something went wrong
162 */
163 public static function getTableTCA($tableName) {
164 $TCA = false;
165 if (isset($GLOBALS['TCA'][$tableName])) {
166 $TCA = $GLOBALS['TCA'][$tableName];
167 }
168 return $TCA;
169 }
170
171 /**
172 * Gets the current backend charset.
173 *
174 * @return string The current backend charset
175 */
176 public static function getCurrentCharset() {
177 return $GLOBALS['LANG']->csConvObj->parse_charset($GLOBALS['LANG']->charSet);
178 }
179
180 /**
181 * Determines whether the current charset is not UTF-8
182 *
183 * @return boolean Whether the current charset is not UTF-8
184 */
185 public static function isNotUtf8Charset() {
186 return (self::getCurrentCharset() !== 'utf-8');
187 }
188
189 /**
190 * Gets an UTF-8 encoded string (only if the current charset is not UTF-8!).
191 *
192 * @param string $string: String to be converted to UTF-8 if required
193 * @return string UTF-8 encoded string
194 */
195 public static function getUtf8String($string) {
196 if (self::isNotUtf8Charset()) {
197 $string = $GLOBALS['LANG']->csConvObj->utf8_encode(
198 $string,
199 self::getCurrentCharset()
200 );
201 }
202 return $string;
203 }
204 }
205
206
207 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/helper/class.tx_recycler_helper.php'])) {
208 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/helper/class.tx_recycler_helper.php']);
209 }
210
211 ?>