private function _getSingleVideoHtml($videoId)
 {
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector();
     $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler();
     $template = $themeHandler->getTemplateInstance('single_video.tpl.php', TUBEPRESS_ROOT . '/src/main/resources/default-themes/default');
     /* grab the video from the provider */
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->debug(sprintf('Asking provider for video with ID %s', $videoId));
     }
     $video = $provider->collectSingleVideo($videoId);
     if ($video === null) {
         return sprintf('Video %s not found', $videoId);
         //>(translatable)<
     }
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::TEMPLATE_SINGLE_VIDEO)) {
         $event = new tubepress_spi_event_EventBase($template, array('video' => $video));
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_SINGLE_VIDEO, $event);
         $template = $event->getSubject();
     }
     $html = $template->toString();
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::HTML_SINGLE_VIDEO)) {
         $event = new tubepress_spi_event_EventBase($html);
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::HTML_SINGLE_VIDEO, $event);
         $html = $event->getSubject();
     }
     return $html;
 }
 /**
  * Determines if this response needs to be decoded.
  *
  * @param ehough_shortstop_api_HttpResponse $response The HTTP response.
  *
  * @return boolean True if this response should be decoded. False otherwise.
  */
 public final function needsToBeDecoded(ehough_shortstop_api_HttpResponse $response)
 {
     $entity = $response->getEntity();
     $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($entity === null) {
         if ($isDebugEnabled) {
             $this->_logger->debug('Response contains no entity');
         }
         return false;
     }
     $content = $entity->getContent();
     if ($content == '' || $content == null) {
         if ($isDebugEnabled) {
             $this->_logger->debug('Response entity contains no content');
         }
         return false;
     }
     $expectedHeaderName = $this->getHeaderName();
     $actualHeaderValue = $response->getHeaderValue($expectedHeaderName);
     if ($actualHeaderValue === null) {
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Response does not contain %s header. No need to decode.', $expectedHeaderName));
         }
         return false;
     }
     if ($isDebugEnabled) {
         $this->_logger->debug(sprintf('Response contains %s header. Will attempt decode.', $expectedHeaderName));
     }
     return true;
 }
 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));
 }
 /**
  * @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();
 }
 /**
  * Sets some default headers on the request.
  *
  * @param ehough_tickertape_GenericEvent $event The pre-request event.
  *
  * @return void
  */
 public function onPreRequest(ehough_tickertape_GenericEvent $event)
 {
     $request = $event->getSubject();
     $this->_isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     $this->_setDefaultHeadersBasic($request);
     $this->_setDefaultHeadersCompression($request);
     $this->_setDefaultHeadersContent($request);
 }
 /**
  * Sets some default headers on the request.
  *
  * @param ehough_tickertape_GenericEvent $event The pre-request event.
  *
  * @return void
  */
 public function onPreRequest(ehough_tickertape_GenericEvent $event)
 {
     $request = $event->getSubject();
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->debug(sprintf('Will attempt %s', $request));
         $this->_logRequest($request);
     }
 }
 public function onResponse(ehough_tickertape_GenericEvent $event)
 {
     if (!$this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         return;
     }
     $response = $event->getSubject();
     $request = $event->getArgument('request');
     $this->_logger->debug(sprintf('The raw result for %s is in the HTML source for this page <span style="display:none">%s</span>', $request, htmlspecialchars(var_export($response, true))));
 }
示例#8
0
 /**
  * Determines whether or not this transport is available on the system.
  *
  * @return bool True if this transport is available on the system. False otherwise.
  */
 public function isAvailable()
 {
     if (!function_exists('http_request')) {
         if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
             $this->_logger->debug('http_request() does not exist');
         }
         return false;
     }
     return true;
 }
 /**
  * Compiles the container, if necessary.
  *
  * @param tubepress_impl_ioc_CoreIocContainer $container
  * @param array                               $addons
  *
  * @return void
  */
 public function compile(tubepress_impl_ioc_CoreIocContainer $container, array $addons)
 {
     $this->_shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     $cachedIconicContainer = $this->getCachedObject(false);
     if ($cachedIconicContainer !== null) {
         $container->setDelegateIconicContainerBuilder($cachedIconicContainer);
         return;
     }
     $this->_compile($container, $addons);
     $this->tryToCache($container->getDelegateIconicContainerBuilder());
 }
 /**
  * @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;
 }
 /**
  * This function is used to parse a shortcode into options that TubePress can use.
  *
  * @param string $content The haystack in which to search
  *
  * @return array The associative array of parsed options.
  */
 public function parse($content)
 {
     $this->_shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     try {
         $this->_wrappedParse($content);
     } catch (Exception $e) {
         if ($this->_shouldLog) {
             $this->_logger->error('Caught exception when parsing shortcode: ' . $e->getMessage());
         }
     }
 }
 public function _primeCache()
 {
     if (isset($this->_nameToOptionDescriptorMap)) {
         return;
     }
     $this->_shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     $fromCache = $this->getCachedObject();
     if ($fromCache !== null) {
         $this->_nameToOptionDescriptorMap = $fromCache;
         return;
     }
     $this->_cacheOds();
     $this->tryToCache($this->_nameToOptionDescriptorMap);
 }
 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);
 }
 /**
  * Execute a unit of processing work to be performed.
  *
  * This Command may either complete the required processing and return true,
  * or delegate remaining processing to the next Command in a Chain containing
  * this Command by returning false.
  *
  * @param ehough_chaingang_api_Context $context The Context to be processed by this Command.
  *
  * @return boolean True if the processing of this Context has been completed, or false if the
  *                 processing of this Context should be delegated to a subsequent Command
  *                 in an enclosing Chain.
  */
 public function execute(ehough_chaingang_api_Context $context)
 {
     $response = $context->get('response');
     $encoding = $response->getHeaderValue(ehough_shortstop_api_HttpResponse::HTTP_HEADER_TRANSFER_ENCODING);
     if (strcasecmp($encoding, 'chunked') !== 0) {
         if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
             $this->_logger->debug('Response is not encoded with Chunked-Transfer');
         }
         return false;
     }
     /** @noinspection PhpUndefinedMethodInspection */
     $decoded = self::_decode($response->getEntity()->getContent());
     $context->put('response', $decoded);
     return true;
 }
 /**
  * Gets an instance of a template appropriate for the current theme.
  *
  * @param string $pathToTemplate    The relative path (from the root of the user's theme directory,
  *                                  or the fallback directory) to the template.
  * @param string $fallBackDirectory The absolute path to a directory where this template (defined by the relative
  *                                  path, can be found). You should make sure that the template will *always* exist
  *                                  here.
  *
  * @throws RuntimeException If the template could not be found.
  *
  * @return ehough_contemplate_api_Template The template instance.
  */
 function getTemplateInstance($pathToTemplate, $fallBackDirectory)
 {
     $debugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($debugEnabled) {
         $this->_logger->debug("Attempting to load template instance from {$pathToTemplate} with fallback directory " . " at {$fallBackDirectory}");
     }
     $currentTheme = $this->calculateCurrentThemeName();
     if ($debugEnabled) {
         $this->_logger->debug("Requested theme is '{$currentTheme}'");
     }
     $templateBuilder = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder();
     $filePath = $this->_getFilePath($currentTheme, $pathToTemplate, $fallBackDirectory, $debugEnabled);
     $template = $templateBuilder->getNewTemplateInstance($filePath);
     if ($debugEnabled) {
         $this->_logger->debug("Successfully loaded template from {$filePath}");
     }
     return $template;
 }
 /**
  * Fetches the feed from the remote provider
  *
  * @param string  $url      The URL to fetch.
  *
  * @return mixed The raw feed from the provider, or null if there was a problem.
  */
 public final function fetch($url)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $cacheEnabled = $context->get(tubepress_api_const_options_names_Cache::CACHE_ENABLED);
     $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($cacheEnabled) {
         $data = $this->_getFromCache($url, $context, $isDebugEnabled);
     } else {
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Skip cache check for <a href="%s">URL</a>', $url));
         }
         $data = $this->_getFromNetwork($url);
     }
     if ($isDebugEnabled) {
         $this->_logger->debug(sprintf('Raw result for <a href="%s">URL</a> is in the HTML source for this page. <span style="display:none">%s</span>', $url, htmlspecialchars($data)));
     }
     return $data;
 }
 private function _init()
 {
     if ($this->_hasInitialized) {
         return;
     }
     $this->_shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     $this->_readConfig();
     $this->_hasInitialized = true;
 }
 public function onResponse(ehough_tickertape_GenericEvent $event)
 {
     $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     $response = $event->getSubject();
     if ($this->_responseDecoder->needsToBeDecoded($response)) {
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Response is %s-Encoded. Attempting decode.', $this->_name));
         }
         $this->_responseDecoder->decode($response);
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Successfully decoded %s-Encoded response.', $this->_name));
         }
     } else {
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Response is not %s-Encoded.', $this->_name));
         }
     }
 }
 /**
  * @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();
 }
 /**
  * Loads the given add-on into the system. This consists of including any defined
  * bootstrap files, then calling boot() on any bootstrap services and classes.
  *
  * If errors are encountered, the loader will record them and make a best effort to continue
  * loading the add-on.
  *
  * @param array $addons An array of tubepress_spi_addon_Addon instances.
  *
  * @return mixed An array of string error messages encountered while loading the
  *               add-ons. May be empty, never null.
  */
 public function boot(array $addons)
 {
     $index = 1;
     $count = count($addons);
     $this->_shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     /**
      * @var $addon tubepress_spi_addon_Addon
      */
     foreach ($addons as $addon) {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Attempting to boot add-on %d of %d: %s', $index, $count, $addon->getName()));
         }
         $this->_boot($addon);
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Done attempting to boot add-on %d of %d: %s', $index, $count, $addon->getName()));
         }
         $index++;
     }
 }
示例#21
0
 /**
  * Perform optional tear down after handling a request.
  *
  * @return void
  */
 protected function tearDown()
 {
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->debug('Closing cURL');
     }
     if (isset($this->_handle)) {
         curl_close($this->_handle);
         unset($this->_handle);
     }
 }
 public function onVideoGalleryPage(tubepress_api_event_EventInterface $event)
 {
     $totalResults = $event->getSubject()->getTotalResultCount();
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $limit = $context->get(tubepress_api_const_options_names_Feed::RESULT_COUNT_CAP);
     $firstCut = $limit == 0 ? $totalResults : min($limit, $totalResults);
     $secondCut = min($firstCut, self::_calculateRealMax($context, $firstCut));
     $videos = $event->getSubject()->getVideos();
     $resultCount = count($videos);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Effective total result count (taking into account user-defined limit) is %d video(s)', $secondCut));
     }
     if ($resultCount > $secondCut) {
         if ($shouldLog) {
             $this->_logger->debug(sprintf('Result has %d video(s), limit is %d. So we\'re chopping it down.', $resultCount, $secondCut));
         }
         $event->getSubject()->setVideos(array_splice($videos, 0, $secondCut - $resultCount));
     }
     $event->getSubject()->setTotalResultCount($secondCut);
 }
 /**
  * Sets the value of an option
  *
  * @param string $optionName  The name of the option
  * @param mixed  $optionValue The option value
  *
  * @return mixed True if the option was set normally, otherwise a string error message.
  */
 public final function set($optionName, $optionValue)
 {
     $eventDispatcherService = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $optionValidatorService = tubepress_impl_patterns_sl_ServiceLocator::getOptionValidator();
     /** First run it through the filters. */
     /** Run it through the filters. */
     $event = new tubepress_spi_event_EventBase($optionValue, array('optionName' => $optionName));
     $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::OPTIONS_NVP_PREVALIDATIONSET, $event);
     $filteredValue = $event->getSubject();
     if ($optionValidatorService->isValid($optionName, $filteredValue)) {
         if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
             $this->_logger->debug(sprintf('Accepted valid value: %s = %s', $optionName, $this->_normalizeForStringOutput($filteredValue)));
         }
         $this->_customOptions[$optionName] = $filteredValue;
         return true;
     }
     $problemMessage = $optionValidatorService->getProblemMessage($optionName, $filteredValue);
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->warn(sprintf('Ignoring invalid value for "%s" (%s)', $optionName, $problemMessage));
     }
     return $problemMessage;
 }
 public function onVideoGalleryPage(tubepress_api_event_EventInterface $event)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $perPageSortOrder = $context->get(tubepress_api_const_options_names_Feed::PER_PAGE_SORT);
     $feedSortOrder = $context->get(tubepress_api_const_options_names_Feed::ORDER_BY);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     /** No sort requested? */
     if ($perPageSortOrder === tubepress_api_const_options_values_PerPageSortValue::NONE) {
         if ($shouldLog) {
             $this->_logger->debug('Requested per-page sort order is "none". Not applying per-page sorting.');
         }
         return;
     }
     /** Grab a handle to the videos. */
     $videos = $event->getSubject()->getVideos();
     if ($perPageSortOrder === tubepress_api_const_options_values_PerPageSortValue::RANDOM) {
         if ($shouldLog) {
             $this->_logger->debug('Shuffling videos');
         }
         shuffle($videos);
     } else {
         /** Determine the sort method name. */
         $sortCallback = '_' . $perPageSortOrder . '_compare';
         /** If we have a sorter, use it. */
         if (method_exists($this, $sortCallback)) {
             if ($shouldLog) {
                 $this->_logger->debug(sprintf('Now sorting %s videos on page (%s)', count($videos), $perPageSortOrder));
             }
             uasort($videos, array($this, $sortCallback));
         } else {
             if ($shouldLog) {
                 $this->_logger->debug(sprintf('No sort available for this page (%s)', $perPageSortOrder));
             }
         }
     }
     $videos = array_values($videos);
     /** Modify the feed result. */
     $event->getSubject()->setVideos($videos);
 }
 /**
  * Spits back the text for this embedded player
  *
  * @param string $videoId The video ID to display
  *
  * @return string The text for this embedded player, or null if there was a problem.
  */
 public final function getHtml($videoId)
 {
     $embeddedPlayer = $this->_getEmbeddedPlayer($videoId);
     if ($embeddedPlayer === null) {
         if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
             $this->_logger->warn('Could not generate the embedded player HTML for ' . $videoId);
         }
         return null;
     }
     $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler();
     $eventDispatcherService = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $template = $embeddedPlayer->getTemplate($themeHandler);
     $dataUrl = $embeddedPlayer->getDataUrlForVideo($videoId);
     $embeddedPlayerName = $embeddedPlayer->getName();
     $providerName = $embeddedPlayer->getHandledProviderName();
     /**
      * Build the embedded template event.
      */
     $embeddedTemplateEvent = new tubepress_spi_event_EventBase($template, array('videoId' => $videoId, 'providerName' => $providerName, 'dataUrl' => $dataUrl, 'embeddedImplementationName' => $embeddedPlayerName));
     /**
      * Dispatch the embedded template event.
      */
     $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_EMBEDDED, $embeddedTemplateEvent);
     /**
      * Pull the template out of the event.
      */
     $template = $embeddedTemplateEvent->getSubject();
     /**
      * Build the embedded HTML event.
      */
     $embeddedHtmlEvent = new tubepress_spi_event_EventBase($template->toString(), array('videoId' => $videoId, 'providerName' => $providerName, 'dataUrl' => $dataUrl, 'embeddedImplementationName' => $embeddedPlayerName));
     /**
      * Dispatche the embedded HTML event.
      */
     $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::HTML_EMBEDDED, $embeddedHtmlEvent);
     return $embeddedHtmlEvent->getSubject();
 }
示例#26
0
 /**
  * Determines whether or not this transport is available on the system.
  *
  * @return bool True if this transport is available on the system. False otherwise.
  */
 public function isAvailable()
 {
     $isDebugging = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if (!function_exists('fopen')) {
         if ($isDebugging) {
             $this->_logger->debug('fopen() does not exist');
         }
         return false;
     }
     if (function_exists('ini_get') && ini_get('allow_url_fopen') != true) {
         if ($isDebugging) {
             $this->_logger->debug('allow_url_fopen is set to false');
         }
         return false;
     }
     return true;
 }
 /**
  * @param $optionName
  * @param $optionValue
  *
  * @return bool True if the option is OK for storage, otherwise a string error message.
  */
 private function _validateOneForStorage($optionName, $optionValue)
 {
     $optionValidatorService = tubepress_impl_patterns_sl_ServiceLocator::getOptionValidator();
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     /** OK, let's see if it's valid. */
     if ($optionValidatorService->isValid($optionName, $optionValue)) {
         if ($shouldLog) {
             $this->_logger->info(sprintf("Accepted valid value: '%s' = '%s'", $optionName, $optionValue));
         }
         return true;
     }
     $problemMessage = $optionValidatorService->getProblemMessage($optionName, $optionValue);
     if ($shouldLog) {
         $this->_logger->info(sprintf("Ignoring invalid value: '%s' = '%s'", $optionName, $optionValue));
     }
     return $problemMessage;
 }
 private function _createDomDocument($feed)
 {
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->debug('Attempting to load XML from YouTube');
     }
     if (!class_exists('DOMDocument')) {
         throw new RuntimeException('DOMDocument class not found');
     }
     $doc = new DOMDocument();
     if ($doc->loadXML($feed) === false) {
         throw new RuntimeException('Could not parse XML from YouTube');
     }
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->debug('Successfully loaded XML from YouTube');
     }
     $this->_domDocument = $doc;
 }
 private function _feedToVideoArray($feed)
 {
     $toReturn = array();
     $total = $this->countVideosInFeed($feed);
     $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($isDebugEnabled) {
         $this->_logger->debug(sprintf('Now attempting to build %d video(s) from raw feed', $total));
     }
     for ($index = 0; $index < $total; $index++) {
         if (!$this->canWorkWithVideoAtIndex($index)) {
             if ($isDebugEnabled) {
                 $this->_logger->debug(sprintf('Skipping video at index %d', $index));
             }
             continue;
         }
         /*
          * Let's build a video!
          */
         $video = new tubepress_api_video_Video();
         /*
          * Every video needs to have a provider.
          */
         $video->setAttribute(tubepress_api_video_Video::ATTRIBUTE_PROVIDER_NAME, $this->getName());
         /*
          * Let add-ons build the rest of the video.
          */
         $event = new tubepress_spi_event_EventBase($video);
         $event->setArgument('zeroBasedFeedIndex', $index);
         $event->setArgument('rawFeed', $feed);
         /*
          * Let subclasses add to the event.
          */
         $this->onBeforeFiringVideoConstructionEvent($event);
         $video = $this->_fireEventAndGetSubject(tubepress_api_const_event_EventNames::VIDEO_CONSTRUCTION, $event);
         array_push($toReturn, $video);
     }
     $this->onFeedAnalysisComplete($feed);
     if ($isDebugEnabled) {
         $this->_logger->debug(sprintf('Built %d video(s) from raw feed', sizeof($toReturn)));
     }
     return $toReturn;
 }
 private function _tryToBuildAddonFromFile(SplFileInfo $infoFile)
 {
     $manifestFilePath = realpath("{$infoFile}");
     $infoFileContents = @json_decode(file_get_contents($manifestFilePath), true);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($infoFileContents === null || $infoFileContents === false || empty($infoFileContents)) {
         if ($shouldLog) {
             $this->_logger->debug('Could not parse add-on manifest file at ' . $manifestFilePath);
         }
         return null;
     }
     try {
         return $this->_constructAddonFromArray($infoFileContents, $manifestFilePath);
     } catch (Exception $e) {
         if ($shouldLog) {
             $this->_logger->warn('Caught exception when parsing info file at ' . $infoFile->getRealpath() . ': ' . $e->getMessage());
         }
         return null;
     }
 }