update
This commit is contained in:
@@ -1,29 +1,28 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2015 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* 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 refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2015 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* 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 refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
@@ -32,38 +31,67 @@ use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
|
||||
|
||||
class Ps_Banner extends Module implements WidgetInterface
|
||||
{
|
||||
/**
|
||||
* @var string Name of the module running on PS 1.6.x. Used for data migration.
|
||||
*/
|
||||
const PS_16_EQUIVALENT_MODULE = 'blockbanner';
|
||||
|
||||
private $templateFile;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ps_banner';
|
||||
$this->version = '2.1.0';
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ps_banner';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->version = '2.1.2';
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
$this->bootstrap = true;
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->trans('Banner', array(), 'Modules.Banner.Admin');
|
||||
$this->description = $this->trans('Displays a banner on your shop.', array(), 'Modules.Banner.Admin');
|
||||
$this->displayName = $this->trans('Banner', [], 'Modules.Banner.Admin');
|
||||
$this->description = $this->trans('Add a banner to the homepage of your store to highlight your sales and new products in a visual and friendly way.', [], 'Modules.Banner.Admin');
|
||||
|
||||
$this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);
|
||||
$this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
|
||||
|
||||
$this->templateFile = 'module:ps_banner/ps_banner.tpl';
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
return (parent::install() &&
|
||||
return parent::install() &&
|
||||
$this->registerHook('displayHome') &&
|
||||
$this->registerHook('actionObjectLanguageAddAfter') &&
|
||||
$this->installFixtures() &&
|
||||
$this->disableDevice(Context::DEVICE_MOBILE));
|
||||
$this->uninstallPrestaShop16Module() &&
|
||||
$this->disableDevice(Context::DEVICE_MOBILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate data from 1.6 equivalent module (if applicable), then uninstall
|
||||
*/
|
||||
public function uninstallPrestaShop16Module()
|
||||
{
|
||||
if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Data migration
|
||||
Configuration::updateValue('BANNER_IMG', Configuration::getInt('BLOCKBANNER_IMG'));
|
||||
Configuration::updateValue('BANNER_LINK', Configuration::getInt('BLOCKBANNER_LINK'));
|
||||
Configuration::updateValue('BANNER_DESC', Configuration::getInt('BLOCKBANNER_DESC'));
|
||||
|
||||
$oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE);
|
||||
if ($oldModule) {
|
||||
$oldModule->uninstall();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hookActionObjectLanguageAddAfter($params)
|
||||
{
|
||||
return $this->installFixture((int)$params['object']->id, Configuration::get('BANNER_IMG', (int)Configuration::get('PS_LANG_DEFAULT')));
|
||||
return $this->installFixture((int) $params['object']->id, Configuration::get('BANNER_IMG', (int) Configuration::get('PS_LANG_DEFAULT')));
|
||||
}
|
||||
|
||||
protected function installFixtures()
|
||||
@@ -71,7 +99,7 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
$this->installFixture((int)$lang['id_lang'], 'sale70.png');
|
||||
$this->installFixture((int) $lang['id_lang'], 'sale70.png');
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -79,9 +107,9 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
|
||||
protected function installFixture($id_lang, $image = null)
|
||||
{
|
||||
$values['BANNER_IMG'][(int)$id_lang] = $image;
|
||||
$values['BANNER_LINK'][(int)$id_lang] = '';
|
||||
$values['BANNER_DESC'][(int)$id_lang] = '';
|
||||
$values['BANNER_IMG'][(int) $id_lang] = $image;
|
||||
$values['BANNER_LINK'][(int) $id_lang] = '';
|
||||
$values['BANNER_DESC'][(int) $id_lang] = '';
|
||||
|
||||
Configuration::updateValue('BANNER_IMG', $values['BANNER_IMG']);
|
||||
Configuration::updateValue('BANNER_LINK', $values['BANNER_LINK']);
|
||||
@@ -101,21 +129,21 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
{
|
||||
if (Tools::isSubmit('submitStoreConf')) {
|
||||
$languages = Language::getLanguages(false);
|
||||
$values = array();
|
||||
$values = [];
|
||||
$update_images_values = false;
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
if (isset($_FILES['BANNER_IMG_'.$lang['id_lang']])
|
||||
&& isset($_FILES['BANNER_IMG_'.$lang['id_lang']]['tmp_name'])
|
||||
&& !empty($_FILES['BANNER_IMG_'.$lang['id_lang']]['tmp_name'])) {
|
||||
if ($error = ImageManager::validateUpload($_FILES['BANNER_IMG_'.$lang['id_lang']], 4000000)) {
|
||||
return $error;
|
||||
if (isset($_FILES['BANNER_IMG_' . $lang['id_lang']])
|
||||
&& isset($_FILES['BANNER_IMG_' . $lang['id_lang']]['tmp_name'])
|
||||
&& !empty($_FILES['BANNER_IMG_' . $lang['id_lang']]['tmp_name'])) {
|
||||
if ($error = ImageManager::validateUpload($_FILES['BANNER_IMG_' . $lang['id_lang']], 4000000)) {
|
||||
return $this->displayError($error);
|
||||
} else {
|
||||
$ext = substr($_FILES['BANNER_IMG_'.$lang['id_lang']]['name'], strrpos($_FILES['BANNER_IMG_'.$lang['id_lang']]['name'], '.') + 1);
|
||||
$file_name = md5($_FILES['BANNER_IMG_'.$lang['id_lang']]['name']).'.'.$ext;
|
||||
$ext = substr($_FILES['BANNER_IMG_' . $lang['id_lang']]['name'], strrpos($_FILES['BANNER_IMG_' . $lang['id_lang']]['name'], '.') + 1);
|
||||
$file_name = md5($_FILES['BANNER_IMG_' . $lang['id_lang']]['name']) . '.' . $ext;
|
||||
|
||||
if (!move_uploaded_file($_FILES['BANNER_IMG_'.$lang['id_lang']]['tmp_name'], dirname(__FILE__).DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.$file_name)) {
|
||||
return $this->displayError($this->trans('An error occurred while attempting to upload the file.', array(), 'Admin.Notifications.Error'));
|
||||
if (!move_uploaded_file($_FILES['BANNER_IMG_' . $lang['id_lang']]['tmp_name'], dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $file_name)) {
|
||||
return $this->displayError($this->trans('An error occurred while attempting to upload the file.', [], 'Admin.Notifications.Error'));
|
||||
} else {
|
||||
if (Configuration::hasContext('BANNER_IMG', $lang['id_lang'], Shop::getContext())
|
||||
&& Configuration::get('BANNER_IMG', $lang['id_lang']) != $file_name) {
|
||||
@@ -129,11 +157,11 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
$update_images_values = true;
|
||||
}
|
||||
|
||||
$values['BANNER_LINK'][$lang['id_lang']] = Tools::getValue('BANNER_LINK_'.$lang['id_lang']);
|
||||
$values['BANNER_DESC'][$lang['id_lang']] = Tools::getValue('BANNER_DESC_'.$lang['id_lang']);
|
||||
$values['BANNER_LINK'][$lang['id_lang']] = Tools::getValue('BANNER_LINK_' . $lang['id_lang']);
|
||||
$values['BANNER_DESC'][$lang['id_lang']] = Tools::getValue('BANNER_DESC_' . $lang['id_lang']);
|
||||
}
|
||||
|
||||
if ($update_images_values) {
|
||||
if ($update_images_values && isset($values['BANNER_IMG'])) {
|
||||
Configuration::updateValue('BANNER_IMG', $values['BANNER_IMG']);
|
||||
}
|
||||
|
||||
@@ -142,7 +170,7 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
|
||||
$this->_clearCache($this->templateFile);
|
||||
|
||||
return $this->displayConfirmation($this->trans('The settings have been updated.', array(), 'Admin.Notifications.Success'));
|
||||
return $this->displayConfirmation($this->trans('The settings have been updated.', [], 'Admin.Notifications.Success'));
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -150,47 +178,47 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->postProcess().$this->renderForm();
|
||||
return $this->postProcess() . $this->renderForm();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->trans('Settings', array(), 'Admin.Global'),
|
||||
'icon' => 'icon-cogs'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
$fields_form = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->trans('Settings', [], 'Admin.Global'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'file_lang',
|
||||
'label' => $this->trans('Banner image', array(), 'Modules.Banner.Admin'),
|
||||
'label' => $this->trans('Banner image', [], 'Modules.Banner.Admin'),
|
||||
'name' => 'BANNER_IMG',
|
||||
'desc' => $this->trans('Upload an image for your top banner. The recommended dimensions are 1110 x 214px if you are using the default theme.', array(), 'Modules.Banner.Admin'),
|
||||
'desc' => $this->trans('Upload an image for your top banner. The recommended dimensions are 1110 x 214px if you are using the default theme.', [], 'Modules.Banner.Admin'),
|
||||
'lang' => true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'lang' => true,
|
||||
'label' => $this->trans('Banner Link', array(), 'Modules.Banner.Admin'),
|
||||
'label' => $this->trans('Banner Link', [], 'Modules.Banner.Admin'),
|
||||
'name' => 'BANNER_LINK',
|
||||
'desc' => $this->trans('Enter the link associated to your banner. When clicking on the banner, the link opens in the same window. If no link is entered, it redirects to the homepage.', array(), 'Modules.Banner.Admin')
|
||||
),
|
||||
array(
|
||||
'desc' => $this->trans('Enter the link associated to your banner. When clicking on the banner, the link opens in the same window. If no link is entered, it redirects to the homepage.', [], 'Modules.Banner.Admin'),
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'lang' => true,
|
||||
'label' => $this->trans('Banner description', array(), 'Modules.Banner.Admin'),
|
||||
'label' => $this->trans('Banner description', [], 'Modules.Banner.Admin'),
|
||||
'name' => 'BANNER_DESC',
|
||||
'desc' => $this->trans('Please enter a short but meaningful description for the banner.', array(), 'Modules.Banner.Admin')
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->trans('Save', array(), 'Admin.Actions')
|
||||
)
|
||||
),
|
||||
);
|
||||
'desc' => $this->trans('Please enter a short but meaningful description for the banner.', [], 'Modules.Banner.Admin'),
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->trans('Save', [], 'Admin.Actions'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
@@ -200,27 +228,27 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submitStoreConf';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = array(
|
||||
$helper->tpl_vars = [
|
||||
'uri' => $this->getPathUri(),
|
||||
'fields_value' => $this->getConfigFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id
|
||||
);
|
||||
'id_language' => $this->context->language->id,
|
||||
];
|
||||
|
||||
return $helper->generateForm(array($fields_form));
|
||||
return $helper->generateForm([$fields_form]);
|
||||
}
|
||||
|
||||
public function getConfigFieldsValues()
|
||||
{
|
||||
$languages = Language::getLanguages(false);
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
$fields['BANNER_IMG'][$lang['id_lang']] = Tools::getValue('BANNER_IMG_'.$lang['id_lang'], Configuration::get('BANNER_IMG', $lang['id_lang']));
|
||||
$fields['BANNER_LINK'][$lang['id_lang']] = Tools::getValue('BANNER_LINK_'.$lang['id_lang'], Configuration::get('BANNER_LINK', $lang['id_lang']));
|
||||
$fields['BANNER_DESC'][$lang['id_lang']] = Tools::getValue('BANNER_DESC_'.$lang['id_lang'], Configuration::get('BANNER_DESC', $lang['id_lang']));
|
||||
$fields['BANNER_IMG'][$lang['id_lang']] = Tools::getValue('BANNER_IMG_' . $lang['id_lang'], Configuration::get('BANNER_IMG', $lang['id_lang']));
|
||||
$fields['BANNER_LINK'][$lang['id_lang']] = Tools::getValue('BANNER_LINK_' . $lang['id_lang'], Configuration::get('BANNER_LINK', $lang['id_lang']));
|
||||
$fields['BANNER_DESC'][$lang['id_lang']] = Tools::getValue('BANNER_DESC_' . $lang['id_lang'], Configuration::get('BANNER_DESC', $lang['id_lang']));
|
||||
}
|
||||
|
||||
return $fields;
|
||||
@@ -238,9 +266,16 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
public function getWidgetVariables($hookName, array $params)
|
||||
{
|
||||
$imgname = Configuration::get('BANNER_IMG', $this->context->language->id);
|
||||
$imgDir = _PS_MODULE_DIR_ . $this->name . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $imgname;
|
||||
|
||||
if ($imgname && file_exists(_PS_MODULE_DIR_.$this->name.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.$imgname)) {
|
||||
$this->smarty->assign('banner_img', $this->context->link->protocol_content . Tools::getMediaServer($imgname) . $this->_path . 'img/' . $imgname);
|
||||
if ($imgname && file_exists($imgDir)) {
|
||||
$sizes = getimagesize($imgDir);
|
||||
|
||||
$this->smarty->assign([
|
||||
'banner_img' => $this->context->link->protocol_content . Tools::getMediaServer($imgname) . $this->_path . 'img/' . $imgname,
|
||||
'banner_width' => $sizes[0],
|
||||
'banner_height' => $sizes[1],
|
||||
]);
|
||||
}
|
||||
|
||||
$banner_link = Configuration::get('BANNER_LINK', $this->context->language->id);
|
||||
@@ -248,16 +283,16 @@ class Ps_Banner extends Module implements WidgetInterface
|
||||
$banner_link = $this->context->link->getPageLink('index');
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'banner_link' => $this->updateUrl($banner_link),
|
||||
'banner_desc' => Configuration::get('BANNER_DESC', $this->context->language->id)
|
||||
);
|
||||
'banner_desc' => Configuration::get('BANNER_DESC', $this->context->language->id),
|
||||
];
|
||||
}
|
||||
|
||||
private function updateUrl($link)
|
||||
{
|
||||
if (substr($link, 0, 7) !== "http://" && substr($link, 0, 8) !== "https://") {
|
||||
$link = "http://" . $link;
|
||||
if (substr($link, 0, 7) !== 'http://' && substr($link, 0, 8) !== 'https://') {
|
||||
$link = 'http://' . $link;
|
||||
}
|
||||
|
||||
return $link;
|
||||
|
||||
Reference in New Issue
Block a user