<?php
// $Id: visit.php,v 1.1 2004/07/11 10:28:18 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// 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($HTTP_GET_VARS['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->fetch_row($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();
?>
