| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: search.php 19343 2010-11-03 18:12:02Z ian $ 4 * @package Joomla 5 * @subpackage Search 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 jimport( 'joomla.application.component.model' ); 19 20 /** 21 * @package Joomla 22 * @subpackage Search 23 */ 24 class SearchModelSearch extends JModel 25 { 26 27 var $lists = ''; 28 29 /** 30 * Overridden constructor 31 * @access protected 32 */ 33 function __construct() 34 { 35 parent::__construct(); 36 } 37 38 function reset() 39 { 40 $db =& JFactory::getDBO(); 41 $db->setQuery( 'DELETE FROM #__core_log_searches' ); 42 $db->query(); 43 } 44 45 function getItems( ) 46 { 47 global $mainframe, $option; 48 $db =& JFactory::getDBO(); 49 50 $filter_order = $mainframe->getUserStateFromRequest( 'com_search.filter_order', 'filter_order', 'hits', 'cmd' ); 51 $filter_order_Dir = $mainframe->getUserStateFromRequest( 'com_search.filter_order_Dir', 'filter_order_Dir', '', 'word' ); 52 $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' ); 53 $limitstart = $mainframe->getUserStateFromRequest( 'com_search.limitstart', 'limitstart', 0, 'int' ); 54 $search = $mainframe->getUserStateFromRequest( 'com_search.search', 'search', '', 'string' ); 55 if (strpos($search, '"') !== false) { 56 $search = str_replace(array('=', '<'), '', $search); 57 } 58 $search = JString::strtolower($search); 59 $showResults = JRequest::getInt('search_results'); 60 61 // sanitize $filter_order 62 if (!in_array($filter_order, array('search_term', 'hits'))) { 63 $filter_order = 'hits'; 64 } 65 66 if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) { 67 $filter_order_Dir = ''; 68 } 69 70 // table ordering 71 if ( strtoupper($filter_order_Dir) == 'ASC' ) { 72 $this->lists['order_Dir'] = 'ASC'; 73 } else { 74 $this->lists['order_Dir'] = 'DESC'; 75 } 76 $this->lists['order'] = $filter_order; 77 78 // search filter 79 $this->lists['search']= $search; 80 81 $where = array(); 82 if ($search) { 83 $where[] = 'LOWER( search_term ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ); 84 } 85 86 $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' ); 87 88 $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', hits DESC'; 89 90 // get the total number of records 91 $query = 'SELECT COUNT(*)' 92 . ' FROM #__core_log_searches' 93 . $where; 94 $db->setQuery( $query ); 95 $total = $db->loadResult(); 96 97 jimport( 'joomla.html.pagination' ); 98 $pageNav = new JPagination( $total, $limitstart, $limit ); 99 100 $query = ' SELECT * ' 101 . ' FROM #__core_log_searches ' 102 . $where 103 . $orderby; 104 $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); 105 106 $rows = $db->loadObjectList(); 107 108 JPluginHelper::importPlugin( 'search' ); 109 110 if (!class_exists( 'JSite' )) 111 { 112 // This fools the routers in the search plugins into thinking it's in the frontend 113 require_once( JPATH_COMPONENT.DS.'helpers'.DS.'site.php' ); 114 } 115 116 for ($i=0, $n = count($rows); $i < $n; $i++) { 117 // determine if number of results for search item should be calculated 118 // by default it is `off` as it is highly query intensive 119 if ( $showResults ) { 120 $results = $mainframe->triggerEvent( 'onSearch', array( $rows[$i]->search_term ) ); 121 122 $count = 0; 123 for ($j = 0, $n2 = count( $results ); $j < $n2; $j++) { 124 $count += count( $results[$j] ); 125 } 126 127 $rows[$i]->returns = $count; 128 } else { 129 $rows[$i]->returns = null; 130 } 131 } 132 133 return $rows; 134 } 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |