[BUGFIX] Correction of Filelink of FAL in linkvalidator
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Linktype / FileLinktype.php
1 <?php
2 namespace TYPO3\CMS\Linkvalidator\Linktype;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
19
20 /**
21 * This class provides Check File Links plugin implementation
22 *
23 * @author Dimitri K├Ânig <dk@cabag.ch>
24 * @author Michael Miousse <michael.miousse@infoglobe.ca>
25 */
26 class FileLinktype extends \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype {
27
28 /**
29 * Type fetching method, based on the type that softRefParserObj returns
30 *
31 * @param array $value Reference properties
32 * @param string $type Current type
33 * @param string $key Validator hook name
34 * @return string fetched type
35 */
36 public function fetchType($value, $type, $key) {
37 if (GeneralUtility::isFirstPartOfStr(strtolower($value['tokenValue']), 'file:')) {
38 $type = 'file';
39 }
40 return $type;
41 }
42
43 /**
44 * Checks a given URL + /path/filename.ext for validity
45 *
46 * @param string $url Url to check
47 * @param array $softRefEntry The soft reference entry which builds the context of the url
48 * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance
49 * @return boolean TRUE on success or FALSE on error
50 */
51 public function checkLink($url, $softRefEntry, $reference) {
52 $resourceFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
53 try {
54 $file = $resourceFactory->retrieveFileOrFolderObject($url);
55 } catch (FileDoesNotExistException $e) {
56 return FALSE;
57 }
58 return !$file->isMissing();
59 }
60
61 /**
62 * Generate the localized error message from the error params saved from the parsing
63 *
64 * @param array $errorParams All parameters needed for the rendering of the error message
65 * @return string Validation error message
66 */
67 public function getErrorMessage($errorParams) {
68 $response = $GLOBALS['LANG']->getLL('list.report.filenotexisting');
69 return $response;
70 }
71
72 /**
73 * Construct a valid Url for browser output
74 *
75 * @param array $row Broken link record
76 * @return string Parsed broken url
77 */
78 public function getBrokenUrl($row) {
79 $brokenUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $row['url'];
80 return $brokenUrl;
81 }
82 }