public function onResponse(tubepress_api_event_EventInterface $event) { /* * @var tubepress_api_http_message_RequestInterface */ $httpRequest = $event->getArgument('request'); if (!$this->_shouldExecute($httpRequest)) { return; } /** * @var $httpResponse tubepress_api_http_message_ResponseInterface */ $httpResponse = $event->getSubject(); if ($httpResponse->hasHeader(self::HTTP_HEADER_CACHE_HIT)) { return; } $url = $httpRequest->getUrl(); $body = $httpResponse->getBody(); $result = $this->_getItem($url); $this->_possiblyClearCache(); $toStore = $body ? $body->toString() : ''; $storedSuccessfully = $result->set($toStore, intval($this->_context->get(tubepress_api_options_Names::CACHE_LIFETIME_SECONDS))); if (!$storedSuccessfully) { if ($this->_logger->isEnabled()) { $this->_logger->error('Unable to store data to cache'); } } }
public function onFilter_PucRequestInfoResultTubePress(tubepress_api_event_EventInterface $event) { $pluginInfo = $event->getSubject(); if ($pluginInfo && $this->_environment->isPro()) { $apiKey = $this->_context->get(tubepress_api_options_Names::TUBEPRESS_API_KEY); if (!$apiKey) { /* * We don't want to downgrade Pro users that haven't entered an API key. */ $pluginInfo->download_url = null; } if (property_exists($pluginInfo, 'download_url') && strpos($pluginInfo->download_url, 'free') !== false) { /* * Extra assurance that we don't downgrade Pro users */ $pluginInfo->download_url = null; } if (property_exists($pluginInfo, 'download_url') && $pluginInfo->download_url && $apiKey) { $url = $this->_urlFactory->fromString($pluginInfo->download_url); $url->getQuery()->set('key', $apiKey)->set('pid', 2); $pluginInfo->download_url = $url->toString(); } $event->setSubject($pluginInfo); } }
public function onSearchInputTemplatePreRender(tubepress_api_event_EventInterface $event) { /* * @var array */ $existingTemplateVars = $event->getSubject(); $resultsUrl = $this->_context->get(tubepress_api_options_Names::SEARCH_RESULTS_URL); $url = ''; try { $url = $this->_urlFactory->fromString($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 = $this->_urlFactory->fromCurrent(); } /* clean up the search terms a bit */ $searchTerms = $this->_requestParams->getParamValue('tubepress_search'); $searchTerms = urldecode($searchTerms); /* * 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->getQuery(); $params->remove('tubepress_page'); $params->remove('tubepress_search'); /* apply the template variables */ $newVars = array(tubepress_api_template_VariableNames::SEARCH_HANDLER_URL => $url->toString(), tubepress_api_template_VariableNames::SEARCH_HIDDEN_INPUTS => $params->toArray(), tubepress_api_template_VariableNames::SEARCH_TERMS => $searchTerms); $existingTemplateVars = array_merge($existingTemplateVars, $newVars); $event->setSubject($existingTemplateVars); }
public function onScriptsStylesTemplatePreRender(tubepress_api_event_EventInterface $event) { $templateVars = $event->getSubject(); if (is_array($templateVars)) { $templateVars['urls'] = array(); $event->setSubject($templateVars); } }
public function onAcceptableValues(tubepress_api_event_EventInterface $event) { $current = $event->getSubject(); if (!is_array($current)) { $current = array(); } $event->setSubject(array_merge($current, $this->_acceptableValues)); }
public function onRequest(tubepress_api_event_EventInterface $event) { /* * @var tubepress_api_http_message_RequestInterface */ $request = $event->getSubject(); $request->setHeader('User-Agent', $this->_getUserAgent()); }
public function onGalleryTemplatePreRender(tubepress_api_event_EventInterface $event) { $currentTemplateVars = $event->getSubject(); $mediaPage = $currentTemplateVars['mediaPage']; $pagination = $this->_getHtml($mediaPage->getTotalResultCount()); $newTemplateVars = array_merge($currentTemplateVars, array(tubepress_api_template_VariableNames::GALLERY_PAGINATION_HTML => $pagination, tubepress_api_template_VariableNames::GALLERY_PAGINATION_SHOW_TOP => (bool) $this->_context->get(tubepress_api_options_Names::GALLERY_PAGINATE_ABOVE), tubepress_api_template_VariableNames::GALLERY_PAGINATION_SHOW_BOTTOM => (bool) $this->_context->get(tubepress_api_options_Names::GALLERY_PAGINATE_BELOW))); $event->setSubject($newTemplateVars); }
public function onHttpItem(tubepress_api_event_EventInterface $event) { $mediaItem = $event->getSubject(); $attributeMap = $this->buildAttributeMap($event); foreach ($attributeMap as $attributeName => $attributeValue) { $mediaItem->setAttribute($attributeName, $attributeValue); } $this->_formatAttributes($mediaItem); }
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 onPreValidationOptionSet(tubepress_api_event_EventInterface $event) { $name = $event->getArgument('optionName'); if (!in_array($name, $this->_applicableOptionNames)) { return; } $value = $event->getSubject(); $value = $this->_stripLeadingHash($value); $event->setSubject($value); }
/** * 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)); }
private function _handle(tubepress_api_event_EventInterface $event, $methodName) { $current = $event->getSubject(); if (!is_array($current)) { $current = array(); } foreach ($this->_mediaProviders as $provider) { $current = array_merge($current, $provider->{$methodName}()); } $event->setSubject($current); }
public function onPreValidationOptionSet(tubepress_api_event_EventInterface $event) { $name = $event->getArgument('optionName'); /** We only care about playlistValue. */ if ($name !== tubepress_addons_youtube_api_const_options_names_GallerySource::YOUTUBE_PLAYLIST_VALUE) { return; } $filteredValue = $this->_maybeGetListValueFromUrl($event->getSubject()); $filteredValue = $this->_maybeRemoveLeadingPL($filteredValue); $event->setSubject($filteredValue); }
private function _prependVideo($id, tubepress_api_event_EventInterface $event, $shouldLog) { $videos = $event->getSubject()->getVideos(); /* see if the array already has it */ if (self::_videoArrayAlreadyHasVideo($videos, $id)) { $videos = self::_moveVideoUpFront($videos, $id); $event->getSubject()->setVideos($videos); return; } try { $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector(); $video = $provider->collectSingleVideo($id); array_unshift($videos, $video); } catch (Exception $e) { if ($shouldLog) { $this->_logger->debug(sprintf('Could not prepend video %s to the gallery: %s', $id, $e->getMessage())); } } /* modify the feed result */ $event->getSubject()->setVideos($videos); }
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)); }
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); }
/** * Filter the content (which may be empty). */ public function onFilter_row_meta(tubepress_api_event_EventInterface $event) { $links = $event->getSubject(); $args = $event->getArgument('args'); $file = $args[0]; $plugin = $this->_wpFunctions->plugin_basename(basename(TUBEPRESS_ROOT) . '/tubepress.php'); if ($file != $plugin) { return; } $toReturn = array_merge($links, array(sprintf('<a href="options-general.php?page=tubepress.php">%s</a>', $this->_wpFunctions->__('Settings', 'tubepress')), sprintf('<a href="http://support.tubepress.com/">Support</a>'))); $event->setSubject($toReturn); }
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 onPreTemplate(tubepress_api_event_EventInterface $event) { /* * @var array */ $templateVars = $event->getSubject(); if (!is_array($templateVars)) { $templateVars = array(); } $vars = array(tubepress_api_template_VariableNames::MEDIA_ITEM_ATTRIBUTE_LABELS => $this->_getLabelMap(), tubepress_api_template_VariableNames::MEDIA_ITEM_ATTRIBUTES_TO_SHOW => $this->_getToShowMap()); $templateVars = array_merge($templateVars, $vars); $event->setSubject($templateVars); }
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 onPreScriptsHtml(tubepress_api_event_EventInterface $event) { $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $jsEvent = new tubepress_spi_event_EventBase(array()); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::CSS_JS_GLOBAL_JS_CONFIG, $jsEvent); $args = $jsEvent->getSubject(); $asJson = json_encode($args); $html = $event->getSubject(); $toPrepend = <<<EOT <script type="text/javascript">var TubePressJsConfig = {$asJson};</script> EOT; $event->setSubject($toPrepend . $html); }
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 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); }
public function onVideoConstruction(tubepress_api_event_EventInterface $event) { $video = $event->getSubject(); /* * Short circuit for videos belonging to someone else. */ if ($video->getAttribute(tubepress_api_video_Video::ATTRIBUTE_PROVIDER_NAME) !== $this->getHandledProviderName()) { return; } $attributeMap = $this->buildAttributeMap($event); foreach ($attributeMap as $attributeName => $attributeValue) { $video->setAttribute($attributeName, $attributeValue); } }
public function onOption(tubepress_api_event_EventInterface $event) { $incoming = (string) $event->getArgument('optionValue'); $final = $this->_transformer->transform($incoming); if (!$final && !$this->_allowEmpty) { $errors = $event->getSubject(); $errors[] = $this->_errorMessage; $event->setSubject($errors); } else { if ($incoming !== $final) { $event->setArgument('optionValue', $final); } } }
public function onOptionValidation(tubepress_api_event_EventInterface $event) { $errors = $event->getSubject(); $optionName = $event->getArgument('optionName'); $optionValue = $event->getArgument('optionValue'); if (!$this->isValid($optionName, $optionValue)) { $template = $this->getErrorMessageTemplate(); $error = $this->_translator->trans($template); $error = sprintf($error, $this->_getLabel($optionName)); $errors[] = $error; $event->setSubject($errors); $event->stopPropagation(); } }
public function onJsConfig(tubepress_api_event_EventInterface $event) { /** * @var $config array */ $config = $event->getSubject(); $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector(); if (!isset($config['urls'])) { $config['urls'] = array(); } $config['urls']['base'] = $environmentDetector->getBaseUrl(); $config['urls']['usr'] = $environmentDetector->getUserContentUrl(); $event->setSubject($config); }
public function onOptionSet(tubepress_api_event_EventInterface $event) { if (!$this->_logger->isEnabled()) { return; } $errors = $event->getSubject(); $optionName = $event->getArgument('optionName'); $optionValue = $event->getArgument('optionValue'); if (count($errors) === 0) { $this->_logger->debug(sprintf('(Option Logger) Accepted valid value: <code>%s</code> = <code>%s</code>', $optionName, $this->_stringUtils->redactSecrets($optionValue))); } else { $this->_logger->error(sprintf('(Option Logger) Rejecting invalid value: <code>%s</code> = <code>%s</code> (%s)', $optionName, $this->_stringUtils->redactSecrets($optionValue), $errors[0])); } }
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); }
public function onAcceptableValues(tubepress_api_event_EventInterface $event) { $current = $event->getSubject(); if (!is_array($current)) { $current = array(); } $result = array(); $allThemes = $this->_themeRegistry->getAll(); foreach ($allThemes as $theme) { $result[$theme->getName()] = $theme->getTitle(); } ksort($result); $toSet = array_merge($current, $result); $event->setSubject($toSet); }