[BUGFIX] Correction of Filelink of FAL in linkvalidator
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Linktype / FileLinktype.php
index 3b7fc8b..3695bfa 100644 (file)
@@ -14,7 +14,10 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * This class provides Check File Links plugin implementation
@@ -24,6 +27,20 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class FileLinktype extends AbstractLinktype {
 
+       /**
+        * Type fetching method, based on the type that softRefParserObj returns
+        *
+        * @param array $value Reference properties
+        * @param string $type Current type
+        * @param string $key Validator hook name
+        * @return string fetched type
+        */
+       public function fetchType($value, $type, $key) {
+               if (StringUtility::beginswith(strtolower($value['tokenValue']), 'file:')) {
+                       $type = 'file';
+               }
+               return $type;
+       }
        /**
         * Checks a given URL + /path/filename.ext for validity
         *
@@ -33,7 +50,13 @@ class FileLinktype extends AbstractLinktype {
         * @return bool TRUE on success or FALSE on error
         */
        public function checkLink($url, $softRefEntry, $reference) {
-               return @file_exists(PATH_site . rawurldecode($url));
+               $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
+               try {
+                       $file = $resourceFactory->retrieveFileOrFolderObject($url);
+               } catch (FileDoesNotExistException $e) {
+                       return FALSE;
+               }
+               return !$file->isMissing();
        }
 
        /**