<?php
session_start();
if (!isset($_SESSION["includes"])) {
	$_SESSION["includes"] = array();
}
if (!isset($_SESSION["repository"])) {
	$_SESSION["repository"] = array();
}
if ($_GET["add"]) {
	$_GET["add"] = basename($_GET["add"]);
	if (FALSE===array_search($_GET["add"], $_SESSION["includes"]) && file_exists("./repository/".$_GET["add"])) {
		$_SESSION["includes"][] = basename($_GET["add"]);
		$pos = array_search(basename($_GET["add"]), $_SESSION["repository"]);
		if (false !== $pos)
			array_splice ($_SESSION["repository"], $pos, 1);
	}
}
if ($_GET["del"]) {
	$_GET["del"] = basename($_GET["del"]);
	if (FALSE===array_search($_GET["del"], $_SESSION["repository"])) {
		$_SESSION["repository"][] = $_GET["del"];
		$pos = array_search($_GET["del"], $_SESSION["includes"]);
		if (false !== $pos)
			array_splice ($_SESSION["includes"], $pos, 1);
	}
}
if ($_GET["up"]) {
	$_GET["up"] = basename($_GET["up"]);
	if ($pos = array_search($_GET["up"], $_SESSION["includes"])) {
		if ($pos-2 >= 0) {
			$tmparr = array_slice($_SESSION["includes"], 0, $pos-1);
		}
		$tmparr[] = $_GET["up"];
		$tmparr[] = $_SESSION["includes"][$pos-1];
		$iend=count($_SESSION["includes"]);
		for($i=$pos+1; $i<$iend; ++$i) {
			$tmparr[] = $_SESSION["includes"][$i];
		}
		$_SESSION["includes"] = $tmparr;
		unset ($tmparr);
	}
}
if ($_GET["down"]) {
	$_GET["down"] = basename($_GET["down"]);
	if (($pos = array_search($_GET["down"], $_SESSION["includes"])) < count($_SESSION["includes"])-1) {
		$tmparr = array_slice($_SESSION["includes"], 0, $pos);
		$tmparr[] = $_SESSION["includes"][$pos+1];
		$tmparr[] = $_GET["down"];
		$iend=count($_SESSION["includes"]);
		for($i=$pos+2; $i<$iend; ++$i)
			$tmparr[] = $_SESSION["includes"][$i];
		$_SESSION["includes"] = $tmparr;
		unset ($tmparr);
	}
}
if ($_POST["envoyer"]) {
	$_FILES['envoi']['name'] = basename($_FILES['envoi']['name']);
	if (file_exists("./repository/".session_id().$_FILES['envoi']['name']))
		unlink("./repository/".session_id().$_FILES['envoi']['name']);
	move_uploaded_file ($_FILES['envoi']['tmp_name'], "./repository/".session_id().$_FILES['envoi']['name']);
	if (
		FALSE===array_search(session_id().$_FILES['envoi']['name'], $_SESSION["repository"]) &&
		FALSE===array_search(session_id().$_FILES['envoi']['name'], $_SESSION["includes"]))
	{
		$_SESSION["repository"][] = session_id().$_FILES['envoi']['name'];
	}
}
if ($_POST["destruction"]) {
	$_SESSION = array();
	if (isset($_COOKIE[session_name()]))
		setcookie(session_name(), '', time()-42000, '/');
	session_destroy();
	header("Location: http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>Zazou Script Parser</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<style type="text/css">
			h2 { margin-top: 0; }
			img { border: 0; }
			.fgauch {float: left}
			.fdroit {
			background: #eeeeee;
			border: solid 1px #000;
			margin-bottom: 20px;
			width: 30%;
			float: right;
			clear: right;
			overflow: auto;
			}
			.clear {clear: both}
		</style>
	</head>
	<body>
		<div>
			<h1>Zazou Script Parser</h1>
		</div>
		<div class="fgauch">
			<form action="sp.php" method="post">
				<textarea rows="30" cols="80" name="file_txt">
				&lt;?php
				phpinfo();
				// Un commentaire !
				
				$test = "Bonjour ";
				?&gt;
				</textarea>
				<div>
					<input type="checkbox" name="showincs" checked="checked" /> Montrer les scripts inclus
					<br />
					<input type="checkbox" name="indent" checked="checked" /> Indenter
					<br />
					<input type="checkbox" name="lnumber" checked="checked" /> Numéroter
					<br />
					<input type="checkbox" name="xhtml" checked="checked" /> Sortie XHTML
					<br />
					<input type="submit" value="Gazzz !" />
				</div>
			</form>
		</div>
		<div class="fdroit">
			<h2>Envoyer au dépôt:</h2>
			<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
				<input type="hidden" name="MAX_FILE_SIZE" value="102400" />
				<input name="envoi" type="file" />
				<input type="submit" name="envoyer" value="Envoyer" />
			</form>
		</div>
		<div class="fdroit">
			<h2>Le dépôt</h2>
<?php
foreach ($_SESSION["repository"] as $f) {
	$affich_f = substr($f, strlen(session_id()));
	echo "<a href=\"sp.php?showincs=1&amp;indent=1&amp;xhtml=1&amp;file=$f\">Voir</a> &lt;&lt;&lt; <a href=\"".$_SERVER["PHP_SELF"]."?add=$f\">Inclure</a> &lt;&lt;&lt; $affich_f<br />\n";
}
?>
		</div>
		<div class="fdroit">
			<h2>Vos inclusions</h2>
<?php
foreach ($_SESSION["includes"] as $f) {
	if ( FALSE!==strpos($f, session_id())) {
		$affich_f = substr($f, strlen(session_id()));
		echo "<a href=\"sp.php?indent=1&amp;xhtml=1&amp;file=$f\">Voir</a> &lt;&lt;&lt; ";
		echo "<a href=\"".$_SERVER["PHP_SELF"]."?del=$f\">Suppr</a> &lt;&lt;&lt; ";
		echo "<a href=\"".$_SERVER["PHP_SELF"]."?up=$f\">Up</a> | ";
		echo "<a href=\"".$_SERVER["PHP_SELF"]."?down=$f\">Down</a> &lt;&lt;&lt; ";
		echo "$affich_f<br />\n";
	}
}
?>
		</div>
		<div class="fdroit">
			<h2>Détruire le dépôt:</h2>
			<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
				<input type="submit" name="destruction" value="BOOOM !" />
			</form>
		</div>
		<div class="clear">
			Le script est <a href="sp.php?indent=1&amp;file=sp.php&amp;xhtml=1">ici</a><br />
			Le code de cette page est <a href="sp.php?indent=1&amp;file=index.php&amp;xhtml=1">ici</a>
			<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
		</div>
	</body>
</html>
Temps d'exécution: 0.299 secs

Valid XHTML 1.0!