This commit is contained in:
2025-07-03 20:56:08 +02:00
parent c5c208aa43
commit cc0c9e86b8
190 changed files with 21992 additions and 61 deletions

View File

@@ -0,0 +1,528 @@
<?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)
*/
require_once _PS_MODULE_DIR_.'anblog/loader.php';
require_once _PS_MODULE_DIR_.'anblog/ReCaptcha/ReCaptcha/ReCaptcha.php';
require_once _PS_MODULE_DIR_.'anblog/ReCaptcha/ReCaptcha/Response.php';
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
use PrestaShop\PrestaShop\Core\Product\ProductListingPresenter;
if (!defined('_PS_VERSION_')) {
exit;
}
class AnblogblogModuleFrontController extends ModuleFrontController
{
public $php_self;
protected $template_path = '';
public function __construct()
{
parent::__construct();
$this->context = Context::getContext();
$this->template_path = _PS_MODULE_DIR_.'anblog/views/templates/front/';
$code = '';
$this->translations = Module::getInstanceByName('anblog')->translateFrontBlog();
if (sizeof(Language::getLanguages(true, true)) > 1) {
$code =$this->context->language->iso_code . '/';
}
$this->context->smarty->assign(
'anblog_main_page',
$this->context->shop->getBaseURL(true) . $code . Configuration::get('link_rewrite', 'blog') . '.html'
);
if (Configuration::get('PS_REWRITING_SETTINGS')) {
$this->blog = AnblogBlog::findByRewrite(array('link_rewrite'=>Tools::getValue('rewrite')));
} else {
$this->blog = new AnblogBlog(Tools::getValue('id'), $this->context->language->id);
}
if (!isset($this->blog->id) || !$this->blog->id){
Tools::redirect('index.php?controller=404');
}
}
/**
* @param object &$object Object
* @param string $table Object table
* @ DONE
*/
protected function copyFromPost(&$object, $table, $post = array())
{
/* Classical fields */
foreach ($post as $key => $value) {
if (property_exists($object, $key) && $key != 'id_'.$table) {
//if (array_key_exists($key, $object) && $key != 'id_'.$table) {
/* Do not take care of password field if empty */
if ($key == 'passwd' && Tools::getValue('id_'.$table) && empty($value)) {
continue;
}
if ($key == 'passwd' && !empty($value)) {
/* Automatically encrypt password in MD5 */
$value = Tools::encrypt($value);
}
$object->{$key} = $value;
}
}
/* Multilingual fields */
$rules = call_user_func(array(get_class($object), 'getValidationRules'), get_class($object));
if (count($rules['validateLang'])) {
$languages = Language::getLanguages(false);
foreach ($languages as $language) {
foreach (array_keys($rules['validateLang']) as $field) {
$field_name = $field.'_'.(int)($language['id_lang']);
$value = Tools::getValue($field_name);
if (isset($value)) {
// validate module
$object->{$field}[(int)($language['id_lang'])] = $value;
}
}
}
}
}
/**
* Save user comment
*/
protected function comment()
{
if (Tools::getValue('token') != Tools::getToken(false)){
Tools::redirect('index.php?controller=404');
}
$post = array();
$post['user'] = Tools::getValue('user');
$post['email'] = Tools::getValue('email');
$post['comment'] = Tools::getValue('comment');
$post['captcha'] = Tools::getValue('g-recaptcha-response', true);
$post['id_anblog_blog'] = Tools::getValue('id_anblog_blog');
$post['submitcomment'] = Tools::getValue('submitcomment');
if (!empty($post)) {
$comment = new AnblogComment();
$config = new AnblogConfig();
$result = true;
$error = new stdClass();
$error->error = true;
if (AnblogConfig::getInstance()->params['google_captcha_status']) {
$recaptcha = new ReReCaptcha(Configuration::get(anblog::PREFIX . 'google_captcha_secret_key'));
$response = $recaptcha->verify(Tools::getValue('g-recaptcha-response'));
$result = $response->isSuccess();
}
$this->copyFromPost($comment, 'comment', $post);
if ($result) {
if ($comment->validateFields(false) && $comment->validateFieldsLang(false)) {
$comment->save();
$error->message = $this->translations['thanks'];
$error->error = false;
} else {
// validate module
$error->message = $this->translations['error'];
}
} else {
// validate module
$error->message = $this->translations['recapcha'];
}
die(json_encode($error));
}
}
/**
* @see FrontController::initContent()
*/
public function initContent()
{
$this->php_self = 'blog';
$config = AnblogConfig::getInstance();
/* Load Css and JS File */
AnblogHelper::loadMedia($this->context, $this);
parent::initContent();
if (Tools::isSubmit('submitcomment')) {
// validate module
$this->comment();
}
$helper = AnblogHelper::getInstance();
if (!$this->blog->id_anblog_blog) {
$this->context->smarty->assign(
array(
'getBlogLink' => true,
'blogLink' => $helper->getFontBlogLink(),
'blogTitle' => htmlentities(Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8'),
'navigationPipe' => Configuration::get('PS_NAVIGATION_PIPE')
)
);
$vars = array(
'error' => true,
);
$this->context->smarty->assign($vars);
$this->context->smarty->assign(
array(
'post_type' => Tools::getIsset('post_type') ? Tools::getValue('post_type') : AnblogConfig::getInstance()->get('item_posts_type'),
'show_in_post' => Tools::getIsset('show_in_post') ? Tools::getValue('show_in_post') : AnblogConfig::getInstance()->get('show_in_post'),
'show_in_blog' => Tools::getIsset('show_in_blog') ? Tools::getValue('show_in_blog') : AnblogConfig::getInstance()->get('show_in_blog'),
)
);
$this->context->smarty->assign('anblog_imageTypes', $this->module->getImageTypesForTpl());
return $this->setTemplate('module:anblog/views/templates/front/single_post.tpl');
}
$category = new anblogcat($this->blog->categories[0], $this->context->language->id);
if ($category->groups != null
&& $category->groups != ''
&& !in_array(Group::getCurrent()->id, explode(';', $category->groups))
) {
Tools::redirect('index.php?controller=404');
}
$this->template_path .= 'default/';
$module_tpl = $this->template_path;
$this->blog->preview_url = '';
if ($this->blog->image) {
$this->blog->image_url = $this->blog->imageObject->mainurl;
if (array_key_exists('anblog_thumb', $this->blog->imageObject->thumbsurls)) {
$this->blog->preview_url = $this->blog->imageObject->thumbsurls['anblog_thumb'];
$this->blog->thumb_url = $this->blog->imageObject->thumbsurls['anblog_thumb'];
}
}
$blog_link = $helper->getBlogLink(get_object_vars($this->blog));
if ($category->id_anblogcat){
$params = array(
'rewrite' => $category->link_rewrite,
'id' => $category->id_anblogcat
);
$this->blog->category_link = $helper->getBlogCatLink($params);
$this->blog->category_title = $category->title;
} else {
$this->blog->category_link = '';
$this->blog->category_title = '';
}
//DONGND:: author name
if ($this->blog->author_name != '') {
$this->blog->author = $this->blog->author_name;
$this->blog->author_link = $helper->getBlogAuthorLink($this->blog->author_name);
} else {
$employee = new Employee($this->blog->id_employee);
$this->blog->author = $employee->firstname.' '.$employee->lastname;
$this->blog->author_link = $helper->getBlogAuthorLink($employee->id);
}
$tags = array();
if ($this->blog->tags && $tmp = explode(',', $this->blog->tags)) {
foreach ($tmp as $tag) {
$tags[] = array(
'tag' => $tag,
'link' => $helper->getBlogTagLink($tag)
);
}
}
$this->blog->hits = $this->blog->hits + 1;
$this->blog->updateField($this->blog->id, array('hits' => $this->blog->hits));
/* breadscrumb */
$params = array(
'rewrite' => $category->link_rewrite,
'id' => $category->id_anblogcat
);
$category->category_link = $helper->getBlogCatLink($params);
$this->context->smarty->assign(
array(
'getBlogLink' => false,
'categories' => array($category),
'blogLink' => $helper->getFontBlogLink(),
'blogTitle' => htmlentities(Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8'),
'navigationPipe' => Configuration::get('PS_NAVIGATION_PIPE')
)
);
$limit = 5;
$samecats = AnblogBlog::getListBlogs(
$category->id_anblogcat,
$this->context->language->id,
0,
$limit,
'date_add',
'DESC',
array('type' => 'samecat', 'id_anblog_blog' => $this->blog->id_anblog_blog),
true
);
foreach ($samecats as $key => $sblog) {
$sblog['link'] = $helper->getBlogLink($sblog);
$samecats[$key] = $sblog;
}
$tagrelated = array();
if ($this->blog->tags) {
$tagrelated = AnblogBlog::getListBlogs(
$category->id_anblogcat,
$this->context->language->id,
0,
$limit,
'date_add',
'DESC',
array('type' => 'tag', 'tag' => $this->blog->tags),
true
);
foreach ($tagrelated as $key => $tblog) {
$tblog['link'] = $helper->getBlogLink($tblog);
$tagrelated[$key] = $tblog;
}
}
/* Comments */
$evars = array();
if (Configuration::get(anblog::PREFIX . 'item_comment_engine', 'local') == 'local') {
$count_comment = 0;
if (Configuration::get(anblog::PREFIX . 'comment_engine', 'local') == 'local') {
// validate module
$count_comment = AnblogComment::countComments($this->blog->id_anblog_blog, true);
}
$blog_link = $helper->getBlogLink(get_object_vars($this->blog)) . '?token=' . Tools::getToken(false);
$limit = (int)Configuration::get(anblog::PREFIX . 'item_limit_comments', 10);
$n = $limit;
$p = abs((int)(Tools::getValue('p', 1)));
$comment = new AnblogComment();
$comments = $comment->getList($this->blog->id_anblog_blog, $this->context->language->id, $p, $limit);
$nb_blogs = $count_comment;
if ($nb_blogs < 1){
$nb_blogs = 1;
}
if ($n < 1){
$n = 1;
}
$range = 2; /* how many pages around page selected */
if ($nb_blogs > 0 && $p > (($nb_blogs / $n) + 1)) {
Tools::redirect(preg_replace('/[&?]p=\d+/', '', $_SERVER['REQUEST_URI']));
}
$pages_nb = ceil($nb_blogs / (int)($n));
$start = (int)($p - $range);
if ($start < 1) {
$start = 1;
}
$stop = (int)($p + $range);
if ($stop > $pages_nb) {
$stop = (int)($pages_nb);
}
$evars = array('pages_nb' => $pages_nb,
'nb_items' => $count_comment,
'p' => (int)$p,
'n' => (int)$n,
'requestPage' => $blog_link,
'requestNb' => $blog_link,
'start' => $start,
'comments' => $comments,
'range' => $range,
'blog_count_comment' => $count_comment,
'stop' => $stop);
}
if ((bool)Module::isEnabled('smartshortcode')
&& context::getcontext()->controller->controller_type == 'front'
) {
$smartshortcode = Module::getInstanceByName('smartshortcode');
$this->blog->content = $smartshortcode->parse($this->blog->content);
}
if (!empty($this->blog->products) && count($this->blog->products) > 0) {
$products = AnblogBlog::getProductsByArrayId($this->blog->products, (int)$this->context->language->id);
if ($products) {
$present_products = array();
$assembler = new ProductAssembler($this->context);
$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
$presenter = new ProductListingPresenter(
new ImageRetriever($this->context->link),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
foreach ($products as $rawProduct) {
$present_products[] = $presenter->present(
$presentationSettings,
$assembler->assembleProduct($rawProduct),
$this->context->language
);
}
$this->blog->products = $present_products;
}
}
$anBlogLikesAddLinks = Context::getContext()->link->getModuleLink(
'anblog',
'likes',
[
'token' => Tools::getToken(false),
'id_post' => $this->blog->id_anblog_blog,
'action' => 'toggleLike'
],
true
);
$anBlogLikesAddLinks = str_replace ('https:', '', $anBlogLikesAddLinks);
$countLikes = anBlogLikes::getCountLikes($this->blog->id_anblog_blog);
if (Context::getContext()->customer->isLogged()) {
$idCustomerGuest = (int) Context::getContext()->customer->id;
} else {
$idCustomerGuest = $this->module->getIdGuest();
}
$anBlogLikes = [
'isLike' => (bool) anBlogLikes::getIdLike($idCustomerGuest, $this->blog->id_anblog_blog),
'count' => anBlogLikes::getCountLikes($this->blog->id_anblog_blog),
'addLink' => $anBlogLikesAddLinks
];
$vars = array(
'tags' => $tags,
'meta_title' => Tools::ucfirst($this->blog->meta_title).' - '.Configuration::get('PS_SHOP_NAME'),
'meta_keywords' => $this->blog->meta_keywords,
'meta_description' => $this->blog->meta_description,
'blog' => $this->blog,
'samecats' => $samecats,
'tagrelated' => $tagrelated,
'config' => $config,
'id_anblog_blog' => $this->blog->id_anblog_blog,
'is_active' => $this->blog->active,
'productrelated' => array(),
'module_tpl' => $module_tpl,
'blog_link' => $blog_link,
'anBlogLikes' => $anBlogLikes
);
$vars = array_merge($vars, $evars);
$this->context->smarty->assign($vars);
$this->context->smarty->assign(
array(
'post_type' => Tools::getIsset('post_type') ? Tools::getValue('post_type') : AnblogConfig::getInstance()->get('item_posts_type'),
'show_in_post' => Tools::getIsset('show_in_post') ? Tools::getValue('show_in_post') : AnblogConfig::getInstance()->get('show_in_post'),
'show_in_blog' => Tools::getIsset('show_in_blog') ? Tools::getValue('show_in_blog') : AnblogConfig::getInstance()->get('show_in_blog'),
)
);
$this->setTemplate('module:anblog/views/templates/front/single_post.tpl');
}
// DONGND:: add meta
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['meta']['title'] = Tools::ucfirst($this->blog->meta_title).' - '.Configuration::get('PS_SHOP_NAME');
$page['meta']['keywords'] = $this->blog->meta_keywords;
$page['meta']['description'] = $this->blog->meta_description;
return $page;
}
//DONGND:: add breadcrumb
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$helper = AnblogHelper::getInstance();
$link = $helper->getFontBlogLink();
$config = AnblogConfig::getInstance();
$breadcrumb['links'][] = array(
'title' => Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id,
$this->translations['blog']
),
'url' => $link,
);
$category = new anblogcat($this->blog->categories[0], $this->context->language->id);
if ($category->id_anblogcat){
$params = array(
'rewrite' => $category->link_rewrite,
'id' => $category->id_anblogcat
);
$breadcrumb['links'][] = array(
'title' => $category->title,
'url' => $helper->getBlogCatLink($params),
);
}
$breadcrumb['links'][] = array(
'title' => Tools::ucfirst($this->blog->meta_title),
'url' => $helper->getBlogLink(get_object_vars($this->blog)),
);
return $breadcrumb;
}
//DONGND:: get layout
public function getLayout()
{
$entity = 'module-anblog-'.$this->php_self;
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
if ($overridden_layout = Hook::exec(
'overrideLayoutTemplate',
array(
'default_layout' => $layout,
'entity' => $entity,
'locale' => $this->context->language->locale,
'controller' => $this,
)
)
) {
return $overridden_layout;
}
if ((int) Tools::getValue('content_only')) {
$layout = 'layouts/layout-content-only.tpl';
}
return $layout;
}
}

View File

@@ -0,0 +1,316 @@
<?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;
}
require_once _PS_MODULE_DIR_.'anblog/loader.php';
class AnblogcategoryModuleFrontController extends ModuleFrontController
{
public $php_self;
protected $template_path = '';
public function __construct()
{
parent::__construct();
$this->context = Context::getContext();
$this->template_path = _PS_MODULE_DIR_.'anblog/views/templates/front/';
$code = '';
if (sizeof(Language::getLanguages(true, true)) > 1) {
$code =$this->context->language->iso_code . '/';
}
$this->context->smarty->assign(
'anblog_main_page',
$this->context->shop->getBaseURL(true) . $code . Configuration::get('link_rewrite', 'blog') . '.html'
);
$this->category = Anblogcat::findByRewrite(array('link_rewrite' => Tools::getValue('rewrite')));
if (!isset($this->category->id) || !$this->category->id){
Tools::redirect('index.php?controller=404');
}
}
/**
* @see FrontController::initContent()
*/
public function initContent()
{
$config = AnblogConfig::getInstance();
/* Load Css and JS File */
AnblogHelper::loadMedia($this->context, $this);
// $this->php_self = 'category';
if ($this->category->groups != null
&& $this->category->groups != ''
&& !in_array(Group::getCurrent()->id, explode(';', $this->category->groups))
) {
Tools::redirect('index.php?controller=404');
}
parent::initContent();
$helper = AnblogHelper::getInstance();
$limit = (int)Configuration::get(anblog::PREFIX . 'listing_limit_items', 6);
$n = $limit;
$p = abs((int)(Tools::getValue('p', 1)));
if ($this->category->id_anblogcat && $this->category->active) {
$this->template_path .= 'default/';
$url = _PS_BASE_URL_;
if (Tools::usingSecureMode()) {
// validate module
$url = _PS_BASE_URL_SSL_;
}
if ($this->category->image) {
// validate module
$this->category->image = $url._ANBLOG_BLOG_IMG_URI_.'/c/'.$this->category->image;
}
$leading_blogs = AnblogBlog::getListBlogs(
$this->category->id_anblogcat,
$this->context->language->id,
$p,
$limit,
'date_add',
'DESC',
[],
true);
$count = AnblogBlog::countBlogs($this->category->id_anblogcat, $this->context->language->id, true);
$authors = array();
foreach ($leading_blogs as $key => $blog) {
$blog = AnblogHelper::buildBlog($helper, $blog, 'anblog_listing_leading_img', $config);
if ($blog['id_employee']) {
if (!isset($authors[$blog['id_employee']])) {
// validate module
$authors[$blog['id_employee']] = new Employee($blog['id_employee']);
}
if ($blog['author_name'] != '') {
$blog['author'] = $blog['author_name'];
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
} else {
$blog['author'] = $authors[$blog['id_employee']]->firstname.' '.$authors[$blog['id_employee']]->lastname;
$blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
}
} else {
$blog['author'] = '';
$blog['author_link'] = '';
}
$leading_blogs[$key] = $blog;
}
$nb_blogs = $count;
$range = 2; /* how many pages around page selected */
if ($p > (($nb_blogs / $n) + 1)) {
Tools::redirect(preg_replace('/[&?]p=\d+/', '', $_SERVER['REQUEST_URI']));
}
$pages_nb = ceil($nb_blogs / (int)($n));
$start = (int)($p - $range);
if ($start < 1) {
$start = 1;
}
$stop = (int)($p + $range);
if ($stop > $pages_nb) {
$stop = (int)($pages_nb);
}
$params = array(
'rewrite' => $this->category->link_rewrite,
'id' => $this->category->id_anblogcat
);
/* breadcrumb */
$r = $helper->getPaginationLink('module-anblog-category', 'category', $params, false, true);
$all_cats = array();
self::parentCategories($this->category, $all_cats);
foreach ($all_cats as $key => $cat) {
$params = array(
'rewrite' => $cat->link_rewrite,
'id' => $cat->id
);
$all_cats[$key]->category_link = $helper->getBlogCatLink($params);
}
$this->context->smarty->assign(
array(
'getBlogLink' => false,
'categories' => $all_cats,
'blogLink' => $helper->getFontBlogLink(),
'blogTitle' => htmlentities(Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8'),
'navigationPipe' => Configuration::get('PS_NAVIGATION_PIPE'),
'isNew' => $this->module->new174,
)
);
/* sub categories */
$categories = $this->category->getChild($this->category->id_anblogcat, $this->context->language->id);
$childrens = array();
if ($categories) {
foreach ($categories as $child) {
$params = array(
'rewrite' => $child['link_rewrite'],
'id' => $child['id_anblogcat']
);
$child['thumb'] = $url._ANBLOG_BLOG_IMG_URI_.'/c/'.$child['image'];
$child['category_link'] = $helper->getBlogCatLink($params);
$childrens[] = $child;
}
}
$this->context->smarty->assign(
array(
'leading_blogs' => $leading_blogs,
'listing_column' => Configuration::get(anblog::PREFIX . 'listing_column', 3),
'module_tpl' => $this->template_path,
'config' => $config,
'range' => $range,
'category' => $this->category,
'start' => $start,
'childrens' => $childrens,
'stop' => $stop,
'pages_nb' => $pages_nb,
'nb_items' => $count,
'p' => (int)$p,
'n' => (int)$n,
'meta_title' => Tools::ucfirst($this->category->title).' - '.Configuration::get('PS_SHOP_NAME'),
'meta_keywords' => $this->category->meta_keywords,
'meta_description' => $this->category->meta_description,
'requestPage' => $r['requestUrl'],
'requestNb' => $r,
'isNew' => $this->module->new174
)
);
} else {
$this->context->smarty->assign(
array(
'getBlogLink' => true,
'blogLink' => $helper->getFontBlogLink(),
'blogTitle' => htmlentities(Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8'),
'navigationPipe' => Configuration::get('PS_NAVIGATION_PIPE')
)
);
$this->context->smarty->assign(
array(
'active' => '0',
'leading_blogs' => array(),
'controller' => 'category',
'isNew' => $this->module->new174,
'category' => $this->category
)
);
}
$this->context->smarty->assign(
array(
'post_type' => Tools::getIsset('post_type') ? Tools::getValue('post_type') : AnblogConfig::getInstance()->get('item_posts_type'),
'show_in_blog' => Tools::getIsset('show_in_blog') ? Tools::getValue('show_in_blog') : AnblogConfig::getInstance()->get('show_in_blog'),
'show_in_post' => Tools::getIsset('show_in_post') ? Tools::getValue('show_in_post') : AnblogConfig::getInstance()->get('show_in_post'),
)
);
$this->context->smarty->assign('anblog_imageTypes', $this->module->getImageTypesForTpl());
$this->setTemplate('module:anblog/views/templates/front/blog.tpl');
}
public static function parentCategories($current, &$return)
{
// if ($current->id_parent) {
// $obj = new Anblogcat($current->id_parent, Context::getContext()->language->id);
// self::parentCategories($obj, $return);
// }
// $return[] = $current;
}
//DONGND:: add meta
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
if ($this->category->meta_title != '' ){
$page['meta']['title'] = $this->category->meta_title;
} else {
$page['meta']['title'] = Tools::ucfirst($this->category->title).' - '.Configuration::get('PS_SHOP_NAME');
}
$page['meta']['keywords'] = $this->category->meta_keywords;
$page['meta']['description'] = $this->category->meta_description;
return $page;
}
//DONGND:: add breadcrumb
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$helper = AnblogHelper::getInstance();
$link = $helper->getFontBlogLink();
$config = AnblogConfig::getInstance();
$breadcrumb['links'][] = array(
'title' => Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, $this->l('Blog', 'category')),
'url' => $link,
);
$category_link = $helper->getBlogCatLink([
'rewrite' => $this->category->link_rewrite,
'id' => $this->category->id_anblogcat
]);
$breadcrumb['links'][] = array(
'title' => $this->category->title,
'url' => $category_link,
);
return $breadcrumb;
}
//DONGND:: get layout
public function getLayout()
{
$entity = 'module-anblog-'.$this->php_self;
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
if ($overridden_layout = Hook::exec(
'overrideLayoutTemplate',
array(
'default_layout' => $layout,
'entity' => $entity,
'locale' => $this->context->language->locale,
'controller' => $this,
)
)
) {
return $overridden_layout;
}
if ((int) Tools::getValue('content_only')) {
$layout = 'layouts/layout-content-only.tpl';
}
return $layout;
}
}

View File

@@ -0,0 +1,72 @@
<?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 anbloglikesModuleFrontController extends ModuleFrontController
{
public function initContent()
{
$result = [];
if (Tools::isSubmit('action')) {
if (Tools::getValue('token') != Tools::getToken(false)){
Tools::redirect('index.php?controller=404');
}
$actionName = Tools::getValue('action', '') . 'Action';
if (method_exists($this, $actionName)) {
$result = $this->$actionName();
}
}
die(json_encode($result));
}
public function toggleLikeAction()
{
$return = [
'status' => '',
'countLikes' => '',
];
$idPost = (int) Tools::getValue('id_post');
if (Context::getContext()->customer->isLogged()) {
$idCustomerGuest = (int) Context::getContext()->customer->id;
} else {
$idCustomerGuest = $this->module->getIdGuest();
}
$idLike = anBlogLikes::getIdLike($idCustomerGuest, $idPost);
if (!$idLike) {
anBlogLikes::addLike($idCustomerGuest, $idPost);
$return['status'] = 1;
} else {
anBlogLikes::deleteLike($idLike, $idPost);
$return['status'] = 0;
}
$return['countLikes'] = anBlogLikes::getCountLikes($idPost);
$this->ajaxDie(json_encode($return));
}
}

View File

@@ -0,0 +1,242 @@
<?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;
}
require_once _PS_MODULE_DIR_.'anblog/loader.php';
class AnbloglistModuleFrontController extends ModuleFrontController
{
public $php_self;
protected $template_path = '';
public function __construct()
{
parent::__construct();
$this->context = Context::getContext();
$this->template_path = _PS_MODULE_DIR_.'anblog/views/templates/front/';
$code = '';
if (sizeof(Language::getLanguages(true, true)) > 1) {
$code =$this->context->language->iso_code . '/';
}
$this->context->smarty->assign(
'anblog_main_page',
$this->context->shop->getBaseURL(true) . $code . Configuration::get('link_rewrite', 'blog') . '.html'
);
}
/**
* @see FrontController::initContent()
*/
public function initContent()
{die('test');
$this->php_self = 'list';
$config = AnblogConfig::getInstance();
$authors = array();
/* Load Css and JS File */
AnblogHelper::loadMedia($this->context, $this);
parent::initContent();
$helper = AnblogHelper::getInstance();
$limit_leading_blogs = (int)$config->get('listing_limit_items', 6);
$author = Tools::getValue('author');
$tag = trim(Tools::getValue('tag'));
$n = (int)$limit_leading_blogs;
$p = abs((int)(Tools::getValue('p', 1)));
$this->template_path .= 'default/';
$condition = array();
if ($author) {
$employee_obj = new Employee($author);
if (isset($employee_obj) && $employee_obj->id != '') {
$condition = array(
'type' => 'author',
'id_employee' => $author,
'employee' => new Employee($author)
);
} else {
$condition = array(
'type' => 'author',
'author_name' => $author,
);
}
$r = $helper->getPaginationLink('module-anblog-list', 'list', array('author' => $author));
}
if ($tag) {
$condition = array(
'type' => 'tag',
'tag' => urldecode($tag)
);
$r = $helper->getPaginationLink('module-anblog-list', 'list', array('tag' => $tag));
}
$blogs = AnblogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'date_add', 'DESC', $condition, true);
$count = AnblogBlog::countBlogs(null, $this->context->language->id, $condition, true);
$leading_blogs = array();
if (count($blogs)) {
$leading_blogs = array_slice($blogs, 0, $limit_leading_blogs);
}
foreach ($leading_blogs as $key => $blog) {
$blog = AnblogHelper::buildBlog($helper, $blog, 'anblog_listing_leading_img', $config);
if ($blog['id_employee']) {
if (!isset($authors[$blog['id_employee']])) {
// validate module
$authors[$blog['id_employee']] = new Employee($blog['id_employee']);
}
if ($blog['author_name'] != '') {
$blog['author'] = $blog['author_name'];
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
} else {
$blog['author'] = $authors[$blog['id_employee']]->firstname . ' ' . $authors[$blog['id_employee']]->lastname;
$blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
}
} else {
$blog['author'] = '';
$blog['author_link'] = '';
}
$leading_blogs[$key] = $blog;
}
$nb_blogs = $count;
$range = 2; /* how many pages around page selected */
if ($p > (($nb_blogs / $n) + 1)) {
Tools::redirect(preg_replace('/[&?]p=\d+/', '', $_SERVER['REQUEST_URI']));
}
$pages_nb = ceil($nb_blogs / (int)($n));
$start = (int)($p - $range);
if ($start < 1) {
$start = 1;
}
$stop = (int)($p + $range);
if ($stop > $pages_nb) {
$stop = (int)($pages_nb);
}
if (!isset($r)) {
$r = $helper->getPaginationLink('module-anblog-list', 'list', array(), false, true);
}
$module_tpl = 'module:anblog/views/templates/front/default';
/* breadcrumb */
$this->context->smarty->assign(
array(
'getBlogLink' => true,
'blogLink' => $helper->getFontBlogLink(),
'blogTitle' => htmlentities(Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8'),
'navigationPipe' => Configuration::get('PS_NAVIGATION_PIPE')
)
);
$url_rss = '';
$enbrss = (int)Configuration::get(anblog::PREFIX . 'indexation', 0);
if ($enbrss == 1) {
$url_rss = Tools::htmlentitiesutf8('http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__).'modules/anblog/rss.php';
}
$this->context->smarty->assign(
array(
'leading_blogs' => $leading_blogs,
'listing_column' => Configuration::get(anblog::PREFIX . 'listing_column', 3),
'filter' => $condition,
'module_tpl' => $module_tpl,
//'module_tpl_listing' => $module_tpl_listing,
'nb_items' => $count,
'range' => $range,
'start' => $start,
'stop' => $stop,
'pages_nb' => $pages_nb,
'config' => $config,
'p' => (int)$p,
'n' => (int)$n,
'meta_title' => Configuration::get(anblog::PREFIX . 'meta_title', Context::getContext()->language->id),
'meta_keywords' => Configuration::get(anblog::PREFIX . 'meta_keywords', Context::getContext()->language->id),
'meta_description' => Configuration::get(anblog::PREFIX . 'meta_description', Context::getContext()->language->id),
'requestPage' => $r['requestUrl'],
'requestNb' => $r,
'controller' => 'latest',
'url_rss' => $url_rss,
'post_type' => Tools::getIsset('post_type') ? Tools::getValue('post_type') : AnblogConfig::getInstance()->get('item_posts_type'),
'show_in_blog' => Tools::getIsset('show_in_blog') ? Tools::getValue('show_in_blog') : AnblogConfig::getInstance()->get('show_in_blog'),
'show_in_post' => Tools::getIsset('show_in_post') ? Tools::getValue('show_in_post') : AnblogConfig::getInstance()->get('show_in_post'),
)
);
$this->context->smarty->assign('anblog_imageTypes', $this->module->getImageTypesForTpl());
$this->setTemplate('module:anblog/views/templates/front/blog.tpl');
}
//DONGND:: add meta title, meta description, meta keywords
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$config = AnblogConfig::getInstance();
$page['meta']['title'] = Configuration::get(anblog::PREFIX . 'meta_title', Context::getContext()->language->id).' - '.Configuration::get('PS_SHOP_NAME');
$page['meta']['keywords'] = Configuration::get(anblog::PREFIX . 'meta_keywords', Context::getContext()->language->id);
$page['meta']['description'] = Configuration::get(anblog::PREFIX . 'meta_description', Context::getContext()->language->id);
return $page;
}
//DONGND:: add breadcrumb
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$link = AnblogHelper::getInstance()->getFontBlogLink();
$config = AnblogConfig::getInstance();
$breadcrumb['links'][] = array(
'title' => Configuration::get(anblog::PREFIX . 'blog_link_title', $this->context->language->id, $this->l('Blog', 'list')),
'url' => $link,
);
return $breadcrumb;
}
//DONGND:: get layout
public function getLayout()
{
$entity = 'module-anblog-'.$this->php_self;
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
if ($overridden_layout = Hook::exec(
'overrideLayoutTemplate',
array(
'default_layout' => $layout,
'entity' => $entity,
'locale' => $this->context->language->locale,
'controller' => $this,
)
)
) {
return $overridden_layout;
}
if ((int) Tools::getValue('content_only')) {
$layout = 'layouts/layout-content-only.tpl';
}
return $layout;
}
}

View File

@@ -0,0 +1,76 @@
<?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 anblogrssModuleFrontController extends ModuleFrontController
{
public function initContent()
{
// Get data
$authors = array();
$config = AnblogConfig::getInstance();
$enbrss = Configuration::get(anblog::PREFIX . 'indexation', 0);
if ($enbrss != 1) {
exit;
}
$config->setVar('blockanblogs_height', Configuration::get('BANBLOGS_HEIGHT'));
$config->setVar('blockanblogs_width', Configuration::get('BANBLOGS_WIDTH'));
$config->setVar('blockanblogs_limit', Configuration::get('BANBLOGS_NBR'));
$limit = Configuration::get(anblog::PREFIX . 'rss_limit_item', 4);
$helper = AnblogHelper::getInstance();
$blogs = AnblogBlog::getListBlogs(
null,
Context::getContext()->language->id,
0,
$limit,
'id_anblog_blog',
'DESC',
array(),
true
);
foreach ($blogs as $key => $blog) {
$blog = AnblogHelper::buildBlog($helper, $blog, 'anblog_listing_leading_img', $config);
if ($blog['id_employee']) {
if (!isset($authors[$blog['id_employee']])) {
// validate module
$authors[$blog['id_employee']] = new Employee($blog['id_employee']);
}
$blog['author'] = $authors[$blog['id_employee']]->firstname.' '.$authors[$blog['id_employee']]->lastname;
$blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
} else {
$blog['author'] = '';
$blog['author_link'] = '';
}
$blogs[$key] = $blog;
}
$this->context->smarty->assign('anblogrss', [
'PS_SHOP_NAME' => Configuration::get('PS_SHOP_NAME'),
'link' => _PS_BASE_URL_.__PS_BASE_URI__,
'webMaster' => Configuration::get('PS_SHOP_EMAIL'),
'language' => Context::getContext()->language->iso_code,
'posts' => $blogs
]);
header('Content-Type:text/xml; charset=utf-8');
echo $this->module->display($this->module->name, 'rss.tpl');
die;
}
}

View File

@@ -0,0 +1,113 @@
<?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;
}
}