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 onPreValidationSet(tubepress_api_event_EventInterface $event)
 {
     $themeValue = $event->getArgument('optionValue');
     $shouldLog = $this->_logger->isEnabled();
     if (in_array($themeValue, self::$_LEGACY_THEME_VALUES)) {
         if ($shouldLog) {
             $this->_logger->debug(sprintf('Renaming theme value from %s to tubepress/legacy-%s', $themeValue, $themeValue));
         }
         $event->setArgument('optionValue', "tubepress/legacy-{$themeValue}");
         return;
     }
     $allThemes = $this->_themeRegistry->getAll();
     foreach ($allThemes as $theme) {
         if ($theme->getName() !== "unknown/legacy-{$themeValue}") {
             continue;
         }
         if ($shouldLog) {
             $this->_logger->debug(sprintf('Renaming theme value from %s to unknown/legacy-%s', $themeValue, $themeValue));
         }
         $event->setArgument('optionValue', "unknown/legacy-{$themeValue}");
     }
 }
示例#3
0
 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);
         }
     }
 }
示例#4
0
 public function onOption(tubepress_api_event_EventInterface $event)
 {
     $optionValue = $event->getArgument('optionValue');
     if (!is_scalar($optionValue)) {
         return;
     }
     if ($this->_ltrim) {
         $optionValue = ltrim($optionValue, $this->_charlist);
     } else {
         if ($this->_rtrim) {
             $optionValue = rtrim($optionValue, $this->_charlist);
         } else {
             $optionValue = trim($optionValue, $this->_charlist);
         }
     }
     $event->setArgument('optionValue', $optionValue);
 }
示例#5
0
 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 onMediaItemRequest(tubepress_api_event_EventInterface $event)
 {
     $itemId = $event->getSubject();
     $provider = null;
     foreach ($this->_mediaProviders as $mediaProvider) {
         if ($mediaProvider->ownsItem($itemId)) {
             $provider = $mediaProvider;
             break;
         }
     }
     if ($provider === null) {
         return;
     }
     $item = $provider->collectSingle($itemId);
     if ($item !== null) {
         $item->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $provider);
     }
     $event->setArgument('mediaItem', $item);
 }
示例#7
0
 public function onShortcode(tubepress_api_event_EventInterface $incomingEvent)
 {
     $subject = $incomingEvent->getSubject();
     $rawShortcodeAttributes = $subject[0];
     $rawShortcodeContent = isset($subject[1]) ? $subject[1] : '';
     if (!is_array($rawShortcodeAttributes)) {
         $rawShortcodeAttributes = array();
     }
     if ($this->_loggingEnabled) {
         $this->_logRawShortcode($rawShortcodeAttributes, $rawShortcodeContent);
     }
     $normalizedOptions = $this->_normalizeIncomingShortcodeOptionMap($rawShortcodeAttributes);
     $this->_context->setEphemeralOptions($normalizedOptions);
     $event = $this->_buildShortcodeEvent($normalizedOptions, $rawShortcodeContent);
     $this->_eventDispatcher->dispatch(tubepress_wordpress_api_Constants::SHORTCODE_PARSED, $event);
     /* Get the HTML for this particular shortcode. */
     $toReturn = $this->_htmlGenerator->getHtml();
     /* reset the context for the next shortcode */
     $this->_context->setEphemeralOptions(array());
     $incomingEvent->setArgument('result', $toReturn);
 }
 public function onSet(tubepress_api_event_EventInterface $event)
 {
     $value = $event->getArgument('optionValue');
     $this->_magic($value);
     $event->setArgument('optionValue', $value);
 }
 protected final function onBeforeFiringVideoConstructionEvent(tubepress_api_event_EventInterface $event)
 {
     $event->setArgument('unserializedFeed', $this->_unserialized);
     $event->setArgument('videoArray', $this->_videoArray);
 }
 protected final function onBeforeFiringVideoConstructionEvent(tubepress_api_event_EventInterface $event)
 {
     $event->setArgument('domDocument', $this->_domDocument);
     $event->setArgument('xPath', $this->_xpath);
 }
 public function onGroupValue(tubepress_api_event_EventInterface $event)
 {
     $filteredValue = $this->_maybeConvertUrl($event->getArgument('optionValue'), 'groups');
     $event->setArgument('optionValue', $filteredValue);
 }
 /**
  * {@inheritdoc}
  */
 public function setArgument($key, $value)
 {
     return $this->_delegate->setArgument($key, $value);
 }
 public function onListValue(tubepress_api_event_EventInterface $event)
 {
     $filteredValue = $this->_normalizeListValue($event->getArgument('optionValue'));
     $event->setArgument('optionValue', $filteredValue);
 }
 private function _handleIncomingTerms(array $registeredTerms, tubepress_api_event_EventInterface $event, $name)
 {
     $optionValue = $event->getArgument('optionValue');
     if (!$optionValue) {
         //no tags or categories requested
         return;
     }
     $exploded = preg_split('~\\s*,\\s*~', $optionValue);
     if (!is_array($exploded)) {
         //this should never happen, right?
         return;
     }
     $toKeep = array();
     foreach ($exploded as $incomingTerm) {
         foreach ($registeredTerms as $registeredTerm) {
             if ($registeredTerm->slug === $incomingTerm) {
                 $toKeep[] = $incomingTerm;
                 break;
             }
         }
     }
     if (count($toKeep) === 0) {
         $newValue = null;
     } else {
         $toKeep = array_unique($toKeep);
         $newValue = implode(',', $toKeep);
     }
     $event->setArgument('optionValue', $newValue);
 }