first commit

This commit is contained in:
2024-12-17 13:43:22 +01:00
commit 8e6cd8b410
21292 changed files with 3514826 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
if (!defined('_PS_VERSION_'))
exit;
class MM_Block extends MM_Obj
{
public $id_block;
public $title;
public $title_link;
public $content;
public $enabled;
public $sort_order;
public $id_categories;
public $order_by_category;
public $id_manufacturers;
public $order_by_manufacturers;
public $display_mnu_img;
public $display_mnu_name;
public $display_mnu_inline;
public $id_suppliers;
public $order_by_suppliers;
public $display_suppliers_img;
public $display_suppliers_name;
public $display_suppliers_inline;
public $id_cmss;
public $block_type;
public $image;
public $custom_class;
public $display_title;
public $id_column;
public $image_link;
public $product_type;
public $id_products;
public $product_count;
public $combination_enabled;
public $show_description;
public $show_clock;
public static $definition = array(
'table' => 'ets_mm_block',
'primary' => 'id_block',
'multilang' => true,
'fields' => array(
'sort_order' => array('type' => self::TYPE_INT),
'id_column' => array('type' => self::TYPE_INT),
'id_categories' => array('type' => self::TYPE_STRING),
'order_by_category' => array('type' => self::TYPE_STRING),
'id_manufacturers' => array('type' => self::TYPE_STRING),
'order_by_manufacturers' => array('type' => self::TYPE_STRING),
'display_mnu_img' => array('type' => self::TYPE_INT),
'display_mnu_name' => array('type' => self::TYPE_INT),
'display_mnu_inline' => array('type' => self::TYPE_STRING),
'id_suppliers' => array('type' => self::TYPE_STRING),
'order_by_suppliers' => array('type' => self::TYPE_STRING),
'display_suppliers_img' => array('type' => self::TYPE_INT),
'display_suppliers_name' => array('type' => self::TYPE_INT),
'display_suppliers_inline' => array('type' => self::TYPE_STRING),
'id_cmss' => array('type' => self::TYPE_STRING),
'product_type' => array('type' => self::TYPE_STRING),
'id_products' => array('type' => self::TYPE_STRING),
'product_count' => array('type' => self::TYPE_INT),
'enabled' => array('type' => self::TYPE_INT),
'image' => array('type' => self::TYPE_STRING,'lang' => false),
'block_type' => array('type' => self::TYPE_STRING),
'display_title' => array('type' => self::TYPE_INT),
'show_description' => array('type' => self::TYPE_INT),
'show_clock' => array('type' => self::TYPE_INT),
// Lang fields
'title' => array('type' => self::TYPE_STRING, 'lang' => true),
'title_link' => array('type' => self::TYPE_STRING, 'lang' => true),
'image_link' => array('type' => self::TYPE_STRING, 'lang' => true),
'content' => array('type' => self::TYPE_HTML, 'lang' => true),
)
);
public function __construct($id_item = null, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::__construct($id_item, $id_lang, $id_shop);
$languages = Language::getLanguages(false);
foreach($languages as $lang)
{
foreach(self::$definition['fields'] as $field => $params)
{
$temp = $this->$field;
if(isset($params['lang']) && $params['lang'] && !isset($temp[$lang['id_lang']]))
{
$temp[$lang['id_lang']] = '';
}
$this->$field = $temp;
}
}
unset($context);
$this->setFields(Ets_megamenu::$blocks);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
class MM_Cache {
private $expire = 1;
public function __construct()
{
$this->expire = (int)Configuration::get('ETS_MM_CACHE_LIFE_TIME') >=1 ? (int)Configuration::get('ETS_MM_CACHE_LIFE_TIME') : 1;
}
public function get($key) {
$files = glob(dirname(__FILE__).'/../cache/' . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');
if ($files) {
$cache = Tools::file_get_contents($files[0]);
foreach ($files as $file) {
$time = (int)Tools::substr(strrchr($file, '.'), 1);
if ($time*3600 < time()) {
if (file_exists($file)) {
@unlink($file);
}
}
}
return $cache;
}
return false;
}
public function set($key, $value) {
$this->delete($key);
$file = dirname(__FILE__).'/../cache/' . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.' . (time() + (int)$this->expire*3600);
$handle = fopen($file, 'w');
fwrite($handle, $value ? $value : '');
fclose($handle);
}
public function delete($key = false) {
$files = glob(dirname(__FILE__).'/../cache/' . ($key ? 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) : '') . '.*');
if ($files) {
foreach ($files as $file) {
if (file_exists($file) && strpos($file,'index.php')===false) {
unlink($file);
}
}
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
if (!defined('_PS_VERSION_'))
exit;
class MM_Column extends MM_Obj
{
public $id_column;
public $id_menu;
public $id_tab;
public $column_size;
public $sort_order;
public $is_breaker;
public static $definition = array(
'table' => 'ets_mm_column',
'primary' => 'id_column',
'multilang' => false,
'fields' => array(
'id_menu' => array('type' => self::TYPE_INT),
'id_tab' => array('type' => self::TYPE_INT),
'column_size' => array('type' => self::TYPE_STRING),
'sort_order' => array('type' => self::TYPE_INT),
'is_breaker' => array('type' => self::TYPE_INT),
)
);
public function __construct($id_item = null, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::__construct($id_item, $id_lang, $id_shop);
$languages = Language::getLanguages(false);
foreach($languages as $lang)
{
foreach(self::$definition['fields'] as $field => $params)
{
$temp = $this->$field;
if(isset($params['lang']) && $params['lang'] && !isset($temp[$lang['id_lang']]))
{
$temp[$lang['id_lang']] = '';
}
$this->$field = $temp;
}
}
unset($context);
$this->setFields(Ets_megamenu::$columns);
}
}

View File

@@ -0,0 +1,331 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
if (!defined('_PS_VERSION_'))
exit;
class MM_Config
{
public $fields;
public function setFields($fields)
{
$this->fields = $fields;
}
public function __construct()
{
$this->context=Context::getContext();
$this->setFields(Ets_megamenu::$configs);
}
public function renderForm()
{
$helper = new HelperForm();
$helper->module = new Ets_megamenu();
$configs = $this->fields['configs'];
$fields_form = array();
$fields_form['form'] = $this->fields['form'];
if($configs)
{
foreach($configs as $key => $config)
{
$confFields = array(
'name' => $key,
'type' => $config['type'],
'label' => $config['label'],
'desc' => isset($config['desc']) ? $config['desc'] : false,
'required' => isset($config['required']) && $config['required'] ? true : false,
'autoload_rte' => isset($config['autoload_rte']) && $config['autoload_rte'] ? true : false,
'options' => isset($config['options']) && $config['options'] ? $config['options'] : array(),
'suffix' => isset($config['suffix']) && $config['suffix'] ? $config['suffix'] : false,
'values' => isset($config['values']) ? $config['values'] : false,
'lang' => isset($config['lang']) ? $config['lang'] : false,
'class' => isset($config['class']) ? $config['class'] : '',
'form_group_class' => isset($config['form_group_class']) ? $config['form_group_class'] : '',
'hide_delete' => isset($config['hide_delete']) ? $config['hide_delete'] : false,
'display_img' => isset($config['type']) && $config['type']=='file' && Configuration::get($key)!='' && @file_exists(dirname(__FILE__).'/../views/img/upload/'.Configuration::get($key)) ? $helper->module->modulePath().'views/img/upload/'.Configuration::get($key) : false,
'img_del_link' => isset($config['type']) && $config['type']=='file' && Configuration::get($key)!='' && @file_exists(dirname(__FILE__).'/../views/img/upload/'.Configuration::get($key)) ? $helper->module->baseAdminUrl().'&deleteimage='.$key.'&itemId=0&mm_object=MM_'.Tools::ucfirst($fields_form['form']['name']) : false,
);
if(isset($config['tree']) && $config['tree'])
{
$confFields['tree'] = $config['tree'];
if(isset($config['tree']['use_checkbox']) && $config['tree']['use_checkbox'])
$confFields['tree']['selected_categories'] = explode(',',Configuration::get($key));
else
$confFields['tree']['selected_categories'] = array(Configuration::get($key));
}
if(!$confFields['suffix'])
unset($confFields['suffix']);
$fields_form['form']['input'][] = $confFields;
}
}
$helper->show_toolbar = false;
$helper->table = false;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->identifier = 'mm_form_'.$this->fields['form']['name'];
$helper->submit_action = 'save_'.$this->fields['form']['name'];
$link = new Link();
$helper->currentIndex = $link->getAdminLink('AdminModules', true).'&configure=ets_megamenu';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$fields = array();
$languages = Language::getLanguages(false);
$helper->override_folder = '/';
if(Tools::isSubmit('save_'.$this->fields['form']['name']))
{
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['lang']) && $config['lang'])
{
foreach($languages as $l)
{
$fields[$key][$l['id_lang']] = Tools::getValue($key.'_'.$l['id_lang'],isset($config['default']) ? $config['default'] : '');
}
}
else
$fields[$key] = Tools::getValue($key,isset($config['default']) ? $config['default'] : '');
}
}
}
else
{
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['lang']) && $config['lang'])
{
foreach($languages as $l)
{
$fields[$key][$l['id_lang']] = Configuration::get($key,$l['id_lang']);
}
}
else
$fields[$key] = Configuration::get($key);
}
}
}
$helper->tpl_vars = array(
'base_url' => Context::getContext()->shop->getBaseURL(),
'language' => array(
'id_lang' => $language->id,
'iso_code' => $language->iso_code
),
'fields_value' => $fields,
'languages' => Context::getContext()->controller->getLanguages(),
'id_language' => Context::getContext()->language->id,
'mm_object' => 'MM_'.Tools::ucfirst($fields_form['form']['name']),
'image_baseurl' => $helper->module->modulePath().'views/img/',
'mm_clear_cache_url' => $helper->module->baseAdminUrl(),
'reset_default' => true,
);
return str_replace(array('id="ets_mm_menu_form"','id="fieldset_0"'),'',$helper->generateForm(array($fields_form)));
}
public function saveData()
{
$errors = array();
$success = array();
$languages = Language::getLanguages(false);
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
$configs = $this->fields['configs'];
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['lang']) && $config['lang'])
{
if(isset($config['required']) && $config['required'] && $config['type']!='switch' && trim(Tools::getValue($key.'_'.$id_lang_default) == ''))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
}
}
else
{
if(isset($config['required']) && $config['required'] && isset($config['type']) && $config['type']=='file')
{
if(Configuration::get($key)=='' && (!isset($_FILES[$key]['size']) || isset($_FILES[$key]['size']) && !$_FILES[$key]['size']))
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
elseif(isset($_FILES[$key]['size']))
{
$fileSize = round((int)$_FILES[$key]['size'] / (1024 * 1024));
if($fileSize > 100)
$errors[] = $config['label'].' '.Ets_megamenu::$trans['file_too_large'];
}
}
else
{
if(isset($config['required']) && $config['required'] && $config['type']!='switch' && trim(Tools::getValue($key) == ''))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
}
elseif(!is_array(Tools::getValue($key)) && isset($config['validate']) && method_exists('Validate',$config['validate']))
{
$validate = $config['validate'];
if(trim(Tools::getValue($key)) && !Validate::$validate(trim(Tools::getValue($key))))
$errors[] = $config['label'].' '.Ets_megamenu::$trans['invalid_text'];
unset($validate);
}
elseif(!Validate::isCleanHtml(trim(Tools::getValue($key))))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
}
}
}
}
}
if(!$errors)
{
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['lang']) && $config['lang'])
{
$valules = array();
foreach($languages as $lang)
{
if($config['type']=='switch')
$valules[$lang['id_lang']] = (int)trim(Tools::getValue($key.'_'.$lang['id_lang'])) ? 1 : 0;
else
$valules[$lang['id_lang']] = trim(Tools::getValue($key.'_'.$lang['id_lang'])) ? trim(Tools::getValue($key.'_'.$lang['id_lang'])) : trim(Tools::getValue($key.'_'.$id_lang_default));
}
Configuration::updateValue($key,$valules,true);
}
elseif($config['type']=='switch')
{
Configuration::updateValue($key,(int)Tools::getValue($key) ? 1 : 0);
}
elseif($config['type']=='file')
{
//Upload file
if(isset($_FILES[$key]['tmp_name']) && isset($_FILES[$key]['name']) && $_FILES[$key]['name'])
{
$salt = Tools::substr(sha1(microtime()),0,10);
$type = Tools::strtolower(Tools::substr(strrchr($_FILES[$key]['name'], '.'), 1));
$imageName = @file_exists(dirname(__FILE__).'/../views/img/upload/'.Tools::strtolower($_FILES[$key]['name'])) ? $salt.'-'.Tools::strtolower($_FILES[$key]['name']) : Tools::strtolower($_FILES[$key]['name']);
$fileName = dirname(__FILE__).'/../views/img/upload/'.$imageName;
if(file_exists($fileName))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['file_existed'];
}
else
{
$imagesize = @getimagesize($_FILES[$key]['tmp_name']);
if (!$errors && isset($_FILES[$key]) &&
!empty($_FILES[$key]['tmp_name']) &&
!empty($imagesize) &&
in_array($type, array('jpg', 'gif', 'jpeg', 'png'))
)
{
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if ($error = ImageManager::validateUpload($_FILES[$key]))
$errors[] = $error;
elseif (!$temp_name || !move_uploaded_file($_FILES[$key]['tmp_name'], $temp_name))
$errors[] = Ets_megamenu::$trans['can_not_upload'];
elseif (!ImageManager::resize($temp_name, $fileName, null, null, $type))
$errors[] = Ets_megamenu::$trans['upload_error_occurred'];
if (isset($temp_name))
@unlink($temp_name);
if(!$errors)
{
if(Configuration::get($key)!='')
{
$oldImage = dirname(__FILE__).'/../views/img/upload/'.Configuration::get($key);
if(file_exists($oldImage))
@unlink($oldImage);
}
Configuration::updateValue($key,$imageName);
}
}
}
}
//End upload file
}
elseif($config['type']=='categories' && isset($config['tree']['use_checkbox']) && $config['tree']['use_checkbox'] || $config['type']=='checkbox')
Configuration::updateValue($key,implode(',',Tools::getValue($key)));
else
Configuration::updateValue($key,(Tools::getValue($key)));
}
}
}
if(!$errors)
{
$success[] = Ets_megamenu::$trans['data_saved'];
if(Configuration::get('ETS_MM_CACHE_ENABLED')) Ets_megamenu::clearAllCache();
}
return array('errors' => $errors, 'success' => $success);
}
public function getConfig()
{
$configs = $this->fields['configs'];
$data = array();
if($configs)
foreach($configs as $key => $config)
{
$data[$key] = isset($config['lang']) && $config['lang'] ? Configuration::get($key,$this->context->language->id) : Configuration::get($key);
}
return $data;
}
public function installConfigs($upgrade = false)
{
$configs = $this->fields['configs'];
$languages = Language::getLanguages(false);
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['lang']) && $config['lang'])
{
$values = array();
foreach($languages as $lang)
{
$values[$lang['id_lang']] = isset($config['default']) ? $config['default'] : '';
}
if ($upgrade && !Configuration::hasKey($key) || !$upgrade)
{
Configuration::updateValue($key, $values, true);
}
}
elseif ($upgrade && !Configuration::hasKey($key) || !$upgrade)
{
Configuration::updateValue($key, isset($config['default']) ? $config['default'] : '',true);
}
}
}
return true;
}
public function unInstallConfigs()
{
if($this->fields['configs'])
{
foreach($this->fields['configs'] as $key => $config)
{
Configuration::deleteByName($key);
unset($config);
}
}
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
if (!defined('_PS_VERSION_'))
exit;
class MM_Menu extends MM_Obj
{
public $id_menu;
public $title;
public $link;
public $enabled;
public $menu_open_new_tab;
public $menu_ver_hidden_border;
public $menu_ver_alway_show;
public $menu_ver_alway_open_first;
public $sort_order;
public $id_category;
public $id_manufacturer;
public $id_supplier;
public $id_cms;
public $link_type;
public $sub_menu_type;
public $sub_menu_max_width;
public $custom_class;
public $menu_icon;
public $menu_img_link;
public $bubble_text;
public $bubble_text_color;
public $bubble_background_color;
public $menu_ver_text_color;
public $menu_ver_background_color;
public $enabled_vertical;
public $menu_item_width;
public $tab_item_width;
public $background_image;
public $position_background;
public $display_tabs_in_full_width;
public static $definition = array(
'table' => 'ets_mm_menu',
'primary' => 'id_menu',
'multilang' => true,
'fields' => array(
'sort_order' => array('type' => self::TYPE_INT),
'id_category' => array('type' => self::TYPE_INT),
'id_manufacturer' => array('type' => self::TYPE_INT),
'id_supplier'=>array('type'=>self::TYPE_INT),
'id_cms' => array('type' => self::TYPE_INT),
'sub_menu_type' => array('type' => self::TYPE_STRING),
'link_type' => array('type' => self::TYPE_STRING),
'sub_menu_max_width' => array('type' => self::TYPE_STRING),
'custom_class' => array('type' => self::TYPE_STRING),
'bubble_text_color' => array('type' => self::TYPE_STRING),
'bubble_background_color' => array('type' => self::TYPE_STRING),
'menu_ver_text_color' => array('type' => self::TYPE_STRING),
'menu_item_width' => array('type' => self::TYPE_STRING),
'tab_item_width'=> array('type'=>self::TYPE_STRING),
'menu_ver_background_color' => array('type' => self::TYPE_STRING),
'menu_ver_hidden_border'=>array('type'=>self::TYPE_INT),
'menu_ver_alway_show'=>array('type'=>self::TYPE_INT),
'menu_ver_alway_open_first'=>array('type'=>self::TYPE_INT),
'enabled' => array('type' => self::TYPE_INT),
'menu_open_new_tab' => array('type' => self::TYPE_INT),
'menu_icon' => array('type' => self::TYPE_STRING, 'lang' => false, 'validate' => 'isCleanHtml'),
'menu_img_link' => array('type' => self::TYPE_STRING, 'lang' => false),
'enabled_vertical' => array('type'=>self::TYPE_INT),
'background_image' => array('type' => self::TYPE_STRING),
'position_background' => array('type' => self::TYPE_STRING),
'display_tabs_in_full_width'=> array('type' => self::TYPE_INT),
// Lang fields
'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true),
'link' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml'),
'bubble_text' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml'),
)
);
public function __construct($id_item = null, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::__construct($id_item, $id_lang, $id_shop);
$languages = Language::getLanguages(false);
foreach($languages as $lang)
{
foreach(self::$definition['fields'] as $field => $params)
{
$temp = $this->$field;
if(isset($params['lang']) && $params['lang'] && !isset($temp[$lang['id_lang']]))
{
$temp[$lang['id_lang']] = '';
}
$this->$field = $temp;
}
}
$this->context = $context;
$this->setFields(Ets_megamenu::$menus);
}
public function add($autodate = true, $null_values = false, $id_shop = null)
{
$context = Context::getContext();
if (!$id_shop)
$id_shop = $context->shop->id;
$res = parent::add($autodate, $null_values);
$res &= Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'ets_mm_menu_shop` (`id_shop`, `id_menu`)
VALUES('.(int)$id_shop.', '.(int)$this->id.')'
);
return $res;
}
}

View File

@@ -0,0 +1,710 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
if (!defined('_PS_VERSION_'))
exit;
class MM_Obj extends ObjectModel
{
public $fields;
public function setFields($fields)
{
$this->fields = $fields;
}
public function renderForm()
{
$helper = new HelperForm();
$helper->module = new Ets_megamenu();
$configs = $this->fields['configs'];
$fields_form = array();
$fields_form['form'] = $this->fields['form'];
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['type']) && in_array($config['type'],array('sort_order')))
continue;
$confFields = array(
'name' => $key,
'type' => $config['type'],
'class'=>isset($config['class'])?$config['class']:'',
'label' => $config['label'],
'desc' => isset($config['desc']) ? $config['desc'] : false,
'required' => isset($config['required']) && $config['required'] ? true : false,
'autoload_rte' => isset($config['autoload_rte']) && $config['autoload_rte'] ? true : false,
'options' => isset($config['options']) && $config['options'] ? $config['options'] : array(),
'suffix' => isset($config['suffix']) && $config['suffix'] ? $config['suffix'] : false,
'values' => isset($config['values']) ? $config['values'] : false,
'lang' => isset($config['lang']) ? $config['lang'] : false,
'showRequired' => isset($config['showRequired']) && $config['showRequired'],
'hide_delete' => isset($config['hide_delete']) ? $config['hide_delete'] : false,
'placeholder' => isset($config['placeholder']) ? $config['placeholder'] : false,
'display_img' => $this->id && isset($config['type']) && $config['type']=='file' && $this->$key!='' && @file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->$key) ? $helper->module->modulePath().'views/img/upload/'.$this->$key : false,
'img_del_link' => $this->id && isset($config['type']) && $config['type']=='file' && $this->$key!='' && @file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->$key) ? $helper->module->baseAdminUrl().'&deleteimage='.$key.'&itemId='.(isset($this->id)?$this->id:'0').'&mm_object=MM_'.Tools::ucfirst($fields_form['form']['name']) : false,
);
if(isset($config['tree']) && $config['tree'])
{
$confFields['tree'] = $config['tree'];
if(isset($config['tree']['use_checkbox']) && $config['tree']['use_checkbox'])
$confFields['tree']['selected_categories'] = explode(',',$this->$key);
else
$confFields['tree']['selected_categories'] = array($this->$key);
}
if(!$confFields['suffix'])
unset($confFields['suffix']);
$fields_form['form']['input'][] = $confFields;
}
}
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->identifier = $this->identifier;
$helper->submit_action = 'save_'.$this->fields['form']['name'];
$link = new Link();
$helper->currentIndex = $link->getAdminLink('AdminModules', true).'&configure=ets_megamenu';
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$fields = array();
$languages = Language::getLanguages(false);
$helper->override_folder = '/';
if($configs)
{
foreach($configs as $key => $config)
{
if($config['type']=='checkbox')
$fields[$key] = $this->id ? explode(',',$this->$key) : (isset($config['default']) && $config['default'] ? $config['default'] : array());
elseif(isset($config['lang']) && $config['lang'])
{
foreach($languages as $l)
{
$temp = $this->$key;
$fields[$key][$l['id_lang']] = $this->id ? $temp[$l['id_lang']] : (isset($config['default']) && $config['default'] ? $config['default'] : null);
}
}
elseif(!isset($config['tree']))
$fields[$key] = $this->id ? $this->$key : (isset($config['default']) && $config['default'] ? $config['default'] : null);
}
}
$helper->tpl_vars = array(
'base_url' => Context::getContext()->shop->getBaseURL(),
'language' => array(
'id_lang' => $language->id,
'iso_code' => $language->iso_code
),
'fields_value' => $fields,
'languages' => Context::getContext()->controller->getLanguages(),
'id_language' => Context::getContext()->language->id,
'key_name' => 'id_'.$fields_form['form']['name'],
'item_id' => $this->id,
'mm_object' => 'MM_'.Tools::ucfirst($fields_form['form']['name']),
'list_item' => true,
'image_baseurl' => $helper->module->modulePath().'views/img/',
);
return str_replace(array('id="ets_mm_menu_form"','id="fieldset_0"'),'',$helper->generateForm(array($fields_form)));
}
public function getFieldVals()
{
if(!$this->id)
return array();
$vals = array();
foreach($this->fields['configs'] as $key => $config)
{
if(property_exists($this,$key))
{
if(isset($config['lang'])&&$config['lang'])
{
$val_lang= $this->$key;
$vals[$key]=$val_lang[Context::getContext()->language->id];
}
else
$vals[$key] = $this->$key;
}
}
$vals['id_'.$this->fields['form']['name']] = (int)$this->id;
unset($config);
return $vals;
}
public function clearImage($image)
{
$configs = $this->fields['configs'];
$errors = array();
$success = array();
if(!$this->id)
$errors[] = Ets_megamenu::$trans['object_empty'];
elseif(!isset($configs[$image]['type']) || isset($configs[$image]['type']) && $configs[$image]['type']!='file')
$errors[] = Ets_megamenu::$trans['field_not_valid'];
elseif(isset($configs[$image]) && !isset($configs[$image]['required']) || (isset($configs[$image]['required']) && !$configs[$image]['required']))
{
$imageName = $this->$image;
$imagePath = dirname(__FILE__).'/../views/img/upload/'.$imageName;
if($imageName && file_exists($imagePath) && !Ets_megamenu::imageExits($imageName,$this->id))
{
@unlink($imagePath);
$this->$image = '';
if($this->update())
{
$success[] = Ets_megamenu::$trans['image_deleted'];
if(Configuration::get('ETS_MM_CACHE_ENABLED'))
Ets_megamenu::clearAllCache();
}
else
$errors[] = Ets_megamenu::$trans['unkown_error'];
}
}
else
$errors[] = $configs[$image]['label']. Ets_megamenu::$trans['required_text'];
return array('errors' => $errors,'success' => $success);
}
public function deleteObj()
{
$errors = array();
$success = array();
$configs = $this->fields['configs'];
$parent=isset($this->fields['form']['parent'])?$this->fields['form']['parent']:'1';
$images = array();
foreach($configs as $key => $config)
{
if($config['type']=='file' && $this->$key && @file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->$key) && !Ets_megamenu::imageExits($this->$key,$this->id))
$images[] = dirname(__FILE__).'/../views/img/upload/'.$this->$key;
}
if(!$this->delete())
$errors[] = Ets_megamenu::$trans['cannot_delete'];
else
{
foreach($images as $image)
@unlink($image);
$success[] = Ets_megamenu::$trans['item_deleted'];
if(Configuration::get('ETS_MM_CACHE_ENABLED'))
Ets_megamenu::clearAllCache();
if(isset($configs['sort_order']) && $configs['sort_order'])
{
Db::getInstance()->execute("
UPDATE "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['name'])."
SET sort_order=sort_order-1
WHERE sort_order>".(int)$this->sort_order." ".(isset($configs['sort_order']['order_group'][$parent]) && ($orderGroup = $configs['sort_order']['order_group'][$parent]) ? " AND ".pSQL($orderGroup)."=".(int)$this->$orderGroup : "")."
");
}
if($this->id && isset($this->fields['form']['connect_to2']) && $this->fields['form']['connect_to2']
&& ($subs = Db::getInstance()->executeS("SELECT id_".pSQL($this->fields['form']['connect_to2'])." FROM "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['connect_to2']). " WHERE id_".pSQL($this->fields['form']['name'])."=".(int)$this->id)))
{
foreach($subs as $sub)
{
$className = 'MM_'.Tools::ucfirst(Tools::strtolower($this->fields['form']['connect_to2']));
if(class_exists($className))
{
$obj = new $className((int)$sub['id_'.$this->fields['form']['connect_to2']]);
$obj->deleteObj();
}
}
}
if($this->id && isset($this->fields['form']['connect_to']) && $this->fields['form']['connect_to']
&& ($subs = Db::getInstance()->executeS("SELECT id_".pSQL($this->fields['form']['connect_to'])." FROM "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['connect_to']). " WHERE id_".pSQL($this->fields['form']['name'])."=".(int)$this->id)))
{
foreach($subs as $sub)
{
$className = 'MM_'.Tools::ucfirst(Tools::strtolower($this->fields['form']['connect_to']));
if(class_exists($className))
{
$obj = new $className((int)$sub['id_'.$this->fields['form']['connect_to']]);
$obj->deleteObj();
}
}
}
}
return array('errors' => $errors,'success' => $success);
}
public function maxVal($key,$group = false, $groupval=0)
{
return ($max = Db::getInstance()->getValue("SELECT max(".pSQL($key).") FROM "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['name']).($group && ($groupval > 0) ? " WHERE ".pSQL($group)."=".(int)$groupval : ''))) ? (int)$max : 0;
}
public function updateOrder($previousId = 0, $groupdId = 0,$parentObj='')
{
$group = isset($this->fields['configs']['sort_order']['order_group'][$parentObj]) && $this->fields['configs']['sort_order']['order_group'][$parentObj] ? $this->fields['configs']['sort_order']['order_group'][$parentObj] : false;
if(!$groupdId && $group)
$groupdId = $this->$group;
$oldOrder = $this->sort_order;
if($group && $groupdId && property_exists($this,$group) && $this->$group != $groupdId)
{
Db::getInstance()->execute("
UPDATE "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['name'])."
SET sort_order=sort_order-1
WHERE sort_order>".(int)$this->sort_order." AND id_".pSQL($this->fields['form']['name'])."!=".(int)$this->id."
".($group && $groupdId ? " AND ".pSQL($group)."=".(int)$this->$group : ""));
$this->$group = $groupdId;
if($parentObj=='tab')
{
$tab= new MM_Tab($groupdId);
$this->id_menu = $tab->id_menu;
}
if($parentObj=='menu')
{
$this->id_tab=0;
}
$changeGroup = true;
}
else
$changeGroup = false;
if($previousId > 0)
{
$objName = 'MM_'.Tools::ucfirst($this->fields['form']['name']);
$obj = new $objName($previousId);
if($obj->sort_order > 0)
$this->sort_order = $obj->sort_order+1;
else
$this->sort_order = 1;
}
else
$this->sort_order = 1;
if($this->update())
{
Db::getInstance()->execute("
UPDATE "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['name'])."
SET sort_order=sort_order+1
WHERE sort_order>=".(int)$this->sort_order." AND id_".pSQL($this->fields['form']['name'])."!=".(int)$this->id."
".($group && $groupdId ? " AND ".pSQL($group)."=".(int)$this->$group : ""));
if(!$changeGroup && $this->sort_order!=$oldOrder)
{
$rs = Db::getInstance()->execute("
UPDATE "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['name'])."
SET sort_order=sort_order-1
WHERE sort_order>".($this->sort_order > $oldOrder ? (int)($oldOrder) : (int)($oldOrder+1)).($group && $groupdId ? " AND ".pSQL($group)."=".(int)$this->$group : ""));
if(Configuration::get('ETS_MM_CACHE_ENABLED'))
Ets_megamenu::clearAllCache();
return $rs;
}
if(Configuration::get('ETS_MM_CACHE_ENABLED'))
Ets_megamenu::clearAllCache();
return true;
}
return false;
}
public function saveData()
{
$errors = array();
$success = array();
$languages = Language::getLanguages(false);
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
$parent=isset($this->fields['form']['parent'])?$this->fields['form']['parent']:'1';
$configs = $this->fields['configs'];
if($configs)
{
foreach($configs as $key => $config)
{
if($config['type']=='sort_order')
continue;
if(isset($config['lang']) && $config['lang'])
{
if(isset($config['required']) && $config['required'] && $config['type']!='switch' && trim(Tools::getValue($key.'_'.$id_lang_default) == ''))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
}
}
else
{
if(isset($config['required']) && $config['required'] && isset($config['type']) && $config['type']=='file')
{
if($this->$key=='' && !isset($_FILES[$key]['size']))
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
elseif(isset($_FILES[$key]['size']))
{
$fileSize = round((int)$_FILES[$key]['size'] / (1024 * 1024));
if($fileSize > 100)
$errors[] = $config['label'].' '.Ets_megamenu::$trans['file_too_large'];
}
}
else
{
if(isset($config['required']) && $config['required'] && $config['type']!='switch' && trim(Tools::getValue($key) == ''))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
}
elseif(!is_array(Tools::getValue($key)) && isset($config['validate']) && method_exists('Validate',$config['validate']))
{
$validate = $config['validate'];
if(!Validate::$validate(trim(Tools::getValue($key))))
$errors[] = $config['label'].' '.Ets_megamenu::$trans['invalid_text'];
unset($validate);
}
elseif(!Validate::isCleanHtml(trim(Tools::getValue($key))))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['required_text'];
}
}
}
}
}
//Custom validation
if($this->fields['form']['name']=='menu')
{
switch(Tools::getValue('link_type'))
{
case 'CUSTOM':
if(trim(Tools::getValue('link_'.$id_lang_default))=='')
$errors[] = Ets_megamenu::$trans['custom_link_required_text'];
break;
case 'CMS':
if(!(int)Tools::getValue('id_cms'))
$errors[] = Ets_megamenu::$trans['cms_required_text'];
break;
case 'CATEGORY':
if(!(int)Tools::getValue('id_category'))
$errors[] = Ets_megamenu::$trans['category_required_text'];
break;
case 'MNFT':
if(!(int)Tools::getValue('id_manufacturer'))
$errors[] = Ets_megamenu::$trans['manufacturer_required_text'];
break;
case 'MNSP':
if(!(int)Tools::getValue('id_supplier'))
$errors[] = Ets_megamenu::$trans['supplier_required_text'];
break;
case 'CONTACT':
break;
case 'HOME':
break;
default:
$errors[] = Ets_megamenu::$trans['link_type_not_valid_text'];
break;
}
if(Tools::strlen(Tools::getValue('sub_menu_max_width'))<1 || Tools::strlen(Tools::getValue('sub_menu_max_width')) > 50)
$errors[] = Ets_megamenu::$trans['sub_menu_width_invalid'].'2';
foreach($languages as $lang)
{
if($bubble_text = Tools::getValue('bubble_text_'.$lang['id_lang']))
{
if(Tools::strlen($bubble_text) > 50)
{
$errors[] = Ets_megamenu::$trans['bubble_text_is_too_long'];
}
$bubble_text_entered = true;
}
}
if(isset($bubble_text_entered) && $bubble_text_entered)
{
if(!Tools::getValue('bubble_text_color'))
$errors[] = Ets_megamenu::$trans['bubble_text_color_is_required'];
if(!Tools::getValue('bubble_background_color'))
$errors[] = Ets_megamenu::$trans['bubble_background_color_is_required'];
}
}
if($this->fields['form']['name']=='block')
{
switch(Tools::getValue('block_type'))
{
case 'HTML':
if(trim(Tools::getValue('content_'.$id_lang_default))=='')
$errors[] = Ets_megamenu::$trans['content_required_text'];
break;
case 'CMS':
if(!Tools::getValue('id_cmss'))
$errors[] = Ets_megamenu::$trans['cmss_required_text'];
break;
case 'CATEGORY':
if(!Tools::getValue('id_categories'))
$errors[] = Ets_megamenu::$trans['categories_required_text'];
break;
case 'MNFT':
if(!Tools::getValue('id_manufacturers'))
$errors[] = Ets_megamenu::$trans['manufacturers_required_text'];
break;
case 'MNSP':
if(!Tools::getValue('id_suppliers'))
$errors[] = Ets_megamenu::$trans['suppliers_required_text'];
break;
case 'PRODUCT':
if (Tools::getValue('product_type', false) == 'specific')
{
if(!Tools::getValue('id_products', false))
$errors[] = Ets_megamenu::$trans['products_required_text'];
}
else
{
if(!Tools::getValue('product_count', false))
$errors[] = Ets_megamenu::$trans['product_count_required_text'];
elseif(!Validate::isUnsignedId(Tools::getValue('product_count')))
$errors[] = Ets_megamenu::$trans['product_count_not_valid_text'];
}
break;
case 'IMAGE':
if($this->image=='' && (!isset($_FILES['image']['size']) || isset($_FILES['image']['size']) && !$_FILES['image']['size']))
$errors[] = Ets_megamenu::$trans['image_required_text'];
break;
default:
$errors[] = Ets_megamenu::$trans['block_type_not_valid_text'];
break;
}
}
if(!$errors)
{
if($configs)
{
foreach($configs as $key => $config)
{
if(isset($config['type']) && $config['type']=='sort_order')
{
if(!$this->id)
{
if(!isset($config['order_group'][$parent]) || isset($config['order_group'][$parent]) && !$config['order_group'][$parent])
$this->$key = $this->maxVal($key)+1;
else
{
$orderGroup = $config['order_group'][$parent];
$this->$key = $this->maxVal($key,$orderGroup,(int)$this->$orderGroup)+1;
}
}
}
elseif(isset($config['lang']) && $config['lang'])
{
$valules = array();
foreach($languages as $lang)
{
if($config['type']=='switch')
$valules[$lang['id_lang']] = (int)trim(Tools::getValue($key.'_'.$lang['id_lang'])) ? 1 : 0;
else
$valules[$lang['id_lang']] = trim(Tools::getValue($key.'_'.$lang['id_lang'])) ? trim(Tools::getValue($key.'_'.$lang['id_lang'])) : trim(Tools::getValue($key.'_'.$id_lang_default));
}
$this->$key = $valules;
}
elseif($config['type']=='switch')
{
$this->$key = (int)Tools::getValue($key) ? 1 : 0;
}
elseif($config['type']=='file')
{
//Upload file
if(isset($_FILES[$key]['tmp_name']) && isset($_FILES[$key]['name']) && $_FILES[$key]['name'])
{
$salt = Tools::substr(sha1(microtime()),0,10);
$type = Tools::strtolower(Tools::substr(strrchr($_FILES[$key]['name'], '.'), 1));
$imageName = @file_exists(dirname(__FILE__).'/../views/img/upload/'.Tools::strtolower($_FILES[$key]['name']))|| Tools::strtolower($_FILES[$key]['name'])==$this->$key ? $salt.'-'.Tools::strtolower($_FILES[$key]['name']) : Tools::strtolower($_FILES[$key]['name']);
$fileName = dirname(__FILE__).'/../views/img/upload/'.$imageName;
if(file_exists($fileName))
{
$errors[] = $config['label'].' '.Ets_megamenu::$trans['file_existed'];
}
else
{
$imagesize = @getimagesize($_FILES[$key]['tmp_name']);
if (!$errors && isset($_FILES[$key]) &&
!empty($_FILES[$key]['tmp_name']) &&
!empty($imagesize) &&
in_array($type, array('jpg', 'gif', 'jpeg', 'png'))
)
{
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if ($error = ImageManager::validateUpload($_FILES[$key]))
$errors[] = $error;
elseif (!$temp_name || !move_uploaded_file($_FILES[$key]['tmp_name'], $temp_name))
$errors[] = Ets_megamenu::$trans['can_not_upload'];
elseif (!ImageManager::resize($temp_name, $fileName, null, null, $type))
$errors[] = Ets_megamenu::$trans['upload_error_occurred'];
if (isset($temp_name))
@unlink($temp_name);
if(!$errors)
{
if($this->$key!='')
{
$oldImage = dirname(__FILE__).'/../views/img/upload/'.$this->$key;
if(file_exists($oldImage) && !Ets_megamenu::imageExits($this->$key,$this->id))
@unlink($oldImage);
}
$this->$key = $imageName;
}
}
}
}
//End upload file
}
elseif($config['type']=='categories' && isset($config['tree']['use_checkbox']) && $config['tree']['use_checkbox'] || $config['type']=='checkbox')
$this->$key = implode(',',Tools::getValue($key));
else
$this->$key = trim(Tools::getValue($key));
}
}
}
if (!count($errors))
{
if($this->id && $this->update() || !$this->id && $this->add())
{
if(Configuration::get('ETS_MM_CACHE_ENABLED'))
Ets_megamenu::clearAllCache();
$success[] = Ets_megamenu::$trans['data_saved'];
}
else
$errors[] = Ets_megamenu::$trans['unkown_error'];
}
return array('errors' => $errors, 'success' => $success);
}
public function duplicateItem($id_parent = false,$id_parent2=false)
{
$oldId = $this->id;
$this->id = null;
if($id_parent && isset($this->fields['form']['parent']) && ($parent = 'id_'.$this->fields['form']['parent']) && property_exists($this,$parent))
$this->$parent = $id_parent;
if($id_parent2 && isset($this->fields['form']['parent2']) && ($parent2 = 'id_'.$this->fields['form']['parent2']) && property_exists($this,$parent2))
$this->$parent2 = $id_parent2;
if(property_exists($this,'sort_order'))
{
if(!isset($this->fields['form']['parent'])|| !isset($this->fields['configs']['sort_order']['order_group'][$this->fields['form']['parent']]) || isset($this->fields['configs']['sort_order']['order_group'][$this->fields['form']['parent']]) && !$this->fields['configs']['sort_order']['order_group'][$this->fields['form']['parent']])
$this->sort_order = $this->maxVal('sort_order')+1;
else
{
$tempName = $this->fields['configs']['sort_order']['order_group'][$this->fields['form']['parent']];
$this->sort_order = $this->maxVal('sort_order',$tempName,(int)$this->$tempName)+1;
$groupId = $this->$tempName;
}
$oldOrder = $this->sort_order;
}
if(property_exists($this,'image') && $this->image && file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->image))
{
$salt = $this->maxVal('id_'.$this->fields['form']['name'])+1;
$oldImage = dirname(__FILE__).'/../views/img/upload/'.$this->image;
$this->image = $salt.'_'.$this->image;
}
if(property_exists($this,'menu_img_link') && $this->menu_img_link && file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->menu_img_link))
{
$salt = $this->maxVal('id_'.$this->fields['form']['name'])+1;
$oldmenu_img_link = dirname(__FILE__).'/../views/img/upload/'.$this->menu_img_link;
$this->menu_img_link = $salt.'_'.$this->menu_img_link;
}
if(property_exists($this,'background_image') && $this->background_image && file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->background_image))
{
$salt = $this->maxVal('id_'.$this->fields['form']['name'])+1;
$oldbackground_image = dirname(__FILE__).'/../views/img/upload/'.$this->background_image;
$this->background_image = $salt.'_'.$this->background_image;
}
if(property_exists($this,'tab_img_link') && $this->tab_img_link && file_exists(dirname(__FILE__).'/../views/img/upload/'.$this->tab_img_link))
{
$salt = $this->maxVal('id_'.$this->fields['form']['name'])+1;
$oldtab_img_link = dirname(__FILE__).'/../views/img/upload/'.$this->tab_img_link;
$this->image = $salt.'_'.$this->tab_img_link;
}
if($this->add())
{
if(isset($oldImage) && $oldImage)
{
@copy($oldImage,dirname(__FILE__).'/../views/img/upload/'.$this->image);
}
if(isset($oldmenu_img_link) && $oldmenu_img_link)
{
@copy($oldmenu_img_link,dirname(__FILE__).'/../views/img/upload/'.$this->menu_img_link);
}
if(isset($oldbackground_image) && $oldbackground_image)
{
@copy($oldbackground_image,dirname(__FILE__).'/../views/img/upload/'.$this->background_image);
}
if(isset($oldtab_img_link) && $oldtab_img_link)
{
@copy($oldtab_img_link,dirname(__FILE__).'/../views/img/upload/'.$this->tab_img_link);
}
if(isset($oldOrder) && $oldOrder)
$this->updateOrder($oldId,isset($groupId) ? (int)$groupId : 0);
if(get_class($this)=='MM_Menu' && $this->enabled_vertical)
{
if(isset($this->fields['form']['connect_to2']) && $this->fields['form']['connect_to2']
&& ($subs = Db::getInstance()->executeS("SELECT id_".pSQL($this->fields['form']['connect_to2'])." FROM "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['connect_to2']). " WHERE id_".pSQL($this->fields['form']['name'])."=".(int)$oldId)))
{
foreach($subs as $sub)
{
$className = 'MM_'.Tools::ucfirst(Tools::strtolower($this->fields['form']['connect_to2']));
if(class_exists($className))
{
$obj = new $className((int)$sub['id_'.$this->fields['form']['connect_to2']]);
if(get_class($this)=='MM_Tab')
$obj->duplicateItem($id_parent, $this->id);
else
$obj->duplicateItem($this->id);
}
}
}
}
else
{
if(isset($this->fields['form']['connect_to']) && $this->fields['form']['connect_to']
&& ($subs = Db::getInstance()->executeS("SELECT id_".pSQL($this->fields['form']['connect_to'])." FROM "._DB_PREFIX_."ets_mm_".pSQL($this->fields['form']['connect_to']). " WHERE id_".pSQL($this->fields['form']['name'])."=".(int)$oldId)))
{
foreach($subs as $sub)
{
$className = 'MM_'.Tools::ucfirst(Tools::strtolower($this->fields['form']['connect_to']));
if(class_exists($className))
{
$obj = new $className((int)$sub['id_'.$this->fields['form']['connect_to']]);
if(get_class($this)=='MM_Tab')
$obj->duplicateItem($id_parent, $this->id);
else
$obj->duplicateItem($this->id);
}
}
}
}
return $this;
}
return false;
}
public function update($null_value=false)
{
$ok = parent::update($null_value);
if(get_class($this)=='MM_Menu' && $this->enabled_vertical)
{
$columns= Db::getInstance()->executeS('SELECT id_column FROM '._DB_PREFIX_.'ets_mm_column WHERE id_menu='.(int)$this->id.' AND id_tab not in (SELECT id_tab FROM '._DB_PREFIX_.'ets_mm_tab where id_menu ='.(int)$this->id.')');
if($columns)
{
$id_tab= Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'ets_mm_tab where id_menu='.(int)$this->id);
if(!$id_tab)
{
$tab=new MM_Tab();
$tab->id_menu=$this->id;
$tab->enabled=1;
$languages= Language::getLanguages(false);
foreach($languages as $language)
{
$tab->title[$language['id_lang']] ='Undefined title';
}
$tab->add();
$id_tab=$tab->id;
}
foreach($columns as $column)
{
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'ets_mm_column SET id_tab="'.(int)$id_tab.'" WHERE id_column='.(int)$column['id_column']);
}
}
}
return $ok;
}
}

View File

@@ -0,0 +1,280 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
class MM_Products
{
private static $is17 = false;
private $nProducts = 1;
private $id_category = 2;
private $Page = 1;
private $orderBy = null;
private $orderWay = null;
private $randSeed = 1;
private $context;
public function __construct(Context $context)
{
if ($context)
$this->context = $context;
else
$this->context = Context::getContext();
self::$is17 = version_compare(_PS_VERSION_, '1.7', '>=');
}
public function setRandSeed($randSeed)
{
$this->randSeed = $randSeed;
return $this;
}
public function setIdCategory($id_category)
{
$this->id_category = $id_category;
return $this;
}
public function setPage($Page)
{
$this->Page = $Page;
return $this;
}
public function setPerPage($nProducts)
{
$this->nProducts = $nProducts;
return $this;
}
public function setOrderBy($orderBy)
{
$this->orderBy = $orderBy;
return $this;
}
public function setOrderWay($orderWay)
{
$this->orderWay = $orderWay;
return $this;
}
public function getPages($methods)
{
if (!$methods)
return 1;
$nbTotal = (int)$this->{$methods}(true);
return ceil($nbTotal/$this->nProducts);
}
public function getBestSellers($count = false)
{
if ($count)
return ProductSale::getNbSales();
if (($bestSales = ProductSale::getBestSales((int)$this->context->language->id, $this->Page, $this->nProducts, $this->orderBy, $this->orderWay)))
{
if (!self::$is17) {
$currency = new Currency((int)$this->context->currency->id);
$use_tax = (Product::getTaxCalculationMethod((isset($this->context->customer->id) && $this->context->customer->id? (int)$this->context->customer->id : null)) != PS_TAX_EXC);
foreach ($bestSales as &$product){
$product['price'] = Tools::displayPrice(Product::getPriceStatic((int)$product['id_product'], $use_tax), $currency);
}
}
}
return $bestSales;
}
public function getHomeFeatured($count = false)
{
if (!$this->id_category)
return array();
$category = new Category((int)$this->id_category, (int)$this->context->language->id);
if (!$category->active)
return false;
if ($count)
return $category->getProducts((int)$this->context->language->id, 0, 0, null, null, false, 1, ($this->context->controller->controller_type != 'admin'? true : false), $this->context);
$products = $category->getProducts(
(int)$this->context->language->id, $this->Page, $this->nProducts, $this->orderBy, $this->orderWay, false, true,
($this->orderBy != 'rand'? false : true), ($this->orderBy != 'rand'? 1 : $this->nProducts),
($this->context->controller->controller_type != 'admin'? true : false), $this->context
);
return $products;
}
public function getNewProducts($count = false)
{
if ($count)
return Product::getNewProducts((int)$this->context->language->id, 0, 0, true);
$newProducts = false;
if (Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) {
$newProducts = Product::getNewProducts((int)$this->context->language->id, $this->Page, $this->nProducts, false, $this->orderBy, $this->orderWay, $this->context);
}
return $newProducts;
}
public function getSpecialProducts($count = false)
{
if ($count)
return self::getPricesDrop((int)$this->context->language->id, 0, 0, true);
$pricesDrops = self::getPricesDrop((int)$this->context->language->id, $this->Page, $this->nProducts, false, $this->orderBy, $this->orderWay, false, false, $this->context);
return $pricesDrops;
}
public static function getPricesDrop(
$id_lang,
$page_number = 0,
$nb_products = 10,
$count = false,
$order_by = null,
$order_way = null,
$beginning = false,
$ending = false,
Context $context = null ) {
if (!Validate::isBool($count)) {
die(Tools::displayError());
}
if (!$context) {
$context = Context::getContext();
}
if ($page_number < 1) {
$page_number = 1;
}
if ($nb_products < 1) {
$nb_products = 10;
}
if (empty($order_by) || $order_by == 'position') {
$order_by = 'price';
}
if (empty($order_way)) {
$order_way = 'DESC';
}
if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') {
$order_by_prefix = 'product_shop';
} elseif ($order_by == 'name') {
$order_by_prefix = 'pl';
}
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
die(Tools::displayError());
}
$current_date = date('Y-m-d H:i:00');
$ids_product = self::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context);
$tab_id_product = array();
foreach ($ids_product as $product) {
if (is_array($product)) {
$tab_id_product[] = (int)$product['id_product'];
} else {
$tab_id_product[] = (int)$product;
}
}
$front = false;
if ($context->controller->controller_type != 'admin') {
$front = true;
}
$sql_groups = '';
if (Group::isFeatureActive()) {
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = ' AND EXISTS(SELECT 1 FROM `'._DB_PREFIX_.'category_product` cp JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').') WHERE cp.`id_product` = p.`id_product`)';
}
if ($count) {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(DISTINCT p.`id_product`)
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
WHERE product_shop.`active` = 1
AND product_shop.`show_price` = 1
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
'.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').'
'.$sql_groups);
}
if (strpos($order_by, '.') > 0) {
$order_by = explode('.', $order_by);
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`';
}
$prev_version = version_compare(_PS_VERSION_, '1.6.1.0', '<');
$sql = '
SELECT
p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`,
'.($prev_version? ' MAX(product_attribute_shop.id_product_attribute)' : ' IFNULL(product_attribute_shop.id_product_attribute, 0)').' `id_product_attribute`,
pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
pl.`name`, '.($prev_version? 'MAX(image_shop.`id_image`)' : 'image_shop.`id_image`').' `id_image`, il.`legend`, m.`name` AS manufacturer_name,
DATEDIFF(
p.`date_add`,
DATE_SUB(
"'.date('Y-m-d').' 00:00:00",
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
)
) > 0 AS new
FROM `'._DB_PREFIX_.'product` p' .Shop::addSqlAssociation('product', 'p')
.($prev_version? 'LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON (pa.id_product = p.id_product)'.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on=1').'':'LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.')')
.Product::sqlStock('p', 0, false, $context->shop).'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').')'
.($prev_version? 'LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') : 'LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.id_shop=' . (int)$context->shop->id . ')').'
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON ('.($prev_version? 'i' : 'image_shop').'.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
WHERE product_shop.`active` = 1
AND product_shop.`show_price` = 1
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
'.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').'
'.pSQL($sql_groups).'
GROUP BY product_shop.id_product
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).'
LIMIT '.(int)(($page_number-1) * $nb_products).', '.(int)$nb_products;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if (!$result) {
return false;
}
if ($order_by == 'price') {
Tools::orderbyPrice($result, $order_way);
}
return Product::getProductsProperties($id_lang, $result);
}
protected static function _getProductIdByDate($beginning, $ending, Context $context = null, $with_combination = false)
{
if (!$context) {
$context = Context::getContext();
}
$id_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
if ($context->controller->controller_type != 'admin')
{
$id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
if (!empty($ids['id_country']))
$id_country = $ids['id_country'];
}
return SpecificPrice::getProductIdByDate(
$context->shop->id,
$context->currency->id,
$id_country,
(int)Configuration::get('PS_CUSTOMER_GROUP'),
$beginning,
$ending,
0,
$with_combination
);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
if (!defined('_PS_VERSION_'))
exit;
class MM_Tab extends MM_Obj
{
public $id_tab;
public $id_menu;
public $tab_img_link;
public $tab_sub_width;
public $menu_ver_hidden_border;
public $tab_sub_content_pos;
public $tab_icon;
public $title;
public $enabled;
public $sort_order;
public $bubble_background_color;
public $bubble_text_color;
public $bubble_text;
public $background_image;
public $position_background;
public $url;
public static $definition = array(
'table' => 'ets_mm_tab',
'primary' => 'id_tab',
'multilang' => true,
'fields' => array(
'id_menu' => array('type' => self::TYPE_INT),
'tab_img_link'=> array('type'=>self::TYPE_STRING),
'tab_sub_width'=> array('type'=>self::TYPE_STRING),
'tab_icon'=> array('type'=>self::TYPE_STRING),
'bubble_text_color'=> array('type'=>self::TYPE_STRING),
'bubble_background_color'=> array('type'=>self::TYPE_STRING),
'tab_sub_content_pos'=>array('type'=>self::TYPE_INT),
'enabled'=>array('type'=>self::TYPE_INT),
'background_image' => array('type' => self::TYPE_STRING),
'position_background' => array('type' => self::TYPE_STRING),
'title' => array('type' => self::TYPE_STRING,'lang' => true),
'url' => array('type'=>self::TYPE_STRING,'lang'=>true),
'bubble_text' => array('type' => self::TYPE_STRING,'lang' => true),
'sort_order' => array('type' => self::TYPE_INT),
)
);
public function __construct($id_item = null, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::__construct($id_item, $id_lang, $id_shop);
$languages = Language::getLanguages(false);
foreach($languages as $lang)
{
foreach(self::$definition['fields'] as $field => $params)
{
$temp = $this->$field;
if(isset($params['lang']) && $params['lang'] && !isset($temp[$lang['id_lang']]))
{
$temp[$lang['id_lang']] = '';
}
$this->$field = $temp;
}
}
unset($context);
$this->setFields(Ets_megamenu::$tab_class);
}
}

View File

@@ -0,0 +1,249 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
class Uploader
{
const DEFAULT_MAX_SIZE = 10485760;
private $_check_file_size;
private $_accept_types;
private $_files;
private $_max_size;
private $_name;
private $_save_path;
public function __construct($name = null)
{
$this->setName($name);
$this->setCheckFileSize(true);
$this->files = array();
}
public function setAcceptTypes($value)
{
if (is_array($value) && count($value)) {
$value = array_map(array('Tools', 'strtolower'), $value);
}
$this->_accept_types = $value;
return $this;
}
public function getAcceptTypes()
{
return $this->_accept_types;
}
public function setCheckFileSize($value)
{
$this->_check_file_size = $value;
return $this;
}
public function getFilePath($file_name = null)
{
if (!isset($file_name)) {
return tempnam($this->getSavePath(), $this->getUniqueFileName());
}
return $this->getSavePath().$file_name;
}
public function getFiles()
{
if (!isset($this->_files)) {
$this->_files = array();
}
return $this->_files;
}
public function setMaxSize($value)
{
$this->_max_size = (int)$value;
return $this;
}
public function getMaxSize()
{
if (!isset($this->_max_size) || empty($this->_max_size)) {
$this->setMaxSize(self::DEFAULT_MAX_SIZE);
}
return $this->_max_size;
}
public function setName($value)
{
$this->_name = $value;
return $this;
}
public function getName()
{
return $this->_name;
}
public function setSavePath($value)
{
$this->_save_path = $value;
return $this;
}
public function getPostMaxSizeBytes()
{
$post_max_size = ini_get('post_max_size');
$bytes = (int)trim($post_max_size);
$last = Tools::strtolower($post_max_size[Tools::strlen($post_max_size) - 1]);
switch ($last) {
case 'g': $bytes *= 1024;
case 'm': $bytes *= 1024;
case 'k': $bytes *= 1024;
}
if ($bytes == '') {
$bytes = null;
}
return $bytes;
}
public function getSavePath()
{
if (!isset($this->_save_path)) {
$this->setSavePath(_PS_UPLOAD_DIR_);
}
return $this->_normalizeDirectory($this->_save_path);
}
public function getUniqueFileName($prefix = 'PS')
{
return uniqid($prefix, true);
}
public function checkFileSize()
{
return (isset($this->_check_file_size) && $this->_check_file_size);
}
public function process($dest = null)
{
$upload = isset($_FILES[$this->getName()]) ? $_FILES[$this->getName()] : null;
if ($upload && is_array($upload['tmp_name'])) {
$tmp = array();
foreach ($upload['tmp_name'] as $index => $value) {
$tmp[$index] = array(
'tmp_name' => $upload['tmp_name'][$index],
'name' => $upload['name'][$index],
'size' => $upload['size'][$index],
'type' => $upload['type'][$index],
'error' => $upload['error'][$index]
);
$this->files[] = $this->upload($tmp[$index], $dest);
}
unset($value);
} elseif ($upload) {
$this->files[] = $this->upload($upload, $dest);
}
return $this->files;
}
public function upload($file, $dest = null)
{
if ($this->validate($file)) {
if (isset($dest) && is_dir($dest)) {
$file_path = $dest;
} else {
$file_path = $this->getFilePath(isset($dest) ? $dest : $file['name']);
}
if ($file['tmp_name'] && is_uploaded_file($file['tmp_name'])) {
move_uploaded_file($file['tmp_name'], $file_path);
} else {
// Non-multipart uploads (PUT method support)
file_put_contents($file_path, fopen('php://input', 'r'));
}
$file_size = $this->_getFileSize($file_path, true);
if ($file_size === $file['size']) {
$file['save_path'] = $file_path;
} else {
$file['size'] = $file_size;
unlink($file_path);
$file['error'] = Tools::displayError('Server file size is different from local file size');
}
}
return $file;
}
protected function checkUploadError($error_code)
{
$error = 0;
switch ($error_code) {
case 1:
$error = sprintf(Tools::displayError('The uploaded file exceeds %s'), ini_get('upload_max_filesize'));
break;
case 2:
$error = sprintf(Tools::displayError('The uploaded file exceeds %s'), ini_get('post_max_size'));
break;
case 3:
$error = Tools::displayError('The uploaded file was only partially uploaded');
break;
case 4:
$error = Tools::displayError('No file was uploaded');
break;
case 6:
$error = Tools::displayError('Missing temporary folder');
break;
case 7:
$error = Tools::displayError('Failed to write file to disk');
break;
case 8:
$error = Tools::displayError('A PHP extension stopped the file upload');
break;
default:
break;
}
return $error;
}
protected function validate(&$file)
{
$file['error'] = $this->checkUploadError($file['error']);
if ($file['error']) {
return false;
}
$post_max_size = $this->getPostMaxSizeBytes();
if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size)) {
$file['error'] = Tools::displayError('The uploaded file exceeds the post_max_size directive in php.ini');
return false;
}
if (preg_match('/\%00/', $file['name'])) {
$file['error'] = Tools::displayError('Invalid file name');
return false;
}
$types = $this->getAcceptTypes();
//TODO check mime type.
if (isset($types) && !in_array(Tools::strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)), $types)) {
$file['error'] = Tools::displayError('Filetype not allowed');
return false;
}
if ($this->checkFileSize() && $file['size'] > $this->getMaxSize()) {
$file['error'] = sprintf(Tools::displayError('File (size : %1s) is too big (max : %2s)'), $file['size'], $this->getMaxSize());
return false;
}
return true;
}
protected function _getFileSize($file_path, $clear_stat_cache = false)
{
if ($clear_stat_cache) {
clearstatcache(true, $file_path);
}
return filesize($file_path);
}
protected function _getServerVars($var)
{
return (isset($_SERVER[$var]) ? $_SERVER[$var] : '');
}
protected function _normalizeDirectory($directory)
{
$last = $directory[Tools::strlen($directory) - 1];
if (in_array($last, array('/', '\\'))) {
$directory[Tools::strlen($directory) - 1] = DIRECTORY_SEPARATOR;
return $directory;
}
$directory .= DIRECTORY_SEPARATOR;
return $directory;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* 2007-2021 ETS-Soft
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 wesite only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please contact us for extra customization service at an affordable price
*
* @author ETS-Soft <etssoft.jsc@gmail.com>
* @copyright 2007-2021 ETS-Soft
* @license Valid for 1 website (or project) for each purchase of license
* International Registered Trademark & Property of ETS-Soft
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;