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();
 }
 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 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 #4
0
 private function _prependVideo($id, tubepress_api_event_EventInterface $event)
 {
     $mediaItemArray = $event->getSubject()->getItems();
     /* see if the array already has it */
     if (self::_mediaItemArrayAlreadyHasItem($mediaItemArray, $id)) {
         $mediaItemArray = $this->_moveItemUpFront($mediaItemArray, $id);
     } else {
         $mediaItem = $this->_collector->collectSingle($id);
         if ($mediaItem) {
             array_unshift($mediaItemArray, $mediaItem);
             array_pop($mediaItemArray);
         }
     }
     /* modify the feed result */
     $event->getSubject()->setItems($mediaItemArray);
 }