first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,632 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusConfigurationController extends ModuleAdminController
{
protected $isShopSelected = true;
public function __construct()
{
$this->bootstrap = true;
$this->tabClassName = 'AdminCookiesPlusConfiguration';
parent::__construct();
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
// CodeMirror
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.css');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/theme/monokai.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/addon/display/autorefresh.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/css/css.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/javascript/javascript.js');
// Shepherd
if (version_compare(_PS_VERSION_, '1.6', '<')) {
Configuration::updateValue('C_P_SHEPHERD', 1);
}
if (!Configuration::get('C_P_SHEPHERD')) {
Configuration::updateValue('C_P_SHEPHERD', 1);
$this->context->smarty->assign([
'C_P_SHEPHERD_STEP1_1' => $this->l('A new menu has been added to configure the Cookies module.') . '\n\r' . $this->l('Please check all the options before enable it.'),
]);
echo $this->context->smarty->fetch($this->module->getLocalPath() . 'lib/shepherd/shepherd.tpl');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/shepherd/shepherd.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/shepherd/shepherd.js');
}
// Tabs
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/tabs.css');
}
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/tabs.js');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/cookiesplus-back.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/cookiesplus-back.js');
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (((bool) Tools::isSubmit('submitCookiesPlusModuleUpdate')) == true) {
Configuration::deleteByName('C_P_UPDATE');
}
if (((bool) Tools::isSubmit('submitCookiesPlusModule')) == true) {
$fields = $this->getConfigFormValues();
if (!Tools::getValue('C_P_EXPIRY')) {
$this->errors[] = $this->l('You have to introduce the cookie expiry time');
} elseif (Tools::getValue('C_P_EXPIRY') <= 0
|| !Validate::isUnsignedInt(Tools::getValue('C_P_EXPIRY'))) {
$this->errors[] = $this->l('You have to introduce a correct value for cookie expiry time');
}
foreach (explode('|', Tools::getValue('C_P_IPS')) as $ip) {
if ($ip && !filter_var($ip, FILTER_VALIDATE_IP)) {
$this->errors[] = sprintf($this->l('Property %s is not valid'), $ip);
}
}
if (!count($this->errors)) {
foreach (array_keys($fields) as $key) {
if ($key === 'C_P_BOTS'
|| $key === 'C_P_IPS') {
$fields[$key] = trim(preg_replace('/\|+/', '|', $fields[$key]), '|');
Configuration::updateValue($key, $fields[$key]);
} else {
Configuration::updateValue($key, $fields[$key], true);
}
}
$this->confirmations[] = $this->l('Settings saved successfully');
}
}
$this->content .= $this->renderGlobalConfigForm();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$module = $this->module;
$default_iso_code = 'en';
$local_path = $module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $module->addons_id_product,
'readme' => $readme,
'this_path' => $module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
parent::initContent();
}
public function initToolbar()
{
parent::initToolbar();
unset($this->toolbar_btn['new']);
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
if (empty($this->display)) {
/*$this->page_header_toolbar_btn['desc-module-new'] = array(
'href' => 'index.php?controller='.$this->tabClassName.'&add'.$this->table.'&token='.Tools::getAdminTokenLite($this->tabClassName),
'desc' => $this->l('New'),
'icon' => 'process-icon-new'
);*/
$this->page_header_toolbar_btn['desc-module-translate'] = [
'href' => '#',
'desc' => $this->l('Translate'),
'modal_target' => '#moduleTradLangSelect',
'icon' => 'process-icon-flag',
];
$this->page_header_toolbar_btn['desc-module-hook'] = [
'href' => 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . Module::getModuleIdByName($this->module->name),
'desc' => $this->l('Manage hooks'),
'icon' => 'process-icon-anchor',
];
}
if (!$this->isShopSelected) {
unset($this->page_header_toolbar_btn['desc-module-new']);
}
$this->context->smarty->clearAssign('help_link', '');
}
public function initModal()
{
parent::initModal();
$languages = Language::getLanguages(false);
$translateLinks = [];
if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) {
$module = Module::getInstanceByName($this->module->name);
$isNewTranslateSystem = $module->isUsingNewTranslationSystem();
$link = Context::getContext()->link;
foreach ($languages as $lang) {
if ($isNewTranslateSystem) {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [
'lang' => $lang['iso_code'],
'type' => 'modules',
'selected' => $module->name,
'locale' => $lang['locale'],
]);
} else {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [
'type' => 'modules',
'module' => $module->name,
'lang' => $lang['iso_code'],
]);
}
}
}
$this->context->smarty->assign([
'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=',
'module_languages' => $languages,
'module_name' => $this->module->name,
'translateLinks' => $translateLinks,
]);
$modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl');
$this->modals[] = [
'modal_id' => 'moduleTradLangSelect',
'modal_class' => 'modal-sm',
'modal_title' => $this->l('Translate this module'),
'modal_content' => $modal_content,
];
}
protected function renderGlobalConfigForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->currentIndex = self::$currentIndex;
$helper->submit_action = 'submitCookiesPlusModule';
$helper->token = Tools::getAdminTokenLite($this->tabClassName);
$helper->tpl_vars = [
'fields_value' => array_merge($this->getConfigFormValues(), $this->getConfigFormTPLs()),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm($this->getConfigForm());
}
protected function getConfigForm()
{
$fields_form = [];
if (Configuration::get('C_P_UPDATE')) {
$fieldsFormIndex = 0;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Warning'),
'icon' => 'icon-warning',
],
'input' => [
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_UPDATE_MSG.tpl'),
],
],
'submit' => [
'title' => $this->l('Understood'),
'type' => 'submit',
'name' => 'submitCookiesPlusModuleUpdate',
],
];
return $fields_form;
}
$fieldsFormIndex = 0;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Module settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Enable module'),
'name' => 'C_P_ENABLE',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_ENABLE_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_ENABLE_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
[
'col' => 6,
'type' => 'text',
'label' => $this->l('Cookie lifetime'),
'desc' => $this->l('The cookie consent will be stored during this time (or until customer delete cookies)') . '<br />' . $this->l('Once the consent is expired, the banner will be displayed again to ask for the consent.'),
'suffix' => $this->l('days'),
'name' => 'C_P_EXPIRY',
'class' => 't fixed-width-xl',
'required' => true,
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Enable module only for the specified IPs (DEBUG mode)'),
'name' => 'C_P_DEBUG',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_DEBUG_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_DEBUG_off',
'value' => 0,
'label' => $this->l('No'), ],
],
'desc' => $this->l('Display the banner only for the specified IPs'),
],
[
'cols' => 113,
'rows' => 4,
'type' => 'textarea',
'label' => $this->l('Display only for these IPs'),
'desc' => $this->l('Cookies (and modules) will only be blocked and cookies notice will only be displayed for these IPs') . '<br />' . $this->l('Separate each IP with a "|" (pipe) character'),
'name' => 'C_P_IPS_DEBUG',
'class' => 't',
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Reload page when user gives consent'),
'desc' => $this->l('If disabled, the consent will be sent dinamically and the page will not be reloaded.') . '<br />' . $this->l('The blocked scripts are loaded "on the fly", without losing referrers nor bounces.'),
'name' => 'C_P_REFRESH',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_REFRESH_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_REFRESH_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Display notice to customers outside the EU'),
'desc' => Configuration::get('PS_GEOLOCATION_ENABLED') ? '' : $this->l('Geolocation must be enabled to enable this option'),
'name' => 'C_P_GEO',
'class' => 't',
'disabled' => !Configuration::get('PS_GEOLOCATION_ENABLED'),
'is_bool' => true,
'values' => [
[
'id' => 'C_P_GEO_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_GEO_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
[
'cols' => 113,
'rows' => 4,
'type' => 'textarea',
'label' => $this->l('Don\'t apply restrictions for these user agents (SEO)'),
'desc' => $this->l('Cookies (and modules) will not be blocked and cookies notice will not be displayed for these user agents') . '<br />' . $this->l('Separate each user agent with a "|" (pipe) character'),
'name' => 'C_P_BOTS',
'class' => 't',
],
[
'cols' => 113,
'rows' => 4,
'type' => 'textarea',
'label' => $this->l('Don\'t apply restrictions for these IPs'),
'desc' => $this->l('Cookies (and modules) will not be blocked for these IPs') . '<br />' . $this->l('Separate each IP with a "|" (pipe) character'),
'name' => 'C_P_IPS',
'class' => 't',
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
'name' => 'submitCookiesPlusModule',
],
];
/*
$fieldsFormIndex++;
$fields_form[$fieldsFormIndex]['form'] = array(
'legend' => array(
'title' => $this->l('Appearance'),
'icon' => 'icon-pencil',
),
'input' => array(
array(
'col' => 12,
'type' => 'free',
'label' => '',
'name' => 'C_P_MENU',
'class' => 't',
'lang' => true,
),
),
);
$fieldsFormIndex++;
$fields_form[$fieldsFormIndex]['form'] = array(
'legend' => array(
'title' => $this->l('Cookie finalities'),
'icon' => 'icon-pencil',
),
'input' => array(
array(
'col' => 12,
'type' => 'free',
'label' => '',
'name' => 'C_P_MENU',
'class' => 't',
'lang' => true,
),
),
);
$fieldsFormIndex++;
$fields_form[$fieldsFormIndex]['form'] = array(
'legend' => array(
'title' => $this->l('Cookies'),
'icon' => 'icon-pencil',
),
'input' => array(
array(
'col' => 12,
'type' => 'free',
'label' => '',
'name' => 'C_P_MENU',
'class' => 't',
'lang' => true,
),
),
);
*/
++$fieldsFormIndex;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Advanced'),
'icon' => 'icon-magic',
],
'input' => [
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_WARNING.tpl'),
],
/*array(
'type' => 'text',
'label' => 'C_P_HOOK_EXECUTED',
'name' => 'C_P_HOOK_EXECUTED',
'col' => 1
),
array(
'type' => 'text',
'label' => 'C_P_HOOK_POSITION',
'name' => 'C_P_HOOK_POSITION',
'col' => 1
),*/
[
'type' => 'textarea',
'label' => 'CSS',
'name' => 'C_P_CSS',
'cols' => 100,
'rows' => 10,
'class' => 't codemirror codemirror-css',
],
[
'type' => 'textarea',
'label' => 'JS',
'name' => 'C_P_JS',
'cols' => 100,
'rows' => 10,
'class' => 't codemirror codemirror-js',
],
[
'type' => 'select',
'label' => 'Icons library',
'name' => 'C_P_MATERIAL_ICONS_LIBRARY',
'class' => 't',
'options' => [
'query' => [
[
'id' => '1',
'name' => 'Material Icons',
],
[
'id' => '2',
'name' => 'Fontello',
],
[
'id' => '3',
'name' => 'Font Awesome',
],
],
'id' => 'id',
'name' => 'name',
],
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => 'Add Material Icons CSS library',
'name' => 'C_P_MATERIAL_ICONS',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_MATERIAL_ICONS_on',
'value' => 1,
'label' => 'Yes',
],
[
'id' => 'C_P_MATERIAL_ICONS_off',
'value' => 0,
'label' => 'No',
],
],
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
'name' => 'submitCookiesPlusModule',
],
];
return $fields_form;
}
protected function getConfigFormValues()
{
$fields = [];
$configFields = [
'C_P_HOOK_EXECUTED',
'C_P_HOOK_POSITION',
'C_P_CSS',
'C_P_JS',
'C_P_MATERIAL_ICONS',
'C_P_MATERIAL_ICONS_LIBRARY',
'C_P_ENABLE',
'C_P_REFRESH',
'C_P_GEO',
'C_P_DEBUG',
'C_P_EXPIRY',
'C_P_BOTS',
'C_P_IPS',
'C_P_IPS_DEBUG',
];
foreach ($configFields as $field) {
$fields[$field] = Tools::getValue($field, Configuration::get($field));
}
return $fields;
}
protected function getConfigFormTPLs()
{
$fields = [];
$this->context->smarty->assign([
'this_path' => $this->module->getPathUri(),
'support_id' => $this->module->addons_id_product,
]);
/*$fields['C_P_MENU'] =
$this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_MENU.tpl');*/
return $fields;
}
}

View File

@@ -0,0 +1,475 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusCookiesController extends ModuleAdminController
{
protected $isShopSelected = true;
private $tabClassName;
public function __construct()
{
$this->bootstrap = true;
$this->table = 'cookiesplus_cookie';
$this->className = 'CookiesPlusCookie';
$this->tabClassName = 'AdminCookiesPlusCookies';
$this->lang = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
parent::__construct();
$this->bulk_actions = [
'delete' => [
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'),
'icon' => 'icon-trash',
],
];
$this->context = Context::getContext();
$this->default_form_language = $this->context->language->id;
$cookiesPlusFinalitiesArray = [];
$cookiesPlusFinalities = CookiesPlusFinality::getCookiesPlusFinalities($this->context->language->id);
foreach ($cookiesPlusFinalities as $cookiesPlusFinality) {
$cookiesPlusFinalitiesArray[$cookiesPlusFinality['id_cookiesplus_finality']] = $cookiesPlusFinality['name'];
}
$this->fields_list = [
'active' => [
'title' => $this->l('Enabled'),
'active' => 'active',
'type' => 'bool',
],
'name' => [
'title' => $this->l('Cookie name'),
'filter_key' => 'a!name',
],
'id_cookiesplus_finality' => [
'title' => $this->l('Cookie finality'),
'callback' => 'getFinalityNameCallback',
'callback_object' => 'CookiesPlusFinality',
'type' => 'select',
'list' => $cookiesPlusFinalitiesArray,
'filter_key' => 'a!id_cookiesplus_finality',
],
'provider' => [
'title' => $this->l('Provider'),
],
'purpose' => [
'title' => $this->l('Purpose'),
'callback' => 'getCookiePurposeCallback',
'callback_object' => 'CookiesPlusCookie',
],
'expiry' => [
'title' => $this->l('Expiry'),
],
];
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryPlugin(['typewatch', 'fancybox', 'autocomplete']);
$this->addJqueryUI(['ui.datepicker', 'ui.button', 'ui.sortable', 'ui.droppable']);
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/cookiesplus-back.css');
if ($this->display) {
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/cookiesplus-back.js');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.css');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/theme/monokai.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/addon/display/autorefresh.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/css/css.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/javascript/javascript.js');
}
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (Tools::isSubmit('submitCookiesPlusRevokeCookies')) {
Configuration::updateValue('C_P_REVOKE_CONSENT', date('Y-m-d H:i:s', time()));
$this->confirmations[] = $this->l('Revoke consent updated');
}
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/cookies.tpl');
parent::initContent();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (!$this->display) {
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$module = $this->module;
$default_iso_code = 'en';
$local_path = $module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $module->addons_id_product,
'readme' => $readme,
'this_path' => $module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
}
}
public function initProcess()
{
parent::initProcess();
if (Tools::isSubmit('activecookiesplus_cookie') && $this->id_object) {
$this->toggleProperty('active', $this->id_object);
if (!$this->errors) {
// Remove toggle from URL
Tools::redirectAdmin(Context::getContext()->link->getAdminLink($this->tabClassName));
}
}
}
public function toggleProperty($property, $id)
{
if (version_compare(_PS_VERSION_, '1.7', '<')) {
if ($this->tabAccess['edit'] !== '1') {
$this->errors[] = $this->l('You do not have permission to edit this.');
return;
}
} else {
if (!$this->access('edit')) {
$this->errors[] = $this->l('You do not have permission to edit this.');
return;
}
}
$object = new $this->className($id);
if (!Validate::isLoadedObject($object)) {
$this->errors[] = $this->l('An error occurred while updating an object.');
}
$object->$property = !$object->$property;
if (!$object->save()) {
$this->errors[] = $this->l('An error occurred while updating an object.');
}
}
public function initToolbar()
{
parent::initToolbar();
if (!$this->isShopSelected) {
unset($this->toolbar_btn['new']);
}
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
if (empty($this->display)) {
$this->page_header_toolbar_btn['desc-module-new'] = [
'href' => 'index.php?controller=' . $this->tabClassName . '&add' . $this->table . '&token=' . Tools::getAdminTokenLite($this->tabClassName),
'desc' => $this->l('New'),
'icon' => 'process-icon-new',
];
}
if (!$this->isShopSelected) {
unset($this->page_header_toolbar_btn['desc-module-new']);
}
$this->context->smarty->clearAssign('help_link', '');
}
public function initModal()
{
parent::initModal();
$languages = Language::getLanguages(false);
$translateLinks = [];
if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) {
$module = Module::getInstanceByName($this->module->name);
$isNewTranslateSystem = $module->isUsingNewTranslationSystem();
$link = Context::getContext()->link;
foreach ($languages as $lang) {
if ($isNewTranslateSystem) {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [
'lang' => $lang['iso_code'],
'type' => 'modules',
'selected' => $module->name,
'locale' => $lang['locale'],
]);
} else {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [
'type' => 'modules',
'module' => $module->name,
'lang' => $lang['iso_code'],
]);
}
}
}
$this->context->smarty->assign([
'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=',
'module_languages' => $languages,
'module_name' => $this->module->name,
'translateLinks' => $translateLinks,
]);
$modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl');
$this->modals[] = [
'modal_id' => 'moduleTradLangSelect',
'modal_class' => 'modal-sm',
'modal_title' => $this->l('Translate this module'),
'modal_content' => $modal_content,
];
}
public function renderList()
{
$this->context->smarty->assign([
'revokeConsentDate' => Tools::displayDate(date('Y-m-d H:i:s', strtotime(Configuration::get('C_P_REVOKE_CONSENT'))), null, true),
]);
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/revoke-consent.tpl');
return parent::renderList();
}
public function renderForm()
{
if (!$this->isShopSelected && $this->display === 'add') {
$this->errors[] = $this->l('You have to select a shop.');
return parent::renderForm();
}
$this->context->smarty->assign([
'revokeConsentDate' => Tools::displayDate(date('Y-m-d H:i:s', strtotime(Configuration::get('C_P_REVOKE_CONSENT'))), null, true),
]);
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/revoke-consent.tpl');
$this->multiple_fieldsets = true;
$this->default_form_language = $this->context->language->id;
$cookiesPlusFinalities = CookiesPlusFinality::getCookiesPlusFinalities($this->context->language->id);
$dummyElement = [
'id_cookiesplus_finality' => '',
'name' => $this->l('-- Choose --'),
];
array_unshift($cookiesPlusFinalities, $dummyElement);
$fieldsFormIndex = 0;
$this->fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Configure cookie'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'hidden',
'name' => 'id_cookiesplus_cookie',
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Enabled'),
'name' => 'active',
'class' => 't',
'col' => 8,
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled'),
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled'),
],
],
],
[
'type' => 'select',
'label' => $this->l('Cookie finality'),
'name' => 'id_cookiesplus_finality',
'required' => true,
'options' => [
'query' => $cookiesPlusFinalities,
'id' => 'id_cookiesplus_finality',
'name' => 'name',
],
],
[
'type' => 'text',
'label' => $this->l('Cookie name'),
'name' => 'name',
'required' => true,
],
[
'type' => 'text',
'label' => $this->l('Provider'),
'name' => 'provider',
],
[
'type' => 'text',
'label' => $this->l('Provider URL'),
'name' => 'provider_url',
],
[
'type' => 'textarea',
'label' => $this->l('Purpose'),
'name' => 'purpose',
'lang' => true,
],
[
'type' => 'text',
'label' => $this->l('Expiry'),
'name' => 'expiry',
'lang' => true,
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
],
'buttons' => [
'save-and-stay' => [
'title' => $this->l('Save and stay'),
'name' => 'submitAdd' . $this->table . 'AndStay',
'type' => 'submit',
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-save',
],
],
];
$this->content .= parent::renderForm();
}
public function processSave()
{
$result = parent::processSave();
if (Tools::getValue('back') && (int) Tools::getvalue('id_cookiesplus_finality')) {
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminCookiesPlusFinalities') . '&updatecookiesplus_finality=&conf=4&id_cookiesplus_finality=' . (int) Tools::getValue('id_cookiesplus_finality');
}
return $result;
}
public function displayDeleteLink($token = null, $id = null, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_delete.tpl');
$tpl->assign([
'href' => self::$currentIndex . '&' . $this->identifier . '=' . $id . '&delete' . $this->table . '&token=' . ($token != null ? $token : $this->token),
'confirm' => $this->l('Delete the selected item?') . $name,
'action' => $this->l('Delete'),
'id' => $id,
]);
return $tpl->fetch();
}
private function _createTemplate($tpl_name)
{
if ($this->override_folder) {
if ($this->context->controller instanceof ModuleAdminController) {
$override_tpl_path = $this->context->controller->getTemplatePath() . $tpl_name;
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/' . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(0) . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(0) . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
}
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/' . $tpl_name;
}
if (isset($override_tpl_path) && file_exists($override_tpl_path)) {
return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty);
} else {
return $this->context->smarty->createTemplate($tpl_name, $this->context->smarty);
}
}
}

View File

@@ -0,0 +1,312 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusFBController extends ModuleAdminController
{
protected $isShopSelected = true;
public function __construct()
{
$this->bootstrap = true;
$this->tabClassName = 'AdminCookiesPlusFB';
parent::__construct();
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (((bool) Tools::isSubmit('submitCookiesPlusModule')) == true) {
if (Tools::getValue('C_P_FB_ENABLE') && !Tools::getValue('fbConfiguration')) {
$this->errors[] = $this->l('You have to define the needed consents to fire the Facebook Pixel.');
}
if (!count($this->errors)) {
$fields = $this->getConfigFormValues();
foreach (array_keys($fields) as $key) {
Configuration::updateValue($key, $fields[$key], true);
}
if ($key === 'C_P_FB_CONSENT') {
$value = json_encode(Tools::getValue('fbConfiguration'));
Configuration::updateValue($key, $value);
} else {
Configuration::updateValue($key, $fields[$key], true);
}
$this->confirmations[] = $this->l('Settings saved successfully');
}
}
$this->content .= $this->renderGlobalConfigForm();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$module = $this->module;
$default_iso_code = 'en';
$local_path = $module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $module->addons_id_product,
'readme' => $readme,
'this_path' => $module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
parent::initContent();
}
public function initToolbar()
{
parent::initToolbar();
unset($this->toolbar_btn['new']);
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
if (empty($this->display)) {
/*$this->page_header_toolbar_btn['desc-module-new'] = array(
'href' => 'index.php?controller='.$this->tabClassName.'&add'.$this->table.'&token='.Tools::getAdminTokenLite($this->tabClassName),
'desc' => $this->l('New'),
'icon' => 'process-icon-new'
);*/
$this->page_header_toolbar_btn['desc-module-translate'] = [
'href' => '#',
'desc' => $this->l('Translate'),
'modal_target' => '#moduleTradLangSelect',
'icon' => 'process-icon-flag',
];
$this->page_header_toolbar_btn['desc-module-hook'] = [
'href' => 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . Module::getModuleIdByName($this->module->name),
'desc' => $this->l('Manage hooks'),
'icon' => 'process-icon-anchor',
];
}
if (!$this->isShopSelected) {
unset($this->page_header_toolbar_btn['desc-module-new']);
}
$this->context->smarty->clearAssign('help_link', '');
}
public function initModal()
{
parent::initModal();
$languages = Language::getLanguages(false);
$translateLinks = [];
if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) {
$module = Module::getInstanceByName($this->module->name);
$isNewTranslateSystem = $module->isUsingNewTranslationSystem();
$link = Context::getContext()->link;
foreach ($languages as $lang) {
if ($isNewTranslateSystem) {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [
'lang' => $lang['iso_code'],
'type' => 'modules',
'selected' => $module->name,
'locale' => $lang['locale'],
]);
} else {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [
'type' => 'modules',
'module' => $module->name,
'lang' => $lang['iso_code'],
]);
}
}
}
$this->context->smarty->assign([
'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=',
'module_languages' => $languages,
'module_name' => $this->module->name,
'translateLinks' => $translateLinks,
]);
$modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl');
$this->modals[] = [
'modal_id' => 'moduleTradLangSelect',
'modal_class' => 'modal-sm',
'modal_title' => $this->l('Translate this module'),
'modal_content' => $modal_content,
];
}
protected function renderGlobalConfigForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->currentIndex = self::$currentIndex;
$helper->submit_action = 'submitCookiesPlusModule';
$helper->token = Tools::getAdminTokenLite($this->tabClassName);
$helper->tpl_vars = [
'fields_value' => array_merge($this->getConfigFormValues(), $this->getConfigFormTPLs()),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm($this->getConfigForm());
}
protected function getConfigForm()
{
$fields_form = [];
$fieldsFormIndex = 0;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Facebook Pixel settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_FB.tpl'),
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Enable integration with the Facebook Pixel'),
'name' => 'C_P_FB_ENABLE',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_FB_ENABLE_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_FB_ENABLE_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
[
'col' => 8,
'type' => 'html',
'label' => 'Cookie finalities needed to include the Facebook Pixel in the page',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_FB_CONSENT.tpl'),
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
'name' => 'submitCookiesPlusModule',
],
];
return $fields_form;
}
protected function getConfigFormValues()
{
$fields = [];
$configFields = [
'C_P_FB_ENABLE',
'C_P_FB_CONSENT',
];
foreach ($configFields as $field) {
$fields[$field] = Tools::getValue($field, Configuration::get($field));
}
return $fields;
}
protected function getConfigFormTPLs()
{
$fields = [];
$this->context->smarty->assign([
'cookiesPlusFinalities' => CookiesPlusFinality::getCookiesPlusFinalities((int) $this->context->language->id, false, false),
'fieldName' => 'fbConfiguration',
'values' => json_decode(Configuration::get('C_P_FB_CONSENT'), true),
]);
return $fields;
}
}

View File

@@ -0,0 +1,610 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusFinalitiesController extends ModuleAdminController
{
protected $isShopSelected = true;
protected $_defaultOrderBy = 'position';
private $tabClassName;
public function __construct()
{
$this->bootstrap = true;
$this->table = 'cookiesplus_finality';
$this->className = 'CookiesPlusFinality';
$this->tabClassName = 'AdminCookiesPlusFinalities';
$this->lang = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
parent::__construct();
$this->bulk_actions = [
'delete' => [
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'),
'icon' => 'icon-trash',
],
];
$this->context = Context::getContext();
$this->default_form_language = $this->context->language->id;
$this->position_identifier = 'position';
$this->fields_list = [
'id_cookiesplus_finality' => [
'title' => $this->l('ID'),
'search' => false,
],
'active' => [
'title' => $this->l('Enabled'),
'active' => 'active',
'type' => 'bool',
'search' => false,
],
'name' => [
'title' => $this->l('Cookie finality name'),
'filter_key' => 'b!name',
'search' => false,
],
'description' => [
'title' => $this->l('Cookie finality description'),
'callback' => 'getFinalityDescriptionCallback',
'callback_object' => 'CookiesPlusFinality',
'search' => false,
],
'technical' => [
'title' => $this->l('Technical'),
'align' => 'text-center',
'active' => 'technical',
'type' => 'bool',
'search' => false,
],
'position' => [
'title' => $this->l('Position'),
'align' => 'center',
'class' => 'fixed-width-sm',
'position' => 'position',
'search' => false,
],
];
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryPlugin(['typewatch', 'fancybox', 'autocomplete']);
$this->addJqueryUI(['ui.datepicker', 'ui.button', 'ui.sortable', 'ui.droppable']);
// Tabs
/*if (version_compare(_PS_VERSION_, '1.6', '<')) {
$this->addCSS(_MODULE_DIR_.$this->module->name.'/views/css/tabs.css');
}
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/tabs.js');
*/
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/cookiesplus-back.css');
if ($this->display) {
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/cookiesplus-back.js');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.css');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/theme/monokai.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/addon/display/autorefresh.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/css/css.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/javascript/javascript.js');
}
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (Tools::isSubmit('submitCookiesPlusRevokeCookies')) {
Configuration::updateValue('C_P_REVOKE_CONSENT', date('Y-m-d H:i:s', time()));
$this->confirmations[] = $this->l('Revoke consent updated');
}
parent::initContent();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (!$this->display) {
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$default_iso_code = 'en';
$local_path = $this->module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $this->module->addons_id_product,
'readme' => $readme,
'this_path' => $this->module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
$this->context->smarty->assign([
'content' => $this->content,
]);
}
}
public function initProcess()
{
parent::initProcess();
if (Tools::isSubmit('activecookiesplus_finality') && $this->id_object) {
$this->toggleProperty('active', $this->id_object);
if (!$this->errors) {
// Remove toggle from URL
Tools::redirectAdmin(Context::getContext()->link->getAdminLink($this->tabClassName));
}
}
if (Tools::isSubmit('technicalcookiesplus_finality') && $this->id_object) {
$this->toggleProperty('technical', $this->id_object);
if (!$this->errors) {
// Remove toggle from URL
Tools::redirectAdmin(Context::getContext()->link->getAdminLink($this->tabClassName));
}
}
}
public function toggleProperty($property, $id)
{
if (version_compare(_PS_VERSION_, '1.7', '<')) {
if ($this->tabAccess['edit'] !== '1') {
$this->errors[] = $this->l('You do not have permission to edit this.');
return;
}
} else {
if (!$this->access('edit')) {
$this->errors[] = $this->l('You do not have permission to edit this.');
return;
}
}
$object = new $this->className($id);
if (!Validate::isLoadedObject($object)) {
$this->errors[] = $this->l('An error occurred while updating an object.');
}
$object->$property = !$object->$property;
if (!$object->save()) {
$this->errors[] = $this->l('An error occurred while updating an object.');
}
}
public function initToolbar()
{
parent::initToolbar();
if (!$this->isShopSelected) {
unset($this->toolbar_btn['new']);
}
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
if (empty($this->display)) {
$this->page_header_toolbar_btn['desc-module-new'] = [
'href' => 'index.php?controller=' . $this->tabClassName . '&add' . $this->table . '&token=' . Tools::getAdminTokenLite($this->tabClassName),
'desc' => $this->l('New'),
'icon' => 'process-icon-new',
];
}
if (!$this->isShopSelected) {
unset($this->page_header_toolbar_btn['desc-module-new']);
}
$this->context->smarty->clearAssign('help_link', '');
}
public function initModal()
{
parent::initModal();
$languages = Language::getLanguages(false);
$translateLinks = [];
if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) {
$module = Module::getInstanceByName($this->module->name);
$isNewTranslateSystem = $module->isUsingNewTranslationSystem();
$link = Context::getContext()->link;
foreach ($languages as $lang) {
if ($isNewTranslateSystem) {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [
'lang' => $lang['iso_code'],
'type' => 'modules',
'selected' => $module->name,
'locale' => $lang['locale'],
]);
} else {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [
'type' => 'modules',
'module' => $module->name,
'lang' => $lang['iso_code'],
]);
}
}
}
$this->context->smarty->assign([
'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=',
'module_languages' => $languages,
'module_name' => $this->module->name,
'translateLinks' => $translateLinks,
]);
$modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl');
$this->modals[] = [
'modal_id' => 'moduleTradLangSelect',
'modal_class' => 'modal-sm',
'modal_title' => $this->l('Translate this module'),
'modal_content' => $modal_content,
];
}
public function renderList()
{
// Redirect if no object created
/*if ($this->isShopSelected && !LoyaltyEditPointsAssignment::getNbObjects()) {
$this->redirect_after = 'index.php?controller='.$this->tabClassName.'&add'.$this->table.'&token='.Tools::getAdminTokenLite($this->tabClassName);
$this->redirect();
}*/
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/cookie-finalities.tpl');
$this->context->smarty->assign([
'revokeConsentDate' => Tools::displayDate(date('Y-m-d H:i:s', strtotime(Configuration::get('C_P_REVOKE_CONSENT'))), null, true),
]);
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/revoke-consent.tpl');
return parent::renderList();
}
public function renderForm()
{
if (!$this->isShopSelected && $this->display === 'add') {
$this->errors[] = $this->l('You have to select a shop.');
return parent::renderForm();
}
$this->context->smarty->assign([
'revokeConsentDate' => Tools::displayDate(date('Y-m-d H:i:s', strtotime(Configuration::get('C_P_REVOKE_CONSENT'))), null, true),
]);
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/revoke-consent.tpl');
$object = $this->loadObject(true);
$this->multiple_fieldsets = true;
$this->default_form_language = $this->context->language->id;
// Modules blocked
$modules = $this->module->getModuleList();
$selectedModules = (array) json_decode($object->modules);
foreach ($modules as &$module) {
if (in_array($module['id_module'], $selectedModules)) {
$module['checked'] = true;
} else {
$module['checked'] = false;
}
$module['sortDisplayName'] = strtolower($module['displayName']);
}
unset($module);
array_multisort(
array_column(
$modules,
'checked'
),
SORT_DESC,
array_column(
$modules,
'sortDisplayName'
),
SORT_ASC,
$modules
);
$this->context->smarty->assign([
'allModules' => $modules,
'fieldName' => 'modules',
]);
$fieldsFormIndex = 0;
$this->fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Cookie finality'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'hidden',
'name' => 'id_cookiesplus_finality',
],
[
'type' => 'hidden',
'name' => 'position',
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Enabled'),
'name' => 'active',
'class' => 't',
'col' => 8,
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No'),
],
],
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('This is a Technical finality'),
'name' => 'technical',
'class' => 't',
'col' => 8,
'is_bool' => true,
'values' => [
[
'id' => 'technical_on',
'value' => 1,
'label' => $this->l('Yes'),
],
[
'id' => 'technical_off',
'value' => 0,
'label' => $this->l('No'),
],
],
'desc' => $this->l('Technical cookies can not be disabled. They are installed automatically.'),
],
[
'type' => 'text',
'label' => $this->l('Cookie finality name'),
'name' => 'name',
'required' => true,
'lang' => true,
],
[
'type' => 'textarea',
'label' => $this->l('Cookie finality description'),
'name' => 'description',
'required' => true,
'lang' => true,
'autoload_rte' => true,
'cols' => 60,
'rows' => 30,
],
[
'type' => 'html',
'col' => 8,
'label' => $this->l('Cookies from this finality'),
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/cookies-list.tpl') . $this->module->getCookiesPlusCookiesList(),
],
[
'type' => 'html',
'name' => 'html',
'html_content' => (Module::isInstalled('litespeedcache') || Module::isInstalled('stadvancedcache') || Module::isInstalled('jprestaspeedpack') || Module::isInstalled('pagecache')) ? '<div class="alert alert-warning">' . $this->l('If you are using a cache module please clear cache when you make any modification.') . '</div>' : '',
],
[
'type' => 'html',
'col' => 8,
'label' => $this->l('Modules blocked'),
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/configure_modules.tpl'),
],
[
'type' => 'textarea',
'label' => $this->l('Execute this JS script when this cookie finality is accepted'),
'name' => 'js_script',
'cols' => 100,
'rows' => 10,
'class' => 't codemirror codemirror-js',
'desc' => sprintf($this->l('Enclose the script between the %s%s tags'), htmlspecialchars('<script>'), htmlspecialchars('</script>')),
],
[
'type' => 'textarea',
'label' => $this->l('Execute this JS script when this cookie finality is rejected'),
'name' => 'js_not_script',
'cols' => 100,
'rows' => 10,
'class' => 't codemirror codemirror-js',
'desc' => sprintf($this->l('Enclose the script between the %s%s tags'), htmlspecialchars('<script>'), htmlspecialchars('</script>')),
],
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_SCRIPT_BLOCK.tpl'),
],
/* Used to override token field from previous helperlist */
[
'type' => 'hidden',
'name' => 'token',
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
],
'buttons' => [
'save-and-stay' => [
'title' => $this->l('Save and stay'),
'name' => 'submitAdd' . $this->table . 'AndStay',
'type' => 'submit',
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-save',
],
],
];
$this->content .= parent::renderForm();
}
public function processSave()
{
$_POST['modules'] = json_encode(Tools::getValue('modules'));
$_POST['js_script'] = str_replace(['{literal}', '{/literal}'], '', Tools::getValue('js_script'));
$_POST['js_not_script'] = str_replace(['{literal}', '{/literal}'], '', Tools::getValue('js_not_script'));
return parent::processSave();
}
protected function afterAdd($object)
{
// Warning: Declaration of AdminCookiesPlusFinalitiesController::afterAdd() should be compatible with AdminControllerCore::afterAdd($object)
$cookiesPlusFinality = new CookiesPlusFinality((int) Tools::getValue('id_cookiesplus_finality'));
$cookiesPlusFinality->position = $cookiesPlusFinality->getHigherPosition() + 1;
$cookiesPlusFinality->save();
return true;
}
public function displayDeleteLink($token = null, $id = null, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_delete.tpl');
$tpl->assign([
'href' => self::$currentIndex . '&' . $this->identifier . '=' . $id . '&delete' . $this->table . '&token=' . ($token != null ? $token : $this->token),
'confirm' => $this->l('Delete the selected item?') . $name,
'action' => $this->l('Delete'),
'id' => $id,
]);
return $tpl->fetch();
}
private function _createTemplate($tpl_name)
{
if ($this->override_folder) {
if ($this->context->controller instanceof ModuleAdminController) {
$override_tpl_path = $this->context->controller->getTemplatePath() . $tpl_name;
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/' . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(0) . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(0) . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
}
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/' . $tpl_name;
}
if (isset($override_tpl_path) && file_exists($override_tpl_path)) {
return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty);
} else {
return $this->context->smarty->createTemplate($tpl_name, $this->context->smarty);
}
}
public function ajaxProcessUpdatePositions()
{
$way = (int) Tools::getValue('way');
$id = (int) Tools::getValue('id');
$positions = Tools::getValue($this->table);
foreach ($positions as $position => $value) {
$pos = explode('_', $value);
if (isset($pos[2]) && (int) $pos[2] === $id) {
if ($conf = new CookiesPlusFinality((int) $pos[2])) {
if (isset($position) && $conf->updatePosition($way, $position)) {
echo 'ok position ' . (int) $position . ' for config ' . (int) $pos[1] . '\r\n';
} else {
echo '{"hasError" : true, "errors" : "Can not update config ' . (int) $id . ' to position ' . (int) $position . ' "}';
}
} else {
echo '{"hasError" : true, "errors" : "This config (' . (int) $id . ') can not be loaded"}';
}
break;
}
}
}
}

View File

@@ -0,0 +1,408 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusGTMController extends ModuleAdminController
{
protected $isShopSelected = true;
public function __construct()
{
$this->bootstrap = true;
$this->tabClassName = 'AdminCookiesPlusGTM';
parent::__construct();
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
// CodeMirror
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.css');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/theme/monokai.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/addon/display/autorefresh.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/css/css.js');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/javascript/javascript.js');
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/cookiesplus-back.css');
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/cookiesplus-back.js');
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (((bool) Tools::isSubmit('submitCookiesPlusModule')) == true) {
if (!Tools::getValue('C_P_GTM_ENABLE') && !Tools::getValue('gtmFireConfiguration')) {
$this->errors[] = $this->l('You have to define the needed consents to fire the Google Tag Manager script.');
}
// Check if the keys inside the "gtmFinality" subarrays are unique across all elements in your array
// Array to store unique keys
$uniqueKeys = [];
// Flag to indicate if keys are unique
$keysAreUnique = true;
foreach (Tools::getValue('gtmConfiguration') as $item) {
if (isset($item["gtmFinality"]) && is_array($item["gtmFinality"])) {
foreach ($item["gtmFinality"] as $key => $value) {
// Check if the key is already in the unique keys array
if (in_array($key, $uniqueKeys)) {
$keysAreUnique = false;
// Optionally, you can break out of the loop or handle the duplication as needed
// break;
} else {
// Add the key to the unique keys array
$uniqueKeys[] = $key;
}
}
}
}
if (!$keysAreUnique) {
$this->errors[] = $this->l('You can not enable the same consent tag in more than one finality.');
}
if (!count($this->errors)) {
$fields = $this->getConfigFormValues();
foreach (array_keys($fields) as $key) {
if ($key === 'C_P_GTM_CONSENT') {
$value = json_encode(Tools::getValue('gtmConfiguration'));
Configuration::updateValue($key, $value);
} elseif ($key === 'C_P_GTM_FIRE_CONSENT') {
$value = json_encode(Tools::getValue('gtmFireConfiguration'));
Configuration::updateValue($key, $value);
} else {
// Workaround to avoid the modification of the HTML code
Configuration::updateValue('PS_USE_HTMLPURIFIER', false);
Configuration::updateValue($key, $fields[$key], true);
Configuration::updateValue('PS_USE_HTMLPURIFIER', true);
}
}
$this->confirmations[] = $this->l('Settings saved successfully');
}
}
$this->content .= $this->renderGlobalConfigForm();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$module = $this->module;
$default_iso_code = 'en';
$local_path = $module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $module->addons_id_product,
'readme' => $readme,
'this_path' => $module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
parent::initContent();
}
public function initToolbar()
{
parent::initToolbar();
unset($this->toolbar_btn['new']);
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
if (empty($this->display)) {
/*$this->page_header_toolbar_btn['desc-module-new'] = array(
'href' => 'index.php?controller='.$this->tabClassName.'&add'.$this->table.'&token='.Tools::getAdminTokenLite($this->tabClassName),
'desc' => $this->l('New'),
'icon' => 'process-icon-new'
);*/
$this->page_header_toolbar_btn['desc-module-translate'] = [
'href' => '#',
'desc' => $this->l('Translate'),
'modal_target' => '#moduleTradLangSelect',
'icon' => 'process-icon-flag',
];
$this->page_header_toolbar_btn['desc-module-hook'] = [
'href' => 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . Module::getModuleIdByName($this->module->name),
'desc' => $this->l('Manage hooks'),
'icon' => 'process-icon-anchor',
];
}
if (!$this->isShopSelected) {
unset($this->page_header_toolbar_btn['desc-module-new']);
}
$this->context->smarty->clearAssign('help_link', '');
}
public function initModal()
{
parent::initModal();
$languages = Language::getLanguages(false);
$translateLinks = [];
if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) {
$module = Module::getInstanceByName($this->module->name);
$isNewTranslateSystem = $module->isUsingNewTranslationSystem();
$link = Context::getContext()->link;
foreach ($languages as $lang) {
if ($isNewTranslateSystem) {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [
'lang' => $lang['iso_code'],
'type' => 'modules',
'selected' => $module->name,
'locale' => $lang['locale'],
]);
} else {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [
'type' => 'modules',
'module' => $module->name,
'lang' => $lang['iso_code'],
]);
}
}
}
$this->context->smarty->assign([
'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=',
'module_languages' => $languages,
'module_name' => $this->module->name,
'translateLinks' => $translateLinks,
]);
$modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl');
$this->modals[] = [
'modal_id' => 'moduleTradLangSelect',
'modal_class' => 'modal-sm',
'modal_title' => $this->l('Translate this module'),
'modal_content' => $modal_content,
];
}
protected function renderGlobalConfigForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->currentIndex = self::$currentIndex;
$helper->submit_action = 'submitCookiesPlusModule';
$helper->token = Tools::getAdminTokenLite($this->tabClassName);
$helper->tpl_vars = [
'fields_value' => array_merge($this->getConfigFormValues(), $this->getConfigFormTPLs()),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm($this->getConfigForm());
}
protected function getConfigForm()
{
$fields_form = [];
$fieldsFormIndex = 0;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Google Tag Manager (GTM) settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_GTM.tpl'),
],
[
'col' => 8,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_GTM_SCRIPT.tpl'),
],
[
'cols' => 110,
'rows' => 4,
'type' => 'textarea',
'label' => $this->l('HEAD code'),
'name' => 'C_P_GTM_HEAD',
'class' => 't codemirror codemirror-js',
],
[
'cols' => 110,
'rows' => 4,
'type' => 'textarea',
'label' => $this->l('BODY code'),
'name' => 'C_P_GTM_BODY',
'class' => 't codemirror codemirror-js',
],
[
'col' => 8,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_GTM_ENABLE.tpl'),
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Enable the integration with Google Consent Mode'),
'name' => 'C_P_GTM_ENABLE',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_GTM_ENABLE_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_GTM_ENABLE_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
[
'col' => 8,
'type' => 'html',
'label' => 'Cookie finalities needed to include the GTM script in the page',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_GTM_FIRE_CONSENT.tpl'),
],
[
'col' => 8,
'type' => 'html',
'label' => 'Cookie finality <> Google consent type',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_GTM_CONSENT.tpl'),
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
'name' => 'submitCookiesPlusModule',
],
];
return $fields_form;
}
protected function getConfigFormValues()
{
$fields = [];
$configFields = [
'C_P_GTM_ENABLE',
'C_P_GTM_HEAD',
'C_P_GTM_BODY',
'C_P_GTM_FIRE_CONSENT',
'C_P_GTM_CONSENT',
];
foreach ($configFields as $field) {
$fields[$field] = Tools::getValue($field, Configuration::get($field));
}
return $fields;
}
protected function getConfigFormTPLs()
{
$fields = [];
$this->context->smarty->assign([
'cookiesPlusFinalities' => CookiesPlusFinality::getCookiesPlusFinalities((int) $this->context->language->id, false, false),
'gtmFinalities' => [
'ad_storage',
'ad_user_data',
'ad_personalization',
'analytics_storage',
'functionality_storage',
'personalization_storage',
'security_storage',
],
'fieldNameGtm' => 'gtmConfiguration',
'valuesGtm' => json_decode(Configuration::get('C_P_GTM_CONSENT'), true),
'fieldNameGtmFire' => 'gtmFireConfiguration',
'valuesGtmFire' => json_decode(Configuration::get('C_P_GTM_FIRE_CONSENT'), true),
]);
return $fields;
}
}

View File

@@ -0,0 +1,311 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusUsersConsentController extends ModuleAdminController
{
protected $isShopSelected = true;
private $tabClassName;
public function __construct()
{
$this->bootstrap = true;
$this->table = 'cookiesplus_user_consent';
$this->className = 'CookiesPlusUserConsent';
$this->tabClassName = 'AdminCookiesPlusUsersConsent';
$this->list_no_link = true;
$this->addRowAction('delete');
parent::__construct();
$this->bulk_actions = [
'delete' => [
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'),
'icon' => 'icon-trash',
],
];
$this->context = Context::getContext();
$this->default_form_language = $this->context->language->id;
$this->fields_list = [
'id_cookiesplus_user_consent' => [
'title' => $this->l('ID'),
'align' => 'text-center center',
'class' => 'fixed-width-xs',
],
'hash' => [
'title' => $this->l('Hash'),
'type' => 'text',
],
'date' => [
'title' => $this->l('Date'),
'align' => 'text-left',
'type' => 'datetime',
],
'ip' => [
'title' => $this->l('IP'),
'align' => 'text-center center',
],
'date_add' => [
'title' => $this->l('Download PDF consent'),
'align' => 'text-center center',
'type' => 'text',
'callback' => 'getDownloadPdfLink',
],
];
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryPlugin(['typewatch', 'fancybox', 'autocomplete']);
$this->addJqueryUI(['ui.datepicker', 'ui.button', 'ui.sortable', 'ui.droppable']);
$this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/cookiesplus-back.css');
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
// parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP) && !Module::isEnabled($this->module->name)) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (Tools::isSubmit('submitCookiesPlusUsersConsent')) {
Configuration::updateValue('C_P_SAVE_CONSENT', Tools::getvalue('C_P_SAVE_CONSENT'));
$this->confirmations[] = $this->l('Settings saved successfully');
}
$this->content .= $this->renderGlobalConfigForm();
parent::initContent();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (!$this->display) {
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$module = $this->module;
$default_iso_code = 'en';
$local_path = $module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $module->addons_id_product,
'readme' => $readme,
'this_path' => $module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
}
$this->context->smarty->assign([
'content' => $this->content,
]);
}
public function renderList()
{
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
$this->getList($this->context->language->id);
foreach ($this->_list as $list) {
if (!CookiesPlusUserConsent::getCookiesPlusUserConsentDataByHash($list['hash'])) {
$cookiesPlusUserContent = new CookiesPlusUserConsent($list['id_cookiesplus_user_consent']);
$cookiesPlusUserContent->delete();
}
}
return parent::renderList();
}
protected function renderGlobalConfigForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->currentIndex = self::$currentIndex;
$helper->submit_action = 'submitCookiesPlusUsersConsent';
$helper->token = Tools::getAdminTokenLite($this->tabClassName);
$helper->tpl_vars = [
'fields_value' => array_merge($this->getConfigFormValues()),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm($this->getConfigForm());
}
protected function getConfigForm()
{
$fields_form = [];
$fieldsFormIndex = 0;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('Configuration'),
'icon' => 'icon-cogs',
],
'input' => [
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_USERS_CONSENT.tpl'),
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Save the consent from the customers'),
'name' => 'C_P_SAVE_CONSENT',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_SAVE_CONSENT_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_SAVE_CONSENT_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
'name' => 'submitCookiesPlusUsersConsent',
],
];
return $fields_form;
}
protected function getConfigFormValues()
{
$fields = [];
$configFields = [
'C_P_SAVE_CONSENT',
];
foreach ($configFields as $field) {
$fields[$field] = Tools::getValue($field, Configuration::get($field));
}
return $fields;
}
public function renderForm()
{
return parent::renderList();
}
private function _createTemplate($tpl_name)
{
if ($this->override_folder) {
if ($this->context->controller instanceof ModuleAdminController) {
$override_tpl_path = $this->context->controller->getTemplatePath() . $tpl_name;
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/' . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(1) . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(0) . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(0) . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
}
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/' . $tpl_name;
}
if (isset($override_tpl_path) && file_exists($override_tpl_path)) {
return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty);
} else {
return $this->context->smarty->createTemplate($tpl_name, $this->context->smarty);
}
}
public function getDownloadPdfLink($value, $object)
{
$this->context->smarty->assign([
'download_link' => $this->context->link->getModuleLink('cookiesplus', 'front', ['hash' => $object['hash'], 'getPdf' => true]),
]);
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
return $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/download_link.tpl');
}
return $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/download_link_15.tpl');
}
}

View File

@@ -0,0 +1,312 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminCookiesPlusYTController extends ModuleAdminController
{
protected $isShopSelected = true;
public function __construct()
{
$this->bootstrap = true;
$this->tabClassName = 'AdminCookiesPlusYT';
parent::__construct();
if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
$this->isShopSelected = false;
}
$this->shopLinkType = 'shop';
}
public function initContent()
{
if (!$this->isShopSelected && !$this->display) {
$this->errors[] = $this->l('You have to select a shop.');
parent::initContent();
return;
}
if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) {
return $this->errors[] = $this->l('Upgrade available');
}
if ($this->isShopSelected
&& (
(version_compare(_PS_VERSION_, '1.5.0.13', '<')
&& !Module::isInstalled($this->module->name))
|| (version_compare(_PS_VERSION_, '1.5.0.13', '>=')
&& !Module::isEnabled($this->module->name))
)
) {
$this->warnings[] = $this->l('Module is not enabled in this shop.');
}
if ($warnings = $this->module->getWarnings(false)) {
$this->warnings[] = $warnings;
}
if (((bool) Tools::isSubmit('submitCookiesPlusModule')) == true) {
if (Tools::getValue('C_P_YT_ENABLE') && !Tools::getValue('ytConfiguration')) {
$this->errors[] = $this->l('You have to define the needed consents to use YouTube cookies.');
}
if (!count($this->errors)) {
$fields = $this->getConfigFormValues();
foreach (array_keys($fields) as $key) {
Configuration::updateValue($key, $fields[$key], true);
}
if ($key === 'C_P_YT_CONSENT') {
$value = json_encode(Tools::getValue('ytConfiguration'));
Configuration::updateValue($key, $value);
} else {
Configuration::updateValue($key, $fields[$key], true);
}
$this->confirmations[] = $this->l('Settings saved successfully');
}
}
$this->content .= $this->renderGlobalConfigForm();
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl');
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$module = $this->module;
$default_iso_code = 'en';
$local_path = $module->getLocalPath();
$readme = null;
if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) {
$readme = 'readme_' . $this->context->language->iso_code . '.pdf';
} elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) {
$readme = 'readme_' . $default_iso_code . '.pdf';
}
$this->context->smarty->assign([
'support_id' => $module->addons_id_product,
'readme' => $readme,
'this_path' => $module->getPathUri(),
]);
if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl');
} elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) {
$this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl');
}
}
parent::initContent();
}
public function initToolbar()
{
parent::initToolbar();
unset($this->toolbar_btn['new']);
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
if (empty($this->display)) {
/*$this->page_header_toolbar_btn['desc-module-new'] = array(
'href' => 'index.php?controller='.$this->tabClassName.'&add'.$this->table.'&token='.Tools::getAdminTokenLite($this->tabClassName),
'desc' => $this->l('New'),
'icon' => 'process-icon-new'
);*/
$this->page_header_toolbar_btn['desc-module-translate'] = [
'href' => '#',
'desc' => $this->l('Translate'),
'modal_target' => '#moduleTradLangSelect',
'icon' => 'process-icon-flag',
];
$this->page_header_toolbar_btn['desc-module-hook'] = [
'href' => 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . Module::getModuleIdByName($this->module->name),
'desc' => $this->l('Manage hooks'),
'icon' => 'process-icon-anchor',
];
}
if (!$this->isShopSelected) {
unset($this->page_header_toolbar_btn['desc-module-new']);
}
$this->context->smarty->clearAssign('help_link', '');
}
public function initModal()
{
parent::initModal();
$languages = Language::getLanguages(false);
$translateLinks = [];
if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) {
$module = Module::getInstanceByName($this->module->name);
$isNewTranslateSystem = $module->isUsingNewTranslationSystem();
$link = Context::getContext()->link;
foreach ($languages as $lang) {
if ($isNewTranslateSystem) {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [
'lang' => $lang['iso_code'],
'type' => 'modules',
'selected' => $module->name,
'locale' => $lang['locale'],
]);
} else {
$translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [
'type' => 'modules',
'module' => $module->name,
'lang' => $lang['iso_code'],
]);
}
}
}
$this->context->smarty->assign([
'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=',
'module_languages' => $languages,
'module_name' => $this->module->name,
'translateLinks' => $translateLinks,
]);
$modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl');
$this->modals[] = [
'modal_id' => 'moduleTradLangSelect',
'modal_class' => 'modal-sm',
'modal_title' => $this->l('Translate this module'),
'modal_content' => $modal_content,
];
}
protected function renderGlobalConfigForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->currentIndex = self::$currentIndex;
$helper->submit_action = 'submitCookiesPlusModule';
$helper->token = Tools::getAdminTokenLite($this->tabClassName);
$helper->tpl_vars = [
'fields_value' => array_merge($this->getConfigFormValues(), $this->getConfigFormTPLs()),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm($this->getConfigForm());
}
protected function getConfigForm()
{
$fields_form = [];
$fieldsFormIndex = 0;
$fields_form[$fieldsFormIndex]['form'] = [
'legend' => [
'title' => $this->l('YouTube settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'col' => 12,
'type' => 'html',
'label' => '',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_YT.tpl'),
],
[
'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio',
'label' => $this->l('Replace youtube.com domain with youtube-nocookie.com'),
'name' => 'C_P_YT_ENABLE',
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'C_P_YT_ENABLE_on',
'value' => 1,
'label' => $this->l('Yes'), ],
[
'id' => 'C_P_YT_ENABLE_off',
'value' => 0,
'label' => $this->l('No'), ],
],
],
[
'col' => 8,
'type' => 'html',
'label' => 'Cookie finalities needed to use the youtube.com domain',
'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/C_P_YT_CONSENT.tpl'),
],
],
'submit' => [
'title' => $this->l('Save'),
'type' => 'submit',
'name' => 'submitCookiesPlusModule',
],
];
return $fields_form;
}
protected function getConfigFormValues()
{
$fields = [];
$configFields = [
'C_P_YT_ENABLE',
'C_P_YT_CONSENT',
];
foreach ($configFields as $field) {
$fields[$field] = Tools::getValue($field, Configuration::get($field));
}
return $fields;
}
protected function getConfigFormTPLs()
{
$fields = [];
$this->context->smarty->assign([
'cookiesPlusFinalities' => CookiesPlusFinality::getCookiesPlusFinalities((int) $this->context->language->id, false, false),
'fieldName' => 'ytConfiguration',
'values' => json_decode(Configuration::get('C_P_YT_CONSENT'), true),
]);
return $fields;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
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;

View File

@@ -0,0 +1,166 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class CookiesPlusFrontModuleFrontController extends ModuleFrontController
{
public function init()
{
parent::init();
if (Tools::isSubmit('saveCookiesPlusPreferences')) {
$data = $this->module->saveCookiesPlusPreferences();
}
if (Tools::getValue('ajax')) {
// $cookiesPlusPreferences = $this->module->getCookiesPlusCookiePreferences();
if (isset($data['consent_hash'])) {
$data['consent_link'] = $this->context->link->getModuleLink('cookiesplus', 'front') . '?hash=' . $data['consent_hash'] . '&getPdf';
}
echo json_encode($data);
exit;
}
if (Tools::isSubmit('getPdf')) {
$data = json_decode(CookiesPlusUserConsent::getCookiesPlusUserConsentDataByHash(Tools::getValue('hash')), true);
if (!$data) {
return Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
}
$pdf = new PDF($data, 'CookiesPlusModule', Context::getContext()->smarty);
// Remove embedded fonts to minimize space
$pdf->pdf_renderer->font_by_lang = array_merge($pdf->pdf_renderer->font_by_lang, [
'dz' => '',
'ar' => '',
'au' => '',
'at' => '',
'az' => '',
'bd' => '',
'by' => '',
'be' => '',
'bo' => '',
'ba' => '',
'br' => '',
'bg' => '',
'cm' => '',
'ca' => '',
'cl' => '',
'cn' => '',
'co' => '',
'cr' => '',
'hr' => '',
'cy' => '',
'cz' => '',
'dk' => '',
'do' => '',
'ec' => '',
'eg' => '',
'sv' => '',
'ee' => '',
'fj' => '',
'fi' => '',
'fr' => '',
'ge' => '',
'de' => '',
'gr' => '',
'gt' => '',
'gy' => '',
'hk' => '',
'hu' => '',
'in' => '',
'id' => '',
'ir' => '',
'ie' => '',
'il' => '',
'it' => '',
'ci' => '',
'jp' => '',
'je' => '',
'ke' => '',
'lv' => '',
'li' => '',
'lt' => '',
'lu' => '',
'mg' => '',
'my' => '',
'mt' => '',
'mx' => '',
'md' => '',
'ma' => '',
'nl' => '',
'nz' => '',
'ng' => '',
'no' => '',
'pk' => '',
'pa' => '',
'py' => '',
'pe' => '',
'ph' => '',
'pl' => '',
'pt' => '',
'ro' => '',
'ru' => '',
'sa' => '',
'sn' => '',
'rs' => '',
'sg' => '',
'sk' => '',
'si' => '',
'za' => '',
'kr' => '',
'es' => '',
'se' => '',
'ch' => '',
'tw' => '',
'tz' => '',
'th' => '',
'tn' => '',
'tr' => '',
'ua' => '',
'ae' => '',
'gb' => '',
'us' => '',
'uy' => '',
've' => '',
'vn' => '',
]);
$pdf->pdf_renderer->DEFAULT_FONT = '';
ob_clean();
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . Tools::getValue('hash') . '.pdf"');
echo $pdf->render('S');
return;
}
return Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
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;

View File

@@ -0,0 +1,32 @@
<?php
/**
* ISC License
*
* Copyright (c) 2024 idnovate.com
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* @author idnovate
* @copyright 2024 idnovate
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
*/
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;