Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function render(MediaInterface $media, VariantInterface $variant, $url = NULL, $options = array())
 {
     $attributes = array('title' => $media->getName() . ' (' . $variant->getMetaValue('size') . ')');
     if (isset($options['attributes'])) {
         $attributes = array_merge($attributes, $options['attributes']);
     }
     $htmlAttributes = '';
     foreach ($attributes as $key => $value) {
         if ($value !== NULL) {
             $htmlAttributes .= $key . '="' . $value . '" ';
         }
     }
     return sprintf('<a href="%s" %s>%s</a>', $url, $htmlAttributes, $media->getName());
 }
 /**
  * {@inheritDoc}
  */
 public function generateName(MediaInterface $media, VariantInterface $variant, Filesystem $filesystem)
 {
     $name = trim($media->getName());
     if ($name == '') {
         throw new InvalidArgumentException('The given media has no name');
     }
     $suffix = uniqid('-') . '_' . $variant->getName();
     if ($this->maxLength && function_exists('mb_strlen')) {
         $nameMaxLength = $this->maxLength - mb_strlen($suffix);
         if (mb_strlen($name . $suffix) > $this->maxLength) {
             $name = mb_substr($name, 0, $nameMaxLength);
         }
     }
     $name = self::urlize($name);
     return $name . $suffix;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function render(MediaInterface $media, VariantInterface $variant, $url = NULL, $options = array())
 {
     $attributes = array('title' => $media->getName(), 'width' => $variant->getMetaValue('width'), 'height' => $variant->getMetaValue('height'));
     if (isset($options['attributes'])) {
         $attributes = array_merge($attributes, $options['attributes']);
     }
     $htmlAttributes = '';
     foreach ($attributes as $key => $value) {
         if ($value !== NULL) {
             $htmlAttributes .= $key . ($value !== '' ? '="' . $value . '"' : '') . ' ';
         }
     }
     return sprintf('<img src="%s" %s/>', $url, $htmlAttributes);
 }
Ejemplo n.º 4
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;
 }