<?php
eval( '
function '. $mydirname .'_search( $keywords , $andor , $limit , $offset , $userid )
{
	return links_search_base( "'.$mydirname.'" , $keywords , $andor , $limit , $offset , $userid ) ;
}
' ) ;


if (!function_exists('links_search_base'))
{
	require_once realpath(dirname(__FILE__)) . '/../class/links_Base.class.php';

	function links_search_base($mydirname, $queryarray, $andor, $limit, $offset, $userid)
	{
		// XOOPS Search module
		$showcontext = empty($_GET['showcontext']) ? 0: 1;

		// $Links OBJ
		$link_search = links_Base::getInstance($mydirname);

		if (! $link_search->isadmin) {
			$link_search->setWhere('l.status', 0, '>');
		}
		$link_search->setWhere('l.date', time(), '<');
		if ($userid != 0) {
			$link_search->setWhere('l.submitter', $userid, '=');
		}
		if (is_array($queryarray) && $count = count($queryarray)) {
			$query = ' (';
			for ($i=0; $i < $count; $i++) {
				$query .= $i == 0 ? '': $andor;
				$query .= " ( l.title LIKE '%". mysql_real_escape_string($queryarray[$i]) ."%' OR l.url LIKE '%". mysql_real_escape_string($queryarray[$i]) ."%' ";
				$query .= " OR t.description LIKE '%". mysql_real_escape_string($queryarray[$i]) ."%' )";
			}
			$query .= ") ";
			$link_search->setRealWhere($query);
		}
		$link_search->setOrder('l.date DESC');
		$links = $link_search->getDatas($limit, $offset);

		$strAnd = '&amp;';

		if ($link_search->module_config['url_approach'] == 0) {
			$link_uri_base = 'index.php?m=item' . $strAnd . 'lid=%u';
		} else {
			$link_uri_base = 'index.php/item/%u';
		}

		$ret = array();
		foreach ($links as $key => $link) {
			if (function_exists('search_make_context') && $showcontext) {
				$full_context = strip_tags($link['description']);
				if( function_exists( 'easiestml' ) ) $full_context = easiestml( $full_context ) ;
				$context = search_make_context($full_context, $queryarray);
				$ret[$key]['context'] = $context;
			}
			$ret[$key]['image']   = "images/link.png";
			$ret[$key]['link']    = sprintf($link_uri_base, $link['lid']);//"index.php?c=index{$strAnd}m=item{$strAnd}lid=" . $link['lid'];
			$ret[$key]['title']   = $link['title'];
			if ($link_search->isadmin && $link['status'] <= 0) {
				$ret[$key]['title'] .= ' [' . $link['status'] . ']';
			}
			$ret[$key]['time']    = $link['date'];
			$ret[$key]['uid']     = $link['submitter'];
		}

		return $ret;
	}

}

