From 66039e56a6b366848dedc6933cf772b7aad4e79b Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 14 May 2014 20:06:16 +0200 Subject: [PATCH] Added information about post space usage --- src/Controllers/StaticPagesController.php | 1 + src/Models/PostModel.php | 26 +++++++++++++++++++++++ src/Models/PropertyModel.php | 2 ++ src/Views/static-main.phtml | 6 +++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Controllers/StaticPagesController.php b/src/Controllers/StaticPagesController.php index fa68acbc..1b721264 100644 --- a/src/Controllers/StaticPagesController.php +++ b/src/Controllers/StaticPagesController.php @@ -6,6 +6,7 @@ class StaticPagesController $context = getContext(); $context->transport->postCount = PostModel::getCount(); $context->viewName = 'static-main'; + $context->transport->postSpaceUsage = PostModel::getSpaceUsage(); PostModel::featureRandomPostIfNecessary(); $featuredPost = PostModel::getFeaturedPost(); diff --git a/src/Models/PostModel.php b/src/Models/PostModel.php index d6e0dc3b..8cd50abe 100644 --- a/src/Models/PostModel.php +++ b/src/Models/PostModel.php @@ -313,6 +313,32 @@ final class PostModel extends AbstractCrudModel + public static function getSpaceUsage() + { + $unixTime = PropertyModel::get(PropertyModel::PostSpaceUsageUnixTime); + if (($unixTime !== null) and (time() - $unixTime < 24 * 60 * 60)) + return PropertyModel::get(PropertyModel::PostSpaceUsage); + + $totalBytes = 0; + $paths = [getConfig()->main->filesPath, getConfig()->main->thumbsPath]; + + foreach ($paths as $path) + { + $iterator = + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + $path, FilesystemIterator::SKIP_DOTS)); + + foreach ($iterator as $object) + $totalBytes += $object->getSize(); + } + + PropertyModel::set(PropertyModel::PostSpaceUsage, $totalBytes); + PropertyModel::set(PropertyModel::PostSpaceUsageUnixTime, time()); + + return $totalBytes; + } + public static function getFeaturedPost() { $featuredPostId = PropertyModel::get(PropertyModel::FeaturedPostId); diff --git a/src/Models/PropertyModel.php b/src/Models/PropertyModel.php index f2a62526..cf8d558b 100644 --- a/src/Models/PropertyModel.php +++ b/src/Models/PropertyModel.php @@ -8,6 +8,8 @@ final class PropertyModel implements IModel const FeaturedPostUserName = 1; const FeaturedPostUnixTime = 2; const DbVersion = 3; + const PostSpaceUsage = 4; + const PostSpaceUsageUnixTime = 5; static $allProperties; static $loaded; diff --git a/src/Views/static-main.phtml b/src/Views/static-main.phtml index 215d9ecf..5d8a5d1a 100644 --- a/src/Views/static-main.phtml +++ b/src/Views/static-main.phtml @@ -6,7 +6,11 @@ Assets::addStylesheet('static-main.css');

main->title ?>

- serving context->transport->postCount ?> posts + + context->transport->postCount, + TextHelper::useBytesUnits($this->context->transport->postSpaceUsage)) ?> +