<?php
/*
 * Apoltix GetSLOC
 * Calculate source lines of code
 * Released under the GNU General Public License
 * @author: Christian Rasmussen
 * @version: 1.0
 * @version-minor: 0.3
 * @license: GNU General Public License
 * @created-date: 2006-07-28
 * @created-time: 13:47
 * @last-edited-date: 2006-07-28
 * @last-edited-time: 23:19
*/

// SETTINGS
$cfg["scandir"] = "/AppServ/www/root/development/sites/hdmedia.dk_dev/";
// END SETTINGS
if ( isset($_GET["source"]) ) {
	highlight_file($_SERVER["SCRIPT_FILENAME"]);
	exit();
}
?>
<!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=iso-8859-1" />
	<title>Apoltix GetSLOC 1.0 alpha</title>
	<style type="text/css">
	body, table {
		font : normal 12px Verdana, Helvetica, sans-serif;
	}
	</style>
</head>

<body>
<?php
$dir = opendir($cfg["scandir"]);
?>
<h2>Source lines of code for <?=$cfg["scandir"]?></h2>
<table>
<tr><td><strong>Fil</strong></td><td><strong>Størrelse</strong></td><td><strong>SLOC</strong></td></tr>
<?php
$dir_content = scandir($cfg["scandir"]);
$totallines = 0;
foreach($dir_content as $dir_key => $dir_value) {
	if ( is_file($cfg["scandir"] . $dir_value) ) {
?>
<tr><td><?=$dir_value?></td><td><?=filesize($cfg["scandir"] . $dir_value)?> byte</td><td><?php
		$total_filesize = $total_filesize + filesize($cfg["scandir"] . $dir_value);
		$filecontent = file($cfg["scandir"] . $dir_value);
		$linesx = 0;
//		if ( is_string($filecontent) ) {
		foreach($filecontent as $lines => $line) {
//			if ( isset($_GET["yes"]) ) {
//				if ( preg_match("/(\/\/|#| )\n/", $line) ) {
					// Don't add the line, because it starts as a comment
//				} else {
//					print $lines . ": " . htmlspecialchars($line) . "<br />";
					$linesx++;
//				}
//			}
		}
		print $linesx;
//		} else {
//			print "(Binær)";
//		}
?> linjer</td></tr>
<?php
		$totallines = $totallines + $linesx;
	} elseif ( is_dir($cfg["scandir"] . $dir_value) && isset($_GET["dir"]) ) {
//		print "{$dir_value}";
//		print " (Mappe)\n";
	$sdir = scandir("./".$dir_value);
	foreach($sdir as $sdir_key => $sdir_value) {
	if ( $sdir_value != '.' && $sdir_value != '..' ) {
?>
<tr><td><?=$sdir_value?></td><td><?=filesize($cfg["scandir"] . $dir_value)?> byte</td><td><?php
//		$total_filesize = $total_filesize + filesize($cfg["scandir"] . $dir_value);
//		$filecontent = file($cfg["scandir"] . $dir_value);
		$linesx = 0;
//		if ( is_string($filecontent) ) {
//		foreach($filecontent as $lines => $line) {
//			if ( isset($_GET["yes"]) ) {
//				if ( preg_match("/(\/\/|#| )\n/", $line) ) {
					// Don't add the line, because it starts as a comment
//				} else {
//					print $lines . ": " . htmlspecialchars($line) . "<br />";
					$linesx++;
//				}
//			}
//		}
//		print $linesx;
//		} else {
//			print "(Binær)";
//		}
?> linjer</td></tr>
<?php
	}
	}
	} else {
//		print " (Ukendt)\n";
	}
}
?>
</table>
Totalt antal linjer: <?=$totallines?><br />
Total filstørrelse: <?=$total_filesize?> byte
</body>
</html>