[BUGFIX] Do not use invalid TSConfig in linkvalidator
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Linktype / LinkHandler.php
1 <?php
2 namespace TYPO3\CMS\Linkvalidator\Linktype;
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
17 /**
18 * This class provides Check Link Handler plugin implementation
19 *
20 * @author Dimitri K├Ânig <dk@cabag.ch>
21 * @author Michael Miousse <michael.miousse@infoglobe.ca>
22 */
23 class LinkHandler extends \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype {
24
25 /**
26 * @var string
27 */
28 const DELETED = 'deleted';
29
30 /**
31 * Checks a given URL for validity
32 *
33 * @param string $url Url to check
34 * @param array $softRefEntry The soft reference entry which builds the context of that url
35 * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance
36 * @return boolean TRUE on success or FALSE on error
37 */
38 public function checkLink($url, $softRefEntry, $reference) {
39 $response = TRUE;
40 $errorParams = array();
41 $parts = explode(':', $url);
42 if (count($parts) == 3) {
43 $tableName = htmlspecialchars($parts[1]);
44 $rowid = (int)$parts[2];
45 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $tableName, 'uid = ' . (int)$rowid);
46 if ($row) {
47 if ($row['deleted'] == '1') {
48 $errorParams['errorType'] = self::DELETED;
49 $errorParams['tablename'] = $tableName;
50 $errorParams['uid'] = $rowid;
51 $response = FALSE;
52 }
53 } else {
54 $errorParams['tablename'] = $tableName;
55 $errorParams['uid'] = $rowid;
56 $response = FALSE;
57 }
58 }
59
60 if (!$response) {
61 $this->setErrorParams($errorParams);
62 }
63 return $response;
64 }
65
66 /**
67 * Type fetching method, based on the type that softRefParserObj returns
68 *
69 * @param array $value Reference properties
70 * @param string $type Current type
71 * @param string $key Validator hook name
72 * @return string fetched type
73 */
74 public function fetchType($value, $type, $key) {
75 if ($type == 'string' && strtolower(substr($value['tokenValue'], 0, 7)) == 'record:') {
76 $type = 'linkhandler';
77 }
78 return $type;
79 }
80
81 /**
82 * Generate the localized error message from the error params saved from the parsing
83 *
84 * @param array $errorParams All parameters needed for the rendering of the error message
85 * @return string Validation error message
86 */
87 public function getErrorMessage($errorParams) {
88 $errorType = $errorParams['errorType'];
89 $tableName = $errorParams['tablename'];
90 if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['title'])) {
91 $title = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'], TRUE);
92 } else {
93 $title = $tableName;
94 }
95 switch ($errorType) {
96 case self::DELETED:
97 $response = str_replace(
98 array(
99 '###title###',
100 '###uid###'
101 ),
102 array(
103 $title,
104 $errorParams['uid']
105 ),
106 $GLOBALS['LANG']->getLL('list.report.rowdeleted')
107 );
108 break;
109 default:
110 $response = str_replace('###uid###', $errorParams['uid'], $GLOBALS['LANG']->getLL('list.report.rownotexisting'));
111 }
112 return $response;
113 }
114 }