Files
wyczarujprezent.pl/modules/anblog/classes/sitemap.php
2025-07-03 20:56:08 +02:00

128 lines
3.6 KiB
PHP

<?php
/**
* 2024 Anvanto
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
*
* @author Anvanto <anvantoco@gmail.com>
* @copyright 2024 Anvanto
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class anBlogSitemap
{
public static function gSitemapCreateLinks($lang)
{
$gSitemapLink[] = ['link' => anBlogSitemap::getHomeLinkBlog($lang)];
if (Configuration::get(anblog::PREFIX . 'enable_posts_sitemap')){
$posts = anBlogSitemap::getPosts($lang['id_lang']);
foreach ($posts as $post) {
$link = [];
$link['link'] = $post['link'];
$link['date_upd'] = $post['date_upd'];
if($post['preview_url'] !== ''){
$link['image'] = [
'link' => $post['preview_url'],
'title_img' => $post['title'],
'caption' => $post['title']
];
}
$gSitemapLink[] = $link;
}
}
if (Configuration::get(anblog::PREFIX . 'enable_categories_sitemap')){
$categories = anBlogSitemap::getCategories($lang['id_lang']);
foreach ($categories as $category) {
$link = [];
$link['link'] = $category['category_link'];
$link['date_upd'] = $category['date_upd'];
if($category['thumb'] !== ''){
$link['image'] = [
'link' => $category['thumb'],
'title_img' => $category['title'],
'caption' => $category['title']
];
}
$gSitemapLink[] = $link;
}
}
return $gSitemapLink;
}
public static function getPosts($id_lang)
{
$helper = AnblogHelper::getInstance();
$config = AnblogConfig::getInstance();
$blogs = AnblogBlog::getListBlogs(
null,
(int) $id_lang,
0,
'all',
'id_anblog_blog',
'DESC',
array(),
true
);
foreach ($blogs as $key => $blog) {
$blog = AnblogHelper::buildBlog($helper, $blog, 'anblog_listing_leading_img', $config, $id_lang);
$blogs[$key] = $blog;
}
return $blogs;
}
public static function getCategories($id_lang)
{
$categories = Anblogcat::getCategories($id_lang);
$helper = AnblogHelper::getInstance();
foreach ($categories as $key => $category) {
$category['thumb'] = '';
if ($category['image'] !=''){
$category['thumb'] = _PS_BASE_URL_ ._ANBLOG_BLOG_IMG_URI_.'c/'.$category['image'];
}
$category['category_link'] = $helper->getBlogCatLink(['rewrite' => $category['link_rewrite'], 'id' => $category['id_anblogcat']], $id_lang);
$categories[$key] = $category;
}
return $categories;
}
public static function getHomeLinkBlog($lang)
{
$homeLinkBlog = '';
if (Configuration::get('PS_REWRITING_SETTINGS')) {
$homeLinkBlog = Context::getContext()->shop->getBaseURL(true) . $lang['iso_code'] . '/' . Configuration::get('link_rewrite', 'blog') . '.html';
} else {
$helper = AnblogHelper::getInstance();
$homeLinkBlog = $helper->getFontBlogLink();
}
return $homeLinkBlog;
}
}
?>