diff --git a/kernel/App.php b/kernel/App.php index 1e6cbb9..9447b4b 100644 --- a/kernel/App.php +++ b/kernel/App.php @@ -42,7 +42,7 @@ class App public function load(): static { $this->moduleService = new ModuleService(); - $this->themeService = new ThemeService(); +// $this->themeService = new ThemeService(); App::$collector = new CgRouteCollector(); $this->setRouting(); @@ -57,9 +57,15 @@ class App foreach ($modules_routs as $rout){ include "$rout"; } - $activeTheme = getConst($this->themeService->getActiveTheme()); +// $activeTheme = getConst($this->themeService->getActiveTheme()); +// if (!empty($activeTheme)){ +// include $activeTheme . "/" . $this->themeService->getThemeRout($activeTheme); +// } + + $themeService = new ThemeService(); + $activeTheme = getConst($themeService->getActiveTheme()); if (!empty($activeTheme)){ - include $activeTheme . "/" . $this->themeService->getThemeRout($activeTheme); + include $activeTheme . "/" . $themeService->getThemeRout($activeTheme); } } diff --git a/kernel/console/controllers/AdminConsoleController.php b/kernel/console/controllers/AdminConsoleController.php index 0af6f7b..4791fec 100644 --- a/kernel/console/controllers/AdminConsoleController.php +++ b/kernel/console/controllers/AdminConsoleController.php @@ -63,6 +63,20 @@ class AdminConsoleController extends ConsoleController ); $this->out->r("create option active_admin_theme", "green"); + $this->optionService->createFromParams( + key: "theme_paths", + value: "{\"paths\": [\"{KERNEL}/themes\", \"{APP}/themes\"]}", + label: "Пути к темам сайта" + ); + $this->out->r("create option theme_paths", "green"); + + $this->optionService->createFromParams( + key: "active_theme", + value: "{KERNEL}/themes/default", + label: "Активная тема сайта" + ); + $this->out->r("create option active_theme", "green"); + $this->optionService->createFromParams( key: "module_paths", value: "{\"paths\": [\"{KERNEL_MODULES}\", \"{APP}/modules\"]}", @@ -72,7 +86,7 @@ class AdminConsoleController extends ConsoleController $this->optionService->createFromParams( key: "active_modules", - value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\", \"menu\", \"post\", \"option\"]}", + value: "{\"modules\":[\"admin_themes\",\"themes\",\"secure\", \"user\", \"menu\", \"post\", \"option\"]}", label: "Активные модули" ); $this->out->r("create option active_modules", "green"); @@ -133,6 +147,14 @@ class AdminConsoleController extends ConsoleController ]); $this->out->r("create item menu admin-themes", "green"); + $this->menuService->createItem([ + "label" => "Темы сайта", + "url" => "/admin/settings/themes", + "slug" => "themes", + "parent_slug" => "settings" + ]); + $this->out->r("create item menu themes", "green"); + $this->menuService->createItem([ "label" => "Меню", "url" => "/admin/settings/menu", diff --git a/kernel/services/ThemeService.php b/kernel/services/ThemeService.php index 3de5900..598e3cd 100644 --- a/kernel/services/ThemeService.php +++ b/kernel/services/ThemeService.php @@ -2,11 +2,15 @@ namespace kernel\services; +use DirectoryIterator; use kernel\helpers\Manifest; +use kernel\helpers\RESTClient; use kernel\models\Option; class ThemeService { + protected array $errors = []; + protected Option $option; protected string $active_theme = ""; @@ -16,6 +20,23 @@ class ThemeService $this->findActiveTheme(); } + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * @param $msg + * @return void + */ + public function addError($msg): void + { + $this->errors[] = $msg; + } + public function findActiveTheme(): void { $model = $this->option::where("key", "active_theme")->first(); @@ -27,16 +48,16 @@ class ThemeService return $this->active_theme; } - public function getThemeRout(string $path) + public function setActiveTheme(string $theme): void { - if (file_exists($path . "/manifest.json")){ - $manifest = json_decode(file_get_contents($path . "/manifest.json"), true); - if ($manifest['routs']) { - return $manifest['routs']; - } - } + $activeTheme = Option::where("key", "active_theme")->first(); + $activeTheme->value = getConst($theme); + $activeTheme->save(); + } - return false; + public function getActiveThemeInfo(): false|array|string + { + return $this->getThemeInfo($this->active_theme); } public function getThemeInfo(string $theme): false|array|string @@ -54,11 +75,44 @@ class ThemeService return $info; } - public function setActiveTheme(string $theme): void + public function getThemeInfoBySlug(string $slug): false|array|string { - $activeTheme = Option::where("key", "active_theme")->first(); - $activeTheme->value = getConst($theme); - $activeTheme->save(); + $dirs = $this->getThemeDirs(); + foreach ($dirs as $dir) { + foreach (new DirectoryIterator($dir) as $fileInfo) { + if ($fileInfo->isDot()) continue; + if ($this->getThemeInfo($fileInfo->getPathname())['slug'] === $slug) { + return $this->getThemeInfo($fileInfo->getPathname()); + } + } + } + + return false; + } + + public function getThemeDirs(): array + { + $ThemePaths = Option::where("key", "theme_paths")->first(); + $dirs = []; + if ($ThemePaths) { + $path = json_decode($ThemePaths->value); + foreach ($path->paths as $p) { + $dirs[] = getConst($p); + } + } + return $dirs; + } + + public function getThemeRout(string $path) + { + if (file_exists($path . "/manifest.json")){ + $manifest = json_decode(file_get_contents($path . "/manifest.json"), true); + if ($manifest['routs']) { + return $manifest['routs']; + } + } + + return false; } } \ No newline at end of file diff --git a/kernel/themes/default/assets/DefaultThemesAssets.php b/kernel/themes/default/assets/DefaultThemesAssets.php index ae07d68..0576814 100644 --- a/kernel/themes/default/assets/DefaultThemesAssets.php +++ b/kernel/themes/default/assets/DefaultThemesAssets.php @@ -8,11 +8,11 @@ class DefaultThemesAssets extends Assets { protected function createCSS(): void { - $this->registerCSS(slug: "main", resource: "some"); + $this->registerCSS(slug: "main", resource: "/css/styles.css"); } protected function createJS(): void { - $this->registerJS(slug: "webpack", resource: "some"); + $this->registerJS(slug: "webpack", resource: "/js/scripts.js"); } } \ No newline at end of file diff --git a/kernel/themes/default/controllers/MainController.php b/kernel/themes/default/controllers/MainController.php index 38fa7f2..57e83c0 100644 --- a/kernel/themes/default/controllers/MainController.php +++ b/kernel/themes/default/controllers/MainController.php @@ -10,14 +10,19 @@ class MainController extends Controller protected function init(): void { parent::init(); - $this->cgView->viewPath = APP_DIR . "/themes/default/views/main/"; + $this->cgView->viewPath = KERNEL_DIR . "/themes/default/views/main/"; $this->cgView->layout = "main.php"; - $this->cgView->layoutPath = APP_DIR . "/themes/default/views/layout/"; - $this->cgView->addVarToLayout("resources", "/resources/default"); + $this->cgView->layoutPath = KERNEL_DIR . "/themes/default/views/layout/"; + $this->cgView->addVarToLayout("resources", "/resources/themes/default"); } public function actionIndex(): void { $this->cgView->render("index.php"); } + + public function actionAbout(): void + { + $this->cgView->render("about.php"); + } } \ No newline at end of file diff --git a/kernel/themes/default/routs/default.php b/kernel/themes/default/routs/default.php index e1b962b..8c643ec 100644 --- a/kernel/themes/default/routs/default.php +++ b/kernel/themes/default/routs/default.php @@ -4,6 +4,7 @@ use kernel\App; App::$collector->get('/', [\kernel\themes\default\controllers\MainController::class, 'actionIndex']); +App::$collector->get('/about', [\kernel\themes\default\controllers\MainController::class, 'actionAbout']); //App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); //App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); diff --git a/kernel/themes/default/views/layout/main.php b/kernel/themes/default/views/layout/main.php index 047ca88..3ca6288 100644 --- a/kernel/themes/default/views/layout/main.php +++ b/kernel/themes/default/views/layout/main.php @@ -5,132 +5,88 @@ * @var string $title * @var \kernel\CgView $view */ -$assets = new \app\themes\gestalt\assets\GestaltThemeAssets($resources); +$assets = new \kernel\themes\default\assets\DefaultThemesAssets($resources); ?> - - + + getCSSAsSTR(); ?> - - - - - - + + <?= $title ?> getMeta() ?> - - + + + + + + + -
-
СобытияУчастники
- logo -
logo_tg - logo_vk -
-
-
- -
-
-
- конференции
-
- акредитации
-
- открытые сертификации
-
- открытые сертификации
-
- общие сборы
-
- протоколы сборов
-
- новости сайта
-
- календарь событий
-
- сайт мги
-
- вопросы и ответы
-
-
-
- arrowКниги
-
- arrowлекции
+ +
-