Added feature #16420: Add link validator module (Thanks to Patrick Gaumond)
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / lib / class.tx_linkvalidator_checklinkhandlerlinks.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005 - 2010 Michael Miousse (michael.miousse@infoglobe.ca)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * This class provides Check Link Handler plugin implementation.
26 *
27 * @author Dimitri K├Ânig <dk@cabag.ch>
28 * @author Michael Miousse <michael.miousse@infoglobe.ca>
29 */
30 class tx_linkvalidator_checklinkhandlerlinks extends tx_linkvalidator_checkbase {
31 public $tsconfig;
32
33 /**
34 * Get TsConfig on loading of the class
35 */
36 function __construct() {
37 $this->tsconfig = t3lib_BEfunc::getModTSconfig(1, 'mod.tx_linkhandler');
38 }
39
40 /**
41 * Checks a given URL + /path/filename.ext for validity
42 *
43 * @param string $url: url to check
44 * @param array $softRefEntry: the softref entry which builds the context of that url
45 * @param object $reference: parent instance of tx_linkvalidator_processing
46 * @return string validation error message or succes code
47 */
48 function checkLink($url, $softRefEntry, $reference) {
49 $parts = explode(":", $url);
50 if (count($parts) == 3) {
51 $tablename = htmlspecialchars($parts[1]);
52 $rowid = intval($parts[2]);
53 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
54 '*',
55 $tablename,
56 'uid = ' . intval($rowid)
57 );
58 $title = 'Link';
59 if ($this->tsconfig['properties'][$tablename . '.']) {
60 $title = $this->tsconfig['properties'][$tablename . '.']['label'];
61 }
62 if ($rows[0]) {
63 if ($rows[0]['deleted'] == '1') {
64 $response = $GLOBALS['LANG']->getLL('list.report.rowdeleted');
65 $response = str_replace('###title###', $title, $response);
66 return $response;
67 }
68 } else {
69 $response = $GLOBALS['LANG']->getLL('list.report.rownotexisting');
70 $response = str_replace('###title###', $title, $response);
71 return $response;
72 }
73 }
74
75 return 1;
76 }
77
78 /**
79 * type fetching method, based on the type that softRefParserObj returns.
80 *
81 * @param array $value: reference properties
82 * @param string $type: current type
83 * @return string fetched type
84 */
85 function fetchType($value, $type) {
86 if ($type == 'string' && strtolower(substr($value['tokenValue'], 0, 7)) == 'record:') {
87 $type = 'linkhandler';
88 }
89 return $type;
90 }
91 }
92
93
94 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/linkvalidator/lib/class.tx_linkvalidator_checklinkhandlerlinks.php']) {
95 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/linkvalidator/lib/class.tx_linkvalidator_checklinkhandlerlinks.php']);
96 }
97
98 ?>