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,62 @@
<?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)
*/
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts;
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminAnblogAjaxController extends ModuleAdminController
{
public function initContent()
{
$result = [];
if (Tools::isSubmit('action')) {
$actionName = Tools::getValue('action', '') . 'Action';
if (method_exists($this, $actionName)) {
$result = $this->$actionName();
}
}
die(json_encode($result));
}
public function searchProductsAction()
{
// $defaultCurrencyId = (int) $this->get('prestashop.adapter.legacy.configuration')->get('PS_CURRENCY_DEFAULT');
//$searchPhrase = $request->query->get('search_phrase');
$searchPhrase = Tools::getValue('q');
if (!$searchPhrase){
return [];
}
$foundProducts = Product::searchByName((int) $this->context->language->id, pSQL($searchPhrase));
if (!$foundProducts){
return [];
}
$products = [];
foreach ($foundProducts as $fProduct){
$products[] = [
'id' => $fProduct['id_product'],
'name' => $fProduct['name']
];
}
return $products;
}
}

View File

@@ -0,0 +1,718 @@
<?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 AdminAnblogBlogsController extends ModuleAdminController
{
protected $max_image_size;
protected $position_identifier = 'id_anblog_blog';
public function __construct()
{
parent::__construct();
$this->bootstrap = true;
$this->table = 'anblog_blog';
//$this->list_id = 'id_anblog_blog'; // must be set same value $this->table to delete multi rows
$this->identifier = 'id_anblog_blog';
$this->className = 'AnblogBlog';
$this->lang = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->bulk_actions = array(
'delete' => array('text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'),
'icon' => 'icon-trash')
);
$this->fields_list = array(
'id_anblog_blog' => array(
'title' => $this->l('ID'),
'align' => 'center',
'class' => 'fixed-width-xs'
),
'image' => array(
'title' => $this->l('Image'),
'width' => 25,
'search' => false,
'type' => 'image',
),
// 'image' => array('title' => $this->l('Image')),
'meta_title' => array('title' => $this->l('Title'), 'filter_key' => 'b!meta_title'),
'author_name' => array('title' => $this->l('Author'), 'filter_key' => 'a!author_name'),
'title' => array('title' => $this->l('Category'), 'filter_key' => 'cl!title'),
'hits' => array(
'title' => $this->l('Views'),
'filter_key' => 'a!hits'
),
'likes' => array(
'title' => $this->l('Likes'),
),
'active' => array(
'title' => $this->l('Status'),
'align' => 'center',
'active' => 'status',
'class' => 'fixed-width-sm',
'type' => 'bool',
'orderby' => true
),
'date_add' => array(
'title' => $this->l('Date Create'),
'type' => 'datetime',
'filter_key' => 'a!date_add'
),
);
$this->max_image_size = Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
$this->_select .= ' cl.title ';
$this->_join .= ' LEFT JOIN '._DB_PREFIX_.'anblog_blog_categories abc ON a.id_anblog_blog = abc.id_anblog_blog
LEFT JOIN '._DB_PREFIX_.'anblogcat c ON abc.id_anblogcat = c.id_anblogcat
LEFT JOIN '._DB_PREFIX_.'anblogcat_lang cl ON cl.id_anblogcat=c.id_anblogcat
AND cl.id_lang=b.id_lang
';
if (Shop::getContext() == Shop::CONTEXT_SHOP) {
$this->_join .= ' INNER JOIN `'._DB_PREFIX_.'anblog_blog_shop` sh
ON (sh.`id_anblog_blog` = b.`id_anblog_blog` AND sh.id_shop = '.(int)Context::getContext()->shop->id.') ';
}
$this->_where = '';
$this->_group = ' GROUP BY (a.id_anblog_blog) ';
$this->_orderBy = 'a.id_anblog_blog';
$this->_orderWay = 'DESC';
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
foreach ($this->_list as &$list) {
if ($list['image'] !='' && Tools::file_exists_no_cache( _ANBLOG_BLOG_IMG_DIR_.'b/'. $list['image'])) {
$list['image'] = _ANBLOG_BLOG_IMG_URI_.'/b/'. $list['image'];
} else {
$list['image'] = '';
}
}
}
public function initHeader()
{
parent::initHeader();
$tabs = &$this->context->smarty->tpl_vars['tabs']->value;
$tabs = $this->module->createAdminTabs($tabs, $this->controller_name);
}
public function initContent()
{
$this->context->smarty->assign('current_tab_level', 3);
return parent::initContent();
}
public function initPageHeaderToolbar()
{
if (empty($this->display)) {
$this->page_header_toolbar_btn['add_field'] = array(
'href' => self::$currentIndex . '&addanblog_blog&token=' . $this->token,
'desc' => $this->trans('Add new', array(), 'Admin.Actions'),
'icon' => 'process-icon-new',
);
}
if (empty($this->display)) {
$this->page_header_toolbar_btn['open_the_blog'] = array(
'href' => AnblogHelper::getInstance()->getFontBlogLink(),
'desc' => $this->trans('View my blog', [], 'Admin.Actions'),
'icon' => 'icon-book',
'target' => '_blank'
);
}
if (Tools::getValue('id_anblog_blog')) {
$helper = AnblogHelper::getInstance();
$blog_obj = new AnblogBlog(Tools::getValue('id_anblog_blog'), $this->context->language->id);
$this->page_header_toolbar_btn['view-blog-preview'] = array(
'href' => $helper->getBlogLink(get_object_vars($blog_obj)),
'desc' => $this->l('View Post'),
'icon' => 'icon-preview anblog-comment-link-icon icon-3x process-icon-preview',
'target' => '_blank',
);
$this->page_header_toolbar_btn['view-blog-comment'] = array(
'href' => $this->context->link->getAdminLink('AdminAnblogComments').'&id_anblog_blog='.Tools::getValue('id_anblog_blog'),
'desc' => $this->l('Manage Comments'),
'icon' => 'icon-comment anblog-comment-link-icon icon-3x process-icon-comment',
'target' => '_blank',
);
}
return parent::initPageHeaderToolbar();
}
public function renderForm()
{
if (!$this->loadObject(true)) {
if (Validate::isLoadedObject($this->object)) {
$this->display = 'edit';
} else {
$this->display = 'add';
}
}
$this->initToolbar();
$this->initPageHeaderToolbar();
$id_anblogcat = (int)(Tools::getValue('id_anblogcat'));
$obj = new anblogcat($id_anblogcat);
$obj->getTree();
$menus = $obj->getDropdown(null, $obj->id_parent, false);
array_shift($menus);
$url = _PS_BASE_URL_;
if (Tools::usingSecureMode()) {
// validate module
$url = _PS_BASE_URL_SSL_;
}
if ($this->object->image) {
$thumb = $url._ANBLOG_BLOG_IMG_URI_.'b/'.$this->object->image;
} else {
$thumb = '';
}
//DONGND:: add default author name is name of current admin
$default_author_name = '';
if (isset($this->context->employee->firstname) && isset($this->context->employee->lastname)) {
$default_author_name = $this->context->employee->firstname.' '.$this->context->employee->lastname;
}
if ($this->object->id == '') {
$this->object->author_name = $default_author_name;
}
$this->multiple_fieldsets = true;
$input = array(
array(
'type' => 'select',
'label' => $this->l('Category'),
'name' => 'categories[]',
'options' => array('query' => $menus,
'id' => 'id',
'name' => 'title'),
'default' => $id_anblogcat,
'multiple' => true,
),
array(
'type' => 'text',
'label' => $this->l('Meta title'),
'name' => 'meta_title',
'id' => 'name', // for copyMeta2friendlyURL compatibility
'lang' => true,
'required' => true,
'class' => 'copyMeta2friendlyURL',
'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
),
array(
'type' => 'text',
'label' => $this->l('Friendly URL'),
'name' => 'link_rewrite',
'required' => true,
'lang' => true,
'hint' => $this->l('Only letters and the minus (-) character are allowed')
),
array(
'type' => 'tags',
'label' => $this->l('Tags'),
'name' => 'tags',
'lang' => true,
'hint' => array(
$this->l('Invalid characters:').' &lt;&gt;;=#{}',
$this->l('To add "tags" click in the field, write something, and then press "Enter."')
)
),
array(
'type' => 'hidden',
'label' => $this->l('Image Name'),
'name' => 'image',
),
array(
'type' => 'file',
'label' => $this->l('Image'),
'name' => 'image_link',
'display_image' => true,
'default' => '',
'desc' => $this->l('Max file size is: ').($this->max_image_size/1024/1024). 'MB',
'thumb' => $thumb,
'class' => 'anblog_image_upload',
),
array(
'type' => 'hidden',
'label' => $this->l('Thumb Name'),
'name' => 'thumb',
),
array(
'type' => 'textarea',
'label' => $this->l('Description'),
'name' => 'description',
'autoload_rte' => true,
'lang' => true,
'rows' => 5,
'cols' => 30,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
array(
'type' => 'textarea',
'label' => $this->l('Content'),
'name' => 'content',
'autoload_rte' => true,
'lang' => true,
'rows' => 5,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
array(
'type' => 'text',
'label' => $this->l('Author'),
'name' => 'author_name',
'desc' => $this->l('Author is displayed in the front-end')
),
array(
'type' => 'date_anblog',
'label' => $this->l('Date'),
'name' => 'date_add',
'default' => date('Y-m-d H:i:s'),
),
array(
'type' => 'switch',
'label' => $this->l('Indexation (by search engines):'),
'name' => 'indexation',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'indexation_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'indexation_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'product_autocomplete',
'label' => $this->l('Select the Products'),
'name' => 'products',
'ajax_path' => self::$currentIndex . '&ajax=1&action=ProductsList&token=' . Tools::getAdminTokenLite('AdminAnblogBlogs'),
'hint' => $this->l('Begin typing the First Letters of the Product Name, then select the Product from the Drop-down List.'),
'form_group_class' => 'content_type_product',
),
array(
'type' => 'switch',
'label' => $this->l('Displayed:'),
'name' => 'active',
'required' => false,
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
);
if (Shop::isFeatureActive()) {
$shopsQuery = array();
foreach (Shop::getShops(false) as $shop) {
$shopsQuery[] = array('name' => $shop['id_shop'], 'title' => $shop['domain'] . $shop['uri']);
}
$input[] = array(
'type' => 'select',
'name' => 'shops[]',
'label' => $this->l('Shops:'),
'id' => 'shops',
'multiple' => true,
'required' => true,
'options' => array(
'query' => $shopsQuery,
'id' => 'name',
'name' => 'title',
),
);
}
$this->fields_form[0]['form'] = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Post'),
'icon' => 'icon-folder-close'
),
'input' => $input,
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
),
'buttons' => array(
'save_and_preview' => array(
'name' => 'saveandstay',
'type' => 'submit',
'title' => $this->l('Save and stay'),
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-save-and-stay'
)
)
);
$this->fields_form[1]['form'] = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('SEO'),
'icon' => 'icon-folder-close'
),
'input' => array(
// custom template
array(
'type' => 'textarea',
'label' => $this->l('Meta description'),
'name' => 'meta_description',
'lang' => true,
'cols' => 40,
'rows' => 10,
'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
),
array(
'type' => 'tags',
'label' => $this->l('Meta keywords'),
'name' => 'meta_keywords',
'lang' => true,
'hint' => $this->l('Invalid characters:') . ' &lt;&gt;;=#{}',
'desc' => array(
$this->l('To add a keyword, enter the keyword and then press "Enter"')
)
),
)
);
if (!is_null($this->object->id)) {
$this->fields_value['categories[]'] = $this->object->categories;
}
$this->fields_value['products'] = $this->object->getProductsAutocompleteInfo($this->context->language->id);
$this->tpl_form_vars = array(
'active' => $this->object->active,
'PS_ALLOW_ACCENTED_CHARS_URL', (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL')
);
$this->context->smarty->assign(
array(
'PS_ALLOW_ACCENTED_CHARS_URL' => (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'),
'anblog_del_img_txt' => $this->l('Delete'),
'anblog_del_img_mess' => $this->l('Are you sure delete this?'),
)
);
$html = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'anblog/views/templates/admin/prerender/additionaljs.tpl');
return $html . parent::renderForm();
}
/**
* Get product list
*/
protected function ajaxProcessProductsList()
{
$query = Tools::getValue('q', false);
if (!$query || $query == '' || Tools::strlen($query) < 1) {
die();
}
if ($pos = strpos($query, ' (ref:')) {
$query = Tools::substr($query, 0, $pos);
}
$sql = 'SELECT p.`id_product`, pl.`link_rewrite`, 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)Context::getContext()->language->id . Shop::addSqlRestrictionOnLang('pl') . ')
WHERE (pl.name LIKE \'%' . pSQL($query) . '%\' OR p.reference LIKE \'%' . pSQL($query) . '%\')
GROUP BY p.`id_product`';
$items = Db::getInstance()->executeS($sql);
if ($items) {
foreach ($items as $item) {
echo trim($item['name']) . (!empty($item['reference']) ? ' (ref: ' . $item['reference'] . ')' : '') . '|' . (int)$item['id_product'] . "\n";
}
} else {
json_encode(new stdClass());
}
}
public function renderList()
{
$this->context->controller->errors = $this->module->checkIssetImageTypes();
$this->toolbar_btn['new'] = array(
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
'desc' => $this->l('Add new')
);
return parent::renderList();
}
public function getFieldsValue($obj)
{
parent::getFieldsValue($obj);
$this->fields_value['shops[]'] = $obj->shops;
return $this->fields_value;
}
/** @noinspection PhpInconsistentReturnPointsInspection */
public function postProcess()
{
if (Tools::isSubmit('viewblog') && ($id_anblog_blog = (int)Tools::getValue('id_anblog_blog'))
&& ($blog = new AnblogBlog($id_anblog_blog, $this->context->language->id))
&& Validate::isLoadedObject($blog)
) {
$this->redirect_after = $this->getPreviewUrl($blog);
}
if (Tools::isSubmit('submitAddanblog_blog') || Tools::isSubmit('submitAddanblog_blogAndPreview') || Tools::isSubmit('saveandstay')) {
if (Shop::isFeatureActive() && !Tools::getIsset('shops')) {
$this->errors[] = $this->l('Please, select at least one shop');
$this->display = 'edit';
}
if (!Tools::getIsset('categories')) {
$this->errors[] = $this->l('Please, select at least one category');
$this->display = 'edit';
}
parent::validateRules();
if (count($this->errors)) {
return false;
}
if (!$id_anblog_blog = (int)Tools::getValue('id_anblog_blog')) {
$blog = new AnblogBlog();
$this->copyFromPost($blog, 'blog');
if(!Tools::getIsset('products')) {
$blog->products = [];
} else {
$blog->products = Tools::getValue('products');
}
$blog->id_employee = $this->context->employee->id;
if (!$blog->add(false)) {
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
} else {// TODO move to blog model
if (isset($_FILES['image_link']) && isset($_FILES['image_link']['tmp_name']) && !empty($_FILES['image_link']['tmp_name'])) {
$imgName = $blog->imageObject->uploadNew();
if (!$imgName) {
$this->errors[] = $this->l('An error occurred while image processing.');
if (property_exists($blog->imageObject, 'error')) {
$this->errors[] = $blog->imageObject->error;
}
$this->display = 'edit';
return false;
}
if(!Tools::getIsset('products')) {
$blog->products = [];
} else {
$blog->products = Tools::getValue('products');
}
$blog->image = $imgName;
$blog->update();
}
}
} else {
$blog = new AnblogBlog($id_anblog_blog);
$this->copyFromPost($blog, 'blog');
if(!Tools::getIsset('products')) {
$blog->products = [];
} else {
unset($blog->products);
$blog->products = Tools::getValue('products');
}
if (!Tools::getValue('image')) {
$blog->imageObject->delete();
}
if (isset($_FILES['image_link']) && isset($_FILES['image_link']['tmp_name']) && !empty($_FILES['image_link']['tmp_name'])) {
$blog->imageObject->delete();
$imgName = $blog->imageObject->uploadNew();
if (!$imgName) {
$this->errors[] = $this->l('An error occurred while image processing.');
if (property_exists($blog->imageObject, 'error')) {
$this->errors[] = $blog->imageObject->error;
}
$this->display = 'edit';
return false;
}
$blog->image = $imgName;
//TODO ADD THUMB $blog->thumb = $anblogImg->thumb;
}
if (!$blog->update()) {
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
}
}
if (Tools::isSubmit('submitAddblogAndPreview')) {
// validate module
$this->redirect_after = $this->previewUrl($blog);
} elseif (Tools::isSubmit('saveandstay')) {
// validate module
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$blog->id.'&conf=4&update'.$this->table.'&token='.Tools::getValue('token'));
} else {
// validate module
Tools::redirectAdmin(self::$currentIndex.'&id_anblogcat='.$blog->id_anblogcat.'&conf=4&token='.Tools::getValue('token'));
}
} else {
return parent::postProcess(true);
}
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryUi('ui.widget');
$this->addJqueryPlugin('tagify');
$this->addJqueryPlugin('autocomplete');
if (file_exists(_PS_THEME_DIR_.'js/modules/anblog/views/assets/admin/form.js')) {
$this->context->controller->addJS(__PS_BASE_URI__.'modules/anblog/assets/admin/form.js');
} else {
$this->context->controller->addJS(__PS_BASE_URI__.'modules/anblog/views/js/admin/form.js');
}
if (file_exists(_PS_THEME_DIR_.'css/modules/anblog/views/assets/admin/form.css')) {
$this->context->controller->addCss(__PS_BASE_URI__.'modules/anblog/views/assets/admin/form.css');
} else {
$this->context->controller->addCss(__PS_BASE_URI__.'modules/anblog/views/css/admin/form.css');
}
}
public function ajaxProcessUpdateblogPositions()
{
if ($this->tabAccess['edit'] === '1') {
$id_anblog_blog = (int)Tools::getValue('id_anblog_blog');
$id_category = (int)Tools::getValue('id_anblog_blog_categories');
$way = (int)Tools::getValue('way');
$positions = Tools::getValue('blog');
if (is_array($positions)) {
foreach ($positions as $key => $value) {
$pos = explode('_', $value);
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_category && $pos[2] == $id_anblog_blog)) {
$position = $key;
break;
}
}
}
$blog = new blog($id_anblog_blog);
if (Validate::isLoadedObject($blog)) {
if (isset($position) && $blog->updatePosition($way, $position)) {
die(true);
} else {
die('{"hasError" : true, "errors" : "Can not update blog position"}');
}
} else {
die('{"hasError" : true, "errors" : "This blog can not be loaded"}');
}
}
}
public function ajaxProcessUpdateblogCategoriesPositions()
{
if ($this->tabAccess['edit'] === '1') {
$id_anblog_blog_category_to_move = (int)Tools::getValue('id_anblog_blog_categories_to_move');
$id_anblog_blog_category_parent = (int)Tools::getValue('id_anblog_blog_categories_parent');
$way = (int)Tools::getValue('way');
$positions = Tools::getValue('blog_category');
if (is_array($positions)) {
foreach ($positions as $key => $value) {
$pos = explode('_', $value);
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_anblog_blog_category_parent && $pos[2] == $id_anblog_blog_category_to_move)) {
$position = $key;
break;
}
}
}
$blog_category = new blogCategory($id_anblog_blog_category_to_move);
if (Validate::isLoadedObject($blog_category)) {
if (isset($position) && $blog_category->updatePosition($way, $position)) {
die(true);
} else {
die('{"hasError" : true, "errors" : "Can not update blog categories position"}');
}
} else {
die('{"hasError" : true, "errors" : "This blog category can not be loaded"}');
}
}
}
public function ajaxProcessPublishblog()
{
if ($this->tabAccess['edit'] === '1') {
if ($id_anblog_blog = (int)Tools::getValue('id_anblog_blog')) {
$bo_blog_url = dirname($_SERVER['PHP_SELF']).
'/index.php?tab=AdminblogContent&id_anblog_blog='.
(int)$id_anblog_blog.'&updateblog&token='.$this->token;
if (Tools::getValue('redirect')) {
die($bo_blog_url);
}
$blog = new blog((int)(Tools::getValue('id_anblog_blog')));
if (!Validate::isLoadedObject($blog)) {
die('error: invalid id');
}
$blog->active = 1;
if ($blog->save()) {
die($bo_blog_url);
} else {
die('error: saving');
}
} else {
die('error: parameters');
}
}
}
}

View File

@@ -0,0 +1,531 @@
<?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/classes/anblogcat.php';
class AdminAnblogCategoriesController extends ModuleAdminController
{
protected $_module = null;
protected $position_identifier = 'position';
protected $_defaultOrderBy = 'position';
protected $_defaultOrderWay = 'ASC';
protected $allow_export = false;
public function __construct()
{
$this->bootstrap = true;
$this->context = Context::getContext();
$this->table = 'anblogcat';
$this->identifier = 'id_anblogcat';
$this->className = 'Anblogcat';
$this->lang = true;
$this->parent_id = (int)Tools::getValue('id_parent');
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->name = 'AdminAnblogCategoriesController';
parent::__construct();
$parentId = 1;
if ($this->parent_id){
$parentId = $this->parent_id;
}
$this->_where .= ' AND a.id_parent = ' . $parentId . ' ';
$this->fields_list = [
'id_anblogcat' => [
'title' => $this->l('ID'),
'width' => 25,
'search' => false,
],
'image' => [
'title' => $this->l('Image'),
'width' => 25,
'search' => false,
'type' => 'image',
],
'title' => [
'title' => $this->l('Name'),
'width' => 25,
'search' => false,
],
'content_text' => [
'title' => $this->l('Description'),
'width' => 25,
'search' => false,
],
'position' => [
'title' => $this->l('Position'),
'search' => false,
'position' => true
],
'active' => [
'title' => $this->l('Status'),
'width' => 40,
'active' => 'update',
'align' => 'center',
'type' => 'bool',
'search' => false,
'orderby' => false
],
'viewBut' => [
'title' => $this->l('View'),
'search' => false,
'type' => 'image',
]
];
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) {
$this->_where .= ' AND a.' . $this->identifier . ' IN (
SELECT sa.' . $this->identifier . '
FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa
WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
)';
}
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
foreach ($this->_list as &$list) {
if ($list['image'] !='' && Tools::file_exists_no_cache( _ANBLOG_BLOG_IMG_DIR_.'c/'. $list['image'])) {
$list['image'] = _ANBLOG_BLOG_IMG_URI_.'/c/'. $list['image'];
} else {
$list['image'] = '';
}
$list['content_text'] = strip_tags($list['content_text']);
$obj = new anblogcat($list['id_anblogcat']);
$child = $obj->getChild($list['id_anblogcat']);
$list['viewBut'] = '';
if (count($child) != 0) {
$list['viewBut'] = $this->context->link->getAdminLink('AdminAnblogCategories'). '&id_parent='. $list['id_anblogcat'];
}
}
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryPlugin('tagify');
$this->js_files[] = _MODULE_DIR_ . 'anblog/views/js/admin/back.js';
$this->css_files[_MODULE_DIR_ . 'anblog/views/css/admin/back.css'] = 'all';
}
public function renderList()
{
$this->initToolbar();
if (!$this->loadObject(true)) {
return false;
}
return parent::renderList();
}
public function initToolBarTitle()
{
$this->toolbar_title[] = $this->l('Categories');
}
public function initHeader()
{
parent::initHeader();
$tabs = &$this->context->smarty->tpl_vars['tabs']->value;
$tabs = $this->module->createAdminTabs($tabs, $this->controller_name);
}
public function initContent()
{
$this->context->smarty->assign('current_tab_level', 3);
return parent::initContent();
}
public function initPageHeaderToolbar()
{
if (empty($this->display)) {
$this->page_header_toolbar_btn['add_field'] = array(
'href' => self::$currentIndex . '&addanblogcat&token=' . $this->token,
'desc' => $this->trans('Add new', array(), 'Admin.Actions'),
'icon' => 'process-icon-new',
);
$this->page_header_toolbar_btn['open_the_blog'] = array(
'href' => AnblogHelper::getInstance()->getFontBlogLink(),
'desc' => $this->trans('View my blog', [], 'Admin.Actions'),
'icon' => 'icon-book',
'target' => '_blank'
);
}
parent::initPageHeaderToolbar();
}
public function renderForm()
{
$this->initToolbar();
if (!$this->loadObject(true)) {
return;
}
$thumb = '';
if ($this->object->image) {
$thumb = _ANBLOG_BLOG_IMG_URI_.'/c/'. $this->object->image;
}
$this->fields_form = array(
'tinymce' => false,
'legend' => ['title' => $this->l('Categories')],
'input' => [],
'buttons' => [
[
'type' => 'submit',
'title' => $this->l('Save'),
'icon' => 'process-icon-save',
'class' => 'pull-right',
'name' => 'submit'.$this->table
],
[
'type' => 'submit',
'title' => $this->l('Save and stay'),
'icon' => 'process-icon-save',
'class' => 'pull-right',
'name' => 'submit'.$this->table.'AndStay'
],
],
);
$this->fields_form['input'][] = [
'type' => 'text',
'label' => $this->l('Title'),
'default' => '',
'name' => 'title',
'id' => 'name',
'lang' => true,
'required' => true,
'class' => 'copyMeta2friendlyURL',
'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
];
$this->fields_form['input'][] = [
'type' => 'text',
'label' => $this->l('Friendly URL'),
'name' => 'link_rewrite',
'required' => true,
'lang' => true,
'default' => '',
'hint' => $this->l('Only letters and the minus (-) character are allowed')
];
$this->context->smarty->assign(['PS_ALLOW_ACCENTED_CHARS_URL' => (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL')]);
$obj = $this->object;
$cats = $obj->getDropdown(null, $obj->id_parent);
$this->fields_form['input'][] = [
'type' => 'select',
'label' => $this->l('Parent ID'),
'name' => 'id_parent',
'options' => [
'query' => $cats,
'id' => 'id',
'name' => 'title'
],
'default' => 'url',
];
$this->fields_form['input'][] = [
'type' => 'switch',
'name' => 'active',
'label' => $this->l('Active'),
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
]
],
];
$this->fields_form['input'][] = [
'type' => 'text',
'name' => 'menu_class',
'label' => $this->l('Additional CSS class'),
'lang' => false,
];
$this->fields_form['input'][] = [
'type' => 'file',
'label' => $this->l('Image'),
'required' => false,
'name' => 'file_icon',
'thumb' => $thumb,
'form_group_class' => 'ab-bi-image'
];
$this->fields_form['input'][] = [
'type' => 'textarea',
'class' => 'autoload_rte',
'name' => 'content_text',
'label' => $this->l('Description'),
'lang' => true,
];
$this->fields_form['input'][] = [
'type' => 'text',
'name' => 'meta_title',
'label' => $this->l('Meta title'),
'required' => true,
'lang' => true,
];
$this->fields_form['input'][] = [
'type' => 'text',
'name' => 'meta_description',
'label' => $this->l('Meta description'),
'lang' => true,
];
$this->fields_form['input'][] = [
'type' => 'tags',
'label' => $this->l('Meta keywords'),
'name' => 'meta_keywords',
'lang' => true,
'default' => '',
'hint' => $this->l('Invalid characters:') . ' &lt;&gt;;=#{}',
'desc' => $this->l('To add a keyword, enter the keyword and then press "Enter"'),
];
if (Shop::isFeatureActive()) {
$this->fields_form['input'][] = [
'required' => true,
'type' => 'shop',
'label' => $this->l('Shop association'),
'name' => 'checkBoxShopAsso',
];
}
return parent::renderForm();
}
public function processSave()
{
if (isset($_FILES['file_icon']) && isset($_FILES['file_icon']['tmp_name'])
&& !empty($_FILES['file_icon']['tmp_name'])) {
if ($error = $this->validateUpload($_FILES['file_icon'])) {
$this->errors[] = $error;
}
}
if (!empty($this->errors)) {
$this->display = 'edit';
return false;
}
$isUpdateImage = false;
$object = parent::processSave();
if (isset($object->id) && $object->id) {
if(tools::getValue('image_del')){
@unlink(_ANBLOG_BLOG_IMG_DIR_.'c/'. $object->image);
$object->image = '';
$isUpdateImage = true;
}
if (isset($_FILES['file_icon']) && !empty($_FILES['file_icon']['tmp_name'])) {
$ext = substr($_FILES['file_icon']['name'], strrpos($_FILES['file_icon']['name'], '.') + 1);
$image = md5(uniqid()) . '.'.$ext;
if (!move_uploaded_file($_FILES['file_icon']['tmp_name'], _ANBLOG_BLOG_IMG_DIR_.'c/'. $image)) {
return $this->displayError(
$this->trans('An error occurred while attempting to upload the file.', [], 'Admin.Notifications.Error')
);
} else {
@unlink(_ANBLOG_BLOG_IMG_DIR_.'c/'. $object->image);
$object->image = $image;
}
$isUpdateImage = true;
}
}
if ($isUpdateImage){
$object->save();
}
if (Tools::getIsset('submit'.$this->table.'AndStay') && empty($this->errors)) {
$this->redirect_after = $this->context->link->getAdminLink($this->controller_name).'&conf=4&updateanblogcat&token='.$this->token.'&id_anblogcat='.$object->id;
}
return $object;
}
public function processDelete()
{
$object = parent::processDelete();
if (isset($object->id) && $object->id) {
if ($object->image){
unlink(_ANBLOG_BLOG_IMG_DIR_.'c/'. $object->image);
}
}
return $object;
}
public function validateUpload($file)
{
$maxFileSize = 4000000;
$types = ['gif', 'jpg', 'jpeg', 'jpe', 'png', 'svg', 'webp'];
// if ((int) $maxFileSize > 0 && $file['size'] > (int) $maxFileSize) {
// return Context::getContext()->getTranslator()->trans('Image is too large (%1$d kB). Maximum allowed: %2$d kB', [$file['size'] / 1024, $maxFileSize / 1024], 'Admin.Notifications.Error');
// }
if (!ImageManager::isCorrectImageFileExt($file['name'], $types) || preg_match('/\%00/', $file['name'])) {
return Context::getContext()->getTranslator()->trans('Image format not recognized, allowed formats are: .gif, .jpg, .png, .svg, .webp', [], 'Admin.Notifications.Error');
}
if ($file['error']) {
return Context::getContext()->getTranslator()->trans('Error while uploading image; please change your server\'s settings. (Error code: %s)', [$file['error']], 'Admin.Notifications.Error');
}
return false;
}
public function ajaxProcessUpdatePositions()
{
$status = false;
$position = 0;
$widget = (array)Tools::getValue('anblogcat');
foreach ($widget as $key => $item){
$ids = explode('_', $item);
$sql = 'UPDATE `' . _DB_PREFIX_ . $this->table .'` SET position="'.(int) $position.'" WHERE '.$this->identifier.'="'.(int) $ids['2'].'" ';
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
$position++;
}
if (count($widget) > 0){
$status = true;
}
return $this->setJsonResponse(array(
'success' => $status,
'message' => $this->l($status ? 'Blocks reordered successfully' : 'An error occurred')
));
}
protected function setJsonResponse($response)
{
header('Content-Type: application/json; charset=utf8');
$this->ajaxDie(json_encode($response));
}
protected function updateAssoShop($id_object)
{
if (!Shop::isFeatureActive()) {
return;
}
$assos_data = $this->getSelectedAssoShop($this->table, $id_object);
$exclude_ids = $assos_data;
foreach (Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop') as $row) {
if (!$this->context->employee->hasAuthOnShop($row['id_shop'])) {
$exclude_ids[] = $row['id_shop'];
}
}
Db::getInstance()->delete($this->table . '_shop', '`' . $this->identifier . '` = ' . (int) $id_object . ($exclude_ids ? ' AND id_shop NOT IN (' . implode(', ', $exclude_ids) . ')' : ''));
$insert = array();
foreach ($assos_data as $id_shop) {
$insert[] = array(
$this->identifier => $id_object,
'id_shop' => (int) $id_shop,
);
}
return Db::getInstance()->insert($this->table . '_shop', $insert, false, true, Db::INSERT_IGNORE);
}
protected function getSelectedAssoShop($table)
{
if (!Shop::isFeatureActive()) {
return array();
}
$shops = Shop::getShops(true, null, true);
if (count($shops) == 1 && isset($shops[0])) {
return array($shops[0], 'shop');
}
$assos = array();
if (Tools::isSubmit('checkBoxShopAsso_' . $table)) {
foreach (Tools::getValue('checkBoxShopAsso_' . $table) as $id_shop => $value) {
$assos[] = (int) $id_shop;
}
} else if (Shop::getTotalShops(false) == 1) {
$assos[] = (int) Shop::getContextShopID();
}
return $assos;
}
}

View File

@@ -0,0 +1,252 @@
<?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';
require_once _PS_MODULE_DIR_.'anblog/classes/comment.php';
class AdminAnblogCommentsController extends ModuleAdminController
{
protected $max_image_size = 1048576;
protected $position_identifier = 'id_anblog_blog';
public function __construct()
{
$this->bootstrap = true;
$this->table = 'anblog_comment';
// $this->list_id = 'id_anblog_comment'; // must be set same value $this->table to delete multi rows
$this->identifier = 'id_anblog_comment';
$this->className = 'AnblogComment';
$this->lang = false;
$this->addRowAction('edit');
$this->addRowAction('delete');
if (Tools::getValue('id_anblog_blog')) {
// validate module
$this->_where = ' AND id_anblog_blog='.(int)Tools::getValue('id_anblog_blog');
}
parent::__construct();
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'),
'icon' => 'icon-trash'
)
);
$this->fields_list = array(
'id_anblog_comment' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
'id_anblog_blog' => array(
'title' => $this->l('Blog ID'),
'align' => 'center',
'class' => 'fixed-width-xs'
),
'user' => array('title' => $this->l('User')),
'comment' => array('title' => $this->l('Comment')),
'date_add' => array('title' => $this->l('Date Added'),'type' => 'datetime'),
'active' => array(
'title' => $this->l('Displayed'),
'align' => 'center',
'active' => 'status',
'class' => 'fixed-width-sm',
'type' => 'bool',
'orderby' => false
)
);
}
public function initPageHeaderToolbar()
{
if (empty($this->display)) {
$this->page_header_toolbar_btn['open_the_blog'] = array(
'href' => AnblogHelper::getInstance()->getFontBlogLink(),
'desc' => $this->trans('View my blog', [], 'Admin.Actions'),
'icon' => 'icon-book',
'target' => '_blank'
);
}
return parent::initPageHeaderToolbar();
}
public function initHeader()
{
parent::initHeader();
$tabs = &$this->context->smarty->tpl_vars['tabs']->value;
$tabs = $this->module->createAdminTabs($tabs, $this->controller_name);
}
public function initContent()
{
$this->context->smarty->assign('current_tab_level', 3);
return parent::initContent();
}
public function renderForm()
{
if (!$this->loadObject(true)) {
if (Validate::isLoadedObject($this->object)) {
$this->display = 'edit';
} else {
$this->display = 'add';
}
}
$this->initToolbar();
$this->initPageHeaderToolbar();
$blog = new AnblogBlog($this->object->id_anblog_blog, $this->context->language->id);
$this->multiple_fieldsets = true;
$this->object->blog_title = $blog->meta_title;
$this->fields_form[0]['form'] = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Blog Form'),
'icon' => 'icon-folder-close'
),
'input' => array(
array(
'type' => 'hidden',
'label' => $this->l('Comment ID'),
'name' => 'id_anblog_comment',
),
array(
'type' => 'text',
'label' => $this->l('Blog Title'),
'name' => 'blog_title',
),
array(
'type' => 'text',
'label' => $this->l('User'),
'name' => 'user',
),
array(
'type' => 'text',
'label' => $this->l('Email'),
'name' => 'email',
),
array(
'type' => 'textarea',
'label' => $this->l('Blog Content'),
'name' => 'comment',
'rows' => 5,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
array(
'type' => 'switch',
'label' => $this->l('Displayed:'),
'name' => 'active',
'required' => false,
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
),
'buttons' => array(
'save_and_preview' => array(
'name' => 'saveandstay',
'type' => 'submit',
'title' => $this->l('Save and stay'),
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-save-and-stay'
)
)
);
$this->tpl_form_vars = array(
'active' => $this->object->active,
'PS_ALLOW_ACCENTED_CHARS_URL', (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL')
);
$this->context->smarty->assign(
array(
'PS_ALLOW_ACCENTED_CHARS_URL' => (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'),
'anblog_del_img_txt' => $this->l('Delete'),
'anblog_del_img_mess' => $this->l('Are you sure delete this?'),
)
);
$html = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'anblog/views/templates/admin/prerender/additionaljs.tpl');
return $html.parent::renderForm();
}
public function initToolbar()
{
parent::initToolbar();
unset($this->toolbar_btn['new']);
}
public function renderList()
{
$config = new AnblogConfig();
if ((!Configuration::get(anblog::PREFIX . 'google_captcha_site_key') || !Configuration::get(anblog::PREFIX . 'google_captcha_secret_key')) && Configuration::get(anblog::PREFIX . 'google_captcha_status')) {
$this->context->controller->errors[] = 'Please fill reCAPTCHA site and secret keys in Config -> Item Blog Settings to enable comments';
return false;
}
$this->toolbar_title = $this->l('Comments');
return parent::renderList();
}
//DONGND:: add save and stay
public function postProcess()
{
if (Tools::isSubmit('saveandstay')) {
parent::validateRules();
if (count($this->errors)) {
return false;
}
if ($id_anblog_comment = (int)Tools::getValue('id_anblog_comment')) {
$comment = new AnblogComment($id_anblog_comment);
$this->copyFromPost($comment, 'comment');
if (!$comment->update()) {
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
} else {
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.Tools::getValue('id_anblog_comment').'&conf=4&update'.$this->table.'&token='.Tools::getValue('token'));
}
} else {
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
}
} else {
return parent::postProcess();
}
}
}

View File

@@ -0,0 +1,859 @@
<?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';
require_once _PS_MODULE_DIR_.'anblog/classes/comment.php';
class AdminAnblogSettingsController extends ModuleAdminController
{
protected $_module = null;
public function __construct()
{
$this->bootstrap = true;
$this->display = 'view';
$this->name = 'AdminAnblogSettingsController';
parent::__construct();
}
public function initToolBarTitle()
{
$this->toolbar_title[] = $this->l('Settings');
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryUi('ui.widget');
$this->addJqueryPlugin('tagify');
if (file_exists(_PS_THEME_DIR_ . 'js/modules/anblog/views/assets/form.js')) {
$this->context->controller->addJS(__PS_BASE_URI__ . 'modules/anblog/views/assets/admin/form.js');
} else {
$this->context->controller->addJS(__PS_BASE_URI__ . 'modules/anblog/views/js/admin/form.js');
}
}
protected function getSettingsForm()
{
$url_rss = Tools::htmlentitiesutf8('http://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__) . 'modules/anblog/rss.php';
$onoff = array(
array(
'id' => 'indexation_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'indexation_off',
'value' => 0,
'label' => $this->l('Disabled')
)
);
$languages = Language::getLanguages();
$sitemapLinks = [];
$sitemapLinks['siteMapAll'] = $this->context->link->getBaseLink(null, null, null) . 'module/anblog/sitemap.xml';
foreach ($languages as $language){
$sitemapLinks['siteMapLang'][$language['iso_code']] = $this->context->link->getModuleLink('anblog', 'sitemap', [], true, $language['id_lang']) . '';
}
$this->context->smarty->assign('sitemapLinks', $sitemapLinks);
$rssLink = $this->context->link->getBaseLink(null, null, null) . 'module/anblog/rss';
$this->context->smarty->assign('rssLink', $rssLink);
$form['0']['form']['legend'] = [
'title' => $this->l('General'),
];
$form['0']['form']['submit'] = [
'name' => 'save',
'title' => $this->l('Save'),
];
$form['0']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Root Link Title'),
'name' => anblog::PREFIX .'blog_link_title',
'required' => true,
'lang' => true,
'default' => 'Blog',
];
$form['0']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Category'),
'name' => anblog::PREFIX . 'category_rewrite',
'lang' => true,
'default' => '',
'form_group_class' => 'url_use_id_sub url_use_id-0',
'desc' => 'Enter a hint word that is displayed in the URL of a category and makes the URL friendly',
'hint' => $this->l('Example http://domain/blog/category/name/'),
];
$form['0']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Post'),
'name' => anblog::PREFIX . 'detail_rewrite',
'required' => true,
'lang' => true,
'default' => 'post',
'form_group_class' => 'url_use_id_sub url_use_id-0',
'desc' => 'Enter a hint word that is displayed in the URL of a post and makes the URL friendly',
'hint' => $this->l('Example http://domain/blog/post/name/'),
];
$form['0']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Add .html prefix to links to posts and categories'),
'name' => anblog::PREFIX . 'cat_post_end_prefix',
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->trans('Enabled', [], 'Admin.Global')
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->trans('Disabled', [], 'Admin.Global')
]
]
];
$form['0']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Root'),
'name' => anblog::PREFIX . 'link_rewrite',
'required' => true,
'desc' => $this->l('If necessary, change root of the blog'),
'default' => 'blog',
];
$form['0']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Meta Title'),
'name' => anblog::PREFIX . 'meta_title',
'lang' => true,
'cols' => 40,
'rows' => 10,
'default' => 'Blog',
];
$form['0']['form']['input'][] = [
'type' => 'textarea',
'label' => $this->l('Meta description'),
'name' => anblog::PREFIX . 'meta_description',
'lang' => true,
'cols' => 40,
'rows' => 10,
'default' => '',
'desk' => $this->l('Display meta descrition on frontpage blog') . 'note: note &lt;&gt;;=#{}'
];
$form['0']['form']['input'][] = [
'type' => 'tags',
'label' => $this->l('Meta keywords'),
'name' => anblog::PREFIX . 'meta_keywords',
'default' => '',
'hint' => $this->l('Invalid characters:') . ' &lt;&gt;;=#{}',
'lang' => true,
'desc' => array(
$this->l('To add a keyword, enter the keyword and then press "Enter"')
)
];
$form['0']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Enable RSS'),
'name' => anblog::PREFIX . 'indexation',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '',
'values' => $onoff,
];
if(Configuration::get(anblog::PREFIX . 'indexation')){
$form['0']['form']['input'][] = [
'type' => 'html',
'label' => $this->l('RSS'),
'name' => anblog::PREFIX . 'rss_link',
'html_content' => $this->module->display(_PS_MODULE_DIR_.'anblog','/views/templates/admin/anblog_settings/helpers/rss.tpl')
];
}
$form['0']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('RSS Limit Items'),
'name' => anblog::PREFIX . 'rss_limit_item',
'default' => '20',
];
$form['0']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Soft reset (Do not delete database tables)'),
'name' => anblog::PREFIX . 'soft_reset',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '',
'values' => $onoff,
];
// $form['0']['form']['input'][] = [
// 'type' => 'text',
// 'label' => $this->l('RSS Title'),
// 'name' => anblog::PREFIX . 'rss_title_item',
// 'default' => 'RSS FEED',
// ];
//////
$form['1']['form']['legend'] = [
'title' => $this->l('Blog'),
];
$form['1']['form']['submit'] = [
'name' => 'save',
'title' => $this->l('Save'),
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Category description'),
'name' => anblog::PREFIX . 'listing_show_categoryinfo',
'required' => false,
'class' => 't',
'desc' => $this->l('Display description of the category in the list of categories'),
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Items limit'),
'name' => anblog::PREFIX . 'listing_limit_items',
'required' => false,
'class' => 't',
'default' => '6',
];
//////////////////////////////////////////// ПЕРЕОПРЕДЕЛИТЬ
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Title'),
'name' => anblog::PREFIX . 'listing_show_title',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Description'),
'name' => anblog::PREFIX . 'listing_show_description',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('"Read more" button'),
'name' => anblog::PREFIX . 'listing_show_readmore',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Image'),
'name' => anblog::PREFIX . 'listing_show_image',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Author'),
'name' => anblog::PREFIX . 'listing_show_author',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Category'),
'name' => anblog::PREFIX . 'listing_show_category',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Date'),
'name' => anblog::PREFIX . 'listing_show_created',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Views'),
'name' => anblog::PREFIX . 'listing_show_hit',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Comments counter'),
'name' => anblog::PREFIX . 'listing_show_counter',
'required' => false,
'class' => 't',
'default' => '0',
'values' => $onoff,
];
$form['1']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Likes'),
'name' => anblog::PREFIX . 'likes',
'required' => false,
'class' => 't',
'default' => '0',
'values' => $onoff,
'desc' => $this->l('If supported by the template.'),
];
$form['1']['form']['input'][] = [
'type' => 'select',
'label' => $this->l('Posts type'),
'name' => anblog::PREFIX . 'item_posts_type',
'id' => 'item_posts_type',
'class' => 'item_posts_type',
'options' => array('query' => array(
array('id' => 'Type 1', 'name' => $this->l('type1')),
array('id' => 'Type 2', 'name' => $this->l('type2')),
array('id' => 'Type 3', 'name' => $this->l('type3')),
),
'id' => 'id',
'name' => 'name'),
'default' => 'local'
];
///////
$form['2']['form']['legend'] = [
'title' => $this->l('Post'),
];
$form['2']['form']['submit'] = [
'name' => 'save',
'title' => $this->l('Save'),
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Description'),
'name' => anblog::PREFIX . 'item_show_description',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Image'),
'name' => anblog::PREFIX . 'item_show_image',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Author'),
'name' => anblog::PREFIX . 'item_show_author',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Category'),
'name' => anblog::PREFIX . 'item_show_category',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Date'),
'name' => anblog::PREFIX . 'item_show_created',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Views'),
'name' => anblog::PREFIX . 'item_show_hit',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Comments counter'),
'name' => anblog::PREFIX . 'item_show_counter',
'required' => false,
'class' => 't',
'default' => '1',
'values' => $onoff,
];
$form['2']['form']['input'][] = [
'type' => 'textarea',
'label' => $this->l('Social Sharing CODE'),
'name' => anblog::PREFIX . 'social_code',
'required' => false,
'default' => '',
'desc' => 'If you want to replace default social sharing buttons, configure them on https://www.sharethis.com/ and paste their code into the field above'
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Comments list'),
'name' => anblog::PREFIX . 'item_show_listcomment',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
'desc' => $this->l('Show/Hide the comments list'),
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Comment form'),
'name' => anblog::PREFIX . 'item_show_formcomment',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '1',
'values' => $onoff,
'desc' => $this->l('This option is compatible only with local comments engine'),
];
$form['2']['form']['input'][] = [
'type' => 'select',
'label' => $this->l('Comments Engine'),
'name' => anblog::PREFIX . 'item_comment_engine',
'id' => 'item_comment_engine',
'class' => 'engine_select',
'options' => array('query' => array(
array('id' => 'local', 'name' => $this->l('Local')),
array('id' => 'facebook', 'name' => $this->l('Facebook')),
array('id' => 'diquis', 'name' => $this->l('Disqus')),
),
'id' => 'id',
'name' => 'name'),
'default' => 'local'
];
$form['2']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Enable reCAPTCHA '),
'name' => anblog::PREFIX . 'google_captcha_status',
'required' => false,
'is_bool' => true,
'class' => 't local comment_item',
'default' => '1',
'values' => $onoff,
'desc' => html_entity_decode('&lt;a target=&#x22;_blank&#x22; href=&quot;https://www.google.com/recaptcha/admin&quot;&gt;Register google reCAPTCHA &lt;/a&gt;')
];
$form['2']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('reCAPTCHA site key'),
'name' => anblog::PREFIX . 'google_captcha_site_key',
'required' => false,
'class' => 't local comment_item',
'default' => '',
];
$form['2']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('reCAPTCHA secret key'),
'name' => anblog::PREFIX . 'google_captcha_secret_key',
'required' => false,
'default' => '',
'class' => 't local comment_item',
];
$form['2']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Comments limit'),
'name' => anblog::PREFIX . 'item_limit_comments',
'required' => false,
'class' => 't local comment_item',
'default' => '10',
'desc' => $this->l('This option is compatible only with local comments engine'),
];
$form['2']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Disqus Account'),
'name' => anblog::PREFIX . 'item_diquis_account',
'required' => false,
'class' => 't diquis comment_item',
'default' => 'demo4antheme',
'desc' => html_entity_decode('Enter the name of your Disqus account (for example anvanto-com). You can copy the name from the address page in your account: for example, the URL is anvanto-com.disqus.com/admin, then copy the text before the first dot. If you have no Disqus account, &lt;a target=&quot;_blank&quot; href=&quot;https://disqus.com/admin/signup/&quot;&gt;sign up here&lt;/a&gt;')
];
$form['2']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Facebook Application ID'),
'name' => anblog::PREFIX . 'item_facebook_appid',
'required' => false,
'class' => 't facebook comment_item',
'default' => '100858303516',
'desc' => html_entity_decode('&#x3C;a target=&#x22;_blank&#x22; href=&#x22;http://developers.facebook.com/docs/reference/plugins/comments/&#x22;&#x3E;' . $this->l('Register a comment box') . '&#x3C;/a&#x3E;' . ' then enter your site URL into the Comments Plugin Code Generator and then press the "Get code" button. Copy the appId from the code and paste it into the field above.')
];
$form['2']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Facebook Width'),
'name' => anblog::PREFIX . 'item_facebook_width',
'required' => false,
'class' => 't facebook comment_item',
'default' => '600'
];
/////////////////
$form['3']['form']['legend'] = [
'title' => $this->l('Left column'),
];
$form['3']['form']['submit'] = [
'name' => 'save',
'title' => $this->l('Save'),
];
$form['3']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Enable in blog'),
'name' => anblog::PREFIX . 'show_in_blog',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => array(
array(
'id' => 'show_in_blog_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'show_in_blog_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
];
$form['3']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Enable on post page'),
'name' => anblog::PREFIX . 'show_in_post',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => array(
array(
'id' => 'show_in_post_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'show_in_post_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
];
$form['3']['form']['input'][] = [
'type' => 'text',
'label' => $this->l('Recent posts limit'),
'name' => anblog::PREFIX . 'limit_recent_blog',
'default' => '5',
];
$form['4']['form']['legend'] = [
'title' => $this->l('Integrations with Google sitemap module'),
];
$form['4']['form']['submit'] = [
'name' => 'save',
'title' => $this->l('Save'),
];
$form['4']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Enable'),
'name' => anblog::PREFIX . 'enable_google_sitemap',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => array(
array(
'id' => 'enable_google_sitemap_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'enable_google_sitemap_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
];
$form['4']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Posts'),
'name' => anblog::PREFIX . 'enable_posts_sitemap',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => array(
array(
'id' => 'enable_posts_sitemap_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'enable_posts_sitemap_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
];
$form['4']['form']['input'][] = [
'type' => 'switch',
'label' => $this->l('Categories'),
'name' => anblog::PREFIX . 'enable_categories_sitemap',
'required' => false,
'class' => 't',
'is_bool' => true,
'default' => '0',
'values' => array(
array(
'id' => 'enable_categories_sitemap_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'enable_categories_sitemap_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
];
if(Configuration::get(anblog::PREFIX . 'enable_google_sitemap')){
// $form['5']['form']['input'][] = [
// 'type' => 'html',
// 'label' => $this->l('Sitemaps'),
// 'name' => anblog::PREFIX . 'Sitemaps',
// 'html_content' => $this->module->display(_PS_MODULE_DIR_.'anblog','/views/templates/admin/anblog_settings/helpers/sitemap.tpl')
// ];
}
////////////////
return $form;
}
public function initHeader()
{
parent::initHeader();
$tabs = &$this->context->smarty->tpl_vars['tabs']->value;
$tabs = $this->module->createAdminTabs($tabs, $this->controller_name);
}
public function initContent()
{
$this->context->smarty->assign('current_tab_level', 3);
return parent::initContent();
}
public function renderView()
{
$languages = $this->context->controller->getLanguages();
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->name_controller = $this->name;
$helper->submit_action = $this->name;
$helper->currentIndex = $this->context->link->getAdminLink('AdminAnblogSettings', false);
$helper->token = Tools::getAdminTokenLite('AdminAnblogSettings');
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->tpl_vars = [
'uri' => $this->module->getPathUri(),
'languages' => $languages,
'id_language' => $this->context->language->id
];
$form = $this->getSettingsForm();
foreach($form as $subForm){
foreach ($subForm['form']['input'] as $input){
if (isset($input['lang']) && $input['lang']){
$value = [];
foreach ($languages as $language){
$value[$language['id_lang']] = Configuration::get($input['name'], $language['id_lang']);
}
$helper->tpl_vars['fields_value'][$input['name']] = $value;
} else {
$helper->tpl_vars['fields_value'][$input['name']] = Configuration::get($input['name']);
}
}
}
//return $this->module->topPromo() . $helper->generateForm([$form]);
return $helper->generateForm($form);
}
public function initPageHeaderToolbar()
{
$this->page_header_toolbar_btn['open_the_blog'] = array(
'href' => AnblogHelper::getInstance()->getFontBlogLink(),
'desc' => $this->trans('View my blog', [], 'Admin.Actions'),
'icon' => 'icon-book',
'target' => '_blank'
);
parent::initPageHeaderToolbar();
}
public function postProcess()
{
if (!empty($this->errors)) {
$this->display = 'edit';
return false;
}
$form = $this->getSettingsForm();
$isSubmit = false;
foreach($form as $subForm){
if (Tools::isSubmit($subForm['form']['submit']['name'])){
$isSubmit = true;
}
}
if ($isSubmit) {
$languages = Language::getLanguages(false);
foreach($form as $subForm){
foreach ($subForm['form']['input'] as $input){
$html = false;
if (isset($input['html']) && $input['html']){
$html = true;
}
if (isset($input['lang']) && $input['lang']){
$value = [];
foreach ($languages as $language){
$value[$language['id_lang']] = Tools::getValue($input['name'].'_' . $language['id_lang']);
}
Configuration::updateValue($input['name'], $value, $html);
} else {
Configuration::updateValue($input['name'], Tools::getValue($input['name']), $html);
}
}
}
$currentIndex = $this->context->link->getAdminLink('AdminAnblogSettings', false);
$token = Tools::getAdminTokenLite('AdminAnblogSettings');
Tools::redirectAdmin($currentIndex.'&token='.$token.'&conf=4');
}
return true;
}
}
?>

View File

@@ -0,0 +1,542 @@
<?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 AdminAnblogWidgetsController extends ModuleAdminController
{
protected $_module = null;
protected $position_identifier = 'id_anblog_blog_widgets';
public function __construct()
{
$this->bootstrap = true;
$this->context = Context::getContext();
$this->table = 'anblog_blog_widgets';
$this->identifier = 'id_anblog_blog_widgets';
$this->className = 'anBlogWidgets';
$this->lang = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->name = 'AdminAnblogWidgetsController';
parent::__construct();
$this->fields_list = [
'id_anblog_blog_widgets' => [
'title' => $this->l('ID'),
'width' => 25,
'search' => false,
],
'title' => [
'title' => $this->l('Title'),
'width' => 25,
'search' => false,
],
'id_anblogcat' => [
'title' => $this->l('Category'),
'width' => 25,
'search' => false,
],
'relation' => [
'title' => $this->l('Relation'),
'search' => false,
'width' => 150,
],
'snow_on' => [
'title' => $this->l('Show on'),
'width' => 25,
'search' => false,
],
'sort' => [
'title' => $this->l('Sort'),
'width' => 25,
'search' => false,
],
// 'slider' => [
// 'title' => $this->l('Slider'),
// 'width' => 40,
// 'active' => 'update',
// 'align' => 'center',
// 'type' => 'bool',
// 'search' => false,
// 'orderby' => false
// ],
'limit' => [
'title' => $this->l('Limit'),
'width' => 25,
'search' => false,
],
];
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) {
$this->_where .= ' AND a.' . $this->identifier . ' IN (
SELECT sa.' . $this->identifier . '
FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa
WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
)';
}
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$showOn = anBlogWidgets::$showOn;
$obj = new anblogcat();
$obj->getTree();
$menus = $obj->getDropdown(null, $obj->id_parent, false);
array_shift($menus);
$itemHome['-'] = ['id'=>'', 'title' => '-', 'selected' => ''];
$menus = array_merge($itemHome, $menus);
foreach ($this->_list as &$list) {
foreach ($showOn as $key => $item){
if ($list['snow_on'] == $key){
$list['snow_on'] = $item['name'];
}
}
if (!$list['id_anblogcat']){
$list['id_anblogcat'] = '-';
}
foreach ($menus as $key => $item){
if ($list['id_anblogcat'] == $item['id']){
$list['id_anblogcat'] = $item['title'];
}
}
switch ($list['relation']){
case 1:
$list['relation'] = $this->l('Categories');
break;
case 2:
$list['relation'] = $this->l('Products');
break;
default:
$list['relation'] = $this->l('all');
}
}
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJquery();
$this->js_files[] = _MODULE_DIR_ . 'anblog/views/js/back_widgets.js';
$this->css_files[_MODULE_DIR_ . 'anblog/views/css/back.css'] = 'all';
}
public function renderList()
{
$this->initToolbar();
if (!$this->loadObject(true)) {
return false;
}
return parent::renderList();
}
public function initToolBarTitle()
{
$this->toolbar_title[] = $this->l('Widgets');
}
public function initHeader()
{
parent::initHeader();
$tabs = &$this->context->smarty->tpl_vars['tabs']->value;
$tabs = $this->module->createAdminTabs($tabs, $this->controller_name);
}
public function initContent()
{
$this->context->smarty->assign('current_tab_level', 3);
return parent::initContent();
}
public function initPageHeaderToolbar()
{
if (empty($this->display)) {
$this->page_header_toolbar_btn['add_field'] = array(
'href' => self::$currentIndex . '&addanblog_blog_widgets&token=' . $this->token,
'desc' => $this->trans('Add new', array(), 'Admin.Actions'),
'icon' => 'process-icon-new',
);
}
if (empty($this->display)) {
$this->page_header_toolbar_btn['open_the_blog'] = array(
'href' => AnblogHelper::getInstance()->getFontBlogLink(),
'desc' => $this->trans('View my blog', [], 'Admin.Actions'),
'icon' => 'icon-book',
'target' => '_blank'
);
}
return parent::initPageHeaderToolbar();
}
public function renderForm()
{
$this->initToolbar();
if (!$this->loadObject(true)) {
return;
}
$values = [];
$showOn = anBlogWidgets::$showOn;
foreach ($showOn as $key => $item){
$values[] = [
'id' => $key,
'name' => $item['name']
];
}
$this->fields_form = array(
'tinymce' => false,
'legend' => ['title' => $this->l('Widgets')],
'input' => [],
'buttons' => [
[
'type' => 'submit',
'title' => $this->l('Save'),
'icon' => 'process-icon-save',
'class' => 'pull-right',
'name' => 'submit'.$this->table
],
[
'type' => 'submit',
'title' => $this->l('Save and stay'),
'icon' => 'process-icon-save',
'class' => 'pull-right',
'name' => 'submit'.$this->table.'AndStay'
],
],
);
$this->fields_form['input'][] = [
'col' => 6,
'type' => 'text',
'name' => 'title',
'label' => $this->l('Title'),
'lang' => true,
];
$this->fields_form['input'][] = [
'type' => 'select',
'label' => $this->l('Show on'),
'name' => 'snow_on',
'options' => ['query' => $values,
'id' => 'id',
'name' => 'name'],
'default' => '',
];
$this->fields_form['input'][] = [
'type' => 'radio',
'label' => $this->l('Sort'),
'name' => 'sort',
'values' => [
[
'id' => 'new',
'value' => 'new',
'label' => $this->l('New')
],
[
'id' => 'popular',
'value' => 'popular',
'label' => $this->l('Popular'),
],
],
];
// $this->fields_form['input'][] = [
// 'type' => 'switch',
// 'name' => 'slider',
// 'label' => $this->l('Slider'),
// 'values' => [
// [
// 'id' => 'slider_on',
// 'value' => 1,
// 'label' => $this->l('Enabled')
// ],
// [
// 'id' => 'slider_off',
// 'value' => 0,
// 'label' => $this->l('Disabled')
// ]
// ],
// ];
$obj = new anblogcat();
$obj->getTree();
$menus = $obj->getDropdown(null, $obj->id_parent, false);
array_shift($menus);
$itemHome['-'] = ['id'=>'', 'title' => '-', 'selected' => ''];
$menus = array_merge($itemHome, $menus);
$this->fields_form['input'][] = [
'type' => 'select',
'label' => $this->l('Category'),
'name' => 'id_anblogcat',
'options' => ['query' => $menus,
'id' => 'id',
'name' => 'title'],
'default' => '',
];
$this->fields_form['input'][] = [
'type' => 'number',
'label' => $this->l('Limit'),
'name' => 'limit',
'lang' => false,
'col' => 2,
'min' => 1,
'max' => 10,
];
if (Shop::isFeatureActive()) {
$this->fields_form['input'][] = [
'required' => true,
'type' => 'shop',
'label' => $this->l('Shop association'),
'name' => 'checkBoxShopAsso',
];
}
$this->fields_form['input'][] = [
'type' => 'radio',
'label' => 'Relation',
'name' => 'relation',
'class' => 'an-sz-type-view',
'form_group_class' => 'js-anblog-relation-group js-anblog-relation',
'values' => [
[
'id' => 'relation_all',
'value' => '0',
'label' => $this->l('All'),
],
[
'id' => 'relation_categories',
'value' => '1',
'label' => $this->l('Categories')
],
[
'id' => 'relation_products',
'value' => '2',
'label' => $this->l('Products')
]
]
];
$this->fields_form['input'][] = array(
'type' => 'anSearchProductsList',
'ignore' => true,
'name' => 'productIds[]',
'class' => 'js-anblog_products js-anblog-searchProducts-components',
'form_group_class' => 'js-anblog-relation-group',
'classSarchInput' => 'js-anblog-search-input',
'label' => '',
'searchProdutsController' => $this->context->link->getAdminLink('AdminAnblogAjax', true, [], ['ajax'=>1, 'action' =>'searchProducts'])
);
$this->fields_form['input'][] = array(
'type' => 'text',
'ignore' => true,
'label' => $this->l('Products'),
'name' => 'products_input',
'size' => 50,
'maxlength' => 50,
'col' => 4,
'class' => 'js-anblog-search-input js-anblog-searchProducts-components',
'form_group_class' => 'js-anblog-relation-group',
'desc' => $this->l('Search for a product by typing the first letters of his name')
);
$this->fields_value['productIds[]'] = anBlogWidgets::getProducsByIdWidgets(Tools::getValue('id_anblog_blog_widgets'));
$this->fields_form['input'][] = [
'type' => 'categories',
'label' => $this->module->l('Categories'),
'name' => 'id_categories',
'class' => 'js-sz-block-categories',
'form_group_class' => 'js-anblog-relation-group',
'tree' => [
'id' => 'id_root_category',
'use_checkbox' => true,
'selected_categories' => anBlogWidgets::getRelationCategories(Tools::getValue('id_anblog_blog_widgets'))
]
];
return parent::renderForm();
}
public function processSave()
{
if (!empty($this->errors)) {
$this->display = 'edit';
return false;
}
$object = parent::processSave();
if (isset($object->id) && $object->id) {
$this->module->registerHook(anBlogWidgets::$showOn[$object->snow_on]['hook']);
// $object->snow_on
switch (Tools::getValue('relation')){
case 1:
$this->updateCategoriesProducts(Tools::getValue('id_categories'), $object->id, 1);
break;
case 2:
$this->updateCategoriesProducts(Tools::getValue('productIds'), $object->id, 2);
break;
default:
$this->updateCategoriesProducts([], $object->id, 0);
}
if (Tools::getIsset('submit'.$this->table.'AndStay')) {
$this->redirect_after = $this->context->link->getAdminLink($this->controller_name).'&conf=4&updateanblog_blog_widgets&token='.$this->token.'&id_anblog_blog_widgets='.$object->id;
}
}
anBlogWidgets::exportJsonWidgets(new anBlogContentTheme());
return $object;
}
public function processDelete()
{
$object = parent::processDelete();
anBlogWidgets::exportJsonWidgets(new anBlogContentTheme());
return $object;
}
public function updateCategoriesProducts($ids = [], $id_anblog_blog_widgets = 0, $type = 0)
{
if (!$id_anblog_blog_widgets){
return false;
}
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('DELETE FROM `'._DB_PREFIX_.'anblog_blog_widgets_relations` WHERE `id_anblog_blog_widgets`='.(int) $id_anblog_blog_widgets.' ');
if (!$ids || count($ids) == 0) {
$ids[] = 0;
}
$ids = array_unique($ids);
foreach ($ids as $id) {
$sql = 'INSERT INTO `'._DB_PREFIX_.'anblog_blog_widgets_relations` (`id_anblog_blog_widgets`, `id_type`, `type`)
VALUES ("'.(int) $id_anblog_blog_widgets.'", "'.(int) $id.'", "'.(int) $type.'" )';
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute($sql);
}
return true;
}
protected function setJsonResponse($response)
{
header('Content-Type: application/json; charset=utf8');
$this->ajaxDie(json_encode($response));
}
protected function updateAssoShop($id_object)
{
if (!Shop::isFeatureActive()) {
return;
}
$assos_data = $this->getSelectedAssoShop($this->table, $id_object);
$exclude_ids = $assos_data;
foreach (Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop') as $row) {
if (!$this->context->employee->hasAuthOnShop($row['id_shop'])) {
$exclude_ids[] = $row['id_shop'];
}
}
Db::getInstance()->delete($this->table . '_shop', '`' . $this->identifier . '` = ' . (int) $id_object . ($exclude_ids ? ' AND id_shop NOT IN (' . implode(', ', $exclude_ids) . ')' : ''));
$insert = array();
foreach ($assos_data as $id_shop) {
$insert[] = array(
$this->identifier => $id_object,
'id_shop' => (int) $id_shop,
);
}
return Db::getInstance()->insert($this->table . '_shop', $insert, false, true, Db::INSERT_IGNORE);
}
protected function getSelectedAssoShop($table)
{
if (!Shop::isFeatureActive()) {
return array();
}
$shops = Shop::getShops(true, null, true);
if (count($shops) == 1 && isset($shops[0])) {
return array($shops[0], 'shop');
}
$assos = array();
if (Tools::isSubmit('checkBoxShopAsso_' . $table)) {
foreach (Tools::getValue('checkBoxShopAsso_' . $table) as $id_shop => $value) {
$assos[] = (int) $id_shop;
}
} else if (Shop::getTotalShops(false) == 1) {
$assos[] = (int) Shop::getContextShopID();
}
return $assos;
}
}