<?php
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: visit.php,v 1.1 2003/08/31 12:16:12 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once('../../mainfile.php');
include_once('./cache/config.php');
$lid    = intval($_GET['lid']);
if ($mydownloadsConfig['check_external']) {
	$dl_ref   = parse_url(_HTTP_REFERER);
	$ref_host = $dl_ref['host'];
	if ($ref_host != _HTTP_HOST) {
		?>
		<script type="text/javascript">
		<!--
		self.moveTo(0,0);
		self.resizeTo(screen.availWidth,screen.availHeight);
		window.focus();
		// -->
		</script>
		<?php
		redirect_header(XOOPS_URL . '/modules/mydownloads/singlefile.php?lid='.$lid.'', 5, _MD_NOLINK);
		exit();
	}
}
$db->query('UPDATE '.$db->prefix('mydownloads_downloads').' SET hits=hits+1 WHERE lid='.$lid.' AND status>0');
$result    = $db->query('SELECT url FROM '.$db->prefix('mydownloads_downloads').' WHERE lid='.$lid.' AND status>0');
list($url) = $db->fetchRow($result);
// Hide file from browser by streaming it, if it's local:
if ( !preg_match('/^(http|https|ftp|ftps)/i', $url) && @is_file('cache/files/'.$url.'') ) {
	header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0');
	header('Content-type: application/octet-stream; name="'.$url.'"');
	header('Content-Disposition: attachment; filename="'.$url.'"');
	header('Location: cache/files/'.$url.'');

	exit();
}
header('Location: '.$url.'');
?>
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=<?php echo $url;?>" />
</head>
<body></body>
</html>
<?php

exit();
?>
