[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_finder 6 * 7 * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Finder\Site\Controller; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\MVC\Controller\BaseController; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('_JEXEC') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Suggestions \JSON controller for Finder. 22 * 23 * @since 2.5 24 */ 25 class SuggestionsController extends BaseController 26 { 27 /** 28 * Method to find search query suggestions. Uses awesomplete 29 * 30 * @return void 31 * 32 * @since 3.4 33 */ 34 public function suggest() 35 { 36 $app = $this->app; 37 $app->mimeType = 'application/json'; 38 39 // Ensure caching is disabled as it depends on the query param in the model 40 $app->allowCache(false); 41 42 $suggestions = $this->getSuggestions(); 43 44 // Send the response. 45 $app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet); 46 $app->sendHeaders(); 47 echo '{ "suggestions": ' . json_encode($suggestions) . ' }'; 48 } 49 50 /** 51 * Method to find search query suggestions for OpenSearch 52 * 53 * @return void 54 * 55 * @since 4.0.0 56 */ 57 public function opensearchsuggest() 58 { 59 $app = $this->app; 60 $app->mimeType = 'application/json'; 61 $result = array(); 62 $result[] = $app->input->request->get('q', '', 'string'); 63 64 $result[] = $this->getSuggestions(); 65 66 // Ensure caching is disabled as it depends on the query param in the model 67 $app->allowCache(false); 68 69 // Send the response. 70 $app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet); 71 $app->sendHeaders(); 72 echo json_encode($result); 73 } 74 75 /** 76 * Method to retrieve the data from the database 77 * 78 * @return array The suggested words 79 * 80 * @since 3.4 81 */ 82 protected function getSuggestions() 83 { 84 $return = array(); 85 86 $params = ComponentHelper::getParams('com_finder'); 87 88 if ($params->get('show_autosuggest', 1)) { 89 // Get the suggestions. 90 $model = $this->getModel('Suggestions'); 91 $return = $model->getItems(); 92 } 93 94 // Check the data. 95 if (empty($return)) { 96 $return = array(); 97 } 98 99 return $return; 100 } 101 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |