private static function setHandle($file, $mode)
 {
     if ($file == self::$file && !self::$handle) {
         self::$handle = fopen($file, $mode);
     } else {
         if ($file != self::$file) {
             if (self::$handle) {
                 fclose(self::$handle);
             }
             self::$file = $file;
             self::$handle = fopen($file, $mode);
         }
     }
 }
    header('Pragma: no-cache');
    exit;
}
$post = trim(Tools::file_get_contents('php://input'));
/* mail("*****@*****.**", "callback ajax mailjet", $post.print_r($_POST, true).print_r($_GET, true)); */
/* die(); */
require_once _PS_ROOT_DIR_ . '/config/config.inc.php';
$method = Tools::getValue('method');
$back_office_method = Tools::getValue('back_office_method');
if (in_array($method, $back_office_method)) {
    define('_PS_ADMIN_DIR_', true);
}
require_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
$method = Tools::isSubmit('method') ? Tools::getValue('method') : '';
$token = Tools::isSubmit('token') ? Tools::getValue('token') : '';
$mj = new Mailjet();
$result = array();
MailJetLog::write(MailJetLog::$file, 'New request sent');
if ($mj->getToken() != Tools::getValue('token')) {
    $result['error'] = $mj->l('Bad token sent');
} else {
    if (!method_exists($mj, $method)) {
        $result['error'] = $mj->l('Method requested doesn\'t exist:') . ' ' . $method;
    } else {
        $result = $mj->{$method}();
    }
}
$message = isset($result['error']) ? $result['error'] : 'Success with method: ' . $method;
MailJetLog::write(MailJetLog::$file, $message);
header('Content-Type: application/json');
die(Tools::jsonEncode($result));
Example #3
0
 public function __construct()
 {
     //$this->getAdminFullUrl();
     // Default module variable
     $this->name = 'mailjet';
     $this->displayName = 'Mailjet';
     $this->description = $this->l('Create contact lists and client segment groups, drag-n-drop newsletters, define client re-engagement triggers, follow and analyze all email user interaction, minimize negative user engagement events (blocked, unsubs and spam) and optimise deliverability and revenue generation. Get started today with 6000 free emails per month.');
     $this->author = 'PrestaShop';
     $this->version = '3.2.5';
     $this->module_key = '59cce32ad9a4b86c46e41ac95f298076';
     $this->tab = 'advertising_marketing';
     // Parent constructor
     parent::__construct();
     // Backward compatibility
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         require _PS_MODULE_DIR_ . $this->name . '/backward_compatibility/backward.php';
     }
     if ($this->active) {
         $this->module_access['uri'] = __PS_BASE_URI__ . 'modules/' . $this->name . '/';
         $this->module_access['dir'] = _PS_MODULE_DIR_ . $this->name . '/';
         $this->initAccountSettings();
         MailJetLog::init();
         $this->initTriggers();
     }
     $this->initContext();
 }
    require_once realpath(dirname(__FILE__) . '/../../init.php');
}
if (Tools::getIsset('data')) {
    $data = (object) Tools::getValue('data');
} else {
    if (Tools::getIsset('mailjet')) {
        $mailjet = Tools::jsonDecode(Tools::getValue('mailjet'));
        $data = $mailjet->data;
    } else {
        $data = new stdClass();
    }
}
require_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
require_once _PS_MODULE_DIR_ . 'mailjet/classes/MailJetLog.php';
$mj = new Mailjet();
MailJetLog::init();
if (Tools::getIsset('response')) {
    $response = (object) Tools::getValue('response');
}
if ($data->next_step_url) {
    if (!empty($response) && ($response->message == 'last change of campaigns parameters' || $response->message == 'send details saved successfully')) {
        $mj_data = new Mailjet_Api($mj->getAccountSettingsKey('API_KEY'), $mj->getAccountSettingsKey('SECRET_KEY'));
        $campaignId = (int) $data->campaign_id;
        $html = $mj_data->data('newsletter', $campaignId, 'HTML', 'text/html', null, 'GET', 'LAST')->getResponse();
        /* On enregistre la campagne en BDD et on génère un token */
        $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'mj_campaign WHERE campaign_id = ' . $campaignId;
        $res_campaign = Db::getInstance()->GetRow($sql);
        if (empty($res_campaign)) {
            $token_presta = md5(uniqid('mj', true));
            $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'mj_campaign (campaign_id, token_presta, date_add)
			VALUES (' . $campaignId . ', \'' . $token_presta . '\', NOW())';
 /**
  * setContactMetaData()
  * First checks if certain contact meta data field is already created, 
  * and if not - creates it in order to be populated by the followed createContacts call
  * @return boolean
  */
 public function setContactMetaData($params = array())
 {
     try {
         /*
          * Add contact properties like First Name and Last Name
          */
         $resContactMetaData = $this->getContactMetaData();
         if (isset($resContactMetaData->Data) && count($resContactMetaData->Data) > 0) {
             foreach ($resContactMetaData->Data as $metaData) {
                 foreach ($params as $paramsMetaData) {
                     if (isset($metaData->Name) && ($metaData->Name = $paramsMetaData['Name'])) {
                         $flagName = $paramsMetaData['Name'] . "NameExists";
                         ${$flagName} = true;
                     }
                 }
             }
         }
         foreach ($params as $paramsMetaData) {
             $flagName = $paramsMetaData['Name'] . "NameExists";
             if (!${$flagName}) {
                 $resContactMetaData = $this->createContactMetaData($paramsMetaData);
             }
         }
         return true;
     } catch (Exception $ex) {
         MailJetLog::write(MailJetLog::$file, 'Exception : ' . $ex->getMessage());
         throw new Mailjet_ApiException($ex->getMessage());
     }
     return false;
 }