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; }
/** * 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 testStripSlashesDeep() { $testPatterns = array('\\"Hello\\"' => '"Hello"', '\\"Hi\\"' => '"Hi"', "\\\\\\x" => 'x', "\\'you\\'" => "'you'"); foreach ($testPatterns as $input => $expected) { $actual = org_tubepress_impl_util_StringUtils::stripslashes_deep($input); $this->assertTrue($actual === $expected, "{$actual} did not equal expected {$expected}"); } }
/** * Converts this template to a string * *@throws Exception If there was a problem. * * @return string The string representation of this template. */ public function toString() { ob_start(); extract($this->_source); include realpath($this->_path); $result = ob_get_contents(); ob_end_clean(); return org_tubepress_impl_util_StringUtils::removeEmptyLines($result); }
public function test() { ${org_tubepress_impl_options_ui_fields_AbstractOptionDescriptorBasedField::TEMPLATE_VAR_NAME} = 'some-name'; ${org_tubepress_impl_options_ui_fields_AbstractOptionDescriptorBasedField::TEMPLATE_VAR_VALUE} = 'some-value'; ob_start(); include BASE . '/sys/ui/templates/options_page/fields/text.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals(org_tubepress_impl_util_StringUtils::removeEmptyLines($this->_expected()), org_tubepress_impl_util_StringUtils::removeEmptyLines($result)); }
public function test() { ${org_tubepress_impl_options_ui_fields_AbstractOptionDescriptorBasedField::TEMPLATE_VAR_NAME} = 'some-name'; ${org_tubepress_impl_options_ui_fields_AbstractOptionDescriptorBasedField::TEMPLATE_VAR_VALUE} = 'poo'; ${org_tubepress_impl_options_ui_fields_DropdownField::TEMPLATE_VAR_ACCEPTABLE_VALUES} = array('crack' => 'rock', 'poo' => 'some-value', 'pretzels' => 'jets'); ob_start(); include BASE . '/sys/ui/templates/options_page/fields/dropdown.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals(org_tubepress_impl_util_StringUtils::removeEmptyLines($this->_expected()), org_tubepress_impl_util_StringUtils::removeEmptyLines($result)); }
/** * 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; }
public function test() { $tab1 = \Mockery::mock(org_tubepress_spi_options_ui_Tab::_); $tab1->shouldReceive('getTitle')->times(3)->andReturn('title1'); $tab1->shouldReceive('getHtml')->once()->andReturn('html1'); $tab2 = \Mockery::mock(org_tubepress_spi_options_ui_Tab::_); $tab2->shouldReceive('getTitle')->times(3)->andReturn('title2'); $tab2->shouldReceive('getHtml')->once()->andReturn('html2'); ${org_tubepress_impl_options_ui_DefaultTabsHandler::TEMPLATE_VAR_TABS} = array($tab1, $tab2); ob_start(); include BASE . '/sys/ui/templates/options_page/tabs.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals(org_tubepress_impl_util_StringUtils::removeEmptyLines($this->_expected()), org_tubepress_impl_util_StringUtils::removeEmptyLines($result)); //$this->assertEquals($this->_removeNewLines($this->_expected()), $this->_removeNewLines($result)); }
protected function _magic($name, $value) { /** If it's an array, send each element through the filter. */ if (is_array($value)) { foreach ($value as $key => $subValue) { $value[$key] = $this->_magic($key, $subValue); } return $value; } /** We're only interested in strings. */ if (!is_string($value)) { return $value; } $toReturn = trim($value); $toReturn = htmlspecialchars($toReturn, ENT_NOQUOTES); $toReturn = org_tubepress_impl_util_StringUtils::stripslashes_deep($toReturn); $toReturn = $this->_booleanMagic($toReturn); return $toReturn; }
/** * 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')); }
public function test() { $one = \Mockery::mock(org_tubepress_spi_options_ui_Field::_); $one->shouldReceive('getHtml')->once()->andReturn('one-html'); $one->shouldReceive('getTitle')->once()->andReturn('one-title'); $one->shouldReceive('getDescription')->once()->andReturn('one-description'); $one->shouldReceive('isProOnly')->once()->andReturn(true); $one->shouldReceive('getArrayOfApplicableProviderNames')->once()->andReturn(array('foo', 'bar')); $two = \Mockery::mock(org_tubepress_spi_options_ui_Field::_); $two->shouldReceive('getHtml')->once()->andReturn('two-html'); $two->shouldReceive('getTitle')->once()->andReturn('two-title'); $two->shouldReceive('getDescription')->once()->andReturn('two-description'); $two->shouldReceive('isProOnly')->once()->andReturn(false); $two->shouldReceive('getArrayOfApplicableProviderNames')->once()->andReturn(array()); ${org_tubepress_impl_options_ui_tabs_AbstractTab::TEMPLATE_VAR_WIDGETARRAY} = array($one, $two); ob_start(); include BASE . '/sys/ui/templates/options_page/tab.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals(org_tubepress_impl_util_StringUtils::removeEmptyLines($this->_expected()), org_tubepress_impl_util_StringUtils::removeEmptyLines($result)); }
public function test() { $one = \Mockery::mock(org_tubepress_api_options_OptionDescriptor::_); $two = \Mockery::mock(org_tubepress_api_options_OptionDescriptor::_); $three = \Mockery::mock(org_tubepress_api_options_OptionDescriptor::_); $one->shouldReceive('getName')->atLeast()->once()->andReturn('name-one'); $two->shouldReceive('getName')->atLeast()->once()->andReturn('name-two'); $one->shouldReceive('getLabel')->atLeast()->once()->andReturn('label-one'); $two->shouldReceive('getLabel')->atLeast()->once()->andReturn('label-two'); $three->shouldReceive('getName')->atLeast()->once()->andReturn('name-three'); $three->shouldReceive('getLabel')->atLeast()->once()->andReturn('label-three'); $descriptors = array($one, $two, $three); ${org_tubepress_impl_options_ui_fields_AbstractMultiSelectField::TEMPLATE_VAR_NAME} = 'some-name'; ${org_tubepress_impl_options_ui_fields_AbstractMultiSelectField::TEMPLATE_VAR_DESCRIPTORS} = $descriptors; ${org_tubepress_impl_options_ui_fields_AbstractMultiSelectField::TEMPLATE_VAR_CURRENTVALUES} = array('crack', 'name-one', 'pittsburgh', 'steelers', 'name-three'); ob_start(); include BASE . '/sys/ui/templates/options_page/fields/multiselect.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals(org_tubepress_impl_util_StringUtils::removeEmptyLines($this->_expected()), org_tubepress_impl_util_StringUtils::removeEmptyLines($result)); }
/** * Does the heavy lifting of generating videos/galleries from content. * * @param string $content The WordPress content. * @param string $trigger The shortcode keyword * * @return string The modified content. */ private static function _getHtml($content, $trigger, $parser, $ioc) { $ms = $ioc->get(org_tubepress_api_message_MessageService::_); $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_); $gallery = $ioc->get(org_tubepress_api_shortcode_ShortcodeHtmlGenerator::_); /* Parse each shortcode one at a time */ while ($parser->somethingToParse($content, $trigger)) { /* Get the HTML for this particular shortcode. Could be a single video or a gallery. */ try { $generatedHtml = $gallery->getHtmlForShortcode($content); } catch (Exception $e) { $generatedHtml = $e->getMessage(); } /* remove any leading/trailing <p> tags from the content */ $pattern = '/(<[P|p]>\\s*)(' . preg_quote($context->getActualShortcodeUsed(), '/') . ')(\\s*<\\/[P|p]>)/'; $content = preg_replace($pattern, '${2}', $content); /* replace the shortcode with our new content */ $currentShortcode = $context->getActualShortcodeUsed(); $content = org_tubepress_impl_util_StringUtils::replaceFirst($currentShortcode, $generatedHtml, $content); /* reset the context for the next shortcode */ $context->reset(); } return $content; }