public function getHeadHtmlMeta()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $qss = $ioc->get('org_tubepress_api_querystring_QueryStringService');
     $page = $qss->getPageNum($_GET);
     return $page > 1 ? "<meta name=\"robots\" content=\"noindex, nofollow\" />" : '';
 }
 function testFetchGoodXmlCacheDisabled()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $httpClient = $ioc->get(org_tubepress_api_http_HttpClient::_);
     $httpClient->shouldReceive('executeAndHandleResponse')->once()->andReturn('someValue');
     $this->assertEquals('someValue', $this->_sut->fetch("http://www.ietf.org/css/ietf.css", false));
 }
Exemplo n.º 3
0
 /**
  * Registers the TubePress options page
  *
  * @return void
  */
 public static function executeOptionsPage()
 {
     /* grab the storage manager */
     $iocContainer = org_tubepress_impl_ioc_IocContainer::getInstance();
     $wpsm = $iocContainer->get(org_tubepress_api_options_StorageManager::_);
     /* initialize our options in case we need to */
     $wpsm->init();
     /* get the form handler */
     $optionsForm = $iocContainer->get(org_tubepress_api_options_ui_FormHandler::_);
     $hrps = $iocContainer->get(org_tubepress_api_http_HttpRequestParameterService::_);
     /* are we updating? */
     if ($hrps->hasParam('tubepress_save')) {
         self::_verifyNonce();
         try {
             $result = $optionsForm->onSubmit();
             if ($result === null) {
                 echo '<div id="message" class="updated fade"><p><strong>Options updated</strong></p></div>';
             } else {
                 self::_error($result);
             }
         } catch (Exception $error) {
             self::_error($error->getMessage());
         }
     }
     print $optionsForm->getHtml();
 }
 private function _wrappedParse($content)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $keyword = $context->get(org_tubepress_api_const_options_names_Advanced::KEYWORD);
     if (!$this->somethingToParse($content, $keyword)) {
         return;
     }
     preg_match("/\\[{$keyword}\\b(.*)\\]/", $content, $matches);
     org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Found a shortcode: %s', $matches[0]);
     $context->setActualShortcodeUsed($matches[0]);
     /* Anything matched? */
     if (isset($matches[1]) && $matches[1] != '') {
         $text = preg_replace('/[\\x{00a0}\\x{200b}]+/u', ' ', utf8_encode($matches[1]));
         $text = self::_convertQuotes($text);
         $pattern = '/(\\w+)\\s*=\\s*"([^"]*)"(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*\'([^\']*)\'(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*([^\\s\'"]+)(?:\\s*,)?(?:\\s|$)/';
         if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) {
             org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Candidate options detected in shortcode: %s', $matches[0]);
             $toReturn = self::_buildNameValuePairArray($match, $ioc);
             $context->setCustomOptions($toReturn);
         }
     } else {
         org_tubepress_impl_log_Log::log(self::$_logPrefix, 'No custom options detected in shortcode: %s', $matches[0]);
     }
 }
 public function getHeadHtmlMeta()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $qss = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $page = $qss->getParamValueAsInt(org_tubepress_api_const_http_ParamName::PAGE, 1);
     return $page > 1 ? "<meta name=\"robots\" content=\"noindex, nofollow\" />" : '';
 }
 /**
  * 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;
 }
 protected function getDelegateFormHandlers()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $tabs = $ioc->get(org_tubepress_impl_options_ui_DefaultTabsHandler::__);
     $filter = $ioc->get(org_tubepress_impl_options_ui_fields_FilterMultiSelectField::__);
     return array($tabs, $filter);
 }
 protected function addToTemplate(org_tubepress_api_template_Template $template)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $currentMode = $execContext->get(org_tubepress_api_const_options_names_Output::GALLERY_SOURCE);
     $template->setVariable(self::TEMPLATE_VAR_CURRENT_MODE, $currentMode);
 }
Exemplo n.º 9
0
 /**
  * Perform boot procedure.
  *
  * @return void
  */
 public function on_boot()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $ed = $ioc->get(org_tubepress_api_environment_Detector::_);
     $fse = $ioc->get(org_tubepress_api_filesystem_Explorer::_);
     if (!$ed->isWordPress()) {
         return;
     }
     global $tubepress_base_url;
     $baseName = $fse->getTubePressInstallationDirectoryBaseName();
     /** http://code.google.com/p/tubepress/issues/detail?id=495#c2 */
     if ($this->_isWordPressMuDomainMapped()) {
         $prefix = $this->_getScheme() . constant('COOKIE_DOMAIN');
     } else {
         $prefix = site_url();
     }
     $tubepress_base_url = $prefix . "/wp-content/plugins/{$baseName}";
     /* register the plugin's message bundles */
     load_plugin_textdomain('tubepress', false, "{$baseName}/sys/i18n");
     add_filter('the_content', array('org_tubepress_impl_env_wordpress_Main', 'contentFilter'));
     add_action('wp_head', array('org_tubepress_impl_env_wordpress_Main', 'headAction'));
     add_action('init', array('org_tubepress_impl_env_wordpress_Main', 'initAction'));
     add_action('admin_menu', array('org_tubepress_impl_env_wordpress_OptionsPage', 'menuAction'));
     add_action('admin_enqueue_scripts', array('org_tubepress_impl_env_wordpress_OptionsPage', 'initAction'));
     add_action('widgets_init', array('org_tubepress_impl_env_wordpress_Widget', 'initAction'));
 }
 function testBoot()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     $expectedSystemFilters = array(array(org_tubepress_api_const_plugin_FilterPoint::OPTION_SET_PRE_VALIDATION, 'org_tubepress_impl_plugin_filters_prevalidationoptionset_YouTubePlaylistPlPrefixRemover'), array(org_tubepress_api_const_plugin_FilterPoint::OPTION_SET_PRE_VALIDATION, 'org_tubepress_impl_plugin_filters_prevalidationoptionset_StringMagic'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_EMBEDDED, 'org_tubepress_impl_plugin_filters_embeddedtemplate_CoreVariables'), array(org_tubepress_api_const_plugin_FilterPoint::HTML_EMBEDDED, 'org_tubepress_impl_plugin_filters_embeddedhtml_PlayerJavaScriptApi'), array(org_tubepress_api_const_plugin_FilterPoint::HTML_GALLERY, 'org_tubepress_impl_plugin_filters_galleryhtml_GalleryJs'), array(org_tubepress_api_const_plugin_FilterPoint::JAVASCRIPT_GALLERYINIT, 'org_tubepress_impl_plugin_filters_galleryinitjs_GalleryInitJsBaseParams'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, 'org_tubepress_impl_plugin_filters_gallerytemplate_CoreVariables'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, 'org_tubepress_impl_plugin_filters_gallerytemplate_EmbeddedPlayerName'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, 'org_tubepress_impl_plugin_filters_gallerytemplate_Pagination'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, 'org_tubepress_impl_plugin_filters_gallerytemplate_Player'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, 'org_tubepress_impl_plugin_filters_gallerytemplate_VideoMeta'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_PLAYER, 'org_tubepress_impl_plugin_filters_playertemplate_CoreVariables'), array(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, 'org_tubepress_impl_plugin_filters_providerresult_ResultCountCapper'), array(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, 'org_tubepress_impl_plugin_filters_providerresult_VideoBlacklist'), array(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, 'org_tubepress_impl_plugin_filters_providerresult_PerPageSorter'), array(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, 'org_tubepress_impl_plugin_filters_providerresult_VideoPrepender'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SEARCHINPUT, 'org_tubepress_impl_plugin_filters_searchinputtemplate_CoreVariables'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SINGLEVIDEO, 'org_tubepress_impl_plugin_filters_singlevideotemplate_CoreVariables'), array(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SINGLEVIDEO, 'org_tubepress_impl_plugin_filters_singlevideotemplate_VideoMeta'), array(org_tubepress_api_const_plugin_FilterPoint::VARIABLE_READ_FROM_EXTERNAL_INPUT, 'org_tubepress_impl_plugin_filters_variablereadfromexternalinput_StringMagic'));
     foreach ($expectedSystemFilters as $filter) {
         $pm->shouldReceive('registerFilter')->with($filter[0], anInstanceOf($filter[1]))->once();
     }
     $pm->shouldReceive('registerListener')->with(org_tubepress_api_const_plugin_EventName::BOOT, anInstanceOf('org_tubepress_impl_plugin_listeners_StorageManagerInitListener'));
     $pm->shouldReceive('registerListener')->with(org_tubepress_api_const_plugin_EventName::BOOT, anInstanceOf('org_tubepress_impl_plugin_listeners_WordPressBoot'));
     $pm->shouldReceive('registerListener')->with(org_tubepress_api_const_plugin_EventName::BOOT, anInstanceOf('org_tubepress_impl_plugin_listeners_SkeletonExistsListener'));
     $pm->shouldReceive('notifyListeners')->with(org_tubepress_api_const_plugin_EventName::BOOT)->once();
     $envD = $ioc->get(org_tubepress_api_environment_Detector::_);
     $envD->shouldReceive('isWordPress')->once()->andReturn(false);
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $context->shouldReceive('get')->with(org_tubepress_api_const_options_names_Advanced::DEBUG_ON)->andReturn(false);
     $fe = $ioc->get(org_tubepress_api_filesystem_Explorer::_);
     $fe->shouldReceive('getDirectoriesInDirectory')->once()->with('<<user-content-dir>>/plugins', anything())->andReturn(array('fakedirectory'));
     $fe->shouldReceive('getFilenamesInDirectory')->once()->with('fakedirectory', anything())->andReturn(array(dirname(__FILE__) . '/../../../resources/simplePhpFile.php'));
     $th = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
     $th->shouldReceive('getUserContentDirectory')->once()->andReturn('<<user-content-dir>>');
     $sm = $ioc->get(org_tubepress_api_options_StorageManager::_);
     $sm->shouldReceive('init')->once();
     $this->_sut->boot();
 }
Exemplo n.º 11
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;
 }
 private function _wrappedParse($content)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     /* what trigger word are we using? */
     $keyword = $context->get(org_tubepress_api_const_options_names_Advanced::KEYWORD);
     if (!$this->somethingToParse($content, $keyword)) {
         return;
     }
     $toReturn = array();
     preg_match("/\\[{$keyword}\\b(.*)\\]/", $content, $matches);
     if (sizeof($matches) === 0) {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'No shortcodes detected in content');
         return;
     }
     org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Found a shortcode: %s', $matches[0]);
     $context->setActualShortcodeUsed($matches[0]);
     /* Anything matched? */
     if (isset($matches[1]) && $matches[1] != '') {
         $text = preg_replace('/[\\x{00a0}\\x{200b}]+/u', ' ', $matches[1]);
         $text = self::_convertQuotes($text);
         $pattern = '/(\\w+)\\s*=\\s*"([^"]*)"(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*\'([^\']*)\'(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*([^\\s\'"]+)(?:\\s*,)?(?:\\s|$)/';
         if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) {
             org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Custom options detected in shortcode: %s', $matches[0]);
             $toReturn = self::_parseCustomOption($toReturn, $match, $ioc);
             $context->setCustomOptions($toReturn);
         }
     } else {
         org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'No custom options detected in shortcode: %s', $matches[0]);
     }
 }
 function testCanHandleYouTube()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::AUTOPLAY)->andReturn(false);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::PLAYER_COLOR)->andReturn('123456');
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::PLAYER_HIGHLIGHT)->andReturn('654321');
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::SHOW_INFO)->andReturn(true);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::LOOP)->andReturn(false);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::SHOW_RELATED)->andReturn(true);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::FULLSCREEN)->andReturn(false);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::ENABLE_JS_API)->andReturn(false);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::HIGH_QUALITY)->andReturn(true);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Advanced::GALLERY_ID)->andReturn('some-gallery-id');
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::AUTOHIDE)->andReturn(true);
     $execContext->shouldReceive('get')->once()->with(org_tubepress_api_const_options_names_Embedded::MODEST_BRANDING)->andReturn(false);
     $mockTemplate = \Mockery::mock('org_tubepress_api_template_Template');
     $mockChainContext = \Mockery::mock('stdClass');
     $mockChainContext->providerName = org_tubepress_api_provider_Provider::YOUTUBE;
     $mockChainContext->videoId = 'video_id';
     $theme = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
     $theme->shouldReceive('getTemplateInstance')->once()->with('embedded_flash/youtube.tpl.php')->andReturn($mockTemplate);
     $this->assertTrue($this->_sut->execute($mockChainContext));
     $this->assertEquals($mockTemplate, $mockChainContext->template);
     $this->assertEquals('http://www.youtube.com/embed/video_id?color1=654321&color2=123456&rel=1&autoplay=0&loop=0&fs=0&showinfo=1&wmode=transparent&enablejsapi=0&autohide=1&modestbranding=0&hd=1', $mockChainContext->dataUrl->toString());
     $this->assertEquals('youtube', $mockChainContext->embeddedImplementationName);
 }
Exemplo n.º 14
0
 function testVideoMetaAboveAndBelow()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $messageService = $ioc->get(org_tubepress_api_message_MessageService::_);
     $messageService->shouldReceive('_')->atLeast()->once()->andReturnUsing(function ($msg) {
         return "##{$msg}##";
     });
     $metaNames = org_tubepress_impl_util_LangUtils::getDefinedConstants(org_tubepress_api_const_options_names_Meta::_);
     $shouldShow = array();
     $labels = array();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $odr = $ioc->get(org_tubepress_api_options_OptionDescriptorReference::_);
     $odr->shouldReceive('findOneByName')->times(17)->andReturnUsing(function ($m) {
         $mock = \Mockery::mock(org_tubepress_api_options_OptionDescriptor::_);
         $mock->shouldReceive('getLabel')->once()->andReturn('video-' . $m);
         return $mock;
     });
     foreach ($metaNames as $metaName) {
         $shouldShow[$metaName] = "<<value of {$metaName}>>";
         $labels[$metaName] = '##video-' . $metaName . '##';
         $execContext->shouldReceive('get')->once()->with($metaName)->andReturnUsing(function ($m) {
             return "<<value of {$m}>>";
         });
     }
     $mockTemplate = \Mockery::mock(org_tubepress_api_template_Template::_);
     $mockTemplate->shouldReceive('setVariable')->once()->with(org_tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow);
     $mockTemplate->shouldReceive('setVariable')->once()->with(org_tubepress_api_const_template_Variable::META_LABELS, $labels);
     $providerResult = \Mockery::mock('org_tubepress_api_provider_ProviderResult');
     $this->assertEquals($mockTemplate, $this->_sut->alter_galleryTemplate($mockTemplate, $providerResult, 1, org_tubepress_api_provider_Provider::YOUTUBE));
 }
 function testHeadMetaPageTwo()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $qss = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $qss->shouldReceive('getParamValueAsInt')->once()->with(org_tubepress_api_const_http_ParamName::PAGE, 1)->andReturn(2);
     $this->assertEquals('<meta name="robots" content="noindex, nofollow" />', $this->_sut->getHeadHtmlMeta());
 }
 /**
  * Constructor.
  */
 public function __construct()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $this->_storageManager = $ioc->get(org_tubepress_api_options_StorageManager::_);
     $this->_validationService = $ioc->get(org_tubepress_api_options_OptionValidator::_);
     $this->_pluginManager = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
 }
 public function testNotExists()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $odr = $ioc->get(org_tubepress_api_options_OptionDescriptorReference::_);
     $odr->shouldReceive('findOneByName')->once()->with('name')->andReturn(null);
     $this->assertTrue($this->_sut->isValid('name', 120) === false);
 }
Exemplo n.º 18
0
 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;
 }
Exemplo n.º 19
0
 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');
     $ms = $ioc->get('org_tubepress_api_message_MessageService');
     $resultsUrl = $context->get(org_tubepress_api_const_options_names_Output::SEARCH_RESULTS_URL);
     /* if the user didn't request a certain page, just send the search results right back here */
     if ($resultsUrl == '') {
         $resultsUrl = $qss->getFullUrl($_SERVER);
     }
     /* clean up the search terms a bit */
     $searchTerms = urldecode($qss->getSearchTerms($_GET));
     $searchTerms = org_tubepress_impl_util_StringUtils::cleanForSearch($searchTerms);
     /* 
      * 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
      */
     $url = new org_tubepress_api_url_Url($resultsUrl);
     $params = $url->getQueryVariables();
     unset($params[org_tubepress_api_const_querystring_QueryParamName::PAGE]);
     unset($params[org_tubepress_api_const_querystring_QueryParamName::SEARCH_TERMS]);
     /* apply the template variables */
     $template->setVariable(org_tubepress_api_const_template_Variable::SEARCH_HANDLER_URL, $resultsUrl);
     $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-input-button'));
     return $template;
 }
Exemplo n.º 20
0
 protected function getAdditionalFields()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $fb = $ioc->get(org_tubepress_spi_options_ui_FieldBuilder::_);
     $fb->shouldReceive('buildMetaDisplayMultiSelectField')->once()->andReturn('foobar');
     return array('foobar');
 }
 /**
  * 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;
 }
Exemplo n.º 22
0
 function testNonWordPress()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $ed = $ioc->get(org_tubepress_api_environment_Detector::_);
     $ed->shouldReceive('isWordPress')->once()->andReturn(false);
     $this->_sut->on_boot();
 }
 /**
  * Gets the failure message of a name/value pair that has failed validation.
  *
  * @param string       $optionName The option name
  * @param unknown_type $candidate  The candidate option value
  *
  * @return unknown Null if the option passes validation, otherwise a string failure message.
  */
 function getProblemMessage($optionName, $candidate)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $odr = $ioc->get(org_tubepress_api_options_OptionDescriptorReference::_);
     $descriptor = $odr->findOneByName($optionName);
     if ($descriptor === null) {
         return sprintf('No option with name %s', $optionName);
     }
     if ($descriptor->hasValidValueRegex()) {
         if (preg_match_all($descriptor->getValidValueRegex(), (string) $candidate, $matches) >= 1 && $matches[0][0] === (string) $candidate) {
             return null;
         }
         return sprintf('"%s" must match the regular expression %s. You supplied "%s".', $optionName, $descriptor->getValidValueRegex(), $candidate);
     }
     if ($descriptor->hasDiscreteAcceptableValues()) {
         $acceptableValues = $descriptor->getAcceptableValues();
         if (org_tubepress_impl_util_LangUtils::isAssociativeArray($acceptableValues)) {
             $values = array_keys($descriptor->getAcceptableValues());
         } else {
             $values = array_values($acceptableValues);
         }
         if (in_array($candidate, $values)) {
             return null;
         }
         return sprintf('"%s" must be one of {%s}. You supplied "%s".', $optionName, implode(', ', $values), $candidate);
     }
     if ($descriptor->isBoolean()) {
         if (is_bool($candidate)) {
             return null;
         }
         return sprintf('"%s" can only accept true/false values. You supplied "%s".', $optionName, $candidate);
     }
     return null;
 }
 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);
     });
 }
Exemplo n.º 25
0
 function testNobodyCanHandle()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = new stdClass();
     $mockCommand = $ioc->get('org_tubepress_spi_patterns_cor_Command');
     $mockCommand->shouldReceive('execute')->once()->with($context)->andReturn(false);
     $this->assertFalse($this->_sut->execute($context, array('org_tubepress_spi_patterns_cor_Command')));
 }
Exemplo n.º 26
0
 /**
  * Perform optional setup to handle a new HTTP request.
  *
  * @param org_tubepress_api_http_HttpRequest $request The HTTP request to handle.
  *
  * @return void
  */
 protected function prepareToHandleNewRequest(org_tubepress_api_http_HttpRequest $request)
 {
     org_tubepress_impl_log_Log::log($this->logPrefix(), 'Creating stream context...');
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $this->_httpMessageParser = $ioc->get(org_tubepress_spi_http_HttpMessageParser::_);
     $streamParams = array(self::$_stream_http_transport => array(self::$_http_context_option_header => $this->_httpMessageParser->getHeaderArrayAsString($request), self::$_http_context_option_method => $request->getMethod(), self::$_http_context_option_useragent => $request->getHeaderValue(org_tubepress_api_http_HttpRequest::HTTP_HEADER_USER_AGENT), self::$_http_context_option_ignoreerrors => true, self::$_http_context_option_content => $request->getEntity() === null ? null : $request->getEntity()->getContent(), self::$_http_context_option_protocol => '1.0'));
     $this->_streamContext = stream_context_create($streamParams);
 }
 private function _setupFilters($name, $value)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
     $pm->shouldReceive('runFilters')->once()->with(org_tubepress_api_const_plugin_FilterPoint::OPTION_SET_PRE_VALIDATION, $value, $name)->andReturnUsing(function ($a, $b, $c) {
         return "<<{$b}>>";
     });
 }
Exemplo n.º 28
0
 protected function _performAdditionGetDescriptionSetup()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $themeHandler = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
     $filesystem = $ioc->get(org_tubepress_api_filesystem_Explorer::_);
     $filesystem->shouldReceive('getTubePressBaseInstallationPath')->once()->andReturn('<<basepath>>');
     $themeHandler->shouldReceive('getUserContentDirectory')->once()->andReturn('<<user content dir>>');
 }
Exemplo n.º 29
0
 function testNoCustomVideo()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $qss = $ioc->get(org_tubepress_api_http_HttpRequestParameterService::_);
     $qss->shouldReceive('getParamValue')->once()->with(org_tubepress_api_const_http_ParamName::VIDEO)->andReturn('');
     $providerResult = \Mockery::mock('org_tubepress_api_provider_ProviderResult');
     $this->assertEquals($providerResult, $this->_sut->alter_providerResult($providerResult, 'provider-name'));
 }
Exemplo n.º 30
0
 public function setup()
 {
     parent::setUp();
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $this->_messageService = $ioc->get(org_tubepress_api_message_MessageService::_);
     $this->_messageService->shouldReceive('_')->andReturnUsing(function ($key) {
         return "<<message: {$key}>>";
     });
 }