ver 0.262 - pages module refactor and admin UX fixes
This commit is contained in:
@@ -48,13 +48,13 @@ class ArticlesArchiveController
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'title' => '<a href="/admin/articles/article_edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'title' => '<a href="/admin/articles/edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'date_add' => !empty($item['date_add']) ? date('Y-m-d H:i', strtotime((string)$item['date_add'])) : '-',
|
||||
'date_modify' => !empty($item['date_modify']) ? date('Y-m-d H:i', strtotime((string)$item['date_modify'])) : '-',
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Przywroc',
|
||||
'url' => '/admin/articles_archive/article_restore/id=' . $id,
|
||||
'url' => '/admin/articles_archive/restore/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-success',
|
||||
'confirm' => 'Na pewno chcesz przywrocic wybrany artykul?',
|
||||
'confirm_ok' => 'Przywroc',
|
||||
@@ -62,7 +62,7 @@ class ArticlesArchiveController
|
||||
],
|
||||
[
|
||||
'label' => 'Usun',
|
||||
'url' => '/admin/articles_archive/article_delete/id=' . $id,
|
||||
'url' => '/admin/articles_archive/delete/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-danger',
|
||||
'confirm' => 'Na pewno chcesz trwale usunac wybrany artykul?',
|
||||
'confirm_ok' => 'Usun',
|
||||
@@ -101,7 +101,7 @@ class ArticlesArchiveController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/articles_archive/view_list/',
|
||||
'/admin/articles_archive/list/',
|
||||
'Brak danych w tabeli.'
|
||||
);
|
||||
|
||||
@@ -121,7 +121,7 @@ class ArticlesArchiveController
|
||||
\S::alert('Artykul zostal przywrocony.');
|
||||
}
|
||||
|
||||
header('Location: /admin/articles_archive/view_list/');
|
||||
header('Location: /admin/articles_archive/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class ArticlesArchiveController
|
||||
\S::alert('Artykul zostal trwale usuniety.');
|
||||
}
|
||||
|
||||
header('Location: /admin/articles_archive/view_list/');
|
||||
header('Location: /admin/articles_archive/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace admin\Controllers;
|
||||
use Domain\Article\ArticleRepository;
|
||||
use Domain\Languages\LanguagesRepository;
|
||||
use Domain\Layouts\LayoutsRepository;
|
||||
use Domain\Pages\PagesRepository;
|
||||
use admin\ViewModels\Forms\FormAction;
|
||||
use admin\ViewModels\Forms\FormEditViewModel;
|
||||
use admin\ViewModels\Forms\FormField;
|
||||
@@ -14,16 +15,19 @@ class ArticlesController
|
||||
private ArticleRepository $repository;
|
||||
private LanguagesRepository $languagesRepository;
|
||||
private LayoutsRepository $layoutsRepository;
|
||||
private PagesRepository $pagesRepository;
|
||||
|
||||
public function __construct(
|
||||
ArticleRepository $repository,
|
||||
LanguagesRepository $languagesRepository,
|
||||
LayoutsRepository $layoutsRepository
|
||||
LayoutsRepository $layoutsRepository,
|
||||
PagesRepository $pagesRepository
|
||||
)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->languagesRepository = $languagesRepository;
|
||||
$this->layoutsRepository = $layoutsRepository;
|
||||
$this->pagesRepository = $pagesRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +87,7 @@ class ArticlesController
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'title' => '<a href="/admin/articles/article_edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>'
|
||||
'title' => '<a href="/admin/articles/edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>'
|
||||
. '<small class="text-muted">' . htmlspecialchars($pages, ENT_QUOTES, 'UTF-8') . '</small>',
|
||||
'status' => ((int)$item['status'] === 1) ? 'tak' : '<span style="color: #FF0000;">nie</span>',
|
||||
'date_add' => !empty($item['date_add']) ? date('Y-m-d H:i', strtotime((string)$item['date_add'])) : '-',
|
||||
@@ -92,12 +96,12 @@ class ArticlesController
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/articles/article_edit/id=' . $id,
|
||||
'url' => '/admin/articles/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
[
|
||||
'label' => 'Usun',
|
||||
'url' => '/admin/articles/article_delete/id=' . $id,
|
||||
'url' => '/admin/articles/delete/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-danger',
|
||||
'confirm' => 'Na pewno chcesz usunac wybrany element?',
|
||||
],
|
||||
@@ -136,9 +140,9 @@ class ArticlesController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/articles/view_list/',
|
||||
'/admin/articles/list/',
|
||||
'Brak danych w tabeli.',
|
||||
'/admin/articles/article_edit/',
|
||||
'/admin/articles/edit/',
|
||||
'Dodaj artykul'
|
||||
);
|
||||
|
||||
@@ -259,7 +263,7 @@ class ArticlesController
|
||||
\S::alert('Artykul zostal przeniesiony do archiwum.');
|
||||
}
|
||||
|
||||
header('Location: /admin/articles/view_list/');
|
||||
header('Location: /admin/articles/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -280,7 +284,7 @@ class ArticlesController
|
||||
|
||||
$article = $this->repository->find((int)\S::get('id')) ?: ['id' => 0, 'languages' => [], 'images' => [], 'files' => [], 'pages' => []];
|
||||
$languages = $this->languagesRepository->languagesList();
|
||||
$menus = \admin\factory\Pages::menus_list();
|
||||
$menus = $this->pagesRepository->menusList();
|
||||
$layouts = $this->layoutsRepository->listAll();
|
||||
|
||||
$viewModel = $this->buildFormViewModel($article, $languages, $menus, $layouts);
|
||||
@@ -400,8 +404,8 @@ class ArticlesController
|
||||
];
|
||||
|
||||
$actions = [
|
||||
FormAction::save('/admin/articles/article_save/' . ($articleId > 0 ? 'id=' . $articleId : ''), '/admin/articles/view_list/'),
|
||||
FormAction::cancel('/admin/articles/view_list/'),
|
||||
FormAction::save('/admin/articles/save/' . ($articleId > 0 ? 'id=' . $articleId : ''), '/admin/articles/list/'),
|
||||
FormAction::cancel('/admin/articles/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
@@ -412,8 +416,8 @@ class ArticlesController
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
'/admin/articles/article_save/' . ($articleId > 0 ? 'id=' . $articleId : ''),
|
||||
'/admin/articles/view_list/',
|
||||
'/admin/articles/save/' . ($articleId > 0 ? 'id=' . $articleId : ''),
|
||||
'/admin/articles/list/',
|
||||
true,
|
||||
['id' => $articleId],
|
||||
$languages
|
||||
@@ -430,7 +434,7 @@ class ArticlesController
|
||||
$menuId = (int)($menu['id'] ?? 0);
|
||||
$menuName = $this->escapeHtml((string)($menu['name'] ?? ''));
|
||||
$menuStatus = (int)($menu['status'] ?? 0);
|
||||
$menuPages = \admin\factory\Pages::menu_pages($menuId);
|
||||
$menuPages = $this->pagesRepository->menuPages($menuId);
|
||||
|
||||
$html .= '<div class="menu_sortable">';
|
||||
$html .= '<ol class="sortable" id="sortable_' . $menuId . '">';
|
||||
|
||||
@@ -92,7 +92,7 @@ class BannerController
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'thumbnail' => $thumbnail,
|
||||
'name' => '<a href="/admin/banners/banner_edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'name' => '<a href="/admin/banners/edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'status' => $isActive ? 'tak' : '<span style="color: #FF0000;">nie</span>',
|
||||
'home_page' => $homePage === 1 ? '<span class="text-system">tak</span>' : 'nie',
|
||||
'slider' => $homePage === 1 ? 'nie' : '<span class="text-system">tak</span>',
|
||||
@@ -101,12 +101,12 @@ class BannerController
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/banners/banner_edit/id=' . $id,
|
||||
'url' => '/admin/banners/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
[
|
||||
'label' => 'Usun',
|
||||
'url' => '/admin/banners/banner_delete/id=' . $id,
|
||||
'url' => '/admin/banners/delete/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-danger',
|
||||
'confirm' => 'Na pewno chcesz usunac wybrany element?',
|
||||
],
|
||||
@@ -147,9 +147,9 @@ class BannerController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/banners/view_list/',
|
||||
'/admin/banners/list/',
|
||||
'Brak danych w tabeli.',
|
||||
'/admin/banners/banner_edit/',
|
||||
'/admin/banners/edit/',
|
||||
'Dodaj baner',
|
||||
'banners/banners-list-custom-script'
|
||||
);
|
||||
@@ -235,7 +235,7 @@ class BannerController
|
||||
\S::alert('Baner zostal usuniety.');
|
||||
}
|
||||
|
||||
header('Location: /admin/banners/view_list/');
|
||||
header('Location: /admin/banners/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -307,10 +307,10 @@ class BannerController
|
||||
|
||||
$actions = [
|
||||
FormAction::save(
|
||||
'/admin/banners/banner_save/' . ($isNew ? '' : 'id=' . $bannerId),
|
||||
'/admin/banners/view_list/'
|
||||
'/admin/banners/save/' . ($isNew ? '' : 'id=' . $bannerId),
|
||||
'/admin/banners/list/'
|
||||
),
|
||||
FormAction::cancel('/admin/banners/view_list/'),
|
||||
FormAction::cancel('/admin/banners/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
@@ -321,8 +321,8 @@ class BannerController
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
'/admin/banners/banner_save/' . ($isNew ? '' : 'id=' . $bannerId),
|
||||
'/admin/banners/view_list/',
|
||||
'/admin/banners/save/' . ($isNew ? '' : 'id=' . $bannerId),
|
||||
'/admin/banners/list/',
|
||||
true,
|
||||
['id' => $bannerId],
|
||||
$languages,
|
||||
|
||||
@@ -61,16 +61,16 @@ class DictionariesController
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'text' => '<a href="/admin/dictionaries/unit_edit/id=' . $id . '">' . htmlspecialchars($text, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'text' => '<a href="/admin/dictionaries/edit/id=' . $id . '">' . htmlspecialchars($text, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/dictionaries/unit_edit/id=' . $id,
|
||||
'url' => '/admin/dictionaries/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
[
|
||||
'label' => 'Usun',
|
||||
'url' => '/admin/dictionaries/unit_delete/id=' . $id,
|
||||
'url' => '/admin/dictionaries/delete/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-danger',
|
||||
'confirm' => 'Na pewno chcesz usunac wybrana jednostke miary?',
|
||||
],
|
||||
@@ -105,9 +105,9 @@ class DictionariesController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/dictionaries/view_list/',
|
||||
'/admin/dictionaries/list/',
|
||||
'Brak danych w tabeli.',
|
||||
'/admin/dictionaries/unit_edit/',
|
||||
'/admin/dictionaries/edit/',
|
||||
'Dodaj jednostke miary'
|
||||
);
|
||||
|
||||
@@ -192,7 +192,7 @@ class DictionariesController
|
||||
\S::alert('Jednostka miary zostala usunieta.');
|
||||
}
|
||||
|
||||
header('Location: /admin/dictionaries/view_list/');
|
||||
header('Location: /admin/dictionaries/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -226,10 +226,10 @@ class DictionariesController
|
||||
]),
|
||||
];
|
||||
|
||||
$actionUrl = '/admin/dictionaries/unit_save/' . ($isNew ? '' : ('id=' . $unitId));
|
||||
$actionUrl = '/admin/dictionaries/save/' . ($isNew ? '' : ('id=' . $unitId));
|
||||
$actions = [
|
||||
FormAction::save($actionUrl, '/admin/dictionaries/view_list/'),
|
||||
FormAction::cancel('/admin/dictionaries/view_list/'),
|
||||
FormAction::save($actionUrl, '/admin/dictionaries/list/'),
|
||||
FormAction::cancel('/admin/dictionaries/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
@@ -241,7 +241,7 @@ class DictionariesController
|
||||
$actions,
|
||||
'POST',
|
||||
$actionUrl,
|
||||
'/admin/dictionaries/view_list/',
|
||||
'/admin/dictionaries/list/',
|
||||
true,
|
||||
['id' => $unitId],
|
||||
$languages,
|
||||
|
||||
@@ -74,18 +74,18 @@ class LayoutsController
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'name' => '<a href="/admin/layouts/layout_edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'name' => '<a href="/admin/layouts/edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'status' => ((int)($item['status'] ?? 0) === 1) ? '<span class="text-system">tak</span>' : 'nie',
|
||||
'categories_default' => ((int)($item['categories_default'] ?? 0) === 1) ? '<span class="text-system">tak</span>' : 'nie',
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/layouts/layout_edit/id=' . $id,
|
||||
'url' => '/admin/layouts/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
[
|
||||
'label' => 'Usun',
|
||||
'url' => '/admin/layouts/layout_delete/id=' . $id,
|
||||
'url' => '/admin/layouts/delete/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-danger',
|
||||
'confirm' => 'Na pewno chcesz usunac wybrany szablon?',
|
||||
],
|
||||
@@ -122,9 +122,9 @@ class LayoutsController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/layouts/view_list/',
|
||||
'/admin/layouts/list/',
|
||||
'Brak danych w tabeli.',
|
||||
'/admin/layouts/layout_edit/',
|
||||
'/admin/layouts/edit/',
|
||||
'Dodaj szablon'
|
||||
);
|
||||
|
||||
@@ -165,7 +165,7 @@ class LayoutsController
|
||||
\S::alert('Szablon zostal usuniety.');
|
||||
}
|
||||
|
||||
header('Location: /admin/layouts/view_list/');
|
||||
header('Location: /admin/layouts/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
660
autoload/admin/Controllers/PagesController.php
Normal file
660
autoload/admin/Controllers/PagesController.php
Normal file
@@ -0,0 +1,660 @@
|
||||
<?php
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\Pages\PagesRepository;
|
||||
use Domain\Languages\LanguagesRepository;
|
||||
use Domain\Layouts\LayoutsRepository;
|
||||
use admin\ViewModels\Forms\FormAction;
|
||||
use admin\ViewModels\Forms\FormEditViewModel;
|
||||
use admin\ViewModels\Forms\FormField;
|
||||
use admin\ViewModels\Forms\FormTab;
|
||||
|
||||
class PagesController
|
||||
{
|
||||
private PagesRepository $repository;
|
||||
private LanguagesRepository $languagesRepository;
|
||||
private LayoutsRepository $layoutsRepository;
|
||||
|
||||
public function __construct(
|
||||
PagesRepository $repository,
|
||||
LanguagesRepository $languagesRepository,
|
||||
LayoutsRepository $layoutsRepository
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->languagesRepository = $languagesRepository;
|
||||
$this->layoutsRepository = $layoutsRepository;
|
||||
}
|
||||
|
||||
public function list(): string
|
||||
{
|
||||
return \Tpl::view('pages/pages-list', [
|
||||
'menus' => $this->repository->menusWithPages(),
|
||||
'cookie_pages' => $this->cookieState('cookie_pages'),
|
||||
'cookie_menus' => $this->cookieState('cookie_menus'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function browseList(): string
|
||||
{
|
||||
$menus = $this->repository->menusWithPages();
|
||||
$defaultLanguage = $this->languagesRepository->defaultLanguageId();
|
||||
|
||||
foreach ($menus as $index => $menu) {
|
||||
$menus[$index]['pages'] = $this->withPreviewUrls($menu['pages'] ?? [], $defaultLanguage);
|
||||
}
|
||||
|
||||
return \Tpl::view('pages/pages-browse-list', [
|
||||
'menus' => $menus,
|
||||
'modal' => \S::get('modal'),
|
||||
'cookie_pages' => $this->cookieState('cookie_pages'),
|
||||
'cookie_menus' => $this->cookieState('cookie_menus'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function pagesUrlBrowser(): string
|
||||
{
|
||||
return $this->browseList();
|
||||
}
|
||||
|
||||
public function menuEdit(): string
|
||||
{
|
||||
$menu = $this->repository->menuDetails((int)\S::get('id'));
|
||||
|
||||
return \Tpl::view('pages/menu-edit', [
|
||||
'form' => $this->buildMenuFormViewModel($menu),
|
||||
]);
|
||||
}
|
||||
|
||||
public function menuSave(): void
|
||||
{
|
||||
$legacyValues = \S::get('values');
|
||||
if ($legacyValues) {
|
||||
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania menu wystapil blad. Prosze sprobowac ponownie.'];
|
||||
$values = json_decode((string)$legacyValues, true);
|
||||
|
||||
if (is_array($values) && $this->repository->menuSave(
|
||||
(int)($values['id'] ?? 0),
|
||||
(string)($values['name'] ?? ''),
|
||||
$values['status'] ?? 0
|
||||
)) {
|
||||
$response = ['status' => 'ok', 'msg' => 'Menu zostalo zapisane.'];
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$menuId = (int)\S::get('id');
|
||||
$name = trim((string)\S::get('name'));
|
||||
$status = \S::get('status');
|
||||
|
||||
if ($name === '') {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'errors' => ['name' => 'Pole "Nazwa" jest wymagane.'],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($this->repository->menuSave($menuId, $name, $status)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Menu zostalo zapisane.',
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'errors' => ['general' => 'Podczas zapisywania menu wystapil blad. Prosze sprobowac ponownie.'],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $menu
|
||||
*/
|
||||
private function buildMenuFormViewModel(array $menu): FormEditViewModel
|
||||
{
|
||||
$menuId = (int)($menu['id'] ?? 0);
|
||||
$actionUrl = '/admin/pages/menuSave/' . ($menuId > 0 ? ('id=' . $menuId) : '');
|
||||
|
||||
$fields = [
|
||||
FormField::hidden('id', $menuId),
|
||||
FormField::text('name', [
|
||||
'label' => 'Nazwa',
|
||||
'required' => true,
|
||||
'attributes' => ['class' => 'require'],
|
||||
'value' => (string)($menu['name'] ?? ''),
|
||||
]),
|
||||
FormField::switch('status', [
|
||||
'label' => 'Aktywne',
|
||||
'value' => (int)($menu['status'] ?? 0) === 1,
|
||||
]),
|
||||
];
|
||||
|
||||
$actions = [
|
||||
FormAction::save($actionUrl, '/admin/pages/list/'),
|
||||
FormAction::cancel('/admin/pages/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
'pages-menu-edit',
|
||||
'Zapisz menu',
|
||||
$menu,
|
||||
$fields,
|
||||
[],
|
||||
$actions,
|
||||
'POST',
|
||||
$actionUrl,
|
||||
'/admin/pages/list/',
|
||||
true,
|
||||
['id' => $menuId]
|
||||
);
|
||||
}
|
||||
|
||||
public function menuDelete(): void
|
||||
{
|
||||
if ($this->repository->menuDelete((int)\S::get('id'))) {
|
||||
\S::set_message('Menu zostało usunięte.');
|
||||
} else {
|
||||
\S::alert('Podczas usuwania menu wystąpił błąd. Aby usunąć menu, nie może ono posiadać przypiętych stron.');
|
||||
}
|
||||
|
||||
header('Location: /admin/pages/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function edit(): string
|
||||
{
|
||||
$page = $this->repository->pageDetails((int)\S::get('id'));
|
||||
$parentId = (int)\S::get('pid');
|
||||
$menuId = (int)\S::get('menu_id');
|
||||
$menus = $this->repository->menusList();
|
||||
$layouts = $this->layoutsRepository->listAll();
|
||||
$languages = $this->languagesRepository->languagesList();
|
||||
|
||||
return \Tpl::view('pages/page-edit', [
|
||||
'form' => $this->buildPageFormViewModel(
|
||||
$page,
|
||||
$parentId,
|
||||
$menuId,
|
||||
$menus,
|
||||
$layouts,
|
||||
$languages
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$legacyValues = \S::get('values');
|
||||
if ($legacyValues) {
|
||||
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania strony wystapil blad. Prosze sprobowac ponownie.'];
|
||||
$values = json_decode((string)$legacyValues, true);
|
||||
|
||||
if (is_array($values)) {
|
||||
$id = $this->repository->pageSave($values);
|
||||
if (!empty($id)) {
|
||||
$response = [
|
||||
'status' => 'ok',
|
||||
'msg' => 'Strona zostala zapisana.',
|
||||
'id' => (int)$id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $_POST;
|
||||
if (!isset($data['id']) || $data['id'] === '') {
|
||||
$data['id'] = (int)\S::get('id');
|
||||
}
|
||||
if (!isset($data['parent_id']) || $data['parent_id'] === '') {
|
||||
$data['parent_id'] = (int)\S::get('pid');
|
||||
}
|
||||
if ((!isset($data['menu_id']) || $data['menu_id'] === '') && (int)\S::get('menu_id') > 0) {
|
||||
$data['menu_id'] = (int)\S::get('menu_id');
|
||||
}
|
||||
|
||||
$savedId = $this->repository->pageSave($data);
|
||||
if (!empty($savedId)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Strona zostala zapisana.',
|
||||
'id' => (int)$savedId,
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'errors' => ['general' => 'Podczas zapisywania strony wystapil blad. Prosze sprobowac ponownie.'],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $page
|
||||
* @param array<int, array<string, mixed>> $menus
|
||||
* @param array<int, array<string, mixed>> $layouts
|
||||
* @param array<int, array<string, mixed>> $languages
|
||||
*/
|
||||
private function buildPageFormViewModel(
|
||||
array $page,
|
||||
int $parentId,
|
||||
int $menuId,
|
||||
array $menus,
|
||||
array $layouts,
|
||||
array $languages
|
||||
): FormEditViewModel {
|
||||
$pageId = (int)($page['id'] ?? 0);
|
||||
$isNew = $pageId <= 0;
|
||||
|
||||
$resolvedParentId = $pageId > 0 ? (int)($page['parent_id'] ?? 0) : $parentId;
|
||||
$resolvedMenuId = $pageId > 0 ? (int)($page['menu_id'] ?? 0) : $menuId;
|
||||
|
||||
$menuOptions = [];
|
||||
foreach ($menus as $menu) {
|
||||
$id = (int)($menu['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
continue;
|
||||
}
|
||||
$menuOptions[$id] = (string)($menu['name'] ?? '');
|
||||
}
|
||||
|
||||
$layoutOptions = ['' => '---- szablon ----'];
|
||||
foreach ($layouts as $layout) {
|
||||
$id = (int)($layout['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
continue;
|
||||
}
|
||||
$layoutOptions[$id] = (string)($layout['name'] ?? '');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $pageId,
|
||||
'parent_id' => $resolvedParentId > 0 ? $resolvedParentId : '',
|
||||
'menu_id' => $resolvedMenuId > 0 ? $resolvedMenuId : '',
|
||||
'page_type' => (int)($page['page_type'] ?? 0),
|
||||
'sort_type' => (int)($page['sort_type'] ?? 0),
|
||||
'layout_id' => (int)($page['layout_id'] ?? 0),
|
||||
'articles_limit' => (int)($page['articles_limit'] ?? 2),
|
||||
'show_title' => (int)($page['show_title'] ?? 1),
|
||||
'status' => (int)($page['status'] ?? 1),
|
||||
'start' => (int)($page['start'] ?? 0),
|
||||
'category_id' => (int)($page['category_id'] ?? 0),
|
||||
'languages' => [],
|
||||
];
|
||||
|
||||
foreach ($languages as $language) {
|
||||
$langId = (string)($language['id'] ?? '');
|
||||
if ($langId === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$translation = is_array($page['languages'][$langId] ?? null) ? $page['languages'][$langId] : [];
|
||||
$data['languages'][$langId] = [
|
||||
'title' => (string)($translation['title'] ?? ''),
|
||||
'link' => (string)($translation['link'] ?? ''),
|
||||
'seo_link' => (string)($translation['seo_link'] ?? ''),
|
||||
'page_title' => (string)($translation['page_title'] ?? ''),
|
||||
'meta_title' => (string)($translation['meta_title'] ?? ''),
|
||||
'meta_description' => (string)($translation['meta_description'] ?? ''),
|
||||
'meta_keywords' => (string)($translation['meta_keywords'] ?? ''),
|
||||
'noindex' => (int)($translation['noindex'] ?? 0),
|
||||
'canonical' => (string)($translation['canonical'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
$tabs = [
|
||||
new FormTab('content', 'Tresc', 'fa-file'),
|
||||
new FormTab('settings', 'Ustawienia', 'fa-wrench'),
|
||||
new FormTab('seo', 'SEO', 'fa-globe'),
|
||||
];
|
||||
|
||||
$fields = [
|
||||
FormField::hidden('id', $pageId),
|
||||
FormField::hidden('parent_id', $resolvedParentId > 0 ? $resolvedParentId : ''),
|
||||
FormField::langSection('page_content', 'content', [
|
||||
FormField::text('title', [
|
||||
'label' => 'Nazwa strony',
|
||||
'required' => true,
|
||||
]),
|
||||
]),
|
||||
FormField::select('menu_id', [
|
||||
'label' => 'Menu',
|
||||
'tab' => 'settings',
|
||||
'options' => $menuOptions,
|
||||
'value' => $resolvedMenuId > 0 ? $resolvedMenuId : '',
|
||||
]),
|
||||
FormField::select('page_type', [
|
||||
'label' => 'Typ strony',
|
||||
'tab' => 'settings',
|
||||
'options' => $this->repository->pageTypes(),
|
||||
'attributes' => ['id' => 'page_type'],
|
||||
'value' => (int)($page['page_type'] ?? 0),
|
||||
]),
|
||||
FormField::langSection('page_links', 'settings', [
|
||||
FormField::text('link', [
|
||||
'label' => 'Link',
|
||||
]),
|
||||
]),
|
||||
FormField::text('category_id', [
|
||||
'label' => 'ID kategorii',
|
||||
'tab' => 'settings',
|
||||
'attributes' => ['id' => 'category_id'],
|
||||
'value' => (int)($page['category_id'] ?? 0),
|
||||
]),
|
||||
FormField::select('sort_type', [
|
||||
'label' => 'Sortowanie artykulow',
|
||||
'tab' => 'settings',
|
||||
'attributes' => ['id' => 'sort_type'],
|
||||
'options' => $this->repository->sortTypes(),
|
||||
'value' => (int)($page['sort_type'] ?? 0),
|
||||
]),
|
||||
FormField::select('layout_id', [
|
||||
'label' => 'Szablon',
|
||||
'tab' => 'settings',
|
||||
'attributes' => ['id' => 'layout_id'],
|
||||
'options' => $layoutOptions,
|
||||
'value' => (int)($page['layout_id'] ?? 0),
|
||||
]),
|
||||
FormField::text('articles_limit', [
|
||||
'label' => 'Liczba artykulow na stronie',
|
||||
'tab' => 'settings',
|
||||
'attributes' => ['id' => 'articles_limit'],
|
||||
'value' => (int)($page['articles_limit'] ?? 2),
|
||||
]),
|
||||
FormField::switch('show_title', [
|
||||
'label' => 'Pokaz tytul',
|
||||
'tab' => 'settings',
|
||||
'value' => (int)($page['show_title'] ?? 0) === 1 || $isNew,
|
||||
]),
|
||||
FormField::switch('status', [
|
||||
'label' => 'Aktywna',
|
||||
'tab' => 'settings',
|
||||
'value' => (int)($page['status'] ?? 0) === 1 || $isNew,
|
||||
]),
|
||||
FormField::switch('start', [
|
||||
'label' => 'Strona startowa',
|
||||
'tab' => 'settings',
|
||||
'value' => (int)($page['start'] ?? 0) === 1,
|
||||
]),
|
||||
FormField::langSection('page_seo', 'seo', [
|
||||
FormField::text('seo_link', [
|
||||
'label' => 'Link SEO',
|
||||
'attributes' => [
|
||||
'icon_content' => 'generuj',
|
||||
'icon_js' => 'generateSeoLinkForButton(\'{lang}\')',
|
||||
],
|
||||
]),
|
||||
FormField::text('page_title', [
|
||||
'label' => 'Tytul strony (h1)',
|
||||
]),
|
||||
FormField::text('meta_title', [
|
||||
'label' => 'Meta title',
|
||||
]),
|
||||
FormField::textarea('meta_description', [
|
||||
'label' => 'Meta description',
|
||||
]),
|
||||
FormField::textarea('meta_keywords', [
|
||||
'label' => 'Meta keywords',
|
||||
]),
|
||||
FormField::select('noindex', [
|
||||
'label' => 'Blokuj indeksacje',
|
||||
'options' => [0 => 'nie', 1 => 'tak'],
|
||||
]),
|
||||
FormField::text('canonical', [
|
||||
'label' => 'Rel canonical',
|
||||
]),
|
||||
]),
|
||||
FormField::custom('page_edit_script', '
|
||||
<script type="text/javascript">
|
||||
(function () {
|
||||
function toggleByType() {
|
||||
var pageType = String($(\'#page_type\').val() || \'\');
|
||||
var $links = $(\'#languages-page_links\');
|
||||
var $category = $(\'#category_id\').closest(\'.form-group\');
|
||||
var $articlesLimit = $(\'#articles_limit\').closest(\'.form-group\');
|
||||
var $sortType = $(\'#sort_type\').closest(\'.form-group\');
|
||||
|
||||
if (pageType === \'0\' || pageType === \'1\' || pageType === \'2\') {
|
||||
$articlesLimit.show();
|
||||
$sortType.show();
|
||||
$links.addClass(\'hide\');
|
||||
$category.hide();
|
||||
} else if (pageType === \'3\') {
|
||||
$links.removeClass(\'hide\');
|
||||
$articlesLimit.hide();
|
||||
$sortType.hide();
|
||||
$category.hide();
|
||||
} else if (pageType === \'5\') {
|
||||
$category.show();
|
||||
$links.addClass(\'hide\');
|
||||
$articlesLimit.hide();
|
||||
$sortType.hide();
|
||||
} else {
|
||||
$links.addClass(\'hide\');
|
||||
$category.hide();
|
||||
$articlesLimit.hide();
|
||||
$sortType.hide();
|
||||
}
|
||||
}
|
||||
|
||||
function generateSeoLink(langId, title) {
|
||||
if (!title) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: \'POST\',
|
||||
cache: false,
|
||||
url: \'/admin/pages/generateSeoLink/\',
|
||||
data: {
|
||||
title: title,
|
||||
page_id: ' . $pageId . '
|
||||
},
|
||||
success: function (data) {
|
||||
var response = data;
|
||||
if (typeof data === \'string\') {
|
||||
try { response = JSON.parse(data); } catch (e) { response = null; }
|
||||
}
|
||||
if (response && response.status === \'ok\') {
|
||||
$(\'#seo_link_\' + langId).val(response.seo_link || \'\');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.generateSeoLinkForButton = function (langId) {
|
||||
var title = $(\'#title_\' + langId).val() || \'\';
|
||||
generateSeoLink(langId, title);
|
||||
};
|
||||
|
||||
$(function () {
|
||||
$(\'#page_type\').on(\'change\', toggleByType);
|
||||
toggleByType();
|
||||
|
||||
$(\'[id^=title_]\').on(\'blur\', function () {
|
||||
var fieldId = $(this).attr(\'id\') || \'\';
|
||||
var langId = fieldId.replace(/^title_/, \'\');
|
||||
if (!langId) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $seo = $(\'#seo_link_\' + langId);
|
||||
if ($seo.length && !$seo.val()) {
|
||||
generateSeoLink(langId, $(this).val());
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>', [
|
||||
'tab' => 'settings',
|
||||
]),
|
||||
];
|
||||
|
||||
$actionUrl = '/admin/pages/save/' . ($pageId > 0 ? ('id=' . $pageId) : '');
|
||||
$actions = [
|
||||
FormAction::save($actionUrl, '/admin/pages/list/'),
|
||||
FormAction::cancel('/admin/pages/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
'pages-page-edit',
|
||||
'Edycja strony',
|
||||
$data,
|
||||
$fields,
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
$actionUrl,
|
||||
'/admin/pages/list/',
|
||||
true,
|
||||
[
|
||||
'id' => $pageId,
|
||||
'parent_id' => $resolvedParentId > 0 ? $resolvedParentId : '',
|
||||
],
|
||||
$languages
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
if ($this->repository->pageDelete((int)\S::get('id'))) {
|
||||
\S::set_message('Strona zostala usunieta.');
|
||||
} else {
|
||||
\S::alert('Podczas usuwania strony wystapil blad. Aby usunac strone nie moze ona posiadac przypietych podstron.');
|
||||
}
|
||||
|
||||
header('Location: /admin/pages/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function pageArticles(): string
|
||||
{
|
||||
$pageId = (int)\S::get('id');
|
||||
return \Tpl::view('pages/page-articles', [
|
||||
'page_id' => $pageId,
|
||||
'articles' => $this->repository->pageArticles($pageId),
|
||||
]);
|
||||
}
|
||||
|
||||
public function savePagesOrder(): void
|
||||
{
|
||||
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania kolejnosci stron wystapil blad. Prosze sprobowac ponownie.'];
|
||||
|
||||
if ($this->repository->savePagesOrder((int)\S::get('menu_id'), \S::get('pages'))) {
|
||||
$response = ['status' => 'ok'];
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function saveArticlesOrder(): void
|
||||
{
|
||||
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania kolejnosci wyswietlania artykulow wystapil blad. Prosze sprobowac ponownie.'];
|
||||
|
||||
if ($this->repository->saveArticlesOrder((int)\S::get('page_id'), \S::get('articles'))) {
|
||||
$response = ['status' => 'ok'];
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function generateSeoLink(): void
|
||||
{
|
||||
$response = ['status' => 'error', 'msg' => 'Podczas generowania pola "seo link" wystapil blad. Prosze sprobowac ponownie.'];
|
||||
|
||||
$seoLink = $this->repository->generateSeoLink(
|
||||
(string)\S::get('title'),
|
||||
(int)\S::get('page_id'),
|
||||
(int)\S::get('article_id'),
|
||||
(int)\S::get('category_id')
|
||||
);
|
||||
|
||||
if ($seoLink !== '') {
|
||||
$response = [
|
||||
'status' => 'ok',
|
||||
'seo_link' => $seoLink,
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function cookieMenus(): void
|
||||
{
|
||||
$this->repository->toggleCookieValue('cookie_menus', (int)\S::get('menu_id'));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function cookiePages(): void
|
||||
{
|
||||
$this->repository->toggleCookieValue('cookie_pages', (int)\S::get('page_id'));
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $pages
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function withPreviewUrls(array $pages, string $defaultLanguage): array
|
||||
{
|
||||
foreach ($pages as $index => $page) {
|
||||
$pageId = (int)($page['id'] ?? 0);
|
||||
$languages = is_array($page['languages'] ?? null) ? $page['languages'] : [];
|
||||
|
||||
$previewUrls = [];
|
||||
foreach ($languages as $languageRow) {
|
||||
$langId = (string)($languageRow['lang_id'] ?? '');
|
||||
if ($langId === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$previewUrls[$langId] = $this->repository->pageUrlPreview(
|
||||
$pageId,
|
||||
$langId,
|
||||
(string)($languageRow['title'] ?? ''),
|
||||
(string)($languageRow['seo_link'] ?? ''),
|
||||
$defaultLanguage
|
||||
);
|
||||
}
|
||||
|
||||
$page['preview_urls'] = $previewUrls;
|
||||
$page['subpages'] = $this->withPreviewUrls($page['subpages'] ?? [], $defaultLanguage);
|
||||
$pages[$index] = $page;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
private function cookieState(string $cookieName): array
|
||||
{
|
||||
if (empty($_COOKIE[$cookieName])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$decoded = @unserialize((string)$_COOKIE[$cookieName], ['allowed_classes' => false]);
|
||||
if (!is_array($decoded)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$state = [];
|
||||
foreach ($decoded as $key => $value) {
|
||||
$state[(int)$key] = (int)$value;
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ class ProductArchiveController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/product_archive/products_list/',
|
||||
'/admin/product_archive/list/',
|
||||
'Brak danych w tabeli.',
|
||||
null,
|
||||
null,
|
||||
@@ -159,7 +159,7 @@ class ProductArchiveController
|
||||
else
|
||||
\S::alert( 'Podczas przywracania produktu z archiwum wystąpił błąd. Proszę spróbować ponownie' );
|
||||
|
||||
header( 'Location: /admin/product_archive/products_list/' );
|
||||
header( 'Location: /admin/product_archive/list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,18 +71,18 @@ class ScontainersController
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'title' => '<a href="/admin/scontainers/container_edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'title' => '<a href="/admin/scontainers/edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'code' => '[KONTENER:' . $id . ']',
|
||||
'status' => ((int)($item['status'] ?? 0) === 1) ? 'tak' : '<span style="color: #FF0000;">nie</span>',
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/scontainers/container_edit/id=' . $id,
|
||||
'url' => '/admin/scontainers/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
[
|
||||
'label' => 'Usun',
|
||||
'url' => '/admin/scontainers/container_delete/id=' . $id,
|
||||
'url' => '/admin/scontainers/delete/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-danger',
|
||||
'confirm' => 'Na pewno chcesz usunac wybrany kontener?',
|
||||
],
|
||||
@@ -119,9 +119,9 @@ class ScontainersController
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/scontainers/view_list/',
|
||||
'/admin/scontainers/list/',
|
||||
'Brak danych w tabeli.',
|
||||
'/admin/scontainers/container_edit/',
|
||||
'/admin/scontainers/edit/',
|
||||
'Dodaj kontener'
|
||||
);
|
||||
|
||||
@@ -218,7 +218,7 @@ class ScontainersController
|
||||
\S::alert('Kontener zostal usuniety.');
|
||||
}
|
||||
|
||||
header('Location: /admin/scontainers/view_list/');
|
||||
header('Location: /admin/scontainers/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -266,10 +266,10 @@ class ScontainersController
|
||||
new FormTab('settings', 'Ustawienia', 'fa-wrench'),
|
||||
];
|
||||
|
||||
$actionUrl = '/admin/scontainers/container_save/' . ($isNew ? '' : ('id=' . $id));
|
||||
$actionUrl = '/admin/scontainers/save/' . ($isNew ? '' : ('id=' . $id));
|
||||
$actions = [
|
||||
FormAction::save($actionUrl, '/admin/scontainers/view_list/'),
|
||||
FormAction::cancel('/admin/scontainers/view_list/'),
|
||||
FormAction::save($actionUrl, '/admin/scontainers/list/'),
|
||||
FormAction::cancel('/admin/scontainers/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
@@ -281,7 +281,7 @@ class ScontainersController
|
||||
$actions,
|
||||
'POST',
|
||||
$actionUrl,
|
||||
'/admin/scontainers/view_list/',
|
||||
'/admin/scontainers/list/',
|
||||
true,
|
||||
[],
|
||||
$languages,
|
||||
|
||||
@@ -309,7 +309,7 @@ class SettingsController
|
||||
];
|
||||
|
||||
$actions = [
|
||||
FormAction::save('/admin/settings/settings_save/', ''),
|
||||
FormAction::save('/admin/settings/save/', ''),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
@@ -320,7 +320,7 @@ class SettingsController
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
'/admin/settings/settings_save/',
|
||||
'/admin/settings/save/',
|
||||
null,
|
||||
false,
|
||||
[],
|
||||
|
||||
@@ -405,6 +405,25 @@ class FormFieldRenderer
|
||||
]), $error);
|
||||
|
||||
default: // TEXT, URL, etc.
|
||||
if (!empty($field->attributes['icon_content'])) {
|
||||
$iconJs = (string)($field->attributes['icon_js'] ?? '');
|
||||
if ($iconJs !== '') {
|
||||
$iconJs = str_replace('{lang}', (string)$languageId, $iconJs);
|
||||
}
|
||||
|
||||
return $this->wrapWithError(\Html::input_icon([
|
||||
'label' => $field->label,
|
||||
'name' => $name,
|
||||
'id' => $id,
|
||||
'value' => $value ?? '',
|
||||
'type' => $field->type === FormFieldType::EMAIL ? 'email' : 'text',
|
||||
'class' => ($field->required ? 'require ' : '') . ($field->attributes['class'] ?? ''),
|
||||
'icon_content' => (string)$field->attributes['icon_content'],
|
||||
'icon_class' => (string)($field->attributes['icon_class'] ?? ''),
|
||||
'icon_js' => $iconJs,
|
||||
]), $error);
|
||||
}
|
||||
|
||||
return $this->wrapWithError(\Html::input([
|
||||
'label' => $field->label,
|
||||
'name' => $name,
|
||||
|
||||
@@ -85,7 +85,7 @@ class Site
|
||||
(bool)\S::get('remember')
|
||||
);
|
||||
|
||||
header('Location: /admin/articles/view_list/');
|
||||
header('Location: /admin/articles/list/');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class Site
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2FA OK — finalna sesja
|
||||
// 2FA OK - finalna sesja
|
||||
$user = $users->details($pending['login']);
|
||||
|
||||
self::finalize_admin_login(
|
||||
@@ -140,7 +140,7 @@ class Site
|
||||
$pending['remember'] ? true : false
|
||||
);
|
||||
|
||||
header('Location: /admin/articles/view_list/');
|
||||
header('Location: /admin/articles/list/');
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
@@ -208,7 +208,8 @@ class Site
|
||||
return new \admin\Controllers\ArticlesController(
|
||||
new \Domain\Article\ArticleRepository( $mdb ),
|
||||
new \Domain\Languages\LanguagesRepository( $mdb ),
|
||||
new \Domain\Layouts\LayoutsRepository( $mdb )
|
||||
new \Domain\Layouts\LayoutsRepository( $mdb ),
|
||||
new \Domain\Pages\PagesRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'ArticlesArchive' => function() {
|
||||
@@ -241,7 +242,7 @@ class Site
|
||||
new \Domain\Product\ProductRepository( $mdb )
|
||||
);
|
||||
},
|
||||
// Alias dla starego modułu /admin/archive/products_list/
|
||||
// Alias dla starego modułu /admin/archive/list/
|
||||
'Archive' => function() {
|
||||
global $mdb;
|
||||
|
||||
@@ -301,6 +302,15 @@ class Site
|
||||
new \Domain\Languages\LanguagesRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'Pages' => function() {
|
||||
global $mdb;
|
||||
|
||||
return new \admin\Controllers\PagesController(
|
||||
new \Domain\Pages\PagesRepository( $mdb ),
|
||||
new \Domain\Languages\LanguagesRepository( $mdb ),
|
||||
new \Domain\Layouts\LayoutsRepository( $mdb )
|
||||
);
|
||||
},
|
||||
];
|
||||
|
||||
return self::$newControllers;
|
||||
@@ -324,40 +334,7 @@ class Site
|
||||
return $factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapowanie nazw akcji: stara_nazwa => nowa_nazwa
|
||||
* Potrzebne gdy stary routing używa innej konwencji nazw
|
||||
*/
|
||||
private static $actionMap = [
|
||||
'gallery_order_save' => 'galleryOrderSave',
|
||||
'files_order_save' => 'filesOrderSave',
|
||||
'view_list' => 'list',
|
||||
'article_edit' => 'edit',
|
||||
'article_save' => 'save',
|
||||
'article_delete' => 'delete',
|
||||
'article_restore' => 'restore',
|
||||
'article_image_alt_change' => 'imageAltChange',
|
||||
'article_file_name_change' => 'fileNameChange',
|
||||
'article_image_delete' => 'imageDelete',
|
||||
'article_file_delete' => 'fileDelete',
|
||||
'banner_edit' => 'edit',
|
||||
'banner_save' => 'save',
|
||||
'banner_delete' => 'delete',
|
||||
'clear_cache' => 'clearCache',
|
||||
'clear_cache_ajax' => 'clearCacheAjax',
|
||||
'settings_save' => 'save',
|
||||
'products_list' => 'list',
|
||||
'unit_edit' => 'edit',
|
||||
'unit_save' => 'save',
|
||||
'unit_delete' => 'delete',
|
||||
'layout_edit' => 'edit',
|
||||
'layout_save' => 'save',
|
||||
'layout_delete' => 'delete',
|
||||
'container_edit' => 'edit',
|
||||
'container_save' => 'save',
|
||||
'container_delete' => 'delete',
|
||||
];
|
||||
|
||||
|
||||
public static function route()
|
||||
{
|
||||
$_SESSION['admin'] = true;
|
||||
@@ -382,12 +359,9 @@ class Site
|
||||
$controller = self::createController( $moduleName );
|
||||
if ( $controller )
|
||||
{
|
||||
// Mapuj nazwę akcji (stara → nowa) lub użyj oryginalnej
|
||||
$newAction = self::$actionMap[$action] ?? $action;
|
||||
|
||||
if ( method_exists( $controller, $newAction ) )
|
||||
if ( method_exists( $controller, $action ) )
|
||||
{
|
||||
return $controller->$newAction();
|
||||
return $controller->$action();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,3 +396,4 @@ class Site
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class Pages
|
||||
{
|
||||
public static function pages_url_browser()
|
||||
{
|
||||
echo \Tpl::view( 'pages/pages-browse-list', [
|
||||
'menus' => \admin\factory\Pages::menus_list(),
|
||||
'modal' => \S::get( 'modal' )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function browse_list()
|
||||
{
|
||||
return \admin\view\Pages::browse_list(
|
||||
\admin\factory\Pages::menus_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function menu_delete()
|
||||
{
|
||||
if ( \admin\factory\Pages::menu_delete( \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Menu zostało usunięte.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania menu wystąpił błąd. Aby usunąć menu nie może ono posiadać przypiętych stron.' );
|
||||
header( 'Location: /admin/pages/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function page_delete()
|
||||
{
|
||||
if ( \admin\factory\Pages::page_delete( \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Strona została usunięta.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania strony wystąpił błąd. Aby usunąć stronę nie może ona posiadać przypiętych podstron.' );
|
||||
header( 'Location: /admin/pages/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function page_articles()
|
||||
{
|
||||
return \admin\view\Pages::page_articles( \S::get( 'id' ), \admin\factory\Pages::page_articles( \S::get( 'id' ) ) );
|
||||
}
|
||||
|
||||
public static function page_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania strony wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Pages::page_save(
|
||||
$values['id'], $values['title'], $values['seo_link'], $values['meta_title'], $values['meta_description'], $values['meta_keywords'], $values['menu_id'], $values['parent_id'], $values['page_type'],
|
||||
$values['sort_type'], $values['layout_id'], $values['articles_limit'], $values['show_title'], $values['status'], $values['link'], $values['noindex'], $values['start'], $values['page_title'],
|
||||
$values['canonical'], $values['category_id']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Strona została zapisana.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function page_edit()
|
||||
{
|
||||
return \Tpl::view( 'pages/page-edit', [
|
||||
'page' => \admin\factory\Pages::page_details( \S::get( 'id' ) ),
|
||||
'parent_id' => \S::get( 'pid' ),
|
||||
'menu_id' => \S::get( 'menu_id' ),
|
||||
'menus' => \admin\factory\Pages::menu_lists(),
|
||||
'layouts' => self::layouts_for_page_edit( $GLOBALS['mdb'] ),
|
||||
'languages' => ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->languagesList()
|
||||
] );
|
||||
}
|
||||
|
||||
private static function layouts_for_page_edit( $db )
|
||||
{
|
||||
if ( class_exists( '\Domain\Layouts\LayoutsRepository' ) )
|
||||
{
|
||||
$rows = ( new \Domain\Layouts\LayoutsRepository( $db ) ) -> listAll();
|
||||
return is_array( $rows ) ? $rows : [];
|
||||
}
|
||||
|
||||
if ( class_exists( '\admin\factory\Layouts' ) )
|
||||
{
|
||||
$rows = \admin\factory\Layouts::layouts_list();
|
||||
return is_array( $rows ) ? $rows : [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function menu_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania menu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( \admin\factory\Pages::menu_save( $values['id'], $values['name'], $values['status'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Menu zostało zapisane.' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function menu_edit()
|
||||
{
|
||||
return \admin\view\Pages::menu_edit(
|
||||
\admin\factory\Pages::menu_details( \S::get( 'id' ) )
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'pages/pages-list', [
|
||||
'menus' => \admin\factory\Pages::menus_list()
|
||||
] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -203,7 +203,7 @@ class ShopProduct
|
||||
else
|
||||
\S::alert( 'Podczas przywracania produktu z archiwum wystąpił błąd. Proszę spróbować ponownie' );
|
||||
|
||||
header( 'Location: /admin/product_archive/products_list/' );
|
||||
header( 'Location: /admin/product_archive/list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -276,8 +276,8 @@ class ShopProduct
|
||||
{
|
||||
echo json_encode( [
|
||||
'status' => 'deprecated',
|
||||
'msg' => 'Endpoint nie jest juz wspierany. Uzyj /admin/product_archive/products_list/.',
|
||||
'redirect_url' => '/admin/product_archive/products_list/'
|
||||
'msg' => 'Endpoint nie jest juz wspierany. Uzyj /admin/product_archive/list/.',
|
||||
'redirect_url' => '/admin/product_archive/list/'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ class Articles
|
||||
public static function article_pages( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
$pagesRepository = new \Domain\Pages\PagesRepository( $mdb );
|
||||
|
||||
$results = $mdb -> query( "SELECT page_id FROM pp_articles_pages WHERE article_id = " . (int)$article_id ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
@@ -68,7 +69,7 @@ class Articles
|
||||
if ( $out == '' )
|
||||
$out .= ' - ';
|
||||
|
||||
$out .= \admin\factory\Pages::page_title( $row['page_id'] );
|
||||
$out .= $pagesRepository->pageTitle( (int)$row['page_id'] );
|
||||
|
||||
if ( end( $results ) != $row )
|
||||
$out .= ' / ';
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace admin\factory;
|
||||
|
||||
use Domain\Layouts\LayoutsRepository;
|
||||
use Domain\Pages\PagesRepository;
|
||||
|
||||
class Layouts
|
||||
{
|
||||
@@ -47,21 +48,8 @@ class Layouts
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
$menus = \admin\factory\Pages::menus_list();
|
||||
if (!is_array($menus)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($menus as $key => $menu) {
|
||||
$menuId = (int)($menu['id'] ?? 0);
|
||||
if ($menuId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$menus[$key]['pages'] = \admin\factory\Pages::menu_pages($menuId);
|
||||
}
|
||||
|
||||
return $menus;
|
||||
global $mdb;
|
||||
return (new PagesRepository($mdb))->menusWithPages();
|
||||
}
|
||||
|
||||
public static function layouts_list()
|
||||
@@ -75,4 +63,3 @@ class Layouts
|
||||
return new LayoutsRepository($mdb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,407 +0,0 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Pages
|
||||
{
|
||||
public static $_page_types = [ 0 => 'pełne artykuły', 1 => 'wprowadzenia', 2 => 'miniaturki', 3 => 'link', 4 => 'kontakt', 5 => 'kategoria sklepu' ];
|
||||
public static $_sort_types = [
|
||||
0 => 'data dodania - najstarsze na początku',
|
||||
1 => 'data dodania - najnowsze na początku',
|
||||
2 => 'data modyfikacji - rosnąco',
|
||||
3 => 'data mofyfikacji - malejąco',
|
||||
4 => 'ręczne',
|
||||
5 => 'alfabetycznie - A - Z',
|
||||
6 => 'alfabetycznie - Z - A'
|
||||
];
|
||||
|
||||
public static function save_articles_order( $page_id, $articles )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $articles ) )
|
||||
{
|
||||
$mdb -> update( 'pp_articles_pages', [ 'o' => 0 ], [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $articles ); $i++ )
|
||||
{
|
||||
if ( $articles[$i]['item_id'] )
|
||||
{
|
||||
$x++;
|
||||
$mdb -> update( 'pp_articles_pages', [ 'o' => $x ], [ 'AND' => [ 'page_id' => (int)$page_id, 'article_id' => $articles[ $i ]['item_id'] ] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function page_articles( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'article_id, o, status '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'page_id = ' . (int)$page_id . ' AND status != -1 '
|
||||
. 'ORDER BY '
|
||||
. 'o ASC' ) -> fetchAll();
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = \admin\factory\Articles::article_title( $row['article_id'] );
|
||||
$articles[] = $row;
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function save_pages_order( $menu_id, $pages )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $pages ) )
|
||||
{
|
||||
$mdb -> update( 'pp_pages', [ 'o' => 0 ], [ 'menu_id' => (int)$menu_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $pages ); $i++ )
|
||||
{
|
||||
if ( $pages[$i]['item_id'] )
|
||||
{
|
||||
$pages[$i]['parent_id'] ? $parent_id = $pages[$i]['parent_id'] : $parent_id = 0;
|
||||
|
||||
if ( $pages[$i]['item_id'] && $pages[$i]['depth'] > 1 )
|
||||
{
|
||||
if ( $pages[$i]['depth'] == 2 )
|
||||
$parent_id = null;
|
||||
|
||||
$x++;
|
||||
|
||||
$mdb -> update( 'pp_pages', [ 'o' => $x, 'parent_id' => $parent_id ], [ 'id' => (int)$pages[ $i ]['item_id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function page_delete( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'parent_id' => (int)$page_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_pages', [ 'id' => (int)$page_id ] );
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_pages', 'o' );
|
||||
}
|
||||
|
||||
public static function page_save(
|
||||
$page_id, $title, $seo_link, $meta_title, $meta_description, $meta_keywords, $menu_id, $parent_id, $page_type, $sort_type, $layout_id, $articles_limit, $show_title, $status,
|
||||
$link, $noindex, $start, $page_title, $canonical, $category_id
|
||||
)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$parent_id )
|
||||
$parent_id = null;
|
||||
|
||||
if ( !$page_id )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_pages', [
|
||||
'menu_id' => (int)$menu_id,
|
||||
'page_type' => $page_type,
|
||||
'sort_type' => $sort_type,
|
||||
'articles_limit' => $articles_limit,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'o' => (int)$order,
|
||||
'parent_id' => $parent_id,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'category_id' => ( $category_id and $page_type == 5 ) ? $category_id : null
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( $start )
|
||||
$mdb -> update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int)$id ] );
|
||||
|
||||
if ( $layout_id )
|
||||
$mdb -> insert( 'pp_layouts_pages', [ 'page_id' => (int)$id, 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_pages_langs', [
|
||||
'page_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_pages', [
|
||||
'menu_id' => (int)$menu_id,
|
||||
'page_type' => $page_type,
|
||||
'sort_type' => $sort_type,
|
||||
'articles_limit' => $articles_limit,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'parent_id' => $parent_id,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'category_id' => ( $category_id and $page_type == 5 ) ? $category_id : null
|
||||
], [
|
||||
'id' => (int)$page_id
|
||||
] );
|
||||
|
||||
if ( $layout_id )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page_id ] );
|
||||
$mdb -> insert( 'pp_layouts_pages', [ 'layout_id' => (int)$layout_id, 'page_id' => (int)$page_id ] );
|
||||
}
|
||||
|
||||
if ( $start )
|
||||
$mdb -> update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int)$page_id ] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_pages_langs', 'id', [ 'AND' => [ 'page_id' => $page_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_pages_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_pages_langs', [
|
||||
'page_id' => (int)$page_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
self::update_supages_menu_id( $page_id, $menu_id );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $page_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function update_supages_menu_id( $parent_id, $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_pages', [ 'menu_id' => (int)$menu_id ], [ 'parent_id' => $parent_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_pages', [ 'id' ], [ 'parent_id' => $parent_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
self::update_supages_menu_id( $row['id'], $menu_id );
|
||||
}
|
||||
|
||||
public static function generate_seo_link( $title, $page_id, $article_id, $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$seo_link = \S::seo( $title );
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_pages_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'page_id[!]' => (int)$page_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
$seo_link_check = false;
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_articles_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'article_id[!]' => (int)$article_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
$seo_link_check = false;
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_shop_categories_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'category_id[!]' => (int)$category_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
return $seo_link;
|
||||
}
|
||||
|
||||
public static function menu_delete( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'menu_id' => (int)$menu_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_menus', [ 'id' => (int)$menu_id ] );
|
||||
}
|
||||
|
||||
public static function menu_details( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_menus', '*', [ 'id' => (int)$menu_id ] );
|
||||
}
|
||||
|
||||
public static function menu_save( $menu_id, $name, $status )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$status == 'on' ? $status = 1 : $status = 0;
|
||||
|
||||
if ( !$menu_id )
|
||||
{
|
||||
return $mdb -> insert( 'pp_menus', [
|
||||
'name' => $name,
|
||||
'status' => $status
|
||||
] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_menus', [
|
||||
'name' => $name,
|
||||
'status' => $status
|
||||
], [
|
||||
'id' => (int)$menu_id
|
||||
] );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function menu_lists()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function page_details( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$page = $mdb -> get( 'pp_pages', '*', [ 'id' => (int)$page_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_pages_langs', '*', [ 'page_id' => (int)$page_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$page['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$page['layout_id'] = $mdb -> get( 'pp_layouts_pages', 'layout_id', [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public static function page_url( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT seo_link FROM pp_pages_langs AS ppl, pp_langs AS pl WHERE lang_id = pl.id AND page_id = " . (int)$page_id . " AND seo_link != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = self::page_title( $article_id );
|
||||
return 's-' . $page_id . '-' . \S::seo( $title );
|
||||
}
|
||||
else
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public static function page_title( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> select( 'pp_pages_langs', [
|
||||
'[><]pp_langs' => [ 'lang_id' => 'id' ]
|
||||
], 'title', [
|
||||
'AND' => [
|
||||
'page_id' => (int)$page_id, 'title[!]' => ''
|
||||
],
|
||||
'ORDER' => [ 'o' => 'ASC' ],
|
||||
'LIMIT' => 1
|
||||
] );
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function page_languages( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_pages_langs', '*',
|
||||
[ 'AND' => [ 'page_id' => (int) $page_id, 'title[!]' => null ] ] );
|
||||
}
|
||||
|
||||
public static function menu_pages( $menu_id, $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_pages',
|
||||
[ 'id', 'menu_id', 'status', 'parent_id', 'start' ],
|
||||
[ 'AND' => [ 'menu_id' => $menu_id, 'parent_id' => $parent_id ], 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = self::page_title( $row['id'] );
|
||||
$row['languages'] = self::page_languages( $row['id'] );
|
||||
$row['subpages'] = self::menu_pages( $menu_id, $row['id'] );
|
||||
|
||||
$pages[] = $row;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,37 +0,0 @@
|
||||
<?
|
||||
namespace admin\view;
|
||||
|
||||
class Pages
|
||||
{
|
||||
public static function subpages_browse_list( $pages, $parent_id = null, $step = 1 )
|
||||
{
|
||||
$tpl = new \Tpl();
|
||||
$tpl -> pages = $pages;
|
||||
$tpl -> parent_id = $parent_id;
|
||||
$tpl -> step = $step;
|
||||
return $tpl -> render( 'pages/subpages-browse-list' );
|
||||
}
|
||||
|
||||
public static function browse_list( $menus )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> menus = $menus;
|
||||
return $tpl -> render( 'pages/pages-browse-list' );
|
||||
}
|
||||
|
||||
public static function page_articles( $page_id, $articles )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> page_id = $page_id;
|
||||
$tpl -> articles = $articles;
|
||||
return $tpl -> render( 'pages/page-articles' );
|
||||
}
|
||||
|
||||
public static function menu_edit( $menu )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> menu = $menu;
|
||||
return $tpl -> render( 'pages/menu-edit' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user