‪TYPO3CMS  9.5
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 
20 
25 {
29  const ‪DELETED = 'deleted';
30 
34  const ‪DISABLED = 'disabled';
35 
44  public function ‪checkLink($url, $softRefEntry, $reference)
45  {
46  $response = true;
47  $errorType = '';
48  ‪$errorParams = [];
49  $parts = explode(':', $url);
50  if (count($parts) !== 3) {
51  return $response;
52  }
53 
54  list(, $tableName, $rowid) = $parts;
55  $rowid = (int)$rowid;
56 
57  $row = null;
58  $tsConfig = $reference->getTSConfig();
59  $reportHiddenRecords = (bool)$tsConfig['linkhandler.']['reportHiddenRecords'];
60 
61  // First check, if we find a non disabled record if the check
62  // for hidden records is enabled.
63  if ($reportHiddenRecords) {
64  $row = $this->‪getRecordRow($tableName, $rowid, 'disabled');
65  if ($row === false) {
66  $response = false;
67  $errorType = ‪self::DISABLED;
68  }
69  }
70 
71  // If no enabled record was found or we did not check that see
72  // if we can find a non deleted record.
73  if ($row === null) {
74  $row = $this->‪getRecordRow($tableName, $rowid, 'deleted');
75  if ($row === false) {
76  $response = false;
77  $errorType = ‪self::DELETED;
78  }
79  }
80 
81  // If we did not find a non deleted record, check if we find a
82  // deleted one.
83  if ($row === null) {
84  $row = $this->‪getRecordRow($tableName, $rowid, 'all');
85  if ($row === false) {
86  $response = false;
87  $errorType = '';
88  }
89  }
90 
91  if (!$response) {
92  ‪$errorParams['errorType'] = $errorType;
93  ‪$errorParams['tablename'] = $tableName;
94  ‪$errorParams['uid'] = $rowid;
96  }
97 
98  return $response;
99  }
100 
109  public function ‪fetchType($value, $type, $key)
110  {
111  if ($value['type'] === 'string' && strpos(strtolower($value['tokenValue']), 'record:') === 0) {
112  $type = 'linkhandler';
113  }
114  return $type;
115  }
116 
124  {
125  $errorType = ‪$errorParams['errorType'];
126  $tableName = ‪$errorParams['tablename'];
127  if (!empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['title'])) {
128  $title = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$tableName]['ctrl']['title']);
129  } else {
130  $title = $tableName;
131  }
132  switch ($errorType) {
133  case ‪self::DISABLED:
134  $response = $this->‪getTranslatedErrorMessage('list.report.rownotvisible', ‪$errorParams['uid'], $title);
135  break;
136  case ‪self::DELETED:
137  $response = $this->‪getTranslatedErrorMessage('list.report.rowdeleted', ‪$errorParams['uid'], $title);
138  break;
139  default:
140  $response = $this->‪getTranslatedErrorMessage('list.report.rownotexisting', ‪$errorParams['uid']);
141  }
142  return $response;
143  }
144 
153  protected function ‪getTranslatedErrorMessage($translationKey, $uid, $title = null)
154  {
155  $message = $this->‪getLanguageService()->‪getLL($translationKey);
156  $message = str_replace('###uid###', (int)$uid, $message);
157  if (isset($title)) {
158  $message = str_replace('###title###', htmlspecialchars($title), $message);
159  }
160  return $message;
161  }
162 
177  protected function ‪getRecordRow($tableName, $uid, $filter = '')
178  {
179  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
180 
181  switch ($filter) {
182  case ‪self::DISABLED:
183  // All default restrictions for the QueryBuilder stay active
184  break;
185  case ‪self::DELETED:
186  $queryBuilder->getRestrictions()
187  ->removeAll()
188  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
189  break;
190  default:
191  $queryBuilder->getRestrictions()->removeAll();
192  }
193 
194  $row = $queryBuilder
195  ->select('*')
196  ->from($tableName)
197  ->where(
198  $queryBuilder->expr()->eq(
199  'uid',
200  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
201  )
202  )
203  ->execute()
204  ->fetch();
205 
206  return $row;
207  }
208 }
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype\$errorParams
‪array $errorParams
Definition: AbstractLinktype.php:27
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractLinktype.php:79
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype
Definition: AbstractLinktype.php:22
‪TYPO3\CMS\Linkvalidator\Linktype
Definition: AbstractLinktype.php:2
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype\setErrorParams
‪setErrorParams($value)
Definition: AbstractLinktype.php:50
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:118
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45