TYPO3 CMS  TYPO3_7-6
LinkHandler.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 
19 
24 {
28  const DELETED = 'deleted';
29 
33  const DISABLED = 'disabled';
34 
43  public function checkLink($url, $softRefEntry, $reference)
44  {
45  $response = true;
46  $errorType = '';
47  $errorParams = [];
48  $parts = explode(':', $url);
49  if (count($parts) !== 3) {
50  return $response;
51  }
52 
53  list(, $tableName, $rowid) = $parts;
54  $rowid = (int)$rowid;
55 
56  $row = null;
57  $tsConfig = $reference->getTSConfig();
58  $reportHiddenRecords = (bool)$tsConfig['linkhandler.']['reportHiddenRecords'];
59 
60  // First check, if we find a non disabled record if the check
61  // for hidden records is enabled.
62  if ($reportHiddenRecords) {
63  $row = $this->getRecordRow($tableName, $rowid, 'disabled');
64  if ($row === null) {
65  $response = false;
66  $errorType = self::DISABLED;
67  }
68  }
69 
70  // If no enabled record was found or we did not check that see
71  // if we can find a non deleted record.
72  if ($row === null) {
73  $row = $this->getRecordRow($tableName, $rowid, 'deleted');
74  if ($row === null) {
75  $response = false;
76  $errorType = self::DELETED;
77  }
78  }
79 
80  // If we did not find a non deleted record, check if we find a
81  // deleted one.
82  if ($row === null) {
83  $row = $this->getRecordRow($tableName, $rowid, 'all');
84  if ($row === null) {
85  $response = false;
86  $errorType = '';
87  }
88  }
89 
90  if (!$response) {
91  $errorParams['errorType'] = $errorType;
92  $errorParams['tablename'] = $tableName;
93  $errorParams['uid'] = $rowid;
95  }
96 
97  return $response;
98  }
99 
108  public function fetchType($value, $type, $key)
109  {
110  if ($value['type'] === 'string' && StringUtility::beginsWith(strtolower($value['tokenValue']), 'record:')) {
111  $type = 'linkhandler';
112  }
113  return $type;
114  }
115 
122  public function getErrorMessage($errorParams)
123  {
124  $errorType = $errorParams['errorType'];
125  $tableName = $errorParams['tablename'];
126  if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['title'])) {
127  $title = $this->getLanguageService()->sL($GLOBALS['TCA'][$tableName]['ctrl']['title']);
128  } else {
129  $title = $tableName;
130  }
131  switch ($errorType) {
132  case self::DISABLED:
133  $response = $this->getTranslatedErrorMessage('list.report.rownotvisible', $errorParams['uid'], $title);
134  break;
135  case self::DELETED:
136  $response = $this->getTranslatedErrorMessage('list.report.rowdeleted', $errorParams['uid'], $title);
137  break;
138  default:
139  $response = $this->getTranslatedErrorMessage('list.report.rownotexisting', $errorParams['uid']);
140  }
141  return $response;
142  }
143 
152  protected function getTranslatedErrorMessage($translationKey, $uid, $title = null)
153  {
154  $message = $this->getLanguageService()->getLL($translationKey);
155  $message = str_replace('###uid###', (int)$uid, $message);
156  if (isset($title)) {
157  $message = str_replace('###title###', htmlspecialchars($title), $message);
158  }
159  return $message;
160  }
161 
176  protected function getRecordRow($tableName, $uid, $filter = '')
177  {
178  $whereStatement = 'uid = ' . (int)$uid;
179 
180  switch ($filter) {
181  case self::DISABLED:
182  $whereStatement .= BackendUtility::BEenableFields($tableName) . BackendUtility::deleteClause($tableName);
183  break;
184  case self::DELETED:
185  $whereStatement .= BackendUtility::deleteClause($tableName);
186  break;
187  }
188 
189  $row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
190  '*',
191  $tableName,
192  $whereStatement
193  );
194 
195  // Since exec_SELECTgetSingleRow can return NULL or FALSE we
196  // make sure we always return NULL if no row was found.
197  if ($row === false) {
198  $row = null;
199  }
200 
201  return $row;
202  }
203 }
static BEenableFields($table, $inv=false)
$uid
Definition: server.php:38
static beginsWith($haystack, $needle)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static deleteClause($table, $tableAlias='')