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 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);
 }
示例#3
0
 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 _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.');
         }
     }
 }
示例#5
0
 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');
 }
示例#6
0
 /**
  * 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);
     }
 }
示例#8
0
 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);
 }