Added feature #16420: Add link validator module (Thanks to Patrick Gaumond)
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / lib / class.tx_linkvalidator_checkexternallinks.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 External Links plugin implementation.
26 *
27 * @author Dimitri K├Ânig <dk@cabag.ch>
28 * @author Michael Miousse <michael.miousse@infoglobe.ca>
29 */
30 class tx_linkvalidator_checkexternallinks extends tx_linkvalidator_checkbase {
31
32 var $url_reports = array();
33
34 /**
35 * Checks a given URL + /path/filename.ext for validity
36 *
37 * @param string $url: url to check
38 * @param array $softRefEntry: the softref entry which builds the context of that url
39 * @param object $reference: parent instance of tx_linkvalidator_processing
40 * @return string validation error message or succes code
41 */
42 function checkLink($url, $softRefEntry, $reference) {
43 if ($this->url_reports[$url]) {
44 return $this->url_reports[$url];
45 }
46 // remove possible anchor from the url
47 if (strrpos($url, '#') !== FALSE) {
48 $url = substr($url, 0, strrpos($url, '#'));
49 }
50
51 // try to fetch the content of the URL (just fetching of headers doesn't work!)
52 $report = array();
53 t3lib_div::getURL($url, 1, FALSE, $report);
54
55 $ret = 1;
56
57 // analyze the response
58 if ($report['error']) {
59 $ret = $GLOBALS['LANG']->getLL('list.report.noresponse');
60 }
61
62 $this->url_reports[$url] = $ret;
63 return $ret;
64 }
65
66 /**
67 * get the external type from the softRefParserObj result.
68 *
69 * @param array $value: reference properties
70 * @param string $type: current type
71 * @return string fetched type
72 */
73 function fetchType($value, $type) {
74 preg_match_all('/((?:http|https|ftp|ftps))(?::\/\/)(?:[^\s<>]+)/i', $value['tokenValue'], $urls, PREG_PATTERN_ORDER);
75
76 if (!empty($urls[0][0])) {
77 $type = "external";
78 }
79
80 return $type;
81 }
82
83 }
84
85
86 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/linkvalidator/lib/class.tx_linkvalidator_checkexternallinks.php']) {
87 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/linkvalidator/lib/class.tx_linkvalidator_checkexternallinks.php']);
88 }
89
90 ?>