Files
2019-11-17 19:14:07 +01:00

480 lines
21 KiB
PHP

<?php
/**
* JQZoom Evolution v1.4.1
* Prestashop Module
*
* @author KreatIN <contact@kreatin.fr>
* @copyright 2012-2017 KreatIN
* @license http://www.apache.org/licenses/LICENSE-2.0
* @version 1.4.1
*
* Designed by Kreatin
* http://www.kreatin.fr/jqzoomevolution/1.4/tshirts/1-1-t-shirt-delave-manches-courtes.html
*
* Thank you to open-source/free code, libraries and sites
* that we either used or we got inspiration from to create
* JQZoom Evolution
*
* -The jQuery Zoom Gallery plugin xZoom :
* https://payalord.github.io/xZoom/
*
* Copyright 2017 KreatIN
*
*/
if (!defined('_PS_VERSION_')) {
exit;
}
include_once(_PS_MODULE_DIR_ . 'jqzoomevolution/JQZoomInstall.php');
class JQZoomEvolution extends Module
{
private $html = '';
private $postErrors = array();
public function __construct()
{
$this->name = 'jqzoomevolution';
$this->tab = 'front_office_features';
$this->version = '1.4.1';
$this->author = 'KreatIN';
$this->need_instance = 0;
$this->module_key = 'df38513e0a96847e4b287ec269edf913';
$this->bootstrap = true;
parent::__construct();
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module ?');
$this->displayName = $this->l('JQZoom Evolution');
$this->description = $this->l('Zoom on a product image (New version of JQZoom Prestashop Feature).');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
include_once(_PS_MODULE_DIR_ . $this->name . '/JQZoomConfig.php');
}
public function install()
{
if (!parent::install() || !JQZoomInstall::installDB() || !JQZoomInstall::insertConfig() || !$this->registerHook('header')) {
return false;
}
return true;
}
public function uninstall()
{
if (!parent::uninstall() ||
!JQZoomInstall::uninstallDB()
) {
return false;
}
return true;
}
private function postValidation()
{
if (Tools::isSubmit('submitSaveConfigJQZoom')) {
if (Tools::getValue('jqzoom_width') && !(int)Tools::getValue('jqzoom_width')) {
$this->postErrors[] = $this->l('JQZoom width must be a number.');
}
if (Tools::getValue('jqzoom_height') && !(int)Tools::getValue('jqzoom_height')) {
$this->postErrors[] = $this->l('JQZoom height must be a number.');
}
if (Tools::getValue('jqzoom_xoffset') && !(int)Tools::getValue('jqzoom_xoffset')) {
$this->postErrors[] = $this->l('JQZoom Horizontal Zoom Distance must be a number.');
}
if (Tools::getValue('jqzoom_yoffset') && !(int)Tools::getValue('jqzoom_yoffset')) {
$this->postErrors[] = $this->l('JQZoom Vertical Zoom Distance must be a number.');
}
if (Tools::getValue('jqzoom_tintopacity') && !(float)Tools::getValue('jqzoom_tintopacity')) {
$this->postErrors[] = $this->l('JQZoom Overlay Opacity must be a number.');
}
if (Tools::getValue('jqzoom_lensopacity') && !(float)Tools::getValue('jqzoom_lensopacity')) {
$this->postErrors[] = $this->l('JQZoom Lens Opacity must be a number.');
}
}
}
private function postProcess()
{
if (Tools::isSubmit('submitSaveConfigJQZoom')) {
JQZoomConfig::updateValue('JQZOOM_POSITION', (string)Tools::getValue('jqzoom_position'));
JQZoomConfig::updateValue('JQZOOM_WIDTH', (int)Tools::getValue('jqzoom_width'));
JQZoomConfig::updateValue('JQZOOM_HEIGHT', (int)Tools::getValue('jqzoom_height'));
JQZoomConfig::updateValue('JQZOOM_XOFFSET', (int)Tools::getValue('jqzoom_xoffset'));
JQZoomConfig::updateValue('JQZOOM_YOFFSET', (int)Tools::getValue('jqzoom_yoffset'));
JQZoomConfig::updateValue('JQZOOM_BCOLOR', (string)Tools::getValue('jqzoom_bcolor'));
JQZoomConfig::updateValue('JQZOOM_SHOWTITLE', (int)Tools::getValue('jqzoom_showtitle'));
JQZoomConfig::updateValue('JQZOOM_LENSSHAPE', (string)Tools::getValue('jqzoom_lensshape'));
JQZoomConfig::updateValue('JQZOOM_FADEINEFFECT', (int)Tools::getValue('jqzoom_fadeineffect'));
JQZoomConfig::updateValue('JQZOOM_FADEOUTEFFECT', (int)Tools::getValue('jqzoom_fadeouteffect'));
JQZoomConfig::updateValue('JQZOOM_TINTCOLOR', (string)Tools::getValue('jqzoom_tintcolor'));
JQZoomConfig::updateValue('JQZOOM_TINTOPACITY', (float)Tools::getValue('jqzoom_tintopacity'));
JQZoomConfig::updateValue('JQZOOM_LENSCOLOR', (string)Tools::getValue('jqzoom_lenscolor'));
JQZoomConfig::updateValue('JQZOOM_LENSOPACITY', (float)Tools::getValue('jqzoom_lensopacity'));
JQZoomConfig::updateValue('JQZOOM_ZOOMPOWER', (string)Tools::getValue('jqzoom_zoompower'));
Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&toconf=1');
}
}
public function getContent()
{
JQZoomConfig::loadConfiguration();
if (Configuration::get('PS_DISPLAY_JQZOOM') == 1) {
$this->html .= $this->displayError($this->l('In order to work properly, please turn off the option "Enable JqZoom instead of Thickbox on the product page" located in Preferences > Products'));
}
if (Tools::isSubmit('submitSaveConfigJQZoom')) {
$this->postValidation();
if (!count($this->postErrors)) {
$this->postProcess();
} else {
$this->displayErrors();
}
}
if ($conf_number = Tools::getValue('toconf')) {
$this->displayConf($conf_number);
}
// Need for multishop
if (!JQZoomConfig::hasKey('JQZOOM_POSITION', Shop::getContextShopGroupID(), Shop::getContextShopID())) {
JQZoomInstall::insertConfig();
}
$this->html .= $this->headerHTML();
$this->html .= $this->renderForm();
return $this->html;
}
private function headerHTML()
{
$this->html .= '
<script type="text/javascript">
$(document).ready(function(){
$(\'select[name="jqzoom_position"]\').change(function(){
if($(\'select[name="jqzoom_position"] option:selected\').val() == \'lens\' || $(\'select[name="jqzoom_position"] option:selected\').val() == \'inside\'){
$(\'div.form-group\').has(\'div .optionnal\').hide();
}
else {
$(\'div.form-group\').has(\'div .optionnal\').show();
}
})
.trigger(\'change\');
$(\'input.format_dec\').keyup(function(){
$(this).val(function(i, value) {
return value.replace(/,/g, \'.\');
});
})
})
</script>';
}
public function renderForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Zoom Position'),
'name' => 'jqzoom_position',
'desc' => $this->l('Where the zoom popup expand') . ' (' . $this->l('Default') . ' : Right)',
'class' => 'fixed-width-xl',
'options' => array(
'query' => array(
array(
'id_option' => 'right',
'name' => 'Right'
),
array(
'id_option' => 'left',
'name' => 'Left'
),
array(
'id_option' => 'top',
'name' => 'Top'
),
array(
'id_option' => 'bottom',
'name' => 'Bottom'
),
array(
'id_option' => 'inside',
'name' => 'Inside'
),
array(
'id_option' => 'lens',
'name' => 'Lens'
)
),
'id' => 'id_option',
'name' => 'name',
)
),
array(
'type' => 'text',
'label' => $this->l('Zoom Width'),
'name' => 'jqzoom_width',
'desc' => $this->l('Choose 0 for automatic size'),
'prefix' => 'px',
'class' => 'fixed-width-xs optionnal'
),
array(
'type' => 'text',
'label' => $this->l('Zoom Height'),
'name' => 'jqzoom_height',
'desc' => $this->l('Choose 0 for automatic size'),
'prefix' => 'px',
'class' => 'fixed-width-xs optionnal'
),
array(
'type' => 'text',
'label' => $this->l('Horizontal Zoom Distance'),
'name' => 'jqzoom_xoffset',
'desc' => '(' . $this->l('Default') . ' : 20px)',
'prefix' => 'px',
'class' => 'fixed-width-xs optionnal'
),
array(
'type' => 'text',
'label' => $this->l('Vertical Zoom Distance'),
'name' => 'jqzoom_yoffset',
'desc' => '(' . $this->l('Default') . ' : 0px)',
'prefix' => 'px',
'class' => 'fixed-width-xs optionnal'
),
array(
'type' => 'color',
'label' => $this->l('Border color'),
'name' => 'jqzoom_bcolor',
'desc' => $this->l('Border color of the zoom popup'),
'class' => 'optionnal'
),
array(
'type' => 'switch',
'label' => $this->l('Show Title'),
'name' => 'jqzoom_showtitle',
'desc' => $this->l('Show the title in zoom popup') . ' (' . $this->l('Default') . ' : ' . $this->l('No') . ')',
'class' => 'optionnal',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
array(
'type' => 'switch',
'label' => $this->l('FadeIn effect'),
'name' => 'jqzoom_fadeineffect',
'desc' => $this->l('Show the popup window with a FadeIn effect') . ' (' . $this->l('Default') . ' : ' . $this->l('No') . ')',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
array(
'type' => 'switch',
'label' => $this->l('FadeOut effect'),
'name' => 'jqzoom_fadeouteffect',
'desc' => $this->l('Hide the popup window with a FadeOut effect') . ' (' . $this->l('Default') . ' : ' . $this->l('Yes') . ')',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
array(
'type' => 'color',
'label' => $this->l('Overlay\'s color'),
'name' => 'jqzoom_tintcolor',
'desc' => $this->l('Overlay\'s color when hovering the image') . ' (' . $this->l('Default') . ' : #000000)',
),
array(
'type' => 'text',
'label' => $this->l('Overlay\'s opacity'),
'name' => 'jqzoom_tintopacity',
'desc' => $this->l('Overlay\'s opacity when hovering the image') . ' (' . $this->l('Default') . ' : 0.4)',
'class' => 'fixed-width-xs format_dec'
),
array(
'type' => 'color',
'label' => $this->l('Lens\' color'),
'name' => 'jqzoom_lenscolor',
'desc' => $this->l('Lens\' color when hovering the image'),
),
array(
'type' => 'text',
'label' => $this->l('Lens\' opacity'),
'name' => 'jqzoom_lensopacity',
'desc' => $this->l('Lens\' opacity when hovering the image') . ' (' . $this->l('Default') . ' : 0.4)',
'class' => 'fixed-width-xs format_dec'
),
array(
'type' => 'select',
'label' => $this->l('Lens\' shape'),
'name' => 'jqzoom_lensshape',
'desc' => $this->l('The lens\' shape is only valid if Position is set to "LENS"') . ' (' . $this->l('Default') . ' : Square)',
'class' => 'fixed-width-xl',
'options' => array(
'query' => array(
array(
'id_option' => 'box',
'name' => 'Square'
),
array(
'id_option' => 'circle',
'name' => 'Circle'
)
),
'id' => 'id_option',
'name' => 'name',
)
),
array(
'type' => 'select',
'label' => $this->l('Zoom Power'),
'name' => 'jqzoom_zoompower',
'desc' => $this->l('The zoom power when hovering the image') . ' (' . $this->l('Default') . ' : Normal)',
'class' => 'fixed-width-xl',
'options' => array(
'query' => array(
array(
'id_option' => '0',
'name' => 'Normal'
),
array(
'id_option' => '-0.5',
'name' => 'x1.5'
),
array(
'id_option' => '-1',
'name' => 'x2'
)
),
'id' => 'id_option',
'name' => 'name',
)
),
),
'submit' => array(
'title' => $this->l('Save'),
)
),
);
$helper = new HelperForm();
$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;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitSaveConfigJQZoom';
$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(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form));
}
public function getConfigFieldsValues()
{
return array(
'jqzoom_position' => Tools::getValue('jqzoom_position', JQZoomConfig::get('JQZOOM_POSITION')),
'jqzoom_width' => Tools::getValue('jqzoom_width', JQZoomConfig::get('JQZOOM_WIDTH')),
'jqzoom_height' => Tools::getValue('jqzoom_height', JQZoomConfig::get('JQZOOM_HEIGHT')),
'jqzoom_xoffset' => Tools::getValue('jqzoom_xoffset', JQZoomConfig::get('JQZOOM_XOFFSET')),
'jqzoom_yoffset' => Tools::getValue('jqzoom_yoffset', JQZoomConfig::get('JQZOOM_YOFFSET')),
'jqzoom_bcolor' => Tools::getValue('jqzoom_bcolor', JQZoomConfig::get('JQZOOM_BCOLOR')),
'jqzoom_showtitle' => Tools::getValue('jqzoom_showtitle', JQZoomConfig::get('JQZOOM_SHOWTITLE')),
'jqzoom_lensshape' => Tools::getValue('jqzoom_lensshape', JQZoomConfig::get('JQZOOM_LENSSHAPE')),
'jqzoom_fadeineffect' => Tools::getValue('jqzoom_fadeineffect', JQZoomConfig::get('JQZOOM_FADEINEFFECT')),
'jqzoom_fadeouteffect' => Tools::getValue('jqzoom_fadeouteffect',
JQZoomConfig::get('JQZOOM_FADEOUTEFFECT')),
'jqzoom_tintcolor' => Tools::getValue('jqzoom_tintcolor', JQZoomConfig::get('JQZOOM_TINTCOLOR')),
'jqzoom_tintopacity' => Tools::getValue('jqzoom_tintopacity', JQZoomConfig::get('JQZOOM_TINTOPACITY')),
'jqzoom_lenscolor' => Tools::getValue('jqzoom_lenscolor', JQZoomConfig::get('JQZOOM_LENSCOLOR')),
'jqzoom_lensopacity' => Tools::getValue('jqzoom_lensopacity', JQZoomConfig::get('JQZOOM_LENSOPACITY')),
'jqzoom_zoompower' => Tools::getValue('jqzoom_zoompower', JQZoomConfig::get('JQZOOM_ZOOMPOWER')),
);
}
private function displayErrors()
{
$this->html .= $this->displayError(implode('<br />', $this->postErrors));
}
private function displayConf($conf_number)
{
if ($conf_number == 1) {
$this->html .= $this->displayConfirmation($this->l('Configuration updated.'));
}
}
public function hookHeader($params)
{
// Determine page
if (!($file = basename(Tools::getValue('controller')))) {
$file = str_replace('.php', '', basename($_SERVER['SCRIPT_NAME']));
}
if (in_array($file, array('product'))) {
$this->context->controller->addCSS(($this->_path) . 'views/css/jqzoomevolution.css', 'all');
$this->context->controller->addJS($this->_path . 'views/js/jqzoomevolution.js');
$JQZoomConf = JQZoomConfig::getAll();
Media::addJsDef(array('jqzoomConf' => $JQZoomConf));
}
}
}