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(); }
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 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); }
public function __construct(tubepress_api_options_ContextInterface $context, tubepress_api_http_RequestParametersInterface $requestParams) { $loggingRequested = $requestParams->hasParam('tubepress_debug') && $requestParams->getParamValue('tubepress_debug') === true; $loggingEnabled = $context->get(tubepress_api_options_Names::DEBUG_ON); $this->_enabled = $loggingRequested && $loggingEnabled; $this->_bootMessageBuffer = array(); $this->_shouldBuffer = true; $this->_timezone = new DateTimeZone(@date_default_timezone_get() ? @date_default_timezone_get() : 'UTC'); }
public function run(tubepress_api_event_EventInterface $event) { $errors = array(); $justSubmitted = false; /* are we updating? */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $this->_httpRequestParams->hasParam('tubepress_save')) { $justSubmitted = true; $errors = $this->_form->onSubmit(); } echo $this->_form->getHtml($errors, $justSubmitted); }
public function prependItems(tubepress_api_event_EventInterface $event) { $customVideoId = $this->_requestParams->getParamValue('tubepress_item'); /* they didn't set a custom video id */ if ($customVideoId == '') { return; } if ($this->_shouldLog) { $this->_logDebug(sprintf('Prepending item <code>%s</code> to the gallery', $customVideoId)); } $this->_prependVideo($customVideoId, $event); }
private function _getHtml($vidCount) { $currentPage = $this->_requestParams->getParamValueAsInt('tubepress_page', 1); $vidsPerPage = $this->_context->get(tubepress_api_options_Names::FEED_ADJUSTED_RESULTS_PER_PAGE); if (!$vidsPerPage) { $vidsPerPage = $this->_context->get(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE); } $newurl = $this->_urlFactory->fromCurrent(); if (!$this->_isLegacyTheme()) { return $this->_paginationFromTemplate($vidCount, $currentPage, $vidsPerPage, $newurl); } return $this->_legacyPagination($vidCount, $currentPage, $vidsPerPage, 1, $newurl, 'tubepress_page'); }
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.'); } } }
public function onPostStylesTemplateRender(tubepress_api_event_EventInterface $event) { $html = $event->getSubject(); $page = $this->_requestParameters->getParamValueAsInt('tubepress_page', 1); if ($page > 1) { $html .= "\n" . '<meta name="robots" content="noindex, nofollow" />'; } $event->setSubject($html); }
private function _ensureRequiredParamsPresent() { $required = array_merge($this->getRequiredParamNames(), array('csrf_token', 'provider')); foreach ($required as $key) { if (!$this->_requestParams->hasParam($key)) { $this->bail(sprintf('Missing %s parameter.', $key)); } } }
/** * Filter the content (which may be empty). */ public function printControlHtml() { /* are we saving? */ if ($this->_httpRequestParams->hasParam(self::WIDGET_SUBMIT_TAG)) { $this->_wpFunctions->check_admin_referer('tubepress-widget-nonce-save', 'tubepress-widget-nonce'); $this->_persistence->queueForSave(tubepress_wordpress_api_Constants::OPTION_WIDGET_SHORTCODE, $this->_httpRequestParams->getParamValue('tubepress-widget-tagstring')); $this->_persistence->queueForSave(tubepress_wordpress_api_Constants::OPTION_WIDGET_TITLE, $this->_httpRequestParams->getParamValue('tubepress-widget-title')); $this->_persistence->flushSaveQueue(); } $templateVars = array(self::WIDGET_TITLE => $this->_persistence->fetch(tubepress_wordpress_api_Constants::OPTION_WIDGET_TITLE), self::WIDGET_CONTROL_TITLE => $this->_translator->trans('Title'), self::WIDGET_CONTROL_SHORTCODE => $this->_translator->trans(sprintf('TubePress shortcode for the widget. See the <a href="%s" target="_blank">documentation</a>.', "http://docs.tubepress.com/")), self::WIDGET_SHORTCODE => $this->_persistence->fetch(tubepress_wordpress_api_Constants::OPTION_WIDGET_SHORTCODE), self::WIDGET_SUBMIT_TAG => self::WIDGET_SUBMIT_TAG, self::WIDGET_NONCE_FIELD => $this->_wpFunctions->wp_nonce_field('tubepress-widget-nonce-save', 'tubepress-widget-nonce', true, false)); echo $this->_templating->renderTemplate('wordpress/single-widget-controls', $templateVars); }
/** * {@inheritdoc} */ public function handle() { if ($this->_isDebugEnabled) { $this->_logger->debug('Handling incoming request'); } if (!$this->_requestParameters->hasParam('tubepress_action')) { $this->_errorOut(new RuntimeException('Missing "tubepress_action" parameter'), 400); return; } $actionName = $this->_requestParameters->getParamValue('tubepress_action'); $ajaxEvent = $this->_eventDispatcher->newEventInstance(); try { $this->_eventDispatcher->dispatch(tubepress_api_event_Events::HTTP_AJAX . ".{$actionName}", $ajaxEvent); } catch (Exception $e) { $this->_errorOut($e, 500); return; } $resultingArgs = $ajaxEvent->getArguments(); if (!array_key_exists('handled', $resultingArgs) || !$resultingArgs['handled']) { $this->_errorOut(new RuntimeException('Action not handled'), 400); } }
private function _collectGroupIdsFromSubmission() { $allParams = $this->_httpRequestParams->getAllParams(); $this->_cachedGroupIds = array(); foreach ($allParams as $key => $value) { if (preg_match_all('/^tubepress-multisource-([0-9]+)-.+$/', $key, $matches) !== 1) { continue; } if (!is_array($matches) || count($matches) !== 2 || !is_array($matches[1]) || count($matches[1]) !== 1) { continue; } $this->_cachedGroupIds[] = $matches[1][0]; } $this->_cachedGroupIds = array_values(array_unique($this->_cachedGroupIds)); if ($this->_shouldLog) { $this->_logger->debug(sprintf('Found %d multisource group(s): %s', count($this->_cachedGroupIds), json_encode($this->_cachedGroupIds))); } }
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); }