Source for file search.php

Documentation is available at search.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_search
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC') or die;
  11.  
  12. /**
  13.  * Search Component Search Model
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_search
  17.  * @since       1.5
  18.  */
  19. {
  20.     /**
  21.      * Search data array
  22.      *
  23.      * @var array 
  24.      */
  25.     protected $_data = null;
  26.  
  27.     /**
  28.      * Search total
  29.      *
  30.      * @var integer 
  31.      */
  32.     protected $_total = null;
  33.  
  34.     /**
  35.      * Search areas
  36.      *
  37.      * @var integer 
  38.      */
  39.     protected  $_areas = null;
  40.  
  41.     /**
  42.      * Pagination object
  43.      *
  44.      * @var object 
  45.      */
  46.     protected $_pagination = null;
  47.  
  48.     /**
  49.      * Constructor
  50.      *
  51.      * @since 1.5
  52.      */
  53.     public function __construct()
  54.     {
  55.         parent::__construct();
  56.  
  57.         //Get configuration
  58.         $app    = JFactory::getApplication();
  59.         $config = JFactory::getConfig();
  60.  
  61.         // Get the pagination request variables
  62.         $this->setState('limit', $app->getUserStateFromRequest('com_search.limit', 'limit', $config->get('list_limit'), 'uint'));
  63.         $this->setState('limitstart', $app->input->get('limitstart', 0, 'uint'));
  64.  
  65.         // Set the search parameters
  66.         $keyword  = urldecode($app->input->getString('searchword'));
  67.         $match    = $app->input->get('searchphrase', 'all', 'word');
  68.         $ordering = $app->input->get('ordering', 'newest', 'word');
  69.         $this->setSearch($keyword, $match, $ordering);
  70.  
  71.         //Set the search areas
  72.         $areas = $app->input->get('areas', null, 'array');
  73.         $this->setAreas($areas);
  74.     }
  75.  
  76.     /**
  77.      * Method to set the search parameters
  78.      *
  79.      * @access    public
  80.      * @param string search string
  81.      * @param string mathcing option, exact|any|all
  82.      * @param string ordering option, newest|oldest|popular|alpha|category
  83.      */
  84.     public function setSearch($keyword, $match = 'all', $ordering = 'newest')
  85.     {
  86.         if (isset($keyword))
  87.         {
  88.             $this->setState('origkeyword', $keyword);
  89.             if ($match !== 'exact')
  90.             {
  91.                 $keyword = preg_replace('#\xE3\x80\x80#s', ' ', $keyword);
  92.             }
  93.             $this->setState('keyword', $keyword);
  94.         }
  95.  
  96.         if (isset($match))
  97.         {
  98.             $this->setState('match', $match);
  99.         }
  100.  
  101.         if (isset($ordering))
  102.         {
  103.             $this->setState('ordering', $ordering);
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * Method to set the search areas
  109.      *
  110.      * @access    public
  111.      * @param   array  Active areas
  112.      * @param   array  Search areas
  113.      */
  114.     public function setAreas($active = array(), $search = array())
  115.     {
  116.         $this->_areas['active'] = $active;
  117.         $this->_areas['search'] = $search;
  118.     }
  119.  
  120.     /**
  121.      * Method to get weblink item data for the category
  122.      *
  123.      * @access public
  124.      * @return array 
  125.      */
  126.     public function getData()
  127.     {
  128.         // Lets load the content if it doesn't already exist
  129.         if (empty($this->_data))
  130.         {
  131.             $areas = $this->getAreas();
  132.  
  133.             JPluginHelper::importPlugin('search');
  134.             $dispatcher = JEventDispatcher::getInstance();
  135.             $results = $dispatcher->trigger('onContentSearch', array(
  136.                 $this->getState('keyword'),
  137.                 $this->getState('match'),
  138.                 $this->getState('ordering'),
  139.                 $areas['active'])
  140.             );
  141.  
  142.             $rows = array();
  143.             foreach ($results as $result)
  144.             {
  145.                 $rows = array_merge((array) $rows, (array) $result);
  146.             }
  147.  
  148.             $this->_total    = count($rows);
  149.             if ($this->getState('limit') > 0)
  150.             {
  151.                 $this->_data    = array_splice($rows, $this->getState('limitstart'), $this->getState('limit'));
  152.             } else {
  153.                 $this->_data = $rows;
  154.             }
  155.         }
  156.  
  157.         return $this->_data;
  158.     }
  159.  
  160.     /**
  161.      * Method to get the total number of weblink items for the category
  162.      *
  163.      * @access public
  164.      * @return  integer 
  165.      */
  166.     public function getTotal()
  167.     {
  168.         return $this->_total;
  169.     }
  170.  
  171.     /**
  172.      * Method to get a pagination object of the weblink items for the category
  173.      *
  174.      * @access public
  175.      * @return  integer 
  176.      */
  177.     public function getPagination()
  178.     {
  179.         // Lets load the content if it doesn't already exist
  180.         if (empty($this->_pagination))
  181.         {
  182.             $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit'));
  183.         }
  184.  
  185.         return $this->_pagination;
  186.     }
  187.  
  188.     /**
  189.      * Method to get the search areas
  190.      *
  191.      * @since 1.5
  192.      */
  193.     public function getAreas()
  194.     {
  195.         // Load the Category data
  196.         if (empty($this->_areas['search']))
  197.         {
  198.             $areas = array();
  199.  
  200.             JPluginHelper::importPlugin('search');
  201.             $dispatcher = JEventDispatcher::getInstance();
  202.             $searchareas = $dispatcher->trigger('onContentSearchAreas');
  203.  
  204.             foreach ($searchareas as $area)
  205.             {
  206.                 if (is_array($area))
  207.                 {
  208.                     $areas = array_merge($areas, $area);
  209.                 }
  210.             }
  211.  
  212.             $this->_areas['search'] = $areas;
  213.         }
  214.  
  215.         return $this->_areas;
  216.     }
  217. }

Documentation generated on Tue, 19 Nov 2013 15:12:39 +0100 by phpDocumentor 1.4.3