Compare commits

..

14 Commits

Author SHA1 Message Date
2ab819ff30 v0.1.8 2025-06-22 15:27:26 +03:00
a64ed080bb v0.1.7 2025-01-28 16:44:34 +03:00
6242304843 flash msg fix 2025-01-28 12:47:44 +03:00
2655a793f5 some fix 2025-01-24 16:47:37 +03:00
de0354f9cb add dependencies to view module shop client 2025-01-24 16:26:11 +03:00
4a4d5b083f some fix 2025-01-24 16:20:15 +03:00
68b5741f46 some fix 2025-01-24 15:14:36 +03:00
fc70051761 theme service fix 2025-01-24 15:00:22 +03:00
b1dacff877 Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 14:30:49 +03:00
64a6cc4340 Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 13:59:55 +03:00
b79483dafd some 2025-01-24 13:59:03 +03:00
c69314b531 Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 12:15:48 +03:00
3c025a4cbc Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 11:56:47 +03:00
6a7cde15e9 some fix 2025-01-24 11:56:29 +03:00
41 changed files with 1603 additions and 32 deletions

View File

@ -1,6 +1,6 @@
{
"name": "Photo",
"version": "0.1",
"version": "0.2",
"author": "ITGuild",
"slug": "photo",
"type": "additional_property",

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\tag;
class TagModule extends \kernel\app_modules\tag\TagModule
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\tag\controllers;
class TagController extends \kernel\app_modules\tag\controllers\TagController
{
}

View File

@ -0,0 +1,13 @@
{
"name": "Tags",
"version": "0.1.1",
"author": "ITGuild",
"slug": "tag",
"type": "additional_property",
"description": "Tags module",
"app_module_path": "{APP}/modules/{slug}",
"module_class": "app\\modules\\tag\\TagModule",
"module_class_file": "{APP}/modules/tag/TagModule.php",
"routs": "routs/tag.php",
"dependence": "menu"
}

View File

@ -0,0 +1,2 @@
<?php
include KERNEL_APP_MODULES_DIR . "/tag/routs/tag.php";

View File

@ -0,0 +1,482 @@
<?php
namespace kernel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class EloquentDataProvider
{
protected Builder $query;
protected int $perPage = 15;
protected array $filters = [];
protected array $sort = [];
protected array $with = [];
protected array $withCount = [];
protected array $search = [];
protected array $allowedFilters = [];
protected array $allowedSorts = [];
protected array $allowedSearch = [];
protected array $defaultSort = [];
protected array $beforeQueryCallbacks = [];
protected array $afterQueryCallbacks = [];
protected array $paginationTemplates = [];
public function __construct(Builder $query)
{
$this->query = $query;
}
public function setPerPage(int $perPage): self
{
$this->perPage = max(1, $perPage);
return $this;
}
public function setFilters(array $filters): self
{
$this->filters = $filters;
return $this;
}
public function setSort(array $sort): self
{
$this->sort = $sort;
return $this;
}
public function with(array $relations): self
{
$this->with = $relations;
return $this;
}
public function withCount(array $relations): self
{
$this->withCount = $relations;
return $this;
}
public function setSearch(array $search): self
{
$this->search = $search;
return $this;
}
public function allowFilters(array $filters): self
{
$this->allowedFilters = $filters;
return $this;
}
public function allowSorts(array $sorts): self
{
$this->allowedSorts = $sorts;
return $this;
}
public function allowSearch(array $fields): self
{
$this->allowedSearch = $fields;
return $this;
}
public function setDefaultSort(array $sort): self
{
$this->defaultSort = $sort;
return $this;
}
public function beforeQuery(callable $callback): self
{
$this->beforeQueryCallbacks[] = $callback;
return $this;
}
public function afterQuery(callable $callback): self
{
$this->afterQueryCallbacks[] = $callback;
return $this;
}
protected function applyFilters(): void
{
foreach ($this->filters as $field => $value) {
if (!$this->isFilterAllowed($field)) {
continue;
}
if (is_array($value)) {
$this->applyArrayFilter($field, $value);
} elseif (Str::contains($field, '.')) {
$this->applyRelationFilter($field, $value);
} elseif ($value !== null && $value !== '') {
$this->query->where($field, $value);
}
}
}
protected function applyArrayFilter(string $field, array $value): void
{
$operator = strtolower($value[0] ?? null);
$operand = $value[1] ?? null;
switch ($operator) {
case 'in':
$this->query->whereIn($field, (array)$operand);
break;
case 'not in':
$this->query->whereNotIn($field, (array)$operand);
break;
case 'between':
$this->query->whereBetween($field, (array)$operand);
break;
case 'not between':
$this->query->whereNotBetween($field, (array)$operand);
break;
case 'null':
$this->query->whereNull($field);
break;
case 'not null':
$this->query->whereNotNull($field);
break;
case 'like':
$this->query->where($field, 'like', "%{$operand}%");
break;
case '>':
case '<':
case '>=':
case '<=':
case '!=':
$this->query->where($field, $operator, $operand);
break;
default:
$this->query->whereIn($field, $value);
}
}
protected function applyRelationFilter(string $field, $value): void
{
[$relation, $column] = explode('.', $field, 2);
$this->query->whereHas($relation, function ($query) use ($column, $value) {
if (is_array($value)) {
$query->whereIn($column, $value);
} else {
$query->where($column, $value);
}
});
}
protected function applySort(): void
{
if (empty($this->sort) && !empty($this->defaultSort)) {
$this->sort = $this->defaultSort;
}
foreach ($this->sort as $field => $direction) {
if (!$this->isSortAllowed($field)) {
continue;
}
$direction = strtolower($direction) === 'desc' ? 'desc' : 'asc';
if (Str::contains($field, '.')) {
$this->applyRelationSort($field, $direction);
} else {
$this->query->orderBy($field, $direction);
}
}
}
protected function applyRelationSort(string $field, string $direction): void
{
[$relation, $column] = explode('.', $field, 2);
$this->query->with([$relation => function ($query) use ($column, $direction) {
$query->orderBy($column, $direction);
}]);
}
protected function applySearch(): void
{
if (empty($this->search) || empty($this->allowedSearch)) {
return;
}
$searchTerm = Arr::get($this->search, 'term', '');
if (empty($searchTerm)) {
return;
}
$this->query->where(function ($query) use ($searchTerm) {
foreach ($this->allowedSearch as $field) {
if (Str::contains($field, '.')) {
[$relation, $column] = explode('.', $field, 2);
$query->orWhereHas($relation, function ($q) use ($column, $searchTerm) {
$q->where($column, 'like', "%{$searchTerm}%");
});
} else {
$query->orWhere($field, 'like', "%{$searchTerm}%");
}
}
});
}
protected function applyRelations(): void
{
if (!empty($this->with)) {
$this->query->with($this->with);
}
if (!empty($this->withCount)) {
$this->query->withCount($this->withCount);
}
}
protected function isFilterAllowed(string $field): bool
{
if (empty($this->allowedFilters)) {
return true;
}
$baseField = Str::before($field, '.');
return in_array($field, $this->allowedFilters) ||
in_array($baseField, $this->allowedFilters);
}
protected function isSortAllowed(string $field): bool
{
if (empty($this->allowedSorts)) {
return true;
}
$baseField = Str::before($field, '.');
return in_array($field, $this->allowedSorts) ||
in_array($baseField, $this->allowedSorts);
}
protected function executeCallbacks(array $callbacks): void
{
foreach ($callbacks as $callback) {
call_user_func($callback, $this->query);
}
}
/**
* Получение данных с ручной пагинацией
*/
public function getManualPaginated(int $page = 1, int $perPage = null): array
{
$perPage = $perPage ?? $this->perPage;
$this->applyRelations();
$this->applyFilters();
$this->applySearch();
$this->applySort();
$total = $this->query->count();
$results = $this->query
->offset(($page - 1) * $perPage)
->limit($perPage)
->get();
return [
'data' => $results,
'meta' => [
'total' => $total,
'per_page' => $perPage,
'current_page' => $page,
'last_page' => ceil($total / $perPage),
]
];
}
public function getAll(): \Illuminate\Database\Eloquent\Collection
{
$this->executeCallbacks($this->beforeQueryCallbacks);
$this->applyRelations();
$this->applyFilters();
$this->applySearch();
$this->applySort();
$result = $this->query->get();
$this->executeCallbacks($this->afterQueryCallbacks);
return $result;
}
public function getFirst(): ?\Illuminate\Database\Eloquent\Model
{
$this->executeCallbacks($this->beforeQueryCallbacks);
$this->applyRelations();
$this->applyFilters();
$this->applySearch();
$this->applySort();
$result = $this->query->first();
$this->executeCallbacks($this->afterQueryCallbacks);
return $result;
}
/**
* Генерирует массив с основными ссылками пагинации
*
* @param array $meta Мета-информация из getManualPaginated()
* @param string|null $baseUrl Базовый URL (если null - определит автоматически)
* @return array
*/
public function getPaginationLinks(array $meta, ?string $baseUrl = null): array
{
$currentPage = $meta['current_page'];
$lastPage = $meta['last_page'];
// Определяем базовый URL
$baseUrl = $this->normalizeBaseUrl($baseUrl);
$links = [
'first' => null,
'previous' => null,
'current' => $this->buildPageUrl($baseUrl, $currentPage),
'next' => null,
'last' => null,
];
// Первая страница (если не на первой)
if ($currentPage > 1) {
$links['first'] = $this->buildPageUrl($baseUrl, 1);
}
// Предыдущая страница
if ($currentPage > 1) {
$links['previous'] = $this->buildPageUrl($baseUrl, $currentPage - 1);
}
// Следующая страница
if ($currentPage < $lastPage) {
$links['next'] = $this->buildPageUrl($baseUrl, $currentPage + 1);
}
// Последняя страница (если не на последней)
if ($currentPage < $lastPage) {
$links['last'] = $this->buildPageUrl($baseUrl, $lastPage);
}
// Дополнительная мета-информация
$links['meta'] = [
'current_page' => $currentPage,
'last_page' => $lastPage,
'per_page' => $meta['per_page'],
'total' => $meta['total']
];
return $links;
}
/**
* Нормализует базовый URL
*/
protected function normalizeBaseUrl(?string $url): string
{
if ($url !== null) {
return $url;
}
if (function_exists('url')) {
// Laravel
return url()->current();
}
// Чистый PHP
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || ($_SERVER['SERVER_PORT'] ?? null) == 443) ? 'https://' : 'http://';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$uri = $_SERVER['REQUEST_URI'] ?? '/';
// Удаляем параметр page если он есть
$uri = preg_replace('/([?&])page=[^&]*(&|$)/', '$1', $uri);
return $protocol . $host . rtrim($uri, '?&');
}
/**
* Строит URL для конкретной страницы
*/
protected function buildPageUrl(string $baseUrl, int $page): string
{
if ($page <= 1) {
return $baseUrl; // Первая страница без параметра
}
$separator = strpos($baseUrl, '?') === false ? '?' : '&';
return $baseUrl . $separator . 'page=' . $page;
}
public function renderPaginationLinks(array $meta, string $url, int $showPages = 5): string
{
$currentPage = $meta['current_page'];
$lastPage = $meta['last_page'];
// Определяем диапазон страниц для отображения
$startPage = max(1, $currentPage - floor($showPages / 2));
$endPage = min($lastPage, $startPage + $showPages - 1);
$html = '<div class="pagination">';
// Кнопка "Назад"
if ($currentPage > 1) {
$html .= '<a href="' . $this->buildPageUrl($url, $currentPage - 1) . '" class="page-link prev">« Назад</a>';
}
// Первая страница
if ($startPage > 1) {
$html .= '<a href="' . $this->buildPageUrl($url, 1) . '" class="page-link">1</a>';
if ($startPage > 2) {
$html .= '<span class="page-dots">...</span>';
}
}
// Основные страницы
for ($i = $startPage; $i <= $endPage; $i++) {
$activeClass = $i == $currentPage ? ' active' : '';
$html .= '<a href="' . $this->buildPageUrl($url, $i) . '" class="page-link' . $activeClass . '">' . $i . '</a>';
}
// Последняя страница
if ($endPage < $lastPage) {
if ($endPage < $lastPage - 1) {
$html .= '<span class="page-dots">...</span>';
}
$html .= '<a href="' . $this->buildPageUrl($url, $lastPage) . '" class="page-link">' . $lastPage . '</a>';
}
// Кнопка "Вперед"
if ($currentPage < $lastPage) {
$html .= '<a href="' . $this->buildPageUrl($url, $currentPage + 1) . '" class="page-link next">Вперед »</a>';
}
$html .= '</div>';
return $html;
}
public function setPaginationTemplate(array $tpl)
{
}
public function getQuery(): Builder
{
return $this->query;
}
}

View File

@ -209,11 +209,11 @@ class EntityRelation
return [];
}
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug): string
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug, array $params = []): string
{
$moduleClass = $this->getAdditionalPropertyClassBySlug($additionalPropertySlug);
if ($moduleClass and method_exists($moduleClass, "getItem")) {
return $moduleClass->getItem($entity, $entity_id);
return $moduleClass->getItem($entity, $entity_id, $params);
}
return "";
@ -276,4 +276,20 @@ class EntityRelation
}
}
}
public function callModuleMethod(string $slug, string $method, array $params)
{
$module = $this->moduleService->getModuleInfoBySlug($slug);
if (isset($module['module_class'])) {
$moduleClass = new $module['module_class']();
if (method_exists($moduleClass, $method)) {
return call_user_func_array([$moduleClass, $method], $params);
} else {
echo "Метод $method не существует";
}
}
return false;
}
}

View File

@ -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();
}
}
}

View File

@ -132,6 +132,18 @@ class Request
return $_GET[$param] ?? $defaultValue;
}
/**
* @param string $param
* @return mixed
*/
public function except(string $param): mixed
{
$params = $this->get();
unset($param);
return $params;
}
/**
* Возвращает POST - параметр.

View File

@ -63,15 +63,6 @@ $assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources)
<li class="nav-item active">
<a class="nav-link" href="/admin/logout">Выход</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>

View File

@ -0,0 +1,124 @@
<?php
namespace kernel\app_modules\tag;
use Illuminate\Database\Eloquent\Model;
use itguild\forms\builders\SelectBuilder;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\models\TagEntity;
use kernel\app_modules\tag\service\TagEntityService;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\modules\option\service\OptionService;
use kernel\Request;
use kernel\services\MigrationService;
class TagModule extends Module
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");
$this->menuService->createItem([
"label" => "Тэги",
"url" => "/admin/tag",
"slug" => "tag",
]);
$this->menuService->createItem([
"label" => "Тэги",
"url" => "/admin/settings/tag",
"slug" => "tag_settings",
"parent_slug" => "settings"
]);
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
{
if (isset($model->id)) {
$value = TagEntityService::getTagsByEntity($entity, $model->id);
}
$input = SelectBuilder::build("tag[]", [
'class' => 'form-control',
'placeholder' => 'Теги',
'value' => $value ?? '',
'multiple' => "multiple",
'options' => Tag::getTagLabelByEntity($entity)
]);
$input->setLabel("Теги");
$input->create()->render();
}
public function saveInputs(string $entity, Model $model, Request $request): void
{
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
$tags = $request->post("tag");
if (is_array($tags)) {
foreach ($tags as $tag) {
$tagEntity = new TagEntity();
$tagEntity->entity = $entity;
$tagEntity->entity_id = $model->id;
$tagEntity->tag_id = $tag;
$tagEntity->save();
}
}
}
public function getItems(string $entity, Model $model): array|string
{
$tags = TagEntity::where("entity", $entity)->where("entity_id", $model->id)->with("tag")->get();
$tagsStr = "";
foreach ($tags as $tag) {
$tagsStr .= $tag->tag->label . ", ";
}
return substr($tagsStr, 0, -2);
}
public function getItem(string $entity, string $entity_id): string
{
$tags = TagEntity::where("entity", $entity)->where("entity_id", $entity_id)->get();
$tagsStr = "";
foreach ($tags as $tag) {
$tagsStr .= $tag->tag->label . ", ";
}
return substr($tagsStr, 0, -2);
}
public function deleteItems(string $entity, Model $model): void
{
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
}
}

View File

@ -0,0 +1,120 @@
<?php
namespace kernel\app_modules\tag\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\tag\models\forms\CreateTagForm;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\service\TagService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\menu\service\MenuService;
use kernel\Request;
class TagController extends AdminController
{
private TagService $tagService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/tag/";
$this->tagService = new TagService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$tagForm = new CreateTagForm();
$tagForm->load($_REQUEST);
if ($tagForm->validate()){
$tag = $this->tagService->create($tagForm);
if ($tag){
$this->redirect("/admin/tag/view/" . $tag->id);
}
}
$this->redirect("/admin/tag/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$tag = Tag::find($id);
if (!$tag){
throw new Exception(message: "The tag not found");
}
$this->cgView->render("view.php", ['tag' => $tag]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = Tag::find($id);
if (!$model){
throw new Exception(message: "The tag not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
$tag = Tag::find($id);
if (!$tag){
throw new Exception(message: "The tag not found");
}
$tagForm = new CreateTagForm();
$tagService = new TagService();
$tagForm->load($_REQUEST);
if ($tagForm->validate()) {
$tag = $tagService->update($tagForm, $tag);
if ($tag) {
$this->redirect("/admin/tag/view/" . $tag->id);
}
}
$this->redirect("/admin/tag/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
$post = Tag::find($id)->first();
$post->delete();
$this->redirect("/admin/tag/");
}
public function actionSettings(): void
{
$this->cgView->render('settingsForm.php');
}
#[NoReturn] public function actionSaveSettings(): void
{
$request = new Request();
$entities = $request->post('entity');
EntityRelation::configurationEntitiesByProperty($entities, 'tag');
Flash::setMessage("success", "Настройка прошла успешно");
$this->redirect("/admin/settings/tag", 302);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace kernel\app_modules\tag\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\tag\models\forms\CreateTagForm;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\models\TagEntity;
use kernel\app_modules\tag\service\TagEntityService;
use kernel\app_modules\tag\service\TagService;
use kernel\helpers\Debug;
use kernel\modules\menu\service\MenuService;
class TagEntityController extends AdminController
{
/**
* @return void
*/
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/tag_entity/";
}
/**
* @param $page_number
* @return void
*/
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$tagEntity = TagEntity::find($id);
if (!$tagEntity){
throw new Exception(message: "The tag entity not found");
}
$this->cgView->render("view.php", ['tagEntity' => $tagEntity]);
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public string $migration;
/**
* Run the migrations.
*/
public function up(): void
{
\kernel\App::$db->schema->create('tag', function (Blueprint $table) {
$table->increments('id');
$table->string('label', 255)->nullable(false);
$table->string('entity', 255)->nullable(false);
$table->string('slug', 255)->unique();
$table->integer('status')->default(1);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('tag');
}
};

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public string $migration;
/**
* Run the migrations.
*/
public function up(): void
{
\kernel\App::$db->schema->create('tag_entity', function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id')->nullable(false);
$table->string('entity', 255)->nullable(false);
$table->integer('entity_id')->nullable(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('tag_entity');
}
};

View File

@ -0,0 +1,61 @@
<?php
namespace kernel\app_modules\tag\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $label
* @property string $entity
* @property int $entity_id
* @property string $slug
* @property int $status
*/
class Tag extends Model
{
const DISABLE_STATUS = 0;
const ACTIVE_STATUS = 1;
protected $table = 'tag';
protected $fillable = ['label', 'slug', 'status'];
public static function labels(): array
{
return [
'label' => 'Заголовок',
'entity' => 'Сущность',
'slug' => 'Slug',
'status' => 'Статус',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
public static function getTagListByEntity(string $entity): array
{
return self::where("entity", $entity)->get()->toArray();
}
public static function getTagLabelByEntity(string $entity): array
{
$result = [];
$tags = self::getTagListByEntity($entity);
foreach ($tags as $tag){
$result[$tag['id']] = $tag['label'];
}
return $result;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace kernel\app_modules\tag\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $tag_id
* @property string $entity
* @property int $entity_id
*/
class TagEntity extends Model
{
protected $table = 'tag_entity';
protected $fillable = ['tag_id', 'entity', 'entity_id'];
public static function labels(): array
{
return [
'tag_id' => 'тег',
'entity' => 'Сущность',
'entity_id' => 'Идентификатор сущности',
];
}
public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Tag::class);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace kernel\app_modules\tag\models\forms;
use kernel\FormModel;
class CreateTagEntityForm extends FormModel
{
public function rules(): array
{
return [
'tag_id' => 'required',
'entity' => '',
'entity_id' => '',
];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace kernel\app_modules\tag\models\forms;
use kernel\FormModel;
class CreateTagForm extends FormModel
{
public function rules(): array
{
return [
'label' => 'required|min-str-len:5|max-str-len:30',
'entity' => 'required',
'slug' => '',
'status' => ''
];
}
}

View File

@ -0,0 +1,34 @@
<?php
use kernel\App;
use kernel\CgRouteCollector;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']);
});
App::$collector->group(["prefix" => "tag_entity"], function (CGRouteCollector $router) {
App::$collector->get('/', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionAdd']);
App::$collector->get('view/{id}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionDelete']);
});
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
});
});
});

View File

@ -0,0 +1,51 @@
<?php
namespace kernel\app_modules\tag\service;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\models\TagEntity;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
class TagEntityService
{
public function create(FormModel $form_model): false|TagEntity
{
$model = new TagEntity();
$model->tag_id = $form_model->getItem('tag_id');
$model->entity = $form_model->getItem('entity');
$model->entity_id = $form_model->getItem('entity_id');
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, TagEntity $tag): false|TagEntity
{
$tag->tag_id = $form_model->getItem('tag_id');
$tag->entity = $form_model->getItem('entity');
$tag->entity_id = $form_model->getItem('entity_id');
if ($tag->save()){
return $tag;
}
return false;
}
public static function getTagsByEntity(string $entity, int $entity_id): array
{
$tags= TagEntity::where("entity_id", $entity_id)->where("entity", $entity)->get();
$value = [];
foreach ($tags as $tag) {
$value[$tag->id] = $tag->tag->label;
}
return $value;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace kernel\app_modules\tag\service;
use kernel\app_modules\tag\models\Tag;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
use kernel\services\ModuleService;
class TagService
{
public function create(FormModel $form_model): false|Tag
{
$model = new Tag();
$model->label = $form_model->getItem('label');
$model->entity = $form_model->getItem('entity');
$model->status = $form_model->getItem('status');
$model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class);
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, Tag $tag): false|Tag
{
if ($tag->label !== $form_model->getItem('label')) {
$tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class);
}
$tag->label = $form_model->getItem('label');
$tag->entity = $form_model->getItem('entity');
$tag->status = $form_model->getItem('status');
if ($tag->save()){
return $tag;
}
return false;
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* @var Tag $model
*/
use kernel\app_modules\tag\models\Tag;
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag");
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [
'class' => "form-control",
'placeholder' => 'Заголовок',
'value' => $model->label ?? ''
])
->setLabel("Заголовок")
->render();
$form->field(class: \itguild\forms\inputs\Select::class, name: "entity", params: [
'class' => "form-control",
'value' => $model->entity ?? ''
])
->setLabel("Сущность")
->setOptions(\kernel\EntityRelation::getEntityList())
->render();
$form->field(\itguild\forms\inputs\Select::class, 'status', [
'class' => "form-control",
'value' => $model->status ?? ''
])
->setLabel("Статус")
->setOptions(Tag::getStatus())
->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 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();

View File

@ -0,0 +1,40 @@
<?php
/**
* @var int $page_number
*/
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\tag\models\Tag;
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(Tag::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch();
});
$table->columns([
"status" => [
"value" => function ($cell) {
return Tag::getStatus()[$cell];
}]
]);
\kernel\widgets\TagTabsWidget::create()->run();
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class);
$table->create();
$table->render();

View File

@ -0,0 +1,47 @@
<?php
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/settings/tag/update");
//\kernel\helpers\Debug::dd($value);
?>
<div class="row">
<h5>Выберите сущности, к которым хотите прикрепить теги</h5>
</div>
<?php
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
'class' => "form-control",
'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '',
'multiple' => "multiple",
])
->setLabel("Сущности")
->setOptions(\kernel\EntityRelation::getEntityList())
->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 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();

View File

@ -0,0 +1,30 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $tag
*/
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;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($tag, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () use ($tag) {
$btn = PrimaryBtn::create("Список", "/admin/tag")->fetch();
$btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch();
$btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch();
return $btn;
});
$table->rows([
'status' => (function ($data) {
return \kernel\app_modules\tag\models\Tag::getStatus()[$data];
})
]);
$table->create();
$table->render();

View File

@ -0,0 +1,34 @@
<?php
/**
* @var int $page_number
*/
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\tag\models\Tag;
use kernel\IGTabel\btn\PrimaryBtn;
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\tag\models\TagEntity::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag_entity",
]));
$table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/tag_entity/create")->fetch();
});
$table->columns([
"tag_id" => [
"value" => function ($data) {
return Tag::find($data)->label;
}]
]);
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class);
\kernel\widgets\TagTabsWidget::create()->run();
$table->create();
$table->render();

View File

@ -0,0 +1,30 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $tagEntity
*/
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;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($tagEntity, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () use ($tagEntity) {
$btn = PrimaryBtn::create("Список", "/admin/tag_entity")->fetch();
$btn .= SuccessBtn::create("Редактировать", "/admin/tag_entity/update/" . $tagEntity->id)->fetch();
$btn .= DangerBtn::create("Удалить", "/admin/tag_entity/delete/" . $tagEntity->id)->fetch();
return $btn;
});
$table->rows([
'tag_id' => (function ($data) {
return \kernel\app_modules\tag\models\Tag::find($data)->label;
})
]);
$table->create();
$table->render();

View File

@ -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) {

View File

@ -119,4 +119,48 @@ class ModuleController extends ConsoleController
$this->out->r("Модуль $slug создан", 'green');
}
public function actionConstructController(): void
{
$this->out->r("Введите slug контроллера:", 'yellow');
$slug = substr(fgets(STDIN), 0, -1);
$slug = strtolower($slug);
$this->out->r("Введите model контроллера:", 'yellow');
$model = substr(fgets(STDIN), 0, -1);
$this->out->r("Введите путь контроллера:", 'yellow');
$path = substr(fgets(STDIN), 0, -1);
$path = strtolower($path);
$moduleService = new ModuleService();
$moduleService->createController([
'slug' => $slug,
'model' => $model,
], $path);
$this->out->r("Контроллер $slug создан", 'green');
}
public function actionConstructCRUD(): void
{
$this->out->r("Введите slug для CRUD:", 'yellow');
$slug = substr(fgets(STDIN), 0, -1);
$slug = strtolower($slug);
$this->out->r("Введите model для CRUD:", 'yellow');
$model = substr(fgets(STDIN), 0, -1);
$this->out->r("Введите путь для CRUD:", 'yellow');
$path = substr(fgets(STDIN), 0, -1);
$path = strtolower($path);
$moduleService = new ModuleService();
$moduleService->createCRUD([
'slug' => $slug,
'model' => $model,
], $path);
$this->out->r("CRUD $model создан", 'green');
}
}

View File

@ -91,6 +91,14 @@ App::$collector->group(["prefix" => "module"], callback: function (RouteCollecto
[\kernel\console\controllers\ModuleController::class, 'actionConstructModule'],
additionalInfo: ['description' => 'Сгенерировать модуль']
);
App::$collector->console('construct/controller',
[\kernel\console\controllers\ModuleController::class, 'actionConstructController'],
additionalInfo: ['description' => 'Сгенерировать контроллер']
);
App::$collector->console('construct/crud',
[\kernel\console\controllers\ModuleController::class, 'actionConstructCRUD'],
additionalInfo: ['description' => 'Сгенерировать CRUD']
);
});
App::$collector->group(["prefix" => "kernel"], callback: function (RouteCollector $router){

View File

@ -125,4 +125,12 @@ class Files
}
}
public static function isImageByExtension($filename): bool
{
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
return in_array($extension, $allowedExtensions);
}
}

19
kernel/helpers/Url.php Normal file
View File

@ -0,0 +1,19 @@
<?php
namespace kernel\helpers;
class Url
{
public static function get_base_url()
{
// Удаляем параметр page если он есть
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http")
. "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// Удаляем параметр page если он есть
$currentUrl = preg_replace('/([?&])page=[^&]*(&|$)/', '$1', $currentUrl);
return rtrim($currentUrl, '?&');
}
}

View File

@ -1,6 +1,6 @@
{
"name": "Kernel",
"version": "0.1.5",
"version": "0.1.8",
"author": "ITGuild",
"slug": "kernel",
"type": "kernel",

View File

@ -92,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);
}
@ -254,10 +254,9 @@ class ModuleShopClientController extends AdminController
$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", "Тема админ-панели успешно установлена.");
Flash::setMessage("success", "Тема админ-панели успешно загружена.");
} else {
Session::start();
Session::set("error", implode(";", $this->adminThemeService->getErrors()));
Flash::setMessage("error", implode(";", $this->adminThemeService->getErrors()));
}
$this->redirect('/admin/module_shop_client', 302);
@ -306,7 +305,7 @@ class ModuleShopClientController extends AdminController
$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", "Тема сайта успешно установлена.");
Flash::setMessage("success", "Тема сайта успешно загружена.");
} else {
Session::start();
Session::set("error", implode(";", $this->themeService->getErrors()));

View File

@ -15,7 +15,8 @@ $table_info = [
"version" => "Версия",
"description" => "Описание",
"installations" => "Установки",
"views" => "Просмотры"
"views" => "Просмотры",
"dependence" => "Зависимости"
],
"params" => ["class" => "table table-bordered"],
"baseUrl" => "/admin/module_shop_client",

View File

@ -105,6 +105,11 @@ class AdminThemeService
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);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace kernel\services;
class Dependencies
{
}

View File

@ -53,7 +53,7 @@ class MigrationService
$dmr->delete($migrationInstance);
}
} catch (\Exception $e) {
throw new \Exception('Не удалось откатить миграции');
throw new \Exception('Не удалось откатить миграции: ' . $e->getMessage());
}
}

View File

@ -185,6 +185,11 @@ class ModuleService
if ($module_paths) {
$path = json_decode($module_paths->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);
}
}
@ -639,4 +644,61 @@ class ModuleService
return true;
}
public function createCRUD(array $params, string $modulePath)
{
$slug = $params['slug'];
$model = $params['model'];
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/controllers/kernel_controller_template',
$modulePath . '/controllers/' . $model . 'Controller.php',
$params
);
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/models/model_template',
$modulePath . '/models/' . $model . '.php',
$params
);
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/models/forms/create_form_template',
$modulePath . '/models/forms/Create' . $model . 'Form.php',
$params
);
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/services/service_template',
$modulePath . '/services/' . $model . 'Service.php',
$params
);
mkdir($modulePath . '/views/' . strtolower($model));
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/views/index_template',
$modulePath . '/views/' . strtolower($model) . '/index.php',
$params
);
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/views/view_template',
$modulePath . '/views/' . strtolower($model) . '/view.php',
$params
);
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/views/form_template',
$modulePath . '/views/' . strtolower($model) . '/form.php',
$params
);
}
public function createController(array $params, string $path): void
{
$slug = $params['slug'];
$model = $params['model'];
$this->createModuleFileByTemplate(
KERNEL_TEMPLATES_DIR . '/controllers/kernel_controller_template',
$path . '/' . $model . 'Controller.php',
$params
);
}
}

View File

@ -98,7 +98,7 @@ class ThemeService
{
if (isset($themeInfo['theme_class'])) {
if (isset($themeInfo['theme_class_file'])) {
require_once $themeInfo['theme_class_file'];
require_once getConst($themeInfo['theme_class_file']);
}
$themeClass = new $themeInfo['theme_class']();
$themeClass->init();
@ -113,7 +113,7 @@ class ThemeService
{
if (isset($themeInfo['theme_class'])) {
if (isset($themeInfo['theme_class_file'])) {
require_once $themeInfo['theme_class_file'];
require_once getConst($themeInfo['theme_class_file']);
}
$themeClass = new $themeInfo['theme_class']();
$themeClass->deactivate();
@ -162,6 +162,11 @@ class ThemeService
if ($ThemePaths) {
$path = json_decode($ThemePaths->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);
}
}
@ -234,12 +239,12 @@ class ThemeService
return false;
}
if (!file_exists($tmpThemeDirFull . "meta/manifest.json")){
if (!file_exists($tmpThemeDirFull . "meta/app/manifest.json")){
$this->addError('manifest.json not found');
return false;
}
$manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json"));
$manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/app/manifest.json"));
$manifest = Manifest::getWithVars($manifestJson);
$fileHelper = new Files();
@ -250,9 +255,9 @@ class ThemeService
}
if (isset($manifest['theme_kernel_path'])) {
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", $manifest['theme_app_path']);
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", $manifest['theme_kernel_path']);
} else {
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", APP_DIR . '/themes/' . $manifest['slug']);
$fileHelper->copy_folder($tmpThemeDirFull . "meta/kernel", KERNEL_DIR . '/app_themes/' . $manifest['slug']);
}
if (isset($manifest['resource_path'])) {