- md5
- a01caeef2773a60b96e29d57a6ff5c2d
- sha1
- 5669787336637d4340d7e19a866e6b28aadae618
- sha256
- d5c6f925521368fc5e7d261e00bd531838afe0f9d9907bc79a715f3a1b2e59c9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
<?php
/**
* @version $Id: search.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Search
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
/**
* @package Joomla
* @subpackage Search
*/
class SearchModelSearch extends JModel
{
var $lists = '';
/**
* Overridden constructor
* @access protected
*/
function __construct()
{
parent::__construct();
}
function reset()
{
$db =& JFactory::getDBO();
$db->setQuery( 'DELETE FROM #__core_log_searches' );
$db->query();
}
function getItems( )
{
global $mainframe, $option;
$db =& JFactory::getDBO();
$filter_order = $mainframe->getUserStateFromRequest( 'com_search.filter_order', 'filter_order', 'hits', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( 'com_search.filter_order_Dir', 'filter_order_Dir', '', 'word' );
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( 'com_search.limitstart', 'limitstart', 0, 'int' );
$search = $mainframe->getUserStateFromRequest( 'com_search.search', 'search', '', 'string' );
$search = JString::strtolower( $search );
$showResults = JRequest::getInt('search_results');
// table ordering
if ( $filter_order_Dir == 'ASC' ) {
$this->lists['order_Dir'] = 'ASC';
} else {
$this->lists['order_Dir'] = 'DESC';
}
$this->lists['order'] = $filter_order;
// search filter
$this->lists['search']= $search;
$where = array();
if ($search) {
$where[] = 'LOWER( search_term ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}
$where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', hits DESC';
// get the total number of records
$query = 'SELECT COUNT(*)'
. ' FROM #__core_log_searches'
. $where;
$db->setQuery( $query );
$total = $db->loadResult();
jimport( 'joomla.html.pagination' );
$pageNav = new JPagination( $total, $limitstart, $limit );
$query = ' SELECT * '
. ' FROM #__core_log_searches '
. $where
. $orderby;
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$rows = $db->loadObjectList();
JPluginHelper::importPlugin( 'search' );
if (!class_exists( 'JSite' ))
{
// This fools the routers in the search plugins into thinking it's in the frontend
require_once( JPATH_COMPONENT.DS.'helpers'.DS.'site.php' );
}
for ($i=0, $n = count($rows); $i < $n; $i++) {
// determine if number of results for search item should be calculated
// by default it is `off` as it is highly query intensive
if ( $showResults ) {
$results = $mainframe->triggerEvent( 'onSearch', array( $rows[$i]->search_term ) );
$count = 0;
for ($j = 0, $n2 = count( $results ); $j < $n2; $j++) {
$count += count( $results[$j] );
}
$rows[$i]->returns = $count;
} else {
$rows[$i]->returns = null;
}
}
return $rows;
}
}
The same content is in 12 releases, Joomla 1.5.4 to 1.5.15. See them all, or every version of this file.