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