Пример #1
0
 public function onHtmlGeneration(tubepress_api_event_EventInterface $event)
 {
     $galleryId = $this->_context->get(tubepress_api_options_Names::HTML_GALLERY_ID);
     $shouldLog = $this->_logger->isEnabled();
     if ($galleryId == '') {
         $galleryId = mt_rand();
         $this->_context->setEphemeralOption(tubepress_api_options_Names::HTML_GALLERY_ID, $galleryId);
     }
     if ($shouldLog) {
         $this->_logDebug(sprintf('Starting to build thumbnail gallery <code>%s</code>', $galleryId));
     }
     $pageNumber = $this->_requestParameters->getParamValueAsInt('tubepress_page', 1);
     /* first grab the items */
     if ($shouldLog) {
         $this->_logDebug('Asking collector for a page.');
     }
     $mediaPage = $this->_collector->collectPage($pageNumber);
     $itemCount = sizeof($mediaPage->getItems());
     if ($shouldLog) {
         $this->_logDebug(sprintf('Collector has delivered <code>%d</code> item(s)', $itemCount));
     }
     $templateVars = array('mediaPage' => $mediaPage, 'pageNumber' => $pageNumber);
     $html = $this->_templating->renderTemplate('gallery/main', $templateVars);
     /* we're done. tie up */
     if ($shouldLog) {
         $this->_logDebug(sprintf('Done assembling gallery <code>%d</code>', $galleryId));
     }
     $event->setSubject($html);
     $event->stopPropagation();
 }
Пример #2
0
 public function onAjax(tubepress_api_event_EventInterface $ajaxEvent)
 {
     $isDebugEnabled = $this->_logger->isEnabled();
     if ($isDebugEnabled) {
         $this->_logger->debug('Handling incoming request. First parsing shortcode.');
     }
     $nvpMap = $this->_requestParams->getParamValue('tubepress_options');
     $itemId = $this->_requestParams->getParamValue('tubepress_item');
     if ($isDebugEnabled) {
         $this->_logger->debug('Requested item ID is ' . $itemId);
     }
     $this->_context->setEphemeralOptions($nvpMap);
     if ($this->_context->get(tubepress_api_options_Names::EMBEDDED_LAZYPLAY)) {
         $this->_context->setEphemeralOption(tubepress_api_options_Names::EMBEDDED_AUTOPLAY, true);
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Now asking collector for item with ID ' . $itemId);
     }
     /* grab the item! */
     $mediaItem = $this->_collector->collectSingle($itemId);
     if ($mediaItem === null) {
         $this->_responseCode->setResponseCode(404);
         $ajaxEvent->setArgument('handled', true);
         return;
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Collector found item with ID ' . $itemId . '. Sending it to browser');
     }
     $playerHtml = $this->_templating->renderTemplate('gallery/player/ajax', array(tubepress_api_template_VariableNames::MEDIA_ITEM => $mediaItem));
     $toReturn = array('mediaItem' => $mediaItem->toHtmlSafeArray(), 'html' => $playerHtml);
     $this->_responseCode->setResponseCode(200);
     echo json_encode($toReturn);
     $ajaxEvent->setArgument('handled', true);
 }
Пример #3
0
 private function _handle(tubepress_api_event_EventInterface $event)
 {
     $itemId = $this->_requestParams->getParamValue('tubepress_item');
     $shouldLog = $this->_logger->isEnabled();
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Building single video with ID %s', $itemId));
     }
     $result = $this->_context->setEphemeralOption(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID, $itemId);
     if ($result !== null) {
         if ($shouldLog) {
             $this->_logger->debug('Could not verify video ID.');
         }
     }
 }
Пример #4
0
 private function _startGalleryUrl($mode, tubepress_api_url_UrlInterface $url)
 {
     switch ($mode) {
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_ALBUM:
             $albumId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_ALBUM_VALUE);
             $url->addPath('albums')->addPath($albumId)->addPath(self::$_PATH_SEGMENT_VIDEOS);
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_APPEARS_IN:
             $userId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_APPEARS_IN_VALUE);
             $url->addPath(self::$_PATH_SEGMENT_USERS)->addPath($userId)->addPath('appearances');
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_CATEGORY:
             $categoryId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_CATEGORY_VALUE);
             $url->addPath('categories')->addPath($categoryId)->addPath(self::$_PATH_SEGMENT_VIDEOS);
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_CHANNEL:
             $channelId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_CHANNEL_VALUE);
             $url->addPath('channels')->addPath($channelId)->addPath(self::$_PATH_SEGMENT_VIDEOS);
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_GROUP:
             $groupId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_GROUP_VALUE);
             $url->addPath('groups')->addPath($groupId)->addPath(self::$_PATH_SEGMENT_VIDEOS);
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_SEARCH:
             $filter = $this->_context->get(tubepress_api_options_Names::SEARCH_ONLY_USER);
             $query = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_SEARCH_VALUE);
             if ($filter) {
                 $newMode = tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_UPLOADEDBY;
                 $this->_context->setEphemeralOption(tubepress_api_options_Names::GALLERY_SOURCE, $newMode);
                 $this->_context->setEphemeralOption(tubepress_vimeo3_api_Constants::OPTION_VIMEO_UPLOADEDBY_VALUE, $filter);
                 $this->_startGalleryUrl($newMode, $url);
             } else {
                 $url->addPath(self::$_PATH_SEGMENT_VIDEOS);
             }
             $url->getQuery()->set('query', $query);
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_TAG:
             $tag = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_TAG_VALUE);
             $url->addPath('tags')->addPath($tag)->addPath(self::$_PATH_SEGMENT_VIDEOS);
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_LIKES:
             $userId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_LIKES_VALUE);
             $url->addPath(self::$_PATH_SEGMENT_USERS)->addPath($userId)->addPath('likes');
             return;
         case tubepress_vimeo3_api_Constants::GALLERYSOURCE_VIMEO_UPLOADEDBY:
             $userId = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_VIMEO_UPLOADEDBY_VALUE);
             $url->addPath(self::$_PATH_SEGMENT_USERS)->addPath($userId)->addPath(self::$_PATH_SEGMENT_VIDEOS);
             return;
     }
     throw new InvalidArgumentException(sprintf('Unknown Vimeo gallery source: %s', $mode));
 }
Пример #5
0
 private function _handleSearchOutput(tubepress_api_event_EventInterface $event)
 {
     $rawSearchTerms = $this->_requestParams->getParamValue('tubepress_search');
     $hasSearchTerms = $rawSearchTerms != '';
     $shouldLog = $this->_logger->isEnabled();
     /* if the user isn't searching, don't display anything */
     if (!$hasSearchTerms) {
         if ($shouldLog) {
             $this->_logDebug('User doesn\'t appear to be searching. Will not display anything.');
         }
         $event->setSubject('');
         $event->stopPropagation();
         return;
     }
     if ($shouldLog) {
         $this->_logDebug('User is searching. We\'ll handle this.');
     }
     $provider = $this->_findMediaProvider();
     $modeName = $provider->getSearchModeName();
     $valueName = $provider->getSearchQueryOptionName();
     $this->_context->setEphemeralOption(tubepress_api_options_Names::GALLERY_SOURCE, $modeName);
     $this->_context->setEphemeralOption($valueName, $rawSearchTerms);
 }
Пример #6
0
 /**
  * Registers all the styles and scripts for the front end.
  *
  * @param array $opts The options.
  *
  * @return void
  */
 public function printWidgetHtml(tubepress_api_event_EventInterface $event)
 {
     $opts = $event->getSubject();
     extract($opts);
     /* default widget options */
     $defaultWidgetOptions = array(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE => 3, tubepress_api_options_Names::META_DISPLAY_VIEWS => false, tubepress_api_options_Names::META_DISPLAY_DESCRIPTION => true, tubepress_api_options_Names::META_DESC_LIMIT => 50, tubepress_api_options_Names::PLAYER_LOCATION => 'shadowbox', tubepress_api_options_Names::GALLERY_THUMB_HEIGHT => 105, tubepress_api_options_Names::GALLERY_THUMB_WIDTH => 135, tubepress_api_options_Names::GALLERY_PAGINATE_ABOVE => false, tubepress_api_options_Names::GALLERY_PAGINATE_BELOW => false, tubepress_api_options_Names::THEME => 'tubepress/default', tubepress_api_options_Names::GALLERY_FLUID_THUMBS => false);
     /* now apply the user's options */
     $rawTag = $this->_context->get(tubepress_wordpress_api_Constants::OPTION_WIDGET_SHORTCODE);
     $widgetTag = $this->_stringUtils->removeNewLines($rawTag);
     $this->_shortcodeParser->parse($widgetTag);
     /* calculate the final options */
     $finalOptions = array_merge($defaultWidgetOptions, $this->_context->getEphemeralOptions());
     $this->_context->setEphemeralOptions($finalOptions);
     if ($this->_context->get(tubepress_api_options_Names::THEME) === '') {
         $this->_context->setEphemeralOption(tubepress_api_options_Names::THEME, 'tubepress/default');
     }
     $out = $this->_htmlGenerator->getHtml();
     /* do the standard WordPress widget dance */
     /* @noinspection PhpUndefinedVariableInspection */
     echo $before_widget . $before_title . $this->_context->get(tubepress_wordpress_api_Constants::OPTION_WIDGET_TITLE) . $after_title . $out . $after_widget;
     /* reset the context for the next shortcode */
     $this->_context->setEphemeralOptions(array());
 }