From 456d5afec31e527240c58d9c3a83584dae701d45 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Fri, 13 Sep 2024 15:45:02 +0300 Subject: [PATCH] activane module fix --- kernel/controllers/ModuleController.php | 2 +- kernel/services/ModuleService.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index 100e42b..f5a8dd9 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -53,7 +53,7 @@ class ModuleController extends AdminController $request = new Request(); $this->moduleService->setActiveModule($request->get("slug")); - $this->cgView->render("view.php", ['data' => $this->moduleService->getModuleInfo(KERNEL_MODULES_DIR . '/' . $request->get("slug"))]); + $this->cgView->render("view.php", ['data' => $this->moduleService->getModuleInfo($this->moduleService->getModuleDir($request->get("slug")))]); } } \ No newline at end of file diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 89687cb..58a79fa 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -2,6 +2,7 @@ namespace kernel\services; +use DirectoryIterator; use kernel\helpers\Debug; use kernel\helpers\Manifest; use kernel\models\Option; @@ -51,4 +52,24 @@ class ModuleService $active_modules->save(); } + public function getModuleDir(string $slug) + { + $module_paths = Option::where("key", "module_paths")->first(); + $dirs = []; + if ($module_paths){ + $path = json_decode($module_paths->value); + foreach ($path->paths as $p){ + $dirs[] = getConst($p); + } + } + + foreach ($dirs as $dir){ + foreach (new DirectoryIterator($dir) as $fileInfo) { + if(basename($fileInfo->getPathname()) !== $slug) continue; + return $fileInfo->getPathname(); + } + } + return false; + } + } \ No newline at end of file