-
Notifications
You must be signed in to change notification settings - Fork 11
/
listmods.php
57 lines (42 loc) · 1.05 KB
/
listmods.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
50
51
52
53
54
55
56
57
<?php
require_once("admin/common.php");
$modules = getmods_db();
if($modules == null){
$response = json_encode("");
echo $response;
exit;
}
$count = count($modules);
if($count == 0){
$response = json_encode("");
echo $response;
exit;
}
$absModPath = getAbsModPath();
$response = array();
foreach($modules as $module){
$absPath = $absModPath . "/" . $module['moddir'];
if(!file_exists($absPath)){
continue;
}
$moddir = $module['moddir'];
$ksize = get_dir_size($absPath);
$mod_json = array('moddir' => $moddir,
'ksize' => $ksize);
$response[$moddir] = $mod_json;
}
echo json_encode($response);
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
echo "{ \"responseText\" : \"Succesfully generated JSON\" }\n";
return;
function get_dir_size($directory){
$size = 0;
$files = glob($directory.'/*');
foreach($files as $path){
is_file($path) && $size += filesize($path);
is_dir($path) && $size += get_dir_size($path);
}
return $size;
}
?>