Exemplo n.º 1
0
 private function _prepareEvent($feed, $index)
 {
     $item = new tubepress_api_media_MediaItem('id');
     $mockProvider = $this->mock(tubepress_spi_media_MediaProviderInterface::_);
     $mockProvider->shouldReceive('getName')->andReturn('vimeo');
     $item->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $mockProvider);
     $unserialized = json_decode($feed, true);
     $videoArray = array();
     /*
      * Is this just a single video?
      */
     if (!isset($unserialized['data'])) {
         $videoArray = (array) $unserialized->video;
     } else {
         $videoArray = (array) $unserialized['data'];
     }
     $event = new tubepress_event_impl_tickertape_EventBase($item);
     $event->setArgument('decodedJson', $unserialized);
     $event->setArgument('videoArray', $videoArray);
     $event->setArgument('zeroBasedIndex', $index);
     $this->_mockAttributeFormatter->shouldReceive('formatNumberAttribute')->once()->with($item, tubepress_api_media_MediaItem::ATTRIBUTE_LIKES_COUNT, tubepress_api_media_MediaItem::ATTRIBUTE_LIKES_COUNT, 0);
     $this->_mockAttributeFormatter->shouldReceive('formatNumberAttribute')->once()->with($item, tubepress_api_media_MediaItem::ATTRIBUTE_VIEW_COUNT, tubepress_api_media_MediaItem::ATTRIBUTE_VIEW_COUNT, 0);
     $this->_mockAttributeFormatter->shouldReceive('truncateStringAttribute')->once()->with($item, tubepress_api_media_MediaItem::ATTRIBUTE_DESCRIPTION, tubepress_api_media_MediaItem::ATTRIBUTE_DESCRIPTION, tubepress_api_options_Names::META_DESC_LIMIT);
     $this->_mockAttributeFormatter->shouldReceive('formatDurationAttribute')->once()->with($item, tubepress_api_media_MediaItem::ATTRIBUTE_DURATION_SECONDS, tubepress_api_media_MediaItem::ATTRIBUTE_DURATION_FORMATTED);
     $this->_mockAttributeFormatter->shouldReceive('formatDateAttribute')->once()->with($item, tubepress_api_media_MediaItem::ATTRIBUTE_TIME_PUBLISHED_UNIXTIME, tubepress_api_media_MediaItem::ATTRIBUTE_TIME_PUBLISHED_FORMATTED);
     $this->_mockAttributeFormatter->shouldReceive('implodeArrayAttribute')->once()->with($item, tubepress_api_media_MediaItem::ATTRIBUTE_KEYWORD_ARRAY, tubepress_api_media_MediaItem::ATTRIBUTE_KEYWORDS_FORMATTED, ', ');
     return $event;
 }
 private function _getDataUrl(tubepress_api_media_MediaItem $mediaItem)
 {
     $link = $this->_urlFactory->fromString('https://www.youtube.com/embed/' . $mediaItem->getId());
     $embedQuery = $link->getQuery();
     $url = $this->_urlFactory->fromCurrent();
     $origin = $url->getScheme() . '://' . $url->getHost();
     $autoPlay = $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY);
     $loop = $this->_context->get(tubepress_api_options_Names::EMBEDDED_LOOP);
     $showInfo = $this->_context->get(tubepress_api_options_Names::EMBEDDED_SHOW_INFO);
     $autoHide = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_AUTOHIDE);
     $fullscreen = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_FULLSCREEN);
     $modestBranding = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_MODEST_BRANDING);
     $showRelated = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_SHOW_RELATED);
     $embedQuery->set('autohide', $this->_getAutoHideValue($autoHide));
     $embedQuery->set('autoplay', $this->_langUtils->booleanToStringOneOrZero($autoPlay));
     $embedQuery->set('enablejsapi', '1');
     $embedQuery->set('fs', $this->_langUtils->booleanToStringOneOrZero($fullscreen));
     $embedQuery->set('modestbranding', $this->_langUtils->booleanToStringOneOrZero($modestBranding));
     $embedQuery->set('origin', $origin);
     $embedQuery->set('rel', $this->_langUtils->booleanToStringOneOrZero($showRelated));
     $embedQuery->set('showinfo', $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $embedQuery->set('wmode', 'opaque');
     if ($loop) {
         $embedQuery->set('loop', $this->_langUtils->booleanToStringOneOrZero($loop));
         $embedQuery->set('playlist', $mediaItem->getId());
     }
     return $link;
 }
 private function _getDataUrl(tubepress_api_media_MediaItem $mediaItem, $playerId)
 {
     $autoPlay = $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY);
     $showInfo = $this->_context->get(tubepress_api_options_Names::EMBEDDED_SHOW_INFO);
     $actualId = str_replace('dailymotion_', '', $mediaItem->getId());
     /* build the data URL based on these options */
     $link = $this->_urlFactory->fromString("https://www.dailymotion.com/embed/video/{$actualId}");
     $query = $link->getQuery();
     $query->set(self::$_URL_PARAM_AUTOPLAY, $this->_langUtils->booleanToStringOneOrZero($autoPlay));
     $query->set(self::$_URL_PARAM_UI_START_SCREEN, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $query->set(self::$_URL_PARAM_ID, $playerId);
     return $link;
 }
Exemplo n.º 4
0
 public function testVideoFound()
 {
     $this->_mockLogger->shouldReceive('isEnabled')->once()->andReturn(true);
     $this->_mockLogger->shouldReceive('debug')->atLeast(1);
     $queryParams = array('foo' => 'bar', 'a' => 'b');
     $this->_mockHttpRequestParameterService->shouldReceive('getParamValue')->once()->with('tubepress_options')->andReturn($queryParams);
     $this->_mockHttpRequestParameterService->shouldReceive('getParamValue')->once()->with('tubepress_item')->andReturn('-video-');
     $this->_mockExecutionContext->shouldReceive('setEphemeralOptions')->once()->with($queryParams);
     $this->_mockExecutionContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::EMBEDDED_LAZYPLAY)->andReturn(false);
     $mockVideo = new tubepress_api_media_MediaItem('id');
     $mockVideo->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_TITLE, 'video title');
     $this->_mockTemplating->shouldReceive('renderTemplate')->once()->with('gallery/player/ajax', array(tubepress_api_template_VariableNames::MEDIA_ITEM => $mockVideo))->andReturn('player-html');
     $this->_mockVideoCollector->shouldReceive('collectSingle')->once()->andReturn($mockVideo);
     $this->_mockResponseCode->shouldReceive('setResponseCode')->once()->with(200);
     $this->expectOutputString('{"mediaItem":{"id":"id","title":"video title"},"html":"player-html"}');
     $this->_mockAjaxEvent->shouldReceive('setArgument')->once()->with('handled', true);
     $this->_sut->onAjax($this->_mockAjaxEvent);
     $this->assertTrue(true);
 }
Exemplo n.º 5
0
 private function _getDataUrl(tubepress_api_media_MediaItem $mediaItem)
 {
     $autoPlay = $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY);
     $showInfo = $this->_context->get(tubepress_api_options_Names::EMBEDDED_SHOW_INFO);
     $loop = $this->_context->get(tubepress_api_options_Names::EMBEDDED_LOOP);
     $color = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_PLAYER_COLOR);
     /* build the data URL based on these options */
     $link = $this->_urlFactory->fromString('https://player.vimeo.com/video/' . $mediaItem->getId());
     $query = $link->getQuery();
     $query->set(self::$_URL_PARAM_AUTOPLAY, $this->_langUtils->booleanToStringOneOrZero($autoPlay));
     $query->set(self::$_URL_PARAM_COLOR, $color);
     $query->set(self::$_URL_PARAM_LOOP, $this->_langUtils->booleanToStringOneOrZero($loop));
     $query->set(self::$_URL_PARAM_PORTRAIT, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $query->set(self::$_URL_PARAM_BYLINE, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $query->set(self::$_URL_PARAM_TITLE, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     return $link;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function implodeArrayAttribute(tubepress_api_media_MediaItem $item, $sourceAttributeName, $destinationAttributeName, $glue)
 {
     if (!$item->hasAttribute($sourceAttributeName)) {
         return;
     }
     $array = $item->getAttribute($sourceAttributeName);
     $formatted = implode($glue, $array);
     $item->setAttribute($destinationAttributeName, $formatted);
 }
 /**
  * {@inheritdoc}
  */
 public function getAttributesForInvocationAnchor(tubepress_api_media_MediaItem $mediaItem)
 {
     return array('rel' => 'external nofollow', 'target' => '_blank', 'href' => $mediaItem->getAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_HOME_URL));
 }
 /**
  * {@inheritdoc}
  */
 public function getAttributesForInvocationAnchor(tubepress_api_media_MediaItem $mediaItem)
 {
     $id = $mediaItem->getId();
     $this->_url->getQuery()->set('tubepress_item', $id);
     return array('rel' => 'nofollow', 'href' => $this->_url->toString());
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getAttributesForInvocationAnchor(tubepress_api_media_MediaItem $mediaItem)
 {
     return array('rel' => 'external nofollow', 'target' => '_blank', 'href' => sprintf('https://www.youtube.com/watch?v=%s', $mediaItem->getId()));
 }
Exemplo n.º 10
0
 public function __perPageSort(tubepress_api_media_MediaItem $first, tubepress_api_media_MediaItem $second)
 {
     $attributeName = self::$_perPageSortMap[$this->_perPageSortOrder];
     if (!$first->hasAttribute($attributeName) || !$second->hasAttribute($attributeName)) {
         return 0;
     }
     $firstAttributeValue = $first->getAttribute($attributeName);
     $secondAttributeValue = $second->getAttribute($attributeName);
     switch ($this->_perPageSortOrder) {
         case tubepress_api_options_AcceptableValues::PER_PAGE_SORT_COMMENT_COUNT:
         case tubepress_api_options_AcceptableValues::PER_PAGE_SORT_NEWEST:
         case tubepress_api_options_AcceptableValues::PER_PAGE_SORT_DURATION:
         case tubepress_api_options_AcceptableValues::PER_PAGE_SORT_VIEW_COUNT:
             $firstAttributeValue = intval($firstAttributeValue);
             $secondAttributeValue = intval($secondAttributeValue);
             if ($firstAttributeValue == $secondAttributeValue) {
                 return 0;
             }
             if ($firstAttributeValue < $secondAttributeValue) {
                 return 1;
             }
             return -1;
         case tubepress_api_options_AcceptableValues::PER_PAGE_SORT_OLDEST:
             $firstAttributeValue = intval($firstAttributeValue);
             $secondAttributeValue = intval($secondAttributeValue);
             if ($firstAttributeValue == $secondAttributeValue) {
                 return 0;
             }
             if ($firstAttributeValue < $secondAttributeValue) {
                 return -1;
             }
             return 1;
         default:
             if ($firstAttributeValue == $secondAttributeValue) {
                 return 0;
             }
             if ($firstAttributeValue < $secondAttributeValue) {
                 return -1;
             }
             return 1;
     }
 }
Exemplo n.º 11
0
 private function _applyHomeUrl(tubepress_api_media_MediaItem $item, array &$toReturn)
 {
     $id = $item->getId();
     $homeUrl = sprintf('https://youtu.be/%s', $id);
     $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_HOME_URL] = $homeUrl;
 }
Exemplo n.º 12
0
 /**
  * @param tubepress_api_media_MediaItem $item
  *
  * @return tubepress_spi_embedded_EmbeddedProviderInterface
  *
  * @throws RuntimeException
  */
 private function _selectEmbeddedProvider(tubepress_api_media_MediaItem $item)
 {
     $requestedEmbeddedPlayerName = $this->_context->get(tubepress_api_options_Names::EMBEDDED_PLAYER_IMPL);
     /*
      * @var tubepress_spi_media_MediaProviderInterface
      */
     $mediaProvider = $item->getAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER);
     $mediaProviderName = $mediaProvider->getName();
     /*
      * The user has requested a specific embedded player that is registered. Let's see if the provider agrees.
      */
     if ($requestedEmbeddedPlayerName !== tubepress_api_options_AcceptableValues::EMBEDDED_IMPL_PROVIDER_BASED) {
         foreach ($this->_embeddedProviders as $embeddedProvider) {
             $compatibleProviderNames = $embeddedProvider->getCompatibleMediaProviderNames();
             if ($embeddedProvider->getName() === $requestedEmbeddedPlayerName && in_array($mediaProviderName, $compatibleProviderNames)) {
                 //found it!
                 return $embeddedProvider;
             }
         }
     }
     /*
      * Do we have an embedded provider whose name exactly matches the provider? If so, let's use that. This
      * should be the common case.
      */
     foreach ($this->_embeddedProviders as $embeddedProvider) {
         if ($embeddedProvider->getName() === $mediaProviderName) {
             return $embeddedProvider;
         }
     }
     /*
      * Running out of options. See if we can find *any* player that can handle videos from this provider.
      */
     foreach ($this->_embeddedProviders as $embeddedProvider) {
         if (in_array($mediaProviderName, $embeddedProvider->getCompatibleMediaProviderNames())) {
             return $embeddedProvider;
         }
     }
     /*
      * None of the registered embedded players support the calculated provider. I give up.
      */
     throw new RuntimeException(sprintf('No embedded providers could generate HTML for item %s', $item->getId()));
 }
Exemplo n.º 13
0
 public function testBlacklist()
 {
     $this->_mockLogger->shouldReceive('debug')->atLeast(1);
     $this->_mockContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::FEED_ITEM_ID_BLACKLIST)->andReturn('xxx');
     $mockVideoProvider = $this->mock(tubepress_spi_media_MediaProviderInterface::_);
     $mockVideo1 = new tubepress_api_media_MediaItem('p');
     $mockVideo1->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $mockVideoProvider);
     $mockVideo2 = new tubepress_api_media_MediaItem('y');
     $mockVideo2->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $mockVideoProvider);
     $mockVideo3 = new tubepress_api_media_MediaItem('xxx');
     $mockVideo3->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $mockVideoProvider);
     $mockVideo4 = new tubepress_api_media_MediaItem('yyy');
     $mockVideo4->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $mockVideoProvider);
     $videoArray = array($mockVideo1, $mockVideo2, $mockVideo3, $mockVideo4);
     $providerResult = new tubepress_api_media_MediaPage();
     $providerResult->setItems($videoArray);
     $event = $this->mock('tubepress_api_event_EventInterface');
     $event->shouldReceive('getSubject')->times(2)->andReturn($providerResult);
     $this->_sut->blacklist($event);
     $this->assertEquals(array($mockVideo1, $mockVideo2, $mockVideo4), $providerResult->getItems());
 }
 /**
  * {@inheritdoc}
  */
 public function getTemplateVariables(tubepress_api_media_MediaItem $mediaItem)
 {
     $dataUrl = $this->_urlFactory->fromString(sprintf('https://www.youtube.com/watch?v=%s', $mediaItem->getId()));
     return array('userContentUrl' => $this->_environment->getUserContentUrl(), 'autostart' => $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY), tubepress_api_template_VariableNames::EMBEDDED_DATA_URL => $dataUrl, tubepress_jwplayer5_api_OptionNames::COLOR_FRONT => $this->_context->get(tubepress_jwplayer5_api_OptionNames::COLOR_FRONT), tubepress_jwplayer5_api_OptionNames::COLOR_LIGHT => $this->_context->get(tubepress_jwplayer5_api_OptionNames::COLOR_LIGHT), tubepress_jwplayer5_api_OptionNames::COLOR_SCREEN => $this->_context->get(tubepress_jwplayer5_api_OptionNames::COLOR_SCREEN), tubepress_jwplayer5_api_OptionNames::COLOR_BACK => $this->_context->get(tubepress_jwplayer5_api_OptionNames::COLOR_BACK));
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function getTemplateVariables(tubepress_api_media_MediaItem $mediaItem)
 {
     return array(tubepress_api_template_VariableNames::EMBEDDED_DATA_URL => $this->_urlFactory->fromString(sprintf('http://www.youtube.com/embed/%s', $mediaItem->getId())));
 }
Exemplo n.º 16
0
 public function testSetGetAuthor()
 {
     $this->_vid->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_AUTHOR_USER_ID, 'hough');
     $this->assertEquals($this->_vid->getAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_AUTHOR_USER_ID), 'hough');
 }