Ejemplo n.º 1
0
 /**
  * Gets a DataURI of the provided file
  * @param string $path Path of the file
  * @return string|null DataURI of the file
  */
 protected function getDataUriFromPath($path)
 {
     $file = $this->fileBrowser->getFile($path);
     if (!$file) {
         $file = $this->fileBrowser->getPublicFile($path);
         if (!$file) {
             return null;
         }
     }
     $dataUri = $this->httpFactory->createDataUriFromFile($file);
     return $dataUri->encode();
 }
 /**
  * Action to download the file
  * @param string $widgetId
  * @param string $fileId
  * @return null
  */
 public function downloadAction(FileBrowser $fileBrowser, $widgetId, $fileId)
 {
     if ($widgetId != $this->id) {
         return;
     }
     $files = $this->getFiles();
     if (!isset($files[$fileId])) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $file = $fileBrowser->getFile($files[$fileId]['file']);
     if (!$file) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $this->setDownloadView($file, $file->getName());
 }
 /**
  * Action to get the original value of an asset
  * @param \ride\library\orm\OrmManager $orm
  * @param string $asset
  * @return null
  */
 public function assetValueAction(OrmManager $orm, FileBrowser $fileBrowser, $asset)
 {
     $assetModel = $orm->getAssetModel();
     if (is_numeric($asset)) {
         $asset = $assetModel->getById($asset);
     } else {
         $asset = $assetModel->getBy(array('filter' => array('slug' => $asset)));
     }
     if (!$asset) {
         $this->response->setNotFound();
         return;
     }
     if ($asset->isUrl()) {
         $this->response->setRedirect($asset->getValue());
         return;
     }
     $file = $fileBrowser->getFile($asset->getValue());
     if (!$file) {
         $this->response->setNotFound();
         return;
     }
     $this->setFileView($file);
 }
Ejemplo n.º 4
0
 /**
  * Action to get the original value of an asset
  * @param \ride\library\orm\OrmManager $orm
  * @param string $asset
  * @return null
  */
 public function assetValueAction(OrmManager $orm, FileBrowser $fileBrowser, AssetService $assetService, $asset)
 {
     $assetModel = $orm->getAssetModel();
     if (is_numeric($asset)) {
         $asset = $assetModel->getById($asset);
     } else {
         $locales = $orm->getLocales();
         foreach ($locales as $locale) {
             $asset = $assetModel->getBy(array('filter' => array('slug' => $asset)), $locale);
             if ($asset) {
                 break;
             }
         }
     }
     if (!$asset) {
         $this->response->setNotFound();
         return;
     }
     $url = $assetService->getAssetUrl($asset, $this->request->getQueryParameter('style'));
     if ($url) {
         $this->response->setRedirect($url);
         return;
     }
     $file = $fileBrowser->getFile($asset->getValue());
     if (!$file) {
         $this->response->setNotFound();
         return;
     }
     $this->setFileView($file);
 }