/**
  * @param string $videoId The video ID to play.
  *
  * @return ehough_curly_Url The URL of the data for this video.
  */
 public final function getDataUrlForVideo($videoId)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $link = new ehough_curly_Url('https://www.youtube.com/embed/' . $videoId);
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService();
     $url = new ehough_curly_Url($qss->getFullUrl($_SERVER));
     $origin = $url->getScheme() . '://' . $url->getHost();
     $autoPlay = $context->get(tubepress_api_const_options_names_Embedded::AUTOPLAY);
     $loop = $context->get(tubepress_api_const_options_names_Embedded::LOOP);
     $showInfo = $context->get(tubepress_api_const_options_names_Embedded::SHOW_INFO);
     $autoHide = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::AUTOHIDE);
     $enableJsApi = $context->get(tubepress_api_const_options_names_Embedded::ENABLE_JS_API);
     $fullscreen = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::FULLSCREEN);
     $modestBranding = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::MODEST_BRANDING);
     $showRelated = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::SHOW_RELATED);
     $link->setQueryVariable('wmode', 'opaque');
     $link->setQueryVariable('autohide', $this->_getAutoHideValue($autoHide));
     $link->setQueryVariable('autoplay', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($autoPlay));
     $link->setQueryVariable('enablejsapi', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($enableJsApi));
     $link->setQueryVariable('fs', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($fullscreen));
     $link->setQueryVariable('loop', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($loop));
     $link->setQueryVariable('modestbranding', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($modestBranding));
     $link->setQueryVariable('rel', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showRelated));
     $link->setQueryVariable('showinfo', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showInfo));
     $link->setQueryVariable('origin', $origin);
     return $link;
 }
 /**
  * Commence authorization by fetching a set of temporary credentials.
  *
  * WARNING. Invoking this function will cause a redirect to the $redirectUrl parameter. Thus, script
  * execution will come to a complete halt from the caller's perspective.
  *
  * http://tools.ietf.org/html/rfc5849#section-2.1
  *
  * @param ehough_coauthor_api_v1_AbstractServer $server
  * @param string|ehough_curly_Url               $redirectUrl
  * @param ehough_coauthor_api_v1_Credentials    $clientCredentials
  *
  * @return void
  *
  * @throws ehough_coauthor_api_exception_RuntimeException If anything fails.
  */
 public function commenceNewAuthorization(ehough_coauthor_api_v1_AbstractServer $server, $redirectUrl, ehough_coauthor_api_v1_Credentials $clientCredentials)
 {
     if (!$redirectUrl instanceof ehough_curly_Url) {
         $redirectUrl = new ehough_curly_Url($redirectUrl);
     }
     /**
      * Grab the temporary credentials from the server.
      *
      * http://tools.ietf.org/html/rfc5849#section-2.1
      */
     $temporaryCredentials = $this->_credentialsFetcher->fetchTemporaryCredentials($clientCredentials, $server, $redirectUrl);
     /**
      * Store them for later.
      */
     $this->_credentialsStorage->store($temporaryCredentials);
     /**
      * Prepare the authorization URL for redirection.
      *
      * http://tools.ietf.org/html/rfc5849#section-2.2
      */
     $authUrl = new ehough_curly_Url($server->getAuthorizationEndpoint()->toString());
     $authUrl->setQueryVariable('oauth_token', $temporaryCredentials->getIdentifier());
     /**
      * Redirect, if we're not testing.
      */
     if (!$this->_inTestMode) {
         header("{$authUrl}", true, 302);
         exit;
     }
 }
 private function _getVideoDomId($providerName, ehough_curly_Url $dataUrl)
 {
     if ($providerName !== 'vimeo') {
         return 'tubepress-video-object-' . mt_rand();
     }
     $queryVars = $dataUrl->getQueryVariables();
     if (isset($queryVars['player_id'])) {
         return $queryVars['player_id'];
     }
     //this should never happen
     return 'tubepress-video-object-' . mt_rand();
 }
 private function _maybeGetListValueFromUrl($originalValue)
 {
     $url = null;
     try {
         $url = new ehough_curly_Url($originalValue);
     } catch (Exception $e) {
         return $originalValue;
     }
     $host = $url->getHost();
     if (!tubepress_impl_util_StringUtils::endsWith($host, 'youtube.com')) {
         return $originalValue;
     }
     $params = $url->getQueryVariables();
     if (!array_key_exists('list', $params)) {
         return $originalValue;
     }
     return $params['list'];
 }
 /**
  * @param string $videoId The video ID to play.
  *
  * @return ehough_curly_Url The URL of the data for this video.
  */
 public final function getDataUrlForVideo($videoId)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $autoPlay = $context->get(tubepress_api_const_options_names_Embedded::AUTOPLAY);
     $showInfo = $context->get(tubepress_api_const_options_names_Embedded::SHOW_INFO);
     $loop = $context->get(tubepress_api_const_options_names_Embedded::LOOP);
     $jsApi = $context->get(tubepress_api_const_options_names_Embedded::ENABLE_JS_API);
     $color = $context->get(tubepress_addons_vimeo_api_const_options_names_Embedded::PLAYER_COLOR);
     /* build the data URL based on these options */
     $link = new ehough_curly_Url("http://player.vimeo.com/video/{$videoId}");
     $link->setQueryVariable(self::$_URL_PARAM_AUTOPLAY, tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($autoPlay));
     $link->setQueryVariable(self::$_URL_PARAM_COLOR, $color);
     $link->setQueryVariable(self::$_URL_PARAM_LOOP, tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($loop));
     $link->setQueryVariable(self::$_URL_PARAM_PORTRAIT, tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showInfo));
     $link->setQueryVariable(self::$_URL_PARAM_BYLINE, tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showInfo));
     $link->setQueryVariable(self::$_URL_PARAM_TITLE, tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showInfo));
     if ($jsApi) {
         $link->setQueryVariable(self::$_URL_PARAM_JS_API, 1);
         $link->setQueryVariable(self::$_URL_PARAM_PLAYER_ID, 'tubepress-video-object-' . mt_rand());
     }
     return $link;
 }
 public function onSearchInputTemplate(tubepress_api_event_EventInterface $event)
 {
     $template = $event->getSubject();
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $resultsUrl = $context->get(tubepress_api_const_options_names_InteractiveSearch::SEARCH_RESULTS_URL);
     $url = '';
     try {
         $url = new ehough_curly_Url($resultsUrl);
     } catch (Exception $e) {
         //this is not a real problem, as the user might simply not supply a custom URL
     }
     /* if the user didn't request a certain page, just send the search results right back here */
     if ($url == '') {
         $url = new ehough_curly_Url($qss->getFullUrl($_SERVER));
     }
     /* clean up the search terms a bit */
     $searchTerms = $hrps->getParamValue(tubepress_spi_const_http_ParamName::SEARCH_TERMS);
     $searchTerms = urldecode($searchTerms);
     //TODO: get rid of this once we move to POST?
     /*
      * read http://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear
      * if you're curious as to what's going on here
      */
     $params = $url->getQueryVariables();
     unset($params[tubepress_spi_const_http_ParamName::PAGE]);
     unset($params[tubepress_spi_const_http_ParamName::SEARCH_TERMS]);
     /* apply the template variables */
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_HANDLER_URL, $url->toString());
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_HIDDEN_INPUTS, $params);
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_TERMS, $searchTerms);
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_BUTTON, $ms->_('Search'));
     //>(translatable)<
 }
 private function _urlToString($url)
 {
     if (!$url instanceof ehough_curly_Url) {
         $url = new ehough_curly_Url($url);
     }
     return rtrim($url->toString(), '/');
 }
Example #8
0
 private function _getNormalizedAuthority(ehough_curly_Url $url)
 {
     $scheme = $url->getScheme();
     $port = $url->getPort();
     if ($port != null && ($scheme === 'http' && $port != 80 || $scheme === 'https' && $port != 465)) {
         return $url->getAuthority();
     }
     return $url->getHost();
 }
 private function _urlProcessingOrderBy(tubepress_spi_context_ExecutionContext $execContext, ehough_curly_Url $url)
 {
     /*
      * In a request for a video feed, the following values are valid for this parameter:
      *
      * relevance – Entries are ordered by their relevance to a search query. This is the default setting for video search results feeds.
      * published – Entries are returned in reverse chronological order. This is the default value for video feeds other than search results feeds.
      * viewCount – Entries are ordered from most views to least views.
      * rating – Entries are ordered from highest rating to lowest rating.
      *
      * In a request for a playlist feed, the following values are valid for this parameter:
      *
      * position – Entries are ordered by their position in the playlist. This is the default setting.
      * commentCount – Entries are ordered by number of comments from most comments to least comments.
      * duration – Entries are ordered by length of each playlist video from longest video to shortest video.
      * published – Entries are returned in reverse chronological order.
      * reversedPosition – Entries are ordered in reverse of their position in the playlist.
      * title – Entries are ordered alphabetically by title.
      * viewCount – Entries are ordered from most views to least views.
      */
     $requestedSortOrder = $execContext->get(tubepress_api_const_options_names_Feed::ORDER_BY);
     $currentGallerySource = $execContext->get(tubepress_api_const_options_names_Output::GALLERY_SOURCE);
     if ($requestedSortOrder === tubepress_api_const_options_values_OrderByValue::DEFAULTT) {
         $url->setQueryVariable(self::$_URL_PARAM_ORDER, $this->_calculateDefaultSearchOrder($currentGallerySource));
         return;
     }
     if ($requestedSortOrder === tubepress_api_const_options_values_OrderByValue::NEWEST) {
         $url->setQueryVariable(self::$_URL_PARAM_ORDER, 'published');
         return;
     }
     if ($requestedSortOrder == tubepress_api_const_options_values_OrderByValue::VIEW_COUNT) {
         $url->setQueryVariable(self::$_URL_PARAM_ORDER, $requestedSortOrder);
         return;
     }
     if ($currentGallerySource == tubepress_addons_youtube_api_const_options_values_GallerySourceValue::YOUTUBE_PLAYLIST) {
         if (in_array($requestedSortOrder, array(tubepress_api_const_options_values_OrderByValue::POSITION, tubepress_api_const_options_values_OrderByValue::COMMENT_COUNT, tubepress_api_const_options_values_OrderByValue::DURATION, tubepress_api_const_options_values_OrderByValue::REV_POSITION, tubepress_api_const_options_values_OrderByValue::TITLE))) {
             $url->setQueryVariable(self::$_URL_PARAM_ORDER, $requestedSortOrder);
             return;
         }
     } else {
         if (in_array($requestedSortOrder, array(tubepress_api_const_options_values_OrderByValue::RELEVANCE, tubepress_api_const_options_values_OrderByValue::RATING))) {
             $url->setQueryVariable(self::$_URL_PARAM_ORDER, $requestedSortOrder);
         }
     }
 }
 /**
  * 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 _diggStyle($totalitems, tubepress_spi_message_MessageService $messageService, $page = 1, $limit = 15, $adjacents = 1, $targetpage = '/', $pagestring = '?page=')
 {
     $prev = $page - 1;
     $next = $page + 1;
     $lastpage = ceil($totalitems / $limit);
     $lpm1 = $lastpage - 1;
     $pagination = '';
     $url = new ehough_curly_Url($targetpage);
     if ($lastpage > 1) {
         $pagination .= '<div class="pagination">';
         if ($page > 1) {
             $url->setQueryVariable($pagestring, $prev);
             $newurl = $url->toString();
             $pagination .= $this->_buildAnchorOpener($newurl, true, $prev);
             $pagination .= "&laquo; " . $messageService->_('prev') . '</a>';
         }
         if ($lastpage < 7 + $adjacents * 2) {
             for ($counter = 1; $counter <= $lastpage; $counter++) {
                 if ($counter == $page) {
                     $pagination .= "<span class=\"current\">{$counter}</span>";
                 } else {
                     $url->setQueryVariable($pagestring, $counter);
                     $newurl = $url->toString();
                     $pagination .= $this->_buildAnchorOpener($newurl, 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->setQueryVariable($pagestring, $counter);
                         $newurl = $url->toString();
                         $pagination .= $this->_buildAnchorOpener($newurl, true, $counter);
                         $pagination .= "{$counter}</a>";
                     }
                 }
                 $pagination .= self::DOTS;
                 $url->setQueryVariable($pagestring, $lpm1);
                 $newurl = $url->toString();
                 $pagination .= ' ' . $this->_buildAnchorOpener($newurl, true, $lpm1);
                 $pagination .= "{$lpm1}</a>";
                 $url->setQueryVariable($pagestring, $lastpage);
                 $newurl = $url->toString();
                 $pagination .= $this->_buildAnchorOpener($newurl, true, $lastpage);
                 $pagination .= "{$lastpage}</a>";
             } elseif ($lastpage - $adjacents * 2 > $page && $page > $adjacents * 2) {
                 $url->setQueryVariable($pagestring, 1);
                 $newurl = $url->toString();
                 $pagination .= $this->_buildAnchorOpener($newurl, true, 1);
                 $pagination .= "1</a>";
                 $url->setQueryVariable($pagestring, 2);
                 $newurl = $url->toString();
                 $pagination .= $this->_buildAnchorOpener($newurl, 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->setQueryVariable($pagestring, $counter);
                         $newurl = $url->toString();
                         $pagination .= ' ' . $this->_buildAnchorOpener($newurl, true, $counter);
                         $pagination .= "{$counter}</a>";
                     }
                 }
                 $pagination .= self::DOTS;
                 $url->setQueryVariable($pagestring, $lpm1);
                 $newurl = $url->toString();
                 $pagination .= ' ' . $this->_buildAnchorOpener($newurl, true, $lpm1);
                 $pagination .= "{$lpm1}</a>";
                 $url->setQueryVariable($pagestring, $lastpage);
                 $newurl = $url->toString();
                 $pagination .= ' ' . $this->_buildAnchorOpener($newurl, true, $lastpage);
                 $pagination .= "{$lastpage}</a>";
             } else {
                 $url->setQueryVariable($pagestring, 1);
                 $newurl = $url->toString();
                 $pagination .= $this->_buildAnchorOpener($newurl, true, 1);
                 $pagination .= "1</a>";
                 $url->setQueryVariable($pagestring, 2);
                 $newurl = $url->toString();
                 $pagination .= $this->_buildAnchorOpener($newurl, 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->setQueryVariable($pagestring, $counter);
                         $newurl = $url->toString();
                         $pagination .= ' ' . $this->_buildAnchorOpener($newurl, true, $counter);
                         $pagination .= "{$counter}</a>";
                     }
                 }
             }
         }
         if ($page < $counter - 1) {
             $url->setQueryVariable($pagestring, $next);
             $newurl = $url->toString();
             $pagination .= $this->_buildAnchorOpener($newurl, true, $next);
             $pagination .= $messageService->_('next') . ' &raquo;</a>';
         } else {
             $pagination .= '<span class="disabled">' . $messageService->_('next') . ' &raquo;</span>';
         }
         $pagination .= "</div>\n";
     }
     return $pagination;
 }