67b5bc18fa12c5f768acf42f5e01dcdf8c501d3b
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Linktype / LinkHandler.php
1 <?php
2 namespace TYPO3\CMS\Linkvalidator\Linktype;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2005 - 2013 Jochen Rieger (j.rieger@connecta.ag)
8 * (c) 2010 - 2013 Michael Miousse (michael.miousse@infoglobe.ca)
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * This class provides Check Link Handler plugin implementation
29 *
30 * @author Dimitri K├Ânig <dk@cabag.ch>
31 * @author Michael Miousse <michael.miousse@infoglobe.ca>
32 */
33 class LinkHandler extends \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype {
34
35 const DELETED = 'deleted';
36 /**
37 * TSconfig of the module tx_linkhandler
38 *
39 * @var array
40 */
41 protected $tsconfig;
42
43 /**
44 * Get TSconfig when loading the class
45 *
46 * @todo Define visibility
47 */
48 public function __construct() {
49 $this->tsconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig(1, 'mod.tx_linkhandler');
50 }
51
52 /**
53 * Checks a given URL for validity
54 *
55 * @param string $url Url to check
56 * @param array $softRefEntry The soft reference entry which builds the context of that url
57 * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance
58 * @return boolean TRUE on success or FALSE on error
59 */
60 public function checkLink($url, $softRefEntry, $reference) {
61 $response = TRUE;
62 $errorParams = array();
63 $parts = explode(':', $url);
64 if (count($parts) == 3) {
65 $tableName = htmlspecialchars($parts[1]);
66 $rowid = intval($parts[2]);
67 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $tableName, 'uid = ' . intval($rowid));
68 if ($row) {
69 if ($row['deleted'] == '1') {
70 $errorParams['errorType'] = self::DELETED;
71 $errorParams['tablename'] = $tableName;
72 $errorParams['uid'] = $rowid;
73 $response = FALSE;
74 }
75 } else {
76 $errorParams['tablename'] = $tableName;
77 $errorParams['uid'] = $rowid;
78 $response = FALSE;
79 }
80 }
81
82 if (!$response) {
83 $this->setErrorParams($errorParams);
84 }
85 return $response;
86 }
87
88 /**
89 * Type fetching method, based on the type that softRefParserObj returns
90 *
91 * @param array $value Reference properties
92 * @param string $type Current type
93 * @param string $key Validator hook name
94 * @return string fetched type
95 */
96 public function fetchType($value, $type, $key) {
97 if ($type == 'string' && strtolower(substr($value['tokenValue'], 0, 7)) == 'record:') {
98 $type = 'linkhandler';
99 }
100 return $type;
101 }
102
103 /**
104 * Generate the localized error message from the error params saved from the parsing
105 *
106 * @param array $errorParams All parameters needed for the rendering of the error message
107 * @return string Validation error message
108 */
109 public function getErrorMessage($errorParams) {
110 $errorType = $errorParams['errorType'];
111 $tableName = $errorParams['tablename'];
112 $title = $GLOBALS['LANG']->getLL('list.report.rowdeleted.default.title');
113 if ($this->tsconfig['properties'][$tableName . '.']) {
114 $title = $this->tsconfig['properties'][$tableName . '.']['label'];
115 }
116 switch ($errorType) {
117 case self::DELETED:
118 $response = $GLOBALS['LANG']->getLL('list.report.rowdeleted');
119 $response = str_replace('###title###', $title, $response);
120 $response = str_replace('###uid###', $errorParams['uid'], $response);
121 break;
122 default:
123 $response = $GLOBALS['LANG']->getLL('list.report.rownotexisting');
124 $response = str_replace('###uid###', $errorParams['uid'], $response);
125 break;
126 }
127 return $response;
128 }
129 }
130 ?>