73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
|
<?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"))]);
|
||
|
}
|
||
|
|
||
|
}
|