-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathService.php
More file actions
99 lines (81 loc) · 2.81 KB
/
Service.php
File metadata and controls
99 lines (81 loc) · 2.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace MerapiPanel\Module\Setting;
use MerapiPanel\Box;
use MerapiPanel\Box\Module\__Fragment;
use MerapiPanel\Box\Module\Entity\Module;
use MerapiPanel\Box\Module\ModuleLoader;
use MerapiPanel\Utility\AES;
use MerapiPanel\Utility\Router;
use Symfony\Component\Filesystem\Path;
class Service extends __Fragment
{
protected $module;
function onCreate(Module $module)
{
$this->module = $module;
}
function onInit()
{
$panel = Box::module('Panel');
$module_configs = [];
foreach (glob(Path::canonicalize(__DIR__ . "/..") . "/*/config.json") as $config) {
$directory = dirname($config);
if (!in_array(basename($directory), ModuleLoader::getDefaultModules()) && !file_exists(Path::join($directory, ".active"))) {
continue;
}
$module = basename($directory);
$icons = glob($directory . "/icon.{png,jpg,jpeg,svg}", GLOB_BRACE);
$module_configs[] = [
"module" => $module,
"icon" => $icons ? $icons[0] : null,
"config" => json_decode(file_get_contents($config), true)
];
$panel->addMenu([
"name" => ucfirst($module),
"link" => $_ENV['__MP_ADMIN__']['prefix'] . "/settings/config/" . strtolower($module),
"icon" => $icons ? $icons[0] : null,
"parent" => "Configuration"
]);
}
if (!empty($module_configs)) {
$panel->addMenu([
"name" => "Configuration",
"icon" => '<i class="fa-solid fa-sliders"></i>',
"parent" => "Settings",
]);
}
}
public function getTimeZones()
{
$raw = file_get_contents(__DIR__ . "/assets/timezone.json");
return json_decode($raw, true);
}
function token(string $form, $moduleName = null)
{
$form = preg_replace("/\n/im", "", $form);
$inputNames = [];
preg_match_all("/<[input|textarea|select].*?name=\"(.*?)\".*?>/i", $form, $matches);
if (isset($matches[1])) {
$inputNames = $matches[1];
}
$route = Router::getInstance()->getRoute();
if (!$route) {
return "";
}
if (empty($moduleName)) {
$contoller = $route->getController();
if (gettype($contoller) !== "string") {
return "";
}
preg_match("/Module\\\(\w+)\\\/i", $contoller, $matches);
if (isset($matches[1])) {
$moduleName = $matches[1];
} else {
return "";
}
}
$text = serialize(["module" => $moduleName, "input" => $inputNames]);
$token = AES::getInstance()->encrypt($text);
return $token;
}
}