Feature #13680 » linkval-user-agent-cleanup-external-url.diff
classes/linktype/class.tx_linkvalidator_linktype_external.php (Arbeitskopie) | ||
---|---|---|
protected $urlErrorParams = array();
|
||
/**
|
||
* List of headers to be used for metching an URL for the current processing
|
||
*
|
||
* @var array
|
||
*/
|
||
protected $additionalHeaders = array();
|
||
/**
|
||
* Checks a given URL + /path/filename.ext for validity
|
||
*
|
||
* @param string $url: url to check
|
||
... | ... | |
*/
|
||
public function checkLink($url, $softRefEntry, $reference) {
|
||
$errorParams = array();
|
||
$report = array();
|
||
$additionalHeaders['User-Agent'] = 'User-Agent: Mozilla/5.0 TYPO3-linkvalidator';
|
||
if (isset($this->urlReports[$url])) {
|
||
if(!$this->urlReports[$url]) {
|
||
if(is_array($this->urlErrorParams[$url])) {
|
||
... | ... | |
$url = substr($url, 0, strrpos($url, '#'));
|
||
}
|
||
// try to fetch the content of the URL (headers only)
|
||
$report = array();
|
||
// try to fetch the content of the URL
|
||
$content = t3lib_div::getURL($url, 1, $additionalHeaders, $report);
|
||
// try fetching the content of the URL (just fetching the headers does not work correctly)
|
||
$content = '';
|
||
$content = t3lib_div::getURL($url, 1, FALSE, $report);
|
||
$tries = 0;
|
||
$lastUrl = $url;
|
||
while (($report['http_code'] == 301 || $report['http_code'] == 302
|
||
|| $report['http_code'] == 303 || $report['http_code'] == 307)
|
||
&& ($tries < 5)) {
|
||
$isCodeRedirect = preg_match('/Location: (.*)/', $content, $location);
|
||
if (isset($location[1])) {
|
||
$content = t3lib_div::getURL($location[1], 2, FALSE, $report);
|
||
|| $report['http_code'] == 303 || $report['http_code'] == 307)
|
||
&& ($tries < 5)) {
|
||
// split header into lines and find Location:
|
||
$responseHeaders = t3lib_div::trimExplode(chr(10), $content, TRUE);
|
||
foreach ($responseHeaders as $line) {
|
||
// construct new URL
|
||
if ((preg_match('/Location: ([^\r\n]+)/', $line, $location))) {
|
||
if (isset($location[1])) {
|
||
$parsedUrl = parse_url($location[1]);
|
||
if (!isset($parsedUrl['host'])) {
|
||
// the location did not contain a complete URI, build it!
|
||
$parsedUrl = parse_url($lastUrl);
|
||
$newUrl = $parsedUrl['scheme'] . '://' . (isset($parsedUrl['user']) ?
|
||
$parsedUrl['user'] . (isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : '')
|
||
: '') . $parsedUrl['host'] . (
|
||
isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '') . $location[1];
|
||
}
|
||
else {
|
||
$newUrl = $location[1];
|
||
}
|
||
if ($lastUrl === $newUrl) break 2;
|
||
} else break 2;
|
||
}
|
||
$tries++;
|
||
}
|
||
// now try to fetch again
|
||
$content = t3lib_div::getURL($newUrl, 1, $additionalHeaders, $report);
|
||
$lastUrl = $newUrl;
|
||
$tries++;
|
||
}
|
||
|
||
|
||
$response = TRUE;
|
||
// analyze the response
|
||
... | ... | |
if (($report['http_code'] == 301) || ($report['http_code'] == 302)
|
||
|| ($report['http_code'] == 303) || ($report['http_code'] == 307)) {
|
||
$errorParams['errorType'] = $report['http_code'];
|
||
$errorParams['location'] = $location[1];
|
||
$errorParams['location'] = $lastUrl;
|
||
$response = FALSE;
|
||
}
|
||
if ($report['http_code'] == 404 || $report['http_code'] == 403) {
|
||
$errorParams['errorType'] = $report['http_code'];
|
||
$response = FALSE;
|
||
}
|
||
if ($report['http_code'] >= 300 && $response) {
|
||
$errorParams['errorType'] = $report['http_code'];
|
||
$response = FALSE;
|
||
... | ... | |
$response = sprintf($GLOBALS['LANG']->getLL('list.report.redirectloop'), $errorType, $errorParams['location']);
|
||
break;
|
||
case 403:
|
||
$response = $GLOBALS['LANG']->getLL('list.report.pageforbidden403');
|
||
break;
|
||
case 404:
|
||
$response = $GLOBALS['LANG']->getLL('list.report.pagenotfound404');
|
||
break;
|
||
case 403:
|
||
$response = $GLOBALS['LANG']->getLL('list.report.pageforbidden403');
|
||
break;
|
||
case 500:
|
||
$response = $GLOBALS['LANG']->getLL('list.report.internalerror500');
|
||
break;
|
||
... | ... | |
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/linkvalidator/classes/linktypes/class.tx_linkvalidator_linktypes_external.php']);
|
||
}
|
||
?>
|
||
?>
|
- « Previous
- 1
- 2
- 3
- Next »