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(); }