Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added `Folder->size` to the `Folder` class (see #3903)

  • Loading branch information...
commit 8b3b0ddfb9b9ec86157c43621a0f33f9ef0279f1 1 parent 0fdaee8
@leofeyer leofeyer authored
Showing with 37 additions and 0 deletions.
  1. +3 −0  system/docs/CHANGELOG.md
  2. +34 −0 system/library/Contao/Folder.php
View
3  system/docs/CHANGELOG.md
@@ -4,6 +4,9 @@ Contao Open Source CMS Changelog
Version 3.0.beta1 (XXXX-XX-XX)
------------------------------
+### New
+Added `Folder->size` to the `Folder` class (see #3903).
+
### Improved
Added better page titles in the back end (see #3980).
View
34 system/library/Contao/Folder.php
@@ -111,6 +111,10 @@ public function __get($strKey)
Cache::set($strCacheKey, $this->strFolder);
break;
+ case 'size':
+ Cache::set($strCacheKey, $this->getSize());
+ break;
+
default:
return parent::__get($strKey);
break;
@@ -251,4 +255,34 @@ protected function getHash()
return md5(implode('-', $arrFiles));
}
+
+ /**
+ * Return the size of the folder
+ * @return integer
+ */
+ protected function getSize()
+ {
+ $intSize = 0;
+
+ foreach (scan(TL_ROOT . '/' . $this->strFolder) as $strFile)
+ {
+ if ($strFile == '.svn' || $strFile == '.DS_Store')
+ {
+ continue;
+ }
+
+ if (is_dir(TL_ROOT . '/' . $this->strFolder . '/' . $strFile))
+ {
+ $objFolder = new Folder($this->strFolder . '/' . $strFile);
+ $intSize += $objFolder->size;
+ }
+ else
+ {
+ $objFile = new File($this->strFolder . '/' . $strFile);
+ $intSize += $objFile->size;
+ }
+ }
+
+ return $intSize;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.