update
This commit is contained in:
72
modules/anblog/classes/anBlogContentTheme.php
Normal file
72
modules/anblog/classes/anBlogContentTheme.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* 2023 Anvanto
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
*
|
||||
* @author Anvanto <anvantoco@gmail.com>
|
||||
* @copyright 2023 Anvanto
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
*/
|
||||
|
||||
class anBlogContentTheme
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->themeDir = Context::getContext()->shop->theme->getDirectory();
|
||||
$this->themeName = Context::getContext()->shop->theme->getName();
|
||||
|
||||
$this->moduleDir = _PS_MODULE_DIR_ . 'anblog/';
|
||||
|
||||
$this->contentDir = $this->themeDir.'assets/antheme/anblog/';
|
||||
$this->jsonContentFile = $this->themeDir.'assets/antheme/anblog/widgets.json';
|
||||
}
|
||||
|
||||
|
||||
public function getContentFilePath()
|
||||
{
|
||||
return $this->getContentDir() . 'widgets.json';
|
||||
}
|
||||
|
||||
public function getContentDir()
|
||||
{
|
||||
$this->createFolders();
|
||||
|
||||
if (Tools::file_exists_no_cache($this->contentDir)){
|
||||
return $this->contentDir;
|
||||
}
|
||||
|
||||
return $this->moduleDir;
|
||||
}
|
||||
|
||||
public function getContentFile()
|
||||
{
|
||||
if (Tools::file_exists_no_cache($this->jsonContentFile)){
|
||||
return Tools::file_get_contents($this->jsonContentFile);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function createFolders()
|
||||
{
|
||||
$this->checkCreateFolder($this->contentDir);
|
||||
}
|
||||
|
||||
public function checkCreateFolder($path)
|
||||
{
|
||||
if (!Tools::file_exists_no_cache($path)){
|
||||
mkdir($path, 0777, true);
|
||||
Tools::copy($this->moduleDir . 'index.php', $path . 'index.php');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
94
modules/anblog/classes/anBlogLikes.php
Normal file
94
modules/anblog/classes/anBlogLikes.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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 anBlogLikes extends ObjectModel
|
||||
{
|
||||
|
||||
public $id_like;
|
||||
|
||||
public $id;
|
||||
|
||||
public $id_customer_guest;
|
||||
|
||||
public $id_post;
|
||||
public $id_shop;
|
||||
public $date_upd;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'anblog_likes',
|
||||
'primary' => 'id_like',
|
||||
'multilang' => false,
|
||||
'fields' => [
|
||||
'id_customer_guest' => ['type' =>self::TYPE_INT ],
|
||||
'id_post' => ['type' =>self::TYPE_INT ],
|
||||
'id_shop' => ['type' =>self::TYPE_INT ],
|
||||
|
||||
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
|
||||
],
|
||||
];
|
||||
|
||||
public static function getIdLike($idCustomerGuest, $idPost)
|
||||
{
|
||||
|
||||
if (!$idCustomerGuest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = '
|
||||
SELECT `id_like`
|
||||
FROM `' . _DB_PREFIX_ . 'anblog_likes`
|
||||
WHERE `id_customer_guest` = ' . (int)$idCustomerGuest . '
|
||||
AND `id_post` = ' . $idPost . '
|
||||
AND `id_shop` = ' . (int) Context::getContext()->shop->id;
|
||||
;
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function addLike($idCustomerGuest, $idPost)
|
||||
{
|
||||
$objLikes = new anBlogLikes;
|
||||
|
||||
$objLikes->id_customer_guest = $idCustomerGuest;
|
||||
$objLikes->id_post = $idPost;
|
||||
$objLikes->id_shop = (int) Context::getContext()->shop->id;
|
||||
$objLikes->save();
|
||||
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
|
||||
UPDATE '._DB_PREFIX_.'anblog_blog SET likes = likes + 1 WHERE id_anblog_blog = '. $idPost .'
|
||||
');
|
||||
|
||||
}
|
||||
public static function deleteLike($idLike, $idPost)
|
||||
{
|
||||
$objLikes = new anBlogLikes($idLike);
|
||||
$objLikes->delete();
|
||||
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
|
||||
UPDATE '._DB_PREFIX_.'anblog_blog SET likes = likes - 1 WHERE id_anblog_blog = '. $idPost .'
|
||||
');
|
||||
}
|
||||
|
||||
public static function getCountLikes($idPost)
|
||||
{
|
||||
$objLikes = new AnblogBlog($idPost);
|
||||
return $objLikes->likes;
|
||||
}
|
||||
|
||||
}
|
||||
241
modules/anblog/classes/anBlogWidgets.php
Normal file
241
modules/anblog/classes/anBlogWidgets.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?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 anBlogWidgets extends ObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id_anblog_blog_widgets;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
public $id_anblogcat;
|
||||
|
||||
public $snow_on;
|
||||
public $sort = 'new';
|
||||
public $slider;
|
||||
public $limit = 3;
|
||||
public $title;
|
||||
public $relation = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'anblog_blog_widgets',
|
||||
'primary' => 'id_anblog_blog_widgets',
|
||||
'multilang' => true,
|
||||
'fields' => [
|
||||
'id_anblogcat' => ['type' =>self::TYPE_INT ],
|
||||
'snow_on' => ['type' =>self::TYPE_INT ],
|
||||
'sort' => ['type' =>self::TYPE_STRING ],
|
||||
'slider' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
|
||||
'limit' => ['type' =>self::TYPE_INT ],
|
||||
'title' => ['type' =>self::TYPE_STRING,'lang' => true, 'validate' => 'isString', 'required' => true, 'size' => 256 ],
|
||||
|
||||
'relation' => ['type' =>self::TYPE_INT],
|
||||
],
|
||||
];
|
||||
|
||||
public static $showOn = [
|
||||
'1' => [
|
||||
'id' => 'index',
|
||||
'name' => 'Home Page (displayHome)',
|
||||
'hook' => ['DisplayHome'],
|
||||
'pageName' => ['index'],
|
||||
],
|
||||
|
||||
'4' => [
|
||||
'id' => 'index',
|
||||
'name' => 'Home Page (displayHomeAfter)',
|
||||
'hook' => ['displayHomeAfter'],
|
||||
'pageName' => ['index'],
|
||||
],
|
||||
|
||||
'5' => [
|
||||
'id' => 'index',
|
||||
'name' => 'Home Page (displayBlogWidget)',
|
||||
'hook' => ['displayBlogWidget'],
|
||||
'pageName' => ['index'],
|
||||
],
|
||||
|
||||
'2' => [
|
||||
'id' => 'category',
|
||||
'name' => 'Category page',
|
||||
'hook' => ['displayContentWrapperBottom'],
|
||||
'pageName' => ['category', 'prices-drop', 'best-sales', 'new-products', 'manufacturer'],
|
||||
],
|
||||
|
||||
'3' => [
|
||||
'id' => 'product',
|
||||
'name' => 'Product page',
|
||||
'hook' => ['displayFooterProduct'],
|
||||
'pageName' => ['product'],
|
||||
],
|
||||
];
|
||||
|
||||
public static function getBlogWidgets($idShowOn = '', $all = false)
|
||||
{
|
||||
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'anblog_blog_widgets` abw
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'anblog_blog_widgets_lang` abwl
|
||||
ON (abwl.`id_anblog_blog_widgets` = abw.`id_anblog_blog_widgets`
|
||||
AND abwl.`id_lang` = '.(int) Context::getContext()->language->id.' )';
|
||||
|
||||
if ($idShowOn != ''){
|
||||
$sql .= 'WHERE abw.`snow_on`= "'. pSQL($idShowOn) .'" ';
|
||||
}
|
||||
|
||||
if (Shop::isFeatureActive()) {
|
||||
$sql .= ' AND abw.`id_anblog_blog_widgets` IN (
|
||||
SELECT abws.`id_anblog_blog_widgets`
|
||||
FROM `' . _DB_PREFIX_ . 'anblog_blog_widgets_shop` abws
|
||||
WHERE abws.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
|
||||
)';
|
||||
}
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getWidgetsByIdProduct($id_product)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$cats = product::getProductCategories($id_product);
|
||||
|
||||
$sql = '
|
||||
SELECT * FROM `' . _DB_PREFIX_ . 'anblog_blog_widgets_relations` szwr, `' . _DB_PREFIX_ . 'anblog_blog_widgets` sw
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'anblog_blog_widgets_lang` sl
|
||||
ON (sw.`id_anblog_blog_widgets` = sl.`id_anblog_blog_widgets`
|
||||
AND sl.`id_lang` = ' . (int) $context->language->id . ')
|
||||
WHERE sw.`id_anblog_blog_widgets` = szwr.`id_anblog_blog_widgets` AND sw.`relation` = szwr.`type`
|
||||
AND ((szwr.`type` = 1 AND szwr.`id_type` IN (' . implode(', ', $cats) . ') )
|
||||
OR (szwr.`type` = 2 AND szwr.`id_type` = '.(int) $id_product.')
|
||||
OR (szwr.`type` = 0 AND szwr.`id_type` = 0)
|
||||
)
|
||||
';
|
||||
|
||||
if (Shop::isFeatureActive()) {
|
||||
$sql .= ' AND sw.`id_anblog_blog_widgets` IN (
|
||||
SELECT sa.`id_anblog_blog_widgets`
|
||||
FROM `' . _DB_PREFIX_ . 'an_productextratabs_shop` sa
|
||||
WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
|
||||
)';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY sw.`id_anblog_blog_widgets`';
|
||||
// echo '<pre>'; echo $sql; die;
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
if (!$result){
|
||||
return [];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public static function getProducsByIdWidgets($id_anblog_blog_widgets = 0)
|
||||
{
|
||||
if (!$id_anblog_blog_widgets){
|
||||
return [];
|
||||
}
|
||||
|
||||
$sql = '
|
||||
SELECT *, p.*
|
||||
FROM `' . _DB_PREFIX_ . 'anblog_blog_widgets_relations` awl
|
||||
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'product` p
|
||||
ON (p.`id_product` = awl.`id_type`)
|
||||
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
|
||||
ON (p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = ' . (int) Context::getContext()->language->id . Shop::addSqlRestrictionOnLang('pl') . ')
|
||||
|
||||
WHERE awl.`id_anblog_blog_widgets` = ' . (int) $id_anblog_blog_widgets . ' AND awl.`type`="2" ';
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false);
|
||||
|
||||
return Product::getProductsProperties(Context::getContext()->language->id, $result);
|
||||
}
|
||||
|
||||
public static function getRelationCategories($id_anblog_blog_widgets = 0)
|
||||
{
|
||||
if (!$id_anblog_blog_widgets){
|
||||
return [];
|
||||
}
|
||||
|
||||
$sql = '
|
||||
SELECT `id_type`
|
||||
FROM `' . _DB_PREFIX_ . 'anblog_blog_widgets_relations` awl
|
||||
WHERE awl.`id_anblog_blog_widgets` = ' . (int) $id_anblog_blog_widgets . ' AND awl.`type`="1" ';
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false);
|
||||
|
||||
$cats = [];
|
||||
if ($result) {
|
||||
foreach ($result as $item){
|
||||
$cats[] = $item['id_type'];
|
||||
}
|
||||
}
|
||||
|
||||
return $cats;
|
||||
}
|
||||
|
||||
public static function exportJsonWidgets($fileManager)
|
||||
{
|
||||
$widgets = self::getBlogWidgets('', 'all');
|
||||
@file_put_contents($fileManager->getContentFilePath(), json_encode($widgets, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
public static function importJsonWidgets($fileManager)
|
||||
{
|
||||
$data = json_decode($fileManager->getContentFile(), true);
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!$data){
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($data as $item){
|
||||
|
||||
$widgetObj = new anBlogWidgets();
|
||||
$widgetObj->id_anblogcat = $item['id_anblogcat'];
|
||||
$widgetObj->snow_on = $item['snow_on'];
|
||||
$widgetObj->sort = $item['sort'];
|
||||
$widgetObj->slider = $item['slider'];
|
||||
$widgetObj->limit = $item['limit'];
|
||||
$widgetObj->relation = $item['relation'];
|
||||
|
||||
$languages = Language::getLanguages();
|
||||
foreach ($languages as $language) {
|
||||
$widgetObj->title[$language['id_lang']] = $item['title'];
|
||||
}
|
||||
$widgetObj->save();
|
||||
|
||||
Db::getInstance()->insert('anblog_blog_widgets_shop', [
|
||||
'id_anblog_blog_widgets' => (int) $widgetObj->id,
|
||||
'id_shop' => (int) Context::getContext()->shop->id
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
612
modules/anblog/classes/anblogcat.php
Normal file
612
modules/anblog/classes/anblogcat.php
Normal file
@@ -0,0 +1,612 @@
|
||||
<?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 Anblogcat extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
public $id_anblogcat;
|
||||
public $image;
|
||||
public $icon_class;
|
||||
public $id_parent = 1;
|
||||
public $is_group = 0;
|
||||
public $width;
|
||||
public $submenu_width;
|
||||
public $colum_width;
|
||||
public $submenu_colum_width;
|
||||
public $item;
|
||||
public $colums = 1;
|
||||
public $type;
|
||||
public $is_content = 0;
|
||||
public $show_title = 1;
|
||||
public $type_submenu;
|
||||
public $level_depth;
|
||||
public $active = 1;
|
||||
public $position;
|
||||
public $show_sub;
|
||||
public $url;
|
||||
public $target;
|
||||
public $privacy;
|
||||
public $position_type;
|
||||
public $menu_class;
|
||||
public $content;
|
||||
public $submenu_content;
|
||||
public $level;
|
||||
public $left;
|
||||
public $right;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
// Lang
|
||||
public $title;
|
||||
public $description;
|
||||
public $content_text;
|
||||
public $submenu_content_text;
|
||||
public $submenu_catids;
|
||||
public $is_cattree = 1;
|
||||
public $template = '';
|
||||
public $meta_title;
|
||||
public $meta_keywords;
|
||||
public $meta_description;
|
||||
public $link_rewrite;
|
||||
private $anModule = null;
|
||||
public $id_shop = '';
|
||||
public $select_data = array();
|
||||
public $randkey;
|
||||
public $groups;
|
||||
|
||||
public function setModule($module)
|
||||
{
|
||||
$this->anModule = $module;
|
||||
}
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'anblogcat',
|
||||
'primary' => 'id_anblogcat',
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'image' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isCatalogName'
|
||||
),
|
||||
'id_parent' => array(
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedInt',
|
||||
'required' => true
|
||||
),
|
||||
'level_depth' => array(
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedInt'
|
||||
),
|
||||
'active' => array(
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
'required' => true
|
||||
),
|
||||
'show_title' => array(
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
'required' => true
|
||||
),
|
||||
'position' => array(
|
||||
'type' => self::TYPE_INT
|
||||
),
|
||||
'privacy' => array(
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedInt',
|
||||
'size' => 6
|
||||
),
|
||||
'menu_class' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isCatalogName',
|
||||
'size' => 25
|
||||
),
|
||||
'icon_class' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isCatalogName',
|
||||
'size' => 125
|
||||
),
|
||||
'date_add' => array(
|
||||
'type' => self::TYPE_DATE,
|
||||
'validate' => 'isDate'
|
||||
),
|
||||
'date_upd' => array(
|
||||
'type' => self::TYPE_DATE,
|
||||
'validate' => 'isDate'
|
||||
),
|
||||
// Lang fields
|
||||
'title' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'required' => true, 'size' => 255
|
||||
),
|
||||
'content_text' => array(
|
||||
'type' => self::TYPE_HTML,
|
||||
'lang' => true,
|
||||
'validate' => 'isString',
|
||||
'required' => false
|
||||
),
|
||||
'meta_title' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255,
|
||||
'required' => false
|
||||
),
|
||||
'meta_description' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255,
|
||||
'required' => false
|
||||
),
|
||||
'meta_keywords' => array('type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255,
|
||||
'required' => false
|
||||
),
|
||||
'link_rewrite' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isLinkRewrite',
|
||||
'required' => true,
|
||||
'size' => 128
|
||||
),
|
||||
'randkey' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => false,
|
||||
'size' => 255
|
||||
),
|
||||
'groups' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => false,
|
||||
'size' => 255
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
public static function findByRewrite($parrams)
|
||||
{
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$id = 0;
|
||||
if (isset($parrams['link_rewrite']) && $parrams['link_rewrite']) {
|
||||
$sql = 'SELECT cl.id_anblogcat FROM '._DB_PREFIX_.'anblogcat_lang cl INNER JOIN '._DB_PREFIX_.'anblogcat_shop cs on cl.id_anblogcat=cs.id_anblogcat AND id_shop='.(int) $id_shop.' INNER JOIN '._DB_PREFIX_.'anblogcat cc on cl.id_anblogcat=cc.id_anblogcat AND cl.id_anblogcat != cc.id_parent AND link_rewrite = "'.pSQL($parrams["link_rewrite"]).'"';
|
||||
if ($row = Db::getInstance()->getRow($sql)) {
|
||||
$id = $row['id_anblogcat'];
|
||||
}
|
||||
}
|
||||
return new Anblogcat($id, $id_lang);
|
||||
}
|
||||
|
||||
public static function getCategories($id_lang = false)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!$id_lang){
|
||||
$id_lang = $context->language->id;
|
||||
}
|
||||
|
||||
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'anblogcat` sw LEFT JOIN `' . _DB_PREFIX_ . 'anblogcat_lang` sl
|
||||
ON (sw.`id_anblogcat` = sl.`id_anblogcat`
|
||||
AND sl.`id_lang` = ' . (int) $id_lang . ')
|
||||
WHERE sw.`active`=1';
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$this->position = self::getLastPosition((int)$this->id_parent);
|
||||
$this->level_depth = $this->calcLevelDepth();
|
||||
$res = parent::add($autodate, $null_values);
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'anblogcat_shop` (`id_shop`, `id_anblogcat`)
|
||||
VALUES('.(int)AnblogHelper::getIDShop().', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
$this->cleanPositions($this->id_parent);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function update($null_values = false)
|
||||
{
|
||||
$this->level_depth = $this->calcLevelDepth();
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
protected function recursiveDelete(&$to_delete, $id_anblogcat)
|
||||
{
|
||||
if (!is_array($to_delete) || !$id_anblogcat) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
|
||||
$result = Db::getInstance()->executeS(
|
||||
'
|
||||
SELECT `id_anblogcat`
|
||||
FROM `'._DB_PREFIX_.'anblogcat`
|
||||
WHERE `id_parent` = '.(int)$id_anblogcat
|
||||
);
|
||||
foreach ($result as $row) {
|
||||
$to_delete[] = (int)$row['id_anblogcat'];
|
||||
$this->recursiveDelete($to_delete, (int)$row['id_anblogcat']);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if ($this->id == 1) {
|
||||
return false;
|
||||
}
|
||||
$this->clearCache();
|
||||
|
||||
// Get children categories
|
||||
$to_delete = array((int)$this->id);
|
||||
$this->recursiveDelete($to_delete, (int)$this->id);
|
||||
$to_delete = array_unique($to_delete);
|
||||
|
||||
// Delete CMS Category and its child from database
|
||||
foreach ($to_delete as &$value) {
|
||||
$value = pSQL($value);
|
||||
}
|
||||
$list = count($to_delete) > 1 ? implode(',', $to_delete) : (int)$this->id;
|
||||
|
||||
Db::getInstance()->execute(
|
||||
'DELETE FROM `'._DB_PREFIX_.'anblogcat` WHERE `id_anblogcat` IN ('.$list.')'
|
||||
);
|
||||
Db::getInstance()->execute(
|
||||
'DELETE FROM `'._DB_PREFIX_.'anblogcat_shop` WHERE `id_anblogcat` IN ('.$list.')'
|
||||
);
|
||||
Db::getInstance()->execute(
|
||||
'DELETE FROM `'._DB_PREFIX_.'anblogcat_lang` WHERE `id_anblogcat` IN ('.$list.')'
|
||||
);
|
||||
anblogcat::cleanPositions($this->id_parent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function countCats()
|
||||
{
|
||||
$row = Db::getInstance()->
|
||||
executeS(
|
||||
'SELECT COUNT(id_anblogcat) as total FROM `'._DB_PREFIX_.'anblogcat` WHERE id_anblogcat!=1 AND 1=1'
|
||||
);
|
||||
return $row[0]['total'];
|
||||
}
|
||||
|
||||
public function deleteSelection($menus)
|
||||
{
|
||||
$return = 1;
|
||||
foreach ($menus as $id_anblogcat) {
|
||||
$obj_menu = new Anblogcat($id_anblogcat);
|
||||
$return &= $obj_menu->delete();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function calcLevelDepth()
|
||||
{
|
||||
$parentanblogcat = new Anblogcat($this->id_parent);
|
||||
if (!$parentanblogcat) {
|
||||
die('parent Menu does not exist');
|
||||
}
|
||||
return $parentanblogcat->level_depth + 1;
|
||||
}
|
||||
|
||||
// public function updatePosition($way, $position)
|
||||
// {
|
||||
// $sql = 'SELECT cp.`id_anblogcat`, cp.`position`, cp.`id_parent`
|
||||
// FROM `'._DB_PREFIX_.'anblogcat` cp
|
||||
// WHERE cp.`id_parent` = '.(int)$this->id_parent.'
|
||||
// ORDER BY cp.`position` ASC';
|
||||
// $res = Db::getInstance()->executeS($sql);
|
||||
// if (!$res) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// foreach ($res as $menu) {
|
||||
// if ((int)$menu['id_anblogcat'] == (int)$this->id) {
|
||||
// $moved_menu = $menu;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!isset($moved_menu) || !isset($position)) {
|
||||
// return false;
|
||||
// }
|
||||
// // < and > statements rather than BETWEEN operator
|
||||
// // since BETWEEN is treated differently according to databases
|
||||
// return (Db::getInstance()->execute(
|
||||
// '
|
||||
// UPDATE `'._DB_PREFIX_.'anblogcat`
|
||||
// SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
// WHERE `position`
|
||||
// '.($way ? '> '.(int)$moved_menu['position'].' AND
|
||||
// `position` <= '.(int)$position : '< '.(int)$moved_menu['position'].' AND `position` >= '.(int)$position).'
|
||||
// AND `id_parent`='.(int)$moved_menu['id_parent']
|
||||
// ) && Db::getInstance()->execute(
|
||||
// '
|
||||
// UPDATE `'._DB_PREFIX_.'anblogcat`
|
||||
// SET `position` = '.(int)$position.'
|
||||
// WHERE `id_parent` = '.(int)$moved_menu['id_parent'].'
|
||||
// AND `id_anblogcat`='.(int)$moved_menu['id_anblogcat']
|
||||
// ));
|
||||
// }
|
||||
|
||||
public static function cleanPositions($id_parent)
|
||||
{
|
||||
$result = Db::getInstance()->executeS(
|
||||
'
|
||||
SELECT `id_anblogcat`
|
||||
FROM `'._DB_PREFIX_.'anblogcat`
|
||||
WHERE `id_parent` = '.(int)$id_parent.'
|
||||
ORDER BY `position`'
|
||||
);
|
||||
$sizeof = count($result);
|
||||
for ($i = 0; $i < $sizeof; ++$i) {
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'anblogcat`
|
||||
SET `position` = '.(int)$i.'
|
||||
WHERE `id_parent` = '.(int)$id_parent.'
|
||||
AND `id_anblogcat` = '.(int)$result[$i]['id_anblogcat'];
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getLastPosition($id_parent)
|
||||
{
|
||||
return (
|
||||
Db::getInstance()->
|
||||
getValue(
|
||||
'SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'anblogcat` WHERE `id_parent` = '.(int)$id_parent
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getInfo($id_anblogcat, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
if (!$id_shop) {
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
}
|
||||
$sql = 'SELECT m.*, md.title, md.description, md.content_text
|
||||
FROM '._DB_PREFIX_.'megamenu m
|
||||
LEFT JOIN '._DB_PREFIX_.'anblogcat_lang md
|
||||
ON m.id_anblogcat = md.id_anblogcat AND md.id_lang = '.(int)$id_lang
|
||||
.' JOIN '._DB_PREFIX_.'anblogcat_shop bs
|
||||
ON m.id_anblogcat = bs.id_anblogcat AND bs.id_shop = '.(int)($id_shop);
|
||||
$sql .= ' WHERE m.id_anblogcat='.(int)$id_anblogcat;
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public function getChild($id_anblogcat = null, $id_lang = null, $id_shop = null, $active = false)
|
||||
{
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
if (!$id_shop) {
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
$sql = ' SELECT m.*, md.*
|
||||
FROM '._DB_PREFIX_.'anblogcat m
|
||||
LEFT JOIN '._DB_PREFIX_.'anblogcat_lang md
|
||||
ON m.id_anblogcat = md.id_anblogcat AND md.id_lang = '.(int)$id_lang
|
||||
.' JOIN '._DB_PREFIX_.'anblogcat_shop bs
|
||||
ON m.id_anblogcat = bs.id_anblogcat AND bs.id_shop = '.(int)($id_shop);
|
||||
if ($active) {
|
||||
$sql .= ' WHERE m.`active`=1 ';
|
||||
}
|
||||
|
||||
if ($id_anblogcat != null) {
|
||||
// validate module
|
||||
$sql .= ' WHERE id_parent='.(int)$id_anblogcat;
|
||||
}
|
||||
$sql .= ' ORDER BY `position` ';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public function getAllChild($id_anblogcat = null, $id_lang = null, $id_shop = null, $active = false)
|
||||
{
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
if (!$id_shop) {
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
$sql = ' SELECT m.id_anblogcat AS id_category, m.id_anblogcat AS id_anblogcat, m.level_depth AS level_depth,
|
||||
md.title AS title, m.id_parent, md.title AS name, m.randkey AS randkey, md.link_rewrite, m.icon_class, m.menu_class
|
||||
FROM '._DB_PREFIX_.'anblogcat m
|
||||
LEFT JOIN '._DB_PREFIX_.'anblogcat_lang md
|
||||
ON m.id_anblogcat = md.id_anblogcat AND md.id_lang = '.(int)$id_lang
|
||||
.' JOIN '._DB_PREFIX_.'anblogcat_shop bs
|
||||
ON m.id_anblogcat = bs.id_anblogcat AND bs.id_shop = '.(int)($id_shop);
|
||||
if ($active) {
|
||||
$sql .= ' WHERE m.`active`=1 ';
|
||||
}
|
||||
|
||||
if ($id_anblogcat != null) {
|
||||
// validate module
|
||||
$sql .= ' WHERE id_parent='.(int)$id_anblogcat;
|
||||
}
|
||||
$sql .= ' ORDER BY `position` ';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public function hasChild($id)
|
||||
{
|
||||
return isset($this->children[$id]);
|
||||
}
|
||||
|
||||
public function getNodes($id)
|
||||
{
|
||||
if (empty($this->children[$id])) {
|
||||
return false;
|
||||
}
|
||||
return $this->children[$id];
|
||||
}
|
||||
|
||||
public function getTree($id = null)
|
||||
{
|
||||
$childs = $this->getChild($id);
|
||||
foreach ($childs as $child) {
|
||||
// validate module
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
}
|
||||
$data = $this->getNodes(1);
|
||||
$tree = $this->genTree($data);
|
||||
|
||||
if (!$tree){
|
||||
return false;
|
||||
}
|
||||
|
||||
Context::getContext()->smarty->assign(
|
||||
array(
|
||||
'tree' => $tree,
|
||||
'selected' => Tools::getValue('id_anblogcat')
|
||||
)
|
||||
);
|
||||
return Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'anblog/views/templates/admin/prerender/tree.tpl');
|
||||
}
|
||||
|
||||
public function getDropdown($id, $selected = 1)
|
||||
{
|
||||
$this->children = array();
|
||||
$childs = $this->getChild($id);
|
||||
foreach ($childs as $child) {
|
||||
// validate module
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
}
|
||||
$output = array(array('id' => '1', 'title' => 'Root', 'selected' => ''));
|
||||
$output = $this->genOption(1, 1, $selected, $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level (default 0 )
|
||||
* @param type $output ( default array )
|
||||
* @param type $output
|
||||
*/
|
||||
public function genOption($parent, $level, $selected, $output)
|
||||
{
|
||||
// module validation
|
||||
!is_null($level) ? $level : $level = 0;
|
||||
is_array($output) ? true : $output = array();
|
||||
|
||||
if ($this->hasChild($parent)) {
|
||||
$data = $this->getNodes($parent);
|
||||
foreach ($data as $menu) {
|
||||
$output[] = array(
|
||||
'id' => $menu['id_anblogcat'],
|
||||
'title' => str_repeat('-', $level).' '.$menu['title'].' (ID:'.$menu['id_anblogcat'].')',
|
||||
'selected' => $selected
|
||||
);
|
||||
if ($menu['id_anblogcat'] != $parent) {
|
||||
$output = $this->genOption($menu['id_anblogcat'], $level + 1, $selected, $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function genTree(&$data)
|
||||
{
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $key => $item) {
|
||||
$id = isset($item['id_anblogcat']) ? $item['id_anblogcat'] : $item['id_category'];
|
||||
$children = $this->getAllChild($id);
|
||||
if (!empty($children)) {
|
||||
$data[$key]['children'] = $children;
|
||||
$this->genTree($data[$key]['children']);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFrontEndTree($id, $helper)
|
||||
{
|
||||
$childs = $this->getChild(null);
|
||||
|
||||
foreach ($childs as $child) {
|
||||
// validate module
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
}
|
||||
|
||||
$data = $this->getNodes($id);
|
||||
$tree = $this->genFrontEndTree($data, $helper);
|
||||
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Context::getContext()->smarty->assign(
|
||||
array(
|
||||
'tree' => $tree,
|
||||
'selected' => Tools::getValue('id_anblogcat')
|
||||
)
|
||||
);
|
||||
return Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'anblog/views/templates/front/category_menu.tpl');
|
||||
}
|
||||
|
||||
public function genFrontEndTree(&$data, $helper)
|
||||
{
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $key => $item) {
|
||||
$id = isset($item['id_anblogcat']) ? $item['id_anblogcat'] : $item['id_category'];
|
||||
$params = array(
|
||||
'rewrite' => $item['link_rewrite'],
|
||||
'id' => $id
|
||||
);
|
||||
|
||||
$category_link = $helper->getBlogCatLink($params);
|
||||
$data[$key]['category_link'] = $category_link;
|
||||
$children = $this->getAllChild($id);
|
||||
if (!empty($children)) {
|
||||
$data[$key]['children'] = $children;
|
||||
$this->genFrontEndTree($data[$key]['children'], $helper);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function autoCreateKey()
|
||||
{
|
||||
$sql = 'SELECT '.self::$definition['primary'].' FROM '._DB_PREFIX_.self::$definition['table'].
|
||||
' WHERE randkey IS NULL OR randkey = ""';
|
||||
|
||||
$rows = Db::getInstance()->executes($sql);
|
||||
foreach ($rows as $row) {
|
||||
$mod_group = new Anblogcat((int)$row[self::$definition['primary']]);
|
||||
include_once _PS_MODULE_DIR_.'anblog/libs/Helper.php';
|
||||
$mod_group->randkey = AnblogHelper::genKey();
|
||||
try {
|
||||
// Try caught to remove validate
|
||||
$mod_group->update();
|
||||
} catch (Exception $exc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
905
modules/anblog/classes/blog.php
Normal file
905
modules/anblog/classes/blog.php
Normal file
@@ -0,0 +1,905 @@
|
||||
<?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/libs/Helper.php';
|
||||
|
||||
class AnblogBlog extends ObjectModel
|
||||
{
|
||||
/**
|
||||
* @var string Name
|
||||
*/
|
||||
public $meta_title;
|
||||
public $meta_description;
|
||||
public $meta_keywords;
|
||||
public $content;
|
||||
public $description;
|
||||
public $video_code;
|
||||
public $image = '';
|
||||
public $thumb = '';
|
||||
public $likes;
|
||||
public $link_rewrite;
|
||||
public $id_anblogcat;
|
||||
public $indexation;
|
||||
public $active;
|
||||
public $id_anblog_blog;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
public $hits = 0;
|
||||
public $id_employee;
|
||||
public $tags;
|
||||
public $shops = array();
|
||||
public $categories = array();
|
||||
public $positions = array();
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $products = 'a:0:{}';
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
//DONGND:: add author name
|
||||
public $author_name;
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'anblog_blog',
|
||||
'primary' => 'id_anblog_blog',
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'image' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'lang' => false),
|
||||
'id_employee' => array('type' => self::TYPE_INT),
|
||||
'indexation' => array('type' => self::TYPE_BOOL),
|
||||
'active' => array('type' => self::TYPE_BOOL),
|
||||
'thumb' => array('type' => self::TYPE_STRING, 'lang' => false,),
|
||||
'hits' => array('type' => self::TYPE_INT),
|
||||
'likes' => array('type' => self::TYPE_INT),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'video_code' => array('type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false),
|
||||
'author_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
|
||||
// Lang fields
|
||||
'meta_description' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255
|
||||
),
|
||||
'meta_keywords' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255
|
||||
),
|
||||
'tags' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255
|
||||
),
|
||||
'meta_title' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'required' => true,
|
||||
'size' => 128
|
||||
),
|
||||
'link_rewrite' => array(
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isLinkRewrite',
|
||||
'required' => true,
|
||||
'size' => 128
|
||||
),
|
||||
'content' => array(
|
||||
'type' => self::TYPE_HTML,
|
||||
'lang' => true,
|
||||
'validate' => 'isString',
|
||||
'size' => 3999999999999
|
||||
),
|
||||
'description' => array(
|
||||
'type' => self::TYPE_HTML,
|
||||
'lang' => true,
|
||||
'validate' => 'isCleanHtml',
|
||||
'size' => 3999999999999
|
||||
),
|
||||
'products' => array('type' => self::TYPE_STRING),
|
||||
),
|
||||
);
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'objectNodeName' => 'content',
|
||||
'objectsNodeName' => 'content_management_system',
|
||||
);
|
||||
|
||||
public function __construct($id = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
parent::__construct($id, $id_lang, $id_shop);
|
||||
$this->imageObject = new AnblogImage($this);
|
||||
|
||||
if ((int)$this->id) {
|
||||
$sql = 'SELECT id_shop FROM `'._DB_PREFIX_.'anblog_blog_shop` '
|
||||
.'WHERE `id_anblog_blog` IN ('.(int)$this->id.')';
|
||||
foreach (Db::getInstance()->executeS($sql) as $id_shop) {
|
||||
$this->shops[] = $id_shop['id_shop'];
|
||||
}
|
||||
$sql = 'SELECT id_anblogcat, position FROM `'._DB_PREFIX_.'anblog_blog_categories` '
|
||||
.'WHERE `id_anblog_blog` IN ('.(int)$this->id.')';
|
||||
foreach (Db::getInstance()->executeS($sql) as $id_category) {
|
||||
$this->categories[] = $id_category['id_anblogcat'];
|
||||
$this->positions[$id_category['id_anblogcat']] = $id_category['position'];
|
||||
}
|
||||
} else {
|
||||
$shops = Shop::getContextListShopID();
|
||||
if (count($shops)) {
|
||||
foreach ($shops as $shop_id) {
|
||||
$this->shops[] = $shop_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->products = json_decode($this->products);
|
||||
if (!$this->products || !is_array($this->products)) {
|
||||
$this->products = array();
|
||||
}
|
||||
}
|
||||
|
||||
public static function findByRewrite($parrams)
|
||||
{
|
||||
$id_lang = (int) Context::getContext()->language->id;
|
||||
$id_shop = (int) Context::getContext()->shop->id;
|
||||
$id = 0;
|
||||
if (isset($parrams['link_rewrite']) && $parrams['link_rewrite']) {
|
||||
$sql = '
|
||||
SELECT bl.id_anblog_blog, bl.id_lang FROM '._DB_PREFIX_.'anblog_blog_lang bl
|
||||
INNER JOIN '._DB_PREFIX_.'anblog_blog_shop bs
|
||||
ON (bl.id_anblog_blog = bs.id_anblog_blog AND id_shop = '. (int) $id_shop.')
|
||||
WHERE link_rewrite = "'.pSQL($parrams['link_rewrite']).'" AND bl.`id_lang` = '.$id_lang.'
|
||||
';
|
||||
|
||||
if ($row = Db::getInstance()->getRow($sql)) {
|
||||
$id = $row['id_anblog_blog'];
|
||||
}
|
||||
}
|
||||
return new AnblogBlog($id, $id_lang);
|
||||
}
|
||||
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$shops = array();
|
||||
if (!Shop::isFeatureActive()) {
|
||||
$shops[] = Shop::getContextShopID();
|
||||
} else {
|
||||
$shops = Tools::getValue('shops', array());
|
||||
}
|
||||
$categories = Tools::getValue('categories', array());
|
||||
$this->products = json_encode($this->products);
|
||||
$res = parent::add($autodate, $null_values);
|
||||
/*if (isset($_FILES['image_link']) && isset($_FILES['image_link']['tmp_name']) && !empty($_FILES['image_link']['tmp_name'])) {
|
||||
$this->imageObject->uploadNew($this->id);
|
||||
}*/
|
||||
|
||||
foreach ($shops as $id_shop) {
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'anblog_blog_shop` (`id_shop`, `id_anblog_blog`)
|
||||
VALUES('.(int)$id_shop.', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
}
|
||||
foreach ($categories as $id_category) {
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'anblog_blog_categories` (`id_anblogcat`, `id_anblog_blog`)
|
||||
VALUES('.(int)$id_category.', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$this->cleanPositions((int)$category);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function update($null_values = false)
|
||||
{
|
||||
$shops = array();
|
||||
if (!Shop::isFeatureActive()) {
|
||||
$shops[] = Shop::getContextShopID();
|
||||
} else {
|
||||
$shops = Tools::getValue('shops', array());
|
||||
}
|
||||
$categories = Tools::getValue('categories', array());
|
||||
$this->products = json_encode($this->products);
|
||||
if (parent::update($null_values)) {
|
||||
$res = true;
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'anblog_blog_shop` '
|
||||
.'WHERE `id_anblog_blog` IN ('.(int)$this->id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
foreach ($shops as $id_shop) {
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'anblog_blog_shop` (`id_shop`, `id_anblog_blog`)
|
||||
VALUES('.(int)$id_shop.', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
}
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'anblog_blog_categories` '
|
||||
.'WHERE `id_anblog_blog` IN ('.(int)$this->id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
foreach ($categories as $id_category) {
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'anblog_blog_categories` (`id_anblogcat`, `id_anblog_blog`)
|
||||
VALUES('.(int)$id_category.', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
}
|
||||
return $res & $this->cleanPositions($this->id_anblogcat);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateField($id, $fields)
|
||||
{
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'anblog_blog` SET ';
|
||||
$last_key = current(array_keys($fields));
|
||||
foreach ($fields as $field => $value) {
|
||||
$sql .= $field." = '".$value."'";
|
||||
if ($field != $last_key) {
|
||||
// validate module
|
||||
$sql .= ',';
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' WHERE `id_anblog_blog`='.(int)$id;
|
||||
return Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (parent::delete()) {
|
||||
// BLOG_SHOP
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'anblog_blog_shop` '
|
||||
.'WHERE `id_anblog_blog` IN ('.(int)$this->id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'anblog_blog_categories` '
|
||||
.'WHERE `id_anblog_blog` IN ('.(int)$this->id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
|
||||
//delete comment
|
||||
$result_comment = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT `id_anblog_comment` as id FROM `'._DB_PREFIX_.'anblog_comment`
|
||||
WHERE `id_anblog_blog` = '.(int)$this->id
|
||||
);
|
||||
foreach ($result_comment as $value) {
|
||||
$comment = new AnblogComment($value['id']);
|
||||
$comment->delete();
|
||||
}
|
||||
|
||||
$this->imageObject->delete();
|
||||
|
||||
return $this->cleanPositions($this->id_anblogcat);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $condition ( default array )
|
||||
* @param Boolean $is_active ( default false )
|
||||
*/
|
||||
public static function getListBlogs($id_category, $id_lang, $page_number, $nb_products, $order_by, $order_way, $condition = array(), $is_active = false, $id_shop = null, $sort = '')
|
||||
{
|
||||
// module validation
|
||||
if ($nb_products !== 'all'){
|
||||
!is_null($nb_products) ? true : $nb_products = 10;
|
||||
|
||||
if ($nb_products < 1) {
|
||||
$nb_products = 10;
|
||||
}
|
||||
}
|
||||
|
||||
!is_null($page_number) ? true : $page_number = 0;
|
||||
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
if ($page_number < 1) {
|
||||
$page_number = 1;
|
||||
}
|
||||
|
||||
if (empty($order_by) || $order_by == 'position') {
|
||||
$order_by = 'date_add';
|
||||
}
|
||||
if (empty($order_way)) {
|
||||
$order_way = 'DESC';
|
||||
}
|
||||
if ($order_by == 'id_anblog_blog' || $order_by == 'date_add' || $order_by == 'date_upd' || $order_by == 'title') {
|
||||
$order_by_prefix = 'c';
|
||||
}
|
||||
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
|
||||
$where = '';
|
||||
|
||||
if ($id_category) {
|
||||
// validate module
|
||||
$where .= ' AND abbc.id_anblogcat='.(int)$id_category;
|
||||
}
|
||||
|
||||
if ($id_shop) {
|
||||
// validate module
|
||||
$where .= ' AND s.id_shop='.(int)$id_shop;
|
||||
}
|
||||
|
||||
|
||||
if (isset($condition['type'])) {
|
||||
switch ($condition['type']) {
|
||||
case 'author':
|
||||
if (isset($condition['id_employee'])) {
|
||||
$where .= ' AND id_employee='.(int)$condition['id_employee'].' AND (author_name = "" OR author_name is null)';
|
||||
} else {
|
||||
$where .= ' AND author_name LIKE "%'.pSQL($condition['author_name']).'%"';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
$tmp = explode(',', $condition['tag']);
|
||||
|
||||
if (!empty($tmp) && count($tmp) > 1) {
|
||||
$t = array();
|
||||
foreach ($tmp as $tag) {
|
||||
// validate module
|
||||
$t[] = 'l.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
}
|
||||
$where .= ' AND ('.implode(' OR ', $t).') ';
|
||||
} else {
|
||||
// validate module
|
||||
$where .= ' AND l.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
}
|
||||
break;
|
||||
case 'samecat':
|
||||
$where .= ' AND c.id_anblog_blog!='.(int)$condition['id_anblog_blog'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_active) {
|
||||
// validate module
|
||||
$where .= ' AND c.active=1';
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT c.*, l.*, l.meta_title as title, blc.link_rewrite as category_link_rewrite , blc.title as category_title
|
||||
FROM '._DB_PREFIX_.'anblog_blog c
|
||||
LEFT JOIN '._DB_PREFIX_.'anblog_blog_lang l
|
||||
ON (c.id_anblog_blog = l.id_anblog_blog) and l.id_lang='.(int)$id_lang
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblog_blog_shop s
|
||||
ON (c.id_anblog_blog = s.id_anblog_blog) and s.id_shop='.(int)$id_shop
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblog_blog_categories abbc ON abbc.id_anblog_blog = c.id_anblog_blog '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblogcat bc ON bc.id_anblogcat = abbc.id_anblogcat '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblogcat_lang blc
|
||||
ON blc.id_anblogcat=bc.id_anblogcat and blc.id_lang='.(int)$id_lang
|
||||
.' '.Shop::addSqlAssociation('blog', 'c').'
|
||||
WHERE l.id_lang = '.(int)$id_lang.$where.'
|
||||
GROUP BY c.id_anblog_blog
|
||||
';
|
||||
|
||||
|
||||
if ($sort == ''){
|
||||
$query .= 'ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '
|
||||
.pSQL($order_way).'';
|
||||
} else if ($sort == 'new'){
|
||||
$query .= 'ORDER BY c.date_add DESC ';
|
||||
} else {
|
||||
$query .= 'ORDER BY c.hits DESC ';
|
||||
}
|
||||
|
||||
|
||||
if ($nb_products !== 'all'){
|
||||
$query .= ' LIMIT '.(int)(($page_number - 1) * $nb_products).', '.(int)$nb_products.'';
|
||||
}
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $condition ( default array )
|
||||
* @param Boolean $is_active ( default false )
|
||||
*/
|
||||
|
||||
public static function countBlogs($id_category, $id_lang = false, $condition = array(), $is_active = false, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (!$id_lang){
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
|
||||
$where = '';
|
||||
if ($id_category) {
|
||||
// validate module
|
||||
$where .= 'AND abc.id_anblogcat='.(int)$id_category;
|
||||
}
|
||||
if ($is_active) {
|
||||
// validate module
|
||||
$where .= ' AND c.active=1';
|
||||
}
|
||||
|
||||
if (isset($condition['type'])) {
|
||||
switch ($condition['type']) {
|
||||
case 'author':
|
||||
if (isset($condition['id_employee'])) {
|
||||
$where .= ' AND id_employee='.(int)$condition['id_employee'].'
|
||||
AND (author_name = "" OR author_name is null)';
|
||||
} else {
|
||||
$where .= ' AND author_name LIKE "%'.pSQL($condition['author_name']).'%"';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
$tmp = explode(',', $condition['tag']);
|
||||
|
||||
if (!empty($tmp) && count($tmp) > 1) {
|
||||
$t = array();
|
||||
foreach ($tmp as $tag) {
|
||||
// validate module
|
||||
$t[] = 'sl.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
}
|
||||
$where .= ' AND '.implode(' OR ', $t).' ';
|
||||
} else {
|
||||
// validate module
|
||||
$where .= ' AND sl.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
}
|
||||
break;
|
||||
case 'samecat':
|
||||
$where .= ' AND c.id_anblog_blog!='.(int)$condition['id_anblog_blog'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'anblog_blog` c
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'anblog_blog_lang` sl
|
||||
ON (c.`id_anblog_blog` = sl.`id_anblog_blog`
|
||||
AND sl.`id_lang` = ' . (int) $id_lang . '),
|
||||
`'._DB_PREFIX_.'anblog_blog_categories` abc
|
||||
';
|
||||
|
||||
$query .= 'WHERE c.`id_anblog_blog`=abc.`id_anblog_blog` '.$where.' ';
|
||||
|
||||
if ($id_shop) {
|
||||
$query .= ' AND c.`id_anblog_blog` IN (
|
||||
SELECT hs.`id_anblog_blog`
|
||||
FROM `' . _DB_PREFIX_ . 'anblog_blog_shop` hs
|
||||
WHERE hs.`id_shop`='.(int) $id_shop.')
|
||||
';
|
||||
}
|
||||
|
||||
$query .= ' GROUP BY c.id_anblog_blog
|
||||
|
||||
';
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return count($data);
|
||||
}
|
||||
|
||||
// public static function countBlogs($id_category, $id_lang, $condition = array(), $is_active = false, $id_shop = null)
|
||||
// {
|
||||
// if (!$id_shop) {
|
||||
// $context = Context::getContext();
|
||||
// $id_shop = $context->shop->id;
|
||||
// }
|
||||
// $where = '';
|
||||
// if ($id_category) {
|
||||
// // validate module
|
||||
// $where .= ' AND c.id_anblogcat='.(int)$id_category;
|
||||
// }
|
||||
// if ($is_active) {
|
||||
// // validate module
|
||||
// $where .= ' AND c.active=1';
|
||||
// }
|
||||
// if ($id_shop) {
|
||||
// // validate module
|
||||
// $where .= ' AND s.id_shop='.(int)$id_shop;
|
||||
// }
|
||||
// if (isset($condition['type'])) {
|
||||
// switch ($condition['type']) {
|
||||
// case 'author':
|
||||
// if (isset($condition['id_employee'])) {
|
||||
// $where .= ' AND id_employee='.(int)$condition['id_employee'].'
|
||||
// AND (author_name = "" OR author_name is null)';
|
||||
// } else {
|
||||
// $where .= ' AND author_name LIKE "%'.pSQL($condition['author_name']).'%"';
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case 'tag':
|
||||
// $tmp = explode(',', $condition['tag']);
|
||||
|
||||
// if (!empty($tmp) && count($tmp) > 1) {
|
||||
// $t = array();
|
||||
// foreach ($tmp as $tag) {
|
||||
// // validate module
|
||||
// $t[] = 'l.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
// }
|
||||
// $where .= ' AND '.implode(' OR ', $t).' ';
|
||||
// } else {
|
||||
// // validate module
|
||||
// $where .= ' AND l.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
// }
|
||||
// break;
|
||||
// case 'samecat':
|
||||
// $where .= ' AND c.id_anblog_blog!='.(int)$condition['id_anblog_blog'];
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// $query = '
|
||||
// SELECT c.id_anblog_blog
|
||||
// FROM '._DB_PREFIX_.'anblog_blog c
|
||||
// LEFT JOIN '._DB_PREFIX_.'anblog_blog_lang l
|
||||
// ON (c.id_anblog_blog = l.id_anblog_blog) and l.id_lang='.(int)$id_lang
|
||||
// .' LEFT JOIN '._DB_PREFIX_.'anblog_blog_shop s ON (c.id_anblog_blog = s.id_anblog_blog) '
|
||||
// .' LEFT JOIN '._DB_PREFIX_.'anblog_blog_categories abc ON abc.id_anblog_blog = c.id_anblog_blog '
|
||||
// .' LEFT JOIN '._DB_PREFIX_.'anblogcat bc ON bc.id_anblogcat = abc.id_anblogcat '
|
||||
// .' LEFT JOIN '._DB_PREFIX_.'anblogcat_lang blc
|
||||
// ON blc.id_anblogcat=bc.id_anblogcat and blc.id_lang='.(int)$id_lang
|
||||
// .'
|
||||
// WHERE l.id_lang = '.(int)$id_lang.$where.'
|
||||
// GROUP BY c.id_anblog_blog
|
||||
// ';
|
||||
|
||||
// $data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
// return count($data);
|
||||
// }
|
||||
|
||||
public static function listblog($id_lang = null, $id_block = false, $active = true, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'
|
||||
SELECT c.id_anblog_blog, l.meta_title
|
||||
FROM '._DB_PREFIX_.'blog c
|
||||
JOIN '._DB_PREFIX_.'blog_lang l ON (c.id_anblog_blog = l.id_anblog_blog)
|
||||
JOIN '._DB_PREFIX_.'anblog_blog_lang s ON (c.id_anblog_blog = s.id_anblog_blog)
|
||||
'.Shop::addSqlAssociation('blog', 'c').'
|
||||
'.(($id_block) ? 'JOIN '._DB_PREFIX_.'block_blog b ON (c.id_anblog_blog = b.id_anblog_blog)' : '').'
|
||||
WHERE s.id_shop = '.(int)$id_shop.'
|
||||
AND l.id_lang = '.(int)$id_lang.
|
||||
(($id_block) ? ' AND b.id_block = '.(int)$id_block : '').
|
||||
($active ? ' AND c.`active` = 1 ' : '').'
|
||||
GROUP BY c.id_anblog_blog
|
||||
ORDER BY c.`position`'
|
||||
);
|
||||
}
|
||||
|
||||
public function updatePosition($way, $position)
|
||||
{
|
||||
$sql = 'SELECT abc.`id_anblog_blog`, abc.`position`, abc.`id_anblogcat`
|
||||
FROM `'._DB_PREFIX_.'blog` cp
|
||||
LEFT JOIN '._DB_PREFIX_.'anblog_blog_categories abc ON abc.id_anblog_blog = cp.id_anblog_blog
|
||||
WHERE abc.`id_anblogcat` = '.(int)$this->id_anblogcat.'
|
||||
ORDER BY abc.`position` ASC';
|
||||
if (!$res = Db::getInstance()->executeS($sql)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($res as $blog) {
|
||||
if ((int)$blog['id_anblog_blog'] == (int)$this->id) {
|
||||
$moved_blog = $blog;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($moved_blog) || !isset($position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
return (Db::getInstance()->execute(
|
||||
'
|
||||
UPDATE `'._DB_PREFIX_.'anblog_blog_categories`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way ? '> '.(int)$moved_blog['position'].'
|
||||
AND `position` <= '.(int)$position : '< '.(int)$moved_blog['position'].'
|
||||
AND `position` >= '.(int)$position).'
|
||||
AND `id_anblogcat`='.(int)$moved_blog['id_anblogcat']
|
||||
) && Db::getInstance()->execute(
|
||||
'
|
||||
UPDATE `'._DB_PREFIX_.'anblog_blog_categories`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_anblog_blog` = '.(int)$moved_blog['id_anblog_blog'].'
|
||||
AND `id_anblogcat`='.(int)$moved_blog['id_anblogcat']
|
||||
));
|
||||
}
|
||||
|
||||
public static function cleanPositions($id_category)
|
||||
{
|
||||
$sql = '
|
||||
SELECT `id_anblog_blog`
|
||||
FROM `'._DB_PREFIX_.'anblog_blog_categories`
|
||||
WHERE `id_anblogcat` = '.(int)$id_category.'
|
||||
ORDER BY `position`';
|
||||
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
|
||||
for ($i = 0, $total = count($result); $i < $total; ++$i) {
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'anblog_blog_categories`
|
||||
SET `position` = '.(int)$i.'
|
||||
WHERE `id_anblogcat` = '.(int)$id_category.'
|
||||
AND `id_anblog_blog` = '.(int)$result[$i]['id_anblog_blog'];
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getLastPosition($id_category)
|
||||
{
|
||||
$sql = '
|
||||
SELECT MAX(position) + 1
|
||||
FROM `'._DB_PREFIX_.'anblog_blog_categories`
|
||||
WHERE `id_anblogcat` = '.(int)$id_category;
|
||||
return (Db::getInstance()->getValue($sql));
|
||||
}
|
||||
|
||||
public static function getblogPages($id_lang = null, $id_anblogcat = null, $active = true, $id_shop = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('blog', 'c');
|
||||
if ($id_lang) {
|
||||
$sql->innerJoin(
|
||||
'blog_lang',
|
||||
'l',
|
||||
'c.id_anblog_blog = l.id_anblog_blog AND l.id_lang = '.(int)$id_lang
|
||||
);
|
||||
}
|
||||
|
||||
if ($id_shop) {
|
||||
$sql->innerJoin(
|
||||
'blog_shop',
|
||||
'cs',
|
||||
'c.id_anblog_blog = cs.id_anblog_blog AND cs.id_shop = '.(int)$id_shop
|
||||
);
|
||||
}
|
||||
|
||||
if ($active) {
|
||||
$sql->where('c.active = 1');
|
||||
}
|
||||
|
||||
if ($id_anblogcat) {
|
||||
$sql->innerJoin(
|
||||
'blog_category',
|
||||
'bc',
|
||||
'c.id_anblog_blog = bc.id_anblog_blog'
|
||||
);
|
||||
$sql->where('bc.id_anblogcat = '.(int)$id_anblogcat);
|
||||
}
|
||||
|
||||
$sql->orderBy('position');
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public static function getUrlRewriteInformations($id_anblog_blog)
|
||||
{
|
||||
$sql = 'SELECT l.`id_lang`, c.`link_rewrite`
|
||||
FROM `'._DB_PREFIX_.'anblog_blog_lang` AS c
|
||||
LEFT JOIN `'._DB_PREFIX_.'lang` AS l ON c.`id_lang` = l.`id_lang`
|
||||
WHERE c.`id_anblog_blog` = '.(int)$id_anblog_blog.'
|
||||
AND l.`active` = 1';
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is build for module ApPageBuilder, most logic query Sqlis clone from function getListBlog.
|
||||
*
|
||||
* @param Int $id_category ( default '' )
|
||||
* @param Int $nb_blog ( default 10 )
|
||||
* @param Array $condition ( default array )
|
||||
* @param Boolean $is_active ( default false )
|
||||
*/
|
||||
public static function getListBlogsForApPageBuilder($id_category, $id_lang, $nb_blog, $order_by, $order_way, $condition, $is_active, $id_shop = null)
|
||||
{
|
||||
// module validation
|
||||
!is_null($id_category) ? true : $id_category = '';
|
||||
!is_null($nb_blog) ? true : $nb_blog = 10;
|
||||
is_array($condition) ? true : $condition = array();
|
||||
!is_null($is_active) ? true : $is_active = false;
|
||||
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
if ($nb_blog < 1) {
|
||||
$nb_blog = 10;
|
||||
}
|
||||
if (empty($order_by) || $order_by == 'position') {
|
||||
$order_by = 'date_add';
|
||||
}
|
||||
if (empty($order_way)) {
|
||||
$order_way = 'DESC';
|
||||
}
|
||||
if ($order_by == 'id_anblog_blog' || $order_by == 'date_add' || $order_by == 'date_upd' || $order_by == 'title') {
|
||||
$order_by_prefix = 'c';
|
||||
}
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
$where = '';
|
||||
if ($id_category) {
|
||||
$where .= ' AND abc.id_anblogcat IN('.$id_category.') ';
|
||||
}
|
||||
if ($id_shop) {
|
||||
$where .= ' AND s.id_shop='.(int)$id_shop;
|
||||
}
|
||||
if (isset($condition['type'])) {
|
||||
switch ($condition['type']) {
|
||||
case 'author':
|
||||
$where .= ' AND id_employee='.(int)$condition['id_employee'];
|
||||
break;
|
||||
case 'tag':
|
||||
$tmp = explode(',', $condition['tag']);
|
||||
if (!empty($tmp) && count($tmp) > 1) {
|
||||
$t = array(); // validate module
|
||||
foreach ($tmp as $tag) {
|
||||
$t[] = 'l.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
}
|
||||
$where .= ' AND '.implode(' OR ', $t).' ';
|
||||
} else {
|
||||
$where .= ' AND l.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
}
|
||||
break;
|
||||
case 'samecat':
|
||||
$where .= ' AND c.id_anblog_blog!='.(int)$condition['id_anblog_blog'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($is_active) {
|
||||
$where .= ' AND c.active=1';
|
||||
}
|
||||
$query = '
|
||||
SELECT c.*, l.*, l.meta_title as title, blc.link_rewrite as category_link_rewrite , blc.title as category_title
|
||||
FROM '._DB_PREFIX_.'anblog_blog c
|
||||
LEFT JOIN '._DB_PREFIX_.'anblog_blog_lang l
|
||||
ON (c.id_anblog_blog = l.id_anblog_blog) and l.id_lang='.(int)$id_lang
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblog_blog_shop s ON (c.id_anblog_blog = s.id_anblog_blog) '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblog_blog_categories abc ON (c.id_anblog_blog = abc.id_anblog_blog) '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblogcat bc ON bc.id_anblogcat = abc.id_anblogcat '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'anblogcat_lang blc
|
||||
ON blc.id_anblogcat=bc.id_anblogcat and blc.id_lang='.(int)$id_lang
|
||||
.' '.Shop::addSqlAssociation('blog', 'c').'
|
||||
WHERE l.id_lang = '.(int)$id_lang.$where.'
|
||||
GROUP BY c.id_anblog_blog ';
|
||||
|
||||
if ($order_way == 'random') {
|
||||
$query .= 'ORDER BY rand() LIMIT 0, '.(int)$nb_blog;
|
||||
} else {
|
||||
$query .= 'ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '')
|
||||
.pSQL($order_by).' '.pSQL($order_way).' LIMIT 0, '.(int)$nb_blog;
|
||||
}
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id_lang
|
||||
* @return array
|
||||
*/
|
||||
public function getProductsAutocompleteInfo($id_lang = null)
|
||||
{
|
||||
$id_lang = is_null($id_lang) ? Context::getContext()->language->id : $id_lang;
|
||||
|
||||
$products = array();
|
||||
|
||||
if (!empty($this->products)) {
|
||||
$rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT p.`id_product`, p.`reference`, pl.name
|
||||
FROM `' . _DB_PREFIX_ . 'product` p
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = ' .
|
||||
(int)$id_lang . ')
|
||||
WHERE p.`id_product` IN (' . implode(',', array_map('intval', $this->products)) . ')'
|
||||
);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$products[$row['id_product']] = trim($row['name']) . (!empty($row['reference']) ?
|
||||
' (ref: ' . $row['reference'] . ')' : '');
|
||||
}
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $array_product_id
|
||||
* @param null $id_lang
|
||||
* @return bool
|
||||
*/
|
||||
public static function getProductsByArrayId($array_product_id = null, $id_lang = null)
|
||||
{
|
||||
if (empty($array_product_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$context = Context::getContext();
|
||||
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select(
|
||||
'p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`,
|
||||
pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`,
|
||||
pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`,
|
||||
m.`name` AS manufacturer_name,
|
||||
DATEDIFF(
|
||||
product_shop.`date_add`,
|
||||
DATE_SUB(
|
||||
NOW(),
|
||||
INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ?
|
||||
Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY
|
||||
)
|
||||
) > 0 AS new'
|
||||
);
|
||||
|
||||
$sql->from('product', 'p');
|
||||
$sql->join(Shop::addSqlAssociation('product', 'p'));
|
||||
$sql->leftJoin('product_lang', 'pl', 'p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int)$id_lang . Shop::addSqlRestrictionOnLang('pl'));
|
||||
$sql->leftJoin('image', 'i', 'i.`id_product` = p.`id_product`');
|
||||
$sql->join(Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1'));
|
||||
$sql->leftJoin('image_lang', 'il', 'i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int)$id_lang);
|
||||
$sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
|
||||
|
||||
$sql->where('p.`id_product` IN (' . implode(',', array_map('intval', $array_product_id)) . ')');
|
||||
|
||||
$sql->groupBy('product_shop.id_product');
|
||||
|
||||
if (Combination::isFeatureActive()) {
|
||||
$sql->select('MAX(product_attribute_shop.id_product_attribute) id_product_attribute');
|
||||
$sql->leftOuterJoin('product_attribute', 'pa', 'p.`id_product` = pa.`id_product`');
|
||||
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1'));
|
||||
}
|
||||
$sql->join(Product::sqlStock('p', Combination::isFeatureActive() ? 'product_attribute_shop' : 0));
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Product::getProductsProperties((int)$id_lang, $result);
|
||||
}
|
||||
}
|
||||
146
modules/anblog/classes/comment.php
Normal file
146
modules/anblog/classes/comment.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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 AnblogComment extends ObjectModel
|
||||
{
|
||||
/**
|
||||
* @var string Name
|
||||
*/
|
||||
public $user;
|
||||
public $comment;
|
||||
public $active;
|
||||
public $id_anblog_blog;
|
||||
public $date_add;
|
||||
public $email;
|
||||
public $id_shop;
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'anblog_comment',
|
||||
'primary' => 'id_anblog_comment',
|
||||
'fields' => array(
|
||||
'id_anblog_blog' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'user' => array('type' => self::TYPE_STRING, 'required' => false),
|
||||
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128, 'required' => true),
|
||||
'comment' => array('type' => self::TYPE_STRING, 'required' => true),
|
||||
'active' => array('type' => self::TYPE_BOOL),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => false)
|
||||
),
|
||||
);
|
||||
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$this->id_shop = AnblogHelper::getIDShop();
|
||||
return parent::add($autodate, $null_values);
|
||||
}
|
||||
|
||||
public static function countComments($id_anblog_blog = 0, $is_active = false, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
$query = ' SELECT count(id_anblog_comment) as total FROM '._DB_PREFIX_.'anblog_comment WHERE 1=1 ';
|
||||
|
||||
if ($id_anblog_blog > 0) {
|
||||
// validate module
|
||||
$query .= ' AND id_anblog_blog='.(int)$id_anblog_blog;
|
||||
}
|
||||
if ($is_active) {
|
||||
// validate module
|
||||
$query .= ' AND active=1 ';
|
||||
}
|
||||
if ($id_shop) {
|
||||
$query .= ' AND id_shop='.(int)$id_shop;
|
||||
}
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
return $data[0]['total'];
|
||||
}
|
||||
|
||||
public static function getComments($id_anblog_blog, $limit, $id_lang, $order = null, $by = null, $id_shop = null)
|
||||
{
|
||||
// validate module
|
||||
!is_null($limit) ? true : $limit = 10;
|
||||
unset($id_anblog_blog);
|
||||
unset($order);
|
||||
unset($by);
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
$query = ' SELECT c.*, b.meta_title FROM '._DB_PREFIX_.'anblog_comment c';
|
||||
$query .= ' LEFT JOIN '._DB_PREFIX_.'anblog_blog_lang b ON c.id_anblog_blog=b.id_anblog_blog';
|
||||
$query .= ' AND b.id_lang='.(int)$id_lang.' WHERE id_shop='.(int)$id_shop;
|
||||
$query .= ' LIMIT '.$limit;
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getList($id_anblog_blog, $id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
|
||||
if ($page_number < 1) {
|
||||
$page_number = 1;
|
||||
}
|
||||
|
||||
if ($nb_products < 1) {
|
||||
$nb_products = 10;
|
||||
}
|
||||
if (empty($order_by) || $order_by == 'position') {
|
||||
$order_by = 'date_add';
|
||||
}
|
||||
if (empty($order_way)) {
|
||||
$order_way = 'DESC';
|
||||
}
|
||||
if ($order_by == 'id_anblog_blog' || $order_by == 'date_add' || $order_by == 'date_upd' || $order_by == 'title') {
|
||||
$order_by_prefix = 'c';
|
||||
}
|
||||
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
|
||||
$query = ' SELECT c.* FROM '._DB_PREFIX_.'anblog_comment c';
|
||||
$query .= ' WHERE 1=1 AND id_shop='.(int)$id_shop;
|
||||
|
||||
$query .= ' AND active=1 AND id_anblog_blog='.(int)$id_anblog_blog;
|
||||
$query .= ' ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '')
|
||||
.pSQL($order_by).' '.pSQL($order_way).' LIMIT '.(($page_number - 1) * $nb_products).', '.(int)$nb_products;
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
98
modules/anblog/classes/config.php
Normal file
98
modules/anblog/classes/config.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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 AnblogConfig
|
||||
{
|
||||
public $params;
|
||||
public $cat_image_dir = '';
|
||||
/**
|
||||
* @var int id_lang current language in for, while
|
||||
*/
|
||||
public $cur_id_lang = '';
|
||||
/**
|
||||
* @var int id_lang current language in for, while
|
||||
*/
|
||||
public $cur_prefix_rewrite = '';
|
||||
const CACHE_HOOK_ID = 'anblogHooks';
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
static $instance;
|
||||
if (!$instance) {
|
||||
// validate module
|
||||
$instance = new AnblogConfig();
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
|
||||
$defaultSettings = include _PS_MODULE_DIR_ . 'anblog/config.php';
|
||||
|
||||
$valuesWithLang = ['blog_link_title', 'meta_title', 'meta_description', 'meta_keywords', 'category_rewrite', 'detail_rewrite'];
|
||||
|
||||
$allConfig = [];
|
||||
|
||||
foreach ($defaultSettings as $key => $value) {
|
||||
if (in_array($key, $valuesWithLang)) {
|
||||
$allConfig[$key] = Configuration::get('an_bl_' . $key , Context::getContext()->language->id, $value);
|
||||
} else {
|
||||
$allConfig[$key] = Configuration::get('an_bl_' . $key , null, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->params = $allConfig;
|
||||
}
|
||||
|
||||
public function mergeParams($params)
|
||||
{
|
||||
// validate module
|
||||
unset($params);
|
||||
}
|
||||
|
||||
public function setVar($key, $value)
|
||||
{
|
||||
$this->params[$key] = $value;
|
||||
}
|
||||
|
||||
public function get($name, $value = '')
|
||||
{
|
||||
if (isset($this->params[$name])) {
|
||||
// validate module
|
||||
return $this->params[$name];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function getConfigName($name)
|
||||
{
|
||||
return Tools::strtoupper(_AN_BLOG_PREFIX_.$name);
|
||||
}
|
||||
|
||||
public static function updateConfigValue($name, $value = '')
|
||||
{
|
||||
Configuration::updateValue(self::getConfigName($name), $value, true);
|
||||
}
|
||||
|
||||
public static function getConfigValue($name)
|
||||
{
|
||||
return Configuration::get(self::getConfigName($name));
|
||||
}
|
||||
|
||||
}
|
||||
0
modules/anblog/classes/index.php
Normal file
0
modules/anblog/classes/index.php
Normal file
133
modules/anblog/classes/link.php
Normal file
133
modules/anblog/classes/link.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?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 AnblogLink extends Link
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a link to a module
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $module Module name
|
||||
* @param string $process Action name
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
* Get link of ROOT_BLOG "Show All"
|
||||
*/
|
||||
public function getLink($route_id, $controller = 'default', array $params = array(), $ssl = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
// validate module
|
||||
unset($controller);
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
$url = $this->getBaseLink($id_shop, $ssl).$this->getLangLink($id_lang, null, $id_shop);
|
||||
return $url.Dispatcher::getInstance()->createUrl($route_id, $id_lang, $params, $this->allow, '', $id_shop);
|
||||
}
|
||||
|
||||
public function getAnblogLink($id_object, $controller, $params = array())
|
||||
{
|
||||
return $this->getLink($id_object, $controller, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pagination link
|
||||
*
|
||||
* @param string $type Controller name
|
||||
* @param int $id_object
|
||||
* @param boolean $nb Show nb element per page attribute
|
||||
* @param boolean $sort Show sort attribute
|
||||
* @param boolean $pagination Show page number attribute
|
||||
* @param boolean $array If false return an url, if true return an array
|
||||
*/
|
||||
public function getANPaginationLink($type, $id_object, $controller, $params, $nb = false, $sort = false, $pagination = false, $array = true)
|
||||
{
|
||||
// If no parameter $type, try to get it by using the controller name
|
||||
if (!$type && !$id_object) {
|
||||
$method_name = 'get'.Dispatcher::getInstance()->getController().'Link';
|
||||
if (method_exists($this, $method_name) && Tools::getIsset(Tools::getValue('id_'.Dispatcher::getInstance()->getController()))) {
|
||||
$type = Dispatcher::getInstance()->getController();
|
||||
$id_object = Tools::getValue('id_'.$type);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type && $id_object) {
|
||||
$url = $this->{'get'.$type.'Link'}($id_object, $controller, $params);
|
||||
} else {
|
||||
if (isset(Context::getContext()->controller->php_self)) {
|
||||
$name = Context::getContext()->controller->php_self;
|
||||
} else {
|
||||
$name = Dispatcher::getInstance()->getController();
|
||||
}
|
||||
$url = $this->getPageLink($name);
|
||||
}
|
||||
|
||||
$vars = array();
|
||||
$vars_nb = array('n', 'search_query');
|
||||
$vars_sort = array('orderby', 'orderway');
|
||||
$vars_pagination = array('p');
|
||||
|
||||
$get = array();
|
||||
$get['isolang'] = Tools::getValue('isolang');
|
||||
$get['id_lang'] = Tools::getValue('id_lang');
|
||||
$get['id'] = Tools::getValue('id');
|
||||
$get['fc'] = Tools::getValue('fc');
|
||||
$get['module'] = Tools::getValue('module');
|
||||
$get['controller'] = Tools::getValue('controller');
|
||||
|
||||
foreach ($get as $k => $value) {
|
||||
if ($k != 'id_'.$type && $k != 'controller') {
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS') && ($k == 'isolang' || $k == 'id_lang')) {
|
||||
continue;
|
||||
}
|
||||
$if_nb = (!$nb || ($nb && !in_array($k, $vars_nb)));
|
||||
$if_sort = (!$sort || ($sort && !in_array($k, $vars_sort)));
|
||||
$if_pagination = (!$pagination || ($pagination && !in_array($k, $vars_pagination)));
|
||||
if ($if_nb && $if_sort && $if_pagination) {
|
||||
if (!is_array($value)) {
|
||||
$vars[urlencode($k)] = $value;
|
||||
} else {
|
||||
foreach (explode('&', http_build_query(array($k => $value), '', '&')) as $val) {
|
||||
$data = explode('=', $val);
|
||||
$vars[urldecode($data[0])] = $data[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$array) {
|
||||
if (count($vars)) {
|
||||
return $url.(($this->allow == 1 || $url == $this->url) ? '?' : '&').http_build_query($vars, '', '&');
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
$vars['requestUrl'] = $url;
|
||||
|
||||
if ($type && $id_object) {
|
||||
$vars['id_'.$type] = (is_object($id_object) ? (int)$id_object->id : (int)$id_object);
|
||||
}
|
||||
|
||||
if (!$this->allow == 1) {
|
||||
$vars['controller'] = Dispatcher::getInstance()->getController();
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
}
|
||||
128
modules/anblog/classes/sitemap.php
Normal file
128
modules/anblog/classes/sitemap.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user