From de690dfd3923aead6fb11da354e5172be53e29bc Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Mon, 23 Dec 2024 14:14:59 +0300 Subject: [PATCH] admin theme pack --- app/admin_themes/custom/layout/main.php | 0 app/admin_themes/custom/manifest.json | 1 + .../controllers/AdminThemeController.php | 66 +++++------ kernel/console/routs/cli.php | 4 + kernel/filters/CustomSelectFilter.php | 23 ++++ .../module_shop_client/views/index.php | 29 ++--- kernel/services/AdminThemeService.php | 111 +++++++++++++++++- kernel/services/ModuleService.php | 8 +- resources/custom/css/bootstrap.min.css | 0 resources/custom/css/bootstrap/_media.css | 0 .../css/bootstrap/mixins/_border-radius.css | 0 .../css/bootstrap/mixins/_screen-reader.css | 0 .../css/bootstrap/mixins/_visibility.css | 0 .../bootstrap/utilities/_stretched-link.css | 0 resources/custom/css/style.css | 0 resources/custom/images/bg_1.jpg | Bin resources/custom/images/logo.jpg | Bin resources/custom/js/bootstrap.min.js | 0 resources/custom/js/jquery.min.js | 0 resources/custom/js/main.js | 0 resources/custom/js/popper.js | 0 resources/custom/nrnv2024_640x360.jpg | Bin resources/custom/scss/bootstrap/_alert.scss | 0 resources/custom/scss/bootstrap/_badge.scss | 0 .../custom/scss/bootstrap/_breadcrumb.scss | 0 .../custom/scss/bootstrap/_button-group.scss | 0 resources/custom/scss/bootstrap/_buttons.scss | 0 resources/custom/scss/bootstrap/_card.scss | 0 .../custom/scss/bootstrap/_carousel.scss | 0 resources/custom/scss/bootstrap/_close.scss | 0 resources/custom/scss/bootstrap/_code.scss | 0 .../custom/scss/bootstrap/_custom-forms.scss | 0 .../custom/scss/bootstrap/_dropdown.scss | 0 resources/custom/scss/bootstrap/_forms.scss | 0 .../custom/scss/bootstrap/_functions.scss | 0 resources/custom/scss/bootstrap/_grid.scss | 0 resources/custom/scss/bootstrap/_images.scss | 0 .../custom/scss/bootstrap/_input-group.scss | 0 .../custom/scss/bootstrap/_jumbotron.scss | 0 .../custom/scss/bootstrap/_list-group.scss | 0 resources/custom/scss/bootstrap/_media.scss | 0 resources/custom/scss/bootstrap/_mixins.scss | 0 resources/custom/scss/bootstrap/_modal.scss | 0 resources/custom/scss/bootstrap/_nav.scss | 0 resources/custom/scss/bootstrap/_navbar.scss | 0 .../custom/scss/bootstrap/_pagination.scss | 0 resources/custom/scss/bootstrap/_popover.scss | 0 resources/custom/scss/bootstrap/_print.scss | 0 .../custom/scss/bootstrap/_progress.scss | 0 resources/custom/scss/bootstrap/_reboot.scss | 0 resources/custom/scss/bootstrap/_root.scss | 0 .../custom/scss/bootstrap/_spinners.scss | 0 resources/custom/scss/bootstrap/_tables.scss | 0 resources/custom/scss/bootstrap/_toasts.scss | 0 resources/custom/scss/bootstrap/_tooltip.scss | 0 .../custom/scss/bootstrap/_transitions.scss | 0 resources/custom/scss/bootstrap/_type.scss | 0 .../custom/scss/bootstrap/_utilities.scss | 0 .../custom/scss/bootstrap/_variables.scss | 0 .../custom/scss/bootstrap/bootstrap-grid.scss | 0 .../scss/bootstrap/bootstrap-reboot.scss | 0 .../custom/scss/bootstrap/bootstrap.scss | 0 .../custom/scss/bootstrap/mixins/_alert.scss | 0 .../bootstrap/mixins/_background-variant.scss | 0 .../custom/scss/bootstrap/mixins/_badge.scss | 0 .../scss/bootstrap/mixins/_border-radius.scss | 0 .../scss/bootstrap/mixins/_box-shadow.scss | 0 .../scss/bootstrap/mixins/_breakpoints.scss | 0 .../scss/bootstrap/mixins/_buttons.scss | 0 .../custom/scss/bootstrap/mixins/_caret.scss | 0 .../scss/bootstrap/mixins/_clearfix.scss | 0 .../scss/bootstrap/mixins/_deprecate.scss | 0 .../custom/scss/bootstrap/mixins/_float.scss | 0 .../custom/scss/bootstrap/mixins/_forms.scss | 0 .../scss/bootstrap/mixins/_gradients.scss | 0 .../bootstrap/mixins/_grid-framework.scss | 0 .../custom/scss/bootstrap/mixins/_grid.scss | 0 .../custom/scss/bootstrap/mixins/_hover.scss | 0 .../custom/scss/bootstrap/mixins/_image.scss | 0 .../scss/bootstrap/mixins/_list-group.scss | 0 .../custom/scss/bootstrap/mixins/_lists.scss | 0 .../scss/bootstrap/mixins/_nav-divider.scss | 0 .../scss/bootstrap/mixins/_pagination.scss | 0 .../scss/bootstrap/mixins/_reset-text.scss | 0 .../custom/scss/bootstrap/mixins/_resize.scss | 0 .../scss/bootstrap/mixins/_screen-reader.scss | 0 .../custom/scss/bootstrap/mixins/_size.scss | 0 .../scss/bootstrap/mixins/_table-row.scss | 0 .../scss/bootstrap/mixins/_text-emphasis.scss | 0 .../scss/bootstrap/mixins/_text-hide.scss | 0 .../scss/bootstrap/mixins/_text-truncate.scss | 0 .../scss/bootstrap/mixins/_transition.scss | 0 .../scss/bootstrap/mixins/_visibility.scss | 0 .../scss/bootstrap/utilities/_align.scss | 0 .../scss/bootstrap/utilities/_background.scss | 0 .../scss/bootstrap/utilities/_borders.scss | 0 .../scss/bootstrap/utilities/_clearfix.scss | 0 .../scss/bootstrap/utilities/_display.scss | 0 .../scss/bootstrap/utilities/_embed.scss | 0 .../scss/bootstrap/utilities/_flex.scss | 0 .../scss/bootstrap/utilities/_float.scss | 0 .../scss/bootstrap/utilities/_overflow.scss | 0 .../scss/bootstrap/utilities/_position.scss | 0 .../bootstrap/utilities/_screenreaders.scss | 0 .../scss/bootstrap/utilities/_shadows.scss | 0 .../scss/bootstrap/utilities/_sizing.scss | 0 .../scss/bootstrap/utilities/_spacing.scss | 0 .../bootstrap/utilities/_stretched-link.scss | 0 .../scss/bootstrap/utilities/_text.scss | 0 .../scss/bootstrap/utilities/_visibility.scss | 0 resources/custom/scss/style.scss | 0 111 files changed, 187 insertions(+), 55 deletions(-) mode change 100644 => 100755 app/admin_themes/custom/layout/main.php mode change 100644 => 100755 app/admin_themes/custom/manifest.json create mode 100644 kernel/filters/CustomSelectFilter.php mode change 100644 => 100755 resources/custom/css/bootstrap.min.css mode change 100644 => 100755 resources/custom/css/bootstrap/_media.css mode change 100644 => 100755 resources/custom/css/bootstrap/mixins/_border-radius.css mode change 100644 => 100755 resources/custom/css/bootstrap/mixins/_screen-reader.css mode change 100644 => 100755 resources/custom/css/bootstrap/mixins/_visibility.css mode change 100644 => 100755 resources/custom/css/bootstrap/utilities/_stretched-link.css mode change 100644 => 100755 resources/custom/css/style.css mode change 100644 => 100755 resources/custom/images/bg_1.jpg mode change 100644 => 100755 resources/custom/images/logo.jpg mode change 100644 => 100755 resources/custom/js/bootstrap.min.js mode change 100644 => 100755 resources/custom/js/jquery.min.js mode change 100644 => 100755 resources/custom/js/main.js mode change 100644 => 100755 resources/custom/js/popper.js mode change 100644 => 100755 resources/custom/nrnv2024_640x360.jpg mode change 100644 => 100755 resources/custom/scss/bootstrap/_alert.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_badge.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_breadcrumb.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_button-group.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_buttons.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_card.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_carousel.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_close.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_code.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_custom-forms.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_dropdown.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_forms.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_functions.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_grid.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_images.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_input-group.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_jumbotron.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_list-group.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_media.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_mixins.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_modal.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_nav.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_navbar.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_pagination.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_popover.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_print.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_progress.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_reboot.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_root.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_spinners.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_tables.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_toasts.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_tooltip.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_transitions.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_type.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_utilities.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/_variables.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/bootstrap-grid.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/bootstrap-reboot.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/bootstrap.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_alert.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_background-variant.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_badge.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_border-radius.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_box-shadow.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_breakpoints.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_buttons.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_caret.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_clearfix.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_deprecate.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_float.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_forms.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_gradients.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_grid-framework.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_grid.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_hover.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_image.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_list-group.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_lists.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_nav-divider.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_pagination.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_reset-text.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_resize.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_screen-reader.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_size.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_table-row.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_text-emphasis.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_text-hide.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_text-truncate.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_transition.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/mixins/_visibility.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_align.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_background.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_borders.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_clearfix.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_display.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_embed.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_flex.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_float.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_overflow.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_position.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_screenreaders.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_shadows.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_sizing.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_spacing.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_stretched-link.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_text.scss mode change 100644 => 100755 resources/custom/scss/bootstrap/utilities/_visibility.scss mode change 100644 => 100755 resources/custom/scss/style.scss diff --git a/app/admin_themes/custom/layout/main.php b/app/admin_themes/custom/layout/main.php old mode 100644 new mode 100755 diff --git a/app/admin_themes/custom/manifest.json b/app/admin_themes/custom/manifest.json old mode 100644 new mode 100755 index ab256cb..5420071 --- a/app/admin_themes/custom/manifest.json +++ b/app/admin_themes/custom/manifest.json @@ -3,6 +3,7 @@ "version": "0.1", "author": "Kavalar", "slug": "custom", + "type": "admin_theme", "description": "Custom admin theme", "preview": "nrnv2024_640x360.jpg", "resource": "/resources/custom", diff --git a/kernel/console/controllers/AdminThemeController.php b/kernel/console/controllers/AdminThemeController.php index 2fc1739..d33d44b 100644 --- a/kernel/console/controllers/AdminThemeController.php +++ b/kernel/console/controllers/AdminThemeController.php @@ -18,31 +18,15 @@ class AdminThemeController extends ConsoleController throw new \Exception('Missing admin theme path "--path" specified'); } - $zip = new ZipArchive; - $tmpThemeDir = md5(time()); - $res = $zip->open(ROOT_DIR . $this->argv['path']); - if ($res === TRUE) { - $tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/"; - $zip->extractTo($tmpThemeDirFull); - $zip->close(); - $this->out->r('Архив распакован', 'green'); + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $adminThemeService = new AdminThemeService(); + if ($adminThemeService->install($this->argv['path'])) { + $this->out->r("Тема админ-панели установлена", 'green'); + } else { + $this->out->r("Ошибка установки темы админ-панели", 'red'); + } } else { - $this->out->r('Message: Ошибка чтения архива', 'red'); - } - - if (file_exists($tmpThemeDirFull . "meta/manifest.json")){ - $manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json")); - $manifest = Manifest::getWithVars($manifestJson); - $this->out->r('manifest.json инициализирован', 'green'); - - $fileHelper = new Files(); - $fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']); - $fileHelper->copy_folder($tmpThemeDirFull . "resources", $manifest['resource_path']); - - $this->out->r("Удаляем временные файлы", 'green'); - $fileHelper->recursiveRemoveDir($tmpThemeDirFull); - - $this->out->r("Тема " . $manifest['name'] . " установлена", 'green'); + $this->out->r("Тема админ-панели не найдена", 'red'); } } @@ -53,17 +37,11 @@ class AdminThemeController extends ConsoleController } if (file_exists(ROOT_DIR . $this->argv['path'])) { - $themeName = basename($this->argv['path']); - $active_admin_theme = Option::where("key", "active_admin_theme")->first(); - if ($active_admin_theme->value === ROOT_DIR . $this->argv['path']) { - $this->out->r("Меняем тему на базовую", 'green'); - $adminThemeService = new AdminThemeService(); - $adminThemeService->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default'); - $this->out->r("Тема изменена", 'green'); - } - $fileHelper = new Files(); - $fileHelper->recursiveRemoveDir(ROOT_DIR . $this->argv['path']); - $fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeName); + $adminThemeService = new AdminThemeService(); + $adminThemeService->uninstall($this->argv['path']); + + + $this->out->r("Тема удалена", 'green'); } else { @@ -71,4 +49,22 @@ class AdminThemeController extends ConsoleController } } + /** + * @throws \Exception + */ + public function actionPackTheme(): void + { + if (!isset($this->argv['path'])) { + throw new \Exception('Missing admin theme path "--path" specified'); + } + + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $adminThemeService = new AdminThemeService(); + $adminThemeService->pack($this->argv['path']); + $this->out->r("Тема админ-панели заархивирована", 'green'); + } else { + $this->out->r("Тема админ-панели не найдена", 'red'); + } + } + } \ No newline at end of file diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php index d0f1032..4676cc7 100644 --- a/kernel/console/routs/cli.php +++ b/kernel/console/routs/cli.php @@ -35,6 +35,10 @@ App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCol [\kernel\console\controllers\AdminThemeController::class, 'actionUninstallTheme'], additionalInfo: ['description' => 'Удалить тему админ-панели', 'params' => ['--path' => 'Путь к удаляемой теме']] ); + App::$collector->console('pack', + [\kernel\console\controllers\AdminThemeController::class, 'actionPackTheme'], + additionalInfo: ['description' => 'Заархивировать тему админ-панели', 'params' => ['--path' => 'Путь к теме, которую нужно заархивировать']] + ); }); App::$collector->group(["prefix" => "secure"], callback: function (RouteCollector $router){ diff --git a/kernel/filters/CustomSelectFilter.php b/kernel/filters/CustomSelectFilter.php new file mode 100644 index 0000000..7a866ad --- /dev/null +++ b/kernel/filters/CustomSelectFilter.php @@ -0,0 +1,23 @@ +html = ""; + return $this->html; + } +} \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/index.php b/kernel/modules/module_shop_client/views/index.php index 930793c..0f9419b 100644 --- a/kernel/modules/module_shop_client/views/index.php +++ b/kernel/modules/module_shop_client/views/index.php @@ -42,15 +42,15 @@ $table->addAction(function ($row, $url) use ($moduleService) { $table->columns([ 'type' => [ 'filter' => [ - 'class' => \Itguild\Tables\Filter\SelectFilter::class, + 'class' => \kernel\filters\CustomSelectFilter::class, 'param' => ['kernel', 'entity'], 'value' => "kernel" ], ] ]); -$table->addAction(function ($row, $url) use ($moduleService){ - if ($row['slug'] !== 'kernel') { +$table->addAction(function ($row, $url) use ($moduleService) { + if ($row['type'] === 'entity' || $row['type'] === 'additional_property') { if ($moduleService->isInstall($row['slug'])) { $url = "$url/delete/?slug=" . $row['slug']; @@ -61,16 +61,19 @@ $table->addAction(function ($row, $url) use ($moduleService){ return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run(); } } - return null; + + return false; }); $table->addAction(function ($row, $url) use ($moduleService) { - $slug = $row['slug']; - if ($moduleService->isInstall($slug)) { - if (!$moduleService->isLastVersion($slug)) { - $url = "$url/update/?slug=" . $slug; + if ($row['type'] === 'entity' || $row['type'] === 'additional_property') { + $slug = $row['slug']; + if ($moduleService->isInstall($slug)) { + if (!$moduleService->isLastVersion($slug)) { + $url = "$url/update/?slug=" . $slug; - return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); + return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); + } } } @@ -78,8 +81,7 @@ $table->addAction(function ($row, $url) use ($moduleService) { }); $table->addAction(function ($row, $url) use ($kernelService) { - $slug = $row['slug']; - if ($slug === 'kernel') { + if ($row['type'] === 'kernel') { if (!$kernelService->isLastVersion()) { $url = "$url/kernel/update_form/"; @@ -91,9 +93,8 @@ $table->addAction(function ($row, $url) use ($kernelService) { }); $table->addAction(function ($row, $url) use ($adminThemeService) { - $type = $row['type']; - $slug = $row['slug']; - if ($type === 'admin_theme') { + if ($row['type'] === 'admin_theme') { + $slug = $row['slug']; if ($adminThemeService->isInstall($slug)) { if (!$adminThemeService->isLastVersion($slug)) { $url = "$url/admin_theme/update/"; diff --git a/kernel/services/AdminThemeService.php b/kernel/services/AdminThemeService.php index 457fa02..a0816f0 100644 --- a/kernel/services/AdminThemeService.php +++ b/kernel/services/AdminThemeService.php @@ -4,12 +4,16 @@ namespace kernel\services; use DirectoryIterator; use kernel\helpers\Debug; +use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\helpers\RESTClient; use kernel\models\Option; +use ZipArchive; class AdminThemeService { + protected array $errors = []; + protected Option $option; protected string $active_theme; protected ModuleService $moduleService; @@ -22,6 +26,24 @@ class AdminThemeService $this->moduleService = new ModuleService(); } + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * @param $msg + * @return void + */ + public function addError($msg): void + { + $this->errors[] = $msg; + } + + public function findActiveAdminTheme(): void { $model = Option::where("key", "active_admin_theme")->first(); @@ -50,7 +72,7 @@ class AdminThemeService $info = []; $theme = getConst($theme); $info['path'] = $theme; - if (file_exists($theme . "/manifest.json")){ + if (file_exists($theme . "/manifest.json")) { $manifest = file_get_contents($theme . "/manifest.json"); $manifest = Manifest::getWithVars($manifest); $manifest['preview'] = $manifest['resource'] . "/" . $manifest['preview']; @@ -60,6 +82,11 @@ class AdminThemeService return $info; } + public function getAdminThemeInfoBySlug(string $slug) + { + // TODO + } + public function isInstall(string $slug): bool { $adminThemePaths = Option::where("key", "admin_theme_paths")->first(); @@ -85,12 +112,13 @@ class AdminThemeService public function isLastVersion(string $slug): bool { if ($this->moduleService->isServerAvailable()) { - $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + $modulesInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - $modules_info = json_decode($modules_info->getBody()->getContents(), true); + $modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true); $themeInfo = $this->getAdminThemeInfo($slug); - foreach ($modules_info as $mod) { + Debug::dd($themeInfo); + foreach ($modulesInfo as $mod) { if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) { return true; } @@ -99,4 +127,79 @@ class AdminThemeService return false; } + + public function pack(string $path): void + { + $themeName = basename($path); + + $tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $themeName . "/"; + + $fileHelper = new Files(); + $fileHelper->copy_folder(ROOT_DIR . $path, $tmpThemeDirFull . 'meta/'); + $fileHelper->copy_folder(RESOURCES_DIR . '/' . $themeName, $tmpThemeDirFull . 'resources/'); + + if (!is_dir(RESOURCES_DIR . '/tmp/admin_themes')) { + $old_mask = umask(0); + mkdir(RESOURCES_DIR . '/tmp/admin_themes', 0775, true); + umask($old_mask); + } + $fileHelper->pack($tmpThemeDirFull, RESOURCES_DIR . '/tmp/admin_themes/' . $themeName . '.igt'); + } + + public function install(string $path): bool + { + $zip = new ZipArchive; + $tmpThemeDir = md5(time()); + $res = $zip->open(ROOT_DIR . $path); + if ($res === TRUE) { + $tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/"; + $zip->extractTo($tmpThemeDirFull); + $zip->close(); + } else { + $this->addError('unable to open zip archive'); + return false; + } + + if (!file_exists($tmpThemeDirFull . "meta/manifest.json")){ + $this->addError('manifest.json not found'); + return false; + } + + $manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json")); + $manifest = Manifest::getWithVars($manifestJson); + + $fileHelper = new Files(); + if (isset($manifest['theme_path'])) { + $fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']); + } else { + $fileHelper->copy_folder($tmpThemeDirFull . "meta", APP_DIR . '/admin_themes/' . $manifest['slug']); + } + + if (isset($manifest['resource_path'])) { + $fileHelper->copy_folder($tmpThemeDirFull . "resources", $manifest['resource_path']); + } else { + $fileHelper->copy_folder($tmpThemeDirFull . "resources", RESOURCES_DIR . '/' . $manifest['slug']); + } + + $fileHelper->recursiveRemoveDir($tmpThemeDirFull); + unlink(ROOT_DIR . $path); + return true; + } + + public function uninstall(string $path): void + { + $themeInfo = $this->getAdminThemeInfo(APP_DIR . '/admin_themes/' . basename($path)); + + $active_admin_theme = Option::where("key", "active_admin_theme")->first(); + if ($active_admin_theme->value === ROOT_DIR . $path) { + $this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default'); + } + $fileHelper = new Files(); + if (file_exists(ROOT_DIR . $path)) { + $fileHelper->recursiveRemoveDir(ROOT_DIR . $path); + } + if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) { + $fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']); + } + } } \ No newline at end of file diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 56ca7be..2a0eb69 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -362,11 +362,15 @@ class ModuleService if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)) { $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/'); } else { - mkdir($tmpModuleDirFull . 'kernel/'); + $old_mask = umask(0); + mkdir($tmpModuleDirFull . 'kernel/', 0775, true); + umask($old_mask); } if (!is_dir(RESOURCES_DIR . '/tmp/modules')) { - mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true); + $old_mask = umask(0); + mkdir(RESOURCES_DIR . '/tmp/modules', 0775, true); + umask($old_mask); } $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm'); } diff --git a/resources/custom/css/bootstrap.min.css b/resources/custom/css/bootstrap.min.css old mode 100644 new mode 100755 diff --git a/resources/custom/css/bootstrap/_media.css b/resources/custom/css/bootstrap/_media.css old mode 100644 new mode 100755 diff --git a/resources/custom/css/bootstrap/mixins/_border-radius.css b/resources/custom/css/bootstrap/mixins/_border-radius.css old mode 100644 new mode 100755 diff --git a/resources/custom/css/bootstrap/mixins/_screen-reader.css b/resources/custom/css/bootstrap/mixins/_screen-reader.css old mode 100644 new mode 100755 diff --git a/resources/custom/css/bootstrap/mixins/_visibility.css b/resources/custom/css/bootstrap/mixins/_visibility.css old mode 100644 new mode 100755 diff --git a/resources/custom/css/bootstrap/utilities/_stretched-link.css b/resources/custom/css/bootstrap/utilities/_stretched-link.css old mode 100644 new mode 100755 diff --git a/resources/custom/css/style.css b/resources/custom/css/style.css old mode 100644 new mode 100755 diff --git a/resources/custom/images/bg_1.jpg b/resources/custom/images/bg_1.jpg old mode 100644 new mode 100755 diff --git a/resources/custom/images/logo.jpg b/resources/custom/images/logo.jpg old mode 100644 new mode 100755 diff --git a/resources/custom/js/bootstrap.min.js b/resources/custom/js/bootstrap.min.js old mode 100644 new mode 100755 diff --git a/resources/custom/js/jquery.min.js b/resources/custom/js/jquery.min.js old mode 100644 new mode 100755 diff --git a/resources/custom/js/main.js b/resources/custom/js/main.js old mode 100644 new mode 100755 diff --git a/resources/custom/js/popper.js b/resources/custom/js/popper.js old mode 100644 new mode 100755 diff --git a/resources/custom/nrnv2024_640x360.jpg b/resources/custom/nrnv2024_640x360.jpg old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_alert.scss b/resources/custom/scss/bootstrap/_alert.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_badge.scss b/resources/custom/scss/bootstrap/_badge.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_breadcrumb.scss b/resources/custom/scss/bootstrap/_breadcrumb.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_button-group.scss b/resources/custom/scss/bootstrap/_button-group.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_buttons.scss b/resources/custom/scss/bootstrap/_buttons.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_card.scss b/resources/custom/scss/bootstrap/_card.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_carousel.scss b/resources/custom/scss/bootstrap/_carousel.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_close.scss b/resources/custom/scss/bootstrap/_close.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_code.scss b/resources/custom/scss/bootstrap/_code.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_custom-forms.scss b/resources/custom/scss/bootstrap/_custom-forms.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_dropdown.scss b/resources/custom/scss/bootstrap/_dropdown.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_forms.scss b/resources/custom/scss/bootstrap/_forms.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_functions.scss b/resources/custom/scss/bootstrap/_functions.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_grid.scss b/resources/custom/scss/bootstrap/_grid.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_images.scss b/resources/custom/scss/bootstrap/_images.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_input-group.scss b/resources/custom/scss/bootstrap/_input-group.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_jumbotron.scss b/resources/custom/scss/bootstrap/_jumbotron.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_list-group.scss b/resources/custom/scss/bootstrap/_list-group.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_media.scss b/resources/custom/scss/bootstrap/_media.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_mixins.scss b/resources/custom/scss/bootstrap/_mixins.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_modal.scss b/resources/custom/scss/bootstrap/_modal.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_nav.scss b/resources/custom/scss/bootstrap/_nav.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_navbar.scss b/resources/custom/scss/bootstrap/_navbar.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_pagination.scss b/resources/custom/scss/bootstrap/_pagination.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_popover.scss b/resources/custom/scss/bootstrap/_popover.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_print.scss b/resources/custom/scss/bootstrap/_print.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_progress.scss b/resources/custom/scss/bootstrap/_progress.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_reboot.scss b/resources/custom/scss/bootstrap/_reboot.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_root.scss b/resources/custom/scss/bootstrap/_root.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_spinners.scss b/resources/custom/scss/bootstrap/_spinners.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_tables.scss b/resources/custom/scss/bootstrap/_tables.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_toasts.scss b/resources/custom/scss/bootstrap/_toasts.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_tooltip.scss b/resources/custom/scss/bootstrap/_tooltip.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_transitions.scss b/resources/custom/scss/bootstrap/_transitions.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_type.scss b/resources/custom/scss/bootstrap/_type.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_utilities.scss b/resources/custom/scss/bootstrap/_utilities.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/_variables.scss b/resources/custom/scss/bootstrap/_variables.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/bootstrap-grid.scss b/resources/custom/scss/bootstrap/bootstrap-grid.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/bootstrap-reboot.scss b/resources/custom/scss/bootstrap/bootstrap-reboot.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/bootstrap.scss b/resources/custom/scss/bootstrap/bootstrap.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_alert.scss b/resources/custom/scss/bootstrap/mixins/_alert.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_background-variant.scss b/resources/custom/scss/bootstrap/mixins/_background-variant.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_badge.scss b/resources/custom/scss/bootstrap/mixins/_badge.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_border-radius.scss b/resources/custom/scss/bootstrap/mixins/_border-radius.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_box-shadow.scss b/resources/custom/scss/bootstrap/mixins/_box-shadow.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_breakpoints.scss b/resources/custom/scss/bootstrap/mixins/_breakpoints.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_buttons.scss b/resources/custom/scss/bootstrap/mixins/_buttons.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_caret.scss b/resources/custom/scss/bootstrap/mixins/_caret.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_clearfix.scss b/resources/custom/scss/bootstrap/mixins/_clearfix.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_deprecate.scss b/resources/custom/scss/bootstrap/mixins/_deprecate.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_float.scss b/resources/custom/scss/bootstrap/mixins/_float.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_forms.scss b/resources/custom/scss/bootstrap/mixins/_forms.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_gradients.scss b/resources/custom/scss/bootstrap/mixins/_gradients.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_grid-framework.scss b/resources/custom/scss/bootstrap/mixins/_grid-framework.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_grid.scss b/resources/custom/scss/bootstrap/mixins/_grid.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_hover.scss b/resources/custom/scss/bootstrap/mixins/_hover.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_image.scss b/resources/custom/scss/bootstrap/mixins/_image.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_list-group.scss b/resources/custom/scss/bootstrap/mixins/_list-group.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_lists.scss b/resources/custom/scss/bootstrap/mixins/_lists.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_nav-divider.scss b/resources/custom/scss/bootstrap/mixins/_nav-divider.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_pagination.scss b/resources/custom/scss/bootstrap/mixins/_pagination.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_reset-text.scss b/resources/custom/scss/bootstrap/mixins/_reset-text.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_resize.scss b/resources/custom/scss/bootstrap/mixins/_resize.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_screen-reader.scss b/resources/custom/scss/bootstrap/mixins/_screen-reader.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_size.scss b/resources/custom/scss/bootstrap/mixins/_size.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_table-row.scss b/resources/custom/scss/bootstrap/mixins/_table-row.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_text-emphasis.scss b/resources/custom/scss/bootstrap/mixins/_text-emphasis.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_text-hide.scss b/resources/custom/scss/bootstrap/mixins/_text-hide.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_text-truncate.scss b/resources/custom/scss/bootstrap/mixins/_text-truncate.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_transition.scss b/resources/custom/scss/bootstrap/mixins/_transition.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/mixins/_visibility.scss b/resources/custom/scss/bootstrap/mixins/_visibility.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_align.scss b/resources/custom/scss/bootstrap/utilities/_align.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_background.scss b/resources/custom/scss/bootstrap/utilities/_background.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_borders.scss b/resources/custom/scss/bootstrap/utilities/_borders.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_clearfix.scss b/resources/custom/scss/bootstrap/utilities/_clearfix.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_display.scss b/resources/custom/scss/bootstrap/utilities/_display.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_embed.scss b/resources/custom/scss/bootstrap/utilities/_embed.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_flex.scss b/resources/custom/scss/bootstrap/utilities/_flex.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_float.scss b/resources/custom/scss/bootstrap/utilities/_float.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_overflow.scss b/resources/custom/scss/bootstrap/utilities/_overflow.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_position.scss b/resources/custom/scss/bootstrap/utilities/_position.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_screenreaders.scss b/resources/custom/scss/bootstrap/utilities/_screenreaders.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_shadows.scss b/resources/custom/scss/bootstrap/utilities/_shadows.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_sizing.scss b/resources/custom/scss/bootstrap/utilities/_sizing.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_spacing.scss b/resources/custom/scss/bootstrap/utilities/_spacing.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_stretched-link.scss b/resources/custom/scss/bootstrap/utilities/_stretched-link.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_text.scss b/resources/custom/scss/bootstrap/utilities/_text.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/bootstrap/utilities/_visibility.scss b/resources/custom/scss/bootstrap/utilities/_visibility.scss old mode 100644 new mode 100755 diff --git a/resources/custom/scss/style.scss b/resources/custom/scss/style.scss old mode 100644 new mode 100755