‪TYPO3CMS  10.4
LinkHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
30  const ‪DELETED = 'deleted';
31 
35  const ‪DISABLED = 'disabled';
36 
45  public function ‪checkLink($url, $softRefEntry, $reference)
46  {
47  $response = true;
48  $errorType = '';
49  ‪$errorParams = [];
50  $parts = explode(':', $url);
51  if (count($parts) !== 3) {
52  return $response;
53  }
54 
55  [, $tableName, $rowid] = $parts;
56  $rowid = (int)$rowid;
57 
58  $row = null;
59  $tsConfig = $reference->getTSConfig();
60  $reportHiddenRecords = (bool)$tsConfig['linkhandler.']['reportHiddenRecords'];
61 
62  // First check, if we find a non disabled record if the check
63  // for hidden records is enabled.
64  if ($reportHiddenRecords) {
65  $row = $this->‪getRecordRow($tableName, $rowid, 'disabled');
66  if ($row === false) {
67  $response = false;
68  $errorType = ‪self::DISABLED;
69  }
70  }
71 
72  // If no enabled record was found or we did not check that see
73  // if we can find a non deleted record.
74  if ($row === null) {
75  $row = $this->‪getRecordRow($tableName, $rowid, 'deleted');
76  if ($row === false) {
77  $response = false;
78  $errorType = ‪self::DELETED;
79  }
80  }
81 
82  // If we did not find a non deleted record, check if we find a
83  // deleted one.
84  if ($row === null) {
85  $row = $this->‪getRecordRow($tableName, $rowid, 'all');
86  if ($row === false) {
87  $response = false;
88  $errorType = '';
89  }
90  }
91 
92  if (!$response) {
93  ‪$errorParams['errorType'] = $errorType;
94  ‪$errorParams['tablename'] = $tableName;
95  ‪$errorParams['uid'] = $rowid;
97  }
98 
99  return $response;
100  }
101 
110  public function ‪fetchType($value, $type, $key)
111  {
112  if ($value['type'] === 'string' && strpos(strtolower($value['tokenValue']), 'record:') === 0) {
113  $type = 'linkhandler';
114  }
115  return $type;
116  }
117 
125  {
126  $errorType = ‪$errorParams['errorType'];
127  $tableName = ‪$errorParams['tablename'];
128  if (!empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['title'])) {
129  $title = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$tableName]['ctrl']['title']);
130  } else {
131  $title = $tableName;
132  }
133  switch ($errorType) {
134  case ‪self::DISABLED:
135  $response = $this->‪getTranslatedErrorMessage('list.report.rownotvisible', ‪$errorParams['uid'], $title);
136  break;
137  case ‪self::DELETED:
138  $response = $this->‪getTranslatedErrorMessage('list.report.rowdeleted', ‪$errorParams['uid'], $title);
139  break;
140  default:
141  $response = $this->‪getTranslatedErrorMessage('list.report.rownotexisting', ‪$errorParams['uid']);
142  }
143  return $response;
144  }
145 
154  protected function ‪getTranslatedErrorMessage($translationKey, $uid, $title = null)
155  {
156  $message = $this->‪getLanguageService()->‪getLL($translationKey);
157  $message = str_replace('###uid###', (string)(int)$uid, $message);
158  if (isset($title)) {
159  $message = str_replace('###title###', htmlspecialchars($title), $message);
160  }
161  return $message;
162  }
163 
178  protected function ‪getRecordRow($tableName, $uid, $filter = '')
179  {
180  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
181 
182  switch ($filter) {
183  case ‪self::DISABLED:
184  // All default restrictions for the QueryBuilder stay active
185  break;
186  case ‪self::DELETED:
187  $queryBuilder->getRestrictions()
188  ->removeAll()
189  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
190  break;
191  default:
192  $queryBuilder->getRestrictions()->removeAll();
193  }
194 
195  $row = $queryBuilder
196  ->select('*')
197  ->from($tableName)
198  ->where(
199  $queryBuilder->expr()->eq(
200  'uid',
201  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
202  )
203  )
204  ->execute()
205  ->fetch();
206 
207  return $row;
208  }
209 }
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype\$errorParams
‪array $errorParams
Definition: AbstractLinktype.php:29
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractLinktype.php:92
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype
Definition: AbstractLinktype.php:24
‪TYPO3\CMS\Linkvalidator\Linktype
Definition: AbstractLinktype.php:16
‪TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype\setErrorParams
‪setErrorParams($value)
Definition: AbstractLinktype.php:63
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:154
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46