| [ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: weblinks.searchbot.php 5057 2006-09-14 16:38:01Z friesengeist $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 6 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 16 17 $_MAMBOTS->registerFunction( 'onSearch', 'botSearchWeblinks' ); 18 19 /** 20 * Weblink Search method 21 * 22 * The sql must return the following fields that are used in a common display 23 * routine: href, title, section, created, text, browsernav 24 * @param string Target search string 25 * @param string mathcing option, exact|any|all 26 * @param string ordering option, newest|oldest|popular|alpha|category 27 */ 28 function botSearchWeblinks( $text, $phrase='', $ordering='' ) { 29 global $database, $my, $_MAMBOTS; 30 31 // check if param query has previously been processed 32 if ( !isset($_MAMBOTS->_search_mambot_params['weblinks']) ) { 33 // load mambot params info 34 $query = "SELECT params" 35 . "\n FROM #__mambots" 36 . "\n WHERE element = 'weblinks.searchbot'" 37 . "\n AND folder = 'search'" 38 ; 39 $database->setQuery( $query ); 40 $database->loadObject($mambot); 41 42 // save query to class variable 43 $_MAMBOTS->_search_mambot_params['weblinks'] = $mambot; 44 } 45 46 // pull query data from class variable 47 $mambot = $_MAMBOTS->_search_mambot_params['weblinks']; 48 49 $botParams = new mosParameters( $mambot->params ); 50 51 $limit = $botParams->def( 'search_limit', 50 ); 52 53 $text = trim( $text ); 54 if ($text == '') { 55 return array(); 56 } 57 $section = _WEBLINKS_TITLE; 58 59 $wheres = array(); 60 switch ($phrase) { 61 case 'exact': 62 $wheres2 = array(); 63 64 $wheres2[] = "LOWER(a.url) LIKE '%$text%'"; 65 $wheres2[] = "LOWER(a.description) LIKE '%$text%'"; 66 $wheres2[] = "LOWER(a.title) LIKE '%$text%'"; 67 $where = '(' . implode( ') OR (', $wheres2 ) . ')'; 68 break; 69 70 case 'all': 71 case 'any': 72 default: 73 $words = explode( ' ', $text ); 74 $wheres = array(); 75 foreach ($words as $word) { 76 $wheres2 = array(); 77 $wheres2[] = "LOWER(a.url) LIKE '%$word%'"; 78 $wheres2[] = "LOWER(a.description) LIKE '%$word%'"; 79 $wheres2[] = "LOWER(a.title) LIKE '%$word%'"; 80 $wheres[] = implode( ' OR ', $wheres2 ); 81 } 82 $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')'; 83 break; 84 } 85 86 switch ( $ordering ) { 87 case 'oldest': 88 $order = 'a.date ASC'; 89 break; 90 91 case 'popular': 92 $order = 'a.hits DESC'; 93 break; 94 95 case 'alpha': 96 $order = 'a.title ASC'; 97 break; 98 99 case 'category': 100 $order = 'b.title ASC, a.title ASC'; 101 break; 102 103 case 'newest': 104 default: 105 $order = 'a.date DESC'; 106 } 107 108 $query = "SELECT a.title AS title," 109 . "\n a.description AS text," 110 . "\n a.date AS created," 111 . "\n CONCAT_WS( ' / ', " . $database->Quote( $section ) . ", b.title ) AS section," 112 . "\n '1' AS browsernav," 113 . "\n a.url AS href" 114 . "\n FROM #__weblinks AS a" 115 . "\n INNER JOIN #__categories AS b ON b.id = a.catid" 116 . "\n WHERE ($where)" 117 . "\n AND a.published = 1" 118 . "\n AND b.published = 1" 119 . "\n AND b.access <= " . (int) $my->gid 120 . "\n ORDER BY $order" 121 ; 122 $database->setQuery( $query, 0, $limit ); 123 $rows = $database->loadObjectList(); 124 125 return $rows; 126 } 127 ?>
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 |
|