CoreFiles by mySites.guru
SuggestionsController.php101 lines, 2,563 bytes, from Joomla_5.4.1-Stable-Full_Package.zip
Raw History Compare with 5.4.0
md5
3b9147ed158d80628ebd7d6ec9d570f4
sha1
fea5e63b2802e015811216f4070d6427b74335cc
sha256
be4be0e0d7006831ba4c4e3286e8c795e6e1e69abbbac993a0a8f2c2a26fc057
<?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;
    }
}

The same content is in 208 releases, Joomla 4.3.0-beta1 to 6.2.1-rc1. See them all, or every version of this file.