add default theme

This commit is contained in:
2025-01-15 16:57:03 +03:00
parent 3e178f6633
commit c228a70468
331 changed files with 660 additions and 29 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace kernel\modules\themes;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class ThemesModule extends Module
{
public MenuService $menuService;
public function __construct()
{
$this->menuService = new MenuService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->menuService->createItem([
"label" => "Темы сайта",
"url" => "/admin/settings/themes",
"slug" => "themes",
"parent_slug" => "settings"
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("themes");
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace kernel\modules\themes\controllers;
use DirectoryIterator;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\Request;
class ThemeController extends AdminController
{
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/themes/views/";
}
public function actionIndex(): void
{
$themePaths = Option::where("key", "theme_paths")->first();
$dirs = [];
if ($themePaths){
$path = json_decode($themePaths->value);
foreach ($path->paths as $p){
$dirs[] = getConst($p);
}
}
$infoToTable = [];
$meta = [];
$meta['columns'] = [
"preview" => "Превью",
"name" => "Название",
"author" => "Автор",
"version" => "Версия",
"description" => "Описание"
];
$meta['params'] = ["class" => "table table-bordered"];
$meta['perPage'] = 10;
$meta['baseUrl'] = "/admin/settings/themes";
$meta['currentPage'] = 1;
$infoToTable['meta'] = $meta;
$themesInfo = [];
foreach ($dirs as $dir){
$i = 1;
foreach (new DirectoryIterator($dir) as $fileInfo) {
$info = [];
if($fileInfo->isDot()) continue;
$info['id'] = $i;
$themesInfo[] = array_merge($info, $this->themeService->getThemeInfo($fileInfo->getPathname()));
$i++;
}
}
$infoToTable['meta']['total'] = count($themesInfo);
$infoToTable['data'] = $themesInfo;
$this->cgView->render("index.php", ['json' => json_encode($infoToTable, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)]);
}
#[NoReturn] public function actionActivate(): void
{
$request = new Request();
$this->themeService->setActiveTheme($request->get("p"));
$this->cgView->render("view.php", ['data' => $this->themeService->getThemeInfo($request->get("p"))]);
}
}

View File

@ -0,0 +1,10 @@
{
"name": "Themes",
"version": "0.1",
"author": "ITGuild",
"slug": "themes",
"description": "Themes module",
"module_class": "kernel\\modules\\themes\\ThemesModule",
"module_class_file": "{KERNEL_MODULES}/themes/ThemesModule.php",
"routs": "routs/themes.php"
}

View File

@ -0,0 +1,16 @@
<?php
use kernel\App;
use kernel\modules\admin_themes\controllers\AdminThemeController;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "settings"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "themes"], function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\themes\controllers\ThemeController::class, 'actionIndex']);
App::$collector->get('/activate', [\kernel\modules\themes\controllers\ThemeController::class, 'actionActivate']);
});
});
});
});

View File

@ -0,0 +1,25 @@
<?php
/**
* @var $json string
*/
$table = new \Itguild\Tables\ListJsonTable($json);
$table->columns([
'preview' => function ($data) {
return "<img src='$data' width='200px'>";
}
]);
$table->addAction(function ($row, $url){
$active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_theme');
if ($row['path'] === $active_admin_theme){
return "Активна";
} else {
$url = "$url/activate/?p=" . $row['path'];
return \kernel\widgets\IconBtn\IconBtnActivateWidget::create(['url' => $url])->run();
}
});
$table->create();
$table->render();

View File

@ -0,0 +1,25 @@
<?php
/**
* @var array $data
*/
$table_info = [
"meta" => [
"rows" => ["preview" => "Превью", "name" => "Название", "version" => "Версия", "description" => "Описание"],
"params" => ["class" => "table table-bordered"],
"baseUrl" => "/admin/settings/themes",
],
"data" => $data
];
$table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->rows([
'preview' => function ($data) {
return "<img src='$data' width='500px'>";
}
]);
$table->beforePrint(function () {
return \kernel\widgets\IconBtn\IconBtnListWidget::create(['url' => '/admin/settings/themes'])->run();
});
$table->create();
$table->render();