<?php
if($_REQUEST["stage"] == 1){
	$file_contents = file_get_contents($_REQUEST["url"]);
	$string = $file_contents;
	$str1 = "http://";
	$str2 = ".swf";
	$pos1 = strpos($string, $str1);
	$len1 = strlen($str1);
	$pos2 = strpos($string, $str2);
	$len2 = strlen($str2);
	if($pos1 === false || $pos2 === false){
		$full_url_passed = false;
	}
	$no_ext_string1 = substr($string, ($pos1 + $len1), ($pos2 - $pos1 + $len1));
	if($full_url_passed === false){
		$no_full_url = false;
	}
	if($no_full_url === false){
		echo "Er is geen SWF file gevonden in " . $_REQUEST["url"] . ". <br /> Controleer of je bestand geen .swf extensie heeft. <br /> Als dat zo is, klik hier.";
	exit();
	}else{
		$string = $no_ext_string1;
		$pos1 = strrpos($string, $str1);
		$len1 = strlen($str1);
		$pos2 = strrpos($string, $str2);
		$len2 = strlen($str2);
		$no_ext_string = substr($string, ($pos1), ($pos2 - $pos1));
		$swfurl = $no_ext_string . ".swf";
	}
	$full_url = strpos ( $swfurl , "=" );
	if ($full_url === false){
	}else{
		$str1 = "=";
		$string = $swfurl;
		$pos1 = strrpos($string, $str1);
		$len1 = strlen($str1);
		$pos2 = strrpos($string, $str2);
		$len2 = strlen($str2);
		$swfext = substr($string, ($pos1 + 2), ($pos2 - $pos1)) . "wf";
		$correcturl1 = "http://" . parse_url( $_REQUEST["url"], PHP_URL_HOST);
		$correcturl2 = parse_url( $_REQUEST["url"], PHP_URL_PATH);
		if (strrpos($correcturl2, ".php") === false){
			$swfurl = $correcturl1 . "/" . $swfext;
		}elseif (strrpos($correcturl2, ".html") === false){
			$swfurl = $correcturl1 . "/" . $swfext;
		}elseif (strrpos($correcturl2, ".htm") === false){
			$swfurl = $correcturl1 . "/" . $swfext;
		}else{
			$swfurl = $correcturl1 . "/" . $correcturl2 . "/" . $swfext;
		}
	}
	$shortname = basename($swfurl);
	header("Content-type: Application/octet-stream");
	header("Content-Disposition: attachment; filename=" . $shortname);
	readfile($swfurl);
}else{
echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>MathijsNET SWF Downloader</title>
<style type='text/css'>
<!--
.style1 {font-family: Tahoma, sans-serif}
.style2 {font-size: xx-large}
.style4 {font-size: small}
.style5 {color: #FF0000}
-->
</style>
</head>
<body>
<form action='Downloadscript.php' method='POST' target='_self' class='style1'>
<input type='hidden' name='stage' value='1' />
  <table width='900' border='0' cellspacing='0' cellpadding='0'>
    <tr>
      <td width='200'>&nbsp;</td>
      <td width='700'><p class='style2'>MathijsNET SWF Downloader! <br />
          <span class='style4'>made by Mathijs Henquet</span></p>
      </td>
    </tr>
    <tr>
      <td>Url van het SWFje:</td>
      <td><span class='style4'>
        <input width='700' name='url' type='text' value='http://' />
      bijvoorbeeld: &quot;http://www.spele.nl/game/arkanoid/arkanoidsneeuw.html&quot;<br />
      <span class='style5'>gebruik dit niet: &quot;http://games.spele.nl/spelehost2/2/snowball.swf&quot;</span></span></td>
    </tr>
  </table>    
  <input type='submit' value='Download' />
</form>
</body>
</html>";
}
?> 