- md5
- 83966613c78fcd7b8b45206b9bbb3691
- sha1
- 2215717b0c78b4bab02ea720c4966b258a453b2a
- sha256
- dddef834277a13bc92a440024cf9d49c93683b6f02838b28cc790b79d58d0cd8
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
<?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;
\defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Controller\BaseController;
/**
* 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 = array();
$result[] = $app->input->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 = array();
$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 = array();
}
return $return;
}
}
The same content is in 49 releases, Joomla 4.0.0-rc1 to 4.2.0-beta2. See them all, or every version of this file.