【发布时间】:2018-08-21 16:52:29
【问题描述】:
我正在使用不再工作的旧 Google 自定义搜索代码,我想检查如何修复代码以使用新的 Google 自定义搜索。
我尝试了很多没有运气的东西,这是我今天的代码:
// Google Search (deprecated - to remove)
if ($task == 'search' && $params->get('googleSearch'))
{
$language = JFactory::getLanguage();
$lang = $language->getTag();
// Fallback to the new container ID without breaking things
$googleSearchContainerID = trim($params->get('googleSearchContainer', 'k2GoogleSearchContainer'));
if($googleSearchContainerID == 'k2Container'){
$googleSearchContainerID = 'k2GoogleSearchContainer';
}
$document->addScript('https://www.google.com/jsapi');
$document->addScriptDeclaration('
google.load("search", "1", {"language" : "'.$lang.'"});
function OnLoad(){
var searchControl = new google.search.SearchControl();
var siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("'.$application->getCfg('sitename').'");
siteSearch.setUserDefinedClassSuffix("k2");
options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
siteSearch.setSiteRestriction("'.JURI::root().'");
searchControl.addSearcher(siteSearch, options);
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
searchControl.draw(document.getElementById("'.$googleSearchContainerID.'"));
searchControl.execute("'.JRequest::getString('searchword').'");
}
google.setOnLoadCallback(OnLoad);
【问题讨论】:
标签: php forms submit google-custom-search