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;

View File

@@ -31,12 +31,17 @@ class Articles
return $tpl -> render( 'articles/tags-cloud' );
}
public static function news( $page_id, $articles )
public static function news( $page_id, $articles, $template = '' )
{
$tpl = new \Tpl;
$tpl -> page_id = $page_id;
$tpl -> articles = $articles;
return $tpl -> render( 'articles/news' );
if ( $template )
$tpl = $template;
else
$tpl = 'articles/news';
return \Tpl::view( $tpl, [
'page_id' => $page_id,
'articles' => $articles
] );
}
public static function articles_list( $articles )

View File

@@ -1,4 +1,5 @@
<?php
namespace front\view;
class Site
@@ -8,7 +9,7 @@ class Site
const submenu_pattern = '/SUBMENU:[0-9]*/';
const container_pattern = '/KONTENER:[0-9]*/';
const language_pattern = '/LANG:[a-zA-Z0-9_-]*/';
const news_pattern = '/AKTUALNOSCI:([0-9]*)((:([0-9]*))?)/';
const news_pattern = '/AKTUALNOSCI:([0-9]+)(?::([0-9]*))?(?::([^:\]]+))?/';
const news_list_pattern = '/AKTUALNOSCI_LISTA:([0-9]*)((:([0-9]*))?)/';
const top_news_pattern = '/NAJPOULARNIEJSZE_ARTYKULY:([0-9]*)((:([0-9]*))?)/';
const article_pattern = '/ARTYKUL:[0-9]*/';
@@ -20,181 +21,193 @@ class Site
$settings['link_version'] ? $www = 'www.' : $www = '';
$settings['ssl'] == true ? $domain_prefix = 'https' : $domain_prefix = 'http';
$url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] );
$url = preg_replace('#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME']);
if ( \S::get( 'article' ) )
$layout = \front\factory\Layouts::article_layout( \S::get( 'article' ) );
if (\S::get('article'))
$layout = \front\factory\Layouts::article_layout(\S::get('article'));
if ( !$layout )
$layout = \front\factory\Layouts::active_layout( $page['id'] );
if (!$layout)
$layout = \front\factory\Layouts::active_layout($page['id']);
if ( \S::get( 'layout_id' ) )
$layout = \front\factory\Layouts::layout_details( \S::get( 'layout_id' ) );
if (\S::get('layout_id'))
$layout = \front\factory\Layouts::layout_details(\S::get('layout_id'));
if ( $settings['devel'] == true and file_exists( 'devel.html' ) )
$html = file_get_contents( 'devel.html' );
if ($settings['devel'] == true and file_exists('devel.html'))
$html = file_get_contents('devel.html');
else
{
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
if (\S::is_mobile() and !empty($layout['m_html']))
$html = $layout['m_html'];
else
$html = $layout['html'];
}
\S::set_session( 'layout_id', $layout['layout_id'] ? $layout['layout_id'] : $layout['id'] );
\S::set_session('layout_id', $layout['layout_id'] ? $layout['layout_id'] : $layout['id']);
if ( $settings['google_search_console'] )
$html = str_replace( '</head>', '<meta name="google-site-verification" content="' . $settings['google_search_console'] . '"></head>', $html );
if ($settings['google_search_console'])
$html = str_replace('</head>', '<meta name="google-site-verification" content="' . $settings['google_search_console'] . '"></head>', $html);
if ( \S::get_session( 'contrast' ) )
$html = str_replace( '</head>', '<link rel="stylesheet" type="text/css" href="/layout/contrast.css"></head>', $html );
if (\S::get_session('contrast'))
$html = str_replace('</head>', '<link rel="stylesheet" type="text/css" href="/layout/contrast.css"></head>', $html);
if ( $settings['facebook_link'] )
$html = str_replace( '</body>', \front\view\Site::facebook( $settings['facebook_link'] ) . '</body>', $html );
if ($settings['facebook_link'])
$html = str_replace('</body>', \front\view\Site::facebook($settings['facebook_link']) . '</body>', $html);
if ( strpos( $html, '[BANER_STRONA_GLOWNA]' ) === false )
$html = str_replace( '</body>', '[BANER_STRONA_GLOWNA]' . '</body>', $html );
if (strpos($html, '[BANER_STRONA_GLOWNA]') === false)
$html = str_replace('</body>', '[BANER_STRONA_GLOWNA]' . '</body>', $html);
if ( strpos( $html, '[WIDGET_TELEFON]' ) === false )
$html = str_replace( '</body>', '[WIDGET_TELEFON]' . '</body>', $html );
if (strpos($html, '[WIDGET_TELEFON]') === false)
$html = str_replace('</body>', '[WIDGET_TELEFON]' . '</body>', $html);
if ( $settings['ssl'] == true )
if ($settings['ssl'] == true)
{
$layout['css'] = str_replace( 'http://', 'https://', $layout['css'] );
$layout['js'] = str_replace( 'http://', 'https://', $layout['js'] );
$layout['m_css'] = str_replace( 'http://', 'https://', $layout['m_css'] );
$layout['m_js'] = str_replace( 'http://', 'https://', $layout['m_js'] );
$layout['css'] = str_replace('http://', 'https://', $layout['css']);
$layout['js'] = str_replace('http://', 'https://', $layout['js']);
$layout['m_css'] = str_replace('http://', 'https://', $layout['m_css']);
$layout['m_js'] = str_replace('http://', 'https://', $layout['m_js']);
}
$html = str_replace( '[COPYRIGHT]', \front\view\Site::copyright(), $html );
$html = str_replace( '[BANER_STRONA_GLOWNA]', \front\view\Banners::main_banner( \front\factory\Banners::main_banner() ), $html );
$html = str_replace( '[BANERY]', \front\view\Banners::banners( \front\factory\Banners::banners() ), $html );
$html = str_replace( '[LICZNIK_ODWIEDZIN]', \front\view\Site::visit_counter( \S::get_session( 'visits' ) ), $html );
$html = str_replace( '[WYSZUKIWARKA]', \front\view\Search::search_form(), $html );
$html = str_replace( '[CHMURA_TAGOW]', \front\view\Articles::tags_cloud(), $html );
$html = str_replace( '[KONTRAST]', \front\view\Site::contrast(), $html );
$html = str_replace( '[NEWSLETTER]', \front\view\Newsletter::newsletter(), $html );
$html = str_replace( '[WIDGET_TELEFON]', $settings['widget_phone'] == 1 ? \front\view\Site::widget_phone() : '', $html );
$html = str_replace('[COPYRIGHT]', \front\view\Site::copyright(), $html);
$html = str_replace('[BANER_STRONA_GLOWNA]', \front\view\Banners::main_banner(\front\factory\Banners::main_banner()), $html);
$html = str_replace('[BANERY]', \front\view\Banners::banners(\front\factory\Banners::banners()), $html);
$html = str_replace('[LICZNIK_ODWIEDZIN]', \front\view\Site::visit_counter(\S::get_session('visits')), $html);
$html = str_replace('[WYSZUKIWARKA]', \front\view\Search::search_form(), $html);
$html = str_replace('[CHMURA_TAGOW]', \front\view\Articles::tags_cloud(), $html);
$html = str_replace('[KONTRAST]', \front\view\Site::contrast(), $html);
$html = str_replace('[NEWSLETTER]', \front\view\Newsletter::newsletter(), $html);
$html = str_replace('[WIDGET_TELEFON]', $settings['widget_phone'] == 1 ? \front\view\Site::widget_phone() : '', $html);
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
$html = str_replace( '[CSS]', $layout['m_css'], $html );
if (\S::is_mobile() and !empty($layout['m_html']))
$html = str_replace('[CSS]', $layout['m_css'], $html);
else
$html = str_replace( '[CSS]', $layout['css'], $html );
$html = str_replace('[CSS]', $layout['css'], $html);
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
$html = str_replace( '[JAVA_SCRIPT]', $layout['m_js'], $html );
if (\S::is_mobile() and !empty($layout['m_html']))
$html = str_replace('[JAVA_SCRIPT]', $layout['m_js'], $html);
else
$html = str_replace( '[JAVA_SCRIPT]', $layout['js'], $html );
$html = str_replace('[JAVA_SCRIPT]', $layout['js'], $html);
preg_match_all( self::menu_pattern, $html, $menu );
if ( is_array( $menu[0] ) ) foreach( $menu[0] as $menu_tmp )
preg_match_all(self::menu_pattern, $html, $menu);
if (is_array($menu[0])) foreach ($menu[0] as $menu_tmp)
{
$menu_tmp = explode( ':', $menu_tmp );
$html = str_replace( '[MENU:' . $menu_tmp[1] . ']', \front\view\Menu::menu(
\front\factory\Menu::menu_details( $menu_tmp[1] ), $page['id']
), $html );
$menu_tmp = explode(':', $menu_tmp);
$html = str_replace('[MENU:' . $menu_tmp[1] . ']', \front\view\Menu::menu(
\front\factory\Menu::menu_details($menu_tmp[1]),
$page['id']
), $html);
}
preg_match_all( self::main_menu_pattern, $html, $menu );
if ( is_array( $menu[0] ) ) foreach( $menu[0] as $menu_tmp )
preg_match_all(self::main_menu_pattern, $html, $menu);
if (is_array($menu[0])) foreach ($menu[0] as $menu_tmp)
{
$menu_tmp = explode( ':', $menu_tmp );
$html = str_replace( '[MENU_GLOWNE:' . $menu_tmp[1] . ']', \front\view\Menu::main_menu(
\front\factory\Menu::menu_details( $menu_tmp[1] ), $page['id']
), $html );
$menu_tmp = explode(':', $menu_tmp);
$html = str_replace('[MENU_GLOWNE:' . $menu_tmp[1] . ']', \front\view\Menu::main_menu(
\front\factory\Menu::menu_details($menu_tmp[1]),
$page['id']
), $html);
}
preg_match_all( self::submenu_pattern, $html, $submenu );
if ( is_array( $submenu[0] ) ) foreach( $submenu[0] as $submenu_tmp )
preg_match_all(self::submenu_pattern, $html, $submenu);
if (is_array($submenu[0])) foreach ($submenu[0] as $submenu_tmp)
{
$submenu_tmp = explode( ':', $submenu_tmp );
$html = str_replace( '[SUBMENU:' . $submenu_tmp[1] . ']', \front\view\Menu::submenu(
\front\factory\Menu::submenu_details( $submenu_tmp[1], $lang_id ), $page['id'], $submenu_tmp[1]
), $html );
$submenu_tmp = explode(':', $submenu_tmp);
$html = str_replace('[SUBMENU:' . $submenu_tmp[1] . ']', \front\view\Menu::submenu(
\front\factory\Menu::submenu_details($submenu_tmp[1], $lang_id),
$page['id'],
$submenu_tmp[1]
), $html);
}
preg_match_all( self::container_pattern, $html, $container_list );
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
preg_match_all(self::container_pattern, $html, $container_list);
if (is_array($container_list[0])) foreach ($container_list[0] as $container_list_tmp)
{
$container_list_tmp = explode( ':', $container_list_tmp );
$html = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $html );
$container_list_tmp = explode(':', $container_list_tmp);
$html = str_replace('[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer($container_list_tmp[1]), $html);
}
$html = str_replace( '[ZAWARTOSC]', \front\controls\Site::route(), $html );
$html = str_replace('[ZAWARTOSC]', \front\controls\Site::route(), $html);
preg_match_all( self::news_pattern, $html, $news_list );
if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp )
if ( is_array( $news_list[0] ) )
{
$news_list_tmp = explode( ':', $news_list_tmp );
foreach ( $news_list[0] as $index => $news_list_tmp )
{
$id = $news_list[1][$index];
$limit = $news_list[2][$index] ?: $settings['news_limit'];
$extra = $news_list[3][$index] ?? '';
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
$pattern_parts = ['AKTUALNOSCI', $id];
if ($news_list[2][$index] !== '') $pattern_parts[] = $limit;
if ($extra !== '') $pattern_parts[] = $extra;
$pattern = '[' . implode(':', $pattern_parts) . ']';
$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(
$news_list_tmp[1],
\front\factory\Articles::news( $news_list_tmp[1], $news_limit, $lang_id )
), $html );
$html = str_replace(
$pattern,
\front\view\Articles::news( $id, \front\factory\Articles::news( $id, $limit, $lang_id ), $extra ),
$html
);
}
}
// 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);
if (is_array($news_list[0])) foreach ($news_list[0] as $news_list_tmp)
{
$news_list_tmp = explode( ':', $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 );
$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);
}
// 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, $news_list);
if (is_array($news_list[0])) foreach ($news_list[0] as $news_list_tmp)
{
$news_list_tmp = explode( ':', $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 );
$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);
}
preg_match_all( self::language_pattern, $html, $language_list );
if ( is_array( $language_list[0] ) ) foreach( $language_list[0] as $language_list_tmp )
preg_match_all(self::language_pattern, $html, $language_list);
if (is_array($language_list[0])) foreach ($language_list[0] as $language_list_tmp)
{
$language_list_tmp = explode( ':', $language_list_tmp );
$html = str_replace( '[LANG:' . $language_list_tmp[1] . ']', \S::lang( $language_list_tmp[1] ), $html );
$language_list_tmp = explode(':', $language_list_tmp);
$html = str_replace('[LANG:' . $language_list_tmp[1] . ']', \S::lang($language_list_tmp[1]), $html);
}
if ( \S::get( 'article' ) )
if (\S::get('article'))
{
$article = \front\factory\Articles::article_details( \S::get( 'article' ), $lang_id );
$article = \front\factory\Articles::article_details(\S::get('article'), $lang_id);
$title = $article['language']['meta_title'] ? $article['language']['meta_title'] : $article['language']['title'];
$meta_keywords = $article['language']['meta_keywords'];
$meta_description = $article['language']['meta_description'];
$og_image = $article['language']['main_image'] ? $article['language']['main_image'] : null;
}
else if ( \S::get( 'tag' ) )
else if (\S::get('tag'))
{
$tag = \front\factory\Articles::tag_details( \S::get( 'tag' ) );
$tag = \front\factory\Articles::tag_details(\S::get('tag'));
$title = 'Tag: ' . $tag['name'];
$meta_keywords = $tag['name'];
$meta_description = 'Artykuły oznaczone tagiem: ' . $tag['name'];
}
else if ( \S::get( 'search' ) )
else if (\S::get('search'))
{
$title = 'Wyniki wyszukiwania: ' . \S::get_session( 'search_txt' );
$meta_keywords = \S::get_session( 'search_txt' );
$meta_description = 'Wyniki wyszukiwania: ' . \S::get_session( 'search_txt' );
$title = 'Wyniki wyszukiwania: ' . \S::get_session('search_txt');
$meta_keywords = \S::get_session('search_txt');
$meta_description = 'Wyniki wyszukiwania: ' . \S::get_session('search_txt');
}
else
{
if ( $page['language']['meta_title'] )
if ($page['language']['meta_title'])
$title = $page['language']['meta_title'];
else
$title = $page['language']['title'] . ' ● ' . $settings['firm_name'];
@@ -204,80 +217,80 @@ class Site
}
$seo_additional = \front\factory\SeoAdditional::seo_active();
if ( is_array( $seo_additional ) and count( $seo_additional ) ) foreach ( $seo_additional as $seo )
if (is_array($seo_additional) and count($seo_additional)) foreach ($seo_additional as $seo)
{
preg_match( '/' . str_replace( '/', '\/', $seo['url'] ) . '/', $_SERVER['REQUEST_URI'], $seo_results );
if ( is_array( $seo_results ) and count( $seo_results ) )
preg_match('/' . str_replace('/', '\/', $seo['url']) . '/', $_SERVER['REQUEST_URI'], $seo_results);
if (is_array($seo_results) and count($seo_results))
{
if ( $seo['title'] )
if ($seo['title'])
$title = $seo['title'];
if ( $seo['keywords'] )
if ($seo['keywords'])
$meta_keywords = $seo['keywords'];
if ( $meta_description )
if ($meta_description)
$meta_description = $seo['description'];
if ( $seo['text'] )
$html = str_replace( '[DODATKOWA_TRESC]', '<div class="seo-additional-text">' . $seo['text'] . '</div>', $html );
if ($seo['text'])
$html = str_replace('[DODATKOWA_TRESC]', '<div class="seo-additional-text">' . $seo['text'] . '</div>', $html);
else
$html = str_replace( '[DODATKOWA_TRESC]', '', $html );
$html = str_replace('[DODATKOWA_TRESC]', '', $html);
}
}
$html = str_replace( '[DODATKOWA_TRESC]', '', $html );
$html = str_replace( '[TITLE]', $title, $html );
$html = str_replace( '[META_KEYWORDS]', $meta_keywords, $html );
$html = str_replace( '[META_DESCRIPTION]', $meta_description, $html );
$html = str_replace( '[OG_URL]', $domain_prefix . '://' . $www . $url . $_SERVER["REQUEST_URI"], $html );
$html = str_replace( '[OG_IMG]', $og_image ? ( $domain_prefix . '://' . $www . $url . '/' . $og_image ) : '', $html );
$html = str_replace( '[JEZYKI]', \front\view\Languages::languages(), $html );
$html = str_replace( '[KALENDARZ]', \front\view\Site::calendar(), $html );
$html = str_replace( '[TYTUL_STRONY]', \front\view\Site::title(
$page['language']['title'],
$page['show_title'],
$page['language']['site_title']
), $html );
$html = str_replace( '[STRONA_GLOWNA]', \front\factory\Pages::lang_url(
\front\factory\Pages::main_page_id(),
$lang_id,
\S::get_domain( $_SERVER['HTTP_HOST'] ),
\front\factory\Languages::default_domain()
), $html );
$html = str_replace('[DODATKOWA_TRESC]', '', $html);
$html = str_replace('[TITLE]', $title, $html);
$html = str_replace('[META_KEYWORDS]', $meta_keywords, $html);
$html = str_replace('[META_DESCRIPTION]', $meta_description, $html);
$html = str_replace('[OG_URL]', $domain_prefix . '://' . $www . $url . $_SERVER["REQUEST_URI"], $html);
$html = str_replace('[OG_IMG]', $og_image ? ($domain_prefix . '://' . $www . $url . '/' . $og_image) : '', $html);
$html = str_replace('[JEZYKI]', \front\view\Languages::languages(), $html);
$html = str_replace('[KALENDARZ]', \front\view\Site::calendar(), $html);
$html = str_replace('[TYTUL_STRONY]', \front\view\Site::title(
$page['language']['title'],
$page['show_title'],
$page['language']['site_title']
), $html);
$html = str_replace('[STRONA_GLOWNA]', \front\factory\Pages::lang_url(
\front\factory\Pages::main_page_id(),
$lang_id,
\S::get_domain($_SERVER['HTTP_HOST']),
\front\factory\Languages::default_domain()
), $html);
preg_match_all( self::article_pattern, $html, $articles_list );
if ( is_array( $articles_list[0] ) ) foreach( $articles_list[0] as $article_tmp )
preg_match_all(self::article_pattern, $html, $articles_list);
if (is_array($articles_list[0])) foreach ($articles_list[0] as $article_tmp)
{
$article_tmp = explode( ':', $article_tmp );
$html = str_replace( '[ARTYKUL:' . $article_tmp[1] . ']', \front\view\Articles::article_full( $article_tmp[1], $lang_id ), $html );
$article_tmp = explode(':', $article_tmp);
$html = str_replace('[ARTYKUL:' . $article_tmp[1] . ']', \front\view\Articles::article_full($article_tmp[1], $lang_id), $html);
}
/* atrybut noindex */
if ( \S::get( 'article' ) )
if (\S::get('article'))
{
\front\factory\Articles::article_noindex( \S::get( 'article' ) ) === '1' ? $noindex = 'noindex' : $noindex = 'index, follow';
$html = str_replace( '[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html );
\front\factory\Articles::article_noindex(\S::get('article')) === '1' ? $noindex = 'noindex' : $noindex = 'index, follow';
$html = str_replace('[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html);
}
else
{
$page['language']['noindex'] === '1' ? $noindex = 'noindex' : $noindex = 'index, follow';
$html = str_replace( '[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html );
$html = str_replace('[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html);
}
if ( $page['language']['canonical'] )
$html = str_replace( '</head>', '<link rel="canonical" href="' . $page['language']['canonical'] . '" /></head>', $html );
if ($page['language']['canonical'])
$html = str_replace('</head>', '<link rel="canonical" href="' . $page['language']['canonical'] . '" /></head>', $html);
while ( strpos( $html, '[PHP]' ) !== false )
while (strpos($html, '[PHP]') !== false)
{
$text = explode( '[PHP]', $html );
$text = explode('[PHP]', $html);
$before = $text[0];
for ( $i = 1; $i < count( $text ); $i++ )
for ($i = 1; $i < count($text); $i++)
{
$temp = explode( '[/PHP]' , $text[$i] );
$temp = explode('[/PHP]', $text[$i]);
$code = $temp[0];
ob_start();
eval( str_replace( '&#39;', '"', $code ) );
eval(str_replace('&#39;', '"', $code));
$out .= ob_get_contents();
ob_end_clean();
@@ -286,19 +299,19 @@ class Site
$html = $before . $out;
}
preg_match_all( self::maps_pattern, $html, $maps_list );
if ( is_array( $maps_list[1] ) and !empty( $maps_list[1] ) )
preg_match_all(self::maps_pattern, $html, $maps_list);
if (is_array($maps_list[1]) and !empty($maps_list[1]))
{
$html = strrev( implode( strrev( '<link class="footer" rel="stylesheet" type="text/css" href="/libraries/leaflet/leaflet.css"><script class="footer" type="text/javascript" src="/libraries/leaflet/leaflet.js"></script></head>' ), explode( strrev( '</head>' ), strrev( $html ), 2 ) ) );
foreach( $maps_list[1] as $map_tmp )
$html = strrev(implode(strrev('<link class="footer" rel="stylesheet" type="text/css" href="/libraries/leaflet/leaflet.css"><script class="footer" type="text/javascript" src="/libraries/leaflet/leaflet.js"></script></head>'), explode(strrev('</head>'), strrev($html), 2)));
foreach ($maps_list[1] as $map_tmp)
{
++$map_counter;
$map_settings = explode( '|', $map_tmp );
$html = str_replace( '[MAPA]' . $map_tmp . '[/MAPA]', \front\view\Articles::map( $map_settings, $map_counter ), $html );
$map_settings = explode('|', $map_tmp);
$html = str_replace('[MAPA]' . $map_tmp . '[/MAPA]', \front\view\Articles::map($map_settings, $map_counter), $html);
}
}
$html = str_replace( '[ALERT]', \front\view\Site::alert(), $html );
$html = str_replace('[ALERT]', \front\view\Site::alert(), $html);
return $html;
}
@@ -306,91 +319,90 @@ class Site
public static function widget_phone()
{
$tpl = new \Tpl;
return $tpl -> render( 'widgets/widget-phone' );
return $tpl->render('widgets/widget-phone');
}
public static function facebook( $facebook_link )
public static function facebook($facebook_link)
{
$tpl = new \Tpl;
$tpl -> facebook_link = $facebook_link;
return $tpl -> render( 'site/facebook' );
$tpl->facebook_link = $facebook_link;
return $tpl->render('site/facebook');
}
public static function title( $title, $show_title, $site_title )
public static function title($title, $show_title, $site_title)
{
if ( !$show_title )
if (!$show_title)
return false;
if ( $site_title )
if ($site_title)
$title = $site_title;
$tpl = new \Tpl;
$tpl -> title = $title;
return $tpl -> render( 'site/title' );
$tpl->title = $title;
return $tpl->render('site/title');
}
static public function alert()
{
if ( $alert = \S::get_session( 'alert' ) )
if ($alert = \S::get_session('alert'))
{
\S::delete_session( 'alert' );
\S::delete_session( 'alert-class' );
\S::delete_session('alert');
\S::delete_session('alert-class');
return \Tpl::view( 'site/alert', [
return \Tpl::view('site/alert', [
'alert' => $alert,
'alert_class' => \S::get_session( 'alert-class' )
] );
'alert_class' => \S::get_session('alert-class')
]);
}
}
public static function copyright()
{
$tpl = new \Tpl;
return $tpl -> render( 'site/copyright' );
return $tpl->render('site/copyright');
}
public static function contact()
{
$tpl = new \Tpl;
return $tpl -> render( 'site/contact' );
return $tpl->render('site/contact');
}
public static function cookie_information()
{
$tpl = new \Tpl;
return $tpl -> render( 'site/cookie-information' );
return $tpl->render('site/cookie-information');
}
public static function calendar( $month = '', $year = '', $ajax = false )
public static function calendar($month = '', $year = '', $ajax = false)
{
global $settings, $lang_id;
if ( !$settings['calendar'] )
if (!$settings['calendar'])
return false;
if ( !$month ) $month = date( 'n' );
if ( !$year ) $year = date( 'Y' );
if (!$month) $month = date('n');
if (!$year) $year = date('Y');
$tpl = new \Tpl;
$tpl -> month = $month;
$tpl -> year = $year;
$tpl -> months = \S::months();
$tpl -> ajax = $ajax;
$tpl -> articles = \front\factory\Articles::articles_by_date( $month, $year, $lang_id );
return $tpl -> render( 'site/calendar' );
$tpl->month = $month;
$tpl->year = $year;
$tpl->months = \S::months();
$tpl->ajax = $ajax;
$tpl->articles = \front\factory\Articles::articles_by_date($month, $year, $lang_id);
return $tpl->render('site/calendar');
}
public static function visit_counter( $visit_counter )
public static function visit_counter($visit_counter)
{
$tpl = new \Tpl;
$tpl -> visit_counter = $visit_counter;
return $tpl -> render( 'site/visit-counter' );
$tpl->visit_counter = $visit_counter;
return $tpl->render('site/visit-counter');
}
public static function contrast()
{
$tpl = new \Tpl;
return $tpl -> render( 'site/contrast' );
return $tpl->render('site/contrast');
}
}
?>