Refactor settings retrieval and improve article rendering

- Cleaned up whitespace in `class.Settings.php` for better readability.
- Enhanced `class.Articles.php` to allow optional template parameter in the `news` method.
- Updated regex patterns in `class.Site.php` for better matching of news parameters.
- Streamlined HTML generation in `class.Site.php` by reducing redundancy and improving readability.
- Improved handling of SEO metadata and canonical links in `class.Site.php`.
- Refactored calendar and visit counter methods for consistency in `class.Site.php`.
This commit is contained in:
2025-12-09 23:25:54 +01:00
parent 512debf4c1
commit a956ec670d
11 changed files with 1027 additions and 709 deletions

View File

@@ -1,165 +1,183 @@
<?php
namespace front\factory;
class Articles
{
static public function generateTableOfContents($content) {
static public function generateTableOfContents($content)
{
$result = '';
$currentLevel = [];
$prevLevel = 0;
$stack = [];
preg_match_all('/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER);
// Tylko h1h3
preg_match_all('/<(h[1-3])([^>]*)>(.*?)<\/\1>/i', $content, $matches, PREG_SET_ORDER);
$firstLevel = true;
if (empty($matches))
{
return '';
}
foreach ($matches as $match) {
$level = intval(substr($match[1], 1));
foreach ($matches as $match)
{
$level = (int)substr($match[1], 1);
$text = trim($match[3]);
while ($level < count($currentLevel)) {
$result .= '</li></ol>';
array_pop($currentLevel);
// Pobierz lub wygeneruj ID
preg_match('/\sid=["\']?([^"\']+)["\']?/', $match[2], $idMatch);
$id = isset($idMatch[1])
? $idMatch[1]
: strtolower(preg_replace('/[^a-z0-9]+/u', '-', html_entity_decode(strip_tags($text), ENT_QUOTES, 'UTF-8')));
if ($prevLevel === 0)
{
$prevLevel = $level;
$stack[] = $level;
}
if ($level > $prevLevel)
{
for ($i = $prevLevel; $i < $level; $i++)
{
$result .= '<ol>';
$stack[] = $i + 1;
}
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>';
}
elseif ($level < $prevLevel)
{
for ($i = $prevLevel; $i > $level; $i--)
{
$result .= '</li></ol>';
array_pop($stack);
}
$result .= '</li>';
}
else
{
$result .= '</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]
);
$result .= '<li><a href="#' . htmlspecialchars($id) . '">' . $text . '</a>';
$prevLevel = $level;
}
while (!empty($currentLevel)) {
$result .= '</li></ol>';
array_pop($currentLevel);
// Zamknij pozostałe listy
while (!empty($stack))
{
$result .= '</li></ol>';
array_pop($stack);
}
if (substr($result, 0, 8) === '<ol><ol>') {
return substr($result, 4, -5);
} else {
return $result;
}
return '<ol>' . $result . '</ol>';
}
// funkcja wywoływana dla każdego dopasowania do wyrażenia regularnego
static public function processHeaders( $matches )
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 );
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 );
$html = sprintf('<h%d%s>%s</h%d>', $level, $attrs, $content, $level);
return $html;
}
static public function generateHeadersIds( $text )
static public function generateHeadersIds($text)
{
$pattern = '/<h([1-6])(.*?)>(.*?)<\/h\1>/si';
$text = preg_replace_callback( $pattern, array(__CLASS__, 'processHeaders'), $text );
$text = preg_replace_callback($pattern, array(__CLASS__, 'processHeaders'), $text);
return $text;
}
public static function pixieset_save_favorite_images( $hash )
public static function pixieset_save_favorite_images($hash)
{
global $mdb, $settings;
\S::delete_dir( 'temp/' );
\S::delete_dir('temp/');
$rows = $mdb -> select( 'pp_articles', [ 'id' ], [ 'hash' => $hash ] );
if ( is_array( $rows ) ) foreach ( $rows as $row ) {
$article = \front\factory\Articles::article_details( $row['id'], 'pl' );
$rows = $mdb->select('pp_articles', ['id'], ['hash' => $hash]);
if (is_array($rows)) foreach ($rows as $row)
{
$article = \front\factory\Articles::article_details($row['id'], 'pl');
$text = '<p>Witaj,<br />';
$text .= 'Użytkownik zatwierdził listę wybranych przez siebie zdjęć.<br />';
$text .= 'Poniżej znajdziesz nazwy wybranych zdjęć.</p>';
$text .= '<ul>';
if ( is_array( $article['images'] ) ) foreach ( $article['images'] as $image )
if ( $image['favorite'] )
$text .= '<li>' . basename( $image['src'] ) . '</li>';
if (is_array($article['images'])) foreach ($article['images'] as $image)
if ($image['favorite'])
$text .= '<li>' . basename($image['src']) . '</li>';
$text .= '</ul>';
\S::send_email( $settings['contact_email'], 'Powiadomienie ze strony: ' . $_SERVER['SERVER_NAME'], $text );
\S::send_email($settings['contact_email'], 'Powiadomienie ze strony: ' . $_SERVER['SERVER_NAME'], $text);
return true;
}
return false;
}
public static function pixieset_image_favorite( $image_id, $hash )
public static function pixieset_image_favorite($image_id, $hash)
{
global $mdb;
$rows = $mdb -> select( 'pp_articles', [ 'id' ], [ 'hash' => $hash ] );
if ( is_array( $rows ) ) foreach ( $rows as $row )
$rows = $mdb->select('pp_articles', ['id'], ['hash' => $hash]);
if (is_array($rows)) foreach ($rows as $row)
{
$status = $mdb -> get( 'pp_articles_images', 'favorite', [ 'AND' => [ 'article_id' => $row['id'], 'id' => $image_id ] ] );
$mdb -> update( 'pp_articles_images', [ 'favorite' => !$status ], [ 'AND' => [ 'article_id' => $row['id'], 'id' => $image_id ] ] );
$status = $mdb->get('pp_articles_images', 'favorite', ['AND' => ['article_id' => $row['id'], 'id' => $image_id]]);
$mdb->update('pp_articles_images', ['favorite' => !$status], ['AND' => ['article_id' => $row['id'], 'id' => $image_id]]);
\S::delete_dir( 'temp/' );
\S::delete_dir('temp/');
return !$status;
}
}
public static function article_password( $article_id )
public static function article_password($article_id)
{
global $mdb;
return $mdb -> get( 'pp_articles', 'password', [ 'id' => $article_id ] );
return $mdb->get('pp_articles', 'password', ['id' => $article_id]);
}
public static function articles_by_tags( $tag_id, $lang_id )
public static function articles_by_tags($tag_id, $lang_id)
{
global $mdb;
if ( !$articles = \Cache::fetch( "articles_by_tags:$tag_id:$lang_id" ) )
if (!$articles = \Cache::fetch("articles_by_tags:$tag_id:$lang_id"))
{
$results = $mdb -> query( 'SELECT '
. 'pa.id '
. 'FROM '
. 'pp_articles AS pa '
. 'INNER JOIN pp_articles_tags AS pat ON pat.article_id = pa.id '
. 'WHERE '
. 'status = 1 '
. 'AND '
. 'tag_id = ' . (int)$tag_id ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$articles[] = \front\factory\Articles::article_details( $row['id'], $lang_id );
$results = $mdb->query('SELECT '
. 'pa.id '
. 'FROM '
. 'pp_articles AS pa '
. 'INNER JOIN pp_articles_tags AS pat ON pat.article_id = pa.id '
. 'WHERE '
. 'status = 1 '
. 'AND '
. 'tag_id = ' . (int)$tag_id)->fetchAll();
if (is_array($results) and !empty($results)) foreach ($results as $row)
$articles[] = \front\factory\Articles::article_details($row['id'], $lang_id);
\Cache::store( "articles_by_tags:$tag_id:$lang_id", $articles );
\Cache::store("articles_by_tags:$tag_id:$lang_id", $articles);
}
return $articles;
}
public static function tag_details( $tag_id )
public static function tag_details($tag_id)
{
global $mdb;
if ( !$tag = \Cache::fetch( "tag_details:$tag_id" ) )
if (!$tag = \Cache::fetch("tag_details:$tag_id"))
{
$tag = $mdb -> get( 'pp_tags', '*', [ 'id' => (int)$tag_id ] );
$tag = $mdb->get('pp_tags', '*', ['id' => (int)$tag_id]);
\Cache::store( "tag_details:$tag_id", $tag );
\Cache::store("tag_details:$tag_id", $tag);
}
return $tag;
}
@@ -168,276 +186,294 @@ class Articles
{
global $mdb;
if ( !$tags = \Cache::fetch( 'tags' ) )
if (!$tags = \Cache::fetch('tags'))
{
$tags = $mdb -> query( 'SELECT '
. 'name, COUNT( tag_id ) AS c '
. 'FROM '
. 'pp_tags AS pt '
. 'INNER JOIN pp_articles_tags ON pt.id = tag_id '
. 'GROUP BY '
. 'tag_id '
. 'ORDER BY '
. 'c DESC '
. 'LIMIT 20'
) -> fetchAll();
$tags = $mdb->query(
'SELECT '
. 'name, COUNT( tag_id ) AS c '
. 'FROM '
. 'pp_tags AS pt '
. 'INNER JOIN pp_articles_tags ON pt.id = tag_id '
. 'GROUP BY '
. 'tag_id '
. 'ORDER BY '
. 'c DESC '
. 'LIMIT 20'
)->fetchAll();
\Cache::store( 'tags', $tags );
\Cache::store('tags', $tags);
}
return $tags;
}
public static function articles_by_date( $month, $year, $lang_id )
public static function articles_by_date($month, $year, $lang_id)
{
global $mdb;
if ( !$articles = \Cache::fetch( "articles_by_date:$month:$year:$lang_id" ) )
if (!$articles = \Cache::fetch("articles_by_date:$month:$year:$lang_id"))
{
$results = $mdb -> query( 'SELECT '
. 'id '
. 'FROM '
. 'pp_articles '
. 'WHERE '
. 'status = 1 '
. 'AND '
. '( '
. '( date_start BETWEEN \'' . date( 'Y-m-d', strtotime( '01-' . $month . '-' . $year ) ) . '\' AND \'' . date( 'Y-m-t', strtotime( '01-' . $month . '-' . $year ) ) . '\' ) '
. 'OR '
. '( date_end BETWEEN \'' . date( 'Y-m-d', strtotime( '01-' . $month . '-' . $year ) ) . '\' AND \'' . date( 'Y-m-t', strtotime( '01-' . $month . '-' . $year ) ) . '\' ) '
. 'OR '
. '( date_start <= \'' . date( 'Y-m-t', strtotime( '01-' . $month . '-' . $year ) ) . '\' AND date_end >= \'' . date( 'Y-m-t', strtotime( '01-' . $month . '-' . $year ) ) . '\' ) '
. ')' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$articles[] = \front\factory\Articles::article_details( $row['id'], $lang_id );
$results = $mdb->query('SELECT '
. 'id '
. 'FROM '
. 'pp_articles '
. 'WHERE '
. 'status = 1 '
. 'AND '
. '( '
. '( date_start BETWEEN \'' . date('Y-m-d', strtotime('01-' . $month . '-' . $year)) . '\' AND \'' . date('Y-m-t', strtotime('01-' . $month . '-' . $year)) . '\' ) '
. 'OR '
. '( date_end BETWEEN \'' . date('Y-m-d', strtotime('01-' . $month . '-' . $year)) . '\' AND \'' . date('Y-m-t', strtotime('01-' . $month . '-' . $year)) . '\' ) '
. 'OR '
. '( date_start <= \'' . date('Y-m-t', strtotime('01-' . $month . '-' . $year)) . '\' AND date_end >= \'' . date('Y-m-t', strtotime('01-' . $month . '-' . $year)) . '\' ) '
. ')')->fetchAll();
if (is_array($results) and !empty($results)) foreach ($results as $row)
$articles[] = \front\factory\Articles::article_details($row['id'], $lang_id);
\Cache::store( "articles_by_date:$month:$year:$lang_id", $articles );
\Cache::store("articles_by_date:$month:$year:$lang_id", $articles);
}
return $articles;
}
public static function news( $page_id, $limit = 6, $lang_id )
public static function news($page_id, $limit = 6, $lang_id)
{
$sort = \front\factory\Pages::page_sort( $page_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 );
$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;
}
public static function get_image( $article, $skip_entry = false )
public static function get_image($article, $skip_entry = false)
{
if ( $article['language']['main_image'] )
if ($article['language']['main_image'])
{
if ( file_exists( substr( $article['language']['main_image'], 1, strlen( $article['language']['main_image'] ) ) ) )
if (file_exists(substr($article['language']['main_image'], 1, strlen($article['language']['main_image']))))
return $article['language']['main_image'];
}
if ( !$skip_entry )
if (!$skip_entry)
{
$dom = new \DOMDocument();
$dom -> loadHTML( mb_convert_encoding( $article['language']['entry'], 'HTML-ENTITIES', "UTF-8" ) );
$images = $dom -> getElementsByTagName( 'img' );
foreach ( $images as $img )
$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 ) ) ) )
$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 )
$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 ) ) ) )
$src = $img->getAttribute('src');
if (file_exists(substr($src, 1, strlen($src))))
return $src;
}
if ( $article['images'] )
if ($article['images'])
return $article['images'][0]['src'];
return false;
}
public static function article_noindex( $article_id )
public static function article_noindex($article_id)
{
global $mdb, $lang;
if ( !$noindex = \Cache::fetch( "article_noindex:$article_id:" . $lang[0] ) )
if (!$noindex = \Cache::fetch("article_noindex:$article_id:" . $lang[0]))
{
$noindex = $mdb -> get( 'pp_articles_langs', 'noindex', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang[0] ] ] );
$noindex = $mdb->get('pp_articles_langs', 'noindex', ['AND' => ['article_id' => (int)$article_id, 'lang_id' => $lang[0]]]);
\Cache::store( "article_noindex:$article_id:" . $lang[0], $noindex );
\Cache::store("article_noindex:$article_id:" . $lang[0], $noindex);
}
return $noindex;
}
public static function page_articles( $page, $lang_id, $bs )
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'] );
$count = \front\factory\Articles::page_articles_count($page['id'], $lang_id);
$ls = ceil($count / $page['articles_limit']);
if ( $bs < 1 )
if ($bs < 1)
$bs = 1;
else if ( $bs > $ls )
else if ($bs > $ls)
$bs = $ls;
$from = $page['articles_limit'] * ( $bs - 1 );
$from = $page['articles_limit'] * ($bs - 1);
if ( $from < 0 )
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['articles'] = \front\factory\Articles::artciles_id((int)$page['id'], $lang_id, (int)$page['articles_limit'], $page['sort_type'], $from);
$results['ls'] = $ls;
return $results;
}
public static function article_details( $article_id, $lang_id )
public static function article_details($article_id, $lang_id)
{
global $mdb;
if ( !$article = \Cache::fetch( "article_details:$lang_id:$article_id" ) )
if (!$article = \Cache::fetch("article_details:$lang_id:$article_id"))
{
$article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] );
$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 )
$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'] )
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 )
$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;
preg_match_all( \front\view\Site::container_pattern, $article['language']['entry'], $container_list );
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
preg_match_all(\front\view\Site::container_pattern, $article['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 );
$article['language']['entry'] = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $article['language']['entry'] );
$container_list_tmp = explode(':', $container_list_tmp);
$article['language']['entry'] = str_replace('[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer($container_list_tmp[1]), $article['language']['entry']);
}
preg_match_all( \front\view\Site::container_pattern, $article['language']['text'], $container_list );
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
preg_match_all(\front\view\Site::container_pattern, $article['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 );
$article['language']['text'] = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $article['language']['text'] );
$container_list_tmp = explode(':', $container_list_tmp);
$article['language']['text'] = str_replace('[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer($container_list_tmp[1]), $article['language']['text']);
}
}
$article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
$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 ] );
$article['tags'] = $mdb -> select( 'pp_tags', [ '[><]pp_articles_tags' => [ 'id' => 'tag_id' ] ], 'name', [ 'article_id' => (int)$article_id ] );
$results = $mdb -> select( 'pp_articles_additional_params', [ '[><]pp_articles_additional_values' => [ 'id' => 'param_id' ] ], [ 'name', 'value', 'language_id' ], [ 'article_id' => (int)$article_id ] );
if ( is_array( $results ) ) foreach ( $results as $row )
$article['images'] = $mdb->select('pp_articles_images', '*', ['article_id' => (int)$article_id, 'ORDER' => ['o' => 'ASC', 'id' => 'ASC'] ] );
// załączniki
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC'] ] );
$article['pages'] = $mdb->select('pp_articles_pages', 'page_id', ['article_id' => (int)$article_id]);
$article['tags'] = $mdb->select('pp_tags', ['[><]pp_articles_tags' => ['id' => 'tag_id']], 'name', ['article_id' => (int)$article_id]);
$results = $mdb->select('pp_articles_additional_params', ['[><]pp_articles_additional_values' => ['id' => 'param_id']], ['name', 'value', 'language_id'], ['article_id' => (int)$article_id]);
if (is_array($results)) foreach ($results as $row)
{
if ( !$row['language_id'] )
$params[ $row['name'] ] = $row['value'];
if (!$row['language_id'])
$params[$row['name']] = $row['value'];
else
$params[ $row['name'] ][$row['language_id']] = $row['value'];
$params[$row['name']][$row['language_id']] = $row['value'];
}
$article['params'] = $params;
\Cache::store( "article_details:$lang_id:$article_id", $article );
\Cache::store("article_details:$lang_id:$article_id", $article);
}
return $article;
}
public static function artciles_id( $page_id, $lang_id, $articles_limit, $sort_type, $from )
public static function artciles_id($page_id, $lang_id, $articles_limit, $sort_type, $from)
{
global $mdb;
switch ( $sort_type )
switch ($sort_type)
{
case 0: $order = 'priority DESC, date_add ASC'; break;
case 1: $order = 'priority DESC, date_add DESC'; break;
case 2: $order = 'priority DESC, date_modify ASC'; break;
case 3: $order = 'priority DESC, date_modify DESC'; break;
case 4: $order = 'priority DESC, o ASC'; break;
case 5: $order = 'priority DESC, title ASC'; break;
case 6: $order = 'priority DESC, title DESC'; break;
default: $order = 'priority DESC, id ASC'; break;
case 0:
$order = 'priority DESC, date_add ASC';
break;
case 1:
$order = 'priority DESC, date_add DESC';
break;
case 2:
$order = 'priority DESC, date_modify ASC';
break;
case 3:
$order = 'priority DESC, date_modify DESC';
break;
case 4:
$order = 'priority DESC, o ASC';
break;
case 5:
$order = 'priority DESC, title ASC';
break;
case 6:
$order = 'priority DESC, title DESC';
break;
default:
$order = 'priority DESC, id ASC';
break;
}
if ( !$output = \Cache::fetch( "artciles_id:$page_id:$lang_id:$order:$from:$articles_limit" ) )
if (!$output = \Cache::fetch("artciles_id:$page_id:$lang_id:$order:$from:$articles_limit"))
{
$results = $mdb -> query( 'SELECT * FROM ( '
. 'SELECT '
. 'a.id, date_modify, date_add, o, priority, '
. '( 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 )
$results = $mdb->query('SELECT * FROM ( '
. 'SELECT '
. 'a.id, date_modify, date_add, o, priority, '
. '( 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'];
\Cache::store( "artciles_id:$page_id:$lang_id:$order:$from:$articles_limit", $output );
\Cache::store("artciles_id:$page_id:$lang_id:$order:$from:$articles_limit", $output);
}
return $output;
}
public static function page_articles_count( $page_id, $lang_id )
public static function page_articles_count($page_id, $lang_id)
{
global $mdb;
if ( !$output = \Cache::fetch( "page_articles_count:$page_id:$lang_id" ) )
if (!$output = \Cache::fetch("page_articles_count:$page_id:$lang_id"))
{
$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();
$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();
$output = $results[0][0];
\Cache::store( "page_articles_count:$page_id:$lang_id", $output );
\Cache::store("page_articles_count:$page_id:$lang_id", $output);
}
return $output;
}
}
}

View File

@@ -6,19 +6,19 @@ class Settings
public static function settings_details()
{
global $mdb;
if ( !$settings = \Cache::fetch( 'settings_details' ) )
{
$results = $mdb -> select( 'pp_settings', '*' );
if ( is_array( $results ) ) foreach ( $results as $row )
$settings[ $row['param'] ] = $row['value'];
\Cache::store( 'settings_details', $settings );
}
return $settings;
}
public static function visit_counter()
{
global $mdb;