first commit
This commit is contained in:
54
modules/mod_finder/mod_finder.php
Normal file
54
modules/mod_finder/mod_finder.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_finder
|
||||
*
|
||||
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Component\Finder\Administrator\Helper\LanguageHelper;
|
||||
use Joomla\Component\Finder\Site\Helper\RouteHelper;
|
||||
use Joomla\Module\Finder\Site\Helper\FinderHelper;
|
||||
|
||||
$cparams = ComponentHelper::getParams('com_finder');
|
||||
|
||||
// Check for OpenSearch
|
||||
if ($params->get('opensearch', $cparams->get('opensearch', 1))) {
|
||||
$defaultTitle = Text::_('MOD_FINDER_OPENSEARCH_NAME') . ' ' . $app->get('sitename');
|
||||
$ostitle = $params->get('opensearch_name', $cparams->get('opensearch_name', $defaultTitle));
|
||||
$app->getDocument()->addHeadLink(
|
||||
Uri::getInstance()->toString(['scheme', 'host', 'port']) . Route::_('index.php?option=com_finder&view=search&format=opensearch'),
|
||||
'search',
|
||||
'rel',
|
||||
['title' => $ostitle, 'type' => 'application/opensearchdescription+xml']
|
||||
);
|
||||
}
|
||||
|
||||
// Get the route.
|
||||
$route = RouteHelper::getSearchRoute($params->get('searchfilter', null));
|
||||
|
||||
if ($params->get('set_itemid')) {
|
||||
$uri = Uri::getInstance($route);
|
||||
$uri->setVar('Itemid', $params->get('set_itemid'));
|
||||
$route = $uri->toString(['path', 'query']);
|
||||
}
|
||||
|
||||
// Load component language file.
|
||||
LanguageHelper::loadComponentLanguage();
|
||||
|
||||
// Load plugin language files.
|
||||
LanguageHelper::loadPluginLanguage();
|
||||
|
||||
// Get Smart Search query object.
|
||||
$query = FinderHelper::getQuery($params);
|
||||
|
||||
require ModuleHelper::getLayoutPath('mod_finder', $params->get('layout', 'default'));
|
||||
135
modules/mod_finder/mod_finder.xml
Normal file
135
modules/mod_finder/mod_finder.xml
Normal file
@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="module" client="site" method="upgrade">
|
||||
<name>mod_finder</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2011-08</creationDate>
|
||||
<copyright>(C) 2011 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>MOD_FINDER_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Module\Finder</namespace>
|
||||
<files>
|
||||
<filename module="mod_finder">mod_finder.php</filename>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/mod_finder.ini</language>
|
||||
<language tag="en-GB">language/en-GB/mod_finder.sys.ini</language>
|
||||
</languages>
|
||||
<help key="Site_Modules:_Smart_Search" />
|
||||
<config>
|
||||
<fields name="params" addfieldprefix="Joomla\Component\Finder\Administrator\Field">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="searchfilter"
|
||||
type="searchfilter"
|
||||
label="MOD_FINDER_FIELDSET_BASIC_SEARCHFILTER_LABEL"
|
||||
default=""
|
||||
/>
|
||||
|
||||
<field
|
||||
name="show_autosuggest"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_FINDER_FIELDSET_BASIC_AUTOSUGGEST_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="show_advanced"
|
||||
type="list"
|
||||
label="MOD_FINDER_FIELDSET_BASIC_SHOW_ADVANCED_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
validate="options"
|
||||
>
|
||||
<option value="2">MOD_FINDER_FIELDSET_BASIC_SHOW_ADVANCED_OPTION_LINK</option>
|
||||
<option value="1">JSHOW</option>
|
||||
<option value="0">JHIDE</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="show_label"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_FINDER_FIELDSET_ADVANCED_SHOW_LABEL_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="alt_label"
|
||||
type="text"
|
||||
label="MOD_FINDER_FIELDSET_ADVANCED_ALT_LABEL"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="show_button"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_FINDER_FIELDSET_ADVANCED_SHOW_BUTTON_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="opensearch"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_FINDER_FIELD_OPENSEARCH_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="opensearch_name"
|
||||
type="text"
|
||||
label="MOD_FINDER_FIELD_OPENSEARCH_TEXT_LABEL"
|
||||
showon="opensearch:1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="set_itemid"
|
||||
type="menuitem"
|
||||
label="MOD_FINDER_FIELDSET_ADVANCED_SETITEMID_LABEL"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">MOD_FINDER_SELECT_MENU_ITEMID</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fieldset name="advanced">
|
||||
<field
|
||||
name="layout"
|
||||
type="modulelayout"
|
||||
label="JFIELD_ALT_LAYOUT_LABEL"
|
||||
class="form-select"
|
||||
validate="moduleLayout"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="moduleclass_sfx"
|
||||
type="textarea"
|
||||
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
|
||||
rows="3"
|
||||
validate="CssIdentifier"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
84
modules/mod_finder/src/Helper/FinderHelper.php
Normal file
84
modules/mod_finder/src/Helper/FinderHelper.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_finder
|
||||
*
|
||||
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Module\Finder\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Component\Finder\Administrator\Indexer\Query;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Finder module helper.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
class FinderHelper
|
||||
{
|
||||
/**
|
||||
* Method to get hidden input fields for a get form so that control variables
|
||||
* are not lost upon form submission.
|
||||
*
|
||||
* @param string $route The route to the page. [optional]
|
||||
* @param integer $paramItem The menu item ID. (@since 3.1) [optional]
|
||||
*
|
||||
* @return string A string of hidden input form fields
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public static function getGetFields($route = null, $paramItem = 0)
|
||||
{
|
||||
$fields = [];
|
||||
$uri = Uri::getInstance(Route::_($route));
|
||||
$uri->delVar('q');
|
||||
|
||||
// Create hidden input elements for each part of the URI.
|
||||
foreach ($uri->getQuery(true) as $n => $v) {
|
||||
$fields[] = '<input type="hidden" name="' . $n . '" value="' . $v . '">';
|
||||
}
|
||||
|
||||
return implode('', $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Smart Search query object.
|
||||
*
|
||||
* @param \Joomla\Registry\Registry $params Module parameters.
|
||||
*
|
||||
* @return Query object
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public static function getQuery($params)
|
||||
{
|
||||
$request = Factory::getApplication()->getInput()->request;
|
||||
$filter = InputFilter::getInstance();
|
||||
|
||||
// Get the static taxonomy filters.
|
||||
$options = [];
|
||||
$options['filter'] = ($request->get('f', 0, 'int') !== 0) ? $request->get('f', '', 'int') : $params->get('searchfilter');
|
||||
$options['filter'] = $filter->clean($options['filter'], 'int');
|
||||
|
||||
// Get the dynamic taxonomy filters.
|
||||
$options['filters'] = $request->get('t', '', 'array');
|
||||
$options['filters'] = $filter->clean($options['filters'], 'array');
|
||||
$options['filters'] = ArrayHelper::toInteger($options['filters']);
|
||||
|
||||
// Instantiate a query object.
|
||||
return new Query($options, Factory::getContainer()->get(DatabaseInterface::class));
|
||||
}
|
||||
}
|
||||
76
modules/mod_finder/tmpl/default.php
Normal file
76
modules/mod_finder/tmpl/default.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_finder
|
||||
*
|
||||
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Module\Finder\Site\Helper\FinderHelper;
|
||||
|
||||
// Load the smart search component language file.
|
||||
$lang = $app->getLanguage();
|
||||
$lang->load('com_finder', JPATH_SITE);
|
||||
|
||||
$input = '<input type="text" name="q" id="mod-finder-searchword' . $module->id . '" class="js-finder-search-query form-control" value="' . htmlspecialchars($app->getInput()->get('q', '', 'string'), ENT_COMPAT, 'UTF-8') . '"'
|
||||
. ' placeholder="' . Text::_('MOD_FINDER_SEARCH_VALUE') . '">';
|
||||
|
||||
$showLabel = $params->get('show_label', 1);
|
||||
$labelClass = (!$showLabel ? 'visually-hidden ' : '') . 'finder';
|
||||
$label = '<label for="mod-finder-searchword' . $module->id . '" class="' . $labelClass . '">' . $params->get('alt_label', Text::_('JSEARCH_FILTER_SUBMIT')) . '</label>';
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($params->get('show_button', 0)) {
|
||||
$output .= $label;
|
||||
$output .= '<div class="mod-finder__search input-group">';
|
||||
$output .= $input;
|
||||
$output .= '<button class="btn btn-primary" type="submit"><span class="icon-search icon-white" aria-hidden="true"></span> ' . Text::_('JSEARCH_FILTER_SUBMIT') . '</button>';
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= $label;
|
||||
$output .= $input;
|
||||
}
|
||||
|
||||
Text::script('MOD_FINDER_SEARCH_VALUE');
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $app->getDocument()->getWebAssetManager();
|
||||
$wa->getRegistry()->addExtensionRegistryFile('com_finder');
|
||||
|
||||
/*
|
||||
* This segment of code sets up the autocompleter.
|
||||
*/
|
||||
if ($params->get('show_autosuggest', 1)) {
|
||||
$wa->usePreset('awesomplete');
|
||||
$app->getDocument()->addScriptOptions('finder-search', ['url' => Route::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component', false)]);
|
||||
|
||||
Text::script('JLIB_JS_AJAX_ERROR_OTHER');
|
||||
Text::script('JLIB_JS_AJAX_ERROR_PARSE');
|
||||
}
|
||||
|
||||
$wa->useScript('com_finder.finder');
|
||||
|
||||
?>
|
||||
|
||||
<form class="mod-finder js-finder-searchform form-search" action="<?php echo Route::_($route); ?>" method="get" role="search">
|
||||
<?php echo $output; ?>
|
||||
|
||||
<?php $show_advanced = $params->get('show_advanced', 0); ?>
|
||||
<?php if ($show_advanced == 2) : ?>
|
||||
<br>
|
||||
<a href="<?php echo Route::_($route); ?>" class="mod-finder__advanced-link"><?php echo Text::_('COM_FINDER_ADVANCED_SEARCH'); ?></a>
|
||||
<?php elseif ($show_advanced == 1) : ?>
|
||||
<div class="mod-finder__advanced js-finder-advanced">
|
||||
<?php echo HTMLHelper::_('filter.select', $query, $params); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php echo FinderHelper::getGetFields($route, (int) $params->get('set_itemid', 0)); ?>
|
||||
</form>
|
||||
Reference in New Issue
Block a user