TYPO3 CMS  TYPO3_7-6
RecyclerUtility.php
Go to the documentation of this file.
1 <?php
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  $calculatedPermissions = $backendUser->calcPerms($calcPRec);
51  $hasAccess = (bool)($calculatedPermissions & Permission::PAGE_EDIT);
52  } else {
53  $calculatedPermissions = $backendUser->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
54  // Fetching pid-record first.
55  $hasAccess = (bool)($calculatedPermissions & Permission::CONTENT_EDIT);
56  }
57  // Check internals regarding access:
58  if ($hasAccess) {
59  $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
60  }
61  }
62  if (!$backendUser->check('tables_modify', $table)) {
63  $hasAccess = false;
64  }
65  return $hasAccess;
66  }
67 
79  public static function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0)
80  {
81  $uid = (int)$uid;
82  $output = ($fullOutput = '/');
83  if ($uid === 0) {
84  return $output;
85  }
86  $databaseConnection = static::getDatabaseConnection();
87  $clause = trim($clause) !== '' ? ' AND ' . $clause : '';
88  $loopCheck = 100;
89  while ($loopCheck > 0) {
90  $loopCheck--;
91  $res = $databaseConnection->exec_SELECTquery('uid,pid,title,deleted,t3ver_oid,t3ver_wsid', 'pages', 'uid=' . $uid . $clause);
92  if ($res !== false) {
93  $row = $databaseConnection->sql_fetch_assoc($res);
94  $databaseConnection->sql_free_result($res);
95  BackendUtility::workspaceOL('pages', $row);
96  if (is_array($row)) {
97  BackendUtility::fixVersioningPid('pages', $row);
98  $uid = (int)$row['pid'];
99  $output = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output;
100  if ($row['deleted']) {
101  $output = '<span class="text-danger">' . $output . '</span>';
102  }
103  if ($fullTitleLimit) {
104  $fullOutput = '/' . htmlspecialchars(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 [$output, $fullOutput];
115  } else {
116  return $output;
117  }
118  }
119 
126  public static function getDeletedField($tableName)
127  {
128  $TCA = self::getTableTCA($tableName);
129  if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
130  return $TCA['ctrl']['delete'];
131  }
132  return '';
133  }
134 
142  public static function getPidOfUid($uid, $table)
143  {
144  $db = static::getDatabaseConnection();
145  $res = $db->exec_SELECTquery('pid', $table, 'uid=' . (int)$uid);
146  if ($res !== false) {
147  $record = $db->sql_fetch_assoc($res);
148  return $record['pid'];
149  }
150  return 0;
151  }
152 
159  public static function getTableTCA($tableName)
160  {
161  $TCA = false;
162  if (isset($GLOBALS['TCA'][$tableName])) {
163  $TCA = $GLOBALS['TCA'][$tableName];
164  }
165  return $TCA;
166  }
167 
173  public static function getCurrentCharset()
174  {
175  $lang = static::getLanguageService();
176  return $lang->csConvObj->parse_charset($lang->charSet);
177  }
178 
184  public static function isNotUtf8Charset()
185  {
186  return self::getCurrentCharset() !== 'utf-8';
187  }
188 
195  public static function getUtf8String($string)
196  {
197  if (self::isNotUtf8Charset()) {
198  $string = static::getLanguageService()->csConvObj->utf8_encode($string, self::getCurrentCharset());
199  }
200  return $string;
201  }
202 
208  protected static function getDatabaseConnection()
209  {
210  return $GLOBALS['TYPO3_DB'];
211  }
212 
218  protected static function getBackendUser()
219  {
220  return $GLOBALS['BE_USER'];
221  }
222 
228  protected static function getLanguageService()
229  {
230  return $GLOBALS['LANG'];
231  }
232 
236  public static function getModifyableTables()
237  {
238  if ((bool)$GLOBALS['BE_USER']->user['admin']) {
239  $tables = array_keys($GLOBALS['TCA']);
240  } else {
241  $tables = explode(',', $GLOBALS['BE_USER']->groupData['tables_modify']);
242  }
243  return $tables;
244  }
245 }
static getRecordPath($uid, $clause='', $titleLimit=1000, $fullTitleLimit=0)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
static fixVersioningPid($table, &$rr, $ignoreWorkspaceMatch=false)
static fixed_lgd_cs($string, $chars, $appendString='...')
$uid
Definition: server.php:38
$TCA['tx_blogexample_domain_model_blog']
Definition: Blog.php:4
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']