From a39d3fff7fbe9095f484f9f9fab8ee2014b595ad Mon Sep 17 00:00:00 2001 From: Anaggh S Date: Fri, 15 Nov 2019 21:17:56 +0530 Subject: [PATCH] Add Disk Size to Simple Stats --- bl-kernel/helpers/filesystem.class.php | 28 ++++++++++++++++++++ bl-plugins/simple-stats/languages/de_CH.json | 3 ++- bl-plugins/simple-stats/languages/de_DE.json | 3 ++- bl-plugins/simple-stats/languages/en.json | 3 ++- bl-plugins/simple-stats/languages/es.json | 5 ++-- bl-plugins/simple-stats/languages/fa_IR.json | 3 ++- bl-plugins/simple-stats/languages/fr_FR.json | 3 ++- bl-plugins/simple-stats/languages/it.json | 3 ++- bl-plugins/simple-stats/languages/ja_JP.json | 3 ++- bl-plugins/simple-stats/languages/nl_NL.json | 3 ++- bl-plugins/simple-stats/languages/ru_RU.json | 3 ++- bl-plugins/simple-stats/languages/tr.json | 3 ++- bl-plugins/simple-stats/plugin.php | 6 +++++ 13 files changed, 57 insertions(+), 12 deletions(-) diff --git a/bl-kernel/helpers/filesystem.class.php b/bl-kernel/helpers/filesystem.class.php index c7c8b186..c7417afa 100644 --- a/bl-kernel/helpers/filesystem.class.php +++ b/bl-kernel/helpers/filesystem.class.php @@ -264,4 +264,32 @@ class Filesystem { public static function extension($file) { return pathinfo($file, PATHINFO_EXTENSION); } + + /** + * Get Size of file or directory in bytes + * @param [string] $fileOrDirectory + * @return [int|bool [bytes or false on error] + */ + public static function getSize($fileOrDirectory) { + // Files + if (is_file($fileOrDirectory)) { + return filesize($fileOrDirectory); + } + // Directories + if (file_exists($fileOrDirectory)) { + $size = 0; + foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fileOrDirectory)) as $file){ + $size += $file->getSize(); + } + return $size; + } + return false; + } + + public static function bytesToHumanFileSize($bytes, $decimals = 2) { + $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); + $factor = floor((strlen($bytes) - 1) / 3); + return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$size[$factor]; + } + } diff --git a/bl-plugins/simple-stats/languages/de_CH.json b/bl-plugins/simple-stats/languages/de_CH.json index ed0cf4d1..3de04034 100644 --- a/bl-plugins/simple-stats/languages/de_CH.json +++ b/bl-plugins/simple-stats/languages/de_CH.json @@ -8,5 +8,6 @@ "visits-today": "Seitenaufrufe heute", "unique-visitors-today": "Besucher heute", "chart": "Chart", - "table": "Table" + "table": "Table", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/de_DE.json b/bl-plugins/simple-stats/languages/de_DE.json index c7b77a97..d5a8e9d0 100644 --- a/bl-plugins/simple-stats/languages/de_DE.json +++ b/bl-plugins/simple-stats/languages/de_DE.json @@ -8,5 +8,6 @@ "visits-today": "Seitenaufrufe heute", "unique-visitors-today": "Besucher heute", "chart": "Chart", - "table": "Table" + "table": "Table", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/en.json b/bl-plugins/simple-stats/languages/en.json index c343b890..5baff329 100644 --- a/bl-plugins/simple-stats/languages/en.json +++ b/bl-plugins/simple-stats/languages/en.json @@ -8,5 +8,6 @@ "visits-today": "Visits today", "unique-visitors-today": "Unique visitors today", "chart": "Chart", - "table": "Table" + "table": "Table", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/es.json b/bl-plugins/simple-stats/languages/es.json index 362e865b..45088270 100644 --- a/bl-plugins/simple-stats/languages/es.json +++ b/bl-plugins/simple-stats/languages/es.json @@ -8,5 +8,6 @@ "visits-today": "Visitas de hoy", "unique-visitors-today": "Visitantes únicos de hoy", "chart": "Gráfico", - "table": "Tabla" -} \ No newline at end of file + "table": "Tabla", + "disk-usage" : "Disk Usage" +} diff --git a/bl-plugins/simple-stats/languages/fa_IR.json b/bl-plugins/simple-stats/languages/fa_IR.json index 228c91d3..34243dd4 100644 --- a/bl-plugins/simple-stats/languages/fa_IR.json +++ b/bl-plugins/simple-stats/languages/fa_IR.json @@ -8,5 +8,6 @@ "visits-today": "بازدیدهای امروز", "unique-visitors-today": "بازدید کنندگان منحصر به فرد امروز", "chart": "چارت", - "table": "جدول" + "table": "جدول", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/fr_FR.json b/bl-plugins/simple-stats/languages/fr_FR.json index 1972173f..fec2a002 100644 --- a/bl-plugins/simple-stats/languages/fr_FR.json +++ b/bl-plugins/simple-stats/languages/fr_FR.json @@ -8,5 +8,6 @@ "visits-today": "Visites du jour", "unique-visitors-today": "Visiteurs uniques du jour", "chart": "Graphique", - "table": "Tableau" + "table": "Tableau", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/it.json b/bl-plugins/simple-stats/languages/it.json index 8362a1f4..c34f5697 100644 --- a/bl-plugins/simple-stats/languages/it.json +++ b/bl-plugins/simple-stats/languages/it.json @@ -8,5 +8,6 @@ "visits-today": "Visite oggi", "unique-visitors-today": "Visitatori unici oggi", "chart": "Grafico", - "table": "Tabella" + "table": "Tabella", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/ja_JP.json b/bl-plugins/simple-stats/languages/ja_JP.json index 8fa3a943..a19deca5 100644 --- a/bl-plugins/simple-stats/languages/ja_JP.json +++ b/bl-plugins/simple-stats/languages/ja_JP.json @@ -8,5 +8,6 @@ "visits-today": "Visits today", "unique-visitors-today": "Unique visitors today", "chart": "Chart", - "table": "テーブル" + "table": "テーブル", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/nl_NL.json b/bl-plugins/simple-stats/languages/nl_NL.json index 0a7071b0..f0ea1331 100644 --- a/bl-plugins/simple-stats/languages/nl_NL.json +++ b/bl-plugins/simple-stats/languages/nl_NL.json @@ -8,5 +8,6 @@ "visits-today": "Aantal bezoeken vandaag", "unique-visitors-today": "Unieke bezoekers vandaag", "chart": "Grafiek", - "table": "Tabel" + "table": "Tabel", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/ru_RU.json b/bl-plugins/simple-stats/languages/ru_RU.json index 5f2bdb2f..93f4f07c 100644 --- a/bl-plugins/simple-stats/languages/ru_RU.json +++ b/bl-plugins/simple-stats/languages/ru_RU.json @@ -8,5 +8,6 @@ "visits-today": "Посещений сегодня", "unique-visitors-today": "Уникальных посетителей сегодня", "chart": "Диаграмма", - "table": "Таблица" + "table": "Таблица", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/languages/tr.json b/bl-plugins/simple-stats/languages/tr.json index ebb7ec99..7e7df061 100644 --- a/bl-plugins/simple-stats/languages/tr.json +++ b/bl-plugins/simple-stats/languages/tr.json @@ -8,5 +8,6 @@ "visits-today": "Bugün yapılan ziyaretler", "unique-visitors-today": "Bugün yapılan benzersiz ziyaretler", "chart": "Grafik", - "table": "Tablo" + "table": "Tablo", + "disk-usage" : "Disk Usage" } diff --git a/bl-plugins/simple-stats/plugin.php b/bl-plugins/simple-stats/plugin.php index 110497ca..5b1686b2 100644 --- a/bl-plugins/simple-stats/plugin.php +++ b/bl-plugins/simple-stats/plugin.php @@ -220,6 +220,11 @@ EOF; public function renderContentStatistics($data) { + global $L; + $diskUsage = Filesystem::bytesToHumanFileSize( + Filesystem::getSize(PATH_ROOT) + ); + $html = '
'; $html .= "

{$data['title']}

"; $html .= ' @@ -237,6 +242,7 @@ EOF; '; + $html .= ""; foreach ($data['data'] as $th => $td) { $html .= "
{$L->get('disk-usage')}$diskUsage