public function onSingleItemTemplatePreRender(tubepress_api_event_EventInterface $event)
 {
     /*
      * @var array
      */
     $existingTemplateVars = $event->getSubject();
     if (!isset($existingTemplateVars[tubepress_api_template_VariableNames::MEDIA_ITEM])) {
         return;
     }
     /*
      * @var tubepress_api_media_MediaItem
      */
     $mediaItem = $existingTemplateVars[tubepress_api_template_VariableNames::MEDIA_ITEM];
     $embeddedProvider = $this->_selectEmbeddedProvider($mediaItem);
     $embedWidth = $this->_context->get(tubepress_api_options_Names::EMBEDDED_WIDTH);
     $embedHeight = $this->_context->get(tubepress_api_options_Names::EMBEDDED_HEIGHT);
     $responsive = $this->_context->get(tubepress_api_options_Names::RESPONSIVE_EMBEDS);
     $templateVars = $embeddedProvider->getTemplateVariables($mediaItem);
     $embeddedHtml = $this->_templating->renderTemplate('single/embedded', array_merge(array('embeddedProvider' => $embeddedProvider, tubepress_api_template_VariableNames::MEDIA_ITEM => $mediaItem, tubepress_api_template_VariableNames::EMBEDDED_WIDTH_PX => $embedWidth, tubepress_api_template_VariableNames::EMBEDDED_HEIGHT_PX => $embedHeight, tubepress_api_options_Names::RESPONSIVE_EMBEDS => $responsive), $templateVars));
     $existingTemplateVars[tubepress_api_template_VariableNames::EMBEDDED_SOURCE] = $embeddedHtml;
     $existingTemplateVars[tubepress_api_template_VariableNames::EMBEDDED_WIDTH_PX] = $embedWidth;
     $existingTemplateVars[tubepress_api_template_VariableNames::EMBEDDED_HEIGHT_PX] = $embedHeight;
     $existingTemplateVars[tubepress_api_options_Names::RESPONSIVE_EMBEDS] = $responsive;
     $event->setSubject($existingTemplateVars);
 }
 public function onAction_in_plugin_update_message(tubepress_api_event_EventInterface $event)
 {
     if (!$this->_context->get(tubepress_api_options_Names::TUBEPRESS_API_KEY)) {
         $html = $this->_templating->renderTemplate('wordpress/in-update-message');
         echo $html;
     }
 }
 public function onHtmlGeneration(tubepress_api_event_EventInterface $event)
 {
     $galleryId = $this->_context->get(tubepress_api_options_Names::HTML_GALLERY_ID);
     $shouldLog = $this->_logger->isEnabled();
     if ($galleryId == '') {
         $galleryId = mt_rand();
         $this->_context->setEphemeralOption(tubepress_api_options_Names::HTML_GALLERY_ID, $galleryId);
     }
     if ($shouldLog) {
         $this->_logDebug(sprintf('Starting to build thumbnail gallery <code>%s</code>', $galleryId));
     }
     $pageNumber = $this->_requestParameters->getParamValueAsInt('tubepress_page', 1);
     /* first grab the items */
     if ($shouldLog) {
         $this->_logDebug('Asking collector for a page.');
     }
     $mediaPage = $this->_collector->collectPage($pageNumber);
     $itemCount = sizeof($mediaPage->getItems());
     if ($shouldLog) {
         $this->_logDebug(sprintf('Collector has delivered <code>%d</code> item(s)', $itemCount));
     }
     $templateVars = array('mediaPage' => $mediaPage, 'pageNumber' => $pageNumber);
     $html = $this->_templating->renderTemplate('gallery/main', $templateVars);
     /* we're done. tie up */
     if ($shouldLog) {
         $this->_logDebug(sprintf('Done assembling gallery <code>%d</code>', $galleryId));
     }
     $event->setSubject($html);
     $event->stopPropagation();
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function getHTML(array $errors = array(), $justSubmitted = false)
 {
     $hasErrors = count($errors) > 0;
     $fields = $this->_buildFieldsArray(false, $hasErrors);
     $templateVariables = array('errors' => $errors, 'fields' => $fields, 'justSubmitted' => $justSubmitted);
     return $this->_templating->renderTemplate('options-ui/form', $templateVariables);
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function getHtml()
 {
     try {
         $htmlGenerationEventPre = $this->_eventDispatcher->newEventInstance('');
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::HTML_GENERATION, $htmlGenerationEventPre);
         /*
          * @var $selected string
          */
         $html = $htmlGenerationEventPre->getSubject();
         if ($html === null) {
             throw new RuntimeException('Unable to generate HTML.');
         }
         $htmlGenerationEventPost = $this->_eventDispatcher->newEventInstance($html);
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::HTML_GENERATION_POST, $htmlGenerationEventPost);
         /*
          * @var string
          */
         $html = $htmlGenerationEventPost->getSubject();
         return $html;
     } catch (Exception $e) {
         $event = $this->_eventDispatcher->newEventInstance($e);
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::HTML_EXCEPTION_CAUGHT, $event);
         $args = array('exception' => $e);
         $html = $this->_templating->renderTemplate('exception/static', $args);
         return $html;
     }
 }
 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);
 }
 private function _paginationFromTemplate($totalItems, $currentPage, $perPage, tubepress_api_url_UrlInterface $url)
 {
     $url->removeSchemeAndAuthority();
     $url->getQuery()->set('tubepress_page', '___page-number___');
     $vars = array(tubepress_api_template_VariableNames::GALLERY_PAGINATION_CURRENT_PAGE_NUMBER => $currentPage, tubepress_api_template_VariableNames::GALLERY_PAGINATION_TOTAL_ITEMS => $totalItems, tubepress_api_template_VariableNames::GALLERY_PAGINATION_HREF_FORMAT => "{$url}", tubepress_api_template_VariableNames::GALLERY_PAGINATION_RESULTS_PER_PAGE => $perPage);
     return $this->_templating->renderTemplate('gallery/pagination', $vars);
 }
 private function _errorOut(Exception $e, $code)
 {
     $this->_responseCode->setResponseCode($code);
     $event = $this->_eventDispatcher->newEventInstance($e);
     $this->_eventDispatcher->dispatch(tubepress_api_event_Events::HTML_EXCEPTION_CAUGHT, $event);
     $args = array('exception' => $e);
     $response = $this->_templating->renderTemplate('exception/ajax', $args);
     echo $response;
 }
Beispiel #9
0
 public function onHtmlGenerationSearchInput(tubepress_api_event_EventInterface $event)
 {
     if ($this->_context->get(tubepress_api_options_Names::HTML_OUTPUT) !== tubepress_api_options_AcceptableValues::OUTPUT_SEARCH_INPUT) {
         return;
     }
     $html = $this->_templating->renderTemplate('search/input', array());
     $event->setSubject($html);
     $event->stopPropagation();
 }
Beispiel #10
0
 public function onGalleryTemplatePreRender(tubepress_api_event_EventInterface $event)
 {
     $activePlayerLocation = $this->_getActivePlayerLocation();
     $staticTemplateName = $activePlayerLocation->getStaticTemplateName();
     if ($staticTemplateName === null) {
         return;
     }
     /*
      * @var array
      */
     $templateVars = $event->getSubject();
     /*
      * @var tubepress_api_media_MediaPage
      */
     $mediaPage = $templateVars['mediaPage'];
     $items = $mediaPage->getItems();
     if (count($items) === 0) {
         return;
     }
     $mediaItem = $items[0];
     $playerTemplateVars = array(tubepress_api_template_VariableNames::MEDIA_ITEM => $mediaItem);
     $playerHtml = $this->_templating->renderTemplate('gallery/player/static', $playerTemplateVars);
     $templateVars[tubepress_api_template_VariableNames::PLAYER_HTML] = $playerHtml;
     $event->setSubject($templateVars);
 }
 public function onHtmlGeneration(tubepress_api_event_EventInterface $event)
 {
     $mediaItemId = $this->_context->get(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID);
     if ($mediaItemId == '') {
         return;
     }
     /* grab the media item from the provider */
     if ($this->_logger->isEnabled()) {
         $this->_logger->debug(sprintf('Asking provider for video with ID %s', $mediaItemId));
     }
     $mediaItem = $this->_collector->collectSingle($mediaItemId);
     $eventArgs = array('itemId' => $mediaItemId);
     if ($mediaItem !== null) {
         $eventArgs['mediaItem'] = $mediaItem;
     }
     $singleHtml = $this->_templating->renderTemplate('single/main', $eventArgs);
     $event->setSubject($singleHtml);
     $event->stopPropagation();
 }
Beispiel #12
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 getWidgetHTML()
 {
     $templateName = $this->getTemplateName();
     $templateVars = $this->getTemplateVariables();
     return $this->_templating->renderTemplate($templateName, $templateVars);
 }
 public function getJS()
 {
     $jsUrls = $this->getUrlsJS();
     return $this->_templating->renderTemplate($this->_templateNameJs, array('urls' => $jsUrls));
 }
 protected function bail($message)
 {
     $this->_renderedResult = $this->_templating->renderTemplate('oauth2/error', array('message' => $message));
     throw new RuntimeException();
 }