[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/mambots/search/ -> newsfeeds.searchbot.php (source)

   1  <?php
   2  /**
   3  * @version $Id: newsfeeds.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', 'botSearchNewsfeedslinks' );
  18  
  19  /**
  20  * Contacts 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 botSearchNewsfeedslinks( $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['newsfeeds']) ) {
  33          // load mambot params info
  34          $query = "SELECT params"
  35          . "\n FROM #__mambots"
  36          . "\n WHERE element = 'newsfeeds.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['newsfeeds'] = $mambot;
  44      }
  45      
  46      // pull query data from class variable
  47      $mambot = $_MAMBOTS->_search_mambot_params['newsfeeds'];    
  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  
  58      $wheres = array();
  59      switch ($phrase) {
  60          case 'exact':
  61              $wheres2 = array();
  62              $wheres2[] = "LOWER(a.name) LIKE '%$text%'";
  63              $wheres2[] = "LOWER(a.link) LIKE '%$text%'";
  64              $where = '(' . implode( ') OR (', $wheres2 ) . ')';
  65              break;
  66              
  67          case 'all':
  68          case 'any':
  69          default:
  70              $words = explode( ' ', $text );
  71              $wheres = array();
  72              foreach ($words as $word) {
  73                  $wheres2 = array();
  74                    $wheres2[] = "LOWER(a.name) LIKE '%$word%'";
  75                  $wheres2[] = "LOWER(a.link) LIKE '%$word%'";
  76                  $wheres[] = implode( ' OR ', $wheres2 );
  77              }
  78              $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
  79              break;
  80      }
  81  
  82  
  83      switch ( $ordering ) {
  84          case 'alpha':
  85              $order = 'a.name ASC';
  86              break;
  87  
  88          case 'category':
  89              $order = 'b.title ASC, a.name ASC';
  90              break;
  91  
  92          case 'oldest':
  93          case 'popular':
  94          case 'newest':
  95          default:
  96              $order = 'a.name ASC';
  97      }
  98  
  99      $query = "SELECT a.name AS title,"
 100      . "\n '' AS created,"
 101      . "\n a.link AS text,"
 102      . "\n CONCAT_WS( ' / '," . $database->Quote( _SEARCH_NEWSFEEDS ) . ", b.title )AS section,"
 103      . "\n CONCAT( 'index.php?option=com_newsfeeds&task=view&feedid=', a.id ) AS href,"
 104      . "\n '1' AS browsernav"
 105      . "\n FROM #__newsfeeds AS a"
 106      . "\n INNER JOIN #__categories AS b ON b.id = a.catid"
 107      . "\n WHERE ( $where )"
 108      . "\n AND a.published = 1"
 109      . "\n AND b.published = 1"
 110      . "\n AND b.access <= " . (int) $my->gid
 111      . "\n ORDER BY $order"
 112      ;
 113      $database->setQuery( $query, 0, $limit );
 114      $rows = $database->loadObjectList();
 115      
 116      return $rows;
 117  }
 118  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics