ea52c5294bbbd993b5df8cbda2377d1169aff3e8
[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 * TSconfig of the module tx_linkhandler
32 *
33 * @var array
34 */
35 protected $tsconfig;
36
37 /**
38 * Get TSconfig when loading the class
39 */
40 public function __construct() {
41 $this->tsconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig(1, 'mod.tx_linkhandler');
42 }
43
44 /**
45 * Checks a given URL for validity
46 *
47 * @param string $url Url to check
48 * @param array $softRefEntry The soft reference entry which builds the context of that url
49 * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance
50 * @return boolean TRUE on success or FALSE on error
51 */
52 public function checkLink($url, $softRefEntry, $reference) {
53 $response = TRUE;
54 $errorParams = array();
55 $parts = explode(':', $url);
56 if (count($parts) == 3) {
57 $tableName = htmlspecialchars($parts[1]);
58 $rowid = (int)$parts[2];
59 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $tableName, 'uid = ' . (int)$rowid);
60 if ($row) {
61 if ($row['deleted'] == '1') {
62 $errorParams['errorType'] = self::DELETED;
63 $errorParams['tablename'] = $tableName;
64 $errorParams['uid'] = $rowid;
65 $response = FALSE;
66 }
67 } else {
68 $errorParams['tablename'] = $tableName;
69 $errorParams['uid'] = $rowid;
70 $response = FALSE;
71 }
72 }
73
74 if (!$response) {
75 $this->setErrorParams($errorParams);
76 }
77 return $response;
78 }
79
80 /**
81 * Type fetching method, based on the type that softRefParserObj returns
82 *
83 * @param array $value Reference properties
84 * @param string $type Current type
85 * @param string $key Validator hook name
86 * @return string fetched type
87 */
88 public function fetchType($value, $type, $key) {
89 if ($type == 'string' && strtolower(substr($value['tokenValue'], 0, 7)) == 'record:') {
90 $type = 'linkhandler';
91 }
92 return $type;
93 }
94
95 /**
96 * Generate the localized error message from the error params saved from the parsing
97 *
98 * @param array $errorParams All parameters needed for the rendering of the error message
99 * @return string Validation error message
100 */
101 public function getErrorMessage($errorParams) {
102 $errorType = $errorParams['errorType'];
103 $tableName = $errorParams['tablename'];
104 $title = $GLOBALS['LANG']->getLL('list.report.rowdeleted.default.title');
105 if ($this->tsconfig['properties'][$tableName . '.']) {
106 $title = $this->tsconfig['properties'][$tableName . '.']['label'];
107 }
108 switch ($errorType) {
109 case self::DELETED:
110 $response = str_replace(
111 array(
112 '###title###',
113 '###uid###'
114 ),
115 array(
116 $title,
117 $errorParams['uid']
118 ),
119 $GLOBALS['LANG']->getLL('list.report.rowdeleted')
120 );
121 break;
122 default:
123 $response = str_replace('###uid###', $errorParams['uid'], $GLOBALS['LANG']->getLL('list.report.rownotexisting'));
124 }
125 return $response;
126 }
127 }