/** * Resolves the URL of an file * * @param string $file * @return string|NULL */ protected function retrieveMediaUrl($file) { $returnValue = NULL; // because the file value can possibly have link parameters, use explode to split all values $fileParts = explode(' ', $file); /** @var $mediaWizard \TYPO3\CMS\Mediace\MediaWizard\MediaWizardProviderInterface */ $mediaWizard = \TYPO3\CMS\Mediace\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($fileParts[0]); // Get the path relative to the page currently outputted if (substr($fileParts[0], 0, 5) === 'file:') { $fileUid = substr($fileParts[0], 5); if (!empty($fileUid) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($fileUid)) { $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($fileUid); if ($fileObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) { $returnValue = $fileObject->getPublicUrl(); } } } elseif (is_file(PATH_site . $fileParts[0])) { $returnValue = $GLOBALS['TSFE']->tmpl->getFileName($fileParts[0]); } elseif ($mediaWizard !== NULL) { $jumpUrlEnabled = $GLOBALS['TSFE']->config['config']['jumpurl_enable']; $GLOBALS['TSFE']->config['config']['jumpurl_enable'] = 0; $returnValue = $this->cObj->typoLink_URL(array('parameter' => $mediaWizard->rewriteUrl($fileParts[0]))); $GLOBALS['TSFE']->config['config']['jumpurl_enable'] = $jumpUrlEnabled; } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($fileParts[0])) { $returnValue = $fileParts[0]; } return $returnValue; }
/** * Resolves the URL of an file * * @param $media * * @return null|string */ protected function retrieveMediaUrl($media) { $returnValue = NULL; if (class_exists('TYPO3\\CMS\\Mediace\\MediaWizard\\MediaWizardProviderManager')) { // 7.2 $mediaWizard = \TYPO3\CMS\Mediace\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($media); } elseif (class_exists('TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProviderManager')) { // before 7.2 $mediaWizard = \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($media); } else { throw new \Exception('You are running TYPO3 > CMS 7.2. Please install the mediace extension', 12367238462384.0); } // Get the path relative to the page currently outputted if (substr($media, 0, 5) === "file:") { $fileUid = substr($media, 5); if (MathUtility::canBeInterpretedAsInteger($fileUid)) { $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid); if ($fileObject instanceof FileInterface) { $returnValue = $fileObject->getPublicUrl(); } } } elseif (is_file(PATH_site . $media)) { $returnValue = $GLOBALS['TSFE']->tmpl->getFileName($media); } elseif ($mediaWizard !== NULL) { $cObj = new ContentObjectRenderer(); $returnValue = $cObj->typoLink_URL(array('parameter' => $mediaWizard->rewriteUrl($media))); } elseif (GeneralUtility::isValidUrl($media)) { $returnValue = $media; } return $returnValue; }