TYPO3  7.6
RecyclerUtility.php
Go to the documentation of this file.
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 
20 
25 {
26  /************************************************************
27  * USER ACCESS
28  *
29  *
30  ************************************************************/
39  public static function checkAccess($table, $row)
40  {
41  $backendUser = static::getBackendUser();
42 
43  // 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...)
44  // First, resetting flags.
45  $hasAccess = false;
46  $calcPRec = $row;
47  BackendUtility::fixVersioningPid($table, $calcPRec);
48  if (is_array($calcPRec)) {
49  if ($table === 'pages') {
50  // If 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 
80  public static function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0)
81  {
82  $uid = (int)$uid;
83  $output = ($fullOutput = '/');
84  if ($uid === 0) {
85  return $output;
86  }
87  $databaseConnection = static::getDatabaseConnection();
88  $clause = trim($clause) !== '' ? ' AND ' . $clause : '';
89  $loopCheck = 100;
90  while ($loopCheck > 0) {
91  $loopCheck--;
92  $res = $databaseConnection->exec_SELECTquery('uid,pid,title,deleted,t3ver_oid,t3ver_wsid', 'pages', 'uid=' . $uid . $clause);
93  if ($res !== false) {
94  $row = $databaseConnection->sql_fetch_assoc($res);
95  $databaseConnection->sql_free_result($res);
96  BackendUtility::workspaceOL('pages', $row);
97  if (is_array($row)) {
98  BackendUtility::fixVersioningPid('pages', $row);
99  $uid = (int)$row['pid'];
100  $output = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output;
101  if ($row['deleted']) {
102  $output = '<span class="text-danger">' . $output . '</span>';
103  }
104  if ($fullTitleLimit) {
105  $fullOutput = '/' . htmlspecialchars(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 
127  public static function getDeletedField($tableName)
128  {
129  $TCA = self::getTableTCA($tableName);
130  if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
131  return $TCA['ctrl']['delete'];
132  }
133  return '';
134  }
135 
142  public static function getTableTCA($tableName)
143  {
144  $TCA = false;
145  if (isset($GLOBALS['TCA'][$tableName])) {
146  $TCA = $GLOBALS['TCA'][$tableName];
147  }
148  return $TCA;
149  }
150 
156  public static function getCurrentCharset()
157  {
158  $lang = static::getLanguageService();
159  return $lang->csConvObj->parse_charset($lang->charSet);
160  }
161 
167  public static function isNotUtf8Charset()
168  {
169  return self::getCurrentCharset() !== 'utf-8';
170  }
171 
178  public static function getUtf8String($string)
179  {
180  if (self::isNotUtf8Charset()) {
181  $string = static::getLanguageService()->csConvObj->utf8_encode($string, self::getCurrentCharset());
182  }
183  return $string;
184  }
185 
191  protected static function getDatabaseConnection()
192  {
193  return $GLOBALS['TYPO3_DB'];
194  }
195 
201  protected static function getBackendUser()
202  {
203  return $GLOBALS['BE_USER'];
204  }
205 
211  protected static function getLanguageService()
212  {
213  return $GLOBALS['LANG'];
214  }
215 
219  public static function getModifyableTables()
220  {
221  if ((bool)$GLOBALS['BE_USER']->user['admin']) {
222  $tables = array_keys($GLOBALS['TCA']);
223  } else {
224  $tables = explode(',', $GLOBALS['BE_USER']->groupData['tables_modify']);
225  }
226  return $tables;
227  }
228 }