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;
 }
Esempio n. 3
0
 /**
  * Prints the output of the TubePress widget.
  *
  * @param array $opts The array of widget options.
  *
  * @return void
  */
 public static function printWidget($opts)
 {
     extract($opts);
     $iocContainer = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $iocContainer->get('org_tubepress_api_exec_ExecutionContext');
     $parser = $iocContainer->get('org_tubepress_api_shortcode_ShortcodeParser');
     $gallery = $iocContainer->get('org_tubepress_api_shortcode_ShortcodeHtmlGenerator');
     $ms = $iocContainer->get('org_tubepress_api_message_MessageService');
     /* Turn on logging if we need to */
     org_tubepress_impl_log_Log::setEnabled($context->get(org_tubepress_api_const_options_names_Advanced::DEBUG_ON), $_GET);
     /* default widget options */
     $defaultWidgetOptions = array(org_tubepress_api_const_options_names_Display::RESULTS_PER_PAGE => 3, org_tubepress_api_const_options_names_Meta::VIEWS => false, org_tubepress_api_const_options_names_Meta::DESCRIPTION => true, org_tubepress_api_const_options_names_Display::DESC_LIMIT => 50, org_tubepress_api_const_options_names_Display::CURRENT_PLAYER_NAME => org_tubepress_api_const_options_values_PlayerValue::POPUP, org_tubepress_api_const_options_names_Display::THUMB_HEIGHT => 105, org_tubepress_api_const_options_names_Display::THUMB_WIDTH => 135, org_tubepress_api_const_options_names_Display::PAGINATE_ABOVE => false, org_tubepress_api_const_options_names_Display::PAGINATE_BELOW => false, org_tubepress_api_const_options_names_Display::THEME => 'sidebar', org_tubepress_api_const_options_names_Display::FLUID_THUMBS => false);
     /* now apply the user's options */
     $rawTag = $context->get(org_tubepress_api_const_options_names_Widget::TAGSTRING);
     $widgetTag = org_tubepress_impl_util_StringUtils::removeNewLines($rawTag);
     $parser->parse($widgetTag);
     /* calculate the final options */
     $finalOptions = array_merge($defaultWidgetOptions, $context->getCustomOptions());
     $context->setCustomOptions($finalOptions);
     if ($context->get(org_tubepress_api_const_options_names_Display::THEME) === '') {
         $context->set(org_tubepress_api_const_options_names_Display::THEME, 'sidebar');
     }
     try {
         $out = $gallery->getHtmlForShortcode('');
     } catch (Exception $e) {
         $out = $ms->_('no-videos-found');
     }
     /* do the standard WordPress widget dance */
     echo $before_widget . $before_title . $context->get(org_tubepress_api_const_options_names_Widget::TITLE) . $after_title . $out . $after_widget;
     /* reset the context for the next shortcode */
     $context->reset();
 }
 function setup()
 {
     parent::setUp();
     $this->_sut = new org_tubepress_impl_provider_SimpleProvider();
     $this->_fakeVideo = \Mockery::mock('org_tubepress_api_video_Video');
     org_tubepress_impl_log_Log::setEnabled(false, array());
 }
 function setUp()
 {
     parent::setUp();
     $this->_sut = $this->_getSutInstance();
     org_tubepress_impl_log_Log::setEnabled(true, array('tubepress_debug' => 'true'));
     $this->_server = 'http://tubepress.org/http_tests';
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $mp = $ioc->get(org_tubepress_spi_http_HttpMessageParser::_);
     $mp->shouldReceive('getHeadersStringFromRawHttpMessage')->andReturnUsing(function ($data) {
         $x = new org_tubepress_impl_http_DefaultHttpMessageParser();
         return $x->getHeadersStringFromRawHttpMessage($data);
     });
     $mp->shouldReceive('getBodyStringFromRawHttpMessage')->andReturnUsing(function ($data) {
         $x = new org_tubepress_impl_http_DefaultHttpMessageParser();
         return $x->getBodyStringFromRawHttpMessage($data);
     });
     $mp->shouldReceive('getArrayOfHeadersFromRawHeaderString')->andReturnUsing(function ($data) {
         $x = new org_tubepress_impl_http_DefaultHttpMessageParser();
         return $x->getArrayOfHeadersFromRawHeaderString($data);
     });
     $mp->shouldReceive('getHeaderArrayAsString')->andReturnUsing(function ($data) {
         $x = new org_tubepress_impl_http_DefaultHttpMessageParser();
         return $x->getHeaderArrayAsString($data);
     });
 }
 /**
  * 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;
 }
Esempio n. 7
0
 /**
  * Conditionally enables the log.
  *
  * @param boolean $enabled Whether or not to enable the log.
  * @param array   $getVars The PHP $_GET array.
  *
  * @return void
  */
 public static function setEnabled($enabled, $getVars)
 {
     self::$_enabled = $enabled && isset($getVars['tubepress_debug']) && $getVars['tubepress_debug'] == 'true';
     if (self::$_enabled) {
         self::$_birthDate = microtime(true);
     }
 }
Esempio n. 8
0
 /**
  * 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;
 }
 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;
 }
 function testCompress()
 {
     org_tubepress_impl_log_Log::setEnabled(true, array('tubepress_debug' => true));
     for ($x = 1; $x < 10; $x++) {
         $this->_testCompress($x);
     }
     org_tubepress_impl_log_Log::setEnabled(false, array());
 }
 /**
  * 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;
 }
 function setUp()
 {
     parent::setUp();
     $this->_sut = new org_tubepress_impl_player_DefaultPlayerHtmlGenerator();
     org_tubepress_impl_log_Log::setEnabled(false, array());
     $this->_video = \Mockery::mock('org_tubepress_api_video_Video');
     $this->_video->shouldReceive('getId')->once()->andReturn('video-id');
 }
Esempio n. 13
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;
 }
Esempio n. 21
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);
 }
 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;
 }
 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;
             }
         }
     }
 }
 /**
  * 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;
 }
Esempio n. 29
0
 function testRegularGet()
 {
     org_tubepress_impl_log_Log::setEnabled(true, array('tubepress_debug' => 'true'));
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $this->_hmp = $ioc->get(org_tubepress_spi_http_HttpMessageParser::_);
     $this->_hmp->shouldReceive('getHeadersStringFromRawHttpMessage')->with($this->_sut->responseBody)->andReturn($this->_sut->headersString);
     $this->_hmp->shouldReceive('getBodyStringFromRawHttpMessage')->with($this->_sut->responseBody)->andReturn('body string');
     $this->_hmp->shouldReceive('getArrayOfHeadersFromRawHeaderString')->with($this->_sut->headersString)->andReturn($this->_sut->headers);
     $result = $this->_sut->execute($this->_context);
     $this->assertTrue($result);
     $response = $this->_context->response;
     $this->assertTrue($response instanceof org_tubepress_api_http_HttpResponse, 'Result is not a response');
     $this->assertTrue($response->getStatusCode() === 200);
     $this->assertTrue($response->getAllHeaders() === array('Content-Type' => 'text/html', 'Content-Encoding' => 'gzip'));
     $entity = $response->getEntity();
     $this->assertTrue($entity instanceof org_tubepress_api_http_HttpEntity);
     $this->assertTrue($entity->getContent() === 'body string', 'wrong response body');
     $this->assertTrue($entity->getContentLength() === 11, 'wrong content length');
     $this->assertTrue($entity->getContentType() === 'text/html', 'wrong content type');
     org_tubepress_impl_log_Log::setEnabled(false, array());
 }
 /**
  * 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;
 }