/**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 public function execute($context)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $playerName = $execContext->get(org_tubepress_api_const_options_names_Embedded::PLAYER_LOCATION);
     if ($playerName !== org_tubepress_api_const_options_values_PlayerLocationValue::SOLO) {
         return false;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Solo player detected. Checking query string for video ID.');
     /* see if we have a custom video ID set */
     $qss = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $videoId = $qss->getParamValue(org_tubepress_api_const_http_ParamName::VIDEO);
     if ($videoId == '') {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Solo player in use, but no video ID set in URL.');
         return false;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Building single video with ID %s', $videoId);
     $result = $execContext->set(org_tubepress_api_const_options_names_Output::VIDEO, $videoId);
     if ($result !== true) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Could not verify video ID.');
         return false;
     }
     /* display the results as a thumb gallery */
     $ioc->get(org_tubepress_spi_patterns_cor_Chain::_)->execute($context, array('org_tubepress_impl_shortcode_commands_SingleVideoCommand'));
     return true;
 }
 /**
  * Executes the given commands with the given context.
  *
  * @param array $context  An array of context elements (may be empty).
  * @param array $commands An array of org_tubepress_api_patterns_cor_Command class names to execute.
  *
  * @return unknown The result of the command execution.
  */
 public function execute($context, $commands)
 {
     /* sanity checkin' */
     if (!is_array($commands)) {
         throw new Exception('execute() requires an array of commands');
     }
     if (!is_object($context)) {
         throw new Exception('execute() requires an object to be passed as the context');
     }
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     /* run the first command that wants to handle this */
     foreach ($commands as $commandName) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Seeing if "%s" wants to handle execution', $commandName);
         $command = $ioc->get($commandName);
         if (!is_a($command, 'org_tubepress_api_patterns_cor_Command')) {
             throw new Exception("{$commandName} does not implement org_tubepress_api_patterns_cor_Command");
         }
         $ableToHandle = call_user_func_array(array($command, 'execute'), array($context));
         if ($ableToHandle === true) {
             org_tubepress_impl_log_Log::log(self::LOG_PREFIX, '%s handled execution', $commandName);
             return true;
         }
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'None of the supplied commands were able to handle the execution: ' . implode("', '", $commands));
     return false;
 }
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $perPageSortOrder = $context->get(org_tubepress_api_const_options_names_Feed::PER_PAGE_SORT);
     $feedSortOrder = $context->get(org_tubepress_api_const_options_names_Feed::ORDER_BY);
     /** No sort requested? */
     if ($perPageSortOrder === org_tubepress_api_const_options_values_PerPageSortValue::NONE) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Requested per-page sort order is "none". Not applying per-page sorting.');
         return $providerResult;
     }
     /** Grab a handle to the videos. */
     $videos = $providerResult->getVideoArray();
     if ($feedSortOrder === org_tubepress_api_const_options_values_OrderByValue::RANDOM || $perPageSortOrder === org_tubepress_api_const_options_values_PerPageSortValue::RANDOM) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, '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)) {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Now sorting %s videos on page (%s)', count($videos), $perPageSortOrder);
             uasort($videos, array($this, $sortCallback));
         } else {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'No sort available for this page (%s)', $perPageSortOrder);
         }
     }
     $videos = array_values($videos);
     /** Modify the feed result. */
     $providerResult->setVideoArray($videos);
     return $providerResult;
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 function execute($context)
 {
     /* grab the arguments */
     $feed = $context->feed;
     if (!$this->_canHandleFeed($feed)) {
         return false;
     }
     /* give the command a chance to do some initial processing */
     $this->_preExecute($feed);
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $this->_context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     $results = array();
     $index = 0;
     $total = $this->_countVideosInFeed($feed);
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Now building %d video(s) from raw feed', $total);
     for ($index = 0; $index < $total; $index++) {
         if (!$this->_canHandleVideo($index)) {
             org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Skipping video at index %d', $index);
             continue;
         }
         /* build the video */
         $results[] = $this->_buildVideo($index);
     }
     /* give the command a chance to do some post processing */
     $this->_postExecute($feed);
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Built %d video(s) from raw feed', sizeof($results));
     $context->returnValue = $results;
     return true;
 }
 protected function _isNotBlacklisted($id, $blacklist)
 {
     if (strpos($blacklist, $id) !== false) {
         org_tubepress_impl_log_Log::log('Video Blacklister', 'Video with ID %s is blacklisted. Skipping it.', $id);
         return false;
     }
     return true;
 }
 /**
  * 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')) {
         org_tubepress_impl_log_Log::log($this->logPrefix(), 'http_request() does not exist');
         return false;
     }
     return true;
 }
示例#7
0
 public function testLogTwoArgs()
 {
     ob_start();
     org_tubepress_impl_log_Log::log('prefix', 'message1 %s', 'message2');
     $contents = ob_get_contents();
     ob_end_clean();
     $this->assertTrue(strpos($contents, 'ms (prefix) message1 message2 (memory: ') !== false);
 }
 /**
  * Count the total videos in this feed result.
  *
  * @param unknown $rawFeed The raw video feed (varies depending on provider)
  *
  * @return int The total result count of this query, or 0 if there was a problem.
  */
 public function getTotalResultCount($rawFeed)
 {
     try {
         return $this->_wrappedCount($rawFeed);
     } catch (Exception $e) {
         org_tubepress_impl_log_Log::log('Delegating Feed Inspector', 'Caught exception while counting: ' . $e->getMessage());
         return 0;
     }
 }
 /**
  * Converts raw video feeds to TubePress videos
  *
  * @param unknown $feed The raw feed result from the video provider
  *
  * @return array an array of TubePress videos generated from the feed
  */
 public function feedToVideoArray($feed)
 {
     try {
         return $this->_wrappedFeedToVideoArray($feed);
     } catch (Exception $e) {
         org_tubepress_impl_log_Log::log('Delegating video factory', 'Caught exception building videos: ' . $e->getMessage());
         return array();
     }
 }
 private function _handleSuccess(org_tubepress_api_http_HttpResponse $response)
 {
     $entity = $response->getEntity();
     if ($entity !== null) {
         return $entity->getContent();
     }
     org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Null entity in response');
     return '';
 }
 public function alter_embeddedHtml($html, $videoId, $videoProviderName, $embeddedImplName)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     if (!$context->get(org_tubepress_api_const_options_names_Embedded::ENABLE_JS_API)) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'JS API is disabled');
         return $html;
     }
     return $html . $this->_getPlayerRegistryJs($videoId);
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 function execute($context)
 {
     $response = $context->response;
     $encoding = $response->getHeaderValue(org_tubepress_api_http_HttpResponse::HTTP_HEADER_TRANSFER_ENCODING);
     if (strcasecmp($encoding, 'chunked') !== 0) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Response is not encoded with Chunked-Transfer');
         return false;
     }
     $context->decoded = self::_decode($response->getEntity()->getContent());
     return true;
 }
 /**
  * Applied to a single option name/value pair before it is applied to TubePress's execution context
  *  or persistence storage. This filter is invoked *before* the option name or value is validated!
  *
  * @param string $value The option value being set.
  * @param string $name  The name of the option being set.
  *
  * @return unknown_type The (possibly modified) option value. May be null.
  *
  * function alter_preValidationOptionSet($value, $name);
  */
 public function alter_preValidationOptionSet($value, $name)
 {
     /** We only care about playlistValue. */
     if ($name !== org_tubepress_api_const_options_names_GallerySource::YOUTUBE_PLAYLIST_VALUE) {
         return $value;
     }
     if (org_tubepress_impl_util_StringUtils::startsWith($value, 'PL')) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Removing \'PL\' prefix from playlist value of %s', $value);
         return org_tubepress_impl_util_StringUtils::replaceFirst('PL', '', $value);
     }
     org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Playlist value %s does not beging with \'PL\'', $value);
     return $value;
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 function execute($context)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $pc = $ioc->get(org_tubepress_api_provider_ProviderCalculator::_);
     $currentProvider = $pc->calculateCurrentVideoProvider();
     if ($currentProvider !== $this->getProviderName()) {
         org_tubepress_impl_log_Log::log($this->getLogPrefix(), 'Not a %s response', $this->getProviderName());
         return false;
     }
     $response = $context->response;
     $context->messageToDisplay = $this->getMessageForResponse($response);
     return true;
 }
示例#15
0
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult, $providerName)
 {
     $videos = $providerResult->getVideoArray();
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     /* shuffle if we need to */
     if ($context->get(org_tubepress_api_const_options_names_Display::ORDER_BY) == org_tubepress_api_const_options_values_OrderValue::RANDOM) {
         org_tubepress_impl_log_Log::log('Shuffler', 'Shuffling videos');
         shuffle($videos);
     }
     /* modify the feed result */
     $providerResult->setVideoArray($videos);
     return $providerResult;
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 public function execute($context)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     /* not configured at all for search results */
     if ($execContext->get(org_tubepress_api_const_options_names_Output::OUTPUT) !== org_tubepress_api_const_options_values_OutputValue::SEARCH_RESULTS) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Not configured for search results');
         return false;
     }
     /* do we have search terms? */
     $qss = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $rawSearchTerms = $qss->getParamValue(org_tubepress_api_const_http_ParamName::SEARCH_TERMS);
     /* are we set up for a gallery fallback? */
     $mustShowSearchResults = $execContext->get(org_tubepress_api_const_options_names_InteractiveSearch::SEARCH_RESULTS_ONLY);
     $hasSearchTerms = $rawSearchTerms != '';
     /* the user is not searching and we don't have to show results */
     if (!$hasSearchTerms && !$mustShowSearchResults) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'The user isn\'t searching.');
         return false;
     }
     /* if the user isn't searching, don't display anything */
     if (!$hasSearchTerms) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'User doesn\'t appear to be searching. Will not display anything.');
         $context->returnValue = '';
         return true;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'User is searching. We\'ll handle this.');
     /* who are we searching? */
     switch ($execContext->get(org_tubepress_api_const_options_names_InteractiveSearch::SEARCH_PROVIDER)) {
         case org_tubepress_api_provider_Provider::VIMEO:
             $execContext->set(org_tubepress_api_const_options_names_Output::GALLERY_SOURCE, org_tubepress_api_const_options_values_GallerySourceValue::VIMEO_SEARCH);
             $result = $execContext->set(org_tubepress_api_const_options_names_GallerySource::VIMEO_SEARCH_VALUE, $rawSearchTerms);
             if ($result !== true) {
                 org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Unable to set search terms, so we will not handle request');
                 return false;
             }
             break;
         default:
             $execContext->set(org_tubepress_api_const_options_names_Output::GALLERY_SOURCE, org_tubepress_api_const_options_values_GallerySourceValue::YOUTUBE_SEARCH);
             $result = $execContext->set(org_tubepress_api_const_options_names_GallerySource::YOUTUBE_TAG_VALUE, $rawSearchTerms);
             if ($result !== true) {
                 org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Unable to set search terms, so we will not handle request');
                 return false;
             }
             break;
     }
     /* display the results as a thumb gallery */
     return $ioc->get(org_tubepress_spi_patterns_cor_Chain::_)->execute($context, array('org_tubepress_impl_shortcode_commands_ThumbGalleryCommand'));
 }
 private function _getSingleVideoHtml($videoId, $ioc)
 {
     $ms = $ioc->get('org_tubepress_api_message_MessageService');
     $pluginManager = $ioc->get('org_tubepress_api_plugin_PluginManager');
     $provider = $ioc->get('org_tubepress_api_provider_Provider');
     $themeHandler = $ioc->get('org_tubepress_api_theme_ThemeHandler');
     $pc = $ioc->get('org_tubepress_api_provider_ProviderCalculator');
     $template = $themeHandler->getTemplateInstance('single_video.tpl.php');
     $providerName = $pc->calculateProviderOfVideoId($videoId);
     /* grab the video from the provider */
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Asking provider for video with ID %s', $videoId);
     $video = $provider->getSingleVideo($videoId);
     /* send the template through the filters */
     $template = $pluginManager->runFilters(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SINGLEVIDEO, $template, $video, $providerName);
     /* send video HTML through the filters */
     return $pluginManager->runFilters(org_tubepress_api_const_plugin_FilterPoint::HTML_SINGLEVIDEO, $template->toString(), $video, $providerName);
 }
 private function _loadUserPlugins(org_tubepress_api_ioc_IocService $ioc)
 {
     $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     $fe = $ioc->get(org_tubepress_api_filesystem_Explorer::_);
     $th = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
     $pluginPath = $th->getUserContentDirectory() . '/plugins';
     $pluginDirs = $fe->getDirectoriesInDirectory($pluginPath, self::LOG_PREFIX);
     foreach ($pluginDirs as $pluginDir) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Examining potential plugin directory at %s', $pluginDir);
         $files = $fe->getFilenamesInDirectory($pluginDir, self::LOG_PREFIX);
         foreach ($files as $file) {
             if ('.php' == substr($file, -4) && is_readable($file)) {
                 org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Loading PHP file at <tt>%s</tt>', $file);
                 include_once $file;
             }
         }
     }
 }
 public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult)
 {
     $totalResults = $providerResult->getEffectiveTotalResultCount();
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $limit = $context->get(org_tubepress_api_const_options_names_Feed::RESULT_COUNT_CAP);
     $firstCut = $limit == 0 ? $totalResults : min($limit, $totalResults);
     $secondCut = min($firstCut, self::_calculateRealMax($context, $firstCut));
     $videos = $providerResult->getVideoArray();
     $resultCount = count($videos);
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Effective total result count (taking into account user-defined limit) is %d video(s)', $secondCut);
     if ($resultCount > $secondCut) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Result has %d video(s), limit is %d. So we\'re chopping it down.', $resultCount, $secondCut);
         $providerResult->setVideoArray(array_splice($videos, 0, $secondCut - $resultCount));
     }
     $providerResult->setEffectiveTotalResultCount($secondCut);
     return $providerResult;
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 public function execute($context)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     /* not configured at all for search results */
     if ($execContext->get(org_tubepress_api_const_options_names_Output::OUTPUT) !== org_tubepress_api_const_options_values_OutputValue::SEARCH_RESULTS) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Not configured for search results');
         return false;
     }
     /* do we have search terms? */
     $qss = $ioc->get('org_tubepress_api_querystring_QueryStringService');
     $rawSearchTerms = $qss->getSearchTerms($_GET);
     /* are we set up for a gallery fallback? */
     $mustShowSearchResults = $execContext->get(org_tubepress_api_const_options_names_Output::SEARCH_RESULTS_ONLY);
     $hasSearchTerms = $rawSearchTerms != '';
     /* the user is not searching and we don't have to show results */
     if (!$hasSearchTerms && !$mustShowSearchResults) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'The user isn\'t searching.');
         return false;
     }
     /* if the user isn't searching, don't display anything */
     if (!$hasSearchTerms) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'User doesn\'t appear to be searching. Will not display anything.');
         $context->returnValue = '';
         return true;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'User is searching. We\'ll handle this.');
     /* clean up the search terms */
     $searchTerms = org_tubepress_impl_util_StringUtils::cleanForSearch($rawSearchTerms);
     /* who are we searching? */
     switch ($execContext->get(org_tubepress_api_const_options_names_Output::SEARCH_PROVIDER)) {
         case org_tubepress_api_provider_Provider::VIMEO:
             $execContext->set(org_tubepress_api_const_options_names_Output::MODE, org_tubepress_api_const_options_values_ModeValue::VIMEO_SEARCH);
             $execContext->set(org_tubepress_api_const_options_names_Output::VIMEO_SEARCH_VALUE, $searchTerms);
             break;
         default:
             $execContext->set(org_tubepress_api_const_options_names_Output::MODE, org_tubepress_api_const_options_values_ModeValue::TAG);
             $execContext->set(org_tubepress_api_const_options_names_Output::TAG_VALUE, $searchTerms);
             break;
     }
     /* display the results as a thumb gallery */
     return $ioc->get('org_tubepress_api_patterns_cor_Chain')->execute($context, array('org_tubepress_impl_shortcode_commands_ThumbGalleryCommand'));
 }
 private function _getThemeName($ioc)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $themeHandler = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
     $fe = $ioc->get(org_tubepress_api_filesystem_Explorer::_);
     $currentTheme = $themeHandler->calculateCurrentThemeName();
     $basePath = $fe->getTubePressBaseInstallationPath();
     if ($currentTheme === 'default') {
         return '';
     }
     /* get the CSS file's path on the filesystem */
     $cssPath = $themeHandler->getCssPath($currentTheme);
     if (!is_readable($cssPath) || strpos($cssPath, 'themes' . DIRECTORY_SEPARATOR . 'default') !== false) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'No theme CSS found.');
         return '';
     } else {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Theme CSS found at <tt>%s</tt>', $cssPath);
     }
     return str_replace($basePath, '', $cssPath);
 }
 private static function _prependVideo($ioc, $id, $providerResult)
 {
     $videos = $providerResult->getVideoArray();
     /* see if the array already has it */
     if (self::_videoArrayAlreadyHasVideo($videos, $id)) {
         $videos = self::_moveVideoUpFront($videos, $id);
         $providerResult->setVideoArray($videos);
         return $providerResult;
     }
     $provider = $ioc->get('org_tubepress_api_provider_Provider');
     try {
         $video = $provider->getSingleVideo($id);
         array_unshift($videos, $video);
     } catch (Exception $e) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Could not prepend video %s to the gallery: %s', $customVideoId, $e->getMessage());
     }
     /* modify the feed result */
     $providerResult->setVideoArray($videos);
     return $providerResult;
 }
 /**
  * Determines if this message needs to be decoded.
  *
  * @param org_tubepress_api_http_HttpResponse $response The HTTP response.
  *
  * @return boolean True if this response should be decoded. False otherwise.
  */
 function needsToBeDecoded(org_tubepress_api_http_HttpResponse $response)
 {
     $entity = $response->getEntity();
     if ($entity === null) {
         org_tubepress_impl_log_Log::log($this->getLogPrefix(), 'Response contains no entity');
         return false;
     }
     $content = $entity->getContent();
     if ($content == '' || $content == null) {
         org_tubepress_impl_log_Log::log($this->getLogPrefix(), 'Response entity contains no content');
         return false;
     }
     $expectedHeaderName = $this->getHeaderName();
     $actualHeaderValue = $response->getHeaderValue($expectedHeaderName);
     if ($actualHeaderValue === null) {
         org_tubepress_impl_log_Log::log($this->getLogPrefix(), 'Response does not contain %s header. No need to decode.', $expectedHeaderName);
         return false;
     }
     org_tubepress_impl_log_Log::log($this->getLogPrefix(), 'Response contains %s header. Will attempt decode.', $expectedHeaderName);
     return true;
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 public function execute($context)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $galleryId = $execContext->get(org_tubepress_api_const_options_names_Advanced::GALLERY_ID);
     if ($galleryId == '') {
         $galleryId = mt_rand();
         $result = $execContext->set(org_tubepress_api_const_options_names_Advanced::GALLERY_ID, $galleryId);
         if ($result !== true) {
             return false;
         }
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Starting to build thumbnail gallery %s', $galleryId);
     $provider = $ioc->get(org_tubepress_api_provider_Provider::_);
     $pluginManager = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     $themeHandler = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
     $ms = $ioc->get(org_tubepress_api_message_MessageService::_);
     $pc = $ioc->get(org_tubepress_api_provider_ProviderCalculator::_);
     $qss = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $template = $themeHandler->getTemplateInstance('gallery.tpl.php');
     $page = $qss->getParamValueAsInt(org_tubepress_api_const_http_ParamName::PAGE, 1);
     $providerName = $pc->calculateCurrentVideoProvider();
     /* first grab the videos */
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Asking provider for videos');
     $feedResult = $provider->getMultipleVideos();
     $numVideos = sizeof($feedResult->getVideoArray());
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Provider has delivered %d videos', $numVideos);
     if ($numVideos == 0) {
         $context->returnValue = $ms->_('no-videos-found');
         return true;
     }
     /* send the template through the plugins */
     $template = $pluginManager->runFilters(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, $template, $feedResult, $page, $providerName);
     /* send gallery HTML through the plugins */
     $filteredHtml = $pluginManager->runFilters(org_tubepress_api_const_plugin_FilterPoint::HTML_GALLERY, $template->toString(), $feedResult, $page, $providerName);
     /* we're done. tie up */
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Done assembling gallery %d', $galleryId);
     $context->returnValue = $filteredHtml;
     return true;
 }
 /**
  * Execute the command.
  *
  * @param array $context An array of context elements (may be empty).
  *
  * @return boolean True if this command was able to handle the execution. False otherwise.
  */
 public function execute($context)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     $playerName = $execContext->get(org_tubepress_api_const_options_names_Display::CURRENT_PLAYER_NAME);
     if ($playerName !== org_tubepress_api_const_options_values_PlayerValue::SOLO) {
         return false;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Solo player detected. Checking query string for video ID.');
     /* see if we have a custom video ID set */
     $qss = $ioc->get('org_tubepress_api_querystring_QueryStringService');
     $videoId = $qss->getCustomVideo($_GET);
     if ($videoId == '') {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Solo player in use, but no video ID set in URL.');
         return false;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Building single video with ID %s', $videoId);
     $execContext->set(org_tubepress_api_const_options_names_Output::VIDEO, $videoId);
     /* display the results as a thumb gallery */
     $ioc->get('org_tubepress_api_patterns_cor_Chain')->execute($context, array('org_tubepress_impl_shortcode_commands_SingleVideoCommand'));
     return true;
 }
 /**
  * Generates the HTML for TubePress. Could be a gallery or single video.
  *
  * @param string $shortCodeContent The shortcode content.
  *
  * @return The HTML for the given shortcode, or the error message if there was a problem.
  */
 public function getHtmlForShortcode($shortCodeContent)
 {
     global $tubepress_base_url;
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $chain = $ioc->get(org_tubepress_spi_patterns_cor_Chain::_);
     $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     /* do a bit of logging */
     org_tubepress_impl_log_Log::log($this->getName(), 'Type of IOC container is %s', get_class($ioc));
     /* parse the shortcode if we need to */
     if ($shortCodeContent != '') {
         $shortcodeParser = $ioc->get(org_tubepress_api_shortcode_ShortcodeParser::_);
         $shortcodeParser->parse($shortCodeContent);
     }
     /* use the chain to get the HTML */
     org_tubepress_impl_log_Log::log($this->getName(), 'Running the shortcode HTML chain');
     $rawHtml = $this->_runChain($chain);
     /* send it through the filters */
     if ($pm->hasFilters(org_tubepress_api_const_plugin_FilterPoint::HTML_ANY)) {
         return $pm->runFilters(org_tubepress_api_const_plugin_FilterPoint::HTML_ANY, $rawHtml);
     }
     return $rawHtml;
 }
 /**
  * Fetches the feed from a remote provider
  *
  * @param string  $url      The URL to fetch.
  * @param boolean $useCache Whether or not to use the network cache.
  *
  * @return unknown The raw feed from the provider
  */
 public function fetch($url, $useCache)
 {
     global $tubepress_base_url;
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $cache = $ioc->get(org_tubepress_api_cache_Cache::_);
     $result = '';
     if ($useCache) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'First asking cache for <a href="%s">URL</a>', $url);
         $result = $cache->get($url);
         if ($result !== false) {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Cache has <a href="%s">URL</a>. Sweet.', $url);
         } else {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Cache does not have <a href="%s">URL</a>. We\'ll have to get it from the network.', $url);
             $result = $this->_getFromNetwork($url, $ioc);
             $cache->save($url, $result);
         }
     } else {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Skip cache check for <a href="%s">URL</a>', $url);
         $result = $this->_getFromNetwork($url, $ioc);
     }
     org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Raw result for <a href="%s">URL</a> is in the HTML source for this page. <span style="display:none">%s</span>', $url, htmlspecialchars($result));
     return $result;
 }
示例#28
0
 /**
  * Filters the HTML for the gallery.
  *
  * @param string $html      The gallery HTML.
  * @param string $galleryId The current gallery ID
  *
  * @return string The modified HTML
  */
 public function alter_galleryHtml($html, org_tubepress_api_provider_ProviderResult $providerResult, $page, $providerName)
 {
     if (!is_string($html)) {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Filter invoked with a non-string argument :(');
         return $html;
     }
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $filterManager = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     $galleryId = $context->get(org_tubepress_api_const_options_names_Advanced::GALLERY_ID);
     $args = $filterManager->runFilters(org_tubepress_api_const_plugin_FilterPoint::JAVASCRIPT_GALLERYINIT, array());
     $argCount = count($args);
     $toReturn = $html . "\n" . '<script type="text/javascript">' . "\n\t" . org_tubepress_api_const_js_TubePressGalleryInit::NAME_CLASS . '.' . org_tubepress_api_const_js_TubePressGalleryInit::NAME_INIT_FUNCTION . "({$galleryId}, {\n";
     $x = 0;
     foreach ($args as $name => $value) {
         $toReturn .= "\t\t{$name} : {$value}";
         if ($x + 1 < $argCount) {
             $toReturn .= ",\n";
         }
         $x++;
     }
     return $toReturn . "\n\t});\n</script>";
 }
 public function alter_searchInputTemplate(org_tubepress_api_template_Template $template)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $qss = $ioc->get(org_tubepress_api_querystring_QueryStringService::_);
     $hrps = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $ms = $ioc->get(org_tubepress_api_message_MessageService::_);
     $resultsUrl = $context->get(org_tubepress_api_const_options_names_InteractiveSearch::SEARCH_RESULTS_URL);
     $url = '';
     try {
         $url = new org_tubepress_api_url_Url($resultsUrl);
     } catch (Exception $e) {
         org_tubepress_impl_log_Log::log('Search Input Core Filter', $e->getMessage());
     }
     /* if the user didn't request a certain page, just send the search results right back here */
     if ($url == '') {
         $url = new org_tubepress_api_url_Url($qss->getFullUrl($_SERVER));
     }
     /* clean up the search terms a bit */
     $searchTerms = $hrps->getParamValue(org_tubepress_api_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[org_tubepress_api_const_http_ParamName::PAGE]);
     unset($params[org_tubepress_api_const_http_ParamName::SEARCH_TERMS]);
     /* apply the template variables */
     $template->setVariable(org_tubepress_api_const_template_Variable::SEARCH_HANDLER_URL, $url->toString());
     $template->setVariable(org_tubepress_api_const_template_Variable::SEARCH_HIDDEN_INPUTS, $params);
     $template->setVariable(org_tubepress_api_const_template_Variable::SEARCH_TERMS, $searchTerms);
     $template->setVariable(org_tubepress_api_const_template_Variable::SEARCH_BUTTON, $ms->_('Search'));
     //>(translatable)<
     return $template;
 }
 /**
  * Fetch a single video.
  *
  * @param string $customVideoId The video ID to fetch.
  *
  * @return org_tubepress_api_video_Video The video.
  */
 public function getSingleVideo($customVideoId)
 {
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Fetching video with ID <tt>%s</tt>', $customVideoId);
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $urlBuilder = $ioc->get('org_tubepress_api_url_UrlBuilder');
     $videoUrl = $urlBuilder->buildSingleVideoUrl($customVideoId);
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'URL to fetch is %s', $videoUrl);
     $feedRetrievalService = $ioc->get('org_tubepress_api_feed_FeedFetcher');
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     $results = $feedRetrievalService->fetch($videoUrl, $context->get(org_tubepress_api_const_options_names_Feed::CACHE_ENABLED));
     $factory = $ioc->get('org_tubepress_api_factory_VideoFactory');
     $videoArray = $factory->feedToVideoArray($results);
     $pm = $ioc->get('org_tubepress_api_plugin_PluginManager');
     $pc = $ioc->get('org_tubepress_api_provider_ProviderCalculator');
     if (empty($videoArray)) {
         throw new Exception("Could not find video with ID {$customVideoId}");
     }
     $result = new org_tubepress_api_provider_ProviderResult();
     $result->setEffectiveTotalResultCount(1);
     $result->setVideoArray($videoArray);
     $provider = $pc->calculateProviderOfVideoId($customVideoId);
     $pm->runFilters(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $result, $provider);
     return $videoArray[0];
 }