Initial commit.

This commit is contained in:
2026-03-10 21:25:26 +08:00
commit 78739bf725
3089 changed files with 472990 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
<?php
// File name: sitesize.inc.php
// Description: PHP subroutines to calculate the size of the web site
// Date: 2007-08-09
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2007 Pristine Communications
// Set the include path
if (!defined("INCPATH_SET")) {
require_once dirname(__FILE__) . "/incpath.inc.php";
}
// Referenced subroutines
require_once "monica/echoform.inc.php";
require_once "monica/gettext.inc.php";
require_once "monica/htmlchar.inc.php";
require_once "monica/markabbr.inc.php";
require_once "monica/requri.inc.php";
require_once "monica/sql.inc.php";
// Settings
// This is true for almost all the cases
define("_SITESIZE_BLKSIZE", 512);
// sitesize: Calculate and return the size of the website
function sitesize()
{
$files = _sitesize_dirsize(DOC_ROOT);
$data = sql_dbsize();
return array(
"files" => $files,
"data" => $data,
"total" => $files + $data,
);
}
// html_sitesize: Print the size usage of the website
function html_sitesize()
{
$size = sitesize();
if ($size["data"] == 0) {
?><p class="sitesize"><?php printf(h(C_("Currently using files %s.\n")),
h_abbr(report_size($size["files"]))); ?></p>
<?php
} else {
?><p class="sitesize"><?php printf(h(C_("Currently using files %s, database %s, total %s.\n")),
h_abbr(report_size($size["files"])),
h_abbr(report_size($size["data"])),
h_abbr(report_size($size["total"]))); ?></p>
<?php
}
return;
}
// _sitesize_dirsize: Calculate the size of a directory
function _sitesize_dirsize($dir)
{
// Get everything inside
$ents = array();
$dh = opendir($dir);
while (($ent = readdir($dh)) !== false) {
// Not a real entry
if ($ent == "." || $ent == "..") {
continue;
}
$ents[] = "$dir/$ent";
}
closedir($dh);
$size = 0;
// Add the size of this directory
$stat = lstat($dir);
$size += $stat[12] * _SITESIZE_BLKSIZE;
for ($i = 0; $i < count($ents); $i++) {
// Directory - recursive into inside
if (is_dir($ents[$i]) && !is_link($ents[$i])) {
$size += _sitesize_dirsize($ents[$i]);
// Non-directory - add its size
} else {
$stat = lstat($ents[$i]);
$size += $stat[12] * _SITESIZE_BLKSIZE;
}
}
return $size;
}
?>