[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

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

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  $_MAMBOTS->registerFunction( 'onSearch', 'botSearchWeblinks' );
  20  
  21  /**
  22  * Web Link Search method
  23  *
  24  * The sql must return the following fields that are used in a common display
  25  * routine: href, title, section, created, text, browsernav
  26  * @param string Target search string
  27  * @param string mathcing option, exact|any|all
  28  * @param string ordering option, newest|oldest|popular|alpha|category
  29  */
  30  function botSearchWeblinks( $text, $phrase='', $ordering='' ) {
  31      global $database, $my;
  32  
  33      $text = trim( $text );
  34      if ($text == '') {
  35          return array();
  36      }
  37      $section     = T_('Web Links');
  38  
  39      $wheres     = array();
  40      switch ($phrase) {
  41          case 'exact':
  42              $wheres2 = array();
  43              
  44              $wheres2[] = "LOWER(a.url) LIKE '%$text%'";
  45              $wheres2[] = "LOWER(a.description) LIKE '%$text%'";
  46              $wheres2[] = "LOWER(a.title) LIKE '%$text%'";            
  47              $where = '(' . implode( ') OR (', $wheres2 ) . ')';
  48              break;
  49          case 'all':
  50          case 'any':
  51          default:
  52              $words = preg_split( '/\s+|,/', $text );
  53              $wheres = array();
  54              foreach ($words as $word) {
  55                  $wheres2 = array();
  56                    $wheres2[]     = "LOWER(a.url) LIKE '%$word%'";
  57                  $wheres2[]     = "LOWER(a.description) LIKE '%$word%'";
  58                  $wheres2[]     = "LOWER(a.title) LIKE '%$word%'";                
  59                  $wheres[]     = implode( ' OR ', $wheres2 );
  60              }
  61              $where     = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
  62              break;
  63      }    
  64  
  65      switch ( $ordering ) {
  66          case 'oldest':
  67              $order = 'a.date ASC';
  68              break;
  69          case 'popular':
  70              $order = 'a.hits DESC';
  71              break;
  72          case 'alpha':
  73              $order = 'a.title ASC';
  74              break;
  75          case 'category':
  76              $order = 'b.title ASC, a.title ASC';
  77              break;
  78          case 'newest':
  79          default:
  80              $order = 'a.date DESC';
  81      }
  82  
  83      $query = "SELECT a.title AS title,"
  84      . "\n a.description AS text,"
  85      . "\n a.date AS created,"
  86      . "\n CONCAT_WS( ' / ', '$section', b.title ) AS section,"
  87      . "\n '1' AS browsernav,"
  88      . "\n a.url AS href"
  89      . "\n FROM #__weblinks AS a"
  90      . "\n INNER JOIN #__categories AS b ON b.id = a.catid AND b.access <= '$my->gid'"
  91      . "\n WHERE ($where)"
  92      . "\n ORDER BY $order"
  93      ;
  94      $database->setQuery( $query );
  95      $rows = $database->loadObjectList();
  96      return $rows;
  97  }
  98  ?>