Compare commits
8 Commits
28c8e24847
...
3e178f6633
Author | SHA1 | Date | |
---|---|---|---|
3e178f6633 | |||
64dad0aaf9 | |||
32d1e93e73 | |||
dd231b0c07 | |||
88114ae9f2 | |||
6a07e5cdde | |||
7489e999ef | |||
1a54003030 |
@ -7,6 +7,7 @@ namespace kernel;
|
|||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\modules\user\models\User;
|
use kernel\modules\user\models\User;
|
||||||
use kernel\services\ModuleService;
|
use kernel\services\ModuleService;
|
||||||
|
use kernel\services\ThemeService;
|
||||||
use Phroute\Phroute\Dispatcher;
|
use Phroute\Phroute\Dispatcher;
|
||||||
|
|
||||||
class App
|
class App
|
||||||
@ -24,6 +25,8 @@ class App
|
|||||||
|
|
||||||
public ModuleService $moduleService;
|
public ModuleService $moduleService;
|
||||||
|
|
||||||
|
public ThemeService $themeService;
|
||||||
|
|
||||||
public static Database $db;
|
public static Database $db;
|
||||||
|
|
||||||
public function run(): void
|
public function run(): void
|
||||||
@ -39,6 +42,7 @@ class App
|
|||||||
public function load(): static
|
public function load(): static
|
||||||
{
|
{
|
||||||
$this->moduleService = new ModuleService();
|
$this->moduleService = new ModuleService();
|
||||||
|
$this->themeService = new ThemeService();
|
||||||
App::$collector = new CgRouteCollector();
|
App::$collector = new CgRouteCollector();
|
||||||
$this->setRouting();
|
$this->setRouting();
|
||||||
|
|
||||||
@ -53,6 +57,10 @@ class App
|
|||||||
foreach ($modules_routs as $rout){
|
foreach ($modules_routs as $rout){
|
||||||
include "$rout";
|
include "$rout";
|
||||||
}
|
}
|
||||||
|
$activeTheme = getConst($this->themeService->getActiveTheme());
|
||||||
|
if (!empty($activeTheme)){
|
||||||
|
include $activeTheme . "/" . $this->themeService->getThemeRout($activeTheme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create(): App
|
public static function create(): App
|
||||||
|
66
kernel/Assets.php
Normal file
66
kernel/Assets.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
class Assets
|
||||||
|
{
|
||||||
|
protected array $jsHeader = [];
|
||||||
|
protected array $jsBody = [];
|
||||||
|
|
||||||
|
protected array $css = [];
|
||||||
|
|
||||||
|
protected string $resourceURI = "/resource";
|
||||||
|
|
||||||
|
public function __construct(string $resourceURI)
|
||||||
|
{
|
||||||
|
$this->setResourceURI($resourceURI);
|
||||||
|
$this->createCSS();
|
||||||
|
$this->createJS();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createCSS(){}
|
||||||
|
protected function createJS(){}
|
||||||
|
|
||||||
|
public function setResourceURI(string $resourceURI): void
|
||||||
|
{
|
||||||
|
$this->resourceURI = $resourceURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerJS(string $slug, string $resource, bool $body = true, bool $addResourceURI = true): void
|
||||||
|
{
|
||||||
|
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
|
||||||
|
if ($body) {
|
||||||
|
$this->jsBody[$slug] = $resource;
|
||||||
|
} else {
|
||||||
|
$this->jsHeader[$slug] = $resource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerCSS(string $slug, string $resource, bool $addResourceURI = true): void
|
||||||
|
{
|
||||||
|
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
|
||||||
|
$this->css[$slug] = $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJSAsStr(bool $body = true): void
|
||||||
|
{
|
||||||
|
if ($body) {
|
||||||
|
foreach ($this->jsBody as $key => $item){
|
||||||
|
echo "<script src='$item'></script>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach ($this->jsHeader as $key => $item){
|
||||||
|
echo "<script src='$item'></script>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCSSAsSTR(): void
|
||||||
|
{
|
||||||
|
foreach ($this->css as $key => $item){
|
||||||
|
echo "<link rel='stylesheet' href='$item'>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace kernel;
|
namespace kernel;
|
||||||
|
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
|
||||||
class CgView
|
class CgView
|
||||||
{
|
{
|
||||||
public string $viewPath = '';
|
public string $viewPath = '';
|
||||||
@ -61,6 +63,13 @@ class CgView
|
|||||||
private function createContent(string $viewFile, array $data = []): false|string
|
private function createContent(string $viewFile, array $data = []): false|string
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
if ($this->varToLayout){
|
||||||
|
foreach ($this->varToLayout as $key => $datum) {
|
||||||
|
${"$key"} = $datum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$view = $this;
|
$view = $this;
|
||||||
foreach ($data as $key => $datum) {
|
foreach ($data as $key => $datum) {
|
||||||
${"$key"} = $datum;
|
${"$key"} = $datum;
|
||||||
|
@ -17,13 +17,32 @@ class RestController
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function filters(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
#[NoReturn] public function actionIndex(): void
|
#[NoReturn] public function actionIndex(): void
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
|
$get = $request->get();
|
||||||
$page = $request->get('page') ?? 1;
|
$page = $request->get('page') ?? 1;
|
||||||
$perPage = $request->get('per_page') ?? 10;
|
$perPage = $request->get('per_page') ?? 10;
|
||||||
$query = $this->model->query();
|
$query = $this->model->query();
|
||||||
|
|
||||||
|
if ($this->filters()) {
|
||||||
|
foreach ($this->filters() as $filter){
|
||||||
|
if (key_exists($filter, $get)){
|
||||||
|
if (is_numeric($get[$filter])){
|
||||||
|
$query->where($filter, $get[$filter]);
|
||||||
|
}
|
||||||
|
elseif (is_string($get[$filter])){
|
||||||
|
$query->where($filter,'like', '%' . $get[$filter] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($page > 1) {
|
if ($page > 1) {
|
||||||
$query->skip(($page - 1) * $perPage)->take($perPage);
|
$query->skip(($page - 1) * $perPage)->take($perPage);
|
||||||
} else {
|
} else {
|
||||||
@ -31,7 +50,7 @@ class RestController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$expand = $this->expand();
|
$expand = $this->expand();
|
||||||
$expandParams = explode( ",", $request->get('expand') ?? "");
|
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||||
$finalExpand = array_intersect($expandParams, $expand);
|
$finalExpand = array_intersect($expandParams, $expand);
|
||||||
if ($finalExpand) {
|
if ($finalExpand) {
|
||||||
$res = $query->get()->load($finalExpand)->toArray();
|
$res = $query->get()->load($finalExpand)->toArray();
|
||||||
@ -46,14 +65,14 @@ class RestController
|
|||||||
{
|
{
|
||||||
$expand = $this->expand();
|
$expand = $this->expand();
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$expandParams = explode( ",", $request->get('expand') ?? "");
|
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||||
$model = $this->model->where("id", $id)->first();
|
$model = $this->model->where("id", $id)->first();
|
||||||
$finalExpand = array_intersect($expandParams, $expand);
|
$finalExpand = array_intersect($expandParams, $expand);
|
||||||
if ($finalExpand){
|
if ($finalExpand) {
|
||||||
$model->load($finalExpand);
|
$model->load($finalExpand);
|
||||||
}
|
}
|
||||||
$res = [];
|
$res = [];
|
||||||
if ($model){
|
if ($model) {
|
||||||
$res = $model->toArray();
|
$res = $model->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +83,7 @@ class RestController
|
|||||||
{
|
{
|
||||||
$model = $this->model->where("id", $id)->first();
|
$model = $this->model->where("id", $id)->first();
|
||||||
$res = [];
|
$res = [];
|
||||||
if ($model){
|
if ($model) {
|
||||||
$res = $model->toArray();
|
$res = $model->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +97,7 @@ class RestController
|
|||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
foreach ($this->model->getFillable() as $item){
|
foreach ($this->model->getFillable() as $item) {
|
||||||
$this->model->{$item} = $data[$item] ?? null;
|
$this->model->{$item} = $data[$item] ?? null;
|
||||||
}
|
}
|
||||||
$this->model->save();
|
$this->model->save();
|
||||||
@ -93,8 +112,8 @@ class RestController
|
|||||||
|
|
||||||
$model = $this->model->where('id', $id)->first();
|
$model = $this->model->where('id', $id)->first();
|
||||||
|
|
||||||
foreach ($model->getFillable() as $item){
|
foreach ($model->getFillable() as $item) {
|
||||||
if (!empty($data[$item])){
|
if (!empty($data[$item])) {
|
||||||
$model->{$item} = $data[$item] ?? null;
|
$model->{$item} = $data[$item] ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,5 +136,4 @@ class RestController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
25
kernel/admin_themes/default/DefaultAdminThemeAssets.php
Normal file
25
kernel/admin_themes/default/DefaultAdminThemeAssets.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\admin_themes\default;
|
||||||
|
|
||||||
|
use kernel\Assets;
|
||||||
|
|
||||||
|
class DefaultAdminThemeAssets extends Assets
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function createJS(): void
|
||||||
|
{
|
||||||
|
$this->registerJS(slug: "jquery", resource: "/js/jquery.min.js");
|
||||||
|
$this->registerJS(slug: "popper", resource: "/js/popper.js");
|
||||||
|
$this->registerJS(slug: "bootstrap", resource: "/js/bootstrap.min.js");
|
||||||
|
$this->registerJS(slug: "main", resource: "/js/main.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createCSS()
|
||||||
|
{
|
||||||
|
$this->registerCSS(slug: "font-awesome", resource: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css", addResourceURI: false);
|
||||||
|
$this->registerCSS(slug: "bootstrap", resource: "/css/bootstrap.min.css");
|
||||||
|
$this->registerCSS(slug: "style", resource: "/css/style.css");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,7 @@
|
|||||||
* @var \kernel\CgView $view
|
* @var \kernel\CgView $view
|
||||||
*/
|
*/
|
||||||
\Josantonius\Session\Facades\Session::start();
|
\Josantonius\Session\Facades\Session::start();
|
||||||
|
$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources)
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -17,19 +18,21 @@
|
|||||||
|
|
||||||
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
<?php $assets->getCSSAsSTR(); ?>
|
||||||
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
|
<?php $assets->getJSAsStr(body: false); ?>
|
||||||
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="wrapper d-flex align-items-stretch">
|
<div class="wrapper d-flex align-items-stretch">
|
||||||
<nav id="sidebar">
|
<nav id="sidebar">
|
||||||
<div class="p-4 pt-5">
|
<div class="p-4 pt-5">
|
||||||
<a href="<?= '/admin/user/view/' . \kernel\modules\user\service\UserService::getAuthUser()->id ?>" class="img logo rounded-circle mb-5"
|
<a href="<?= '/admin/user/profile' ?>" class="img logo rounded-circle mb-5"
|
||||||
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/images/noPhoto.png' ?>);"></a>
|
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/default_user_photo/noPhoto.png' ?>);">
|
||||||
|
</a>
|
||||||
<p>
|
<p>
|
||||||
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
<a href="<?= '/admin/user/profile' ?>">
|
||||||
|
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
@ -74,24 +77,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<?php if (\kernel\Flash::hasMessage("error")): ?>
|
<?php if (\kernel\Flash::hasMessage("error")): ?>
|
||||||
<div class="alert alert-danger alert-dismissible mainAlert">
|
<div class="alert alert-danger alert-dismissible mainAlert">
|
||||||
<?= \kernel\Flash::getMessage("error"); ?>
|
<?= \kernel\Flash::getMessage("error"); ?>
|
||||||
<button type="button" class="btn-close closeAlertBtn"></button>
|
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if (\kernel\Flash::hasMessage("success")): ?>
|
<?php if (\kernel\Flash::hasMessage("success")): ?>
|
||||||
<div class="alert alert-success alert-dismissible">
|
<div class="alert alert-success alert-dismissible">
|
||||||
<?= \kernel\Flash::getMessage("success"); ?>
|
<?= \kernel\Flash::getMessage("success"); ?>
|
||||||
<button type="button" class="btn-close closeAlertBtn" ></button>
|
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?= $content ?>
|
<?= $content ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="<?= $resources ?>/js/jquery.min.js"></script>
|
<?php $assets->getJSAsStr(); ?>
|
||||||
<script src="<?= $resources ?>/js/popper.js"></script>
|
|
||||||
<script src="<?= $resources ?>/js/bootstrap.min.js"></script>
|
|
||||||
<script src="<?= $resources ?>/js/main.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -13,8 +13,9 @@ class BootstrapSelectFilter extends Filter
|
|||||||
{
|
{
|
||||||
$select = SelectBuilder::build($this->name, [
|
$select = SelectBuilder::build($this->name, [
|
||||||
'class' => 'form-control',
|
'class' => 'form-control',
|
||||||
'options' => $this->param,
|
'options' => $this->params['options'],
|
||||||
'value' => $this->value,
|
'value' => $this->value,
|
||||||
|
'prompt' => $this->params['prompt'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return "<td>" . $select->create()->fetch() . "</td>";
|
return "<td>" . $select->create()->fetch() . "</td>";
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace kernel\filters;
|
|
||||||
|
|
||||||
use itguild\forms\builders\SelectBuilder;
|
|
||||||
use Itguild\Tables\Filter\Filter;
|
|
||||||
use kernel\helpers\Debug;
|
|
||||||
|
|
||||||
class BootstrapSelectFilterWithPrompt extends Filter
|
|
||||||
{
|
|
||||||
|
|
||||||
public function fetch(): string
|
|
||||||
{
|
|
||||||
$select = SelectBuilder::build($this->name, [
|
|
||||||
'class' => 'form-control',
|
|
||||||
'options' => $this->param,
|
|
||||||
'value' => $this->value,
|
|
||||||
'prompt' => "Не выбрано"
|
|
||||||
]);
|
|
||||||
|
|
||||||
return "<td>" . $select->create()->fetch() . "</td>";
|
|
||||||
}
|
|
||||||
}
|
|
48
kernel/helpers/ImageGD.php
Normal file
48
kernel/helpers/ImageGD.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\helpers;
|
||||||
|
|
||||||
|
class ImageGD
|
||||||
|
{
|
||||||
|
public \GdImage $img;
|
||||||
|
|
||||||
|
public function __construct(string $resource = '', int $width = 200, int $height = 200)
|
||||||
|
{
|
||||||
|
if ($resource){
|
||||||
|
$this->img = imagecreatefrompng($resource);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->img = imagecreatetruecolor($width, $height);
|
||||||
|
}
|
||||||
|
imagesavealpha($this->img, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addText(string $font_size, int $degree, int $x, int $y, string $color, string $font, string $text): void
|
||||||
|
{
|
||||||
|
$rgbArr = $this->hexToRgb($color);
|
||||||
|
$color = imagecolorallocate($this->img, $rgbArr[0], $rgbArr[1], $rgbArr[2]);
|
||||||
|
imagettftext($this->img, $font_size, $degree, $x, $y, $color, $font, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addImg(\GdImage $gdImage, int $location_x, int $location_y, int $offset_src_x, int $offset_src_y, int $src_width, int $src_height, int $no_transparent): void
|
||||||
|
{
|
||||||
|
imagecopymerge($this->img, $gdImage, $location_x, $location_y, $offset_src_x, $offset_src_y, $src_width, $src_height, $no_transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getImg()
|
||||||
|
{
|
||||||
|
return $this->img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(string $path): void
|
||||||
|
{
|
||||||
|
imagepng($this->img, $path);
|
||||||
|
imagedestroy($this->img);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function hexToRgb(string $hex)
|
||||||
|
{
|
||||||
|
return sscanf($hex, "#%02x%02x%02x");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Kernel",
|
"name": "Kernel",
|
||||||
"version": "0.1.1",
|
"version": "0.1.4",
|
||||||
"author": "ITGuild",
|
"author": "ITGuild",
|
||||||
"slug": "kernel",
|
"slug": "kernel",
|
||||||
"type": "kernel",
|
"type": "kernel",
|
||||||
|
@ -5,6 +5,7 @@ namespace kernel\modules\module_shop_client\controllers;
|
|||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use Josantonius\Session\Facades\Session;
|
||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
use kernel\Flash;
|
use kernel\Flash;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
@ -162,18 +163,22 @@ class ModuleShopClientController extends AdminController
|
|||||||
$filters = $request->get();
|
$filters = $request->get();
|
||||||
if ($this->moduleService->issetModuleShopToken()) {
|
if ($this->moduleService->issetModuleShopToken()) {
|
||||||
if ($this->moduleService->isServerAvailable()) {
|
if ($this->moduleService->isServerAvailable()) {
|
||||||
$modules_info = [];
|
// $modules_info = [];
|
||||||
$per_page = 8;
|
$per_page = 8;
|
||||||
$modules = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||||
$modules = json_decode($modules->getBody()->getContents(), true);
|
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||||
foreach ($modules as $module) {
|
foreach ($modules_info as $key => $module) {
|
||||||
foreach ($filters as $key => $value) {
|
foreach ($filters as $column => $value) {
|
||||||
if ($value === '') continue;
|
if ($value === '') continue;
|
||||||
if ($module[$key] !== $value) {
|
if (is_numeric($value)) {
|
||||||
break;
|
if ($module[$column] !== $value) {
|
||||||
|
unset($modules_info[$key]);
|
||||||
|
}
|
||||||
|
} elseif (is_string($value)) {
|
||||||
|
if (!str_contains($module[$column], $value)) {
|
||||||
|
unset($modules_info[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$modules_info[] = $module;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$module_count = count($modules_info);
|
$module_count = count($modules_info);
|
||||||
@ -209,7 +214,7 @@ class ModuleShopClientController extends AdminController
|
|||||||
$moduleShopService = new ModuleShopService();
|
$moduleShopService = new ModuleShopService();
|
||||||
$result = $moduleShopService->email_auth($address);
|
$result = $moduleShopService->email_auth($address);
|
||||||
|
|
||||||
if ($result['status'] == 'success'){
|
if ($result['status'] == 'success') {
|
||||||
$this->cgView->render('enter_code.php', ['email' => $address]);
|
$this->cgView->render('enter_code.php', ['email' => $address]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +229,7 @@ class ModuleShopClientController extends AdminController
|
|||||||
$moduleShopService = new ModuleShopService();
|
$moduleShopService = new ModuleShopService();
|
||||||
$result = $moduleShopService->code_check($code);
|
$result = $moduleShopService->code_check($code);
|
||||||
|
|
||||||
if (isset($result['access_token'])){
|
if (isset($result['access_token'])) {
|
||||||
|
|
||||||
$envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env");
|
$envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env");
|
||||||
|
|
||||||
@ -238,4 +243,56 @@ class ModuleShopClientController extends AdminController
|
|||||||
$this->cgView->render('module_shop_error_connection.php');
|
$this->cgView->render('module_shop_error_connection.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionAdminThemeInstall(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$id = $request->get("id");
|
||||||
|
$adminThemeInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
|
||||||
|
|
||||||
|
$adminThemeInfo = json_decode($adminThemeInfo->getBody()->getContents(), true);
|
||||||
|
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $adminThemeInfo['path_to_archive'], RESOURCES_DIR . "/tmp/admin_themes");
|
||||||
|
if ($this->adminThemeService->install('/resources/tmp/admin_themes/' . basename($adminThemeInfo['path_to_archive']))) {
|
||||||
|
Flash::setMessage("success", "Тема админ-панели успешно установлена.");
|
||||||
|
} else {
|
||||||
|
Session::start();
|
||||||
|
Session::set("error", implode(";", $this->adminThemeService->getErrors()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redirect('/admin/module_shop_client', 302);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionAdminThemeUpdate(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$slug = $request->get("slug");
|
||||||
|
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||||
|
|
||||||
|
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||||
|
foreach ($modules_info as $module) {
|
||||||
|
if ($module['slug'] === $slug) {
|
||||||
|
$path = $module['path_to_archive'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($path)) {
|
||||||
|
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/admin_themes");
|
||||||
|
$this->adminThemeService->update('/resources/tmp/admin_themes/' . basename($path));
|
||||||
|
Flash::setMessage("success", "Тема админ-панели успешно обновлена.");
|
||||||
|
} else {
|
||||||
|
Flash::setMessage("error", "Ошибка обновления темы админ-панели.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redirect('/admin/module_shop_client', 302);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionAdminThemeDelete(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$slug = $request->get("slug");
|
||||||
|
$adminThemeInfo = $this->adminThemeService->getAdminThemeInfoBySlug($slug);
|
||||||
|
$this->adminThemeService->uninstall($adminThemeInfo['path']);
|
||||||
|
|
||||||
|
Flash::setMessage("success", "Тема админ-панели успешно удалена.");
|
||||||
|
$this->redirect('/admin/module_shop_client', 302);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -24,7 +24,9 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
|||||||
});
|
});
|
||||||
App::$collector->group(["prefix" => "admin_theme"], function (RouteCollector $router) {
|
App::$collector->group(["prefix" => "admin_theme"], function (RouteCollector $router) {
|
||||||
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeInstall']);
|
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeInstall']);
|
||||||
App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']);
|
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']);
|
||||||
|
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeDelete']);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
use Itguild\Tables\ListJsonTable;
|
use Itguild\Tables\ListJsonTable;
|
||||||
use kernel\widgets\ActionButtonWidget;
|
use kernel\widgets\ActionButtonWidget;
|
||||||
|
|
||||||
$meta = [];
|
$meta = [];
|
||||||
$meta['columns'] = [
|
$meta['columns'] = [
|
||||||
"name" => "Название",
|
"name" => "Название",
|
||||||
@ -42,10 +43,13 @@ $table->addAction(function ($row, $url) use ($moduleService) {
|
|||||||
$table->columns([
|
$table->columns([
|
||||||
'type' => [
|
'type' => [
|
||||||
'filter' => [
|
'filter' => [
|
||||||
'class' => \kernel\filters\BootstrapSelectFilterWithPrompt::class,
|
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||||
'param' => [
|
'params' => [
|
||||||
'kernel' => 'kernel',
|
'options' => [
|
||||||
'entity' => 'entity',
|
'kernel' => 'kernel',
|
||||||
|
'entity' => 'entity',
|
||||||
|
],
|
||||||
|
'prompt' => 'Не выбрано'
|
||||||
],
|
],
|
||||||
'value' => $filterValues['type'] ?? ''
|
'value' => $filterValues['type'] ?? ''
|
||||||
],
|
],
|
||||||
@ -100,7 +104,7 @@ $table->addAction(function ($row, $url) use ($adminThemeService) {
|
|||||||
$slug = $row['slug'];
|
$slug = $row['slug'];
|
||||||
if ($adminThemeService->isInstall($slug)) {
|
if ($adminThemeService->isInstall($slug)) {
|
||||||
if (!$adminThemeService->isLastVersion($slug)) {
|
if (!$adminThemeService->isLastVersion($slug)) {
|
||||||
$url = "$url/admin_theme/update/";
|
$url = "$url/admin_theme/update/?slug=" . $row['slug'];
|
||||||
|
|
||||||
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
|
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
|
||||||
}
|
}
|
||||||
@ -110,6 +114,22 @@ $table->addAction(function ($row, $url) use ($adminThemeService) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$table->addAction(function ($row, $url) use ($adminThemeService) {
|
||||||
|
if ($row['type'] === 'admin_theme') {
|
||||||
|
if ($adminThemeService->isInstall($row['slug'])) {
|
||||||
|
$url = "$url/admin_theme/delete/?slug=" . $row['slug'];
|
||||||
|
|
||||||
|
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
|
||||||
|
} else {
|
||||||
|
$url = "$url/admin_theme/install/?id=" . $row['id'];
|
||||||
|
|
||||||
|
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
$table->afterPrint(function () {
|
$table->afterPrint(function () {
|
||||||
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
|
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
|
||||||
});
|
});
|
||||||
|
@ -26,8 +26,6 @@ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
|
|||||||
'searchParams' => $get,
|
'searchParams' => $get,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
//\kernel\helpers\Debug::dd((new \kernel\Request())->get());
|
|
||||||
|
|
||||||
$view->setTitle("Список постов");
|
$view->setTitle("Список постов");
|
||||||
$view->setMeta([
|
$view->setMeta([
|
||||||
'description' => 'Список постов системы'
|
'description' => 'Список постов системы'
|
||||||
@ -72,12 +70,13 @@ $table->columns([
|
|||||||
return User::find($data)->username;
|
return User::find($data)->username;
|
||||||
},
|
},
|
||||||
'filter' => [
|
'filter' => [
|
||||||
'class' => \kernel\filters\BootstrapSelectFilterWithPrompt::class,
|
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||||
'param' => \kernel\modules\user\service\UserService::createUsernameArr(),
|
'params' => [
|
||||||
|
'options' => \kernel\modules\user\service\UserService::createUsernameArr(),
|
||||||
|
'prompt' => 'Не выбрано'
|
||||||
|
],
|
||||||
'value' => $get['user_id'] ?? '',
|
'value' => $get['user_id'] ?? '',
|
||||||
'prompt' => 'dsds'
|
|
||||||
],
|
],
|
||||||
'prompt' => 'dsds'
|
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -13,21 +13,28 @@ use kernel\services\TokenService;
|
|||||||
class SecureService
|
class SecureService
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function createSecretCode(User $user): void
|
public static function createSecretCode(User $user): SecretCode
|
||||||
{
|
{
|
||||||
$secretCode = new SecretCode();
|
$secretCode = new SecretCode();
|
||||||
$secretCode->user_id = $user->id;
|
$secretCode->user_id = $user->id;
|
||||||
$secretCode->code = mt_rand(100000, 999999);
|
$secretCode->code = mt_rand(100000, 999999);
|
||||||
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
||||||
$secretCode->save();
|
$secretCode->save();
|
||||||
|
|
||||||
|
return $secretCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function updateSecretCode(User $user): void
|
public static function updateSecretCode(User $user): SecretCode
|
||||||
{
|
{
|
||||||
$secretCode = SecretCode::where('user_id', $user->id)->first();
|
$secretCode = SecretCode::where('user_id', $user->id)->first();
|
||||||
|
if(!$secretCode){
|
||||||
|
return self::createSecretCode($user);
|
||||||
|
}
|
||||||
$secretCode->code = mt_rand(100000, 999999);
|
$secretCode->code = mt_rand(100000, 999999);
|
||||||
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
||||||
$secretCode->save();
|
$secretCode->save();
|
||||||
|
|
||||||
|
return $secretCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCodeByUserId(int $user_id)
|
public static function getCodeByUserId(int $user_id)
|
||||||
|
@ -144,4 +144,53 @@ class UserController extends AdminController
|
|||||||
$this->redirect("/admin/user/");
|
$this->redirect("/admin/user/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionProfile(): void
|
||||||
|
{
|
||||||
|
$user = UserService::getAuthUser();
|
||||||
|
if (!$user){
|
||||||
|
throw new Exception(message: "The user not found");
|
||||||
|
}
|
||||||
|
$this->cgView->render("view_profile.php", ['user' => $user]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionProfileUpdate(): void
|
||||||
|
{
|
||||||
|
$model = UserService::getAuthUser();
|
||||||
|
if (!$model){
|
||||||
|
throw new Exception(message: "The user not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cgView->render("form_profile.php", ['model' => $model]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionProfileEdit(): void
|
||||||
|
{
|
||||||
|
$user = UserService::getAuthUser();
|
||||||
|
if (!$user){
|
||||||
|
throw new Exception(message: "The user not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
$userForm = new CreateUserForm();
|
||||||
|
$userService = new UserService();
|
||||||
|
$userForm->load($_REQUEST);
|
||||||
|
|
||||||
|
if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']);
|
||||||
|
$file->upload();
|
||||||
|
$userForm->setItem('user_photo', $file->getUploadFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($userForm->validateForUpdate()){
|
||||||
|
$user = $userService->update($userForm, $user);
|
||||||
|
|
||||||
|
$entityRelation = new EntityRelation();
|
||||||
|
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
|
||||||
|
|
||||||
|
if ($user){
|
||||||
|
$this->redirect("/admin/user/profile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->redirect("/admin/user/profile/update");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,6 +17,11 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
|||||||
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
|
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
|
||||||
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
|
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
|
||||||
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
|
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
|
||||||
|
App::$collector->group(["prefix" => "profile"], callback: function (RouteCollector $router) {
|
||||||
|
App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionProfile']);
|
||||||
|
App::$collector->get('/update', [\kernel\modules\user\controllers\UserController::class, 'actionProfileUpdate']);
|
||||||
|
App::$collector->any('/edit', [\kernel\modules\user\controllers\UserController::class, 'actionProfileEdit']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -11,7 +11,11 @@ class UserService
|
|||||||
|
|
||||||
public function create(FormModel $form_model): false|User
|
public function create(FormModel $form_model): false|User
|
||||||
{
|
{
|
||||||
$model = new User();
|
$model = User::where("username", $form_model->getItem('username'))->first();
|
||||||
|
if ($model){
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
$model = new User();
|
||||||
$model->username = $form_model->getItem('username');
|
$model->username = $form_model->getItem('username');
|
||||||
$model->email = $form_model->getItem('email');
|
$model->email = $form_model->getItem('email');
|
||||||
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
||||||
|
74
kernel/modules/user/views/form_profile.php
Normal file
74
kernel/modules/user/views/form_profile.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var User $model
|
||||||
|
*/
|
||||||
|
|
||||||
|
use kernel\modules\user\models\User;
|
||||||
|
|
||||||
|
$form = new \itguild\forms\ActiveForm();
|
||||||
|
$form->beginForm("/admin/user/profile/edit", enctype: 'multipart/form-data');
|
||||||
|
|
||||||
|
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "username", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => 'Логин',
|
||||||
|
'value' => $model->username ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Логин")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "password", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'type' => "password",
|
||||||
|
])
|
||||||
|
->setLabel("Пароль")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'type' => "email",
|
||||||
|
'placeholder' => 'test@mail.ru',
|
||||||
|
'value' => $model->email ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Email")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
if (!empty($model->user_photo)){
|
||||||
|
echo "<div><img src='$model->user_photo' width='200px'></div>";
|
||||||
|
}
|
||||||
|
$form->field(class: \itguild\forms\inputs\File::class, name: "user_photo", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'value' => $model->user_photo ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Фото профиля")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$entityRelations = new \kernel\EntityRelation();
|
||||||
|
if (!isset($model)) {
|
||||||
|
$model = new User();
|
||||||
|
}
|
||||||
|
$entityRelations->renderEntityAdditionalPropertyFormBySlug("user", $model);
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
|
||||||
|
'class' => "btn btn-primary ",
|
||||||
|
'value' => 'Отправить',
|
||||||
|
'typeInput' => 'submit'
|
||||||
|
])
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
|
||||||
|
'class' => "btn btn-warning",
|
||||||
|
'value' => 'Сбросить',
|
||||||
|
'typeInput' => 'reset'
|
||||||
|
])
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$form->endForm();
|
56
kernel/modules/user/views/view_profile.php
Normal file
56
kernel/modules/user/views/view_profile.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection $user
|
||||||
|
*/
|
||||||
|
|
||||||
|
use kernel\modules\user\models\User;
|
||||||
|
use Itguild\EloquentTable\ViewEloquentTable;
|
||||||
|
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||||
|
use kernel\IGTabel\btn\DangerBtn;
|
||||||
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
|
use kernel\IGTabel\btn\SuccessBtn;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||||
|
|
||||||
|
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user, [
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/user",
|
||||||
|
]));
|
||||||
|
$table->beforePrint(function () use ($user) {
|
||||||
|
$btn = IconBtnEditWidget::create(['url' => '/admin/user/profile/edit'])->run();
|
||||||
|
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/user/delete/' . $user->id])->run();
|
||||||
|
return $btn;
|
||||||
|
});
|
||||||
|
|
||||||
|
$entityRelation = new \kernel\EntityRelation();
|
||||||
|
$additionals = $entityRelation->getEntityAdditionalProperty("user", $user);
|
||||||
|
|
||||||
|
foreach ($additionals as $key => $additional) {
|
||||||
|
$table->addRow($key, function () use ($additional) {
|
||||||
|
return $additional;
|
||||||
|
}, ['after' => 'email']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->rows([
|
||||||
|
'user_photo' => function ($data) {
|
||||||
|
return $data ? "<img src='$data' width='300px'>" : "";
|
||||||
|
},
|
||||||
|
'created_at' => function ($data) {
|
||||||
|
if (!$data){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||||
|
},
|
||||||
|
'updated_at' => function ($data) {
|
||||||
|
if (!$data){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
@ -82,12 +82,22 @@ class AdminThemeService
|
|||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAdminThemeInfoBySlug(string $slug)
|
public function getAdminThemeInfoBySlug(string $slug): false|array|string
|
||||||
{
|
{
|
||||||
// TODO
|
$dirs = $this->getAdminThemeDirs();
|
||||||
|
foreach ($dirs as $dir) {
|
||||||
|
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||||
|
if ($fileInfo->isDot()) continue;
|
||||||
|
if ($this->getAdminThemeInfo($fileInfo->getPathname())['slug'] === $slug) {
|
||||||
|
return $this->getAdminThemeInfo($fileInfo->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isInstall(string $slug): bool
|
public function getAdminThemeDirs(): array
|
||||||
{
|
{
|
||||||
$adminThemePaths = Option::where("key", "admin_theme_paths")->first();
|
$adminThemePaths = Option::where("key", "admin_theme_paths")->first();
|
||||||
$dirs = [];
|
$dirs = [];
|
||||||
@ -97,6 +107,12 @@ class AdminThemeService
|
|||||||
$dirs[] = getConst($p);
|
$dirs[] = getConst($p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $dirs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isInstall(string $slug): bool
|
||||||
|
{
|
||||||
|
$dirs = $this->getAdminThemeDirs();
|
||||||
foreach ($dirs as $dir) {
|
foreach ($dirs as $dir) {
|
||||||
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||||
if ($fileInfo->isDot()) continue;
|
if ($fileInfo->isDot()) continue;
|
||||||
@ -116,8 +132,7 @@ class AdminThemeService
|
|||||||
|
|
||||||
$modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true);
|
$modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true);
|
||||||
|
|
||||||
$themeInfo = $this->getAdminThemeInfo($slug);
|
$themeInfo = $this->getAdminThemeInfoBySlug($slug);
|
||||||
// Debug::dd($themeInfo);
|
|
||||||
foreach ($modulesInfo as $mod) {
|
foreach ($modulesInfo as $mod) {
|
||||||
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
|
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
|
||||||
return true;
|
return true;
|
||||||
@ -195,11 +210,20 @@ class AdminThemeService
|
|||||||
$this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default');
|
$this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default');
|
||||||
}
|
}
|
||||||
$fileHelper = new Files();
|
$fileHelper = new Files();
|
||||||
if (file_exists(ROOT_DIR . $path)) {
|
if (file_exists($path)) {
|
||||||
$fileHelper->recursiveRemoveDir(ROOT_DIR . $path);
|
$fileHelper->recursiveRemoveDir($path);
|
||||||
}
|
}
|
||||||
if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) {
|
if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) {
|
||||||
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']);
|
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update(string $path): bool
|
||||||
|
{
|
||||||
|
if ($this->install($path)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
41
kernel/services/ThemeService.php
Normal file
41
kernel/services/ThemeService.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\services;
|
||||||
|
|
||||||
|
use kernel\models\Option;
|
||||||
|
|
||||||
|
class ThemeService
|
||||||
|
{
|
||||||
|
protected Option $option;
|
||||||
|
protected string $active_theme = "";
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->option = new Option();
|
||||||
|
$this->findActiveAdminTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findActiveAdminTheme(): void
|
||||||
|
{
|
||||||
|
$model = $this->option::where("key", "active_theme")->first();
|
||||||
|
$this->active_theme = $model->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActiveTheme(): string
|
||||||
|
{
|
||||||
|
return $this->active_theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
// Responsive images (ensure images don't scale beyond their parents)
|
// Responsive default_user_photo (ensure default_user_photo don't scale beyond their parents)
|
||||||
//
|
//
|
||||||
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
|
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
|
||||||
// We previously tried the "images are responsive by default" approach in Bootstrap v2,
|
// We previously tried the "default_user_photo are responsive by default" approach in Bootstrap v2,
|
||||||
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
|
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
|
||||||
// which weren't expecting the images within themselves to be involuntarily resized.
|
// which weren't expecting the default_user_photo within themselves to be involuntarily resized.
|
||||||
// See also https://github.com/twbs/bootstrap/issues/18178
|
// See also https://github.com/twbs/bootstrap/issues/18178
|
||||||
.img-fluid {
|
.img-fluid {
|
||||||
@include img-fluid;
|
@include img-fluid;
|
||||||
|
@ -249,7 +249,7 @@ figure {
|
|||||||
|
|
||||||
img {
|
img {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
border-style: none; // Remove the border on images inside links in IE 10-.
|
border-style: none; // Remove the border on default_user_photo inside links in IE 10-.
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
// Responsive image
|
// Responsive image
|
||||||
//
|
//
|
||||||
// Keep images from scaling beyond the width of their parents.
|
// Keep default_user_photo from scaling beyond the width of their parents.
|
||||||
|
|
||||||
@mixin img-fluid {
|
@mixin img-fluid {
|
||||||
// Part 1: Set a maximum relative to the parent
|
// Part 1: Set a maximum relative to the parent
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
// Part 2: Override the height to auto, otherwise images will be stretched
|
// Part 2: Override the height to auto, otherwise default_user_photo will be stretched
|
||||||
// when setting a width and height attribute on the img element.
|
// when setting a width and height attribute on the img element.
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// Responsive images (ensure images don't scale beyond their parents)
|
// Responsive default_user_photo (ensure default_user_photo don't scale beyond their parents)
|
||||||
//
|
//
|
||||||
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
|
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
|
||||||
// We previously tried the "images are responsive by default" approach in Bootstrap v2,
|
// We previously tried the "default_user_photo are responsive by default" approach in Bootstrap v2,
|
||||||
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
|
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
|
||||||
// which weren't expecting the images within themselves to be involuntarily resized.
|
// which weren't expecting the default_user_photo within themselves to be involuntarily resized.
|
||||||
// See also https://github.com/twbs/bootstrap/issues/18178
|
// See also https://github.com/twbs/bootstrap/issues/18178
|
||||||
.img-fluid {
|
.img-fluid {
|
||||||
@include img-fluid;
|
@include img-fluid;
|
||||||
|
@ -249,7 +249,7 @@ figure {
|
|||||||
|
|
||||||
img {
|
img {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
border-style: none; // Remove the border on images inside links in IE 10-.
|
border-style: none; // Remove the border on default_user_photo inside links in IE 10-.
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
// Responsive image
|
// Responsive image
|
||||||
//
|
//
|
||||||
// Keep images from scaling beyond the width of their parents.
|
// Keep default_user_photo from scaling beyond the width of their parents.
|
||||||
|
|
||||||
@mixin img-fluid {
|
@mixin img-fluid {
|
||||||
// Part 1: Set a maximum relative to the parent
|
// Part 1: Set a maximum relative to the parent
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
// Part 2: Override the height to auto, otherwise images will be stretched
|
// Part 2: Override the height to auto, otherwise default_user_photo will be stretched
|
||||||
// when setting a width and height attribute on the img element.
|
// when setting a width and height attribute on the img element.
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
@ -1,9 +1,9 @@
|
|||||||
// Responsive images (ensure images don't scale beyond their parents)
|
// Responsive default_user_photo (ensure default_user_photo don't scale beyond their parents)
|
||||||
//
|
//
|
||||||
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
|
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
|
||||||
// We previously tried the "images are responsive by default" approach in Bootstrap v2,
|
// We previously tried the "default_user_photo are responsive by default" approach in Bootstrap v2,
|
||||||
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
|
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
|
||||||
// which weren't expecting the images within themselves to be involuntarily resized.
|
// which weren't expecting the default_user_photo within themselves to be involuntarily resized.
|
||||||
// See also https://github.com/twbs/bootstrap/issues/18178
|
// See also https://github.com/twbs/bootstrap/issues/18178
|
||||||
.img-fluid {
|
.img-fluid {
|
||||||
@include img-fluid;
|
@include img-fluid;
|
||||||
|
@ -249,7 +249,7 @@ figure {
|
|||||||
|
|
||||||
img {
|
img {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
border-style: none; // Remove the border on images inside links in IE 10-.
|
border-style: none; // Remove the border on default_user_photo inside links in IE 10-.
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
// Responsive image
|
// Responsive image
|
||||||
//
|
//
|
||||||
// Keep images from scaling beyond the width of their parents.
|
// Keep default_user_photo from scaling beyond the width of their parents.
|
||||||
|
|
||||||
@mixin img-fluid {
|
@mixin img-fluid {
|
||||||
// Part 1: Set a maximum relative to the parent
|
// Part 1: Set a maximum relative to the parent
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
// Part 2: Override the height to auto, otherwise images will be stretched
|
// Part 2: Override the height to auto, otherwise default_user_photo will be stretched
|
||||||
// when setting a width and height attribute on the img element.
|
// when setting a width and height attribute on the img element.
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user