[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\Resource\ResourceFactory;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
20 use TYPO3\CMS\Core\Utility\StringUtility;
21
22 /**
23 * This class provides Check File Links plugin implementation
24 *
25 * @author Dimitri K├Ânig <dk@cabag.ch>
26 * @author Michael Miousse <michael.miousse@infoglobe.ca>
27 */
28 class FileLinktype extends AbstractLinktype {
29
30 /**
31 * Type fetching method, based on the type that softRefParserObj returns
32 *
33 * @param array $value Reference properties
34 * @param string $type Current type
35 * @param string $key Validator hook name
36 * @return string fetched type
37 */
38 public function fetchType($value, $type, $key) {
39 if (StringUtility::beginswith(strtolower($value['tokenValue']), 'file:')) {
40 $type = 'file';
41 }
42 return $type;
43 }
44 /**
45 * Checks a given URL + /path/filename.ext for validity
46 *
47 * @param string $url Url to check
48 * @param array $softRefEntry The soft reference entry which builds the context of the url
49 * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance
50 * @return bool TRUE on success or FALSE on error
51 */
52 public function checkLink($url, $softRefEntry, $reference) {
53 $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
54 try {
55 $file = $resourceFactory->retrieveFileOrFolderObject($url);
56 } catch (FileDoesNotExistException $e) {
57 return FALSE;
58 }
59 return !$file->isMissing();
60 }
61
62 /**
63 * Generate the localized error message from the error params saved from the parsing
64 *
65 * @param array $errorParams All parameters needed for the rendering of the error message
66 * @return string Validation error message
67 */
68 public function getErrorMessage($errorParams) {
69 return $this->getLanguageService()->getLL('list.report.filenotexisting');
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 return GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $row['url'];
80 }
81
82 }