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