Compare commits
67 Commits
378f27970e
...
master
Author | SHA1 | Date | |
---|---|---|---|
a64ed080bb | |||
6242304843 | |||
2655a793f5 | |||
de0354f9cb | |||
4a4d5b083f | |||
68b5741f46 | |||
fc70051761 | |||
b1dacff877 | |||
e904cedf40 | |||
64a6cc4340 | |||
b79483dafd | |||
7ab241daa2 | |||
c69314b531 | |||
e448ffa6b6 | |||
3c025a4cbc | |||
6a7cde15e9 | |||
2b2c99cd17 | |||
b6ba8f8718 | |||
11c99be0f6 | |||
f421e0c649 | |||
3120795eab | |||
50c6ca98d8 | |||
dac4db96af | |||
c228a70468 | |||
3e178f6633 | |||
64dad0aaf9 | |||
32d1e93e73 | |||
dd231b0c07 | |||
88114ae9f2 | |||
6a07e5cdde | |||
7489e999ef | |||
1a54003030 | |||
28c8e24847 | |||
b5b7befd34 | |||
2790105a7d | |||
f0bda2ee24 | |||
04bd134e3e | |||
c23b84bcea | |||
de690dfd39 | |||
093b04c2c9 | |||
b24fac512a | |||
a71102eb05 | |||
7a7241746a | |||
95c3c0755b | |||
1cf2dc3d86 | |||
57d2f20255 | |||
5d671d03d2 | |||
d74a30f33e | |||
798c687547 | |||
bcf8b6621b | |||
0d98ec7cde | |||
a0a99de862 | |||
ea83698070 | |||
aa913293ef | |||
e152e0f193 | |||
bbc7eafc3d | |||
e6455165b3 | |||
2e4fc0496b | |||
045bd837b7 | |||
c4b3f46111 | |||
625089acd1 | |||
cebae3491b | |||
1d7ed112a7 | |||
fc188482d0 | |||
11cb001cfd | |||
6c1bd4a8e6 | |||
73a64ff717 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ vendor
|
||||
views_cache
|
||||
resources/upload
|
||||
resources/tmp
|
||||
composer.lock
|
0
app/admin_themes/custom/layout/main.php
Normal file → Executable file
0
app/admin_themes/custom/layout/main.php
Normal file → Executable file
5
app/admin_themes/custom/manifest.json
Normal file → Executable file
5
app/admin_themes/custom/manifest.json
Normal file → Executable file
@ -3,10 +3,11 @@
|
||||
"version": "0.1",
|
||||
"author": "Kavalar",
|
||||
"slug": "custom",
|
||||
"type": "admin_theme",
|
||||
"description": "Custom admin theme",
|
||||
"preview": "nrnv2024_640x360.jpg",
|
||||
"resource": "/resources/custom",
|
||||
"resource_path": "{RESOURCES}/custom",
|
||||
"resource": "/resources/admin_themes/custom",
|
||||
"resource_path": "{RESOURCES}/admin_themes/custom",
|
||||
"layout": "main.php",
|
||||
"theme_path": "{APP}/admin_themes/{slug}",
|
||||
"layout_path": "{APP}/admin_themes/{slug}/layout"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Photo",
|
||||
"version": "0.1",
|
||||
"version": "0.2",
|
||||
"author": "ITGuild",
|
||||
"slug": "photo",
|
||||
"type": "additional_property",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Tags",
|
||||
"version": "0.1",
|
||||
"version": "0.1.1",
|
||||
"author": "ITGuild",
|
||||
"slug": "tag",
|
||||
"type": "additional_property",
|
||||
|
8
app/themes/custom/CustomTheme.php
Normal file
8
app/themes/custom/CustomTheme.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace app\themes\custom;
|
||||
|
||||
class CustomTheme extends \kernel\app_themes\custom\CustomTheme
|
||||
{
|
||||
|
||||
}
|
18
app/themes/custom/assets/CustomThemesAssets.php
Normal file
18
app/themes/custom/assets/CustomThemesAssets.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\themes\custom\assets;
|
||||
|
||||
use kernel\Assets;
|
||||
|
||||
class CustomThemesAssets extends Assets
|
||||
{
|
||||
protected function createCSS(): void
|
||||
{
|
||||
$this->registerCSS(slug: "main", resource: "/css/styles.css");
|
||||
}
|
||||
|
||||
protected function createJS(): void
|
||||
{
|
||||
$this->registerJS(slug: "webpack", resource: "/js/scripts.js");
|
||||
}
|
||||
}
|
28
app/themes/custom/controllers/MainController.php
Normal file
28
app/themes/custom/controllers/MainController.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace app\themes\custom\controllers;
|
||||
|
||||
use kernel\Controller;
|
||||
|
||||
class MainController extends Controller
|
||||
{
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = APP_DIR . "/themes/custom/views/main/";
|
||||
$this->cgView->layout = "main.php";
|
||||
$this->cgView->layoutPath = APP_DIR . "/themes/custom/views/layout/";
|
||||
$this->cgView->addVarToLayout("resources", "/resources/themes/custom");
|
||||
}
|
||||
|
||||
public function actionIndex(): void
|
||||
{
|
||||
$this->cgView->render("index.php");
|
||||
}
|
||||
|
||||
public function actionAbout(): void
|
||||
{
|
||||
$this->cgView->render("about.php");
|
||||
}
|
||||
}
|
15
app/themes/custom/manifest.json
Normal file
15
app/themes/custom/manifest.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Custom",
|
||||
"version": "0.1",
|
||||
"author": "ItGuild",
|
||||
"slug": "custom",
|
||||
"type": "theme",
|
||||
"description": "Custom theme",
|
||||
"preview": "preview.png",
|
||||
"resource": "/resources/themes/custom",
|
||||
"resource_path": "{RESOURCES}/themes/custom",
|
||||
"theme_class": "app\\themes\\custom\\CustomTheme",
|
||||
"theme_class_file": "{APP}/themes/custom/CustomTheme.php",
|
||||
"routs": "routs/custom.php",
|
||||
"dependence": "photo,tag"
|
||||
}
|
12
app/themes/custom/routs/custom.php
Normal file
12
app/themes/custom/routs/custom.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
|
||||
|
||||
App::$collector->get('/', [\app\themes\custom\controllers\MainController::class, 'actionIndex']);
|
||||
App::$collector->get('/about', [\app\themes\custom\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']);
|
||||
|
||||
|
||||
|
92
app/themes/custom/views/layout/main.php
Normal file
92
app/themes/custom/views/layout/main.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* @var string $content
|
||||
* @var string $resources
|
||||
* @var string $title
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
$assets = new \app\themes\custom\assets\CustomThemesAssets($resources);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
|
||||
<?php $assets->getCSSAsSTR(); ?>
|
||||
<meta name="description" content=""/>
|
||||
<meta name="author" content=""/>
|
||||
<title><?= $title ?></title>
|
||||
<?= $view->getMeta() ?>
|
||||
<link rel="icon" type="image/x-icon" href="<?= $resources ?>/assets/favicon.ico"/>
|
||||
<!-- Font Awesome icons (free version)-->
|
||||
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
|
||||
<!-- Google fonts-->
|
||||
<link href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet"
|
||||
type="text/css"/>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800"
|
||||
rel="stylesheet" type="text/css"/>
|
||||
<!-- Core theme CSS (includes Bootstrap)-->
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navigation-->
|
||||
<nav class="navbar navbar-expand-lg navbar-light" id="mainNav">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<a class="navbar-brand" href="/">Custom theme</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive"
|
||||
aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
|
||||
Menu
|
||||
<i class="fas fa-bars"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||
<ul class="navbar-nav ms-auto py-4 py-lg-0">
|
||||
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="/">На главную</a></li>
|
||||
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="/about">О нас</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<?= $content ?>
|
||||
|
||||
<!-- Footer-->
|
||||
<footer class="border-top">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<ul class="list-inline text-center">
|
||||
<li class="list-inline-item">
|
||||
<a href="#!">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fas fa-circle fa-stack-2x"></i>
|
||||
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<a href="#!">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fas fa-circle fa-stack-2x"></i>
|
||||
<i class="fab fa-facebook-f fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<a href="#!">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fas fa-circle fa-stack-2x"></i>
|
||||
<i class="fab fa-github fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="small text-center text-muted fst-italic">Copyright © IT Guild Micro Framework</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<!-- Bootstrap core JS-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<!-- Core theme JS-->
|
||||
<?php $assets->getJSAsStr(); ?>
|
||||
</body>
|
||||
</html>
|
36
app/themes/custom/views/main/about.php
Normal file
36
app/themes/custom/views/main/about.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @var string $resources;
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
$view->setTitle("Старт Bootstrap");
|
||||
$view->setMeta([
|
||||
'description' => 'Дефолтная bootstrap тема'
|
||||
]);
|
||||
?>
|
||||
<!-- Page Header-->
|
||||
<header class="masthead" style="background-image: url('<?= $resources ?>/assets/img/about-bg.jpeg')">
|
||||
<div class="container position-relative px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<div class="page-heading">
|
||||
<h1>About Me</h1>
|
||||
<span class="subheading">This is what I do.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<!-- Main Content-->
|
||||
<main class="mb-4">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe nostrum ullam eveniet pariatur voluptates odit, fuga atque ea nobis sit soluta odio, adipisci quas excepturi maxime quae totam ducimus consectetur?</p>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius praesentium recusandae illo eaque architecto error, repellendus iusto reprehenderit, doloribus, minus sunt. Numquam at quae voluptatum in officia voluptas voluptatibus, minus!</p>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut consequuntur magnam, excepturi aliquid ex itaque esse est vero natus quae optio aperiam soluta voluptatibus corporis atque iste neque sit tempora!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
86
app/themes/custom/views/main/index.php
Normal file
86
app/themes/custom/views/main/index.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @var string $resources;
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
$view->setTitle("IT Guild Micro Framework");
|
||||
$view->setMeta([
|
||||
'description' => 'Default IT Guild Micro Framework theme'
|
||||
]);
|
||||
?>
|
||||
<!-- Page Header-->
|
||||
<header class="masthead" style="background-image: url('<?= $resources ?>/assets/img/home-bg.jpeg')">
|
||||
<div class="container position-relative px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<div class="site-heading">
|
||||
<h1>Clean Blog</h1>
|
||||
<span class="subheading">A Blog Theme by IT Guild Micro Framework</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<!-- Main Content-->
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<!-- Post preview-->
|
||||
<div class="post-preview">
|
||||
<a href="#!">
|
||||
<h2 class="post-title">Man must explore, and this is exploration at its greatest</h2>
|
||||
<h3 class="post-subtitle">Problems look mighty small from 150 miles up</h3>
|
||||
</a>
|
||||
<p class="post-meta">
|
||||
Posted by
|
||||
<a href="#!">Start Bootstrap</a>
|
||||
on September 24, 2023
|
||||
</p>
|
||||
</div>
|
||||
<!-- Divider-->
|
||||
<hr class="my-4" />
|
||||
<!-- Post preview-->
|
||||
<div class="post-preview">
|
||||
<a href="#!"><h2 class="post-title">I believe every human has a finite number of heartbeats. I don't intend to waste any of mine.</h2></a>
|
||||
<p class="post-meta">
|
||||
Posted by
|
||||
<a href="#!">Start Bootstrap</a>
|
||||
on September 18, 2023
|
||||
</p>
|
||||
</div>
|
||||
<!-- Divider-->
|
||||
<hr class="my-4" />
|
||||
<!-- Post preview-->
|
||||
<div class="post-preview">
|
||||
<a href="#!">
|
||||
<h2 class="post-title">Science has not yet mastered prophecy</h2>
|
||||
<h3 class="post-subtitle">We predict too much for the next year and yet far too little for the next ten.</h3>
|
||||
</a>
|
||||
<p class="post-meta">
|
||||
Posted by
|
||||
<a href="#!">Start Bootstrap</a>
|
||||
on August 24, 2023
|
||||
</p>
|
||||
</div>
|
||||
<!-- Divider-->
|
||||
<hr class="my-4" />
|
||||
<!-- Post preview-->
|
||||
<div class="post-preview">
|
||||
<a href="#!">
|
||||
<h2 class="post-title">Failure is not an option</h2>
|
||||
<h3 class="post-subtitle">Many say exploration is part of our destiny, but it’s actually our duty to future generations.</h3>
|
||||
</a>
|
||||
<p class="post-meta">
|
||||
Posted by
|
||||
<a href="#!">Start Bootstrap</a>
|
||||
on July 8, 2023
|
||||
</p>
|
||||
</div>
|
||||
<!-- Divider-->
|
||||
<hr class="my-4" />
|
||||
<!-- Pager-->
|
||||
<div class="d-flex justify-content-end mb-4"><a class="btn btn-primary text-uppercase" href="#!">Older Posts →</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
$secure_config = [
|
||||
'web_auth_type' => 'email_code', // login_password, email_code
|
||||
'token_type' => 'crypt', // random_bytes, md5, crypt, hash, JWT
|
||||
'web_auth_type' => 'login_password', // login_password, email_code
|
||||
'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT
|
||||
'token_expired_time' => "+30 days", // +1 day
|
||||
];
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
"firebase/php-jwt": "^6.10",
|
||||
"k-adam/env-editor": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.9",
|
||||
"phpmailer/phpmailer": "^6.9"
|
||||
"phpmailer/phpmailer": "^6.9",
|
||||
"zircote/swagger-php": "^4.11",
|
||||
"doctrine/annotations": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
3294
composer.lock
generated
3294
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -5,14 +5,17 @@ namespace kernel;
|
||||
use kernel\Controller;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\services\AdminThemeService;
|
||||
use kernel\services\ThemeService;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
protected AdminThemeService $adminThemeService;
|
||||
protected ThemeService $themeService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
$this->adminThemeService = new AdminThemeService();
|
||||
$this->themeService = new ThemeService();
|
||||
$active_theme = $this->adminThemeService->getActiveAdminThemeInfo();
|
||||
$this->cgView->layoutPath = getConst($active_theme['layout_path']);
|
||||
$this->cgView->layout = "/" . $active_theme['layout'];
|
||||
|
@ -7,6 +7,7 @@ namespace kernel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\user\models\User;
|
||||
use kernel\services\ModuleService;
|
||||
use kernel\services\ThemeService;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
class App
|
||||
@ -24,6 +25,8 @@ class App
|
||||
|
||||
public ModuleService $moduleService;
|
||||
|
||||
public ThemeService $themeService;
|
||||
|
||||
public static Database $db;
|
||||
|
||||
public function run(): void
|
||||
@ -53,6 +56,12 @@ class App
|
||||
foreach ($modules_routs as $rout){
|
||||
include "$rout";
|
||||
}
|
||||
|
||||
$themeService = new ThemeService();
|
||||
$activeTheme = getConst($themeService->getActiveTheme());
|
||||
if (!empty($activeTheme)){
|
||||
include $activeTheme . "/" . $themeService->getThemeRout($activeTheme);
|
||||
}
|
||||
}
|
||||
|
||||
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'>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -46,8 +46,16 @@ class CgRouteCollector extends RouteCollector
|
||||
//TODO
|
||||
}
|
||||
|
||||
public function console($route, $handler, array $filters = []): void
|
||||
/**
|
||||
* @param $route
|
||||
* @param $handler
|
||||
* @param array $filters
|
||||
* @param array $additionalInfo
|
||||
* @return void
|
||||
*/
|
||||
public function console($route, $handler, array $filters = [], array $additionalInfo = []): void
|
||||
{
|
||||
$this->addRoute(Route::GET, $route, $handler, $filters);
|
||||
$additionalInfo['type'] = "console";
|
||||
$this->addRoute(Route::GET, $route, $handler, $filters, $additionalInfo);
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace kernel;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class CgView
|
||||
{
|
||||
public string $viewPath = '';
|
||||
@ -61,6 +63,13 @@ class CgView
|
||||
private function createContent(string $viewFile, array $data = []): false|string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
if ($this->varToLayout){
|
||||
foreach ($this->varToLayout as $key => $datum) {
|
||||
${"$key"} = $datum;
|
||||
}
|
||||
}
|
||||
|
||||
$view = $this;
|
||||
foreach ($data as $key => $datum) {
|
||||
${"$key"} = $datum;
|
||||
|
@ -36,7 +36,9 @@ class FileUpload
|
||||
$newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension;
|
||||
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||
$this->uploadDir = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
|
||||
$oldMask = umask(0);
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||
umask($oldMask);
|
||||
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||
$this->destPath = $uploadFileDir . $newFileName;
|
||||
$this->uploadFile = $this->uploadDir . $newFileName;
|
||||
@ -49,7 +51,9 @@ class FileUpload
|
||||
} else {
|
||||
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||
$this->uploadDir = $uploadDir;
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
|
||||
$oldMask = umask(0);
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||
umask($oldMask);
|
||||
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||
$this->destPath = $uploadFileDir . $this->fileName;
|
||||
$this->uploadFile = $this->uploadDir . $this->fileName;
|
||||
|
@ -9,12 +9,13 @@ class Flash
|
||||
|
||||
public static function setMessage(string $type, string $msg): void
|
||||
{
|
||||
Session::start();
|
||||
self::start();
|
||||
Session::set($type, $msg);
|
||||
}
|
||||
|
||||
public static function getMessage(string $type): string
|
||||
{
|
||||
self::start();
|
||||
$msg = Session::get($type, false);
|
||||
Session::remove($type);
|
||||
|
||||
@ -23,7 +24,16 @@ class Flash
|
||||
|
||||
public static function hasMessage(string $type): bool
|
||||
{
|
||||
self::start();
|
||||
|
||||
return Session::has($type);
|
||||
}
|
||||
|
||||
public static function start()
|
||||
{
|
||||
if (!Session::isStarted()){
|
||||
Session::start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,9 +6,9 @@ class PrimaryBtn
|
||||
{
|
||||
protected string $btn = '';
|
||||
|
||||
public function __construct(string $title, string $url)
|
||||
public function __construct(string $title, string $url, $width)
|
||||
{
|
||||
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: 150px;' >$title</a>";
|
||||
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: '$width >$title</a>";
|
||||
}
|
||||
|
||||
public function fetch(): string
|
||||
@ -16,9 +16,9 @@ class PrimaryBtn
|
||||
return $this->btn;
|
||||
}
|
||||
|
||||
public static function create(string $title, string $url): PrimaryBtn
|
||||
public static function create(string $title, string $url, $width = '150px'): PrimaryBtn
|
||||
{
|
||||
return new self($title, $url);
|
||||
return new self($title, $url, $width);
|
||||
}
|
||||
|
||||
}
|
@ -17,13 +17,32 @@ class RestController
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionIndex(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$get = $request->get();
|
||||
$page = $request->get('page') ?? 1;
|
||||
$perPage = $request->get('per_page') ?? 10;
|
||||
$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) {
|
||||
$query->skip(($page - 1) * $perPage)->take($perPage);
|
||||
} else {
|
||||
@ -31,7 +50,7 @@ class RestController
|
||||
}
|
||||
|
||||
$expand = $this->expand();
|
||||
$expandParams = explode( ",", $request->get('expand') ?? "");
|
||||
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||
$finalExpand = array_intersect($expandParams, $expand);
|
||||
if ($finalExpand) {
|
||||
$res = $query->get()->load($finalExpand)->toArray();
|
||||
@ -46,14 +65,14 @@ class RestController
|
||||
{
|
||||
$expand = $this->expand();
|
||||
$request = new Request();
|
||||
$expandParams = explode( ",", $request->get('expand') ?? "");
|
||||
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$finalExpand = array_intersect($expandParams, $expand);
|
||||
if ($finalExpand){
|
||||
if ($finalExpand) {
|
||||
$model->load($finalExpand);
|
||||
}
|
||||
$res = [];
|
||||
if ($model){
|
||||
if ($model) {
|
||||
$res = $model->toArray();
|
||||
}
|
||||
|
||||
@ -64,7 +83,7 @@ class RestController
|
||||
{
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$res = [];
|
||||
if ($model){
|
||||
if ($model) {
|
||||
$res = $model->toArray();
|
||||
}
|
||||
|
||||
@ -78,7 +97,7 @@ class RestController
|
||||
{
|
||||
$request = new Request();
|
||||
$data = $request->post();
|
||||
foreach ($this->model->getFillable() as $item){
|
||||
foreach ($this->model->getFillable() as $item) {
|
||||
$this->model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
$this->model->save();
|
||||
@ -93,9 +112,11 @@ class RestController
|
||||
|
||||
$model = $this->model->where('id', $id)->first();
|
||||
|
||||
foreach ($model->getFillable() as $item){
|
||||
foreach ($model->getFillable() as $item) {
|
||||
if (!empty($data[$item])) {
|
||||
$model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
$model->save();
|
||||
$this->renderApi($model->toArray());
|
||||
@ -115,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
|
||||
*/
|
||||
\Josantonius\Session\Facades\Session::start();
|
||||
$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources)
|
||||
?>
|
||||
<!doctype html>
|
||||
<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 rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
|
||||
<?php $assets->getCSSAsSTR(); ?>
|
||||
<?php $assets->getJSAsStr(body: false); ?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="wrapper d-flex align-items-stretch">
|
||||
<nav id="sidebar">
|
||||
<div class="p-4 pt-5">
|
||||
<a href="#" class="img logo rounded-circle mb-5"
|
||||
style="background-image: url(/resources/admin_theme/images/logo.jpg);"></a>
|
||||
<a href="<?= '/admin/user/profile' ?>" class="img logo rounded-circle mb-5"
|
||||
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/default_user_photo/noPhoto.png' ?>);">
|
||||
</a>
|
||||
<p>
|
||||
<a href="<?= '/admin/user/profile' ?>">
|
||||
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
||||
</a>
|
||||
</p>
|
||||
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||
<div class="footer">
|
||||
@ -82,16 +85,13 @@
|
||||
<?php if (\kernel\Flash::hasMessage("success")): ?>
|
||||
<div class="alert alert-success alert-dismissible">
|
||||
<?= \kernel\Flash::getMessage("success"); ?>
|
||||
<button type="button" class="btn-close closeAlertBtn" ></button>
|
||||
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?= $content ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="<?= $resources ?>/js/jquery.min.js"></script>
|
||||
<script src="<?= $resources ?>/js/popper.js"></script>
|
||||
<script src="<?= $resources ?>/js/bootstrap.min.js"></script>
|
||||
<script src="<?= $resources ?>/js/main.js"></script>
|
||||
<?php $assets->getJSAsStr(); ?>
|
||||
</body>
|
||||
</html>
|
@ -3,10 +3,11 @@
|
||||
"version": "0.1",
|
||||
"author": "ItGuild",
|
||||
"slug": "default",
|
||||
"type": "admin_theme",
|
||||
"description": "Default admin theme",
|
||||
"preview": "preview.png",
|
||||
"resource": "/resources/default",
|
||||
"resource_path": "{RESOURCES}/default",
|
||||
"resource": "/resources/admin_themes/default",
|
||||
"resource_path": "{RESOURCES}/admin_themes/default",
|
||||
"layout": "main.php",
|
||||
"layout_path": "{KERNEL_ADMIN_THEMES}/default/layout"
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
"slug": "simple",
|
||||
"description": "Simple admin theme",
|
||||
"preview": "preview.png",
|
||||
"resource": "/resources/simple",
|
||||
"resource_path": "{RESOURCES}/simple",
|
||||
"resource": "/resources/admin_themes/simple",
|
||||
"resource_path": "{RESOURCES}/admin_themes/simple",
|
||||
"layout": "main.php",
|
||||
"layout_path": "{KERNEL_ADMIN_THEMES}/simple/layout"
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
@ -30,8 +30,7 @@ class TagModule extends Module
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag");
|
||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag_entity");
|
||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Тэги",
|
||||
@ -49,11 +48,17 @@ class TagModule extends Module
|
||||
OptionService::createFromParams("entity_tag_list", "{}", "Список тегов");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("tag");
|
||||
$this->menuService->removeItemBySlug("tag_settings");
|
||||
|
||||
OptionService::removeOptionByKey("entity_tag_list");
|
||||
|
||||
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tag/migrations");
|
||||
}
|
||||
|
||||
public function formInputs(string $entity, Model $model = null): void
|
||||
|
0
kernel/app_modules/tag/controllers/TagController.php
Executable file → Normal file
0
kernel/app_modules/tag/controllers/TagController.php
Executable file → Normal file
0
kernel/app_modules/tag/controllers/TagEntityController.php
Executable file → Normal file
0
kernel/app_modules/tag/controllers/TagEntityController.php
Executable file → Normal file
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
@ -28,4 +29,5 @@ return new class extends Migration
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('tag');
|
||||
}
|
||||
|
||||
};
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
0
kernel/app_modules/tag/models/Tag.php
Executable file → Normal file
0
kernel/app_modules/tag/models/Tag.php
Executable file → Normal file
0
kernel/app_modules/tag/models/TagEntity.php
Executable file → Normal file
0
kernel/app_modules/tag/models/TagEntity.php
Executable file → Normal file
0
kernel/app_modules/tag/models/forms/CreateTagEntityForm.php
Executable file → Normal file
0
kernel/app_modules/tag/models/forms/CreateTagEntityForm.php
Executable file → Normal file
0
kernel/app_modules/tag/models/forms/CreateTagForm.php
Executable file → Normal file
0
kernel/app_modules/tag/models/forms/CreateTagForm.php
Executable file → Normal file
0
kernel/app_modules/tag/routs/tag.php
Executable file → Normal file
0
kernel/app_modules/tag/routs/tag.php
Executable file → Normal file
0
kernel/app_modules/tag/service/TagEntityService.php
Executable file → Normal file
0
kernel/app_modules/tag/service/TagEntityService.php
Executable file → Normal file
0
kernel/app_modules/tag/service/TagService.php
Executable file → Normal file
0
kernel/app_modules/tag/service/TagService.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag/form.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag/form.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag/index.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag/index.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag/view.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag/view.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag_entity/index.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag_entity/index.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag_entity/view.php
Executable file → Normal file
0
kernel/app_modules/tag/views/tag_entity/view.php
Executable file → Normal file
31
kernel/app_themes/custom/CustomTheme.php
Normal file
31
kernel/app_themes/custom/CustomTheme.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_themes\custom;
|
||||
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class CustomTheme
|
||||
{
|
||||
public MenuService $menuService;
|
||||
public MigrationService $migrationService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
$this->migrationService = new MigrationService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
}
|
8
kernel/app_themes/custom/services/CustomThemeService.php
Normal file
8
kernel/app_themes/custom/services/CustomThemeService.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_themes\custom\services;
|
||||
|
||||
class CustomThemeService
|
||||
{
|
||||
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
namespace kernel\console;
|
||||
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class Out
|
||||
{
|
||||
private $foreground_colors = array();
|
||||
@ -64,6 +66,11 @@ class Out
|
||||
echo $this->get($string, $foreground_color, $background_color) . "\n";
|
||||
}
|
||||
|
||||
public function inLine($string, $foreground_color = null, $background_color = null): void
|
||||
{
|
||||
echo $this->get($string, $foreground_color, $background_color) ;
|
||||
}
|
||||
|
||||
// Returns all foreground color names
|
||||
public function getForegroundColors()
|
||||
{
|
||||
@ -75,4 +82,16 @@ class Out
|
||||
{
|
||||
return array_keys($this->background_colors);
|
||||
}
|
||||
|
||||
// public function printHeaderTable(): void
|
||||
// {
|
||||
// echo "\n+-----------------------------+-----------------------------+-----------------------------+-----------------------------+\n";
|
||||
// printf("%-30s", "| Routs");
|
||||
// printf("%-30s", "| Description");
|
||||
// printf("%-30s", "| Params");
|
||||
// printf("%-30s", "| Params description");
|
||||
// printf("%-30s", "|");
|
||||
// echo "\n+-----------------------------+-----------------------------+-----------------------------+-----------------------------+\n";
|
||||
// }
|
||||
|
||||
}
|
@ -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",
|
||||
|
@ -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('Message: Ошибка чтения архива', 'red');
|
||||
$this->out->r("Ошибка установки темы админ-панели", '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');
|
||||
} else {
|
||||
$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->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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -27,7 +27,7 @@ class KernelController extends ConsoleController
|
||||
|
||||
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
||||
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel';
|
||||
$this->files->copy_folder(KERNEL_DIR, $tmpKernelDirFull);
|
||||
$this->files->copyKernelFolder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull);
|
||||
$this->out->r("Ядро скопировано во временную папку", 'green');
|
||||
} else {
|
||||
$this->out->r("Ядро не найдено", 'red');
|
||||
@ -35,7 +35,7 @@ class KernelController extends ConsoleController
|
||||
|
||||
if (file_exists(ROOT_DIR . '/bootstrap')) {
|
||||
$tmpBootstrapDirFull = RESOURCES_DIR . '/tmp/ad/kernel/bootstrap';
|
||||
$this->files->copy_folder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull);
|
||||
$this->files->copyKernelFolder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull);
|
||||
$this->out->r("/bootstrap скопирован во временную папку", 'green');
|
||||
} else {
|
||||
$this->out->r("/bootstrap не найден", 'red');
|
||||
@ -65,11 +65,19 @@ class KernelController extends ConsoleController
|
||||
$this->out->r("/composer.json не найден", 'red');
|
||||
}
|
||||
|
||||
if (!is_dir(RESOURCES_DIR . '/tmp/app')) {
|
||||
mkdir(RESOURCES_DIR . '/tmp/app');
|
||||
if (!is_dir(RESOURCES_DIR . '/tmp/kernel')) {
|
||||
mkdir(RESOURCES_DIR . '/tmp/kernel');
|
||||
}
|
||||
|
||||
if (file_exists(KERNEL_DIR . '/manifest.json')) {
|
||||
$manifest = json_decode(file_get_contents(KERNEL_DIR . '/manifest.json'), true);
|
||||
$version = $manifest['version'] ?? '';
|
||||
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel_v' . $version . '.igk');
|
||||
}
|
||||
else {
|
||||
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk');
|
||||
}
|
||||
|
||||
$this->files->recursiveRemoveDir(RESOURCES_DIR . '/tmp/ad/kernel/');
|
||||
}
|
||||
|
||||
@ -91,11 +99,11 @@ class KernelController extends ConsoleController
|
||||
$zip->extractTo($tmpKernelDirFull);
|
||||
$zip->close();
|
||||
$this->files->recursiveRemoveKernelDir();
|
||||
$this->files->copy_folder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
|
||||
$this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
|
||||
|
||||
if (isset($this->argv['bootstrap'])) {
|
||||
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
|
||||
$this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
|
||||
$this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
|
||||
copy($tmpKernelDirFull . '/bootstrap.php' , ROOT_DIR . '/bootstrap.php');
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,23 @@ class MainController extends ConsoleController
|
||||
|
||||
public function actionHelp(): void
|
||||
{
|
||||
// Debug::dd(App::$collector->getData());
|
||||
// foreach (App::$collector->getDescriptions() as $description){
|
||||
// $this->out->r($description, "green");
|
||||
// }
|
||||
$routs = App::$collector->getData()->getStaticRoutes();
|
||||
foreach ($routs as $rout => $data){
|
||||
$additionalInfo = $data['GET'][3];
|
||||
if (isset($additionalInfo['description']) and $additionalInfo['type'] === "console"){
|
||||
$this->out->inLine($rout . " - ", "green");
|
||||
$this->out->inLine($additionalInfo['description'], 'yellow');
|
||||
$this->out->r("");
|
||||
if (isset($additionalInfo['params'])){
|
||||
foreach ($additionalInfo['params'] as $key => $param){
|
||||
$this->out->inLine($key . " - ", "green");
|
||||
$this->out->inLine($param, 'yellow');
|
||||
$this->out->r("");
|
||||
}
|
||||
}
|
||||
$this->out->r("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -71,11 +71,16 @@ class MigrationController extends ConsoleController
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
if (isset($this->argv['path'])){
|
||||
$migrationPaths = [ROOT_DIR . $this->argv['path']];
|
||||
}
|
||||
else {
|
||||
if (\kernel\App::$db->schema->hasTable('option')) {
|
||||
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
|
||||
} else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $m->run($migrationPaths);
|
||||
foreach ($res as $re) {
|
||||
@ -94,7 +99,13 @@ class MigrationController extends ConsoleController
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
//$migrationPaths = array_merge(App::$migrationsPaths, [WORKSPACE_DIR . '/console/migrations']);
|
||||
if (isset($this->argv['path'])){
|
||||
$migrationPaths = [ROOT_DIR . $this->argv['path']];
|
||||
}
|
||||
else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
}
|
||||
|
||||
$res = $m->rollback($migrationPaths, ['step' => $step]);
|
||||
print_r($step);
|
||||
foreach ($res as $re) {
|
||||
|
73
kernel/console/controllers/ThemeController.php
Normal file
73
kernel/console/controllers/ThemeController.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\console\controllers;
|
||||
|
||||
use kernel\console\ConsoleController;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\models\Option;
|
||||
use kernel\services\AdminThemeService;
|
||||
use kernel\services\ThemeService;
|
||||
use ZipArchive;
|
||||
|
||||
class ThemeController extends ConsoleController
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function actionInstallTheme(): void
|
||||
{
|
||||
if (!isset($this->argv['path'])) {
|
||||
throw new \Exception('Missing theme path "--path" specified');
|
||||
}
|
||||
|
||||
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
||||
$themeService = new ThemeService();
|
||||
if ($themeService->install($this->argv['path'])) {
|
||||
$this->out->r("Тема сайта установлена", 'green');
|
||||
} else {
|
||||
$this->out->r("Ошибка установки темы сайта", 'red');
|
||||
}
|
||||
} else {
|
||||
$this->out->r("Тема сайта не найдена", 'red');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function actionUninstallTheme(): void
|
||||
{
|
||||
if (!isset($this->argv['path'])) {
|
||||
throw new \Exception('Missing theme path "--path" specified');
|
||||
}
|
||||
|
||||
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
||||
$themeService = new ThemeService();
|
||||
$themeService->uninstall($this->argv['path']);
|
||||
$this->out->r("Тема сайта удалена", 'green');
|
||||
} else {
|
||||
$this->out->r("Тема сайта не найдена", 'red');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function actionPackTheme(): void
|
||||
{
|
||||
if (!isset($this->argv['path'])) {
|
||||
throw new \Exception('Missing theme path "--path" specified');
|
||||
}
|
||||
|
||||
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
||||
$themeService = new ThemeService();
|
||||
$themeService->pack($this->argv['path']);
|
||||
$this->out->r("Тема сайта заархивирована", 'green');
|
||||
} else {
|
||||
$this->out->r("Тема сайта не найдена", 'red');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
@ -1,44 +1,115 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\console\controllers\MigrationController;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]);
|
||||
App::$collector->console("help", [\kernel\console\controllers\MainController::class, "actionHelp"]);
|
||||
|
||||
App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('run', [\kernel\console\controllers\MigrationController::class, 'actionRun']);
|
||||
App::$collector->console('init', [\kernel\console\controllers\MigrationController::class, 'actionCreateMigrationTable']);
|
||||
App::$collector->console('create', [\kernel\console\controllers\MigrationController::class, 'actionCreate']);
|
||||
App::$collector->console('rollback', [\kernel\console\controllers\MigrationController::class, 'actionRollback']);
|
||||
App::$collector->console('run',
|
||||
[MigrationController::class, 'actionRun'],
|
||||
additionalInfo: ['description' => 'Запуск существующих миграций']
|
||||
);
|
||||
App::$collector->console('init',
|
||||
[MigrationController::class, 'actionCreateMigrationTable'],
|
||||
additionalInfo: ['description' => 'Инициализация миграций']
|
||||
);
|
||||
App::$collector->console('create',
|
||||
[MigrationController::class, 'actionCreate'],
|
||||
additionalInfo: ['description' => 'Создание миграции', 'params' => ['--name' => 'Название миграции', '--path' => 'Путь по которому будет создана миграция']]
|
||||
);
|
||||
App::$collector->console('rollback',
|
||||
[MigrationController::class, 'actionRollback'],
|
||||
additionalInfo: ['description' => 'Откатить миграции']
|
||||
);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('install', [\kernel\console\controllers\AdminThemeController::class, 'actionInstallTheme']);
|
||||
App::$collector->console('uninstall', [\kernel\console\controllers\AdminThemeController::class, 'actionUninstallTheme']);
|
||||
App::$collector->console('install',
|
||||
[\kernel\console\controllers\AdminThemeController::class, 'actionInstallTheme'],
|
||||
additionalInfo: ['description' => 'Установить тему админ-панели', 'params' => ['--path' => 'Путь к устанавливаемой теме']]
|
||||
);
|
||||
App::$collector->console('uninstall',
|
||||
[\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" => "theme"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('install',
|
||||
[\kernel\console\controllers\ThemeController::class, 'actionInstallTheme'],
|
||||
additionalInfo: ['description' => 'Установить тему сайта', 'params' => ['--path' => 'Путь к устанавливаемой теме']]
|
||||
);
|
||||
App::$collector->console('uninstall',
|
||||
[\kernel\console\controllers\ThemeController::class, 'actionUninstallTheme'],
|
||||
additionalInfo: ['description' => 'Удалить тему сайта', 'params' => ['--path' => 'Путь к удаляемой теме']]
|
||||
);
|
||||
App::$collector->console('pack',
|
||||
[\kernel\console\controllers\ThemeController::class, 'actionPackTheme'],
|
||||
additionalInfo: ['description' => 'Заархивировать тему сайта', 'params' => ['--path' => 'Путь к теме, которую нужно заархивировать']]
|
||||
);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "secure"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('create-secret-key', [\kernel\console\controllers\SecureController::class, 'actionCreateSecretKey']);
|
||||
App::$collector->console('create-secret-key',
|
||||
[\kernel\console\controllers\SecureController::class, 'actionCreateSecretKey'],
|
||||
additionalInfo: ['description' => 'Генерация секрктного ключа и запись его в .env']
|
||||
);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('init', [\kernel\console\controllers\AdminConsoleController::class, 'actionInit']);
|
||||
App::$collector->console('init',
|
||||
[\kernel\console\controllers\AdminConsoleController::class, 'actionInit'],
|
||||
additionalInfo: ['description' => 'Инициализация админ-панели']
|
||||
);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "module"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']);
|
||||
App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']);
|
||||
App::$collector->console('pack', [\kernel\console\controllers\ModuleController::class, 'actionPackModule']);
|
||||
App::$collector->console('update', [\kernel\console\controllers\ModuleController::class, 'actionUpdateModule']);
|
||||
App::$collector->console('construct', [\kernel\console\controllers\ModuleController::class, 'actionConstructModule']);
|
||||
App::$collector->console('mk', [\kernel\console\controllers\ModuleController::class, 'actionMk']);
|
||||
App::$collector->console('install',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionInstallModule'],
|
||||
additionalInfo: ['description' => 'Установка модуля', 'params' => ['--path' => 'Путь к устанавливаемому модулю']]
|
||||
);
|
||||
App::$collector->console('uninstall',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionUninstallModule'],
|
||||
additionalInfo: ['description' => 'Удалить модуль', 'params' => ['--path' => 'Путь к удаляемому модулю']]
|
||||
);
|
||||
App::$collector->console('pack',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionPackModule'],
|
||||
additionalInfo: ['description' => 'Заархивировать модуль', 'params' => ['--path' => 'Путь к модулю, который нужно заархивировать']]
|
||||
);
|
||||
App::$collector->console('update',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionUpdateModule'],
|
||||
additionalInfo: ['description' => 'Обновить модуль', 'params' => ['--path' => 'Путь к архиву с модулем']]
|
||||
);
|
||||
App::$collector->console('construct',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionConstructModule'],
|
||||
additionalInfo: ['description' => 'Сгенерировать модуль']
|
||||
);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "kernel"], callback: function (RouteCollector $router){
|
||||
// App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']);
|
||||
// App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']);
|
||||
App::$collector->console('pack', [\kernel\console\controllers\KernelController::class, 'actionPackKernel']);
|
||||
App::$collector->console('update', [\kernel\console\controllers\KernelController::class, 'actionUpdateKernel']);
|
||||
App::$collector->console('pack',
|
||||
[\kernel\console\controllers\KernelController::class, 'actionPackKernel'],
|
||||
additionalInfo: ['description' => 'Заархивировать ядро', 'params' => ['--path' => 'Путь к ядру']]
|
||||
);
|
||||
App::$collector->console('update',
|
||||
[\kernel\console\controllers\KernelController::class, 'actionUpdateKernel'],
|
||||
additionalInfo: [
|
||||
'description' => 'Обновить модуль',
|
||||
'params' =>
|
||||
[
|
||||
'--path' => 'Путь к архиву ядра',
|
||||
'bootstrap' => 'Обновить bootstrap',
|
||||
'composer' => 'Обновить composer',
|
||||
'env' => 'Обновить .env.example'
|
||||
]
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -6,11 +6,8 @@ use DirectoryIterator;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use Josantonius\Session\Facades\Session;
|
||||
use kernel\AdminController;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\models\Option;
|
||||
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
||||
use kernel\modules\user\service\UserService;
|
||||
use kernel\Request;
|
||||
use kernel\services\ModuleService;
|
||||
|
||||
|
23
kernel/filters/BootstrapSelectFilter.php
Normal file
23
kernel/filters/BootstrapSelectFilter.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\filters;
|
||||
|
||||
use itguild\forms\builders\SelectBuilder;
|
||||
use Itguild\Tables\Filter\Filter;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class BootstrapSelectFilter extends Filter
|
||||
{
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
$select = SelectBuilder::build($this->name, [
|
||||
'class' => 'form-control',
|
||||
'options' => $this->params['options'],
|
||||
'value' => $this->value,
|
||||
'prompt' => $this->params['prompt'] ?? null,
|
||||
]);
|
||||
|
||||
return "<td>" . $select->create()->fetch() . "</td>";
|
||||
}
|
||||
}
|
21
kernel/filters/BootstrapTextFilter.php
Normal file
21
kernel/filters/BootstrapTextFilter.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\filters;
|
||||
|
||||
use itguild\forms\builders\TextInputBuilder;
|
||||
use Itguild\Tables\Filter\Filter;
|
||||
|
||||
class BootstrapTextFilter extends Filter
|
||||
{
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$textInput = TextInputBuilder::build($this->name, [
|
||||
'value' => $this->value,
|
||||
'class' => "form-control"
|
||||
]);
|
||||
|
||||
return "<td>" . $textInput->create()->fetch() . "</td>";
|
||||
|
||||
}
|
||||
}
|
@ -7,11 +7,38 @@ use ZipArchive;
|
||||
|
||||
class Files
|
||||
{
|
||||
public function copy_folder($d1, $d2): void
|
||||
public function copy_folder($d1, $d2, int $permissions = 0775, bool $recursive = true): void
|
||||
{
|
||||
if (is_dir($d1)) {
|
||||
if (!file_exists($d2)){
|
||||
$_d2 = mkdir($d2, permissions: 0774, recursive: true);
|
||||
$old_mask = umask(0);
|
||||
$_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive);
|
||||
umask($old_mask);
|
||||
if (!$_d2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$d = dir($d1);
|
||||
while (false !== ($entry = $d->read())) {
|
||||
if ($entry != '.' && $entry != '..') {
|
||||
$this->copy_folder("$d1/$entry", "$d2/$entry");
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
} else {
|
||||
copy($d1, $d2);
|
||||
chmod($d2, permissions: $permissions);
|
||||
}
|
||||
}
|
||||
|
||||
public function copyKernelFolder($d1, $d2, int $permissions = 0775, bool $recursive = true): void
|
||||
{
|
||||
if (is_dir($d1)) {
|
||||
if (!file_exists($d2)){
|
||||
$old_mask = umask(0);
|
||||
$_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive);
|
||||
umask($old_mask);
|
||||
if (!$_d2) {
|
||||
return;
|
||||
}
|
||||
@ -20,12 +47,13 @@ class Files
|
||||
$d = dir($d1);
|
||||
while (false !== ($entry = $d->read())) {
|
||||
if ($entry != '.' && $entry != '..' && $entry != 'app_modules') {
|
||||
$this->copy_folder("$d1/$entry", "$d2/$entry");
|
||||
$this->copyKernelFolder("$d1/$entry", "$d2/$entry");
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
} else {
|
||||
copy($d1, $d2);
|
||||
chmod($d2, permissions: $permissions);
|
||||
}
|
||||
}
|
||||
|
||||
|
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");
|
||||
}
|
||||
|
||||
}
|
16
kernel/helpers/Version.php
Normal file
16
kernel/helpers/Version.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\helpers;
|
||||
|
||||
class Version
|
||||
{
|
||||
public static function getIntVersionByString(string $version): int
|
||||
{
|
||||
$version = preg_replace('/[^0-9]+/', '', $version);
|
||||
return match (strlen($version)) {
|
||||
1 => intval($version) * 100,
|
||||
2 => intval($version) * 10,
|
||||
3 => intval($version),
|
||||
};
|
||||
}
|
||||
}
|
8
kernel/manifest.json
Normal file
8
kernel/manifest.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "Kernel",
|
||||
"version": "0.1.7",
|
||||
"author": "ITGuild",
|
||||
"slug": "kernel",
|
||||
"type": "kernel",
|
||||
"description": "Kernel"
|
||||
}
|
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
@ -19,12 +19,15 @@ $table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
|
||||
'baseUrl' => "/admin/settings/menu",
|
||||
]));
|
||||
$table->columns([
|
||||
'parent_id' => (function ($data) {
|
||||
'parent_id' => function ($data) {
|
||||
if ($data == 0) return null;
|
||||
return Menu::find($data)->label;
|
||||
}),
|
||||
},
|
||||
'icon_file' => function ($data) {
|
||||
return $data ? "<img src='$data' width='150px'>" : "";
|
||||
},
|
||||
'status' => function ($data) {
|
||||
return Menu::getStatus()[$data];
|
||||
}
|
||||
]);
|
||||
$table->beforePrint(function () {
|
||||
|
@ -5,18 +5,19 @@ namespace kernel\modules\module_shop_client\controllers;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use Josantonius\Session\Facades\Session;
|
||||
use kernel\AdminController;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\helpers\SMTP;
|
||||
use kernel\Mailing;
|
||||
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
||||
use kernel\Request;
|
||||
use kernel\services\AdminThemeService;
|
||||
use kernel\services\KernelService;
|
||||
use kernel\services\ModuleService;
|
||||
use kernel\services\ModuleShopService;
|
||||
use kernel\services\TokenService;
|
||||
use kernel\services\ThemeService;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class ModuleShopClientController extends AdminController
|
||||
@ -24,6 +25,8 @@ class ModuleShopClientController extends AdminController
|
||||
|
||||
protected Client $client;
|
||||
protected ModuleService $moduleService;
|
||||
protected KernelService $kernelService;
|
||||
protected ModuleShopClientService $moduleShopClientService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
@ -32,6 +35,8 @@ class ModuleShopClientController extends AdminController
|
||||
|
||||
$this->client = new Client();
|
||||
$this->moduleService = new ModuleService();
|
||||
$this->kernelService = new KernelService();
|
||||
$this->moduleShopClientService = new ModuleShopClientService();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,7 +44,6 @@ class ModuleShopClientController extends AdminController
|
||||
*/
|
||||
public function actionIndex(int $page_number = 1): void
|
||||
{
|
||||
|
||||
if ($this->moduleService->issetModuleShopToken()) {
|
||||
if ($this->moduleService->isServerAvailable()) {
|
||||
|
||||
@ -55,6 +59,9 @@ class ModuleShopClientController extends AdminController
|
||||
'page_number' => $page_number,
|
||||
'module_count' => $module_count,
|
||||
'per_page' => $per_page,
|
||||
'kernelService' => new KernelService(),
|
||||
'adminThemeService' => new AdminThemeService(),
|
||||
'themeService' => new ThemeService(),
|
||||
]);
|
||||
} else {
|
||||
$this->cgView->render("module_shop_error_connection.php");
|
||||
@ -85,7 +92,7 @@ class ModuleShopClientController extends AdminController
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $module_info['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->installModule('/resources/tmp/modules/' . basename($module_info['path_to_archive']));
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно установлен.");
|
||||
Flash::setMessage("success", "Модуль успешно загружен.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
@ -112,6 +119,35 @@ class ModuleShopClientController extends AdminController
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
public function actionRenderKernelUpdateForm(): void
|
||||
{
|
||||
$this->cgView->render("kernel_update.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionKernelUpdate(): void
|
||||
{
|
||||
$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'] === 'kernel') {
|
||||
$path = $module['path_to_archive'];
|
||||
}
|
||||
}
|
||||
if (isset($path)) {
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/kernel");
|
||||
if ($this->kernelService->updateKernel('/resources/tmp/kernel/' . basename($path))) {
|
||||
Flash::setMessage("success", "Ядро успешно обновлено.");
|
||||
} else {
|
||||
Flash::setMessage("error", "Ошибка обновления ядра.");
|
||||
}
|
||||
} else {
|
||||
Flash::setMessage("error", "Ошибка обновления ядра.");
|
||||
}
|
||||
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete(): void
|
||||
{
|
||||
$request = new Request();
|
||||
@ -123,6 +159,52 @@ class ModuleShopClientController extends AdminController
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
public function actionSearch(int $page_number = 1): void
|
||||
{
|
||||
$request = new Request();
|
||||
$filters = $request->get();
|
||||
if ($this->moduleService->issetModuleShopToken()) {
|
||||
if ($this->moduleService->isServerAvailable()) {
|
||||
// $modules_info = [];
|
||||
$per_page = 8;
|
||||
$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 $key => $module) {
|
||||
foreach ($filters as $column => $value) {
|
||||
if ($value === '') continue;
|
||||
if (is_numeric($value)) {
|
||||
if ($module[$column] !== $value) {
|
||||
unset($modules_info[$key]);
|
||||
}
|
||||
} elseif (is_string($value)) {
|
||||
if (!str_contains($module[$column], $value)) {
|
||||
unset($modules_info[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$module_count = count($modules_info);
|
||||
$modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page);
|
||||
|
||||
$this->cgView->render("index.php", [
|
||||
'modules_info' => $modules_info,
|
||||
'moduleService' => $this->moduleService,
|
||||
'page_number' => $page_number,
|
||||
'module_count' => $module_count,
|
||||
'per_page' => $per_page,
|
||||
'kernelService' => new KernelService(),
|
||||
'adminThemeService' => new AdminThemeService(),
|
||||
'filterValues' => $filters
|
||||
]);
|
||||
} else {
|
||||
$this->cgView->render("module_shop_error_connection.php");
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->cgView->render("login_at_module_shop.php");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@ -131,17 +213,10 @@ class ModuleShopClientController extends AdminController
|
||||
$request = new Request();
|
||||
$address = $request->post("email");
|
||||
|
||||
// $mailing = new Mailing();
|
||||
// $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [
|
||||
// 'address' => $address,
|
||||
// 'subject' => "Код авторизации",
|
||||
// "from_name" => $_ENV['APP_NAME']
|
||||
// ]);
|
||||
|
||||
$moduleShopService = new ModuleShopService();
|
||||
$result = $moduleShopService->email_auth($address);
|
||||
|
||||
if ($result['status'] == 'success'){
|
||||
if ($result['status'] == 'success') {
|
||||
$this->cgView->render('enter_code.php', ['email' => $address]);
|
||||
}
|
||||
|
||||
@ -153,17 +228,10 @@ class ModuleShopClientController extends AdminController
|
||||
$request = new Request();
|
||||
$code = $request->post("code");
|
||||
|
||||
// $mailing = new Mailing();
|
||||
// $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [
|
||||
// 'address' => $address,
|
||||
// 'subject' => "Код авторизации",
|
||||
// "from_name" => $_ENV['APP_NAME']
|
||||
// ]);
|
||||
|
||||
$moduleShopService = new ModuleShopService();
|
||||
$result = $moduleShopService->code_check($code);
|
||||
|
||||
if (isset($result['access_token'])){
|
||||
if (isset($result['access_token'])) {
|
||||
|
||||
$envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env");
|
||||
|
||||
@ -177,4 +245,107 @@ class ModuleShopClientController extends AdminController
|
||||
$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 {
|
||||
Flash::setMessage("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);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionThemeInstall(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$id = $request->get("id");
|
||||
$themeInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
|
||||
|
||||
$themeInfo = json_decode($themeInfo->getBody()->getContents(), true);
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $themeInfo['path_to_archive'], RESOURCES_DIR . "/tmp/themes");
|
||||
if ($this->themeService->install('/resources/tmp/themes/' . basename($themeInfo['path_to_archive']))) {
|
||||
Flash::setMessage("success", "Тема сайта успешно загружена.");
|
||||
} else {
|
||||
Session::start();
|
||||
Session::set("error", implode(";", $this->themeService->getErrors()));
|
||||
}
|
||||
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionThemeUpdate(): 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/themes");
|
||||
$this->themeService->update('/resources/tmp/themes/' . basename($path));
|
||||
Flash::setMessage("success", "Тема сайта успешно обновлена.");
|
||||
} else {
|
||||
Flash::setMessage("error", "Ошибка обновления темы сайта.");
|
||||
}
|
||||
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionThemeDelete(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$slug = $request->get("slug");
|
||||
$themeInfo = $this->themeService->getThemeInfoBySlug($slug);
|
||||
$this->themeService->uninstall($themeInfo['path']);
|
||||
|
||||
Flash::setMessage("success", "Тема сайта успешно удалена.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
}
|
@ -15,8 +15,23 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']);
|
||||
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']);
|
||||
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']);
|
||||
App::$collector->get('/search', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionSearch']);
|
||||
App::$collector->post('/auth', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAuth']);
|
||||
App::$collector->post('/code_check', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionCodeCheck']);
|
||||
App::$collector->group(["prefix" => "kernel"], function (RouteCollector $router) {
|
||||
App::$collector->get('/update_form', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionRenderKernelUpdateForm']);
|
||||
App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionKernelUpdate']);
|
||||
});
|
||||
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('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']);
|
||||
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeDelete']);
|
||||
});
|
||||
App::$collector->group(["prefix" => "theme"], function (RouteCollector $router) {
|
||||
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionThemeInstall']);
|
||||
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionThemeUpdate']);
|
||||
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionThemeDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\module_shop_client\services;
|
||||
|
||||
use kernel\helpers\RESTClient;
|
||||
|
||||
class ModuleShopClientService
|
||||
{
|
||||
// public function getModulesInfo(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface
|
||||
// {
|
||||
// $modules_info = RESTClient::request($url);
|
||||
// $modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
// return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage);
|
||||
// }
|
||||
//
|
||||
// public function getModulesInfoWithFilters(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface
|
||||
// {
|
||||
// $modules_info = RESTClient::request($url);
|
||||
// $modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
// return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage);
|
||||
// }
|
||||
}
|
@ -5,6 +5,10 @@
|
||||
* @var int $page_number
|
||||
* @var int $per_page
|
||||
* @var \kernel\services\ModuleService $moduleService
|
||||
* @var \kernel\services\KernelService $kernelService
|
||||
* @var \kernel\services\AdminThemeService $adminThemeService
|
||||
* @var \kernel\services\ThemeService $themeService
|
||||
* @var array $filterValues
|
||||
*/
|
||||
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
@ -15,6 +19,7 @@ $meta['columns'] = [
|
||||
"name" => "Название",
|
||||
"author" => "Автор",
|
||||
"version" => "Версия",
|
||||
"type" => "Тип",
|
||||
"description" => "Описание",
|
||||
"installations" => "Установки",
|
||||
"views" => "Просмотры"
|
||||
@ -36,32 +41,131 @@ $table->addAction(function ($row, $url) use ($moduleService) {
|
||||
return \kernel\widgets\IconBtn\IconBtnViewWidget::create(['url' => $url])->run();
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
if ($moduleService->isInstall($row['slug'])){
|
||||
$table->columns([
|
||||
'type' => [
|
||||
'filter' => [
|
||||
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||
'params' => [
|
||||
'options' => [
|
||||
'kernel' => 'kernel',
|
||||
'entity' => 'entity',
|
||||
],
|
||||
'prompt' => 'Не выбрано'
|
||||
],
|
||||
'value' => $filterValues['type'] ?? ''
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$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'];
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$url = "$url/install/?id=" . $row['id'];
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$table->addAction(function ($row, $url) use ($moduleService) {
|
||||
if ($row['type'] === 'entity' || $row['type'] === 'additional_property') {
|
||||
$slug = $row['slug'];
|
||||
if ($moduleService->isInstall($slug)){
|
||||
if ($moduleService->isInstall($slug)) {
|
||||
if (!$moduleService->isLastVersion($slug)) {
|
||||
$url = "$url/update/?slug=" . $slug;
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($kernelService) {
|
||||
if ($row['type'] === 'kernel') {
|
||||
if (!$kernelService->isLastVersion()) {
|
||||
$url = "$url/kernel/update_form/";
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($adminThemeService) {
|
||||
if ($row['type'] === 'admin_theme') {
|
||||
$slug = $row['slug'];
|
||||
if ($adminThemeService->isInstall($slug)) {
|
||||
if (!$adminThemeService->isLastVersion($slug)) {
|
||||
$url = "$url/admin_theme/update/?slug=" . $row['slug'];
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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->addAction(function ($row, $url) use ($themeService) {
|
||||
if ($row['type'] === 'theme') {
|
||||
$slug = $row['slug'];
|
||||
if ($themeService->isInstall($slug)) {
|
||||
if (!$themeService->isLastVersion($slug)) {
|
||||
$url = "$url/theme/update/?slug=" . $row['slug'];
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($themeService) {
|
||||
if ($row['type'] === 'theme') {
|
||||
if ($themeService->isInstall($row['slug'])) {
|
||||
$url = "$url/theme/delete/?slug=" . $row['slug'];
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
|
||||
} else {
|
||||
$url = "$url/theme/install/?id=" . $row['id'];
|
||||
|
||||
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->afterPrint(function () {
|
||||
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
|
||||
});
|
||||
|
||||
\kernel\widgets\ModuleTabsWidget::create()->run();
|
||||
|
||||
$table->create();
|
||||
|
39
kernel/modules/module_shop_client/views/kernel_update.php
Normal file
39
kernel/modules/module_shop_client/views/kernel_update.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use itguild\forms\ActiveForm;
|
||||
|
||||
\kernel\widgets\ModuleTabsWidget::create()->run();
|
||||
|
||||
echo \kernel\helpers\Html::h(2, "Выберите нужные файлы для обновления");
|
||||
|
||||
$form = new ActiveForm();
|
||||
$form->beginForm("/admin/module_shop_client/kernel/update/", enctype: 'multipart/form-data');
|
||||
|
||||
$form->field(\itguild\forms\inputs\Select::class, "files[]", [
|
||||
'class' => "form-control",
|
||||
'multiple' => "multiple",
|
||||
])
|
||||
->setLabel("Дополнительные файлы")
|
||||
->setOptions([
|
||||
'env.example' => 'env.example',
|
||||
'bootstrap.php' => 'bootstrap',
|
||||
'composer.json' => 'composer.json',
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
|
||||
<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>
|
||||
<?php
|
||||
$form->endForm();
|
@ -15,7 +15,8 @@ $table_info = [
|
||||
"version" => "Версия",
|
||||
"description" => "Описание",
|
||||
"installations" => "Установки",
|
||||
"views" => "Просмотры"
|
||||
"views" => "Просмотры",
|
||||
"dependence" => "Зависимости"
|
||||
],
|
||||
"params" => ["class" => "table table-bordered"],
|
||||
"baseUrl" => "/admin/module_shop_client",
|
||||
|
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
@ -5,17 +5,22 @@ namespace kernel\modules\post;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class PostModule extends Module
|
||||
{
|
||||
public MenuService $menuService;
|
||||
public MigrationService $migrationService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
$this->migrationService = new MigrationService();
|
||||
}
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$this->migrationService->runAtPath("{KERNEL_MODULES}/post/migrations");
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Посты",
|
||||
"url" => "/admin/post",
|
||||
@ -26,5 +31,6 @@ class PostModule extends Module
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("post");
|
||||
$this->migrationService->rollbackAtPath("{KERNEL_MODULES}/post/migrations");
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
@ -15,11 +15,15 @@ use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$get = (new \kernel\Request())->get();
|
||||
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 3,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/post"
|
||||
'baseUrl' => "/admin/post",
|
||||
'searchPrefix' => "",
|
||||
'searchParams' => $get,
|
||||
]));
|
||||
|
||||
$view->setTitle("Список постов");
|
||||
@ -36,36 +40,57 @@ foreach ($additionals as $additional) {
|
||||
});
|
||||
}
|
||||
|
||||
//\kernel\helpers\Debug::dd($request);
|
||||
|
||||
$table->columns([
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'title' => [
|
||||
'filter' => [
|
||||
'class' => \kernel\filters\BootstrapTextFilter::class,
|
||||
'value' => $get['title'] ?? ''
|
||||
]
|
||||
],
|
||||
'content' => [
|
||||
'filter' => [
|
||||
'class' => \kernel\filters\BootstrapTextFilter::class,
|
||||
'value' => $get['content'] ?? ''
|
||||
]
|
||||
],
|
||||
'created_at' => [
|
||||
'format' => 'date:d-m-Y',
|
||||
],
|
||||
'updated_at' => function ($data) {
|
||||
if (!$data){
|
||||
if (!$data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'user_id' => (function ($data) {
|
||||
'user_id' => [
|
||||
'value' => function ($data) {
|
||||
return User::find($data)->username;
|
||||
})
|
||||
},
|
||||
'filter' => [
|
||||
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||
'params' => [
|
||||
'options' => \kernel\modules\user\service\UserService::createUsernameArr(),
|
||||
'prompt' => 'Не выбрано'
|
||||
],
|
||||
'value' => $get['user_id'] ?? '',
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return IconBtnCreateWidget::create(['url' => '/admin/post/create'])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
$table->addAction(function ($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/post/view/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
$table->addAction(function ($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/post/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
$table->addAction(function ($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
|
@ -36,6 +36,7 @@ class SecureRestController extends RestController
|
||||
$res = [];
|
||||
if ($model) {
|
||||
if (password_verify($data["password"], $model->password_hash)) {
|
||||
if ($model->access_token_expires_at < date("Y-m-d H:i:s") or $model->access_token === null){
|
||||
$model->access_token_expires_at = date("Y-m-d H:i:s", strtotime(App::$secure['token_expired_time']));
|
||||
$model->access_token = match (App::$secure['token_type']) {
|
||||
"JWT" => TokenService::JWT($_ENV['SECRET_KEY'], 'HS256'),
|
||||
@ -44,6 +45,7 @@ class SecureRestController extends RestController
|
||||
"hash" => TokenService::hash('sha256'),
|
||||
default => TokenService::random_bytes(20),
|
||||
};
|
||||
}
|
||||
|
||||
$res = [
|
||||
"access_token" => $model->access_token,
|
||||
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
@ -13,21 +13,28 @@ use kernel\services\TokenService;
|
||||
class SecureService
|
||||
{
|
||||
|
||||
public static function createSecretCode(User $user): void
|
||||
public static function createSecretCode(User $user): SecretCode
|
||||
{
|
||||
$secretCode = new SecretCode();
|
||||
$secretCode->user_id = $user->id;
|
||||
$secretCode->code = mt_rand(100000, 999999);
|
||||
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
||||
$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();
|
||||
if(!$secretCode){
|
||||
return self::createSecretCode($user);
|
||||
}
|
||||
$secretCode->code = mt_rand(100000, 999999);
|
||||
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
||||
$secretCode->save();
|
||||
|
||||
return $secretCode;
|
||||
}
|
||||
|
||||
public static function getCodeByUserId(int $user_id)
|
||||
|
33
kernel/modules/themes/ThemesModule.php
Normal file
33
kernel/modules/themes/ThemesModule.php
Normal 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");
|
||||
}
|
||||
}
|
95
kernel/modules/themes/controllers/ThemeController.php
Normal file
95
kernel/modules/themes/controllers/ThemeController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\themes\controllers;
|
||||
|
||||
use DirectoryIterator;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use Josantonius\Session\Exceptions\HeadersSentException;
|
||||
use Josantonius\Session\Exceptions\SessionNotStartedException;
|
||||
use Josantonius\Session\Exceptions\SessionStartedException;
|
||||
use Josantonius\Session\Exceptions\WrongSessionOptionException;
|
||||
use Josantonius\Session\Facades\Session;
|
||||
use kernel\AdminController;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\models\Option;
|
||||
use kernel\Request;
|
||||
use kernel\services\ModuleService;
|
||||
use kernel\services\ThemeService;
|
||||
|
||||
class ThemeController extends AdminController
|
||||
{
|
||||
public ThemeService $themeService;
|
||||
|
||||
public ModuleService $moduleService;
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/themes/views/";
|
||||
$this->themeService = new ThemeService();
|
||||
$this->moduleService = new ModuleService();
|
||||
}
|
||||
|
||||
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)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HeadersSentException
|
||||
* @throws WrongSessionOptionException
|
||||
* @throws SessionStartedException
|
||||
* @throws GuzzleException
|
||||
* @throws SessionNotStartedException
|
||||
*/
|
||||
#[NoReturn] public function actionActivate(): void
|
||||
{
|
||||
$request = new Request();
|
||||
if(!$this->themeService->setActiveTheme($request->get("p"))){
|
||||
$this->redirect("/admin/settings/themes/", 302);
|
||||
}
|
||||
|
||||
$this->cgView->render("view.php", ['data' => $this->themeService->getThemeInfo($request->get("p"))]);
|
||||
}
|
||||
|
||||
}
|
10
kernel/modules/themes/manifest.json
Normal file
10
kernel/modules/themes/manifest.json
Normal 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"
|
||||
}
|
16
kernel/modules/themes/routs/themes.php
Normal file
16
kernel/modules/themes/routs/themes.php
Normal 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']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
25
kernel/modules/themes/views/index.php
Normal file
25
kernel/modules/themes/views/index.php
Normal 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();
|
25
kernel/modules/themes/views/view.php
Normal file
25
kernel/modules/themes/views/view.php
Normal 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();
|
@ -6,6 +6,8 @@ use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\FileUpload;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\user\models\forms\CreateUserForm;
|
||||
use kernel\modules\user\models\User;
|
||||
use kernel\modules\user\service\UserService;
|
||||
@ -35,10 +37,17 @@ class UserController extends AdminController
|
||||
{
|
||||
$userForm = new CreateUserForm();
|
||||
$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->validate()){
|
||||
$user = $this->userService->create($userForm);
|
||||
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
|
||||
|
||||
@ -98,6 +107,13 @@ class UserController extends AdminController
|
||||
$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);
|
||||
|
||||
@ -128,4 +144,53 @@ class UserController extends AdminController
|
||||
$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");
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
@ -18,6 +20,7 @@ return new class extends Migration
|
||||
$table->string('username', 255)->nullable(false);
|
||||
$table->string('email', 255);
|
||||
$table->string('password_hash', 255);
|
||||
$table->string('user_photo', 255)->nullable();
|
||||
$table->integer('role')->default(1);
|
||||
$table->string('access_token', 255)->nullable(true);
|
||||
$table->dateTime('access_token_expires_at')->nullable(true);
|
||||
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string $username
|
||||
* @property string $email
|
||||
* @property string $password_hash
|
||||
* @property string $user_photo
|
||||
* @property string $access_token
|
||||
* @property string $access_token_expires_at
|
||||
* @method static find($id)
|
||||
@ -17,7 +18,7 @@ class User extends Model {
|
||||
const ADMIN_USER_ROLE = 9;
|
||||
|
||||
protected $table = 'user';
|
||||
protected $fillable = ['username', 'email', 'password_hash', 'role', 'access_token', 'access_token_expires_at'];
|
||||
protected $fillable = ['username', 'email', 'password_hash', 'user_photo', 'role', 'access_token', 'access_token_expires_at'];
|
||||
protected array $dates = ['deleted at'];
|
||||
|
||||
public static function labels(): array
|
||||
@ -25,6 +26,7 @@ class User extends Model {
|
||||
return [
|
||||
'username' => 'Логин',
|
||||
'email' => 'Email',
|
||||
'user_photo' => 'Фото профиля',
|
||||
'created_at' => 'Создан',
|
||||
'updated_at' => 'Обновлен',
|
||||
];
|
||||
|
@ -12,7 +12,8 @@ class CreateUserForm extends FormModel
|
||||
return [
|
||||
'username' => 'required|min-str-len:5|max-str-len:30',
|
||||
'password' => 'required|min-str-len:5|max-str-len:30',
|
||||
'email' => 'required|email'
|
||||
'email' => 'required|email',
|
||||
'user_photo' => ''
|
||||
];
|
||||
}
|
||||
|
||||
@ -21,7 +22,9 @@ class CreateUserForm extends FormModel
|
||||
return [
|
||||
'username' => 'required|min-str-len:5|max-str-len:30',
|
||||
'password' => '',
|
||||
'email' => 'required|email'
|
||||
'email' => 'required|email',
|
||||
'user_photo' => ''
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
|
||||
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,10 +11,15 @@ class UserService
|
||||
|
||||
public function create(FormModel $form_model): false|User
|
||||
{
|
||||
$model = User::where("username", $form_model->getItem('username'))->first();
|
||||
if ($model){
|
||||
return $model;
|
||||
}
|
||||
$model = new User();
|
||||
$model->username = $form_model->getItem('username');
|
||||
$model->email = $form_model->getItem('email');
|
||||
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
||||
$model->user_photo = $form_model->getItem('user_photo');
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
@ -29,6 +34,7 @@ class UserService
|
||||
if ($form_model->getItem('password')) {
|
||||
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
||||
}
|
||||
$user->user_photo = $form_model->getItem('user_photo');
|
||||
if ($user->save()){
|
||||
return $user;
|
||||
}
|
||||
@ -80,6 +86,28 @@ class UserService
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function getAuthUserId(): string
|
||||
{
|
||||
$user = self::getAuthUser();
|
||||
if ($user){
|
||||
return $user->id;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function getAuthUserPhoto(): string|null
|
||||
{
|
||||
$user = self::getAuthUser();
|
||||
if ($user){
|
||||
if ($user->user_photo) {
|
||||
return $user->user_photo;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getByAccessToken(string $token)
|
||||
{
|
||||
return $this->getByField("access_token", $token);
|
||||
|
@ -32,6 +32,16 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", param
|
||||
->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();
|
||||
|
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();
|
@ -17,13 +17,15 @@ use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$get = (new \kernel\Request())->get();
|
||||
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 3,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/user",
|
||||
'filters' => ['email'],
|
||||
]));
|
||||
'searchPrefix' => "",
|
||||
'searchParams' => $get,]));
|
||||
|
||||
$entityRelation = new \kernel\EntityRelation();
|
||||
$additionals = $entityRelation->getEntityRelationsBySlug("user");
|
||||
@ -37,9 +39,13 @@ foreach ($additionals as $additional) {
|
||||
$table->columns([
|
||||
'username' => [
|
||||
"filter" => [
|
||||
'class' => \Itguild\Tables\Filter\InputTextFilter::class
|
||||
'class' => \kernel\filters\BootstrapTextFilter::class,
|
||||
'value' => $get['username'] ?? null,
|
||||
]
|
||||
],
|
||||
'user_photo' => function ($data) {
|
||||
return $data ? "<img src='$data' width='150px'>" : "";
|
||||
},
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
|
@ -35,6 +35,9 @@ foreach ($additionals as $key => $additional) {
|
||||
}
|
||||
|
||||
$table->rows([
|
||||
'user_photo' => function ($data) {
|
||||
return $data ? "<img src='$data' width='300px'>" : "";
|
||||
},
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
|
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();
|
@ -2,22 +2,49 @@
|
||||
|
||||
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;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->option = new Option();
|
||||
$this->findActiveAdminTheme();
|
||||
$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();
|
||||
@ -46,7 +73,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'];
|
||||
@ -56,4 +83,153 @@ class AdminThemeService
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function getAdminThemeInfoBySlug(string $slug): false|array|string
|
||||
{
|
||||
$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 getAdminThemeDirs(): array
|
||||
{
|
||||
$adminThemePaths = Option::where("key", "admin_theme_paths")->first();
|
||||
$dirs = [];
|
||||
if ($adminThemePaths) {
|
||||
$path = json_decode($adminThemePaths->value);
|
||||
foreach ($path->paths as $p) {
|
||||
if (!is_dir(getConst($p))){
|
||||
$old_mask = umask(0);
|
||||
mkdir(getConst($p), permissions: 0775, recursive: true);
|
||||
umask($old_mask);
|
||||
}
|
||||
$dirs[] = getConst($p);
|
||||
}
|
||||
}
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
public function isInstall(string $slug): bool
|
||||
{
|
||||
$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 true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isLastVersion(string $slug): bool
|
||||
{
|
||||
if ($this->moduleService->isServerAvailable()) {
|
||||
$modulesInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true);
|
||||
|
||||
$themeInfo = $this->getAdminThemeInfoBySlug($slug);
|
||||
foreach ($modulesInfo as $mod) {
|
||||
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 . '/admin_themes/' . $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 . '/admin_themes/' . $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($path)) {
|
||||
$fileHelper->recursiveRemoveDir($path);
|
||||
}
|
||||
if (file_exists(RESOURCES_DIR . '/admin_themes/' . $themeInfo['slug'])) {
|
||||
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/admin_themes/' . $themeInfo['slug']);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(string $path): bool
|
||||
{
|
||||
if ($this->install($path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
10
kernel/services/Dependencies.php
Normal file
10
kernel/services/Dependencies.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
class Dependencies
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
99
kernel/services/KernelService.php
Normal file
99
kernel/services/KernelService.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\helpers\Version;
|
||||
use kernel\Request;
|
||||
use ZipArchive;
|
||||
|
||||
class KernelService
|
||||
{
|
||||
protected null|bool $serverAvailable = null;
|
||||
protected ModuleService $moduleService;
|
||||
protected Files $files;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->moduleService = new ModuleService();
|
||||
$this->files = new Files();
|
||||
}
|
||||
|
||||
public function getKernelInfo(): false|array|string
|
||||
{
|
||||
$info = [];
|
||||
$info['path'] = KERNEL_DIR;
|
||||
if (file_exists(KERNEL_DIR . "/manifest.json")) {
|
||||
$manifest = json_decode(file_get_contents(KERNEL_DIR . "/manifest.json"), true);
|
||||
$manifest = getConst($manifest);
|
||||
$info = array_merge($info, $manifest);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function isLastVersion(): bool
|
||||
{
|
||||
if ($this->moduleService->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
|
||||
$kernel_info = $this->getKernelInfo();
|
||||
|
||||
$kernelVersion = Version::getIntVersionByString($kernel_info['version']);
|
||||
|
||||
foreach ($modules_info as $mod) {
|
||||
$modVersion = Version::getIntVersionByString($mod['version']);
|
||||
if ($mod['slug'] === $kernel_info['slug'] && $modVersion <= $kernelVersion) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateKernel(string $path): bool
|
||||
{
|
||||
$request = new Request();
|
||||
$files = $request->post('files');
|
||||
|
||||
$zip = new ZipArchive;
|
||||
if (file_exists(ROOT_DIR . $path)) {
|
||||
$tmpKernelDir = md5(time());
|
||||
$res = $zip->open(ROOT_DIR . $path);
|
||||
if ($res === TRUE) {
|
||||
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/";
|
||||
$zip->extractTo($tmpKernelDirFull);
|
||||
$zip->close();
|
||||
$this->files->recursiveRemoveKernelDir();
|
||||
$this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file === 'bootstrap.php') {
|
||||
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
|
||||
$this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
|
||||
}
|
||||
if ($file === 'env.example') {
|
||||
copy($tmpKernelDirFull . $file , ROOT_DIR . '/.' . $file);
|
||||
chmod(ROOT_DIR . '/.' . $file, 0775);
|
||||
continue;
|
||||
}
|
||||
copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file);
|
||||
chmod(ROOT_DIR . '/' . $file, 0775);
|
||||
}
|
||||
|
||||
$this->files->recursiveRemoveDir($tmpKernelDirFull);
|
||||
unlink(ROOT_DIR . $path);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user