From 0402dbee769a49f377c56145f3380774fc7ef777 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Mon, 16 Feb 2026 15:52:03 +0100 Subject: [PATCH] ver. 0.280: Articles frontend migration, class.Article removal, Settings facade cleanup - Add 8 frontend methods to ArticleRepository (with Redis cache) - Create front\Views\Articles (rendering + utility methods) - Rewire front\view\Site::show() and front\controls\Site::route() to repo + Views - Update 5 article templates to use \front\Views\Articles:: - Convert front\factory\Articles and front\view\Articles to facades - Remove class.Article (entity + static methods migrated to repo + Views) - Remove front\factory\Settings facade (already migrated) - Fix: eliminate global $lang from articleNoindex(), inline page sort query - Tests: 450 OK, 1431 assertions (+13 new) Co-Authored-By: Claude Opus 4.6 --- admin/index.php | 2 +- ajax.php | 2 +- api.php | 2 +- autoload/Domain/Article/ArticleRepository.php | 337 +++++++++++++++++- autoload/Domain/Product/ProductRepository.php | 2 +- autoload/class.Article.php | 217 ----------- autoload/class.S.php | 2 +- autoload/front/Views/Articles.php | 241 +++++++++++++ autoload/front/controls/class.Site.php | 21 +- autoload/front/factory/class.Articles.php | 309 ++-------------- autoload/front/factory/class.Settings.php | 22 -- autoload/front/view/class.Articles.php | 107 ++---- autoload/front/view/class.Site.php | 28 +- autoload/shop/class.Order.php | 2 +- cron-turstmate.php | 2 +- cron.php | 2 +- cron/cron-xml.php | 2 +- docs/CHANGELOG.md | 19 + docs/FRONTEND_REFACTORING_PLAN.md | 38 +- docs/PROJECT_STRUCTURE.md | 6 +- docs/TESTING.md | 9 +- docs/UPDATE_INSTRUCTIONS.md | 14 +- index.php | 2 +- templates/articles/article-entry.php | 2 +- templates/articles/article-full.php | 10 +- templates/articles/article-miniature.php | 2 +- templates/articles/article.php | 4 +- templates/articles/news.php | 2 +- templates/menu/pages.php | 2 +- .../Domain/Article/ArticleRepositoryTest.php | 286 +++++++++++++++ tests/bootstrap.php | 1 + updates/0.20/ver_0.280.zip | Bin 0 -> 65159 bytes updates/0.20/ver_0.280_files.txt | 2 + updates/changelog.php | 11 + updates/versions.php | 2 +- 35 files changed, 1070 insertions(+), 642 deletions(-) delete mode 100644 autoload/class.Article.php create mode 100644 autoload/front/Views/Articles.php delete mode 100644 autoload/front/factory/class.Settings.php create mode 100644 updates/0.20/ver_0.280.zip create mode 100644 updates/0.20/ver_0.280_files.txt diff --git a/admin/index.php b/admin/index.php index b708eb1..6eb5c7a 100644 --- a/admin/index.php +++ b/admin/index.php @@ -45,7 +45,7 @@ define( 'REDBEAN_MODEL_PREFIX', '' ); date_default_timezone_set( 'Europe/Warsaw' ); -$settings = \front\factory\Settings::settings_details(); +$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); if ( file_exists( 'config.php' ) ) include 'config.php'; diff --git a/ajax.php b/ajax.php index d1d74c0..68d48c5 100644 --- a/ajax.php +++ b/ajax.php @@ -52,7 +52,7 @@ if ( !$lang = \S::get_session( 'lang' ) ) if ( !$settings = \S::get_session( 'settings' ) ) { - $settings = \front\factory\Settings::settings_details(); + $settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); \S::set_session( 'settings', $settings ); } diff --git a/api.php b/api.php index eb93262..26032c7 100644 --- a/api.php +++ b/api.php @@ -50,7 +50,7 @@ $mdb = new medoo( [ 'charset' => 'utf8' ] ); -$settings = \front\factory\Settings::settings_details(); +$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); if ( \S::get( 'ekomi_csv' ) ) { diff --git a/autoload/Domain/Article/ArticleRepository.php b/autoload/Domain/Article/ArticleRepository.php index a5ea795..ae654d9 100644 --- a/autoload/Domain/Article/ArticleRepository.php +++ b/autoload/Domain/Article/ArticleRepository.php @@ -858,7 +858,342 @@ class ArticleRepository if ( is_array( $rows ) ) { foreach ( $rows as $row ) { - $articles[] = \front\factory\Articles::article_details( $row['id'], 'pl' ); + $articles[] = $this->articleDetailsFrontend( $row['id'], 'pl' ); + } + } + + return $articles; + } + + // ========================================================================= + // FRONTEND METHODS (z Redis cache) + // ========================================================================= + + /** + * Pobiera szczegoly artykulu dla frontendu (z copy_from fallback + Redis cache). + */ + public function articleDetailsFrontend(int $articleId, string $langId): ?array + { + $cacheHandler = new \CacheHandler(); + $cacheKey = "ArticleRepository::articleDetailsFrontend:{$articleId}:{$langId}"; + + $objectData = $cacheHandler->get($cacheKey); + + if ($objectData) { + return unserialize($objectData); + } + + $article = $this->db->get('pp_articles', '*', ['id' => $articleId]); + + if (!$article) { + return null; + } + + $results = $this->db->select('pp_articles_langs', '*', [ + 'AND' => ['article_id' => $articleId, 'lang_id' => $langId] + ]); + + if (is_array($results)) { + foreach ($results as $row) { + if ($row['copy_from']) { + $results2 = $this->db->select('pp_articles_langs', '*', [ + 'AND' => ['article_id' => $articleId, 'lang_id' => $row['copy_from']] + ]); + if (is_array($results2)) { + foreach ($results2 as $row2) { + $article['language'] = $row2; + } + } + } else { + $article['language'] = $row; + } + } + } + + $article['images'] = $this->db->select('pp_articles_images', '*', [ + 'article_id' => $articleId, + 'ORDER' => ['o' => 'ASC', 'id' => 'DESC'] + ]); + + $article['files'] = $this->db->select('pp_articles_files', '*', [ + 'article_id' => $articleId + ]); + + $article['pages'] = $this->db->select('pp_articles_pages', 'page_id', [ + 'article_id' => $articleId + ]); + + $cacheHandler->set($cacheKey, $article); + + return $article; + } + + /** + * Pobiera ID artykulow ze strony z sortowaniem i paginacja (z Redis cache). + */ + public function articlesIds(int $pageId, string $langId, int $limit, int $sortType, int $from): ?array + { + $output = null; + + switch ($sortType) { + case 0: $order = 'date_add ASC'; break; + case 1: $order = 'date_add DESC'; break; + case 2: $order = 'date_modify ASC'; break; + case 3: $order = 'date_modify DESC'; break; + case 4: $order = 'o ASC'; break; + case 5: $order = 'title ASC'; break; + case 6: $order = 'title DESC'; break; + default: $order = 'id ASC'; break; + } + + $cacheHandler = new \CacheHandler(); + $cacheKey = "ArticleRepository::articlesIds:{$pageId}:{$langId}:{$limit}:{$sortType}:{$from}:{$order}"; + + $objectData = $cacheHandler->get($cacheKey); + + if ($objectData) { + return unserialize($objectData); + } + + $results = $this->db->query( + 'SELECT * FROM ( ' + . 'SELECT ' + . 'a.id, date_modify, date_add, o, ' + . '( CASE ' + . 'WHEN copy_from IS NULL THEN title ' + . 'WHEN copy_from IS NOT NULL THEN ( ' + . 'SELECT title FROM pp_articles_langs ' + . 'WHERE lang_id = al.copy_from AND article_id = a.id ' + . ') ' + . 'END ) AS title ' + . 'FROM ' + . 'pp_articles_pages AS ap ' + . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' + . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' + . 'WHERE ' + . 'status = 1 AND page_id = ' . (int)$pageId . ' AND lang_id = \'' . $langId . '\' ' + . ') AS q1 ' + . 'WHERE q1.title IS NOT NULL ' + . 'ORDER BY q1.' . $order . ' ' + . 'LIMIT ' . (int)$from . ',' . (int)$limit + )->fetchAll(); + + if (is_array($results) && !empty($results)) { + foreach ($results as $row) { + $output[] = $row['id']; + } + } + + $cacheHandler->set($cacheKey, $output); + + return $output; + } + + /** + * Zlicza artykuly na stronie (z Redis cache). + */ + public function pageArticlesCount(int $pageId, string $langId): int + { + $cacheHandler = new \CacheHandler(); + $cacheKey = "ArticleRepository::pageArticlesCount:{$pageId}:{$langId}"; + + $objectData = $cacheHandler->get($cacheKey); + + if ($objectData) { + return (int)unserialize($objectData); + } + + $results = $this->db->query( + 'SELECT COUNT(0) FROM ( ' + . 'SELECT ' + . 'a.id, ' + . '( CASE ' + . 'WHEN copy_from IS NULL THEN title ' + . 'WHEN copy_from IS NOT NULL THEN ( ' + . 'SELECT title FROM pp_articles_langs ' + . 'WHERE lang_id = al.copy_from AND article_id = a.id ' + . ') ' + . 'END ) AS title ' + . 'FROM ' + . 'pp_articles_pages AS ap ' + . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' + . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' + . 'WHERE ' + . 'status = 1 AND page_id = ' . (int)$pageId . ' AND lang_id = \'' . $langId . '\' ' + . ') AS q1 ' + . 'WHERE q1.title IS NOT NULL' + )->fetchAll(); + + $count = isset($results[0][0]) ? (int)$results[0][0] : 0; + + $cacheHandler->set($cacheKey, $count); + + return $count; + } + + /** + * Pobiera paginowane artykuly ze strony. + * + * @return array{articles: ?array, ls: int} + */ + public function pageArticles(array $page, string $langId, int $bs): array + { + $count = $this->pageArticlesCount((int)$page['id'], $langId); + $articlesLimit = (int)($page['articles_limit'] ?: 10); + $ls = (int)ceil($count / $articlesLimit); + + if ($bs < 1) { + $bs = 1; + } elseif ($bs > $ls) { + $bs = $ls; + } + + $from = $articlesLimit * ($bs - 1); + + if ($from < 0) { + $from = 0; + } + + return [ + 'articles' => $this->articlesIds((int)$page['id'], $langId, $articlesLimit, (int)($page['sort_type'] ?? 0), $from), + 'ls' => $ls, + ]; + } + + /** + * Pobiera artykuly-aktualnosci ze strony (z sortowaniem wg page_sort). + */ + public function news(int $pageId, int $limit, string $langId): ?array + { + $sort = (int)$this->db->get('pp_pages', 'sort_type', ['id' => $pageId]); + + $articlesIds = $this->articlesIds($pageId, $langId, $limit, $sort, 0); + + $articles = null; + if (is_array($articlesIds) && !empty($articlesIds)) { + foreach ($articlesIds as $articleId) { + $articles[] = $this->articleDetailsFrontend($articleId, $langId); + } + } + + return $articles; + } + + /** + * Sprawdza czy artykul ma flage noindex (z Redis cache). + */ + public function articleNoindex(int $articleId, string $langId): bool + { + $cacheHandler = new \CacheHandler(); + $cacheKey = "ArticleRepository::articleNoindex:{$articleId}:{$langId}"; + + $objectData = $cacheHandler->get($cacheKey); + + if ($objectData) { + return (bool)unserialize($objectData); + } + + $noindex = $this->db->get('pp_articles_langs', 'noindex', [ + 'AND' => ['article_id' => $articleId, 'lang_id' => $langId] + ]); + + $cacheHandler->set($cacheKey, $noindex); + + return (bool)$noindex; + } + + /** + * Pobiera najpopularniejsze artykuly ze strony (wg views DESC, z Redis cache). + */ + public function topArticles(int $pageId, int $limit, string $langId): ?array + { + $cacheHandler = new \CacheHandler(); + $cacheKey = "ArticleRepository::topArticles:{$pageId}:{$limit}:{$langId}"; + + $objectData = $cacheHandler->get($cacheKey); + + if (!$objectData) { + $articlesData = $this->db->query( + 'SELECT * FROM ( ' + . 'SELECT ' + . 'a.id, date_add, views, ' + . '( CASE ' + . 'WHEN copy_from IS NULL THEN title ' + . 'WHEN copy_from IS NOT NULL THEN ( ' + . 'SELECT title FROM pp_articles_langs ' + . 'WHERE lang_id = al.copy_from AND article_id = a.id ' + . ') ' + . 'END ) AS title ' + . 'FROM ' + . 'pp_articles_pages AS ap ' + . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' + . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' + . 'WHERE ' + . 'status = 1 AND page_id = ' . (int)$pageId . ' AND lang_id = \'' . $langId . '\' ' + . ') AS q1 ' + . 'WHERE q1.title IS NOT NULL ' + . 'ORDER BY q1.views DESC ' + . 'LIMIT 0, ' . (int)$limit + )->fetchAll(\PDO::FETCH_ASSOC); + + $cacheHandler->set($cacheKey, $articlesData); + } else { + $articlesData = unserialize($objectData); + } + + $articles = null; + if (\S::is_array_fix($articlesData)) { + foreach ($articlesData as $row) { + $articles[] = $this->articleDetailsFrontend((int)$row['id'], $langId); + } + } + + return $articles; + } + + /** + * Pobiera najnowsze artykuly ze strony (wg date_add DESC, z Redis cache). + */ + public function newsListArticles(int $pageId, int $limit, string $langId): ?array + { + $cacheHandler = new \CacheHandler(); + $cacheKey = "ArticleRepository::newsListArticles:{$pageId}:{$limit}:{$langId}"; + + $objectData = $cacheHandler->get($cacheKey); + + if (!$objectData) { + $articlesData = $this->db->query( + 'SELECT * FROM ( ' + . 'SELECT ' + . 'a.id, date_add, ' + . '( CASE ' + . 'WHEN copy_from IS NULL THEN title ' + . 'WHEN copy_from IS NOT NULL THEN ( ' + . 'SELECT title FROM pp_articles_langs ' + . 'WHERE lang_id = al.copy_from AND article_id = a.id ' + . ') ' + . 'END ) AS title ' + . 'FROM ' + . 'pp_articles_pages AS ap ' + . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' + . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' + . 'WHERE ' + . 'status = 1 AND page_id = ' . (int)$pageId . ' AND lang_id = \'' . $langId . '\' ' + . ') AS q1 ' + . 'WHERE q1.title IS NOT NULL ' + . 'ORDER BY q1.date_add DESC ' + . 'LIMIT 0, ' . (int)$limit + )->fetchAll(\PDO::FETCH_ASSOC); + + $cacheHandler->set($cacheKey, $articlesData); + } else { + $articlesData = unserialize($objectData); + } + + $articles = null; + if (\S::is_array_fix($articlesData)) { + foreach ($articlesData as $row) { + $articles[] = $this->articleDetailsFrontend((int)$row['id'], $langId); } } diff --git a/autoload/Domain/Product/ProductRepository.php b/autoload/Domain/Product/ProductRepository.php index 6cd4d1f..128d5ba 100644 --- a/autoload/Domain/Product/ProductRepository.php +++ b/autoload/Domain/Product/ProductRepository.php @@ -1524,7 +1524,7 @@ class ProductRepository { global $lang_id; - $settings = \front\factory\Settings::settings_details( true ); + $settings = ( new \Domain\Settings\SettingsRepository( $this->db ) )->allSettings( true ); $domainPrefix = 'https'; $url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] ); diff --git a/autoload/class.Article.php b/autoload/class.Article.php deleted file mode 100644 index 3998a06..0000000 --- a/autoload/class.Article.php +++ /dev/null @@ -1,217 +0,0 @@ - get( 'pp_articles', '*', [ 'id' => (int)$article_id ] ); - if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val ) - $this -> $key = $val; - - $results = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang_id ] ] ); - if ( is_array( $results ) ) foreach ( $results as $row ) - { - if ( $row['copy_from'] ) - { - $results2 = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $row['copy_from'] ] ] ); - if ( is_array( $results2 ) ) foreach ( $results2 as $row2 ) - $this -> language = $row2; - } - else - $this -> language = $row; - - preg_match_all( \front\view\Site::container_pattern, $this -> language['entry'], $container_list ); - if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp ) - { - $container_list_tmp = explode( ':', $container_list_tmp ); - $this -> language['entry'] = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $this -> language['entry'] ); - } - - preg_match_all( \front\view\Site::container_pattern, $this -> language['text'], $container_list ); - if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp ) - { - $container_list_tmp = explode( ':', $container_list_tmp ); - $this -> language['text'] = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $this -> language['text'] ); - } - } - - $this -> images = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] ); - $this -> files = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] ); - $this -> pages = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] ); - if ( is_array( $results ) ) foreach ( $results as $row ) - { - if ( !$row['language_id'] ) - $params[ $row['name'] ] = $row['value']; - else - $params[ $row['name'] ][$row['language_id']] = $row['value']; - } - $this -> params = $params; - } - - static public function get_from_cache( $article_id, $lang_id ) - { - $cacheHandler = new \CacheHandler(); - $cacheKey = "\Article::get_from_cache:$article_id:$lang_id"; - - $objectData = $cacheHandler -> get( $cacheKey ); - - if ( !$objectData ) - { - $article = new \Article( $article_id, $lang_id ); - - $cacheHandler -> set( $cacheKey, $article ); - } - else - { - return unserialize( $objectData ); - } - - return $article; - } - - public function updateView() - { - global $mdb; - $mdb -> update( 'pp_articles', [ 'views[+]' => 1 ], [ 'id' => $this -> id ] ); - } - - static public function newsList( $articles ) - { - return \Tpl::view( 'articles/news-list', [ - 'articles' => $articles - ] ); - } - - // pobierz najczęściej wyświtlane artykuły - static public function getTopNews( $page_id, $limit = 6, $lang_id ) - { - global $mdb; - - $cacheHandler = new \CacheHandler(); - $cacheKey = "\Article::getTopNews:$page_id:$limit:$lang_id"; - - $objectData = $cacheHandler -> get( $cacheKey ); - - if ( !$objectData ) - { - $articles_id = $mdb -> query( 'SELECT * FROM ( ' - . 'SELECT ' - . 'a.id, date_add, views, ' - . '( CASE ' - . 'WHEN copy_from IS NULL THEN title ' - . 'WHEN copy_from IS NOT NULL THEN ( ' - . 'SELECT ' - . 'title ' - . 'FROM ' - . 'pp_articles_langs ' - . 'WHERE ' - . 'lang_id = al.copy_from AND article_id = a.id ' - . ') ' - . 'END ) AS title ' - . 'FROM ' - . 'pp_articles_pages AS ap ' - . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' - . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' - . 'WHERE ' - . 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' ' - . ') AS q1 ' - . 'WHERE ' - . 'q1.title IS NOT NULL ' - . 'ORDER BY ' - . 'q1.views DESC ' - . 'LIMIT ' - . '0, ' . (int)$limit ) -> fetchAll( \PDO::FETCH_ASSOC ); - - $cacheHandler -> set( $cacheKey, $articles_id ); - } - else - { - $articles_id = unserialize( $objectData ); - } - - if ( \S::is_array_fix( $articles_id ) ) foreach ( $articles_id as $article_tmp ) - { - $article = \Article::get_from_cache( $article_tmp['id'], $lang_id ); - $articles[] = $article; - } - - return $articles; - } - - static public function getNews( $page_id, $limit = 6, $lang_id ) - { - global $mdb; - - if ( !$articles_id = \Cache::fetch( "getNews:$page_id:$limit:$lang_id" ) ) - { - $articles_id = $mdb -> query( 'SELECT * FROM ( ' - . 'SELECT ' - . 'a.id, date_add, ' - . '( CASE ' - . 'WHEN copy_from IS NULL THEN title ' - . 'WHEN copy_from IS NOT NULL THEN ( ' - . 'SELECT ' - . 'title ' - . 'FROM ' - . 'pp_articles_langs ' - . 'WHERE ' - . 'lang_id = al.copy_from AND article_id = a.id ' - . ') ' - . 'END ) AS title ' - . 'FROM ' - . 'pp_articles_pages AS ap ' - . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' - . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' - . 'WHERE ' - . 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' ' - . ') AS q1 ' - . 'WHERE ' - . 'q1.title IS NOT NULL ' - . 'ORDER BY ' - . 'q1.date_add DESC ' - . 'LIMIT ' - . '0, ' . (int)$limit ) -> fetchAll( \PDO::FETCH_ASSOC ); - \Cache::store( "getNews:$page_id:$limit:$lang_id", $articles_id ); - } - - if ( \S::is_array_fix( $articles_id ) ) foreach ( $articles_id as $article_tmp ) - { - $article = \Article::get_from_cache( $article_tmp['id'], $lang_id ); - $articles[] = $article; - } - - return $articles; - } - - public function __get( $variable ) - { - if ( array_key_exists( $variable, $this -> data ) ) - return $this -> $variable; - } - - public function __set( $variable, $value ) - { - $this -> $variable = $value; - } - - public function offsetExists( $offset ) - { - return isset( $this -> $offset ); - } - - public function offsetGet( $offset ) - { - return $this -> $offset; - } - - public function offsetSet( $offset, $value ) - { - $this -> $offset = $value; - } - - public function offsetUnset( $offset ) - { - unset( $this -> $offset ); - } -} \ No newline at end of file diff --git a/autoload/class.S.php b/autoload/class.S.php index 67e0aa3..17e7531 100644 --- a/autoload/class.S.php +++ b/autoload/class.S.php @@ -573,7 +573,7 @@ class S { global $mdb; - $settings = \front\factory\Settings::settings_details( true ); + $settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings( true ); $url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] ); diff --git a/autoload/front/Views/Articles.php b/autoload/front/Views/Articles.php new file mode 100644 index 0000000..5cc5c10 --- /dev/null +++ b/autoload/front/Views/Articles.php @@ -0,0 +1,241 @@ +article = $article; + return $tpl->render( 'articles/article' ); + } + + /** + * Renderuje liste artykulow w trybie miniaturek z pagerem. + */ + public static function miniatureArticlesList( $articles, $ls, $bs, $page ) + { + $out = ''; + + if ( is_array( $articles ) ) foreach ( $articles as $article ) + { + $tpl = new \Tpl; + $tpl->article = $article; + $out .= $tpl->render( 'articles/article-miniature' ); + } + + if ( $ls > 1 ) + { + $tpl = new \Tpl; + $tpl->ls = $ls; + $tpl->bs = $bs ? $bs : 1; + $tpl->page = $page; + $out .= $tpl->render( 'site/pager' ); + } + + return $out; + } + + /** + * Renderuje liste artykulow w trybie wprowadzen z pagerem. + */ + public static function entryArticlesList( $articles, $ls, $bs, $page ) + { + $tpl = new \Tpl; + $tpl->page_id = $page['id']; + $tpl->articles = $articles; + $out = $tpl->render( 'articles/articles-entries' ); + + if ( $ls > 1 ) + { + $tpl = new \Tpl; + $tpl->ls = $ls; + $tpl->bs = $bs ? $bs : 1; + $tpl->page = $page; + $out .= $tpl->render( 'site/pager' ); + } + + return $out; + } + + /** + * Renderuje liste pelnych artykulow z pagerem. + */ + public static function fullArticlesList( $articles, $ls, $bs, $page ) + { + $out = ''; + + if ( is_array( $articles ) ) foreach ( $articles as $article ) + { + $tpl = new \Tpl; + $tpl->article = $article; + $out .= $tpl->render( 'articles/article-full' ); + } + + if ( $ls > 1 ) + { + $tpl = new \Tpl; + $tpl->ls = $ls; + $tpl->bs = $bs ? $bs : 1; + $tpl->page = $page; + $out .= $tpl->render( 'site/pager' ); + } + + return $out; + } + + /** + * Renderuje box z aktualnosciami. + */ + public static function news( $page_id, $articles ) + { + $tpl = new \Tpl; + $tpl->page_id = $page_id; + $tpl->articles = $articles; + return $tpl->render( 'articles/news' ); + } + + /** + * Renderuje prosta liste artykulow (news-list). + */ + public static function newsList( $articles ) + { + return \Tpl::view( 'articles/news-list', [ + 'articles' => $articles + ] ); + } + + // ========================================================================= + // UTILITY (czyste transformacje HTML, brak DB) + // ========================================================================= + + /** + * Generuje spis tresci z naglowkow HTML. + */ + public static function generateTableOfContents( $content ) + { + $result = ''; + $currentLevel = []; + + preg_match_all( '/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER ); + + $firstLevel = true; + + foreach ( $matches as $match ) + { + $level = intval( substr( $match[1], 1 ) ); + + while ( $level < count( $currentLevel ) ) + { + $result .= ''; + array_pop( $currentLevel ); + } + + if ( $level > count( $currentLevel ) ) + { + while ( $level > count( $currentLevel ) ) + { + if ( count( $currentLevel ) > 0 || $firstLevel ) + { + $result .= '
    '; + $firstLevel = false; + } + array_push( $currentLevel, 0 ); + } + $result .= '
  1. '; + } + else + { + $result .= '
  2. '; + } + + $currentLevel[ count( $currentLevel ) - 1 ]++; + + preg_match( '/\sid="([^"]*)"/', $match[2], $idMatches ); + $id = isset( $idMatches[1] ) ? $idMatches[1] : ''; + + $result .= sprintf( + '%s', + urlencode( strtolower( $id ) ), + $match[3] + ); + } + + while ( !empty( $currentLevel ) ) + { + $result .= '
'; + array_pop( $currentLevel ); + } + + if ( substr( $result, 0, 8 ) === '
      ' ) + return substr( $result, 4, -5 ); + else + return $result; + } + + /** + * Callback dla processHeaders. + */ + public static function processHeaders( $matches ) + { + $level = $matches[1]; + $attrs = $matches[2]; + $content = $matches[3]; + $id_attr = 'id='; + $id_attr_pos = strpos( $attrs, $id_attr ); + if ( $id_attr_pos === false ) + { + $id = \S::seo( $content ); + $attrs .= sprintf( ' id="%s"', $id ); + } + + return sprintf( '%s', $level, $attrs, $content, $level ); + } + + /** + * Dodaje atrybuty id do naglowkow HTML. + */ + public static function generateHeadersIds( $text ) + { + $pattern = '/(.*?)<\/h\1>/si'; + $text = preg_replace_callback( $pattern, array( __CLASS__, 'processHeaders' ), $text ); + return $text; + } + + /** + * Pobiera glowne zdjecie artykulu (z entry, text lub galerii). + */ + public static function getImage( $article ) + { + if ( $main_img = $article['language']['main_image'] ) + return $main_img; + + $dom = new \DOMDocument(); + @$dom->loadHTML( mb_convert_encoding( $article['language']['entry'], 'HTML-ENTITIES', 'UTF-8' ) ); + $images = $dom->getElementsByTagName( 'img' ); + foreach ( $images as $img ) + { + $src = $img->getAttribute( 'src' ); + if ( file_exists( substr( $src, 1, strlen( $src ) ) ) ) + return $src; + } + + $dom = new \DOMDocument(); + @$dom->loadHTML( mb_convert_encoding( $article['language']['text'], 'HTML-ENTITIES', 'UTF-8' ) ); + $images = $dom->getElementsByTagName( 'img' ); + foreach ( $images as $img ) + { + $src = $img->getAttribute( 'src' ); + if ( file_exists( substr( $src, 1, strlen( $src ) ) ) ) + return $src; + } + + if ( $article['images'] ) + return $article['images'][0]['src']; + + return false; + } +} diff --git a/autoload/front/controls/class.Site.php b/autoload/front/controls/class.Site.php index d91337d..0cf94ce 100644 --- a/autoload/front/controls/class.Site.php +++ b/autoload/front/controls/class.Site.php @@ -35,8 +35,10 @@ class Site { global $page, $lang_id, $settings; + $articleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + if ( \S::get( 'article' ) ) - return \front\view\Articles::full_article( \S::get( 'article' ), $lang_id ); + return \front\Views\Articles::fullArticle( $articleRepo->articleDetailsFrontend( (int)\S::get( 'article' ), $lang_id ) ); // wyświetlenie pojedynczego produktu if ( $product ) @@ -86,26 +88,35 @@ class Site if ( $page['id'] ) { + $bs = (int)\S::get( 'bs' ); + $pageArticlesResult = $articleRepo->pageArticles( $page, $lang_id, $bs ?: 1 ); + $articlesForPage = []; + if ( is_array( $pageArticlesResult['articles'] ) ) { + foreach ( $pageArticlesResult['articles'] as $aid ) { + $articlesForPage[] = $articleRepo->articleDetailsFrontend( (int)$aid, $lang_id ); + } + } + switch ( $page['page_type'] ) { /* pełne artykuły */ case 0: - return \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) ); + return \front\Views\Articles::fullArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page ); break; /* wprowadzenia */ case 1: - return \front\view\Articles::entry_articles_list( $page, $lang_id, \S::get( 'bs' ) ); + return \front\Views\Articles::entryArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page ); break; /* miniaturki */ case 2: - return \front\view\Articles::miniature_articles_list( $page, $lang_id, \S::get( 'bs' ) ); + return \front\Views\Articles::miniatureArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page ); break; /* strona kontaktu */ case 4: - $out = \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) ); + $out = \front\Views\Articles::fullArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page ); $out .= \front\view\Site::contact(); return $out; break; diff --git a/autoload/front/factory/class.Articles.php b/autoload/front/factory/class.Articles.php index fd2098c..e7d90c0 100644 --- a/autoload/front/factory/class.Articles.php +++ b/autoload/front/factory/class.Articles.php @@ -1,317 +1,66 @@ ]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER); - - $firstLevel = true; - - foreach ($matches as $match) { - $level = intval(substr($match[1], 1)); - - while ($level < count($currentLevel)) { - $result .= '
    '; - array_pop($currentLevel); - } - - if ($level > count($currentLevel)) { - while ($level > count($currentLevel)) { - if (count($currentLevel) > 0 || $firstLevel) { - $result .= '
      '; - $firstLevel = false; - } - array_push($currentLevel, 0); - } - $result .= '
    1. '; - } else { - $result .= '
    2. '; - } - - $currentLevel[count($currentLevel) - 1]++; - - preg_match('/\sid="([^"]*)"/', $match[2], $idMatches); - $id = isset($idMatches[1]) ? $idMatches[1] : ''; - - $result .= sprintf( - '%s', - urlencode(strtolower($id)), - $match[3] - ); - } - - while (!empty($currentLevel)) { - $result .= '
    '; - array_pop($currentLevel); - } - - if (substr($result, 0, 8) === '
        ') { - return substr($result, 4, -5); - } else { - return $result; - } + static public function generateTableOfContents( $content ) + { + return \front\Views\Articles::generateTableOfContents( $content ); } - // funkcja wywoływana dla każdego dopasowania do wyrażenia regularnego static public function processHeaders( $matches ) { - $level = $matches[1]; - $attrs = $matches[2]; - $content = $matches[3]; - $id_attr = 'id='; - $id_attr_pos = strpos($attrs, $id_attr); - if ($id_attr_pos === false) { // jeśli nie ma atrybutu id - $id = \S::seo( $content ); - $attrs .= sprintf(' id="%s"', $id); - } - - $html = sprintf( '%s', $level, $attrs, $content, $level ); - return $html; + return \front\Views\Articles::processHeaders( $matches ); } static public function generateHeadersIds( $text ) { - $pattern = '/(.*?)<\/h\1>/si'; - - $text = preg_replace_callback( $pattern, array(__CLASS__, 'processHeaders'), $text ); - - return $text; - } - - public static function news( $page_id, $limit = 6, $lang_id ) - { - $sort = \front\factory\Pages::page_sort( $page_id ); - - $articles_id = \front\factory\Articles::artciles_id( (int)$page_id, $lang_id, $limit, $sort, 0 ); - if ( is_array( $articles_id ) and !empty( $articles_id ) ) foreach ( $articles_id as $article_id ) - $articles[] = \front\factory\Articles::article_details( $article_id, $lang_id ); - - return $articles; + return \front\Views\Articles::generateHeadersIds( $text ); } public static function get_image( $article ) { - if ( $main_img = $article['language']['main_image'] ) - return $main_img; - - $dom = new \DOMDocument(); - $dom -> loadHTML( mb_convert_encoding( $article['language']['entry'], 'HTML-ENTITIES', "UTF-8" ) ); - $images = $dom -> getElementsByTagName( 'img' ); - foreach ( $images as $img ) - { - $src = $img -> getAttribute( 'src' ); - if ( file_exists( substr( $src, 1, strlen( $src ) ) ) ) - return $src; - } - - $dom = new \DOMDocument(); - $dom -> loadHTML( mb_convert_encoding( $article['language']['text'], 'HTML-ENTITIES', "UTF-8" ) ); - $images = $dom -> getElementsByTagName( 'img' ); - foreach ( $images as $img ) - { - $src = $img -> getAttribute( 'src' ); - if ( file_exists( substr( $src, 1, strlen( $src ) ) ) ) - return $src; - } - - if ( $article['images'] ) - return $article['images'][0]['src']; - - return false; + return \front\Views\Articles::getImage( $article ); } public static function article_noindex( $article_id ) { - global $mdb, $lang; - - $cacheHandler = new \CacheHandler(); - $cacheKey = "\front\factory\Articles::article_noindex:$article_id"; - - $objectData = $cacheHandler -> get( $cacheKey ); - - if ( !$objectData ) - { - $noindex = $mdb -> get( 'pp_articles_langs', 'noindex', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang[0] ] ] ); - - $cacheHandler -> set( $cacheKey, $noindex ); - } - else - { - return unserialize( $objectData ); - } - return $noindex; - } - - public static function page_articles( $page, $lang_id, $bs ) - { - $count = \front\factory\Articles::page_articles_count( $page['id'], $lang_id ); - $ls = ceil( $count / $page['articles_limit'] ); - - if ( $bs < 1 ) - $bs = 1; - else if ( $bs > $ls ) - $bs = $ls; - - $from = $page['articles_limit'] * ( $bs - 1 ); - - if ( $from < 0 ) - $from = 0; - - $results['articles'] = \front\factory\Articles::artciles_id( (int)$page['id'], $lang_id, (int)$page['articles_limit'], $page['sort_type'], $from ); - $results['ls'] = $ls; - - return $results; + global $lang; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + return $repo->articleNoindex( (int)$article_id, $lang[0] ); } public static function article_details( $article_id, $lang_id ) { - global $mdb; - - $cacheHandler = new \CacheHandler(); - $cacheKey = "\front\factory\Articles::article_details:$article_id:$lang_id"; - - $objectData = $cacheHandler->get($cacheKey); - - if ( !$objectData ) - { - $article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] ); - - $results = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang_id ] ] ); - if ( is_array( $results ) ) foreach ( $results as $row ) - { - if ( $row['copy_from'] ) - { - $results2 = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $row['copy_from'] ] ] ); - if ( is_array( $results2 ) ) foreach ( $results2 as $row2 ) - $article['language'] = $row2; - } - else - $article['language'] = $row; - } - - $article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'DESC' ] ] ); - $article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] ); - $article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] ); - - $cacheHandler -> set( $cacheKey, $article ); - } - else - { - return unserialize( $objectData ); - } - - return $article; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + return $repo->articleDetailsFrontend( (int)$article_id, $lang_id ); } public static function artciles_id( $page_id, $lang_id, $articles_limit, $sort_type, $from ) { - global $mdb; - - switch ( $sort_type ) - { - case 0: $order = 'date_add ASC'; break; - case 1: $order = 'date_add DESC'; break; - case 2: $order = 'date_modify ASC'; break; - case 3: $order = 'date_modify DESC'; break; - case 4: $order = 'o ASC'; break; - case 5: $order = 'title ASC'; break; - case 6: $order = 'title DESC'; break; - default: $order = 'id ASC'; break; - } - - $cacheHandler = new \CacheHandler(); - $cacheKey = "\front\factory\Artiles::artciles_id:$page_id:$lang_id:$articles_limit:$sort_type:$from:$order"; - - $objectData = $cacheHandler->get($cacheKey); - - if ( !$objectData ) - { - $results = $mdb -> query( 'SELECT * FROM ( ' - . 'SELECT ' - . 'a.id, date_modify, date_add, o, ' - . '( CASE ' - . 'WHEN copy_from IS NULL THEN title ' - . 'WHEN copy_from IS NOT NULL THEN ( ' - . 'SELECT ' - . 'title ' - . 'FROM ' - . 'pp_articles_langs ' - . 'WHERE ' - . 'lang_id = al.copy_from AND article_id = a.id ' - . ') ' - . 'END ) AS title ' - . 'FROM ' - . 'pp_articles_pages AS ap ' - . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' - . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' - . 'WHERE ' - . 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' ' - . ') AS q1 ' - . 'WHERE ' - . 'q1.title IS NOT NULL ' - . 'ORDER BY ' - . 'q1.' . $order . ' ' - . 'LIMIT ' - . (int)$from . ',' . (int)$articles_limit ) -> fetchAll(); - if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row ) - $output[] = $row['id']; - - $cacheHandler -> set( $cacheKey, $output ); - } - else - { - return unserialize($objectData); - } - return $output; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + return $repo->articlesIds( (int)$page_id, $lang_id, (int)$articles_limit, (int)$sort_type, (int)$from ); } public static function page_articles_count( $page_id, $lang_id ) { - global $mdb; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + return $repo->pageArticlesCount( (int)$page_id, $lang_id ); + } - $cacheHandler = new \CacheHandler(); - $cacheKey = "\front\factory\Articles::page_articles_count:$page_id:$lang_id"; + public static function page_articles( $page, $lang_id, $bs ) + { + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + return $repo->pageArticles( $page, $lang_id, (int)$bs ); + } - $objectData = $cacheHandler -> get( $cacheKey ); - - if ( !$objectData ) - { - $results = $mdb -> query( 'SELECT COUNT(0) FROM ( ' - . 'SELECT ' - . 'a.id, ' - . '( CASE ' - . 'WHEN copy_from IS NULL THEN title ' - . 'WHEN copy_from IS NOT NULL THEN ( ' - . 'SELECT ' - . 'title ' - . 'FROM ' - . 'pp_articles_langs ' - . 'WHERE ' - . 'lang_id = al.copy_from AND article_id = a.id ' - . ') ' - . 'END ) AS title ' - . 'FROM ' - . 'pp_articles_pages AS ap ' - . 'INNER JOIN pp_articles AS a ON a.id = ap.article_id ' - . 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id ' - . 'WHERE ' - . 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' ' - . ') AS q1 ' - . 'WHERE ' - . 'q1.title IS NOT NULL' ) -> fetchAll(); - $articles_count = $results[0][0]; - - $cacheHandler -> set( $cacheKey, $articles_count ); - } - else - { - return unserialize( $objectData ); - } - - return $articles_count; + public static function news( $page_id, $limit = 6, $lang_id ) + { + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + return $repo->news( (int)$page_id, (int)$limit, $lang_id ); } } diff --git a/autoload/front/factory/class.Settings.php b/autoload/front/factory/class.Settings.php deleted file mode 100644 index 1c48f69..0000000 --- a/autoload/front/factory/class.Settings.php +++ /dev/null @@ -1,22 +0,0 @@ -allSettings($admin); - } - - public static function get_single_settings_value($param) - { - global $mdb; - $repo = new \Domain\Settings\SettingsRepository($mdb); - return $repo->getSingleValue($param); - } -} diff --git a/autoload/front/view/class.Articles.php b/autoload/front/view/class.Articles.php index 6347af7..1e01e2c 100644 --- a/autoload/front/view/class.Articles.php +++ b/autoload/front/view/class.Articles.php @@ -1,90 +1,57 @@ page_id = $page_id; - $tpl -> articles = $articles; - return $tpl -> render( 'articles/news' ); + return \front\Views\Articles::news( $page_id, $articles ); } - + public static function full_article( $article_id, $lang_id ) { - $tpl = new \Tpl; - $tpl -> article = \front\factory\Articles::article_details( $article_id, $lang_id ); - return $tpl -> render( 'articles/article' ); + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + $article = $repo->articleDetailsFrontend( (int)$article_id, $lang_id ); + return \front\Views\Articles::fullArticle( $article ); } - + public static function miniature_articles_list( $page, $lang_id, $bs = 1 ) { - $results = \front\factory\Articles::page_articles( $page, $lang_id, $bs ); - - if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article ) - { - $tpl = new \Tpl; - $tpl -> article = \front\factory\Articles::article_details( $article, $lang_id ); - $out .= $tpl -> render( 'articles/article-miniature' ); - } - - if ( $results['ls'] > 1 ) - { - $tpl = new \Tpl; - $tpl -> ls = $results['ls']; - $tpl -> bs = $bs ? $bs : 1; - $tpl -> page = $page; - $out .= $tpl -> render( 'site/pager' ); - } - - return $out; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + $results = $repo->pageArticles( $page, $lang_id, (int)$bs ); + + $articles = []; + if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article_id ) + $articles[] = $repo->articleDetailsFrontend( (int)$article_id, $lang_id ); + + return \front\Views\Articles::miniatureArticlesList( $articles, $results['ls'], $bs ?: 1, $page ); } - + public static function entry_articles_list( $page, $lang_id, $bs = 1 ) { - $results = \front\factory\Articles::page_articles( $page, $lang_id, $bs ); - - if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article ) - $articles[] = \front\factory\Articles::article_details( $article, $lang_id ); - - $tpl = new \Tpl; - $tpl -> page_id = $page['id']; - $tpl -> articles = $articles; - $out .= $tpl -> render( 'articles/articles-entries' ); - - if ( $results['ls'] > 1 ) - { - $tpl = new \Tpl; - $tpl -> ls = $results['ls']; - $tpl -> bs = $bs ? $bs : 1; - $tpl -> page = $page; - $out .= $tpl -> render( 'site/pager' ); - } - - return $out; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + $results = $repo->pageArticles( $page, $lang_id, (int)$bs ); + + $articles = []; + if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article_id ) + $articles[] = $repo->articleDetailsFrontend( (int)$article_id, $lang_id ); + + return \front\Views\Articles::entryArticlesList( $articles, $results['ls'], $bs ?: 1, $page ); } - + public static function full_articles_list( $page, $lang_id, $bs = 1 ) { - $results = \front\factory\Articles::page_articles( $page, $lang_id, $bs ); - - if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article ) - { - $tpl = new \Tpl; - $tpl -> article = \front\factory\Articles::article_details( $article, $lang_id ); - $out .= $tpl -> render( 'articles/article-full' ); - } - - if ( $results['ls'] > 1 ) - { - $tpl = new \Tpl; - $tpl -> ls = $results['ls']; - $tpl -> bs = $bs ? $bs : 1; - $tpl -> page = $page; - $out .= $tpl -> render( 'site/pager' ); - } - - return $out; + $repo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + $results = $repo->pageArticles( $page, $lang_id, (int)$bs ); + + $articles = []; + if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article_id ) + $articles[] = $repo->articleDetailsFrontend( (int)$article_id, $lang_id ); + + return \front\Views\Articles::fullArticlesList( $articles, $results['ls'], $bs ?: 1, $page ); } -} \ No newline at end of file +} diff --git a/autoload/front/view/class.Site.php b/autoload/front/view/class.Site.php index e2e51b0..9e5b4a2 100644 --- a/autoload/front/view/class.Site.php +++ b/autoload/front/view/class.Site.php @@ -22,6 +22,8 @@ class Site { global $page, $settings, $settings, $lang, $lang_id; + $articleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + if ( (int) \S::get( 'layout_id' ) ) $layout = new \cms\Layout( (int) \S::get( 'layout_id' ) ); @@ -92,9 +94,9 @@ class Site $news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit']; $news_list_tmp[2] != '' ? $pattern = '[AKTUALNOSCI:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[AKTUALNOSCI:' . $news_list_tmp[1] . ']'; - $html = str_replace( $pattern, \front\view\Articles::news( + $html = str_replace( $pattern, \front\Views\Articles::news( $news_list_tmp[1], - \front\factory\Articles::news( $news_list_tmp[1], $news_limit, $lang_id ) + $articleRepo->news( (int)$news_list_tmp[1], (int)$news_limit, $lang_id ) ), $html ); } @@ -175,7 +177,7 @@ class Site // if ( \S::get( 'article' ) ) { - $article = \front\factory\Articles::article_details( \S::get( 'article' ), $lang_id ); + $article = $articleRepo->articleDetailsFrontend( (int)\S::get( 'article' ), $lang_id ); if ( $article['language']['meta_title'] ) $page['language']['title'] = $article['language']['meta_title']; @@ -340,7 +342,7 @@ class Site /* atrybut noindex */ if ( \S::get( 'article' ) ) { - \front\factory\Articles::article_noindex( \S::get( 'article' ) ) ? $noindex = 'noindex' : $noindex = 'all'; + $articleRepo->articleNoindex( (int)\S::get( 'article' ), $lang_id ) ? $noindex = 'noindex' : $noindex = 'all'; $html = str_replace( '[META_INDEX]', '', $html ); } else @@ -390,29 +392,27 @@ class Site } // prosta lista aktualności z wybranej podstrony - preg_match_all( self::news_list_pattern, $html, $news_list ); - if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp ) + preg_match_all( self::news_list_pattern, $html, $news_list_matches ); + if ( is_array( $news_list_matches[0] ) ) foreach( $news_list_matches[0] as $news_list_tmp ) { $news_list_tmp = explode( ':', $news_list_tmp ); $news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit']; $news_list_tmp[2] != '' ? $pattern = '[AKTUALNOSCI_LISTA:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[AKTUALNOSCI_LISTA:' . $news_list_tmp[1] . ']'; - $news_list = \Article::getNews( $news_list_tmp[1], $news_limit, $lang_id ); - $view_news_list = \Article::newsList( $news_list ); - $html = str_replace( $pattern, $view_news_list, $html ); + $newsArticles = $articleRepo->newsListArticles( (int)$news_list_tmp[1], (int)$news_limit, $lang_id ); + $html = str_replace( $pattern, \front\Views\Articles::newsList( $newsArticles ), $html ); } // prosta lista z najpopularniejszymi artykułami - preg_match_all( self::top_news_pattern, $html, $news_list ); - if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp ) + preg_match_all( self::top_news_pattern, $html, $top_news_matches ); + if ( is_array( $top_news_matches[0] ) ) foreach( $top_news_matches[0] as $news_list_tmp ) { $news_list_tmp = explode( ':', $news_list_tmp ); $news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit']; $news_list_tmp[2] != '' ? $pattern = '[NAJPOULARNIEJSZE_ARTYKULY:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[NAJPOULARNIEJSZE_ARTYKULY:' . $news_list_tmp[1] . ']'; - $news_list = \Article::getTopNews( $news_list_tmp[1], $news_limit, $lang_id ); - $view_news_list = \Article::newsList( $news_list ); - $html = str_replace( $pattern, $view_news_list, $html ); + $topArticles = $articleRepo->topArticles( (int)$news_list_tmp[1], (int)$news_limit, $lang_id ); + $html = str_replace( $pattern, \front\Views\Articles::newsList( $topArticles ), $html ); } $html = str_replace( '[ALERT]', \front\view\Site::alert(), $html ); diff --git a/autoload/shop/class.Order.php b/autoload/shop/class.Order.php index 2ea5e40..883b314 100644 --- a/autoload/shop/class.Order.php +++ b/autoload/shop/class.Order.php @@ -197,7 +197,7 @@ class Order implements \ArrayAccess $order_statuses = self::order_statuses(); - $firm_name = \front\factory\Settings::get_single_settings_value( 'firm_name' ); + $firm_name = ( new \Domain\Settings\SettingsRepository( $mdb ) )->getSingleValue( 'firm_name' ); switch( $this -> status ): case 0: diff --git a/cron-turstmate.php b/cron-turstmate.php index a0e3868..0f7451e 100644 --- a/cron-turstmate.php +++ b/cron-turstmate.php @@ -58,7 +58,7 @@ if ( !$config['trustmate']['enabled'] ) exit; } -$settings = \front\factory\Settings::settings_details(); +$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); $order_id = $mdb -> get( 'pp_shop_orders', '*', [ 'AND' => [ 'status' => 6, 'trustmate_send' => 0 ] ] ); if ( is_array( $order_id ) and $order_id['id'] ) diff --git a/cron.php b/cron.php index 5fd8059..fde4599 100644 --- a/cron.php +++ b/cron.php @@ -52,7 +52,7 @@ $mdb = new medoo( [ 'charset' => 'utf8' ] ); -$settings = \front\factory\Settings::settings_details(); +$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); $integrationsRepository = new \Domain\Integrations\IntegrationsRepository( $mdb ); $apilo_settings = $integrationsRepository -> getSettings( 'apilo' ); diff --git a/cron/cron-xml.php b/cron/cron-xml.php index e43a549..3f10c3b 100644 --- a/cron/cron-xml.php +++ b/cron/cron-xml.php @@ -50,7 +50,7 @@ $mdb = new medoo( [ 'charset' => 'utf8' ] ); -$settings = \front\factory\Settings::settings_details(); +$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); $lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage(); ( new \Domain\Product\ProductRepository( $mdb ) )->generateGoogleFeedXml(); \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a6a9c41..9510f3f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,25 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze. --- +## ver. 0.280 (2026-02-16) - Articles frontend migration + +- **Articles (frontend)** — pelna migracja na Domain + Views + - NOWE METODY w `ArticleRepository`: `articleDetailsFrontend()`, `articlesIds()`, `pageArticlesCount()`, `pageArticles()`, `news()`, `articleNoindex()`, `topArticles()`, `newsListArticles()` + - NOWY: `front\Views\Articles` — czysty VIEW + utility (renderowanie, generateTableOfContents, generateHeadersIds, getImage) + - UPDATE: `front\view\Site::show()` — przepiecie 5 sekcji na repo + Views (BOX aktualnosci, article meta, noindex, news list, top articles) + - UPDATE: `front\controls\Site::route()` — przepiecie single article + page_type switch (4 typy) na repo + Views + - UPDATE: 5 szablonow `templates/articles/*` — przepiecie na `\front\Views\Articles::` + - FASADA: `front\factory\Articles` — 10 metod delegujacych do repo + Views + - FASADA: `front\view\Articles` — 5 metod delegujacych do repo + Views + - USUNIETA: `class.Article` — encja + metody statyczne; logika przeniesiona do `ArticleRepository` + `front\Views\Articles` + - FIX: eliminacja `global $lang` z `articleNoindex()` — zamiana na jawny parametr `$langId` + - FIX: eliminacja zaleznosci od `\front\factory\Pages::page_sort()` w `news()` — inline query + - FIX: naprawione kolizje nazw zmiennych w `front\view\Site::show()` ($news_list → $news_list_matches, $top_news_matches) + - Testy: 450 OK, 1431 asercji (+13 nowych testow w ArticleRepositoryTest) + - UPDATE: `tests/bootstrap.php` — dodany stub `S::is_array_fix()` + +--- + ## ver. 0.279 (2026-02-16) - Newsletter + Languages frontend migration, front\Controllers, front\Views - **Languages (view)** — migracja do nowego namespace diff --git a/docs/FRONTEND_REFACTORING_PLAN.md b/docs/FRONTEND_REFACTORING_PLAN.md index 11cbd03..1e7c5f4 100644 --- a/docs/FRONTEND_REFACTORING_PLAN.md +++ b/docs/FRONTEND_REFACTORING_PLAN.md @@ -215,7 +215,38 @@ Legacy Cleanup --- -### Etap: Banners, Menu, Pages, Articles, Layouts Frontend Services +### Etap: Articles Frontend — ZREALIZOWANY + +**Cel:** Migracja `front\factory\Articles`, `front\view\Articles` i statycznych metod `class.Article` do Domain + Views. + +**DODANE METODY (do istniejącej klasy `ArticleRepository`):** +- `articleDetailsFrontend(int $articleId, string $langId): ?array` — z copy_from fallback + Redis cache +- `articlesIds(int $pageId, string $langId, int $limit, int $sortType, int $from): ?array` — złożone SQL z language fallback + sortowanie + LIMIT + Redis cache +- `pageArticlesCount(int $pageId, string $langId): int` — COUNT z Redis cache +- `pageArticles(array $page, string $langId, int $bs): array` — paginacja +- `news(int $pageId, int $limit, string $langId): ?array` — inline sort_type query (eliminacja zależności od `front\factory\Pages`) +- `articleNoindex(int $articleId, string $langId): bool` — jawny $langId zamiast `global $lang` +- `topArticles(int $pageId, int $limit, string $langId): ?array` — ORDER BY views DESC + Redis cache +- `newsListArticles(int $pageId, int $limit, string $langId): ?array` — ORDER BY date_add DESC + CacheHandler (Redis) zamiast legacy `\Cache` + +**NOWE:** +- `front\Views\Articles` — czysty VIEW + utility: + - Renderowanie: `fullArticle()`, `miniatureArticlesList()`, `entryArticlesList()`, `fullArticlesList()`, `news()`, `newsList()` + - Utility: `generateTableOfContents()`, `processHeaders()`, `generateHeadersIds()`, `getImage()` + +**ZMIANA:** +- `front\factory\Articles` → fasada (10 metod delegujących do repo + Views) +- `front\view\Articles` → fasada (5 metod delegujących do repo + Views) +- `class.Article` → USUNIĘTA (encja + metody statyczne przeniesione do `ArticleRepository` + `front\Views\Articles`) +- `front\view\Site::show()` → 5 sekcji przepiętych na repo + Views +- `front\controls\Site::route()` → single article + page_type switch przepięte na repo + Views +- 5 szablonów `templates/articles/*` → `\front\Views\Articles::` +- `tests/bootstrap.php` — dodany stub `S::is_array_fix()` +- Testy: 13 nowych w `ArticleRepositoryTest` (450 OK, 1431 asercji) + +--- + +### Etap: Banners, Menu, Pages, Layouts Frontend Services **Cel:** Migracja pozostałych fabryk "liściowych". @@ -223,12 +254,11 @@ Legacy Cleanup - `Domain/Banner/BannerFrontendService.php` — `mainBanner()`, `banners()` (filtrowanie po datach) - `Domain/Menu/MenuFrontendService.php` — `menuDetails()`, `menuPages()` (rekurencja) - `Domain/Pages/PagesFrontendService.php` — `pageDetails()`, `mainPageId()`, `langUrl()`, `pageSort()` -- `Domain/Article/ArticleFrontendService.php` — `articleDetails()`, `news()`, `pageArticles()`, `pageArticlesCount()`, `generateTableOfContents()`, `generateHeadersIds()` - `Domain/Layouts/LayoutsFrontendService.php` — `activeLayout()`, `articleLayout()`, `productLayout()`, `categoryLayout()`, `defaultLayout()`, `categoryDefaultLayout()` -- Testy: 5 plików testowych +- Testy: 4 pliki testowe **ZMIANA:** -- `front/factory/Banners`, `Menu`, `Pages`, `Articles`, `Layouts` → fasady +- `front/factory/Banners`, `Menu`, `Pages`, `Layouts` → fasady **BUG FIX:** `cms\Layout::__get()` — poprawka referencji do `$this->data` diff --git a/docs/PROJECT_STRUCTURE.md b/docs/PROJECT_STRUCTURE.md index b618153..e7631e9 100644 --- a/docs/PROJECT_STRUCTURE.md +++ b/docs/PROJECT_STRUCTURE.md @@ -101,7 +101,11 @@ shopPRO/ │ │ └── factory/ # Fabryki/helpery │ ├── Domain/ # Repozytoria/logika domenowa │ ├── front/ # Klasy frontendu -│ │ └── factory/ # Fabryki/helpery +│ │ ├── Controllers/ # Nowe kontrolery DI (Newsletter) +│ │ ├── Views/ # Nowe widoki (Newsletter, Articles, Languages) +│ │ ├── controls/ # Kontrolery legacy (Site, ShopBasket, ...) +│ │ ├── view/ # Widoki legacy (Site, ...) +│ │ └── factory/ # Fabryki/helpery (fasady) │ └── shop/ # Klasy sklepu ├── docs/ # Dokumentacja techniczna ├── libraries/ # Biblioteki zewnętrzne diff --git a/docs/TESTING.md b/docs/TESTING.md index a167208..0acf102 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -36,7 +36,14 @@ Alternatywnie (Git Bash): Ostatnio zweryfikowano: 2026-02-16 ```text -OK (437 tests, 1398 assertions) +OK (450 tests, 1431 assertions) +``` + +Aktualizacja po migracji Articles frontend (2026-02-16, ver. 0.280): +```text +Pelny suite: OK (450 tests, 1431 assertions) +Nowe testy: ArticleRepositoryTest (+13: articleDetailsFrontend, copyFromFallback, articlesIds, pageArticlesCount, pageArticlesPagination, articleNoindex, news, topArticles, newsListArticles) +Zaktualizowane: tests/bootstrap.php (stub: S::is_array_fix) ``` Aktualizacja po migracji Newsletter + Languages frontend (2026-02-16, ver. 0.279): diff --git a/docs/UPDATE_INSTRUCTIONS.md b/docs/UPDATE_INSTRUCTIONS.md index 34c1e1d..3721175 100644 --- a/docs/UPDATE_INSTRUCTIONS.md +++ b/docs/UPDATE_INSTRUCTIONS.md @@ -18,17 +18,17 @@ Aktualizacje znajdują się w folderze `updates/0.XX/` gdzie XX oznacza dziesią ## Procedura tworzenia nowej aktualizacji -## Status biezacej aktualizacji (ver. 0.279) +## Status biezacej aktualizacji (ver. 0.280) -- Wersja udostepniona: `0.279` (data: 2026-02-16). +- Wersja udostepniona: `0.280` (data: 2026-02-16). - Pliki publikacyjne: - - `updates/0.20/ver_0.279.zip` - - `updates/0.20/ver_0.279_files.txt` + - `updates/0.20/ver_0.280.zip` + - `updates/0.20/ver_0.280_files.txt` - Pliki metadanych aktualizacji: - - `updates/changelog.php` (dodany wpis `ver. 0.279`) - - `updates/versions.php` (`$current_ver = 279`) + - `updates/changelog.php` (dodany wpis `ver. 0.280`) + - `updates/versions.php` (`$current_ver = 280`) - Weryfikacja testow przed publikacja: - - `OK (437 tests, 1398 assertions)` + - `OK (450 tests, 1431 assertions)` ### 1. Określ numer wersji Sprawdź ostatnią wersję w `updates/` i zwiększ o 1. diff --git a/index.php b/index.php index 5a1353e..be15011 100644 --- a/index.php +++ b/index.php @@ -75,7 +75,7 @@ if ( !$lang = \S::get_session( 'lang-' . $lang_id ) ) \S::set_session( 'lang-' . $lang_id, $lang ); } -$settings = \front\factory\Settings::settings_details(); +$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings(); $client = \S::get_session( 'client' ); if ( \S::get( 'action' ) == 'htaccess' ) diff --git a/templates/articles/article-entry.php b/templates/articles/article-entry.php index 8b2ce4c..3750fb6 100644 --- a/templates/articles/article-entry.php +++ b/templates/articles/article-entry.php @@ -3,7 +3,7 @@
        article['language']['seo_link'] ? $url = $this -> article['language']['seo_link'] : $url = 'a-' . $this -> article['id'] . '-' . \S::seo( $this -> article['language']['title'] );?>

        article['language']['noindex'] ):?>rel="nofollow"> article['language']['title'];?> diff --git a/templates/articles/article-full.php b/templates/articles/article-full.php index b7bc802..403ce53 100644 --- a/templates/articles/article-full.php +++ b/templates/articles/article-full.php @@ -1,7 +1,7 @@ article['language']['text']; -$text = \front\factory\Articles::generateHeadersIds( $text ); +$text = \front\Views\Articles::generateHeadersIds( $text ); ?>
        - +

        @@ -67,7 +67,11 @@ $text = \front\factory\Articles::generateHeadersIds( $text ); { $article_tmp = explode( ':', $article_tmp ); if ( $article_tmp[1] != $this -> article['id'] ) - $text = str_replace( '[ARTYKUL:' . $article_tmp[1] . ']', \front\view\Articles::article_full( $article_tmp[1], $lang_id ), $text ); + { + $nestedArticleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] ); + $nestedArticle = $nestedArticleRepo->articleDetailsFrontend( (int)$article_tmp[1], $lang_id ); + $text = str_replace( '[ARTYKUL:' . $article_tmp[1] . ']', $nestedArticle ? \front\Views\Articles::fullArticle( $nestedArticle ) : '', $text ); + } else $text = str_replace( '[ARTYKUL:' . $article_tmp[1] . ']', '', $text ); } diff --git a/templates/articles/article-miniature.php b/templates/articles/article-miniature.php index ab32e19..5b97998 100644 --- a/templates/articles/article-miniature.php +++ b/templates/articles/article-miniature.php @@ -15,7 +15,7 @@ if ( $this -> article['show_date_modify'] ) echo '
        ' . $lang['data-modyfikacji'] . ': ' . $this -> article['date_modify'] . '
        '; - if ( $img = \front\factory\Articles::get_image( $this -> article ) ): + if ( $img = \front\Views\Articles::getImage( $this -> article ) ): ?> article['language']['noindex'] ):?>rel="nofollow">
        diff --git a/templates/articles/article.php b/templates/articles/article.php index 42aad60..3be7cd2 100644 --- a/templates/articles/article.php +++ b/templates/articles/article.php @@ -1,7 +1,7 @@ article['language']['text']; -$text = \front\factory\Articles::generateHeadersIds( $text ); +$text = \front\Views\Articles::generateHeadersIds( $text ); ?>
        - + diff --git a/templates/articles/news.php b/templates/articles/news.php index e1af2cb..086a0f2 100644 --- a/templates/articles/news.php +++ b/templates/articles/news.php @@ -5,7 +5,7 @@
        rel="nofollow">
        - <?= $article['language']['title'];?> + <?= $article['language']['title'];?>

        diff --git a/templates/menu/pages.php b/templates/menu/pages.php index d3221d1..cd4a854 100644 --- a/templates/menu/pages.php +++ b/templates/menu/pages.php @@ -1,6 +1,6 @@ pages ) ) { - $settings = \front\factory\Settings::settings_details(); + $settings = ( new \Domain\Settings\SettingsRepository( $GLOBALS['mdb'] ) )->allSettings(); echo '