mirror of
https://github.com/joomla/joomla-cms.git
synced 2024-05-28 07:53:37 +00:00
032ea5d32d
-----BEGIN PGP SIGNATURE----- iQHIBAABCgAyFiEEc8tLlhrb4aveTfJiRzuTXEnqGwgFAl34mZsUHGxlaXRobmVy QGl0cm9uaWMuYXQACgkQRzuTXEnqGwhOYAv+PgzapMJWw6Hic32RIfVrgQtbl4ac gybmYhBLFeSd4qrc1Ya8+Fsx79U1RR1elkrZGB1Rm5/vGvHqgFI9JzmpbK8wGTWF yU46g9rDM++2M08qQQxg8a2vx9VoN5yvccPi7oKEpU4gzRcEsPr9ih406dtPlSBZ w38jmD8J/DF0TcOuWS0dZjEF8NtbxGFGS6x9Wc4ZyYoPvfsqpjYXKnc70ExifSgc 373B+vCkyhvHaW+aA4nZ50WuZHd3Rasf4VNB8JVz8hXMnnJf2zwthWaJtWiwjLeS u6x59xbsibQqZImlqdooSbIKROY3ZjVgNPCrYk4Iolm6MD8khIm4rvOmGP1Nrrr8 fZrBuN42ynv5tLutuSwSJSPXvX+RGjgPSeLSGM8FXujtCoxNJrbP3qo7EdkIofAD BPwwRDUiorRFwT4JfMqyBHSrM4BUqOlFN+9wi7oVM/405LfmTx3K0zfh2YCPvRXt IybdpfYAld7RQb6KWONf42Q/+mEVE5/wJhRe =KyXf -----END PGP SIGNATURE----- Merge tag '3.9.14' into 4.0-dev Joomla! 3.9.14
101 lines
2.1 KiB
PHP
101 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* @package Joomla.Site
|
|
* @subpackage com_finder
|
|
*
|
|
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
|
|
* @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 jQuery and autocompleter.js
|
|
*
|
|
* @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;
|
|
}
|
|
}
|