/components/com_finder/controllers/suggestions.json.php

https://bitbucket.org/eternaware/joomus · PHP · 56 lines · 22 code · 6 blank · 28 comment · 2 complexity · 6ec7c8a5f8288461f86a9bd08d753526 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_finder
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Suggestions JSON controller for Finder.
  12. *
  13. * @package Joomla.Site
  14. * @subpackage com_finder
  15. * @since 2.5
  16. */
  17. class FinderControllerSuggestions extends JControllerLegacy
  18. {
  19. /**
  20. * Method to find search query suggestions.
  21. *
  22. * @param boolean $cachable If true, the view output will be cached
  23. * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  24. *
  25. * @return void
  26. *
  27. * @since 2.5
  28. */
  29. public function display($cachable = false, $urlparams = false)
  30. {
  31. $return = array();
  32. $params = JComponentHelper::getParams('com_finder');
  33. if ($params->get('show_autosuggest', 1))
  34. {
  35. // Get the suggestions.
  36. $model = $this->getModel('Suggestions', 'FinderModel');
  37. $return = $model->getItems();
  38. }
  39. // Check the data.
  40. if (empty($return))
  41. {
  42. $return = array();
  43. }
  44. // Use the correct json mime-type
  45. header('Content-Type: application/json');
  46. // Send the response.
  47. echo json_encode($return);
  48. JFactory::getApplication()->close();
  49. }
  50. }