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 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 onRequest(tubepress_api_event_EventInterface $event) { /* * @var tubepress_api_http_message_RequestInterface */ $httpRequest = $event->getSubject(); if (!$this->_shouldExecute($httpRequest)) { return; } $url = $httpRequest->getUrl(); $item = $this->_getCachedItem($url); if ($item->isMiss()) { return; } $response = new tubepress_http_impl_puzzle_PuzzleBasedResponse(new puzzle_message_Response(200, array(self::HTTP_HEADER_CACHE_HIT => 'true'), puzzle_stream_Stream::factory($item->get()))); $event->setArgument('response', $response); $event->stopPropagation(); }
public function onHtmlGeneration(tubepress_api_event_EventInterface $event) { $mediaItemId = $this->_context->get(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID); if ($mediaItemId == '') { return; } /* grab the media item from the provider */ if ($this->_logger->isEnabled()) { $this->_logger->debug(sprintf('Asking provider for video with ID %s', $mediaItemId)); } $mediaItem = $this->_collector->collectSingle($mediaItemId); $eventArgs = array('itemId' => $mediaItemId); if ($mediaItem !== null) { $eventArgs['mediaItem'] = $mediaItem; } $singleHtml = $this->_templating->renderTemplate('single/main', $eventArgs); $event->setSubject($singleHtml); $event->stopPropagation(); }
/** * {@inheritdoc} */ public function stopPropagation() { $this->_delegate->stopPropagation(); }
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); }