ver. 0.286: Layouts, Menu, Pages frontend migration to Domain
- Add 6 frontend methods to LayoutsRepository (Redis cache, 3-level fallback) - Add 6 frontend methods to PagesRepository (Redis cache, recursive pages) - Create front\Views\Menu (clean VIEW replacing front\view\Menu) - Delete front\factory\Layouts, Menu, Pages + front\view\Menu + dead submenu.php - Fix null $lang_id TypeError in check_url_params() (remove string type hint + ?? '') - Optimize Helpers::htacces() from 3 layout calls to 1 - Tests: 470 OK, 1484 assertions (+16 new) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -227,6 +227,183 @@ class LayoutsRepository
|
||||
];
|
||||
}
|
||||
|
||||
// ── Frontend methods ──────────────────────────────────────────
|
||||
|
||||
public function categoryDefaultLayoutId()
|
||||
{
|
||||
return $this->db->get('pp_layouts', 'id', ['categories_default' => 1]);
|
||||
}
|
||||
|
||||
public function getDefaultLayout(): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'LayoutsRepository::getDefaultLayout';
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached) && !empty($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
if (!is_array($layout) || empty($layout)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function getProductLayout(int $productId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getProductLayout:$productId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached) && !empty($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layoutRows = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_shop_products ON pp_layouts.id = pp_shop_products.layout_id
|
||||
WHERE pp_shop_products.id = " . (int)$productId . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layoutRows = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
JOIN pp_shop_products_categories ON pp_shop_products_categories.category_id = pp_layouts_categories.category_id
|
||||
WHERE pp_shop_products_categories.product_id = " . (int)$productId . "
|
||||
ORDER BY pp_shop_products_categories.o ASC, pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['categories_default' => 1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
}
|
||||
|
||||
if (!is_array($layout) || empty($layout)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function getArticleLayout(int $articleId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getArticleLayout:$articleId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layout = $this->db->get('pp_layouts', ['[><]pp_articles' => ['id' => 'layout_id']], '*', ['pp_articles.id' => (int)$articleId]);
|
||||
|
||||
if (is_array($layout)) {
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCategoryLayout(int $categoryId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getCategoryLayout:$categoryId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached) && !empty($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layoutRows = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
WHERE pp_layouts_categories.category_id = " . (int)$categoryId . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['categories_default' => 1]);
|
||||
}
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
}
|
||||
|
||||
if (!is_array($layout) || empty($layout)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function getActiveLayout(int $pageId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getActiveLayout:$pageId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layout = $this->db->get('pp_layouts', ['[><]pp_layouts_pages' => ['id' => 'layout_id']], '*', ['page_id' => (int)$pageId]);
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
}
|
||||
|
||||
if (is_array($layout)) {
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Private helpers ──────────────────────────────────────────
|
||||
|
||||
private function syncPages(int $layoutId, $pages): void
|
||||
{
|
||||
foreach ($this->normalizeIds($pages) as $pageId) {
|
||||
|
||||
@@ -628,4 +628,158 @@ class PagesRepository
|
||||
$value = trim((string)$value);
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
|
||||
// ── Frontend methods ──────────────────────────────────────────
|
||||
|
||||
public function frontPageDetails($id = '', $langId = ''): ?array
|
||||
{
|
||||
$langId = (string)$langId;
|
||||
|
||||
if (!$id) {
|
||||
$id = $this->frontMainPageId();
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "PagesRepository::frontPageDetails:$id:$langId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$page = $this->db->get('pp_pages', '*', ['id' => (int)$id]);
|
||||
if (!is_array($page)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$page['language'] = $this->db->get('pp_pages_langs', '*', ['AND' => ['page_id' => (int)$id, 'lang_id' => $langId]]);
|
||||
|
||||
$cacheHandler->set($cacheKey, $page);
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function frontPageSort(int $pageId)
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "PagesRepository::frontPageSort:$pageId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if ($cached !== false) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$sort = $this->db->get('pp_pages', 'sort_type', ['id' => $pageId]);
|
||||
|
||||
$cacheHandler->set($cacheKey, $sort);
|
||||
return $sort;
|
||||
}
|
||||
|
||||
public function frontMainPageId()
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'PagesRepository::frontMainPageId';
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if ($cached) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$id = $this->db->get('pp_pages', 'id', ['AND' => ['status' => 1, 'start' => 1]]);
|
||||
if (!$id) {
|
||||
$id = $this->db->get('pp_pages', 'id', ['status' => 1, 'ORDER' => ['menu_id' => 'ASC', 'o' => 'ASC'], 'LIMIT' => 1]);
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $id);
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function frontLangUrl(int $pageId, string $langId): string
|
||||
{
|
||||
$page = $this->frontPageDetails($pageId, $langId);
|
||||
if (!is_array($page) || !is_array($page['language'] ?? null)) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
$seoLink = $page['language']['seo_link'] ?? '';
|
||||
$title = $page['language']['title'] ?? '';
|
||||
$url = $seoLink ? '/' . $seoLink : '/s-' . $page['id'] . '-' . \Shared\Helpers\Helpers::seo($title);
|
||||
|
||||
$defaultLang = (new \Domain\Languages\LanguagesRepository($this->db))->defaultLanguage();
|
||||
if ($langId !== $defaultLang && $url !== '#') {
|
||||
$url = '/' . $langId . $url;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function frontMenuDetails(int $menuId, string $langId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "PagesRepository::frontMenuDetails:$menuId:$langId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$menu = $this->db->get('pp_menus', '*', ['id' => (int)$menuId]);
|
||||
if (!is_array($menu)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$menu['pages'] = $this->frontMenuPages($menuId, $langId);
|
||||
|
||||
$cacheHandler->set($cacheKey, $menu);
|
||||
return $menu;
|
||||
}
|
||||
|
||||
public function frontMenuPages(int $menuId, string $langId, $parentId = null): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "PagesRepository::frontMenuPages:$menuId:$langId:$parentId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$results = $this->db->select('pp_pages', ['id'], [
|
||||
'AND' => ['status' => 1, 'menu_id' => (int)$menuId, 'parent_id' => $parentId],
|
||||
'ORDER' => ['o' => 'ASC'],
|
||||
]);
|
||||
|
||||
$pages = [];
|
||||
if (is_array($results)) {
|
||||
foreach ($results as $row) {
|
||||
$page = $this->frontPageDetails($row['id'], $langId);
|
||||
if (is_array($page)) {
|
||||
$page['pages'] = $this->frontMenuPages($menuId, $langId, $row['id']);
|
||||
$pages[] = $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $pages);
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,13 +445,14 @@ class Helpers
|
||||
//
|
||||
// PRODUCENCI
|
||||
//
|
||||
$htaccess_data .= 'RewriteRule ^producenci$ index.php?module=shop_producer&action=list&layout_id=' . \front\factory\Layouts::category_default_layout() . '&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
$categoryDefaultLayoutId = ( new \Domain\Layouts\LayoutsRepository( $mdb ) )->categoryDefaultLayoutId();
|
||||
$htaccess_data .= 'RewriteRule ^producenci$ index.php?module=shop_producer&action=list&layout_id=' . $categoryDefaultLayoutId . '&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_producer', '*', [ 'status' => 1 ] );
|
||||
if ( self::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
{
|
||||
$htaccess_data .= 'RewriteRule ^producent/' . self::seo( $row['name'] ) . '$ index.php?module=shop_producer&action=products&producer_id=' . $row['id'] . '&layout_id=' . \front\factory\Layouts::category_default_layout() . '&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^producent/' . self::seo( $row['name'] ) . '/([0-9]+)$ index.php?module=shop_producer&action=products&producer_id=' . $row['id'] . '&layout_id=' . \front\factory\Layouts::category_default_layout() . '&bs=$1&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^producent/' . self::seo( $row['name'] ) . '$ index.php?module=shop_producer&action=products&producer_id=' . $row['id'] . '&layout_id=' . $categoryDefaultLayoutId . '&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^producent/' . self::seo( $row['name'] ) . '/([0-9]+)$ index.php?module=shop_producer&action=products&producer_id=' . $row['id'] . '&layout_id=' . $categoryDefaultLayoutId . '&bs=$1&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id', 'start' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
|
||||
22
autoload/front/Views/Menu.php
Normal file
22
autoload/front/Views/Menu.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public static function pages($pages, $level = 0, $current_page = 0)
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->pages = $pages;
|
||||
$tpl->level = $level;
|
||||
$tpl->current_page = $current_page;
|
||||
return $tpl->render('menu/pages');
|
||||
}
|
||||
|
||||
public static function menu($menu, $current_page)
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->menu = $menu;
|
||||
$tpl->current_page = $current_page;
|
||||
return $tpl->render('menu/menu');
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,9 @@ class Site
|
||||
switch ( $a )
|
||||
{
|
||||
case 'page':
|
||||
$page = \front\factory\Pages::page_details( \Shared\Helpers\Helpers::get( 'id' ) );
|
||||
global $lang_id;
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $GLOBALS['mdb'] );
|
||||
$page = $pagesRepo->frontPageDetails( \Shared\Helpers\Helpers::get( 'id' ), $lang_id ?? '' );
|
||||
\Shared\Helpers\Helpers::set_session( 'page', $page );
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
class Layouts
|
||||
{
|
||||
static public function category_default_layout()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_layouts', 'id', [ 'categories_default' => 1 ] );
|
||||
}
|
||||
|
||||
static public function default_layout()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Layouts::default_layout";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
if ( $objectData )
|
||||
{
|
||||
$cachedLayout = @unserialize( $objectData );
|
||||
if ( is_array( $cachedLayout ) and !empty( $cachedLayout ) )
|
||||
return $cachedLayout;
|
||||
|
||||
$cacheHandler -> delete( $cacheKey );
|
||||
}
|
||||
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
|
||||
$cacheHandler -> set( $cacheKey, $layout );
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
static public function product_layout( $product_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Layouts::product_layout:$product_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
if ( $objectData )
|
||||
{
|
||||
$cachedLayout = @unserialize( $objectData );
|
||||
if ( is_array( $cachedLayout ) and !empty( $cachedLayout ) )
|
||||
return $cachedLayout;
|
||||
|
||||
$cacheHandler -> delete( $cacheKey );
|
||||
}
|
||||
|
||||
$layoutRows = $mdb -> query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_shop_products ON pp_layouts.id = pp_shop_products.layout_id
|
||||
WHERE pp_shop_products.id = " . (int)$product_id . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
|
||||
if ( is_array( $layoutRows ) and isset( $layoutRows[0] ) )
|
||||
$layout = $layoutRows[0];
|
||||
else
|
||||
{
|
||||
$layoutRows = $mdb -> query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
JOIN pp_shop_products_categories ON pp_shop_products_categories.category_id = pp_layouts_categories.category_id
|
||||
WHERE pp_shop_products_categories.product_id = " . (int)$product_id . "
|
||||
ORDER BY pp_shop_products_categories.o ASC, pp_layouts.id DESC"
|
||||
) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
|
||||
if ( is_array( $layoutRows ) and isset( $layoutRows[0] ) )
|
||||
$layout = $layoutRows[0];
|
||||
else
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
|
||||
}
|
||||
|
||||
if ( !$layout )
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $layout );
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
static public function article_layout( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Layouts::article_layout:$article_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_articles' => [ 'id' => 'layout_id' ] ], '*', [ 'pp_articles.id' => (int)$article_id ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $layout );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
static public function category_layout( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Layouts::category_layout:$category_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
if ( $objectData )
|
||||
{
|
||||
$cachedLayout = @unserialize( $objectData );
|
||||
if ( is_array( $cachedLayout ) and !empty( $cachedLayout ) )
|
||||
return $cachedLayout;
|
||||
|
||||
$cacheHandler -> delete( $cacheKey );
|
||||
}
|
||||
|
||||
$layoutRows = $mdb -> query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
WHERE pp_layouts_categories.category_id = " . (int)$category_id . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
|
||||
if ( is_array( $layoutRows ) and isset( $layoutRows[0] ) )
|
||||
$layout = $layoutRows[0];
|
||||
else
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
|
||||
|
||||
if ( !$layout )
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $layout );
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
static public function active_layout( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Layouts::active_layout:$page_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_layouts_pages' => [ 'id' => 'layout_id' ] ], '*', [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
if ( !$layout )
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $layout );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public static function menu_details( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Menu::menu_details:$menu_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$menu = $mdb -> get( 'pp_menus', '*', [ 'id' => (int)$menu_id ] );
|
||||
$menu['pages'] = self::menu_pages( $menu_id );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $menu );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
public static function menu_pages( $menu_id, $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Menu::menu_pages:$menu_id:$parent_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_pages', [ 'id' ], [ 'AND' => [ 'status' => 1, 'menu_id' => (int)$menu_id, 'parent_id' => $parent_id ], 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$page = \front\factory\Pages::page_details( $row['id'] );
|
||||
$page['pages'] = self::menu_pages( $menu_id, $row['id'] );
|
||||
|
||||
$pages[] = $page;
|
||||
}
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $pages );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
class Pages
|
||||
{
|
||||
public static function page_sort( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Pages::page_sort:$page_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$sort = $mdb -> get( 'pp_pages', 'sort_type', [ 'id' => $page_id ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $sort );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $sort;
|
||||
}
|
||||
|
||||
public static function lang_url( $page_id, $lang_id )
|
||||
{
|
||||
$page = self::page_details( $page_id, $lang_id );
|
||||
|
||||
$page['language']['seo_link'] ? $url = '/' . $page['language']['seo_link'] : $url = '/s-' . $page['id'] . '-' . \Shared\Helpers\Helpers::seo( $page['language']['title'] );
|
||||
|
||||
if ( $lang_id != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' )
|
||||
$url = '/' . $lang_id . $url;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function page_details( $id = '', $lang_tmp = '' )
|
||||
{
|
||||
global $mdb, $lang_id;
|
||||
|
||||
if ( !$id )
|
||||
$id = self::main_page_id();
|
||||
|
||||
if ( $lang_tmp )
|
||||
$lang_id = $lang_tmp;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Pages::page_details:$id:$lang_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData ) {
|
||||
$page = $mdb->get('pp_pages', '*', ['id' => (int)$id]);
|
||||
$page['language'] = $mdb->get('pp_pages_langs', '*', ['AND' => ['page_id' => (int)$id, 'lang_id' => $lang_id]]);
|
||||
|
||||
$cacheHandler->set($cacheKey, $page);
|
||||
} else {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public static function main_page_id()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\Pages::main_page_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$id = $mdb -> get( 'pp_pages', 'id', [ 'AND' => [ 'status' => 1, 'start' => 1 ] ] );
|
||||
if ( !$id )
|
||||
$id = $mdb -> get( 'pp_pages', 'id', [ 'status' => 1, 'ORDER' => [ 'menu_id' => 'ASC', 'o' => 'ASC' ], 'LIMIT' => 1 ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $id );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public static function pages( $pages, $level = 0, $current_page = 0 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl -> pages = $pages;
|
||||
$tpl -> level = $level;
|
||||
$tpl -> current_page = $current_page;
|
||||
return $tpl -> render( 'menu/pages' );
|
||||
}
|
||||
|
||||
public static function menu( $menu, $current_page )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl -> menu = $menu;
|
||||
$tpl -> current_page = $current_page;
|
||||
return $tpl -> render( 'menu/menu' );
|
||||
}
|
||||
}
|
||||
@@ -24,24 +24,26 @@ class Site
|
||||
|
||||
$articleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] );
|
||||
$bannerRepo = new \Domain\Banner\BannerRepository( $GLOBALS['mdb'] );
|
||||
$layoutsRepo = new \Domain\Layouts\LayoutsRepository( $GLOBALS['mdb'] );
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $GLOBALS['mdb'] );
|
||||
|
||||
if ( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) )
|
||||
$layout = new \cms\Layout( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) );
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get( 'article' ) )
|
||||
$layout = \front\factory\Layouts::article_layout( \Shared\Helpers\Helpers::get( 'article' ) );
|
||||
$layout = $layoutsRepo->getArticleLayout( (int) \Shared\Helpers\Helpers::get( 'article' ) );
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get( 'product' ) )
|
||||
$layout = \front\factory\Layouts::product_layout( \Shared\Helpers\Helpers::get( 'product' ) );
|
||||
$layout = $layoutsRepo->getProductLayout( (int) \Shared\Helpers\Helpers::get( 'product' ) );
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get( 'category' ) )
|
||||
$layout = \front\factory\Layouts::category_layout( \Shared\Helpers\Helpers::get( 'category' ) );
|
||||
$layout = $layoutsRepo->getCategoryLayout( (int) \Shared\Helpers\Helpers::get( 'category' ) );
|
||||
|
||||
if ( !$layout and \Shared\Helpers\Helpers::get( 'module' ) )
|
||||
$layout = \front\factory\Layouts::default_layout();
|
||||
$layout = $layoutsRepo->getDefaultLayout();
|
||||
|
||||
if ( !$layout )
|
||||
$layout = \front\factory\Layouts::active_layout( $page['id'] );
|
||||
$layout = $layoutsRepo->getActiveLayout( $page['id'] );
|
||||
|
||||
if ( $settings['devel'] == true and file_exists( 'devel.html' ) )
|
||||
$html = file_get_contents( 'devel.html' );
|
||||
@@ -120,7 +122,7 @@ class Site
|
||||
if ( is_array( $menu[0] ) ) foreach( $menu[0] as $menu_tmp )
|
||||
{
|
||||
$menu_tmp = explode( ':', $menu_tmp );
|
||||
$html = str_replace( '[MENU:' . $menu_tmp[1] . ']', \front\view\Menu::menu( \front\factory\Menu::menu_details( $menu_tmp[1] ), $page['id'] ), $html );
|
||||
$html = str_replace( '[MENU:' . $menu_tmp[1] . ']', \front\Views\Menu::menu( $pagesRepo->frontMenuDetails( (int) $menu_tmp[1], $lang_id ), $page['id'] ), $html );
|
||||
}
|
||||
|
||||
preg_match_all( self::menu_main_pattern, $html, $menu );
|
||||
@@ -130,7 +132,7 @@ class Site
|
||||
$html = str_replace(
|
||||
'[MENU_GLOWNE:' . $menu_tmp[1] . ']',
|
||||
\Shared\Tpl\Tpl::view( 'menu/main-menu', [
|
||||
'menu' => \front\factory\Menu::menu_details( $menu_tmp[1] )
|
||||
'menu' => $pagesRepo->frontMenuDetails( (int) $menu_tmp[1], $lang_id )
|
||||
] ),
|
||||
$html );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user