<?php
/**
* Class file to get different statistics
*
*/
class RSTATS extends RCORE
{
/**
* Function to display different all in one statistics
*
*/
function DisplayStats()
{
echo
"
<table width='100%' cellspacing='6' cellpadding='5'>
<tr>
<td colspan='2'><strong>RGameScript Pro Statistics</strong></td>
</tr>
<tr>
<td>Total Diskspace Usage: </td>
<td><div align='right'>".$this->RDiskSpaceUsage("./../")."</div></td>
</tr>
<tr>
<td>Total Diskspace Used by Games: </td>
<td><div align='right'>".$this->RDiskSpaceUsage("./../rgames/swf/")."</div></td>
</tr>
<tr>
<td>Total Diskspace Used by Game Icons: </td>
<td><div align='right'>".$this->RDiskSpaceUsage("./../rgames/game_icons/")."</div></td>
</tr>
<tr>
<td>Total Diskspace Used by Category Icons: </td>
<td><div align='right'>".$this->RDiskSpaceUsage("./../icons/")."</div></td>
</tr>
<tr>
<td>Total Active Games: </td>
<td><div align='right'>".$this->GetActiveGames()."</div></td>
</tr>
<tr>
<td>Total Game Files: </td>
<td><div align='right'>".$this->num_files("./../rgames/swf/")."</div></td>
</tr>
<tr>
<td>Total Game Icons: </td>
<td><div align='right'>".$this->num_files("./../rgames/game_icons/")."</div></td>
</tr>
</table>
";
}
/**
* Function to count number of files in a directory
*
* @param string $directory The directory from which files will be counted
* @return integer The total amount of files
*/
function num_files($directory='.') {
return count(glob($directory."/*.*"));
}
/**
* Function to active games
*
* @return integer The total amount of active games
*/
function GetActiveGames()
{
$amount = $this->RNumRows("SELECT * FROM rgames_flash WHERE GameAlive = 1");
return $amount;
}
/**
* Function to count total diskspace usage in a directory
*
* @param string $dir The directory to find the diskusage of
* @return string The amount of diskspace used
*/
function RDiskSpaceUsage($dir)
{
$usage = $this->disk_usage($dir);
$format = $this->format_filesize($usage);
return $format;
}
/**
* Function to find the actual diskspace and its sub-directories
*
* @param string $d The directory
* @param string $depth Depth level of the directory
* @return integer The amount of diskspace used
*/
function disk_usage($d, $depth = NULL)
{
if(is_file($d))
return filesize($d);
if(isset($depth) && $depth < 0)
return 0;
if($d[strlen($d)-1] != '\\' || $d[strlen($d)-1] != '/')
$d .= '/';
$dh=@opendir($d);
if(!$dh)
return 0;
while($e = readdir($dh))
if($e != '.' && $e != '..')
$usage += $this->disk_usage($d.$e, isset($depth) ? $depth - 1 : NULL);
closedir($dh);
return $usage;
}
/**
* Function format any filesize and return as bytes, MB or GB
*
* @param integer $int The amount
* @param string $bytesstyle Options style (leave false)
* @return string The file size
*/
function format_filesize($int,$bytesstyle = false)
{
if ($bytesstyle != false){$bytes = $int;}
$str = " bytes";
if ($int > 1024+256){$int /= 1024; $str = " KB";}
if ($int > 1024+256){$int /= 1024; $str = " MB";}
if ($int > 1024+256){$int /= 1024; $str = " GB";}
if ($int > 1024+256){$int /= 1024; $str = " TB";}
$int2 = round(number_format($int,2),2);
if ($str != " bytes" AND $bytesstyle == 1){$str .= " (".$bytes." bytes)";}
return $int2.$str;
}
}
?>