Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function fromCurrent()
 {
     if (!isset($this->_cachedCurrentUrl)) {
         $this->_cacheUrl();
     }
     return $this->_cachedCurrentUrl->getClone();
 }
Exemple #2
0
 private function _findMaxResults($minimumPage, $maximumPage)
 {
     $currentPage = floor(($maximumPage + $minimumPage) / 2);
     if ($this->_shouldLog) {
         $this->_logDebug(sprintf('Starting new iteration. Minimum page is <code>%d</code>, maximum page is <code>%d</code>, current page is <code>%d</code>', $minimumPage, $maximumPage, $currentPage));
     }
     $url = $this->_urlFetched->getClone();
     $query = $url->getQuery();
     $query->set('fields', 'id');
     $query->set('limit', 100);
     $query->set('page', $currentPage);
     $result = $this->_apiUtility->getDecodedApiResponse($url);
     $currentPageCount = count($this->_arrayReader->getAsArray($result, 'list'));
     $hasMore = $this->_arrayReader->getAsBoolean($result, 'has_more');
     unset($url);
     unset($query);
     unset($result);
     if ($this->_shouldLog) {
         $this->_logDebug(sprintf('Page <code>%d</code> contains <code>%d</code> videos and <code>has_more</code> is <code>%s</code>', $currentPage, $currentPageCount, $hasMore ? 'true' : 'false'));
     }
     /*
      * There are 4 possible cases here:
      *
      * 1. We have over 10,000 results.
      * 2. Middle page is the last page in the result set.
      * 3. Middle page overshoots the last page.
      * 4. Middle page undershoots the last page.
      */
     if ($hasMore) {
         //scenario 1
         if (intval($currentPage) === 100) {
             if ($this->_shouldLog) {
                 $this->_logDebug('There are over 10K videos in this result set.');
             }
             // we've hit the max
             return 10000;
         }
         if ($this->_shouldLog) {
             $this->_logDebug('We have undershot the last page in the result set.');
         }
         //scenario 4
         return $this->_findMaxResults($currentPage + 1, $maximumPage);
     }
     // scenario 2
     if ($currentPageCount > 0) {
         if ($this->_shouldLog) {
             $this->_logDebug('Looks like this was the last page in the result set.');
         }
         return ($currentPage - 1) * 100 + $currentPageCount;
     }
     if ($this->_shouldLog) {
         $this->_logDebug('We have overshot the last page in the result set.');
     }
     // scenario 3
     return $this->_findMaxResults($minimumPage, $currentPage - 1);
 }
 private function _convertRelativeUrlToAbsolute(tubepress_api_url_UrlInterface $baseUrl, tubepress_api_url_UrlInterface $userContentUrl, tubepress_api_url_UrlInterface $candidate)
 {
     $toReturn = null;
     $properties = $this->getProperties();
     $manifestPath = $properties->get(self::$_PROPERTY_MANIFEST_PATH);
     $themeBase = basename(dirname($manifestPath));
     if ($properties->getAsBoolean(self::$_PROPERTY_IS_SYSTEM)) {
         $toReturn = $baseUrl->getClone();
         if ($properties->getAsBoolean(self::$_PROPERTY_IS_ADMIN)) {
             $toReturn->addPath("/web/admin-themes/{$themeBase}/{$candidate}");
         } else {
             $toReturn->addPath("/web/themes/{$themeBase}/{$candidate}");
         }
     } else {
         $toReturn = $userContentUrl->getClone();
         if ($properties->getAsBoolean(self::$_PROPERTY_IS_ADMIN)) {
             $toReturn->addPath("/admin-themes/{$themeBase}/{$candidate}");
         } else {
             $toReturn->addPath("/themes/{$themeBase}/{$candidate}");
         }
     }
     return $toReturn;
 }
Exemple #4
0
 private function _urlBuildingPageCommonParams(tubepress_api_url_UrlInterface $url, $currentPage)
 {
     if (isset($this->_invokedAtLeastOnce)) {
         $perPage = $this->_context->get(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE);
     } else {
         $perPage = min($this->_context->get(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE), ceil(2.07));
     }
     $url->getQuery()->set(tubepress_youtube3_impl_ApiUtility::QUERY_MAX_RESULTS, $perPage);
     if ($currentPage === 1) {
         return;
     }
     $clone = $url->getClone();
     $query = $clone->getQuery();
     $nextToken = null;
     $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_PART, tubepress_youtube3_impl_ApiUtility::PART_ID);
     $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_FIELDS, tubepress_youtube3_impl_ApiUtility::RESPONSE_NEXT_PAGE_TOKEN);
     for ($page = 2; $page <= $currentPage; ++$page) {
         if ($nextToken !== null) {
             $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_PAGETOKEN, $nextToken);
         }
         $result = $this->_apiUtility->getDecodedApiResponse($clone);
         if (!isset($result[tubepress_youtube3_impl_ApiUtility::RESPONSE_NEXT_PAGE_TOKEN])) {
             throw new RuntimeException('Failed to retrieve pagination tokens');
         }
         $nextToken = $result[tubepress_youtube3_impl_ApiUtility::RESPONSE_NEXT_PAGE_TOKEN];
     }
     $url->getQuery()->set(tubepress_youtube3_impl_ApiUtility::QUERY_PAGETOKEN, $nextToken);
 }