diff --git a/tools/image_cache.inc.php b/tools/image_cache.inc.php new file mode 100644 index 0000000..7db158f --- /dev/null +++ b/tools/image_cache.inc.php @@ -0,0 +1,88 @@ +isFile() && !$item->isLink()) + { + continue; + } + + if (strtolower($item->getFilename()) === 'index.htm') + { + continue; + } + + $path = $item->getPathname(); + $size = $item->isFile() ? $item->getSize() : 0; + + if (@unlink($path)) + { + $deleted_files++; + $deleted_bytes += $size; + } + else + { + $failed_files++; + } + } + + if ($failed_files > 0) + { + throw new RuntimeException( + sprintf('%d Dateien geloescht, %d Dateien konnten nicht geloescht werden.', $deleted_files, $failed_files) + ); + } + + return array( + 'message' => sprintf( + 'Bildcache geleert: %d Dateien (%s) entfernt.', + $deleted_files, + bratonien_tools_format_bytes($deleted_bytes) + ), + ); +} + +function bratonien_tools_format_bytes($bytes) +{ + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + $value = (float) $bytes; + $unit = 0; + + while ($value >= 1024 && $unit < count($units) - 1) + { + $value /= 1024; + $unit++; + } + + return number_format($value, $unit === 0 ? 0 : 2, ',', '.') . ' ' . $units[$unit]; +}