/**
  * Returns a publicly accessible URL for a file.
  *
  * WARNING: Access to the file may be restricted by further means, e.g.
  * some web-based authentication. You have to take care of this yourself.
  *
  * @param ResourceInterface $resourceObject The file or folder object
  * @param boolean $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver)
  * @return string
  */
 public function getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript = FALSE)
 {
     $publicUrl = NULL;
     if ($this->isOnline()) {
         // Pre-process the public URL by an accordant slot
         $this->emitPreGeneratePublicUrlSignal($resourceObject, $relativeToCurrentScript, array('publicUrl' => &$publicUrl));
         // If slot did not handle the signal, use the default way to determine public URL
         if ($publicUrl === NULL) {
             if ($this->hasCapability(self::CAPABILITY_PUBLIC)) {
                 $publicUrl = $this->driver->getPublicUrl($resourceObject->getIdentifier());
             }
             if ($publicUrl === NULL && $resourceObject instanceof FileInterface) {
                 $queryParameterArray = array('eID' => 'dumpFile', 't' => '');
                 if ($resourceObject instanceof File) {
                     $queryParameterArray['f'] = $resourceObject->getUid();
                     $queryParameterArray['t'] = 'f';
                 } elseif ($resourceObject instanceof ProcessedFile) {
                     $queryParameterArray['p'] = $resourceObject->getUid();
                     $queryParameterArray['t'] = 'p';
                 }
                 $queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
                 $publicUrl = 'index.php?' . str_replace('+', '%20', http_build_query($queryParameterArray));
             }
             // If requested, make the path relative to the current script in order to make it possible
             // to use the relative file
             if ($publicUrl !== NULL && $relativeToCurrentScript && !GeneralUtility::isValidUrl($publicUrl)) {
                 $absolutePathToContainingFolder = PathUtility::dirname(PATH_site . $publicUrl);
                 $pathPart = PathUtility::getRelativePathTo($absolutePathToContainingFolder);
                 $filePart = substr(PATH_site . $publicUrl, strlen($absolutePathToContainingFolder) + 1);
                 $publicUrl = $pathPart . $filePart;
             }
         }
     }
     return $publicUrl;
 }
Esempio n. 2
0
 /**
  * @param \TYPO3\CMS\Core\Resource\ResourceStorage $resourceStorage
  * @param \TYPO3\CMS\Core\Resource\Driver\DriverInterface $driver
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resourceObject
  * @param boolean $relativeToCurrentScript
  * @param string $urlData
  */
 public function getCdnPublicUrl($resourceStorage, $driver, $resourceObject, $relativeToCurrentScript, $urlData)
 {
     if (!$driver instanceof LocalDriver || $this->environmentService->isEnvironmentInBackendMode()) {
         return;
     }
     if (($resourceObject instanceof File || $resourceObject instanceof ProcessedFile) && ($resourceStorage->getCapabilities() & ResourceStorageInterface::CAPABILITY_PUBLIC) == ResourceStorageInterface::CAPABILITY_PUBLIC) {
         $publicUrl = $driver->getPublicUrl($resourceObject->getIdentifier());
         $urlData['publicUrl'] = $GLOBALS['TSFE']->config['config']['cdnBaseUrl'] . $publicUrl;
         if ($resourceObject instanceof File) {
             $urlData['publicUrl'] .= '?' . $resourceObject->getModificationTime();
         } else {
             if ($resourceObject instanceof ProcessedFile) {
                 $urlData['publicUrl'] .= '?' . $resourceObject->getProperty('tstamp');
             }
         }
     }
 }