protected function getAdditionalTemplateVariables()
 {
     $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $cancelText = $ms->_('cancel');
     $chooseText = $ms->_('Choose');
     return array('preferredFormat' => $this->_preferredFormat, 'showAlpha' => $this->_showAlpha, 'showInput' => $this->_showInput, 'showPalette' => $this->_showSelectionPalette, 'cancelText' => $cancelText, 'chooseText' => $chooseText);
 }
 /**
  * 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()
 {
     $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;
 }
Exemplo n.º 4
0
 protected function getAdditionalTemplateVariables()
 {
     $values = array();
     $map = $this->getOptionDescriptor()->getAcceptableValues();
     if (!tubepress_impl_util_LangUtils::isAssociativeArray($map)) {
         throw new InvalidArgumentException(sprintf('"%s" has a non-associative array set for its value map', $this->getOptionDescriptor()->getName()));
     }
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     foreach ($map as $key => $value) {
         $values[$key] = $messageService->_($value);
     }
     return array('choices' => $values);
 }
 /**
  * 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;
 }
 public function onSingleVideoTemplate(tubepress_api_event_EventInterface $event)
 {
     $template = $event->getSubject();
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $optionDescriptorReference = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference();
     $metaNames = tubepress_impl_util_LangUtils::getDefinedConstants('tubepress_api_const_options_names_Meta');
     $shouldShow = array();
     $labels = array();
     foreach ($metaNames as $metaName) {
         $optionDescriptor = $optionDescriptorReference->findOneByName($metaName);
         $shouldShow[$metaName] = $context->get($metaName);
         $labels[$metaName] = $messageService->_($optionDescriptor->getLabel());
     }
     $template->setVariable(tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow);
     $template->setVariable(tubepress_api_const_template_Variable::META_LABELS, $labels);
 }
 public function onOptionsUiTemplate(tubepress_api_event_EventInterface $event)
 {
     /**
      * @var $template ehough_contemplate_api_Template
      */
     $template = $event->getSubject();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $template->setVariable("pageTitle", $messageService->_('TubePress Options'));
     //>(translatable)<                                                                                                                                                                                                                                                                                                      //>(translatable)<
     $template->setVariable("introBlurb", $messageService->_('Here you can set the default options for TubePress. Each option here can be overridden on a per page/post basis with TubePress shortcodes. See the <a href="http://tubepress.com/documentation" target="_blank">documentation</a> for more information.'));
     //>(translatable)<
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $toEncode = array();
     if (!$environmentDetector->isPro()) {
         $toEncode[] = $this->_generateBox('You\'re Missing Out!', 'http://tubepress.com/snippets/wordpress/youre-missing-out.php');
     }
     $toEncode[] = $this->_generateBox('TubePress News', 'http://tubepress.com/snippets/wordpress/latest-news.php');
     $toEncode[] = $this->_generateBox('Need Help?', 'http://tubepress.com/snippets/wordpress/need-help.php');
     $template->setVariable(self::TEMPLATE_VAR_BOX_ARRAY, json_encode($toEncode));
 }
 /**
  * @return array An associative array of translated group names to associative array of
  *               value => translated display names
  */
 protected function getGroupedTranslatedChoicesArray()
 {
     $toReturn = array();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     //prime cache
     $this->_getOptionDescriptors();
     foreach ($this->_cachedProvidedOptionDescriptors as $friendlyName => $optionDescriptorArray) {
         $values = array();
         /**
          * @var $optionDescriptorArray tubepress_spi_options_OptionDescriptor[]
          */
         foreach ($optionDescriptorArray as $optionDescriptor) {
             $values[$optionDescriptor->getName()] = $messageService->_($optionDescriptor->getLabel());
         }
         asort($values);
         $toReturn[$friendlyName] = $values;
     }
     ksort($toReturn);
     return $toReturn;
 }
 /**
  * Gets the failure message of a name/value pair that has failed validation.
  *
  * @param string $optionName The option name
  * @param mixed  $candidate  The candidate option value
  *
  * @return mixed Null if the option passes validation, otherwise a string failure message.
  */
 public final function getProblemMessage($optionName, $candidate)
 {
     $optionDescriptorReferenceService = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $descriptor = $optionDescriptorReferenceService->findOneByName($optionName);
     if ($descriptor === null) {
         return sprintf('No option with name "%s".', $optionName);
         //>(translatable)<
     }
     if ($descriptor->hasValidValueRegex()) {
         if (preg_match_all($descriptor->getValidValueRegex(), (string) $candidate, $matches) >= 1 && $matches[0][0] === (string) $candidate) {
             return null;
         }
         return sprintf('Invalid value supplied for "%s".', $messageService->_($descriptor->getLabel()));
         //>(translatable)<
     }
     if ($descriptor->hasDiscreteAcceptableValues()) {
         $acceptableValues = $descriptor->getAcceptableValues();
         if (tubepress_impl_util_LangUtils::isAssociativeArray($acceptableValues)) {
             $values = array_keys($descriptor->getAcceptableValues());
         } else {
             $values = array_values($acceptableValues);
         }
         if (in_array($candidate, $values)) {
             return null;
         }
         return sprintf('"%s" must be one of "%s". You supplied "%s".', $messageService->_($descriptor->getLabel()), implode(', ', $values), $candidate);
     }
     if ($descriptor->isBoolean()) {
         if (is_bool($candidate)) {
             return null;
         }
         return sprintf('"%s" can only be "true" or "false". You supplied "%s".', $optionName, $candidate);
         //>(translatable)<
     }
     return null;
 }
 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)<
 }
Exemplo n.º 11
0
 protected function translate($message)
 {
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     return $messageService->_($message);
 }