/**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->dir = vfsStream::setup();
     $dir = $this->dir;
     $tempDir = vfsStream::url($dir->getName()) . '/';
     $this->media = $this->getMock('\\Oryzone\\MediaStorage\\Model\\MediaInterface');
     $this->media->expects($this->any())->method('getContext')->will($this->returnValue('default'));
     $this->media->expects($this->any())->method('getName')->will($this->returnValue('sample'));
     $this->media->expects($this->any())->method('getContent')->will($this->returnValue('http://vimeo.com/56974716'));
     $this->media->expects($this->any())->method('getMetaValue')->will($this->returnValueMap(array(array('id', null, '56974716'))));
     $this->variant = $this->getMock('\\Oryzone\\MediaStorage\\Variant\\VariantInterface');
     $this->variant->expects($this->any())->method('getName')->will($this->returnValue('default'));
     $this->variant->expects($this->any())->method('getOptions')->will($this->returnValue(array('width' => 50, 'height' => 30, 'resize' => 'stretch')));
     $this->variant->expects($this->any())->method('getMetaValue')->will($this->returnValueMap(array(array('width', null, 50), array('height', null, 30))));
     $image = $this->getMock('\\Imagine\\Image\\ImageInterface');
     $image->expects($this->any())->method('save')->will($this->returnCallback(function ($destFile) use($dir) {
         $temp = vfsStream::newFile(basename($destFile));
         $dir->addChild($temp);
         return true;
     }));
     $imagine = $this->getMock('\\Imagine\\Image\\ImagineInterface');
     $imagine->expects($this->any())->method('open')->will($this->returnValue($image));
     $downloader = $this->getMock('\\Oryzone\\MediaStorage\\Downloader\\DownloaderInterface');
     $downloader->expects($this->any())->method('download')->will($this->returnCallback(function ($url, $destination) use($dir) {
         $temp = vfsStream::newFile(basename($destination));
         $temp->setContent(file_get_contents(__DIR__ . '/../fixtures/images/sample.jpg'));
         $dir->addChild($temp);
         return true;
     }));
     $videoService = $this->getMock('\\Oryzone\\MediaStorage\\Integration\\Video\\VideoServiceInterface');
     $this->provider = new VimeoProvider($tempDir, $imagine, $videoService, $downloader);
 }
Ejemplo n.º 2
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.º 4
0
 /**
  * {@inheritDoc}
  */
 public function getUrl(MediaInterface $media, VariantInterface $variant, $options = array())
 {
     $url = $this->path . $variant->getFilename();
     if (isset($options['absolute']) && $options['absolute']) {
         if (isset($options['domain'])) {
             $domain = $options['domain'];
         } else {
             $domain = $_SERVER['HTTP_HOST'];
         }
         if (isset($options['protocol'])) {
             $protocol = $options['protocol'];
         } else {
             $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http';
         }
         $url = sprintf('%s://%s/%s', $protocol, $domain, ltrim($url, '/'));
     }
     return $url;
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->dir = vfsStream::setup();
     vfsStream::copyFromFileSystem(__DIR__ . '/../fixtures/images', $this->dir);
     $dir = $this->dir;
     $image = $this->getMock('\\Imagine\\Image\\ImageInterface');
     $image->expects($this->any())->method('save')->will($this->returnCallback(function ($destFile) use($dir) {
         $temp = vfsStream::newFile(basename($destFile));
         $dir->addChild($temp);
         return TRUE;
     }));
     $imagine = $this->getMock('\\Imagine\\Image\\ImagineInterface');
     $imagine->expects($this->any())->method('open')->will($this->returnValue($image));
     $this->media = $this->getMock('\\Oryzone\\MediaStorage\\Model\\MediaInterface');
     $this->media->expects($this->any())->method('getContext')->will($this->returnValue('default'));
     $this->media->expects($this->any())->method('getName')->will($this->returnValue('sample'));
     $this->variant = $this->getMock('\\Oryzone\\MediaStorage\\Variant\\VariantInterface');
     $this->variant->expects($this->any())->method('getName')->will($this->returnValue('default'));
     $this->variant->expects($this->any())->method('getOptions')->will($this->returnValue(array('width' => 50, 'height' => 30, 'resize' => 'stretch')));
     $this->variant->expects($this->any())->method('getMetaValue')->will($this->returnValueMap(array(array('width', NULL, 50), array('height', NULL, 30))));
     $this->provider = new ImageProvider(vfsStream::url($this->dir->getName()) . '/', $imagine);
 }
Ejemplo n.º 6
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.º 7
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.º 8
0
 /**
  * {@inheritDoc}
  */
 public function getUrl(MediaInterface $media, VariantInterface $variant, $options = array())
 {
     return $this->baseUrl . $variant->getFilename();
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function addVariant(VariantInterface $variant)
 {
     $this->variants[$variant->getName()] = $variant->toArray();
 }