public function __callbackConvertToWpUrlString(tubepress_api_url_UrlInterface $url)
 {
     if ($url->isAbsolute()) {
         return $url->toString();
     }
     if (!isset($this->_urlCache)) {
         $this->_urlCache = new tubepress_internal_collection_Map();
         $this->_urlCache->put('url.base', rtrim($this->_environment->getBaseUrl()->toString(), '/'));
         $this->_urlCache->put('url.user', rtrim($this->_environment->getUserContentUrl()->toString(), '/'));
         $this->_urlCache->put('basename', basename(TUBEPRESS_ROOT));
     }
     $urlAsString = $url->toString();
     $tubePressBaseUrl = $this->_urlCache->get('url.base');
     $userContentUrl = $this->_urlCache->get('url.user');
     $baseName = $this->_urlCache->get('basename');
     $isSystem = false;
     if ($this->_stringUtils->startsWith($urlAsString, "{$tubePressBaseUrl}/web/")) {
         $isSystem = true;
     } else {
         if (!$this->_stringUtils->startsWith($urlAsString, "{$userContentUrl}/")) {
             //this should never happen
             return $urlAsString;
         }
     }
     if ($isSystem) {
         $path = str_replace($tubePressBaseUrl, '', $urlAsString);
         return $this->_wpFunctions->plugins_url($path, "{$baseName}/tubepress.php");
     }
     $path = str_replace($userContentUrl, '', $urlAsString);
     return $this->_wpFunctions->content_url('tubepress-content' . $path);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function fromCurrent()
 {
     if (!isset($this->_cachedCurrentUrl)) {
         $this->_cacheUrl();
     }
     return $this->_cachedCurrentUrl->getClone();
 }
Example #3
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);
 }
 /**
  * {@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());
 }
Example #5
0
 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;
 }
 /**
  * {@inheritdoc}
  */
 public function getTranslatedClientRegistrationInstructions(tubepress_api_translation_TranslatorInterface $translator, tubepress_api_url_UrlInterface $redirectUrl)
 {
     $step1 = $translator->trans('<a href="%client-registration-url%" target="_blank">Click here</a> to create a new Vimeo &quot;App&quot;.', array('%client-registration-url%' => 'https://developer.vimeo.com/apps/new'));
     $step1Subs = array($translator->trans('Use anything you\'d like for the App Name, App Description, and App URL.'), $translator->trans('In the field for &quot;App Callback URLs&quot;, enter:<br /><code>%redirect-uri%</code>', array('%redirect-uri%' => $redirectUrl->toString())));
     $step2 = $translator->trans('Under the &quot;OAuth2&quot; tab of your new Vimeo App, you will find your &quot;Client Identifier&quot; and &quot;Client Secret&quot;. Enter those values into the text boxes below.');
     //>(translatable)<
     $step3 = $translator->trans('Click the &quot;New token&quot; button below to authorize TubePress to communicate with Vimeo on your behalf. This step will take place in a popup window.');
     //>(translatable)<
     return array($step1, $step1Subs, $step2, $step3);
 }
 /**
  * Does the heavy lifting of generating pagination.
  *
  * @param int    $totalitems The total items in this gallery.
  * @param int    $page       The current page number.
  * @param int    $limit      How many videos per page.
  * @param int    $adjacents  How many adjacents.
  * @param string $targetpage The target page
  * @param string $pagestring The query parameter controlling the page number.
  *
  * @return string The HTML for the pagination
  */
 private function _legacyPagination($totalitems, $page = 1, $limit = 15, $adjacents = 1, tubepress_api_url_UrlInterface $url, $pagestring = '?page=')
 {
     $url->getQuery()->remove('tubepress_page');
     $prev = $page - 1;
     $next = $page + 1;
     $lastpage = ceil($totalitems / $limit);
     $lpm1 = $lastpage - 1;
     $pagination = '';
     if ($lastpage > 1) {
         $pagination .= '<div class="pagination">';
         if ($page > 1) {
             $url->getQuery()->set($pagestring, $prev);
             $pagination .= $this->_buildAnchorOpener($url, true, $prev);
             $pagination .= '&laquo; ' . $this->_translator->trans('prev') . '</a>';
         }
         if ($lastpage < 7 + $adjacents * 2) {
             for ($counter = 1; $counter <= $lastpage; ++$counter) {
                 if ($counter == $page) {
                     $pagination .= "<span class=\"current\">{$counter}</span>";
                 } else {
                     $url->getQuery()->set($pagestring, $counter);
                     $pagination .= $this->_buildAnchorOpener($url, true, $counter);
                     $pagination .= "{$counter}</a>";
                 }
             }
         } elseif ($lastpage >= 7 + $adjacents * 2) {
             if ($page < 1 + $adjacents * 3) {
                 for ($counter = 1; $counter < 4 + $adjacents * 2; ++$counter) {
                     if ($counter == $page) {
                         $pagination .= "<span class=\"current\">{$counter}</span>";
                     } else {
                         $url->getQuery()->set($pagestring, $counter);
                         $pagination .= $this->_buildAnchorOpener($url, true, $counter);
                         $pagination .= "{$counter}</a>";
                     }
                 }
                 $pagination .= self::DOTS;
                 $url->getQuery()->set($pagestring, $lpm1);
                 $pagination .= ' ' . $this->_buildAnchorOpener($url, true, $lpm1);
                 $pagination .= "{$lpm1}</a>";
                 $url->getQuery()->set($pagestring, $lastpage);
                 $pagination .= $this->_buildAnchorOpener($url, true, $lastpage);
                 $pagination .= "{$lastpage}</a>";
             } elseif ($lastpage - $adjacents * 2 > $page && $page > $adjacents * 2) {
                 $url->getQuery()->set($pagestring, 1);
                 $pagination .= $this->_buildAnchorOpener($url, true, 1);
                 $pagination .= '1</a>';
                 $url->getQuery()->set($pagestring, 2);
                 $pagination .= $this->_buildAnchorOpener($url, true, 2);
                 $pagination .= '2</a>';
                 $pagination .= self::DOTS;
                 for ($counter = $page - $adjacents; $counter <= $page + $adjacents; ++$counter) {
                     if ($counter == $page) {
                         $pagination .= "<span class=\"current\">{$counter}</span>";
                     } else {
                         $url->getQuery()->set($pagestring, $counter);
                         $pagination .= ' ' . $this->_buildAnchorOpener($url, true, $counter);
                         $pagination .= "{$counter}</a>";
                     }
                 }
                 $pagination .= self::DOTS;
                 $url->getQuery()->set($pagestring, $lpm1);
                 $pagination .= ' ' . $this->_buildAnchorOpener($url, true, $lpm1);
                 $pagination .= "{$lpm1}</a>";
                 $url->getQuery()->set($pagestring, $lastpage);
                 $pagination .= ' ' . $this->_buildAnchorOpener($url, true, $lastpage);
                 $pagination .= "{$lastpage}</a>";
             } else {
                 $url->getQuery()->set($pagestring, 1);
                 $pagination .= $this->_buildAnchorOpener($url, true, 1);
                 $pagination .= '1</a>';
                 $url->getQuery()->set($pagestring, 2);
                 $pagination .= $this->_buildAnchorOpener($url, true, 1);
                 $pagination .= '2</a>';
                 $pagination .= self::DOTS;
                 for ($counter = $lastpage - (1 + $adjacents * 3); $counter <= $lastpage; ++$counter) {
                     if ($counter == $page) {
                         $pagination .= "<span class=\"current\">{$counter}</span>";
                     } else {
                         $url->getQuery()->set($pagestring, $counter);
                         $pagination .= ' ' . $this->_buildAnchorOpener($url, true, $counter);
                         $pagination .= "{$counter}</a>";
                     }
                 }
             }
         }
         if ($page < $counter - 1) {
             $url->getQuery()->set($pagestring, $next);
             $pagination .= $this->_buildAnchorOpener($url, true, $next);
             $pagination .= $this->_translator->trans('next') . ' &raquo;</a>';
         } else {
             $pagination .= '<span class="disabled">' . $this->_translator->trans('next') . ' &raquo;</span>';
         }
         $pagination .= "</div>\n";
     }
     return $pagination;
 }
Example #8
0
 private function _urlBuildingPageSearch(tubepress_api_url_UrlInterface $url, tubepress_api_url_QueryInterface $query, $requestedMode)
 {
     $url->addPath(tubepress_youtube3_impl_ApiUtility::PATH_SEARCH);
     switch ($requestedMode) {
         case tubepress_youtube3_api_Constants::GALLERYSOURCE_YOUTUBE_RELATED:
             $videoId = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_YOUTUBE_RELATED_VALUE);
             $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_RELATED, $videoId);
             break;
         case tubepress_youtube3_api_Constants::GALLERYSOURCE_YOUTUBE_SEARCH:
             $tags = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_YOUTUBE_TAG_VALUE);
             $tags = str_replace(array('&#8216', '&#8217', '&#8242;', '&#34', '&#8220;', '&#8221;', '&#8243;'), '"', $tags);
             $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_Q, $tags);
             break;
         default:
             break;
     }
     $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_TYPE, 'video')->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_SYNDICATED, 'true');
     if ($this->_context->get(tubepress_youtube3_api_Constants::OPTION_EMBEDDABLE_ONLY)) {
         $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_EMBEDDABLE, 'true');
     }
     $restrictToUser = $this->_context->get(tubepress_api_options_Names::SEARCH_ONLY_USER);
     if ($restrictToUser) {
         $userChannelId = $this->_urlBuildingConvertUserOrChannelToChannelId($restrictToUser);
         $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_CHANNEL_ID, $userChannelId);
     }
     switch ($this->_context->get(tubepress_youtube3_api_Constants::OPTION_FILTER)) {
         case tubepress_youtube3_api_Constants::SAFESEARCH_STRICT:
             $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_SAFESEARCH, 'strict');
             break;
         case tubepress_youtube3_api_Constants::SAFESEARCH_MODERATE:
             $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_SAFESEARCH, 'moderate');
             break;
         default:
             $query->set(tubepress_youtube3_impl_ApiUtility::QUERY_SEARCH_SAFESEARCH, 'none');
     }
     $this->_urlBuildingPageSearchOrderBy($url);
 }
Example #9
0
 private function _addPagination($currentPage, tubepress_api_url_UrlInterface $url)
 {
     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.04));
     }
     $url->getQuery()->set('page', $currentPage)->set('per_page', $perPage);
 }