CoreFiles by mySites.guru
SuggestionsController.php100 lines, 2,199 bytes, from Joomla_4.0.0-beta1-Beta-Full_Package.zip
Raw History Compare with 3.9.0-beta4
md5
7135f353bd96b1bfe197131ca5c0f94f
sha1
67ade80eb7c5787871ddbd82b5e09b538b0b5021
sha256
b5d9d48abb287fc0657fc601fbcd8f95ee175ddd27539349c9cca2aa5da30b27
<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_finder
 *
 * @copyright   Copyright (C) 2005 - 2020 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;
	}
}

The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.