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

113 lines
3.2 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;
}
include_once _PS_MODULE_DIR_.'anblog/loader.php';
class anblogsitemapModuleFrontController extends ModuleFrontController
{
public function initContent()
{
if(!(Configuration::get(anblog::PREFIX . 'enable_google_sitemap'))){
Tools::redirect('index.php?controller=404');
}
if (Tools::isSubmit('id_lang')){
$this->getSitemapAction();
} else {
$this->getMainSitemapAction();
}
}
public function getMainSitemapAction()
{
$context = Context::getContext()->language;
$languages = Language::getLanguages();
$sitemapLinks = [];
foreach ($languages as $language){
$sitemapLinks[$language['iso_code']] = $this->context->link->getModuleLink('anblog', 'sitemap', [], true, $language['id_lang']) . '';
}
$this->context->smarty->assign('anblogsitemap', ['sitemapLinks' => $sitemapLinks]);
header('Content-Type:text/xml; charset=utf-8');
echo $this->module->display($this->module->name, 'sitemap_old.tpl');
die;
}
public function getSitemapAction()
{
$posts = $this->getPosts();
$categories = $this->getCategories();
$lastmod = date('Y-m-d');
$this->context->smarty->assign('anblogsitemap', [
'posts' => $posts,
'categories' => $categories,
'lastmod' => $lastmod,
'linkSiteMap' => $this->context->link->getModuleLink('anblog', 'sitemap', [], true)
]);
header('Content-Type:text/xml; charset=utf-8');
echo $this->module->display($this->module->name, 'sitemap_old.tpl');
die;
}
public function getPosts()
{
$helper = AnblogHelper::getInstance();
$config = AnblogConfig::getInstance();
$blogs = AnblogBlog::getListBlogs(
null,
Context::getContext()->language->id,
0,
'all',
'id_anblog_blog',
'DESC',
array(),
true
);
foreach ($blogs as $key => $blog) {
$blog = AnblogHelper::buildBlog($helper, $blog, 'anblog_listing_leading_img', $config);
$blogs[$key] = $blog;
}
return $blogs;
}
public function getCategories()
{
$categories = Anblogcat::getCategories();
$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']]);
$categories[$key] = $category;
}
return $categories;
}
}