コード例 #1
0
 /**
  * Replace 4/3 by 16/9 format
  * Possible Formats :
  * default
  * mqdefault -> medium quality
  * hqdefault -> high quality
  * sddefault
  * maxresdefault
  *
  * {@inheritdoc}
  */
 public function getReferenceImage(MediaInterface $media)
 {
     $url = $media->getMetadataValue('thumbnail_url');
     $pattern = '/\\bhqdefault\\b/i';
     $sddefault_url = preg_replace($pattern, 'sddefault', $url);
     //var_dump($sddefault_url);
     //exit();
     return $sddefault_url;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getReferenceImage(MediaInterface $media)
 {
     return $media->getMetadataValue('thumbnail_url');
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getDownloadResponse(MediaInterface $media, $format, $mode, array $headers = array())
 {
     // build the default headers
     $headers = array_merge(array('Content-Type' => $media->getContentType(), 'Content-Disposition' => sprintf('attachment; filename="%s"', $media->getMetadataValue('filename'))), $headers);
     if (!in_array($mode, array('http', 'X-Sendfile', 'X-Accel-Redirect'))) {
         throw new \RuntimeException('Invalid mode provided');
     }
     if ($mode == 'http') {
         if ($format == 'reference') {
             $file = $this->getReferenceFile($media);
         } else {
             $file = $this->getFilesystem()->get($this->generatePrivateUrl($media, $format));
         }
         return new StreamedResponse(function () use($file) {
             echo $file->getContent();
         }, 200, $headers);
     }
     if (!$this->getFilesystem()->getAdapter() instanceof \Sonata\MediaBundle\Filesystem\Local) {
         throw new \RuntimeException('Cannot use X-Sendfile or X-Accel-Redirect with non \\Sonata\\MediaBundle\\Filesystem\\Local');
     }
     $filename = sprintf('%s/%s', $this->getFilesystem()->getAdapter()->getDirectory(), $this->generatePrivateUrl($media, $format));
     return new BinaryFileResponse($filename, 200, $headers);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function getReferenceImage(MediaInterface $media)
 {
     $content = $media->getMetadataValue('content');
     return $content['poster'];
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function getDownloadResponse(MediaInterface $media, $format, $mode, array $headers = array())
 {
     // build the default headers
     $headers = array_merge(array('Content-Type' => $media->getContentType(), 'Content-Disposition' => sprintf('attachment; filename="%s"', $media->getMetadataValue('filename'))), $headers);
     if (!in_array($mode, array('http', 'X-Sendfile', 'X-Accel-Redirect'))) {
         throw new \RuntimeException('Invalid mode provided');
     }
     if ($mode == 'http') {
         $provider = $this;
         return new StreamedResponse(function () use($provider, $media) {
             echo $provider->getReferenceFile($media)->getContent();
         }, 200, $headers);
     }
     $headers[$mode] = $this->generatePrivateUrl($media, $format);
     return new Response('', 200, $headers);
 }
コード例 #6
0
 protected function generateReferenceSlug(MediaInterface $media)
 {
     $filename = $media->getMetadataValue('filename');
     $extension = substr($filename, strrpos($filename, '.') + 1);
     return (new Slugify())->slugify(substr($filename, 0, strlen($filename) - strlen($extension)));
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function getDownloadResponse(MediaInterface $media, $format, $mode = null, array $headers = array())
 {
     $headers = array_merge(array('Content-Type' => $media->getContentType(), 'Content-Disposition' => sprintf('attachment; filename="%s"', $media->getMetadataValue('filename'))), $headers);
     // create default variables
     if ($mode == 'X-Sendfile') {
         $headers['X-Sendfile'] = $this->generatePrivateUrl($media, $format);
         $content = '';
     } elseif ($mode == 'X-Accel-Redirect') {
         $headers['X-Accel-Redirect'] = $this->generatePrivateUrl($media, $format);
         $content = '';
     } elseif ($mode == 'http') {
         $content = $this->getReferenceFile($media)->getContent();
     } else {
         $content = '';
     }
     return new Response($content, 200, $headers);
 }