diff --git a/app/modules/tag/manifest.json b/app/modules/tag/manifest.json index 3159ed4..87665ad 100644 --- a/app/modules/tag/manifest.json +++ b/app/modules/tag/manifest.json @@ -1,6 +1,6 @@ { "name": "Tags", - "version": "0.3", + "version": "0.1", "author": "ITGuild", "slug": "tag", "description": "Tags module", diff --git a/composer.lock b/composer.lock index 5a69ad7..ca65c63 100644 --- a/composer.lock +++ b/composer.lock @@ -3205,5 +3205,5 @@ "ext-zip": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/kernel/admin_themes/default/layout/main.php b/kernel/admin_themes/default/layout/main.php index 704683f..5864fb1 100644 --- a/kernel/admin_themes/default/layout/main.php +++ b/kernel/admin_themes/default/layout/main.php @@ -14,7 +14,7 @@ - + diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index fab7bd3..3e2bb18 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -3,6 +3,7 @@ namespace kernel\controllers; use DirectoryIterator; +use JetBrains\PhpStorm\NoReturn; use Josantonius\Session\Facades\Session; use kernel\AdminController; use kernel\helpers\Debug; @@ -53,10 +54,6 @@ class ModuleController extends AdminController $i++; } } -// foreach (ModuleShopClientService::getModuleShopClientInfo() as $module) { -// $module->id = $i++; -// $modules_info[] = $module; -// } $module_count = count($modules_info); $modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page); @@ -106,25 +103,11 @@ class ModuleController extends AdminController $this->cgView->render("view.php", ['data' => $mod_info]); } - public function actionUpdate(): void + #[NoReturn] public function actionUpdate(): void { $request = new Request(); $slug = $request->get('slug'); - if ($this->moduleService->isKernelModule($slug)) { - $active_res = $this->moduleService->updateModule($request->get("slug")); - if (!$active_res){ - Session::start(); - Session::set("error", implode(";", $this->moduleService->getErrors())); - $this->redirect("/admin", 302); - } - $mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug')); - } else { - $this->redirect("/admin/module_shop_client/update/?slug=" . $slug, 302); - } - - - - $this->cgView->render("view.php", ['data' => $mod_info]); + $this->redirect("/admin/module_shop_client/update/?slug=" . $slug, 302); } } \ No newline at end of file diff --git a/kernel/modules/secure/controllers/SecureController.php b/kernel/modules/secure/controllers/SecureController.php index e698424..5eac006 100644 --- a/kernel/modules/secure/controllers/SecureController.php +++ b/kernel/modules/secure/controllers/SecureController.php @@ -44,9 +44,8 @@ class SecureController extends AdminController Flash::setMessage("error", "User not found."); $this->redirect("/admin/login", code: 302); } - if (password_verify($loginForm->getItem("password"), $user->password_hash)) { - setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false); + setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['HTTP_HOST'], false); $this->redirect("/admin", code: 302); } else { Flash::setMessage("error", "Username or password incorrect."); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index cc45d1a..3840192 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -189,8 +189,8 @@ class ModuleService */ public function runInitScript($mod_info): void { - if (isset($mod_info['module_class'])){ - if (isset($mod_info['module_class_file'])){ + if (isset($mod_info['module_class'])) { + if (isset($mod_info['module_class_file'])) { require_once $mod_info['module_class_file']; } $moduleClass = new $mod_info['module_class'](); @@ -204,8 +204,8 @@ class ModuleService */ public function runDeactivateScript($mod_info): void { - if (isset($mod_info['module_class'])){ - if (isset($mod_info['module_class_file'])){ + if (isset($mod_info['module_class'])) { + if (isset($mod_info['module_class_file'])) { require_once $mod_info['module_class_file']; } $moduleClass = new $mod_info['module_class'](); @@ -233,11 +233,11 @@ class ModuleService foreach ($dirs as $dir) { foreach (new DirectoryIterator($dir) as $fileInfo) { - if($fileInfo->isDot() or !in_array($fileInfo->getFilename(), $active_modules['modules'])) continue; + if ($fileInfo->isDot() or !in_array($fileInfo->getFilename(), $active_modules['modules'])) continue; $modules[] = $this->getModuleInfo($fileInfo->getPathname()); } } - + return $modules; } @@ -248,8 +248,8 @@ class ModuleService { $routs = []; $modules = $this->getActiveModules(); - foreach ($modules as $module){ - if (isset($module['routs'])){ + foreach ($modules as $module) { + if (isset($module['routs'])) { $routs[] = $module['path'] . "/" . $module['routs']; } } @@ -264,8 +264,8 @@ class ModuleService { $migrationsPaths = []; $modules = $this->getActiveModules(); - foreach ($modules as $module){ - if (isset($module['migration_path'])){ + foreach ($modules as $module) { + if (isset($module['migration_path'])) { $migrationsPaths[] = $module['path'] . "/" . $module['migration_path']; } } @@ -326,7 +326,7 @@ class ModuleService $fileHelper = new Files(); if (file_exists(APP_DIR . '/modules/' . $moduleInfo['slug'])) { - $fileHelper->recursiveRemoveDir(APP_DIR . '/modules/'. $moduleInfo['slug']); + $fileHelper->recursiveRemoveDir(APP_DIR . '/modules/' . $moduleInfo['slug']); } if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug'])) { $fileHelper->recursiveRemoveDir(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug']); @@ -345,10 +345,9 @@ class ModuleService $fileHelper = new Files(); $fileHelper->copy_folder(ROOT_DIR . $path, $tmpModuleDirFull . 'app/'); - if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)){ + if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)) { $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/'); - } - else { + } else { mkdir($tmpModuleDirFull . 'kernel/'); } @@ -419,15 +418,15 @@ class ModuleService { $module_paths = Option::where("key", "module_paths")->first(); $dirs = []; - if ($module_paths){ + if ($module_paths) { $path = json_decode($module_paths->value); - foreach ($path->paths as $p){ + foreach ($path->paths as $p) { $dirs[] = getConst($p); } } - foreach ($dirs as $dir){ + foreach ($dirs as $dir) { foreach (new DirectoryIterator($dir) as $fileInfo) { - if($fileInfo->isDot()) continue; + if ($fileInfo->isDot()) continue; if ($this->getModuleInfo($fileInfo->getPathname())['slug'] === $slug) { return true; }; @@ -454,17 +453,25 @@ class ModuleService public function isKernelModule(string $slug): bool { - $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - - $modules_info = json_decode($modules_info->getBody()->getContents(), true); - $mod_info = $this->getModuleInfoBySlug($slug); + $modules_info = $this->getKernelModules(); foreach ($modules_info as $mod) { - if ($mod['slug'] === $mod_info['slug']) { - return false; + if ($mod['slug'] === $slug) { + return true; } } - return true; + return false; + } + + public function getKernelModules(): array + { + $modules_info = []; + foreach (new DirectoryIterator(KERNEL_MODULES_DIR) as $fileInfo) { + if ($fileInfo->isDot()) continue; + $modules_info[] = $this->getModuleInfo($fileInfo->getPathname()); + } + + return $modules_info; } } \ No newline at end of file diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php index 3cbf641..aeee0ad 100644 --- a/kernel/views/module/index.php +++ b/kernel/views/module/index.php @@ -34,9 +34,9 @@ $table->addAction(function ($row, $url) use ($moduleService) { $btn = "$label"; } else { - $label = "Активировать"; + $label = ""; $btn_type = "success"; - $btn = "$label"; + $btn = "$label"; } return $btn; @@ -60,7 +60,7 @@ $table->addAction(function ($row, $url) use ($moduleService){ return false; }); -$table->addAction(function ($row, $url) use ($moduleService){ +$table->addAction(function ($row) use ($moduleService){ $slug = $row['slug']; if (!$moduleService->isKernelModule($slug)){ $label = "Удалить"; @@ -69,7 +69,6 @@ $table->addAction(function ($row, $url) use ($moduleService){ } return false; }); - $table->create(); if ($moduleService->isActive('module_shop_client')) { diff --git a/kernel/views/widgets/admin/action_button.php b/kernel/views/widgets/admin/action_button.php new file mode 100644 index 0000000..32dee23 --- /dev/null +++ b/kernel/views/widgets/admin/action_button.php @@ -0,0 +1,9 @@ + + +"$icon"; \ No newline at end of file diff --git a/kernel/views/widgets/admin/menu.php b/kernel/views/widgets/admin/menu.php new file mode 100644 index 0000000..124c239 --- /dev/null +++ b/kernel/views/widgets/admin/menu.php @@ -0,0 +1,28 @@ + + \ No newline at end of file diff --git a/kernel/views/widgets/admin/module_tabs.php b/kernel/views/widgets/admin/module_tabs.php new file mode 100644 index 0000000..ac618d2 --- /dev/null +++ b/kernel/views/widgets/admin/module_tabs.php @@ -0,0 +1,14 @@ + + + +
\ No newline at end of file diff --git a/kernel/widgets/ActionButtonWidget.php b/kernel/widgets/ActionButtonWidget.php new file mode 100644 index 0000000..adea90f --- /dev/null +++ b/kernel/widgets/ActionButtonWidget.php @@ -0,0 +1,16 @@ +data['icon']; + $btn = $this->data['btn']; + $url = $this->data['url']; + $this->cgView->render('/admin/action_button.php', ['icon' => $icon, 'btn' => $btn, 'url' => $url]); + } +} \ No newline at end of file diff --git a/views/widgets/admin/action_button.php b/views/widgets/admin/action_button.php index f04355c..edd9968 100644 --- a/views/widgets/admin/action_button.php +++ b/views/widgets/admin/action_button.php @@ -6,4 +6,4 @@ */ ?> -"$label"; \ No newline at end of file +"$label";