diff --git a/app/modules/tag/manifest.json b/app/modules/tag/manifest.json
index 456f81c..87665ad 100644
--- a/app/modules/tag/manifest.json
+++ b/app/modules/tag/manifest.json
@@ -7,5 +7,6 @@
"app_module_path": "{APP}/modules/{slug}",
"module_class": "app\\modules\\tag\\TagModule",
"module_class_file": "{APP}/modules/tag/TagModule.php",
- "routs": "routs/tag.php"
+ "routs": "routs/tag.php",
+ "dependence": "menu"
}
diff --git a/kernel/Flash.php b/kernel/Flash.php
new file mode 100644
index 0000000..83efc3f
--- /dev/null
+++ b/kernel/Flash.php
@@ -0,0 +1,29 @@
+data[$name])){
+ if (isset($this->data[$name])) {
return $this->data[$name];
}
@@ -64,4 +64,19 @@ class FormModel
return $this->validator->getProcessedErrors();
}
+ public function getErrorsStr(): string
+ {
+ $errorsArr = $this->getErrors();
+ $str = '';
+ if ($errorsArr['errors']) {
+ foreach ($errorsArr['errors'] as $key => $errorArr) {
+ foreach ($errorsArr['errors'][$key] as $error){
+ $str .= "$error
";
+ }
+ }
+ }
+
+ return $str;
+ }
+
}
\ No newline at end of file
diff --git a/kernel/Middleware.php b/kernel/Middleware.php
new file mode 100644
index 0000000..d26629d
--- /dev/null
+++ b/kernel/Middleware.php
@@ -0,0 +1,10 @@
+/css/style.css">
-
-
+
+
+ = \kernel\Flash::getMessage("error"); ?>
+
+
+
+
+
+ = \kernel\Flash::getMessage("success"); ?>
+
+
+
= $content ?>
diff --git a/kernel/admin_themes/default/layout/main.php b/kernel/admin_themes/default/layout/main.php
index e8f69b8..704683f 100644
--- a/kernel/admin_themes/default/layout/main.php
+++ b/kernel/admin_themes/default/layout/main.php
@@ -70,13 +70,18 @@
-
-
- = \Josantonius\Session\Facades\Session::get("error"); ?>
-
-
+
+
+ = \kernel\Flash::getMessage("error"); ?>
+
+
+
+ = \kernel\Flash::getMessage("success"); ?>
+
+
+
= $content ?>
diff --git a/kernel/console/controllers/KernelController.php b/kernel/console/controllers/KernelController.php
index 4b47ee6..0486071 100644
--- a/kernel/console/controllers/KernelController.php
+++ b/kernel/console/controllers/KernelController.php
@@ -5,9 +5,17 @@ namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\helpers\Files;
use kernel\services\KernelService;
+use ZipArchive;
class KernelController extends ConsoleController
{
+ protected Files $files;
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->files = new Files();
+ }
/**
* @throws \Exception
@@ -34,4 +42,40 @@ class KernelController extends ConsoleController
}
}
+ /**
+ * @throws \Exception
+ */
+ public function actionUpdateKernel()
+ {
+ if (!isset($this->argv['path'])) {
+ throw new \Exception('Missing kernel path "--path" specified');
+ }
+
+ $path = $this->argv['path'];
+
+ if (file_exists(ROOT_DIR . $path)) {
+ $zip = new ZipArchive;
+ $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->copy_folder($tmpKernelDirFull , ROOT_DIR . "/kernel");
+ $this->files->recursiveRemoveDir($tmpKernelDirFull);
+ $this->out->r('Ядро обновлено.', 'green');
+ } else {
+ $this->out->r('unable to open zip archive', 'red');
+ return false;
+ }
+ } else {
+ $this->out->r("Модуль не найден", 'red');
+ }
+ }
+
+ public function test()
+ {
+
+ }
+
}
\ No newline at end of file
diff --git a/kernel/helpers/Slug.php b/kernel/helpers/Slug.php
index 0bde8c1..cfbd995 100644
--- a/kernel/helpers/Slug.php
+++ b/kernel/helpers/Slug.php
@@ -132,9 +132,9 @@ class Slug
* @param $model
* @return string
*/
- public static function createSlug(string $title, $model = null): string
+ public static function createSlug(string $data, $model = null): string
{
- $slug = Slug::url_slug($title, ['transliterate' => true, 'lowercase' => true]);
+ $slug = Slug::url_slug($data, ['transliterate' => true, 'lowercase' => true]);
if ($model === null) {
return $slug;
}
diff --git a/kernel/middlewares/AuthMiddleware.php b/kernel/middlewares/AuthMiddleware.php
new file mode 100644
index 0000000..368ca3e
--- /dev/null
+++ b/kernel/middlewares/AuthMiddleware.php
@@ -0,0 +1,19 @@
+filter("auth", [\kernel\middlewares\AuthMiddleware::class, "handler"]);
+
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) {
- App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){
- App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){
- App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
- App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
- App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']);
- App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']);
- App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
- App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']);
- App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']);
- App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']);
+ App::$collector->group(["before" => "auth"], function (RouteCollector $router){
+ App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){
+ App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){
+ App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
+ App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
+ App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']);
+ App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']);
+ App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
+ App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']);
+ App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']);
+ App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']);
+ });
});
});
+
});
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
diff --git a/kernel/modules/menu/views/index.php b/kernel/modules/menu/views/index.php
index f9cd7c9..4f445df 100644
--- a/kernel/modules/menu/views/index.php
+++ b/kernel/modules/menu/views/index.php
@@ -6,11 +6,11 @@
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
+use kernel\IGTabel\action_column\DeleteActionColumn;
+use kernel\IGTabel\action_column\EditActionColumn;
+use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu;
-use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
-use kernel\modules\menu\table\columns\MenuEditActionColumn;
-use kernel\modules\menu\table\columns\MenuViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
'currentPage' => $page_number,
@@ -28,8 +28,8 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/settings/menu/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
});
-$table->addAction(MenuViewActionColumn::class);
-$table->addAction(MenuEditActionColumn::class);
-$table->addAction(MenuDeleteActionColumn::class);
+$table->addAction(ViewActionColumn::class);
+$table->addAction(EditActionColumn::class);
+$table->addAction(DeleteActionColumn::class);
$table->create();
$table->render();
\ No newline at end of file
diff --git a/kernel/modules/option/controllers/OptionController.php b/kernel/modules/option/controllers/OptionController.php
index db84e99..bc929df 100644
--- a/kernel/modules/option/controllers/OptionController.php
+++ b/kernel/modules/option/controllers/OptionController.php
@@ -4,6 +4,7 @@ namespace kernel\modules\option\controllers;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
+use kernel\Flash;
use kernel\helpers\Debug;
use kernel\modules\option\models\forms\CreateOptionForm;
use kernel\modules\option\models\Option;
@@ -33,9 +34,11 @@ class OptionController extends AdminController
if ($optionForm->validate()) {
$option = $this->optionService->create($optionForm);
if ($option) {
+ Flash::setMessage("success", "Опция успешно создана.");
$this->redirect('/admin/option');
}
}
+ Flash::setMessage("error", $optionForm->getErrorsStr());
$this->redirect('/admin/option/create');
}
@@ -95,6 +98,7 @@ class OptionController extends AdminController
#[NoReturn] public function actionDelete(int $id): void
{
Option::find($id)->delete();
+ Flash::setMessage("success", "Опция успешно удалена.");
$this->redirect('/admin/option');
}
diff --git a/kernel/modules/option/models/forms/CreateOptionForm.php b/kernel/modules/option/models/forms/CreateOptionForm.php
index 28c9dbf..e6b09ab 100644
--- a/kernel/modules/option/models/forms/CreateOptionForm.php
+++ b/kernel/modules/option/models/forms/CreateOptionForm.php
@@ -16,7 +16,7 @@ class CreateOptionForm extends FormModel
public function rules(): array
{
return [
- 'key' => 'required|min-str-len:1|max-str-len:50',
+ 'key' => 'required|min-str-len:3|max-str-len:50',
'value' => '',
'label' => '',
'status' => ''
diff --git a/kernel/modules/option/views/index.php b/kernel/modules/option/views/index.php
index db334b7..00ad1fc 100644
--- a/kernel/modules/option/views/index.php
+++ b/kernel/modules/option/views/index.php
@@ -6,11 +6,11 @@
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
+use kernel\IGTabel\action_column\DeleteActionColumn;
+use kernel\IGTabel\action_column\EditActionColumn;
+use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\modules\option\models\Option;
-use kernel\modules\option\table\columns\OptionDeleteActionColumn;
-use kernel\modules\option\table\columns\OptionEditActionColumn;
-use kernel\modules\option\table\columns\OptionViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Option::class, [
'current_page' => $page_number,
@@ -31,8 +31,8 @@ $table->columns([
}]
]);
-$table->addAction(OptionViewActionColumn::class);
-$table->addAction(OptionEditActionColumn::class);
-$table->addAction(OptionDeleteActionColumn::class);
+$table->addAction(ViewActionColumn::class);
+$table->addAction(EditActionColumn::class);
+$table->addAction(DeleteActionColumn::class);
$table->create();
$table->render();
\ No newline at end of file
diff --git a/kernel/modules/post/controllers/PostController.php b/kernel/modules/post/controllers/PostController.php
index a085533..b65c628 100644
--- a/kernel/modules/post/controllers/PostController.php
+++ b/kernel/modules/post/controllers/PostController.php
@@ -42,7 +42,7 @@ class PostController extends AdminController
* @throws Exception
*/
- public function actionIndex($page_number = 1): void
+ public function actionIndex(int $page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
@@ -50,7 +50,7 @@ class PostController extends AdminController
/**
* @throws Exception
*/
- public function actionView($id): void
+ public function actionView(int $id): void
{
$content = Post::find($id);
@@ -63,7 +63,7 @@ class PostController extends AdminController
/**
* @throws Exception
*/
- public function actionUpdate($id): void
+ public function actionUpdate(int $id): void
{
$model = Post::find($id);
if (!$model){
@@ -76,17 +76,16 @@ class PostController extends AdminController
/**
* @throws Exception
*/
- public function actionEdit($id): void
+ public function actionEdit(int $id): void
{
$post = Post::find($id);
if (!$post){
throw new Exception(message: "The post not found");
}
$postForm = new CreatePostForm();
- $postService = new PostService();
$postForm->load($_REQUEST);
if ($postForm->validate()) {
- $post = $postService->update($postForm, $post);
+ $post = $this->postService->update($postForm, $post);
if ($post) {
$this->redirect("/admin/post/" . $post->id);
}
@@ -94,9 +93,15 @@ class PostController extends AdminController
$this->redirect("/admin/post/update/" . $id);
}
- #[NoReturn] public function actionDelete($id): void
+ /**
+ * @throws Exception
+ */
+ #[NoReturn] public function actionDelete(int $id): void
{
$post = Post::find($id)->first();
+ if (!$post){
+ throw new Exception(message: "The post not found");
+ }
$post->delete();
$this->redirect("/admin/post/");
}
diff --git a/kernel/modules/post/views/index.php b/kernel/modules/post/views/index.php
index 03e22a0..26eb926 100644
--- a/kernel/modules/post/views/index.php
+++ b/kernel/modules/post/views/index.php
@@ -5,14 +5,11 @@
* @var int $page_number
*/
+use kernel\IGTabel\action_column\DeleteActionColumn;
+use kernel\IGTabel\action_column\EditActionColumn;
+use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\modules\post\models\Post;
-use kernel\modules\post\table\columns\PostDeleteActionColumn;
-use kernel\modules\post\table\columns\PostEditActionColumn;
-use kernel\modules\post\table\columns\PostViewActionColumn;
use kernel\modules\user\models\User;
-//use app\tables\columns\post\PostDeleteActionColumn;
-//use app\tables\columns\post\PostEditActionColumn;
-//use app\tables\columns\post\PostViewActionColumn;
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\btn\PrimaryBtn;
@@ -46,8 +43,8 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
});
-$table->addAction(PostViewActionColumn::class);
-$table->addAction(PostEditActionColumn::class);
-$table->addAction(PostDeleteActionColumn::class);
+$table->addAction(ViewActionColumn::class);
+$table->addAction(EditActionColumn::class);
+$table->addAction(DeleteActionColumn::class);
$table->create();
$table->render();
\ No newline at end of file
diff --git a/kernel/modules/secure/controllers/SecureController.php b/kernel/modules/secure/controllers/SecureController.php
index bfdcd1c..e698424 100644
--- a/kernel/modules/secure/controllers/SecureController.php
+++ b/kernel/modules/secure/controllers/SecureController.php
@@ -4,6 +4,8 @@ namespace kernel\modules\secure\controllers;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
+use kernel\Flash;
+use kernel\helpers\Debug;
use kernel\modules\secure\models\forms\LoginForm;
use kernel\modules\user\service\UserService;
@@ -25,7 +27,7 @@ class SecureController extends AdminController
$this->cgView->render('login.php');
}
- public function actionAuth(): void
+ #[NoReturn] public function actionAuth(): void
{
$loginForm = new LoginForm();
$loginForm->load($_REQUEST);
@@ -39,21 +41,23 @@ class SecureController extends AdminController
$user = $this->userService->getByField($field, $loginForm->getItem("username"));
if (!$user){
- throw new \Exception(message: "User not found");
+ Flash::setMessage("error", "User not found.");
+ $this->redirect("/admin/login", code: 302);
}
if (password_verify($loginForm->getItem("password"), $user->password_hash)) {
setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false);
- $this->redirect("/admin");
+ $this->redirect("/admin", code: 302);
} else {
- $this->redirect("/admin/login");
+ Flash::setMessage("error", "Username or password incorrect.");
+ $this->redirect("/admin/login", code: 302);
}
}
#[NoReturn] public function actionLogout(): void
{
unset($_COOKIE['user_id']);
- setcookie('user_id', "", -1, '/', $_SERVER['SERVER_NAME'], false);
+ setcookie('user_id', "", -1, '/', ".".$_SERVER['SERVER_NAME'], false);
$this->redirect("/", code: 302);
}
diff --git a/kernel/modules/secure/routs/secure.php b/kernel/modules/secure/routs/secure.php
index 9cda940..c7c8acf 100644
--- a/kernel/modules/secure/routs/secure.php
+++ b/kernel/modules/secure/routs/secure.php
@@ -3,14 +3,7 @@
use kernel\App;
use Phroute\Phroute\RouteCollector;
-App::$collector->filter("auth", function (){
- if(!isset($_COOKIE['user_id']))
- {
- header('Location: /admin/login', true, 302);
-
- return false;
- }
-});
+App::$collector->filter("auth", [\kernel\middlewares\AuthMiddleware::class, "handler"]);
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["before" => "auth"], function (RouteCollector $router){
@@ -19,4 +12,5 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/login', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogin']);
App::$collector->get('/logout', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogout']);
App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']);
-});
\ No newline at end of file
+});
+
diff --git a/kernel/modules/user/views/index.php b/kernel/modules/user/views/index.php
index 2b51add..5876e6c 100644
--- a/kernel/modules/user/views/index.php
+++ b/kernel/modules/user/views/index.php
@@ -7,11 +7,11 @@
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
+use kernel\IGTabel\action_column\DeleteActionColumn;
+use kernel\IGTabel\action_column\EditActionColumn;
+use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\modules\user\models\User;
-use kernel\modules\user\table\columns\UserDeleteActionColumn;
-use kernel\modules\user\table\columns\UserEditActionColumn;
-use kernel\modules\user\table\columns\UserViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
'currentPage' => $page_number,
@@ -45,8 +45,8 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/user/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
});
-$table->addAction(UserViewActionColumn::class);
-$table->addAction(UserEditActionColumn::class);
-$table->addAction(UserDeleteActionColumn::class);
+$table->addAction(ViewActionColumn::class);
+$table->addAction(EditActionColumn::class);
+$table->addAction(DeleteActionColumn::class);
$table->create();
$table->render();
\ No newline at end of file
diff --git a/kernel/services/AdminThemeService.php b/kernel/services/AdminThemeService.php
index 6bdc894..c833cbb 100644
--- a/kernel/services/AdminThemeService.php
+++ b/kernel/services/AdminThemeService.php
@@ -32,7 +32,6 @@ class AdminThemeService
public function setActiveAdminTheme(string $theme): void
{
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
- Debug::prn(getConst($theme));
$active_admin_theme->value = getConst($theme);
$active_admin_theme->save();
}
diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php
index 7467221..80b140c 100644
--- a/kernel/services/ModuleService.php
+++ b/kernel/services/ModuleService.php
@@ -346,6 +346,9 @@ class ModuleService
$fileHelper->copy_folder(APP_DIR . '/modules/' . $moduleName, $tmpModuleDirFull . 'app/');
$fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/');
+ if (!is_dir(RESOURCES_DIR . '/tmp/module')) {
+ mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true);
+ }
$fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.itguild');
$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
diff --git a/resources/default/js/main.js b/resources/default/js/main.js
index 4b4e790..c591409 100644
--- a/resources/default/js/main.js
+++ b/resources/default/js/main.js
@@ -16,8 +16,15 @@
$('#sidebar').toggleClass('active');
});
- $("#closeAlertBtn").click(function () {
- $("#mainAlert").alert("close");
- });
-
})(jQuery);
+
+window.addEventListener("load", function () {
+ let closeBtn = document.querySelectorAll(".closeAlertBtn");
+ closeBtn.forEach((item) => {
+ item.addEventListener("click", closeAlert);
+ });
+});
+
+function closeAlert() {
+ this.parentNode.setAttribute("style", "display: none;")
+}
\ No newline at end of file