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);
 }
Exemple #2
0
 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 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 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 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 onAcceptableValues(tubepress_api_event_EventInterface $event)
 {
     $current = $event->getSubject();
     if (!is_array($current)) {
         $current = array();
     }
     $event->setSubject(array_merge($current, $this->_acceptableValues));
 }
 public function onMediaItemRequest(tubepress_api_event_EventInterface $event)
 {
     if (!$event->hasArgument('mediaItem')) {
         return;
     }
     $item = $event->getArgument('mediaItem');
     $event = $this->_eventDispatcher->newEventInstance($item);
     $item = $this->_dispatchAndReturnSubject($event, tubepress_api_event_Events::MEDIA_ITEM_NEW);
     $event->setArgument('mediaItem', $item);
 }
 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);
 }
 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));
 }
 /**
  * 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 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 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 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 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 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 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 onAction_widgets_init(tubepress_api_event_EventInterface $event)
 {
     if (!$event->hasArgument('unit-testing') && !class_exists('tubepress_wordpress_impl_wp_WpWidget')) {
         require TUBEPRESS_ROOT . '/src/add-ons/wordpress/classes/tubepress/wordpress/impl/wp/WpWidget.php';
     }
     $this->_wpFunctions->register_widget('tubepress_wordpress_impl_wp_WpWidget');
     /*
      * These next three lines are deprecated!
      */
     $widgetOps = array('classname' => 'widget_tubepress', 'description' => $this->_translator->trans('Displays YouTube or Vimeo videos with TubePress. Limited to a single instance per site. Use the other TubePress widget instead!'));
     //>(translatable)<
     $this->_wpFunctions->wp_register_sidebar_widget('tubepress', 'TubePress (legacy)', array($this, '__fireWidgetHtmlEvent'), $widgetOps);
     $this->_wpFunctions->wp_register_widget_control('tubepress', 'TubePress (legacy)', array($this, '__fireWidgetControlEvent'));
 }
 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);
 }
Exemple #27
0
 public function onGalleryInitJs(tubepress_api_event_EventInterface $event)
 {
     $args = $event->getSubject();
     if (!isset($args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_PLAYER_IMPL])) {
         return;
     }
     $implementation = $args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_PLAYER_IMPL];
     if ($implementation !== 'embedplus') {
         return;
     }
     $existingHeight = $args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_HEIGHT];
     $newHeight = intval($existingHeight) + 30;
     $args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_HEIGHT] = $newHeight;
     $event->setSubject($args);
 }
 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);
 }
 public function onAdminScripts(tubepress_api_event_EventInterface $event)
 {
     $urls = $event->getSubject();
     if (!$this->_isIE8OrLower() || !$this->_containsBootstrap($urls)) {
         return;
     }
     $baseUrl = $this->_environment->getBaseUrl()->getClone();
     $baseUrl->setPath('/web/admin-themes/admin-default/vendor/respond-1.4.2/respond.min.js');
     $baseUrl->freeze();
     array_unshift($urls, $baseUrl);
     $baseUrl = $baseUrl->getClone();
     $baseUrl->setPath('/web/admin-themes/admin-default/vendor/html5-shiv-3.7.0/html5shiv.js');
     $baseUrl->freeze();
     array_unshift($urls, $baseUrl);
     $event->setSubject($urls);
 }
 public function onSingleItemTemplate(tubepress_api_event_EventInterface $event)
 {
     if (!$this->_legacyThemeInUse()) {
         return;
     }
     $existingTemplateVars = $event->getSubject();
     $itemId = $existingTemplateVars[tubepress_api_template_VariableNames::MEDIA_ITEM_ID];
     if (!isset($existingTemplateVars[tubepress_api_template_VariableNames::MEDIA_ITEM])) {
         throw new RuntimeException(sprintf($this->_translator->trans('Video %s not found'), $itemId));
         //>(translatable)<
     }
     $item = $existingTemplateVars[tubepress_api_template_VariableNames::MEDIA_ITEM];
     $existingTemplateVars[tubepress_api_const_template_Variable::VIDEO] = $item;
     $existingTemplateVars[tubepress_api_const_template_Variable::EMBEDDED_WIDTH] = $this->_context->get(tubepress_api_options_Names::EMBEDDED_WIDTH);
     $event->setSubject($existingTemplateVars);
 }