Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function render(MediaInterface $media, VariantInterface $variant, $url = NULL, $options = array())
 {
     $availableModes = array('video', 'image', 'embedUrl', 'url');
     $defaultOptions = array('mode' => 'video', 'attributes' => array());
     $options = array_merge($defaultOptions, $options);
     if (!in_array($options['mode'], $availableModes)) {
         throw new InvalidArgumentException(sprintf('Invalid mode "%s" to render a Youtube Video. Allowed values: "%s"', $options['mode'], json_encode($availableModes)));
     }
     $id = $media->getMetaValue('id');
     $embedUrl = sprintf(self::EMBED_URL, $id);
     if ($options['mode'] == 'embedUrl') {
         return $embedUrl;
     }
     if ($options['mode'] == 'url') {
         return sprintf(self::CANONICAL_URL, $id);
     }
     switch ($options['mode']) {
         case 'video':
             $options['attributes'] = array_merge(array('width' => $variant->getMetaValue('width', 420), 'height' => $variant->getMetaValue('height', 315), 'frameborder' => 0, 'allowfullscreen' => '', 'webkitAllowFullScreen' => '', 'mozallowfullscreen' => ''), $options['attributes']);
             break;
         case 'image':
             $options['attributes'] = array_merge(array('title' => $media->getName(), 'width' => $variant->getMetaValue('width', 420), 'height' => $variant->getMetaValue('height', 315)), $options['attributes']);
             break;
     }
     $htmlAttributes = '';
     foreach ($options['attributes'] as $key => $value) {
         if ($value !== NULL) {
             $htmlAttributes .= $key . ($value !== '' ? '="' . $value . '"' : '') . ' ';
         }
     }
     if ($options['mode'] == 'video') {
         $code = sprintf('<iframe src="%s" %s></iframe>', $embedUrl, $htmlAttributes);
     } else {
         $code = sprintf('<img src="%s" %s/>', $url, $htmlAttributes);
     }
     return $code;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function hasChangedContent(MediaInterface $media)
 {
     $content = $media->getContent();
     return $content != NULL && $media->getMetaValue('id') !== md5_file($content);
 }