Files
2024-11-20 09:09:44 +01:00

167 lines
5.2 KiB
PHP

<?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);
}
}