primo commit
This commit is contained in:
62
components/com_finder/src/Controller/DisplayController.php
Normal file
62
components/com_finder/src/Controller/DisplayController.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_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\Component\Finder\Site\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\Component\Finder\Administrator\Helper\LanguageHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Finder Component Controller.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached. [optional]
|
||||
* @param array $urlparams An array of safe URL parameters and their variable types. Optional.
|
||||
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
|
||||
*
|
||||
* @return static This object is to support chaining.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = [])
|
||||
{
|
||||
$input = $this->app->getInput();
|
||||
$cachable = true;
|
||||
|
||||
// Load plugin language files.
|
||||
LanguageHelper::loadPluginLanguage();
|
||||
|
||||
// Set the default view name and format from the Request.
|
||||
$viewName = $input->get('view', 'search', 'word');
|
||||
$input->set('view', $viewName);
|
||||
|
||||
// Don't cache view for search queries
|
||||
if ($input->get('q', null, 'string') || $input->get('f', null, 'int') || $input->get('t', null, 'array')) {
|
||||
$cachable = false;
|
||||
}
|
||||
|
||||
$safeurlparams = [
|
||||
'f' => 'INT',
|
||||
'lang' => 'CMD',
|
||||
];
|
||||
|
||||
return parent::display($cachable, $safeurlparams);
|
||||
}
|
||||
}
|
||||
101
components/com_finder/src/Controller/SuggestionsController.php
Normal file
101
components/com_finder/src/Controller/SuggestionsController.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_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\Component\Finder\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Suggestions \JSON controller for Finder.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
class SuggestionsController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method to find search query suggestions. Uses awesomplete
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.4
|
||||
*/
|
||||
public function suggest()
|
||||
{
|
||||
$app = $this->app;
|
||||
$app->mimeType = 'application/json';
|
||||
|
||||
// Ensure caching is disabled as it depends on the query param in the model
|
||||
$app->allowCache(false);
|
||||
|
||||
$suggestions = $this->getSuggestions();
|
||||
|
||||
// Send the response.
|
||||
$app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet);
|
||||
$app->sendHeaders();
|
||||
echo '{ "suggestions": ' . json_encode($suggestions) . ' }';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to find search query suggestions for OpenSearch
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function opensearchsuggest()
|
||||
{
|
||||
$app = $this->app;
|
||||
$app->mimeType = 'application/json';
|
||||
$result = [];
|
||||
$result[] = $app->getInput()->request->get('q', '', 'string');
|
||||
|
||||
$result[] = $this->getSuggestions();
|
||||
|
||||
// Ensure caching is disabled as it depends on the query param in the model
|
||||
$app->allowCache(false);
|
||||
|
||||
// Send the response.
|
||||
$app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet);
|
||||
$app->sendHeaders();
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve the data from the database
|
||||
*
|
||||
* @return array The suggested words
|
||||
*
|
||||
* @since 3.4
|
||||
*/
|
||||
protected function getSuggestions()
|
||||
{
|
||||
$return = [];
|
||||
|
||||
$params = ComponentHelper::getParams('com_finder');
|
||||
|
||||
if ($params->get('show_autosuggest', 1)) {
|
||||
// Get the suggestions.
|
||||
$model = $this->getModel('Suggestions');
|
||||
$return = $model->getItems();
|
||||
}
|
||||
|
||||
// Check the data.
|
||||
if (empty($return)) {
|
||||
$return = [];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user