* @copyright 2022 idnovate.com * @license See above */ class AdvancedPopupCreatorPopupModuleFrontController extends ModuleFrontController { public function init() { parent::init(); header('X-Robots-Tag: noindex, nofollow', true); } public function postProcess() { // For powerfulformgenerator module if (Tools::getValue('pfg_form_id')) { require_once(_PS_MODULE_DIR_.'powerfulformgenerator/classes/PFGRenderer.php'); $renderer = new PFGRenderer(1); Tools::redirect('index'); } if ($this->isTokenValid()) { if (Tools::getValue('getPopup')) { $loAPC = new AdvancedPopup(); //Sanitize parameter $availablePopups = explode(',', Tools::getValue('availablePopups')); foreach ($availablePopups as $availablePopupKey => $availablePopup) { if (!(int)$availablePopup) { unset($availablePopups[$availablePopupKey]); } } $availablePopups = implode(',', $availablePopups); $laPopups = $loAPC->getPopupToDisplay($availablePopups); $popups = array(); if ($laPopups) { foreach ($laPopups as $laPopup) { // Render and return data $popups[] = json_encode(array( 'selector' => (Tools::getValue('event') == 4 && $laPopup['display_on_click'] == 1) ? $laPopup['display_on_click_selector'] : '', 'id' => $laPopup['id_advancedpopup'] )); } } die(json_encode(array( 'hasError' => false, 'popups' => $popups, ))); } if (Tools::getValue('updateVisits')) { $loAPC = new AdvancedPopup(); $loAPC->updateVisits(); } if (Tools::getValue('markAsSeen')) { $loAPC = new AdvancedPopup(); $popupId = (int)Tools::getValue('popupId'); if (!$popupId || $popupId <= 0) { return false; } $popups = $loAPC->getApcCookiePopups(); $liNow = time(); $popups[$popupId]['last_displayed'] = $liNow; if (isset($popups[$popupId]['times_displayed'])) { $popups[$popupId]['times_displayed']++; } else { $popups[$popupId]['times_displayed'] = 1; } //$popups[$popupId]['visits'] = 0; $loAPC->setApcCookiePopups($popups); die(json_encode(array('hasError' => false, 'errors' => ''))); } if (Tools::getValue('dontDisplayAgain')) { $loAPC = new AdvancedPopup(); $popups = $loAPC->getApcCookiePopups(); $lbFound = false; if (!empty($popups)) { foreach ($popups as $laPopupId => &$popup) { if ((int)$laPopupId === (int)Tools::getValue('popupId')) { $lbFound = true; $popup['last_displayed'] = PHP_INT_MAX-1; } } unset($popup); // Save if found id if ($lbFound) { $loAPC->setApcCookiePopups($popups); } } } die(json_encode(array('hasError' => false, 'errors' => ''))); } die(json_encode(array('hasError' => true, 'errors' => 'Token not valid'))); } private function generatePFG($id_pfg) { $renderer = new PFGRenderer($id_pfg); if ($renderer->isAllowed(true)) { return $renderer->displayForm(); } return false; } }