<?php
//v1.7 www.exoops.info 2006/03 
// $Id: search.inc.php,v 1.6 2003/03/19 07:01:17 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
function news_search($queryarray, $andor, $limit, $offset, $userid) {
global $db;
$sql = "
	SELECT
	storyid,
	uid,
	title,
	created,
	LEFT(hometext, 95) AS content
	FROM ".$db->prefix("stories")."
	WHERE
	published > 0
	AND
	published < ".time()."";
if ( $userid != 0 ) {
	$sql .= " AND uid=".$userid." ";
}
// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
$count = count($queryarray);
if ( $count > 0 && is_array($queryarray) ) {
	$sql .= " AND ((hometext LIKE '%$queryarray[0]%' OR bodytext LIKE '%$queryarray[0]%' OR title LIKE '%$queryarray[0]%')";
	for ($i=1; $i<$count; $i++) {
		$sql .= " $andor ";
		$sql .= "(hometext LIKE '%$queryarray[$i]%' OR bodytext LIKE '%$queryarray[$i]%' OR title LIKE '%$queryarray[$i]%')";
	}
	$sql .= ") ";
}
$sql   .= " ORDER BY created DESC";
$result = $db->query($sql, $limit, $offset);
$i = 0;
if ($result) {
	while ($myrow = $db->fetchArray($result)) {
		$ret[$i]['image']   = "images/content.gif";
		$ret[$i]['link']    = "article.php?storyid=".$myrow['storyid']."";
		$ret[$i]['title']   = $myrow['title'];
		$ret[$i]['content'] = $myrow['content'];
		$ret[$i]['time']    = $myrow['created'];
		$ret[$i]['uid']     = $myrow['uid'];
		$i++;
	}
}
return $ret;
}
?>
