Здравствуйте!
Есть модуль
https://www.sakic.net/products/ajax-search/, который представлен формой ajax-поиска, основанного на структуре com_search. Подскажите, как изменить файлы модуля (прикрепляю в спойлеры), чтобы поиск вёлся через com_finder (Умный поиск).
mod_ajaxsearch.php<?php
defined('_JEXEC') or die;
require_once __DIR__ . '/helper.php';
$lang = JFactory::getLanguage();
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$doc = JFactory::getDocument();
if ($params->get('opensearch', 1))
{
$ostitle = $params->get('opensearch_title', JText::_('MOD_AJAXSEARCH_SEARCHBUTTON_TEXT'). ' ' . $app->getCfg('sitename'));
$doc->addHeadLink(
JUri::getInstance()->toString(array('scheme', 'host', 'port'))
. JRoute::_('&option=com_search&format=opensearch'), 'search', 'rel',
array(
'title' => htmlspecialchars($ostitle),
'type' => 'application/opensearchdescription+xml'
)
);
}
$upper_limit = $lang->getUpperLimitSearchWord();
$lower_limit = $lang->getLowerLimitSearchWord();
$button = $params->get('button', 0);
$button_text = htmlspecialchars($params->get('button_text', JText::_('MOD_AJAXSEARCH_SEARCHBUTTON_TEXT')));
$width = (int) $params->get('width');
$maxlength = $upper_limit;
$text = htmlspecialchars($params->get('text', JText::_('MOD_AJAXSEARCH_SEARCHBOX_TEXT')));
$label = htmlspecialchars($params->get('label', JText::_('MOD_AJAXSEARCH_LABEL_TEXT')));
$max_results = (int) $params->get('max_results', 5);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
$pagination_limit = $config->get('list_limit');
$mitemid = 0;
if ($params->get('find_itemid')) {
$mitemid = ModAjaxSearchHelper::getItemid();
}
$include_css = (int) $params->get('include_css', 1);
require JModuleHelper::getLayoutPath('mod_ajaxsearch', $params->get('layout', 'default'));
helper.php<?php
defined('_JEXEC') or die;
/**
* Helper for mod_ajaxsearch
*/
class ModAjaxSearchHelper
{
/**
* Find Itemid considering language priority
*/
public static function getItemid()
{
$lang = JFactory::getLanguage();
$lang_tag = $lang->getTag();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id')->from('#__menu')->where('link LIKE '.$db->q('index.php?option=com_search&view=search%').' AND (language='.$db->q($lang_tag).' OR language='.$db->q('*').') AND published=1 ORDER BY language DESC');
$db->setQuery($query);
//die($query);
$Itemid = $db->loadResult();
return $Itemid;
}
}
tmpl/default.php<?php
defined('_JEXEC') or die;
// Include module's assets
if ($include_css) {
JHtml::_('stylesheet', 'modules/mod_ajaxsearch/assets/css/style.css');
}
JHtml::_('script', 'modules/mod_ajaxsearch/assets/js/script.js');
if ($width)
{
$moduleclass_sfx .= ' ' . 'mod_ajaxsearch' . $module->id;
$css = 'div.mod_ajaxsearch' . $module->id . ' input[type="search"]{ width:auto; }';
$doc->addStyleDeclaration($css);
$width = ' size="' . $width . '"';
} else {
$width = '';
}
$input = $app->input;
if ($input->get('searchword', '', 'string')!='') {
$text = $input->get('searchword', '', 'string');
$text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
// js settings
$js = '
var asoptions = {
lower_limit: '.$lower_limit.',
max_results: '.$max_results.'
};
var asstrings = {
show_all: "'.JText::_('MOD_AJAXSEARCH_SHOW_ALL').'"
};
';
$doc->addScriptDeclaration($js);
$action_url = 'index.php?option=com_search&view=search';
if ($mitemid) {
$action_url .= '&Itemid='.$mitemid;
}
?>
<div class="ajax-search<?php echo $moduleclass_sfx ?>">
<form id="mod-ajaxsearch-form" action="<?php echo JRoute::_($action_url);?>" method="post" class="form-inline">
<div class="btn-toolbar">
<div class="btn-group pull-left">
<input type="search" name="searchword" id="mod-ajaxsearch-searchword" placeholder="<?php echo $label; ?>"<?php echo $width; ?> maxlength="<?php echo $maxlength; ?>" class="inputbox" value="<?php echo $text; ?>" autocomplete="off" onblur="if (this.value=='') this.value='<?php echo $text; ?>';" onfocus="if (this.value=='<?php echo $text; ?>') this.value='';" />
</div>
<?php if ($button) : ?>
<div class="btn-group pull-left hidden-phone">
<button name="Search" onclick="this.form.submit()" class="btn hasTooltip" title="<?php echo JHtml::tooltipText($button_text);?>"><span class="icon-search"></span></button>
</div>
<?php endif; ?>
<div class="clearfix"></div>
</div>
<div id="mod-ajaxsearch-results-box" class="results-box"></div>
<input type="hidden" name="task" value="search" />
<input type="hidden" name="limit" value="<?php echo $pagination_limit; ?>" />
</form>
</div>
assets/js/script.jsjQuery(document).ready(function($) {
$('#mod-ajaxsearch-form').on('submit', function(e) {
e.preventDefault()
});
var asxhr;
$('#mod-ajaxsearch-searchword').on('keyup', function(e) {
var el = $(this);
var search_string = el.val();
if (search_string !== '' && search_string.length >= asoptions.lower_limit) {
if (asxhr && asxhr.readyState != 4) {
asxhr.abort()
}
asxhr = $.ajax({
beforeSend: function() {
el.addClass('loading')
},
url: $('#mod-ajaxsearch-form').attr('action'),
data: {
type: 'raw',
option: 'com_search',
searchword: search_string,
limit: asoptions.max_results,
tmpl: 'component'
},
cache: false,
complete: function() {
el.removeClass('loading')
},
success: function(response) {
var container = $('#mod-ajaxsearch-results-box');
if ($(response).find('.search-results').html()) {
container.html($(response).find('.search-results'));
container.append('<div class="mod-ajaxsearch-results-footer"><a href="javascript: void(0);" onclick="document.getElementById(\'mod-ajaxsearch-form\').submit();">' + asstrings.show_all + '</a></div>')
} else {
container.html('')
}
},
dataType: 'html'
})
} else {
$('#mod-ajaxsearch-results-box').html('')
}
return false
});
$(document).on('click', function(e) {
var container = $('#mod-ajaxsearch-results-box');
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.html('')
}
})
});