-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
49 lines (40 loc) · 1.36 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace FreeSpace;
use Omeka\Module\AbstractModule;
use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\View\View;
class Module extends AbstractModule
{
private $cssClass = "";
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
private function formattedDiskUsage() {
$bytes = disk_free_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
$gigaBytesWarningLimit = 15;
if ((int)$bytes < ($gigaBytesWarningLimit * $base * $base * $base)) {
$this->cssClass = "freeSpaceWarning";
}
return sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class] . '';
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach(
'Omeka\Controller\Admin\Index',
'view.browse.after',
function(Event $event) {
print $event->getTarget()->partial("free-space-block",
[
"freeSpaceFormatted" => $this->formattedDiskUsage(),
"freeSpaceClass" => $this->cssClass
]
);
}
);
}
}