-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
66 lines (55 loc) · 2.55 KB
/
Module.php
File metadata and controls
66 lines (55 loc) · 2.55 KB
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
58
59
60
61
62
63
64
65
66
<?php
namespace MerapiPanel\Module\Setting;
use Exception;
use MerapiPanel\Box\Module\__Fragment;
use MerapiPanel\Box\Module\Entity\Module as EntityModule;
use MerapiPanel\Box\Module\ModuleLoader;
use Symfony\Component\Filesystem\Path;
class Module extends __Fragment
{
protected $module;
function onCreate(EntityModule $module)
{
$this->module = $module;
}
function listpops()
{
$modules = [];
foreach (glob($_ENV['__MP_APP__'] . "/Module/*", GLOB_ONLYDIR) as $directory) {
$manifest = [];
if (file_exists(Path::join($directory, "manifest.json"))) {
$manifest = json_decode(file_get_contents(Path::join($directory, "manifest.json")), 1);
}
if (isset($manifest['icon']) && !strpos($manifest['icon'], "http")) {
$manifest['icon'] = "/" . Path::makeRelative(Path::join($directory, $manifest['icon']), $_ENV["__MP_CWD__"]);
}
$modules[] = [
"location" => $directory,
"name" => basename($directory),
"manifest" => $manifest,
"active" => in_array(basename($directory), ModuleLoader::getDefaultModules()) || is_file(Path::join($directory, '.active')),
"isdefault" => in_array(basename($directory), ModuleLoader::getDefaultModules())
];
}
return $modules;
}
function getpop($module_name)
{
$directory = Path::join($_ENV['__MP_APP__'], "Module", $module_name);
if (!is_dir($directory)) throw new Exception("Module {$module_name} does't exist", 404);
$manifest = [];
if (file_exists(Path::join($directory, "manifest.json"))) {
$manifest = json_decode(file_get_contents(Path::join($directory, "manifest.json")), 1);
}
if (isset($manifest['icon']) && !strpos($manifest['icon'], "http")) {
$manifest['icon'] = "/" . Path::makeRelative(Path::join($directory, $manifest['icon']), $_ENV["__MP_CWD__"]);
}
$module["location"] = $directory;
$module["name"] = basename($directory);
$module['manifest'] = $manifest;
$module['active'] = in_array($module_name, ModuleLoader::getDefaultModules()) || is_file(Path::join($directory, '.active'));
$module['readme'] = file_exists(Path::join($directory, "README.md")) ? file_get_contents(Path::join($directory, "README.md")) : "";
$module["isdefault"] = in_array(basename($directory), ModuleLoader::getDefaultModules());
return $module;
}
}