예제 #1
0
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $perPageSortOrder = $context->get(org_tubepress_api_const_options_names_Feed::PER_PAGE_SORT);
     $feedSortOrder = $context->get(org_tubepress_api_const_options_names_Feed::ORDER_BY);
     /** No sort requested? */
     if ($perPageSortOrder === org_tubepress_api_const_options_values_PerPageSortValue::NONE) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Requested per-page sort order is "none". Not applying per-page sorting.');
         return $providerResult;
     }
     /** Grab a handle to the videos. */
     $videos = $providerResult->getVideoArray();
     if ($feedSortOrder === org_tubepress_api_const_options_values_OrderByValue::RANDOM || $perPageSortOrder === org_tubepress_api_const_options_values_PerPageSortValue::RANDOM) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Shuffling videos');
         shuffle($videos);
     } else {
         /** Determine the sort method name. */
         $sortCallback = '_' . $perPageSortOrder . '_compare';
         /** If we have a sorter, use it. */
         if (method_exists($this, $sortCallback)) {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Now sorting %s videos on page (%s)', count($videos), $perPageSortOrder);
             uasort($videos, array($this, $sortCallback));
         } else {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'No sort available for this page (%s)', $perPageSortOrder);
         }
     }
     $videos = array_values($videos);
     /** Modify the feed result. */
     $providerResult->setVideoArray($videos);
     return $providerResult;
 }
예제 #2
0
 function testViewCount()
 {
     $providerResult = new org_tubepress_api_provider_ProviderResult();
     $providerResult->setVideoArray($this->_videos);
     $this->_setSortAndPerPageOrder(org_tubepress_api_const_options_values_OrderByValue::RANDOM, org_tubepress_api_const_options_values_PerPageSortValue::VIEW_COUNT);
     $result = $this->_sut->alter_providerResult($providerResult);
     $this->_verifySort($result->getVideoArray(), 3, 2, 1);
 }
예제 #3
0
 public function alter_galleryTemplate(org_tubepress_api_template_Template $template, org_tubepress_api_provider_ProviderResult $providerResult, $page, $providerName)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $htmlGenerator = $ioc->get(org_tubepress_api_player_PlayerHtmlGenerator::_);
     $playerName = $context->get(org_tubepress_api_const_options_names_Embedded::PLAYER_LOCATION);
     $videos = $providerResult->getVideoArray();
     $galleryId = $context->get(org_tubepress_api_const_options_names_Advanced::GALLERY_ID);
     $playerHtml = $playerHtml = $this->_showPlayerHtmlOnPageLoad($ioc, $playerName) ? $htmlGenerator->getHtml($videos[0], $galleryId) : '';
     $template->setVariable(org_tubepress_api_const_template_Variable::PLAYER_HTML, $playerHtml);
     $template->setVariable(org_tubepress_api_const_template_Variable::PLAYER_NAME, $playerName);
     return $template;
 }
예제 #4
0
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult, $providerName)
 {
     $videos = $providerResult->getVideoArray();
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     /* shuffle if we need to */
     if ($context->get(org_tubepress_api_const_options_names_Display::ORDER_BY) == org_tubepress_api_const_options_values_OrderValue::RANDOM) {
         org_tubepress_impl_log_Log::log('Shuffler', 'Shuffling videos');
         shuffle($videos);
     }
     /* modify the feed result */
     $providerResult->setVideoArray($videos);
     return $providerResult;
 }
 public function alter_galleryTemplate(org_tubepress_api_template_Template $template, org_tubepress_api_provider_ProviderResult $providerResult, $page, $providerName)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     $videoArray = $providerResult->getVideoArray();
     $thumbWidth = $context->get(org_tubepress_api_const_options_names_Display::THUMB_WIDTH);
     $thumbHeight = $context->get(org_tubepress_api_const_options_names_Display::THUMB_HEIGHT);
     $galleryId = $context->get(org_tubepress_api_const_options_names_Advanced::GALLERY_ID);
     /* add some core template variables */
     $template->setVariable(org_tubepress_api_const_template_Variable::VIDEO_ARRAY, $videoArray);
     $template->setVariable(org_tubepress_api_const_template_Variable::GALLERY_ID, $galleryId);
     $template->setVariable(org_tubepress_api_const_template_Variable::THUMBNAIL_WIDTH, $thumbWidth);
     $template->setVariable(org_tubepress_api_const_template_Variable::THUMBNAIL_HEIGHT, $thumbHeight);
     return $template;
 }
예제 #6
0
 public function alter_galleryTemplate(org_tubepress_api_template_Template $template, org_tubepress_api_provider_ProviderResult $providerResult, $page, $providerName)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     $pm = $ioc->get('org_tubepress_api_plugin_PluginManager');
     $pagination = $this->_getHtml($providerResult->getEffectiveTotalResultCount());
     $pagination = $pm->runFilters(org_tubepress_api_const_plugin_FilterPoint::HTML_PAGINATION, $pagination);
     if ($context->get(org_tubepress_api_const_options_names_Display::PAGINATE_ABOVE)) {
         $template->setVariable(org_tubepress_api_const_template_Variable::PAGINATION_TOP, $pagination);
     }
     if ($context->get(org_tubepress_api_const_options_names_Display::PAGINATE_BELOW)) {
         $template->setVariable(org_tubepress_api_const_template_Variable::PAGINATION_BOTTOM, $pagination);
     }
     return $template;
 }
예제 #7
0
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult)
 {
     $videos = $providerResult->getVideoArray();
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $blacklist = $context->get(org_tubepress_api_const_options_names_Feed::VIDEO_BLACKLIST);
     $videosToKeep = array();
     $blacklistCount = 0;
     foreach ($videos as $video) {
         $id = $video->getId();
         /* keep videos without an ID or that aren't blacklisted */
         if (!isset($id) || $this->_isNotBlacklisted($id, $blacklist)) {
             $videosToKeep[] = $video;
         } else {
             $blacklistCount++;
         }
     }
     /* modify the feed result */
     $providerResult->setVideoArray($videosToKeep);
     return $providerResult;
 }
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult)
 {
     $totalResults = $providerResult->getEffectiveTotalResultCount();
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $limit = $context->get(org_tubepress_api_const_options_names_Feed::RESULT_COUNT_CAP);
     $firstCut = $limit == 0 ? $totalResults : min($limit, $totalResults);
     $secondCut = min($firstCut, self::_calculateRealMax($context, $firstCut));
     $videos = $providerResult->getVideoArray();
     $resultCount = count($videos);
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Effective total result count (taking into account user-defined limit) is %d video(s)', $secondCut);
     if ($resultCount > $secondCut) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Result has %d video(s), limit is %d. So we\'re chopping it down.', $resultCount, $secondCut);
         $providerResult->setVideoArray(array_splice($videos, 0, $secondCut - $resultCount));
     }
     $providerResult->setEffectiveTotalResultCount($secondCut);
     return $providerResult;
 }
예제 #9
0
 /**
  * Fetch a single video.
  *
  * @param string $customVideoId The video ID to fetch.
  *
  * @return org_tubepress_api_video_Video The video.
  */
 public function getSingleVideo($customVideoId)
 {
     org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Fetching video with ID <tt>%s</tt>', $customVideoId);
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $urlBuilder = $ioc->get(org_tubepress_api_feed_UrlBuilder::_);
     $videoUrl = $urlBuilder->buildSingleVideoUrl($customVideoId);
     org_tubepress_impl_log_Log::log(self::$_logPrefix, 'URL to fetch is <a href="%s">this</a>', $videoUrl);
     $feedRetrievalService = $ioc->get(org_tubepress_api_feed_FeedFetcher::_);
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $results = $feedRetrievalService->fetch($videoUrl, $context->get(org_tubepress_api_const_options_names_Cache::CACHE_ENABLED));
     $factory = $ioc->get(org_tubepress_api_factory_VideoFactory::_);
     $videoArray = $factory->feedToVideoArray($results);
     $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     $pc = $ioc->get(org_tubepress_api_provider_ProviderCalculator::_);
     if (empty($videoArray)) {
         throw new Exception(sprintf('Could not find video with ID %s', $customVideoId));
         //>(translatable)<
     }
     $result = new org_tubepress_api_provider_ProviderResult();
     $result->setEffectiveTotalResultCount(1);
     $result->setVideoArray($videoArray);
     $provider = $pc->calculateProviderOfVideoId($customVideoId);
     $pm->runFilters(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $result, $provider);
     return $videoArray[0];
 }