| [ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: search.php 7211 2007-04-29 02:26:51Z robs $ 4 * @package Joomla 5 * @subpackage Search 6 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 7 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // no direct access 16 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 17 18 require_once( $mainframe->getPath( 'front_html' ) ); 19 20 // page title 21 $mainframe->setPageTitle( _SEARCH_TITLE ); 22 23 switch ( $task ) { 24 default: 25 viewSearch(); 26 break; 27 } 28 29 function viewSearch() { 30 global $mainframe, $mosConfig_absolute_path, $mosConfig_lang, $my; 31 global $Itemid, $database, $_MAMBOTS; 32 global $mosConfig_list_limit; 33 34 $restriction = 0; 35 36 // try to find search component's Itemid 37 // Only search if we don't have a valid Itemid (e.g. from module) 38 if(!intval($Itemid) || intval($Itemid) == 99999999) { 39 $query = "SELECT id" 40 . "\n FROM #__menu" 41 . "\n WHERE type = 'components'" 42 . "\n AND published = 1" 43 . "\n AND link = 'index.php?option=com_search'" 44 ; 45 $database->setQuery( $query ); 46 $_Itemid = $database->loadResult(); 47 48 if ($_Itemid != "") { 49 $Itemid = $_Itemid; 50 } 51 } 52 53 $gid = $my->gid; 54 55 // Adds parameter handling 56 if( $Itemid > 0 && $Itemid != 99999999 ) { 57 $menu = $mainframe->get( 'menu' ); 58 $params = new mosParameters( $menu->params ); 59 $params->def( 'page_title', 1 ); 60 $params->def( 'pageclass_sfx', '' ); 61 $params->def( 'header', $menu->name, _SEARCH_TITLE ); 62 $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); 63 } else { 64 $params = new mosParameters(''); 65 $params->def( 'page_title', 1 ); 66 $params->def( 'pageclass_sfx', '' ); 67 $params->def( 'header', _SEARCH_TITLE ); 68 $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); 69 } 70 71 // html output 72 search_html::openhtml( $params ); 73 74 $searchword = strval( mosGetParam( $_REQUEST, 'searchword', '' ) ); 75 $searchword = trim( stripslashes( $searchword ) ); 76 77 // limit searchword to 20 characters 78 if ( strlen( $searchword ) > 20 ) { 79 $searchword = substr( $searchword, 0, 19 ); 80 $restriction = 1; 81 } 82 83 // searchword must contain a minimum of 3 characters 84 if ( $searchword && strlen( $searchword ) < 3 ) { 85 $searchword = ''; 86 $restriction = 1; 87 } 88 89 $search_ignore = array(); 90 @include "$mosConfig_absolute_path/language/$mosConfig_lang.ignore.php"; 91 92 $orders = array(); 93 $orders[] = mosHTML::makeOption( 'newest', _SEARCH_NEWEST ); 94 $orders[] = mosHTML::makeOption( 'oldest', _SEARCH_OLDEST ); 95 $orders[] = mosHTML::makeOption( 'popular', _SEARCH_POPULAR ); 96 $orders[] = mosHTML::makeOption( 'alpha', _SEARCH_ALPHABETICAL ); 97 $orders[] = mosHTML::makeOption( 'category', _SEARCH_CATEGORY ); 98 $ordering = mosGetParam( $_REQUEST, 'ordering', 'newest'); 99 $ordering = preg_replace( '/[^a-z]/', '', strtolower( $ordering ) ); 100 $lists = array(); 101 $lists['ordering'] = mosHTML::selectList( $orders, 'ordering', 'id="search_ordering" class="inputbox"', 'value', 'text', $ordering ); 102 103 $searchphrase = mosGetParam( $_REQUEST, 'searchphrase', 'any' ); 104 $searchphrase = preg_replace( '/[^a-z]/', '', strtolower( $searchphrase ) ); 105 $searchphrases = array(); 106 107 $phrase = new stdClass(); 108 $phrase->value = 'any'; 109 $phrase->text = _SEARCH_ANYWORDS; 110 $searchphrases[] = $phrase; 111 112 $phrase = new stdClass(); 113 $phrase->value = 'all'; 114 $phrase->text = _SEARCH_ALLWORDS; 115 $searchphrases[] = $phrase; 116 117 $phrase = new stdClass(); 118 $phrase->value = 'exact'; 119 $phrase->text = _SEARCH_PHRASE; 120 $searchphrases[] = $phrase; 121 122 $lists['searchphrase']= mosHTML::radioList( $searchphrases, 'searchphrase', '', $searchphrase ); 123 124 // html output 125 search_html::searchbox( htmlspecialchars( $searchword ), $lists, $params ); 126 127 if (!$searchword) { 128 if ( count( $_POST ) ) { 129 // html output 130 // no matches found 131 search_html::message( _NOKEYWORD, $params ); 132 } else if ( $restriction ) { 133 // html output 134 search_html::message( _SEARCH_MESSAGE, $params ); 135 } 136 } else if ( in_array( $searchword, $search_ignore ) ) { 137 // html output 138 search_html::message( _IGNOREKEYWORD, $params ); 139 } else { 140 // html output 141 142 if ( $restriction ) { 143 // html output 144 search_html::message( _SEARCH_MESSAGE, $params ); 145 } 146 147 $searchword_clean = htmlspecialchars( $searchword ); 148 149 search_html::searchintro( $searchword_clean, $params ); 150 151 mosLogSearch( $searchword ); 152 153 $_MAMBOTS->loadBotGroup( 'search' ); 154 $results = $_MAMBOTS->trigger( 'onSearch', array( $database->getEscaped( $searchword ), $searchphrase, $ordering ) ); 155 $totalRows = 0; 156 157 $rows = array(); 158 for ($i = 0, $n = count( $results); $i < $n; $i++) { 159 $rows = array_merge( (array)$rows, (array)$results[$i] ); 160 } 161 162 $totalRows = count( $rows ); 163 164 for ($i=0; $i < $totalRows; $i++) { 165 $text = &$rows[$i]->text; 166 167 if ($searchphrase == 'exact') { 168 $searchwords = array($searchword); 169 $needle = $searchword; 170 } else { 171 $searchwords = explode(' ', $searchword); 172 $needle = $searchwords[0]; 173 } 174 175 $text = mosPrepareSearchContent( $text, 200, $needle ); 176 177 foreach ($searchwords as $hlword) { 178 $text = preg_replace( '/' . preg_quote( $hlword, '/' ) . '/i', '<span class="highlight">\0</span>', $text ); 179 } 180 181 if ( strpos( $rows[$i]->href, 'http' ) == false ) { 182 $url = parse_url( $rows[$i]->href ); 183 parse_str( @$url['query'], $link ); 184 185 // determines Itemid for Content items where itemid has not been included 186 if ( isset($rows[$i]->type) && @$link['task'] == 'view' && isset($link['id']) && !isset($link['Itemid']) ) { 187 $itemid = ''; 188 $_itemid = $mainframe->getItemid( $link['id'], 0 ); 189 190 if ($_itemid) { 191 $itemid = '&Itemid='. $_itemid; 192 } 193 194 $rows[$i]->href = $rows[$i]->href . $itemid; 195 } 196 } 197 } 198 199 $mainframe->setPageTitle( _SEARCH_TITLE ); 200 201 $total = $totalRows; 202 $limit = intval( mosGetParam( $_GET, 'limit', $mosConfig_list_limit ) ); 203 $limit = ( $limit ? $limit : $mosConfig_list_limit ); 204 $limitstart = intval( mosGetParam( $_GET, 'limitstart', 0 ) ); 205 206 // prepares searchword for proper display in url 207 $searchword_clean = urlencode( $searchword_clean ); 208 209 if ( $n ) { 210 // html output 211 require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' ); 212 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 213 214 search_html::display( $rows, $params, $pageNav, $limitstart, $limit, $total, $totalRows, $searchword_clean ); 215 } else { 216 // html output 217 search_html::displaynoresult(); 218 } 219 220 // html output 221 search_html::conclusion( $searchword_clean, $pageNav ); 222 } 223 224 // displays back button 225 echo '<br/>'; 226 mosHTML::BackButton ( $params, 0 ); 227 } 228 229 function mosLogSearch( $search_term ) { 230 global $database; 231 global $mosConfig_enable_log_searches; 232 233 if ( @$mosConfig_enable_log_searches ) { 234 $query = "SELECT hits" 235 . "\n FROM #__core_log_searches" 236 . "\n WHERE LOWER( search_term ) = " . $database->Quote( $search_term ) 237 ; 238 $database->setQuery( $query ); 239 $hits = intval( $database->loadResult() ); 240 if ( $hits ) { 241 $query = "UPDATE #__core_log_searches" 242 . "\n SET hits = ( hits + 1 )" 243 . "\n WHERE LOWER( search_term ) = " . $database->Quote( $search_term ) 244 ; 245 $database->setQuery( $query ); 246 $database->query(); 247 } else { 248 $query = "INSERT INTO #__core_log_searches VALUES ( " . $database->Quote( $search_term ) . ", 1 )" 249 ; 250 $database->setQuery( $query ); 251 $database->query(); 252 } 253 } 254 } 255 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
|