[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  /**
   3  * @version $Id: content.searchbot.php 5486 2006-10-16 12:14:56Z akede $
   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', 'botSearchContent' );
  18  
  19  /**
  20  * Content 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 botSearchContent( $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['content']) ) {
  33          // load mambot params info
  34          $query = "SELECT params"
  35          . "\n FROM #__mambots"
  36          . "\n WHERE element = 'content.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['content'] = $mambot;
  44      }
  45  
  46      // pull query data from class variable
  47      $mambot = $_MAMBOTS->_search_mambot_params['content'];
  48  
  49      $botParams = new mosParameters( $mambot->params );
  50  
  51      $limit         = $botParams->def( 'search_limit', 50 );
  52      $nonmenu    = $botParams->def( 'nonmenu', 1 );
  53  
  54      $nullDate     = $database->getNullDate();
  55      $now         = _CURRENT_SERVER_TIME;
  56  
  57      $text = trim( $text );
  58      if ($text == '') {
  59          return array();
  60      }
  61  
  62      $wheres = array();
  63      switch ($phrase) {
  64          case 'exact':
  65              $wheres2     = array();
  66              $wheres2[]     = "LOWER(a.title) LIKE LOWER('%$text%')";
  67              $wheres2[]     = "LOWER(a.introtext) LIKE LOWER('%$text%')";
  68              $wheres2[]     = "LOWER(a.fulltext) LIKE LOWER('%$text%')";
  69              $wheres2[]     = "LOWER(a.metakey) LIKE LOWER('%$text%')";
  70              $wheres2[]     = "LOWER(a.metadesc) LIKE LOWER('%$text%')";
  71              $where         = '(' . implode( ') OR (', $wheres2 ) . ')';
  72              break;
  73  
  74          case 'all':
  75          case 'any':
  76          default:
  77              $words = explode( ' ', $text );
  78              $wheres = array();
  79              foreach ($words as $word) {
  80                  $wheres2     = array();
  81                  $wheres2[]     = "LOWER(a.title) LIKE LOWER('%$word%')";
  82                  $wheres2[]     = "LOWER(a.introtext) LIKE LOWER('%$word%')";
  83                  $wheres2[]     = "LOWER(a.fulltext) LIKE LOWER('%$word%')";
  84                  $wheres2[]     = "LOWER(a.metakey) LIKE LOWER('%$word%')";
  85                  $wheres2[]     = "LOWER(a.metadesc) LIKE LOWER('%$word%')";
  86                  $wheres[]     = implode( ' OR ', $wheres2 );
  87              }
  88              $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
  89              break;
  90      }
  91  
  92      $morder = '';
  93      switch ($ordering) {
  94          case 'oldest':
  95              $order = 'a.created ASC';
  96              break;
  97  
  98          case 'popular':
  99              $order = 'a.hits DESC';
 100              break;
 101  
 102          case 'alpha':
 103              $order = 'a.title ASC';
 104              break;
 105  
 106          case 'category':
 107              $order = 'b.title ASC, a.title ASC';
 108              $morder = 'a.title ASC';
 109              break;
 110  
 111          case 'newest':
 112          default:
 113              $order = 'a.created DESC';
 114              break;
 115      }
 116  
 117      // search content items
 118      $query = "SELECT a.title AS title,"
 119      . "\n a.created AS created,"
 120      . "\n CONCAT(a.introtext, a.fulltext) AS text,"
 121      . "\n CONCAT_WS( '/', u.title, b.title ) AS section,"
 122      . "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id ) AS href,"
 123      . "\n '2' AS browsernav,"
 124      . "\n 'content' AS type"
 125       . "\n, u.id AS sec_id, b.id as cat_id"
 126       . "\n FROM #__content AS a"
 127      . "\n INNER JOIN #__categories AS b ON b.id=a.catid"
 128      . "\n INNER JOIN #__sections AS u ON u.id = a.sectionid"
 129      . "\n WHERE ( $where )"
 130      . "\n AND a.state = 1"
 131      . "\n AND u.published = 1"
 132      . "\n AND b.published = 1"
 133      . "\n AND a.access <= " . (int) $my->gid
 134      . "\n AND b.access <= " . (int) $my->gid
 135      . "\n AND u.access <= " . (int) $my->gid
 136      . "\n AND ( a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " )"
 137      . "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"
 138      . "\n GROUP BY a.id"
 139      . "\n ORDER BY $order"
 140      ;
 141      $database->setQuery( $query, 0, $limit );
 142      $list = $database->loadObjectList();
 143  
 144      // search static content
 145      $query = "SELECT a.title AS title,"
 146      . "\n a.created AS created,"
 147      . "\n a.introtext AS text,"
 148      . "\n " . $database->Quote( _STATIC_CONTENT ) . " AS section,"
 149      . "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id, '&Itemid=', m.id ) AS href,"
 150      . "\n '2' AS browsernav,"
 151      . "\n a.id"
 152      . "\n FROM #__content AS a"
 153      . "\n LEFT JOIN #__menu AS m ON m.componentid = a.id"
 154      . "\n WHERE ($where)"
 155      . "\n AND a.state = 1"
 156      . "\n AND a.access <= " . (int) $my->gid
 157      . "\n AND m.type = 'content_typed'"
 158      . "\n AND ( a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " )"
 159      . "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"
 160      . "\n GROUP BY a.id"
 161      . "\n ORDER BY ". ($morder ? $morder : $order)
 162      ;
 163      $database->setQuery( $query, 0, $limit );
 164      $list2 = $database->loadObjectList();
 165  
 166      // search archived content
 167      $query = "SELECT a.title AS title,"
 168      . "\n a.created AS created,"
 169      . "\n a.introtext AS text,"
 170      . "\n CONCAT_WS( '/', " . $database->Quote( _SEARCH_ARCHIVED ) . ", u.title, b.title ) AS section,"
 171      . "\n CONCAT('index.php?option=com_content&task=view&id=',a.id) AS href,"
 172      . "\n '2' AS browsernav,"
 173      . "\n 'content' AS type"
 174      . "\n FROM #__content AS a"
 175      . "\n INNER JOIN #__categories AS b ON b.id=a.catid"
 176      . "\n INNER JOIN #__sections AS u ON u.id = a.sectionid"
 177      . "\n WHERE ( $where )"
 178      . "\n AND a.state = -1"
 179      . "\n AND u.published = 1"
 180      . "\n AND b.published = 1"
 181      . "\n AND a.access <= " . (int) $my->gid
 182      . "\n AND b.access <= " . (int) $my->gid
 183      . "\n AND u.access <= " . (int) $my->gid
 184      . "\n AND ( a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " )"
 185      . "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"
 186      . "\n ORDER BY $order"
 187      ;
 188      $database->setQuery( $query, 0, $limit );
 189      $list3 = $database->loadObjectList();
 190  
 191      // check if search of nonmenu linked static content is allowed
 192      if ($nonmenu) {
 193          // collect ids of static content items linked to menu items
 194          // so they can be removed from query that follows
 195          $ids = null;
 196          if(count($list2)) {
 197              foreach($list2 as $static) {
 198                  $ids[] = (int) $static->id;
 199              }
 200              $ids = "a.id != " . implode( " OR a.id != ", $ids );
 201          }
 202  
 203          // search static content not connected to a menu
 204          $query = "SELECT a.title AS title,"
 205          . "\n a.created AS created,"
 206          . "\n a.introtext AS text,"
 207          . "\n '2' as browsernav, " . $database->Quote( _STATIC_CONTENT ) . " AS section,"
 208          . "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id ) AS href,"
 209          . "\n a.id"
 210          . "\n FROM #__content AS a"
 211          . "\n WHERE ($where)"
 212          . (($ids) ? "\n AND ( $ids )" : '')
 213          . "\n AND a.state = 1"
 214          . "\n AND a.access <= " . (int) $my->gid
 215          . "\n AND a.sectionid = 0"
 216          . "\n AND ( a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " )"
 217          . "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"
 218          . "\n ORDER BY ". ($morder ? $morder : $order)
 219          ;
 220          $database->setQuery( $query, 0, $limit );
 221          $list4 = $database->loadObjectList();
 222      } else {
 223          $list4 = array();
 224      }
 225  
 226      return array_merge( $list, $list2, $list3, (array)$list4 );
 227  }
 228  ?>


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