suggestions.json.php
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?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
*/
defined('_JEXEC') or die;
/**
* Suggestions JSON controller for Finder.
*
* @since 2.5
*/
class FinderControllerSuggestions extends JControllerLegacy
{
/**
* Method to find search query suggestions. Uses jQuery and autocompleter.js
*
* @return void
*
* @since 3.4
*/
public function suggest()
{
/** @var \Joomla\CMS\Application\CMSApplication $app */
$app = JFactory::getApplication();
$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) . ' }';
$app->close();
}
/**
* Method to find search query suggestions. Uses Mootools and autocompleter.js
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return void
*
* @since 2.5
* @deprecated 3.4
*/
public function display($cachable = false, $urlparams = false)
{
/** @var \Joomla\CMS\Application\CMSApplication $app */
$app = JFactory::getApplication();
$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 json_encode($suggestions);
$app->close();
}
/**
* Method to retrieve the data from the database
*
* @return array The suggested words
*
* @since 3.4
*/
protected function getSuggestions()
{
$return = array();
$params = JComponentHelper::getParams('com_finder');
if ($params->get('show_autosuggest', 1))
{
// Get the suggestions.
$model = $this->getModel('Suggestions', 'FinderModel');
$return = $model->getItems();
}
// Check the data.
if (empty($return))
{
$return = array();
}
return $return;
}
}