toutpratique/modules/blocknewsletter/ajax_ligthbox.php
Marion Muszynski 1014c59941 blocknewsletter
2015-09-23 12:45:32 +02:00

59 lines
1.7 KiB
PHP

<?php
require_once dirname(__FILE__).'/../../config/config.inc.php';
require_once dirname(__FILE__).'/../../init.php';
/*require_once dirname(__FILE__).'/../../override/modules/blocknewsletter/blocknewsletter.php';*/
require_once dirname(__FILE__).'/blocknewsletter.php';
require_once dirname(__FILE__).'/../../override/modules/blocknewsletter/blocknewsletter.php';
$NWAjax = new NWAjax();
$NWAjax->process();
class NWAjax{
public function __construct(){}
public function process(){
if(Tools::getValue('cookie')){
$lifetime = (int)Tools::getValue('lifetime');
$update = (int)Tools::getValue('update');
die(Tools::JsonEncode($response = $this->checkCookie($update, $lifetime)));
}
elseif((int)Tools::getValue('action') == 0){
$action = (int)Tools::getValue('action');
$email = Tools::getValue('email');
$page = Tools::getValue('page');
$post_id = false;
if(Tools::getValue('id_post'))
$post_id = (int)Tools::getValue('id_post');
$blocknewsletter = new BlockNewsletterOverride();
$response = $blocknewsletter->ajaxCall($email,$action,$page,$post_id);
die(Tools::JsonEncode($response));
}
}
private function checkCookie($update = false, $lifetime = 3600){
$cookie = $this->getCookie('ps_newsletter_ligthbox'.Context::getContext()->shop->id);
if ($update){
$cookie->event_date = time();
return false;
}
if (!isset($cookie->event_date) || time() > $cookie->event_date + $lifetime){
return true;
}
return false;
}
private function getCookie($cookie_name){
$cookie = new Cookie($cookie_name);
if (!$cookie->exists())
$cookie = $this->createCookie($cookie_name);
return $cookie;
}
private function createCookie($cookie_name){
return new Cookie($cookie_name);
}
}