/** * @return string The HTML for this shortcode handler. */ public final function getHtml() { $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService(); $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $rawSearchTerms = $qss->getParamValue(tubepress_spi_const_http_ParamName::SEARCH_TERMS); $hasSearchTerms = $rawSearchTerms != ''; $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); /* if the user isn't searching, don't display anything */ if (!$hasSearchTerms) { if ($shouldLog) { $this->_logger->debug('User doesn\'t appear to be searching. Will not display anything.'); } return ''; } if ($shouldLog) { $this->_logger->debug('User is searching. We\'ll handle this.'); } /* who are we searching? */ switch ($execContext->get(tubepress_api_const_options_names_InteractiveSearch::SEARCH_PROVIDER)) { case 'vimeo': $execContext->set(tubepress_api_const_options_names_Output::GALLERY_SOURCE, tubepress_addons_vimeo_api_const_options_values_GallerySourceValue::VIMEO_SEARCH); $execContext->set(tubepress_addons_vimeo_api_const_options_names_GallerySource::VIMEO_SEARCH_VALUE, $rawSearchTerms); break; default: $execContext->set(tubepress_api_const_options_names_Output::GALLERY_SOURCE, tubepress_addons_youtube_api_const_options_values_GallerySourceValue::YOUTUBE_SEARCH); $execContext->set(tubepress_addons_youtube_api_const_options_names_GallerySource::YOUTUBE_TAG_VALUE, $rawSearchTerms); break; } /* display the results as a thumb gallery */ return $this->_thumbGalleryShortcodeHandler->getHtml(); }
/** * Build the URL for a single video. * * @param string $id The video ID. * * @throws InvalidArgumentException If we can't build a URL for the given ID. * * @return string The URL for the video. */ public final function buildSingleVideoUrl($id) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $requestURL = new ehough_curly_Url("http://gdata.youtube.com/feeds/api/videos/{$id}"); $this->_urlPostProcessingCommon($context, $requestURL); return $this->_finishUrl($requestURL, tubepress_addons_youtube_api_const_YouTubeEventNames::URL_SINGLE); }
/** * Registers all the styles and scripts for the front end. * * @param array $opts The options. * * @return void */ public final function printWidgetHtml($opts) { extract($opts); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $parser = tubepress_impl_patterns_sl_ServiceLocator::getShortcodeParser(); $gallery = tubepress_impl_patterns_sl_ServiceLocator::getShortcodeHtmlGenerator(); /* default widget options */ $defaultWidgetOptions = array(tubepress_api_const_options_names_Thumbs::RESULTS_PER_PAGE => 3, tubepress_api_const_options_names_Meta::VIEWS => false, tubepress_api_const_options_names_Meta::DESCRIPTION => true, tubepress_api_const_options_names_Meta::DESC_LIMIT => 50, tubepress_api_const_options_names_Embedded::PLAYER_LOCATION => 'popup', tubepress_api_const_options_names_Thumbs::THUMB_HEIGHT => 105, tubepress_api_const_options_names_Thumbs::THUMB_WIDTH => 135, tubepress_api_const_options_names_Thumbs::PAGINATE_ABOVE => false, tubepress_api_const_options_names_Thumbs::PAGINATE_BELOW => false, tubepress_api_const_options_names_Thumbs::THEME => 'sidebar', tubepress_api_const_options_names_Thumbs::FLUID_THUMBS => false); /* now apply the user's options */ $rawTag = $context->get(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_SHORTCODE); $widgetTag = tubepress_impl_util_StringUtils::removeNewLines($rawTag); $parser->parse($widgetTag); /* calculate the final options */ $finalOptions = array_merge($defaultWidgetOptions, $context->getCustomOptions()); $context->setCustomOptions($finalOptions); if ($context->get(tubepress_api_const_options_names_Thumbs::THEME) === '') { $context->set(tubepress_api_const_options_names_Thumbs::THEME, 'sidebar'); } try { $out = $gallery->getHtmlForShortcode(''); } catch (Exception $e) { $out = $this->_dispatchErrorAndGetMessage($e); } /* do the standard WordPress widget dance */ /** @noinspection PhpUndefinedVariableInspection */ echo $before_widget . $before_title . $context->get(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_TITLE) . $after_title . $out . $after_widget; /* reset the context for the next shortcode */ $context->reset(); }
private function _wrappedParse($content) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $keyword = $context->get(tubepress_api_const_options_names_Advanced::KEYWORD); if (!$this->somethingToParse($content, $keyword)) { return; } preg_match("/\\[{$keyword}\\b(.*)\\]/", $content, $matches); if ($this->_shouldLog) { $this->_logger->debug(sprintf('Found a shortcode: %s', $matches[0])); } $context->setActualShortcodeUsed($matches[0]); /* Anything matched? */ if (isset($matches[1]) && $matches[1] != '') { $text = preg_replace('/[\\x{00a0}\\x{200b}]+/u', ' ', $matches[1]); $text = self::_convertQuotes($text); $pattern = '/(\\w+)\\s*=\\s*"([^"]*)"(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*\'([^\']*)\'(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*([^\\s\'"]+)(?:\\s*,)?(?:\\s|$)/'; if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) { if ($this->_shouldLog) { $this->_logger->debug(sprintf('Candidate options detected in shortcode: %s', $matches[0])); } $toReturn = $this->_buildNameValuePairArray($match); $context->setCustomOptions($toReturn); } } else { if ($this->_shouldLog) { $this->_logger->debug(sprintf('No custom options detected in shortcode: %s', $matches[0])); } } }
protected function getStatusCodeToHtmlMap() { $executionContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $player = tubepress_impl_patterns_sl_ServiceLocator::getPlayerHtmlGenerator(); $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector(); $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService(); $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($isDebugEnabled) { $this->_logger->debug('Handling incoming request. First parsing shortcode.'); } $nvpMap = $qss->getAllParams(); $videoId = $qss->getParamValue(tubepress_spi_const_http_ParamName::VIDEO); if ($isDebugEnabled) { $this->_logger->debug('Requested video is ' . $videoId); } $executionContext->setCustomOptions($nvpMap); if ($executionContext->get(tubepress_api_const_options_names_Embedded::LAZYPLAY)) { $executionContext->set(tubepress_api_const_options_names_Embedded::AUTOPLAY, true); } if ($isDebugEnabled) { $this->_logger->debug('Now asking video collector for video ' . $videoId); } /* grab the video! */ $video = $provider->collectSingleVideo($videoId); if ($video === null) { return array(404 => "Video {$videoId} not found"); } if ($isDebugEnabled) { $this->_logger->debug('Video collector found video ' . $videoId . '. Sending it to browser'); } $toReturn = array('title' => $video->getAttribute(tubepress_api_video_Video::ATTRIBUTE_TITLE), 'html' => $player->getHtml($video)); return array(200 => json_encode($toReturn)); }
/** * @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; }
/** * Returns the name of the current TubePress theme in use. * * @return string The current theme name, or 'default' if the default theme is in use or if there was a problem. */ public function calculateCurrentThemeName() { $executionContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $currentTheme = $executionContext->get(tubepress_api_const_options_names_Thumbs::THEME); if ($currentTheme == '') { $currentTheme = 'default'; } return $currentTheme; }
/** * @return string The HTML for this shortcode handler. */ public final function getHtml() { $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $videoId = $execContext->get(tubepress_api_const_options_names_Output::VIDEO); if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) { $this->_logger->debug(sprintf('Building single video with ID %s', $videoId)); } return $this->_getSingleVideoHtml($videoId); }
/** * The following options are required by JS, so we explicity set them: * * ajaxPagination * autoNext * embeddedHeight * embeddedWidth * fluidThumbs * httpMethod * playerLocation * * The following options are JS-specific * * playerJsUrl * playerLocationProducesHtml * * Otherwise, we simply set any "custom" options so they can be passed back in via Ajax operations. */ public function onGalleryInitJs(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $args = $event->getSubject(); $requiredNvpMap = $this->_buildRequiredNvpMap($context); $jsMap = $this->_buildJsMap($context); $customNvpMap = $context->getCustomOptions(); $nvpMap = array_merge($requiredNvpMap, $customNvpMap); $newArgs = array(self::$_PROPERTY_NVPMAP => tubepress_impl_context_MemoryExecutionContext::convertBooleans($nvpMap), self::$_PROPERTY_JSMAP => tubepress_impl_context_MemoryExecutionContext::convertBooleans($jsMap)); $event->setSubject(array_merge($args, $newArgs)); }
/** * @return string The HTML for this shortcode handler. */ public final function getHtml() { $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $galleryId = $execContext->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($galleryId == '') { $galleryId = mt_rand(); $result = $execContext->set(tubepress_api_const_options_names_Advanced::GALLERY_ID, $galleryId); if ($result !== true) { return false; } } if ($shouldLog) { $this->_logger->debug(sprintf('Starting to build thumbnail gallery %s', $galleryId)); } $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector(); $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler(); $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService(); $template = $themeHandler->getTemplateInstance('gallery.tpl.php', TUBEPRESS_ROOT . '/src/main/resources/default-themes/default'); $page = $qss->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1); /* first grab the videos */ if ($shouldLog) { $this->_logger->debug('Asking provider for videos'); } $feedResult = $provider->collectVideoGalleryPage(); $numVideos = sizeof($feedResult->getVideos()); if ($shouldLog) { $this->_logger->debug(sprintf('Provider has delivered %d videos', $numVideos)); } if ($numVideos == 0) { return $ms->_('No matching videos'); //>(translatable)< } /* send the template through the listeners */ if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::TEMPLATE_THUMBNAIL_GALLERY)) { $event = new tubepress_spi_event_EventBase($template, array('page' => $page, 'videoGalleryPage' => $feedResult)); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_THUMBNAIL_GALLERY, $event); $template = $event->getSubject(); } $html = $template->toString(); /* send gallery HTML through the listeners */ if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::HTML_THUMBNAIL_GALLERY)) { $event = new tubepress_spi_event_EventBase($html, array('page' => $page, 'videoGalleryPage' => $feedResult)); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::HTML_THUMBNAIL_GALLERY, $event); $html = $event->getSubject(); } /* we're done. tie up */ if ($shouldLog) { $this->_logger->debug(sprintf('Done assembling gallery %d', $galleryId)); } return $html; }
public function onPlayerTemplate(tubepress_api_event_EventInterface $event) { $embedded = tubepress_impl_patterns_sl_ServiceLocator::getEmbeddedHtmlGenerator(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); $template = $event->getSubject(); $video = $event->getArgument('video'); $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_SOURCE, $embedded->getHtml($video->getId())); $template->setVariable(tubepress_api_const_template_Variable::GALLERY_ID, $galleryId); $template->setVariable(tubepress_api_const_template_Variable::VIDEO, $video); $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_WIDTH, $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_WIDTH)); }
/** * Get the HTML for pagination. * * @param int $vidCount The total number of results in this gallery * * @return string The HTML for the pagination. */ private function _getHtml($vidCount) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService(); $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService(); $currentPage = $hrps->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1); $vidsPerPage = $context->get(tubepress_api_const_options_names_Thumbs::RESULTS_PER_PAGE); $newurl = new ehough_curly_Url($qss->getFullUrl($_SERVER)); $newurl->unsetQueryVariable('tubepress_page'); $result = $this->_diggStyle($vidCount, $messageService, $currentPage, $vidsPerPage, 1, $newurl->toString(), 'tubepress_page'); return $result; }
public function onEmbeddedTemplate(tubepress_api_event_EventInterface $event) { $implName = $event->getArgument('embeddedImplementationName'); if ($implName !== 'longtail') { return; } $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $template = $event->getSubject(); $toSet = array(tubepress_addons_jwplayer_api_const_template_Variable::COLOR_FRONT => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_FRONT, tubepress_addons_jwplayer_api_const_template_Variable::COLOR_LIGHT => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_LIGHT, tubepress_addons_jwplayer_api_const_template_Variable::COLOR_SCREEN => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_SCREEN, tubepress_addons_jwplayer_api_const_template_Variable::COLOR_BACK => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_BACK); foreach ($toSet as $templateVariableName => $optionName) { $template->setVariable($templateVariableName, $context->get($optionName)); } }
public function onGalleryTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $htmlGenerator = tubepress_impl_patterns_sl_ServiceLocator::getPlayerHtmlGenerator(); $playerName = $context->get(tubepress_api_const_options_names_Embedded::PLAYER_LOCATION); $providerResult = $event->getArgument('videoGalleryPage'); $videos = $providerResult->getVideos(); $template = $event->getSubject(); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); $playerHtml = $playerHtml = $this->_showPlayerHtmlOnPageLoad($playerName) ? $htmlGenerator->getHtml($videos[0], $galleryId) : ''; $template->setVariable(tubepress_api_const_template_Variable::PLAYER_HTML, $playerHtml); $template->setVariable(tubepress_api_const_template_Variable::PLAYER_NAME, $playerName); }
public function onSingleVideoTemplate(tubepress_api_event_EventInterface $event) { $video = $event->getArgument('video'); $template = $event->getSubject(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $embedded = tubepress_impl_patterns_sl_ServiceLocator::getEmbeddedHtmlGenerator(); $embeddedString = $embedded->getHtml($video->getId()); $width = $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_WIDTH); /* apply it to the template */ $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_SOURCE, $embeddedString); $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_WIDTH, $width); $template->setVariable(tubepress_api_const_template_Variable::VIDEO, $video); }
public function buildCache() { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $dir = $context->get(tubepress_api_const_options_names_Cache::CACHE_DIR); if (!$dir || !is_writable($dir)) { @mkdir($dir, 0755, true); } if (!$dir || !is_writable($dir)) { $fs = tubepress_impl_patterns_sl_ServiceLocator::getFileSystem(); $dir = $fs->getSystemTempDirectory() . DIRECTORY_SEPARATOR . 'tubepress-api-cache'; } return new ehough_stash_Pool(new ehough_stash_driver_FileSystem(array('path' => $dir))); }
public function onGalleryTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $videoGalleryPage = $event->getArgument('videoGalleryPage'); $template = $event->getSubject(); $videoArray = $videoGalleryPage->getVideos(); $thumbWidth = $context->get(tubepress_api_const_options_names_Thumbs::THUMB_WIDTH); $thumbHeight = $context->get(tubepress_api_const_options_names_Thumbs::THUMB_HEIGHT); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); /* add some core template variables */ $template->setVariable(tubepress_api_const_template_Variable::VIDEO_ARRAY, $videoArray); $template->setVariable(tubepress_api_const_template_Variable::GALLERY_ID, $galleryId); $template->setVariable(tubepress_api_const_template_Variable::THUMBNAIL_WIDTH, $thumbWidth); $template->setVariable(tubepress_api_const_template_Variable::THUMBNAIL_HEIGHT, $thumbHeight); }
/** * Stores a value into the cache. * * The $value argument can be any item that can be serialized by PHP, * although the method of serialization is left up to the Implementing * Library. * * The $ttl can be defined in a number of ways. As an integer or * DateInverval object the argument defines how long before the cache should * expire. As a DateTime object the argument defines the actual expiration * time of the object. Implementations are allowed to use a lower time than * passed, but should not use a longer one. * * If no $ttl is passed then the item can be stored indefinitely or a * default value can be set by the Implementing Library. * * Returns true if the item was successfully stored. * * @param mixed $value * @param int|DateInterval|DateTime $ttl * * @return bool */ public function set($value, $ttl = null) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $cleaningFactor = $context->get(tubepress_api_const_options_names_Cache::CACHE_CLEAN_FACTOR); $cleaningFactor = intval($cleaningFactor); /** * Handle cleaning factor. */ if ($cleaningFactor > 0 && rand(1, $cleaningFactor) === 1) { $this->_parentCache->flush(); } if ($ttl === null) { $ttl = intval($context->get(tubepress_api_const_options_names_Cache::CACHE_LIFETIME_SECONDS)); } return $this->_delegate->set($value, $ttl); }
private static function _getEmbeddedServiceName(tubepress_api_video_VideoGalleryPage $page) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $stored = $context->get(tubepress_api_const_options_names_Embedded::PLAYER_IMPL); $videoArray = $page->getVideos(); /** * @var $randomVideo tubepress_api_video_Video */ $randomVideo = $videoArray[array_rand($videoArray)]; $provider = $randomVideo->getAttribute(tubepress_api_video_Video::ATTRIBUTE_PROVIDER_NAME); $longTailWithYouTube = $stored === 'longtail' && $provider === 'youtube'; $embedPlusWithYouTube = $stored === 'embedplus' && $provider === 'youtube'; if ($longTailWithYouTube || $embedPlusWithYouTube) { return $stored; } return $provider; }
public function onEmbeddedTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $environment = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector(); $template = $event->getSubject(); $dataUrl = $event->getArgument('dataUrl'); $videoId = $event->getArgument('videoId'); $providerName = $event->getArgument('providerName'); $autoPlay = $context->get(tubepress_api_const_options_names_Embedded::AUTOPLAY); $embedWidth = $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_WIDTH); $embedHeight = $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_HEIGHT); $vars = array(tubepress_api_const_template_Variable::EMBEDDED_DATA_URL => $dataUrl->toString(true), tubepress_api_const_template_Variable::TUBEPRESS_BASE_URL => $environment->getBaseUrl(), tubepress_api_const_template_Variable::EMBEDDED_AUTOSTART => tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToString($autoPlay), tubepress_api_const_template_Variable::EMBEDDED_WIDTH => $embedWidth, tubepress_api_const_template_Variable::EMBEDDED_HEIGHT => $embedHeight, tubepress_api_const_template_Variable::VIDEO_ID => $videoId, tubepress_api_const_template_Variable::VIDEO_DOM_ID => $this->_getVideoDomId($providerName, $dataUrl), tubepress_api_const_template_Variable::EMBEDDED_IMPL_NAME => $event->getArgument('embeddedImplementationName'), tubepress_api_const_template_Variable::VIDEO_PROVIDER_NAME => $providerName); foreach ($vars as $key => $value) { $template->setVariable($key, $value); } return $template; }
public function onSingleVideoTemplate(tubepress_api_event_EventInterface $event) { $template = $event->getSubject(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); $optionDescriptorReference = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference(); $metaNames = tubepress_impl_util_LangUtils::getDefinedConstants('tubepress_api_const_options_names_Meta'); $shouldShow = array(); $labels = array(); foreach ($metaNames as $metaName) { $optionDescriptor = $optionDescriptorReference->findOneByName($metaName); $shouldShow[$metaName] = $context->get($metaName); $labels[$metaName] = $messageService->_($optionDescriptor->getLabel()); } $template->setVariable(tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow); $template->setVariable(tubepress_api_const_template_Variable::META_LABELS, $labels); }
/** * Fetches the feed from the remote provider * * @param string $url The URL to fetch. * * @return mixed The raw feed from the provider, or null if there was a problem. */ public final function fetch($url) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $cacheEnabled = $context->get(tubepress_api_const_options_names_Cache::CACHE_ENABLED); $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($cacheEnabled) { $data = $this->_getFromCache($url, $context, $isDebugEnabled); } else { if ($isDebugEnabled) { $this->_logger->debug(sprintf('Skip cache check for <a href="%s">URL</a>', $url)); } $data = $this->_getFromNetwork($url); } if ($isDebugEnabled) { $this->_logger->debug(sprintf('Raw result for <a href="%s">URL</a> is in the HTML source for this page. <span style="display:none">%s</span>', $url, htmlspecialchars($data))); } return $data; }
/** * @return string The HTML for this shortcode handler. */ public final function getHtml() { $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService(); $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $videoId = $qss->getParamValue(tubepress_spi_const_http_ParamName::VIDEO); $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($shouldLog) { $this->_logger->debug(sprintf('Building single video with ID %s', $videoId)); } $result = $execContext->set(tubepress_api_const_options_names_Output::VIDEO, $videoId); if ($result !== true) { if ($shouldLog) { $this->_logger->debug('Could not verify video ID.'); } return false; } /* display the results as a thumb gallery */ return $this->_singleVideoShortcodeHandler->getHtml(); }
public function onGalleryHtml(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); $jsEvent = new tubepress_spi_event_EventBase(array()); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::CSS_JS_GALLERY_INIT, $jsEvent); $args = $jsEvent->getSubject(); $asJson = json_encode($args); $html = $event->getSubject(); $toReturn = $html . <<<EOT <script type="text/javascript"> var tubePressDomInjector = tubePressDomInjector || [], tubePressGalleryRegistrar = tubePressGalleryRegistrar || []; tubePressDomInjector.push(['loadGalleryJs']); tubePressGalleryRegistrar.push(['register', '{$galleryId}', {$asJson} ]); </script> EOT; $event->setSubject($toReturn); }
public function onVideoGalleryPage(tubepress_api_event_EventInterface $event) { $videos = $event->getSubject()->getVideos(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $blacklist = $context->get(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 */ $event->getSubject()->setVideos($videosToKeep); }
public function onVideoGalleryPage(tubepress_api_event_EventInterface $event) { $totalResults = $event->getSubject()->getTotalResultCount(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $limit = $context->get(tubepress_api_const_options_names_Feed::RESULT_COUNT_CAP); $firstCut = $limit == 0 ? $totalResults : min($limit, $totalResults); $secondCut = min($firstCut, self::_calculateRealMax($context, $firstCut)); $videos = $event->getSubject()->getVideos(); $resultCount = count($videos); $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($shouldLog) { $this->_logger->debug(sprintf('Effective total result count (taking into account user-defined limit) is %d video(s)', $secondCut)); } if ($resultCount > $secondCut) { if ($shouldLog) { $this->_logger->debug(sprintf('Result has %d video(s), limit is %d. So we\'re chopping it down.', $resultCount, $secondCut)); } $event->getSubject()->setVideos(array_splice($videos, 0, $secondCut - $resultCount)); } $event->getSubject()->setTotalResultCount($secondCut); }
public function onVideoGalleryPage(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $perPageSortOrder = $context->get(tubepress_api_const_options_names_Feed::PER_PAGE_SORT); $feedSortOrder = $context->get(tubepress_api_const_options_names_Feed::ORDER_BY); $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); /** No sort requested? */ if ($perPageSortOrder === tubepress_api_const_options_values_PerPageSortValue::NONE) { if ($shouldLog) { $this->_logger->debug('Requested per-page sort order is "none". Not applying per-page sorting.'); } return; } /** Grab a handle to the videos. */ $videos = $event->getSubject()->getVideos(); if ($perPageSortOrder === tubepress_api_const_options_values_PerPageSortValue::RANDOM) { if ($shouldLog) { $this->_logger->debug('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)) { if ($shouldLog) { $this->_logger->debug(sprintf('Now sorting %s videos on page (%s)', count($videos), $perPageSortOrder)); } uasort($videos, array($this, $sortCallback)); } else { if ($shouldLog) { $this->_logger->debug(sprintf('No sort available for this page (%s)', $perPageSortOrder)); } } } $videos = array_values($videos); /** Modify the feed result. */ $event->getSubject()->setVideos($videos); }
/** * @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; }
/** * Collects a video gallery page. * * @return tubepress_api_video_VideoGalleryPage The video gallery page, never null. */ public final function collectVideoGalleryPage() { $this->_isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); $executionContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $videoSource = $executionContext->get(tubepress_api_const_options_names_Output::GALLERY_SOURCE); $result = null; $providerName = null; $currentPage = $this->_getCurrentPage(); if ($this->_isDebugEnabled) { $this->_logger->debug('There are ' . count($this->_videoProviders) . ' pluggable video provider service(s) registered'); $this->_logger->debug('Asking to see who wants to handle page ' . $currentPage . ' for gallery source "' . $videoSource . '"'); } foreach ($this->_videoProviders as $videoProvider) { $sources = $videoProvider->getGallerySourceNames(); if (in_array($videoSource, $sources)) { if ($this->_isDebugEnabled) { $this->_logger->debug($videoProvider->getName() . ' chosen to handle page ' . $currentPage . ' for gallery source "' . $videoSource . '"'); } $result = $videoProvider->fetchVideoGalleryPage($currentPage); break; } if ($this->_isDebugEnabled) { $this->_logger->debug($videoProvider->getName() . ' cannot handle ' . $currentPage . ' for gallery source "' . $videoSource . '"'); } } if ($result === null) { if ($this->_isDebugEnabled) { $this->_logger->debug('No video providers could handle this request'); } $result = new tubepress_api_video_VideoGalleryPage(); } $event = new tubepress_spi_event_EventBase($result); $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::VIDEO_GALLERY_PAGE, $event); return $event->getSubject(); }
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)< }