/**
  * Filter the content (which may be empty).
  */
 public final function printControlHtml()
 {
     $wpsm = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager();
     $msg = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $tplBuilder = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     /* are we saving? */
     if ($hrps->hasParam(self::WIDGET_SUBMIT_TAG)) {
         self::_verifyNonce();
         $wpsm->queueForSave(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_SHORTCODE, $hrps->getParamValue('tubepress-widget-tagstring'));
         $wpsm->queueForSave(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_TITLE, $hrps->getParamValue('tubepress-widget-title'));
         $wpsm->flushSaveQueue();
     }
     /* load up the gallery template */
     $templatePath = TUBEPRESS_ROOT . '/src/main/php/add-ons/wordpress/resources/templates/widget_controls.tpl.php';
     $tpl = $tplBuilder->getNewTemplateInstance($templatePath);
     /* set up the template */
     $tpl->setVariable(self::WIDGET_TITLE, $wpsm->fetch(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_TITLE));
     $tpl->setVariable(self::WIDGET_CONTROL_TITLE, $msg->_('Title'));
     //>(translatable)<
     $tpl->setVariable(self::WIDGET_CONTROL_SHORTCODE, $msg->_('TubePress shortcode for the widget. See the <a href="http://tubepress.com/documentation" target="_blank">documentation</a>.'));
     //>(translatable)<
     $tpl->setVariable(self::WIDGET_SHORTCODE, $wpsm->fetch(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_SHORTCODE));
     $tpl->setVariable(self::WIDGET_SUBMIT_TAG, self::WIDGET_SUBMIT_TAG);
     /* get the template's output */
     echo $tpl->toString();
 }
 /**
  * @return string The HTML for this shortcode handler.
  */
 public final function getHtml()
 {
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $rawSearchTerms = $qss->getParamValue(tubepress_spi_const_http_ParamName::SEARCH_TERMS);
     $hasSearchTerms = $rawSearchTerms != '';
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     /* if the user isn't searching, don't display anything */
     if (!$hasSearchTerms) {
         if ($shouldLog) {
             $this->_logger->debug('User doesn\'t appear to be searching. Will not display anything.');
         }
         return '';
     }
     if ($shouldLog) {
         $this->_logger->debug('User is searching. We\'ll handle this.');
     }
     /* who are we searching? */
     switch ($execContext->get(tubepress_api_const_options_names_InteractiveSearch::SEARCH_PROVIDER)) {
         case 'vimeo':
             $execContext->set(tubepress_api_const_options_names_Output::GALLERY_SOURCE, tubepress_addons_vimeo_api_const_options_values_GallerySourceValue::VIMEO_SEARCH);
             $execContext->set(tubepress_addons_vimeo_api_const_options_names_GallerySource::VIMEO_SEARCH_VALUE, $rawSearchTerms);
             break;
         default:
             $execContext->set(tubepress_api_const_options_names_Output::GALLERY_SOURCE, tubepress_addons_youtube_api_const_options_values_GallerySourceValue::YOUTUBE_SEARCH);
             $execContext->set(tubepress_addons_youtube_api_const_options_names_GallerySource::YOUTUBE_TAG_VALUE, $rawSearchTerms);
             break;
     }
     /* display the results as a thumb gallery */
     return $this->_thumbGalleryShortcodeHandler->getHtml();
 }
 protected function getStatusCodeToHtmlMap()
 {
     $executionContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $player = tubepress_impl_patterns_sl_ServiceLocator::getPlayerHtmlGenerator();
     $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($isDebugEnabled) {
         $this->_logger->debug('Handling incoming request. First parsing shortcode.');
     }
     $nvpMap = $qss->getAllParams();
     $videoId = $qss->getParamValue(tubepress_spi_const_http_ParamName::VIDEO);
     if ($isDebugEnabled) {
         $this->_logger->debug('Requested video is ' . $videoId);
     }
     $executionContext->setCustomOptions($nvpMap);
     if ($executionContext->get(tubepress_api_const_options_names_Embedded::LAZYPLAY)) {
         $executionContext->set(tubepress_api_const_options_names_Embedded::AUTOPLAY, true);
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Now asking video collector for video ' . $videoId);
     }
     /* grab the video! */
     $video = $provider->collectSingleVideo($videoId);
     if ($video === null) {
         return array(404 => "Video {$videoId} not found");
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Video collector found video ' . $videoId . '. Sending it to browser');
     }
     $toReturn = array('title' => $video->getAttribute(tubepress_api_video_Video::ATTRIBUTE_TITLE), 'html' => $player->getHtml($video));
     return array(200 => json_encode($toReturn));
 }
 /**
  * Invoked when the element is submitted by the user.
  *
  * @return string|null A string error message to be displayed to the user, or null if no problem.
  */
 public function onSubmit()
 {
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $fieldName = tubepress_api_const_options_names_Output::GALLERY_SOURCE;
     if (!$hrps->hasParam($fieldName)) {
         return null;
     }
     return $this->sendToStorage($fieldName, $hrps->getParamValue($fieldName));
 }
 private function _addMetaTags($html)
 {
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $page = $qss->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     if ($page > 1) {
         $html .= "\n" . '<meta name="robots" content="noindex, nofollow" />';
     }
     return $html;
 }
 /**
  * @return string The HTML for this shortcode handler.
  */
 public final function getHtml()
 {
     $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $galleryId = $execContext->get(tubepress_api_const_options_names_Advanced::GALLERY_ID);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($galleryId == '') {
         $galleryId = mt_rand();
         $result = $execContext->set(tubepress_api_const_options_names_Advanced::GALLERY_ID, $galleryId);
         if ($result !== true) {
             return false;
         }
     }
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Starting to build thumbnail gallery %s', $galleryId));
     }
     $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector();
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler();
     $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $template = $themeHandler->getTemplateInstance('gallery.tpl.php', TUBEPRESS_ROOT . '/src/main/resources/default-themes/default');
     $page = $qss->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     /* first grab the videos */
     if ($shouldLog) {
         $this->_logger->debug('Asking provider for videos');
     }
     $feedResult = $provider->collectVideoGalleryPage();
     $numVideos = sizeof($feedResult->getVideos());
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Provider has delivered %d videos', $numVideos));
     }
     if ($numVideos == 0) {
         return $ms->_('No matching videos');
         //>(translatable)<
     }
     /* send the template through the listeners */
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::TEMPLATE_THUMBNAIL_GALLERY)) {
         $event = new tubepress_spi_event_EventBase($template, array('page' => $page, 'videoGalleryPage' => $feedResult));
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_THUMBNAIL_GALLERY, $event);
         $template = $event->getSubject();
     }
     $html = $template->toString();
     /* send gallery HTML through the listeners */
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::HTML_THUMBNAIL_GALLERY)) {
         $event = new tubepress_spi_event_EventBase($html, array('page' => $page, 'videoGalleryPage' => $feedResult));
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::HTML_THUMBNAIL_GALLERY, $event);
         $html = $event->getSubject();
     }
     /* we're done. tie up */
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Done assembling gallery %d', $galleryId));
     }
     return $html;
 }
 /**
  * Get the HTML for pagination.
  *
  * @param int $vidCount The total number of results in this gallery
  *
  * @return string The HTML for the pagination.
  */
 private function _getHtml($vidCount)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $currentPage = $hrps->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     $vidsPerPage = $context->get(tubepress_api_const_options_names_Thumbs::RESULTS_PER_PAGE);
     $newurl = new ehough_curly_Url($qss->getFullUrl($_SERVER));
     $newurl->unsetQueryVariable('tubepress_page');
     $result = $this->_diggStyle($vidCount, $messageService, $currentPage, $vidsPerPage, 1, $newurl->toString(), 'tubepress_page');
     return $result;
 }
 /**
  * Invoked when the element is submitted by the user.
  *
  * @return string|null A string error message to be displayed to the user, or null if no problem.
  */
 public function onSubmit()
 {
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $id = $this->getId();
     if (!$hrps->hasParam($id)) {
         return $this->onSubmitAllMissing();
     }
     $vals = $hrps->getParamValue($id);
     if (!is_array($vals)) {
         /* this should never happen. */
         return null;
     }
     return $this->onSubmitMixed($vals);
 }
 /**
  * Filter the content (which may be empty).
  */
 public final function printOptionsPageHtml()
 {
     /* get the form handler */
     $optionsForm = tubepress_impl_patterns_sl_ServiceLocator::getOptionsPage();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $errors = array();
     $justSubmitted = false;
     /* are we updating? */
     if ($_SERVER['REQUEST_METHOD'] === 'POST' && $hrps->hasParam('tubepress_save')) {
         $justSubmitted = true;
         $errors = $optionsForm->onSubmit();
     }
     print $optionsForm->getHtml($errors, $justSubmitted);
 }
 /**
  * Handles form submission.
  *
  * @return array An array of failure messages if there's a problem, otherwise null.
  */
 public final function onSubmit()
 {
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $id = $this->getId();
     if ($this->_optionDescriptor->isBoolean()) {
         return $this->sendToStorage($id, $hrps->hasParam($id));
     }
     if (!$hrps->hasParam($id)) {
         /* not submitted. */
         return null;
     }
     $value = $hrps->getParamValue($id);
     return $this->sendToStorage($id, $this->convertIncomingStringValueToStorageFormat($value));
 }
 public function onVideoGalleryPage(tubepress_api_event_EventInterface $event)
 {
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $customVideoId = $hrps->getParamValue(tubepress_spi_const_http_ParamName::VIDEO);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     /* they didn't set a custom video id */
     if ($customVideoId == '') {
         return;
     }
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Prepending video %s to the gallery', $customVideoId));
     }
     self::_prependVideo($customVideoId, $event, $shouldLog);
 }
 /**
  * Handles incoming requests.
  *
  * @return void Handle the request and output a response.
  */
 public final function handle()
 {
     $this->_isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($this->_isDebugEnabled) {
         $this->_logger->debug('Handling incoming request');
     }
     $httpRequestParameterService = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $httpResponseCodeHandler = tubepress_impl_patterns_sl_ServiceLocator::getHttpResponseCodeHandler();
     $actionName = $httpRequestParameterService->getParamValue(tubepress_spi_const_http_ParamName::ACTION);
     if ($actionName == '') {
         $httpResponseCodeHandler->setResponseCode(400);
         echo 'Missing "action" parameter';
         return;
     }
     $chosenCommandHandler = null;
     if ($this->_isDebugEnabled) {
         $this->_logger->debug('There are ' . count($this->_commandHandlers) . ' pluggable Ajax command service(s) registered');
     }
     /**
      * @var $commandHandler tubepress_spi_http_PluggableAjaxCommandService
      */
     foreach ($this->_commandHandlers as $commandHandler) {
         if ($commandHandler->getName() === $actionName) {
             $chosenCommandHandler = $commandHandler;
             break;
         }
         if ($this->_isDebugEnabled) {
             $this->_logger->debug($commandHandler->getName() . ' could not handle action ' . $actionName);
         }
     }
     if ($chosenCommandHandler === null) {
         if ($this->_isDebugEnabled) {
             $this->_logger->debug('No pluggable Ajax command services could handle action ' . $actionName);
         }
         $httpResponseCodeHandler->setResponseCode(500);
         return;
     }
     if ($this->_isDebugEnabled) {
         $this->_logger->debug($chosenCommandHandler->getName() . ' chose to handle action ' . $actionName);
     }
     $chosenCommandHandler->handle();
     $httpResponseCodeHandler->setResponseCode($chosenCommandHandler->getHttpStatusCode());
     echo $chosenCommandHandler->getOutput();
 }
 /**
  * @return string The HTML for this shortcode handler.
  */
 public final function getHtml()
 {
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $videoId = $qss->getParamValue(tubepress_spi_const_http_ParamName::VIDEO);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Building single video with ID %s', $videoId));
     }
     $result = $execContext->set(tubepress_api_const_options_names_Output::VIDEO, $videoId);
     if ($result !== true) {
         if ($shouldLog) {
             $this->_logger->debug('Could not verify video ID.');
         }
         return false;
     }
     /* display the results as a thumb gallery */
     return $this->_singleVideoShortcodeHandler->getHtml();
 }
 public function onSearchInputTemplate(tubepress_api_event_EventInterface $event)
 {
     $template = $event->getSubject();
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $resultsUrl = $context->get(tubepress_api_const_options_names_InteractiveSearch::SEARCH_RESULTS_URL);
     $url = '';
     try {
         $url = new ehough_curly_Url($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 = new ehough_curly_Url($qss->getFullUrl($_SERVER));
     }
     /* clean up the search terms a bit */
     $searchTerms = $hrps->getParamValue(tubepress_spi_const_http_ParamName::SEARCH_TERMS);
     $searchTerms = urldecode($searchTerms);
     //TODO: get rid of this once we move to POST?
     /*
      * 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->getQueryVariables();
     unset($params[tubepress_spi_const_http_ParamName::PAGE]);
     unset($params[tubepress_spi_const_http_ParamName::SEARCH_TERMS]);
     /* apply the template variables */
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_HANDLER_URL, $url->toString());
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_HIDDEN_INPUTS, $params);
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_TERMS, $searchTerms);
     $template->setVariable(tubepress_api_const_template_Variable::SEARCH_BUTTON, $ms->_('Search'));
     //>(translatable)<
 }
 private function _getCurrentPage()
 {
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $page = $qss->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     if ($this->_isDebugEnabled) {
         $this->_logger->debug(sprintf('Current page number is %d', $page));
     }
     return $page;
 }
 private function _12_flushLogIfNeeded()
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $loggingEnabled = $context->get(tubepress_api_const_options_names_Advanced::DEBUG_ON);
     $loggingRequested = $hrps->hasParam('tubepress_debug') && $hrps->getParamValue('tubepress_debug') === true;
     $status = $loggingEnabled && $loggingRequested;
     $this->_loggingHandler->setStatus($status);
     $this->_shouldLog = $status;
 }