[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

/mambots/search/ -> newsfeeds.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', 'botSearchNewsfeedslinks' );
  20  
  21  /**
  22  * Contacts 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 botSearchNewsfeedslinks( $text, $phrase='', $ordering='' ) {
  31      global $database, $my;
  32  
  33      $text = trim( $text );
  34      if ($text == '') {
  35          return array();
  36      }
  37      
  38      $menuhandler = mosMenuHandler::getInstance();
  39      $Itemid = $menuhandler->getIDByTypeLink('*', 'index.php?option=com_newsfeeds');
  40  
  41      $wheres = array();
  42      switch ($phrase) {
  43          case 'exact':
  44              $wheres2 = array();
  45              $wheres2[] = "LOWER(a.name) LIKE '%$text%'";
  46              $wheres2[] = "LOWER(a.link) 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.name) LIKE '%$word%'";
  57                  $wheres2[] = "LOWER(a.link) LIKE '%$word%'";
  58                  $wheres[] = implode( ' OR ', $wheres2 );
  59              }
  60              $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
  61              break;
  62      }
  63      
  64  
  65      switch ( $ordering ) {
  66          case 'alpha':
  67              $order = 'a.name ASC';
  68              break;
  69              
  70          case 'category':
  71              $order = 'b.title ASC, a.name ASC';
  72              break;
  73              
  74          case 'oldest':
  75          case 'popular':
  76          case 'newest':
  77          default:
  78              $order = 'a.name ASC';
  79      }
  80  
  81      $query = "SELECT a.name AS title,"
  82      . "\n a.link AS text,"
  83      . "\n '' AS created,"
  84      . "\n CONCAT_WS( ' / ','News Feeds', b.title )AS section,"
  85      . "\n '1' AS browsernav,"
  86      . "\n CONCAT( 'index.php?option=com_newsfeeds&task=view&Itemid=$Itemid&feedid=', a.id ) AS href"
  87      . "\n FROM #__newsfeeds AS a"
  88      . "\n INNER JOIN #__categories AS b ON b.id = a.catid AND b.access <= '$my->gid'"
  89      . "\n WHERE ( $where )"
  90      . "\n AND a.published = 1"
  91      . "\n ORDER BY $order"
  92      ;
  93      $database->setQuery( $query );
  94      $rows = $database->loadObjectList();
  95      return $rows;
  96  }
  97  ?>