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 <noreply@anthropic.com>
This commit is contained in:
@@ -1,90 +1,57 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
/**
|
||||
* FASADA — deleguje do \Domain\Article\ArticleRepository i \front\Views\Articles
|
||||
* Zachowana dla wstecznej kompatybilności. Nowy kod powinien używać bezpośrednio repo + Views.
|
||||
*/
|
||||
class Articles
|
||||
{
|
||||
public static function news( $page_id, $articles )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]', '<meta name="robots" content="' . $noindex . '">', $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 );
|
||||
|
||||
Reference in New Issue
Block a user