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:
241
autoload/front/Views/Articles.php
Normal file
241
autoload/front/Views/Articles.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Articles
|
||||
{
|
||||
/**
|
||||
* Renderuje pelny widok pojedynczego artykulu.
|
||||
*/
|
||||
public static function fullArticle( $article )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl->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 .= '</li></ol>';
|
||||
array_pop( $currentLevel );
|
||||
}
|
||||
|
||||
if ( $level > count( $currentLevel ) )
|
||||
{
|
||||
while ( $level > count( $currentLevel ) )
|
||||
{
|
||||
if ( count( $currentLevel ) > 0 || $firstLevel )
|
||||
{
|
||||
$result .= '<ol>';
|
||||
$firstLevel = false;
|
||||
}
|
||||
array_push( $currentLevel, 0 );
|
||||
}
|
||||
$result .= '<li>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$result .= '</li><li>';
|
||||
}
|
||||
|
||||
$currentLevel[ count( $currentLevel ) - 1 ]++;
|
||||
|
||||
preg_match( '/\sid="([^"]*)"/', $match[2], $idMatches );
|
||||
$id = isset( $idMatches[1] ) ? $idMatches[1] : '';
|
||||
|
||||
$result .= sprintf(
|
||||
'<a href="#%s">%s</a>',
|
||||
urlencode( strtolower( $id ) ),
|
||||
$match[3]
|
||||
);
|
||||
}
|
||||
|
||||
while ( !empty( $currentLevel ) )
|
||||
{
|
||||
$result .= '</li></ol>';
|
||||
array_pop( $currentLevel );
|
||||
}
|
||||
|
||||
if ( substr( $result, 0, 8 ) === '<ol><ol>' )
|
||||
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( '<h%d%s>%s</h%d>', $level, $attrs, $content, $level );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje atrybuty id do naglowkow HTML.
|
||||
*/
|
||||
public static function generateHeadersIds( $text )
|
||||
{
|
||||
$pattern = '/<h([1-6])(.*?)>(.*?)<\/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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -1,317 +1,66 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
static public 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 .= '</li></ol>';
|
||||
array_pop($currentLevel);
|
||||
}
|
||||
|
||||
if ($level > count($currentLevel)) {
|
||||
while ($level > count($currentLevel)) {
|
||||
if (count($currentLevel) > 0 || $firstLevel) {
|
||||
$result .= '<ol>';
|
||||
$firstLevel = false;
|
||||
}
|
||||
array_push($currentLevel, 0);
|
||||
}
|
||||
$result .= '<li>';
|
||||
} else {
|
||||
$result .= '</li><li>';
|
||||
}
|
||||
|
||||
$currentLevel[count($currentLevel) - 1]++;
|
||||
|
||||
preg_match('/\sid="([^"]*)"/', $match[2], $idMatches);
|
||||
$id = isset($idMatches[1]) ? $idMatches[1] : '';
|
||||
|
||||
$result .= sprintf(
|
||||
'<a href="#%s">%s</a>',
|
||||
urlencode(strtolower($id)),
|
||||
$match[3]
|
||||
);
|
||||
}
|
||||
|
||||
while (!empty($currentLevel)) {
|
||||
$result .= '</li></ol>';
|
||||
array_pop($currentLevel);
|
||||
}
|
||||
|
||||
if (substr($result, 0, 8) === '<ol><ol>') {
|
||||
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( '<h%d%s>%s</h%d>', $level, $attrs, $content, $level );
|
||||
return $html;
|
||||
return \front\Views\Articles::processHeaders( $matches );
|
||||
}
|
||||
|
||||
static public function generateHeadersIds( $text )
|
||||
{
|
||||
$pattern = '/<h([1-6])(.*?)>(.*?)<\/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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
/**
|
||||
* Fasada delegujaca do Domain\Settings\SettingsRepository.
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
public static function settings_details($admin = false)
|
||||
{
|
||||
global $mdb;
|
||||
$repo = new \Domain\Settings\SettingsRepository($mdb);
|
||||
return $repo->allSettings($admin);
|
||||
}
|
||||
|
||||
public static function get_single_settings_value($param)
|
||||
{
|
||||
global $mdb;
|
||||
$repo = new \Domain\Settings\SettingsRepository($mdb);
|
||||
return $repo->getSingleValue($param);
|
||||
}
|
||||
}
|
||||
@@ -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