<?php

/*
** DGS Search
** $Id: results.php,v 1.2 2006/01/24 07:08:09 sella Exp $
** Copyright (c) 2000-2001 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

function results($retVal, $sq, $timer) {
	global $config, $css, $lang;

	$o = $sq['o'];
	$r = $sq['r'];
	$descHeight = $config['descHeight'];
	$size = ($sq['s'] < 1) ? count($retVal) : $sq['s'];
	$target = $config['resultTarget'];
	$infoBar = $config['infoBar'];
	$infoBarFormat = $config['infoBarFormat'];
	$translate = $config['translate'];
	$translateFrom = $config['translateFrom'];
	$docExts = $config['docExts'];
	$extSeparator = $config['extSeparator'];
	$lowerBound = $o + 1;
	$upperBound = ($r + $o < $size) ? $o + $r : $size;
	$dispR = ($r == $config['maxResults']) ? 0 : $r;

	if ($size > 0) {
		printf("\t<DIV CLASS=\"results\"> <!-- Display Module: results -->\n", $css['results']);
		$i = 0;
		reset($retVal);
		while (list(, $match) = each($retVal)) {
			$i++;
			if ($i <= $o)
				continue;
			if ($i > $o + $r)
				break;
			$link = $match['link'];
			$url = str_replace(' ', '%20', $match['url']);
			$urlExt = ereg_replace(sprintf('^.*\\%s([^\\%s]+)$', $extSeparator, $extSeparator), '\\1', $url);
			$fileSize = $match['fileSize'] / 1024;
			$lastMod = $match['lastMod'];
			$descArray = $match['description'];
			$source = $match['source'];
			printf("\t\t<DL>\n\t\t\t<DT CLASS=\"%s\">%d. <A CLASS=\"%s\" HREF=\"%s\" TARGET=\"%s\">%s</A>", $css['resultNum'], $i, $css['resultLink'], $url, $target, $link);
			if ($translate && !dgs_in_array($urlExt, $docExts)) {
				//EXAMPLE: http://babel.altavista.com/urltrurl?url=2F%2Fwww.digital-genesis.com&lp=en_de&tt=url'
				//The original way..
				//$translateURL = 'http://babel.altavista.com/translate.dyn?url=' . urlencode($url);
				//The new way..
				$translateURL = 'http://babel.altavista.com/urltrurl?tt=url&url=' . urlencode($url);
				if (eregi("^[a-z][a-z]_[a-z][a-z]$", $translateFrom)) {
					$translateURL .= '&lp=' . $translateFrom;
				}
				printf(" - <A CLASS=\"%s\" HREF=\"%s\" TARGET=\"%s\">%s</A>", $css['transLink'], $translateURL, $target, $lang['translate']);
			}
			printf("</DT>\n");
			while (list(, $desc) = each($descArray)) {
				printf("\t\t\t<DD CLASS=\"%s\">%s</DD>\n", $css['desc'], $desc);
			}
			if ($infoBar) {
				$buffer = $infoBarFormat;
				if ($url) {
					$buffer = str_replace('@DASH-URL@', '-', $buffer);
					$buffer = str_replace('@FULLURL@', $url, $buffer);
					$buffer = str_replace('@URL@', eregi_replace('^[a-z]+://', '', $url), $buffer);
					$buffer = str_replace('@HOST@', eregi_replace('^[a-z]+://([^/]+)..*$', '\\1', $url), $buffer);
				}
				if ($fileSize) {
					$buffer = str_replace('@DASH-SIZE@', '-', $buffer);
					$buffer = str_replace('@SIZE@', sprintf('%dk', $fileSize), $buffer);
					$buffer = str_replace('@SIZE1@', sprintf('%0.1fk', $fileSize), $buffer);
					$buffer = str_replace('@SIZE2@', sprintf('%0.2fk', $fileSize), $buffer);
				}
				if ($lastMod) {
					$buffer = str_replace('@DASH-LASTMOD@', '-', $buffer);
					$buffer = str_replace('@LASTMOD@', $lastMod, $buffer);
				}
				if ($target) {
					$buffer = str_replace('@DASH-TARGET@', '-', $buffer);
					$buffer = str_replace('@TARGET@', $target, $buffer);
				}
				/* Eat up any extra variables. */
				$buffer = ereg_replace('(@[A-Z0-9-]+@)', '<!-- Unused: \\1 -->', $buffer);
				if (strlen(trim($buffer)) > 0) {
					printf("\t\t\t<DD CLASS=\"%s\">%s</DD>\n", $css['infoBar'], $buffer);
				}
			}
			printf("\t\t</DL>\n");
		}
		printf("\t</DIV>\n");
	}

	return true;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim:
** vim: noet ts=3 sw=3
*/

?>
