diff --git a/README.md b/README.md index f9a5a6b..8a4d9b2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Boost your ROI and increase your merchant revenue with the Mailjet v3 all-in-one ## Plug-in Key Info * Plug-in languages: English, French, German, Spanish -* PrestaShop Compatibility: PrestaShop v1.5.0 - v1.7.5 +* PrestaShop Compatibility: PrestaShop v1.5.0 - v8.0.x * PHP Compatibility: requires PHP 5.5 or newer * Mailjet Compatibility: Mailjet account * Support: https://app.mailjet.com/support/ticket @@ -65,6 +65,10 @@ Happy emailing! ## Changelog += 3.6.0 = +* Support version 8.0.x +* Code cleanup + = 3.5.2 = * Correct config file for PS version 1.7.* * Code cleanup diff --git a/ajax.php b/ajax.php index 53d74d2..fcfdfbd 100644 --- a/ajax.php +++ b/ajax.php @@ -24,9 +24,9 @@ * International Registered Trademark & Property of PrestaShop SA */ -require_once(realpath(dirname(__FILE__) . '/../../config/config.inc.php')); +require_once(dirname(__DIR__, 2) . '/config/config.inc.php'); if (_PS_VERSION_ < '1.5' || !defined('_PS_ADMIN_DIR_')) { - require_once(realpath(dirname(__FILE__) . '/../../init.php')); + require_once(dirname(__DIR__, 2) . '/init.php'); } $token_ok = Tools::getAdminToken( @@ -65,7 +65,7 @@ $token = Tools::isSubmit('token') ? Tools::getValue('token') : ''; $mj = new Mailjet(); -$result = array(); +$result = []; MailJetLog::write(MailJetLog::$file, 'New request sent'); @@ -81,4 +81,4 @@ MailJetLog::write(MailJetLog::$file, $message); header('Content-Type: application/json'); -die(Tools::jsonEncode($result)); +die(json_encode($result)); diff --git a/ajax/ajax.php b/ajax/ajax.php index 5cc6dd3..d0d57d3 100644 --- a/ajax/ajax.php +++ b/ajax/ajax.php @@ -69,7 +69,7 @@ 'values' => $bindOrderStates ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ case 4: /* payment method used */ $res = Db::getInstance()->executeS('SELECT DISTINCT(payment) FROM ' . _DB_PREFIX_ . 'orders'); @@ -84,7 +84,7 @@ 'values' => $values ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ case 8: /* ca */ case 9: /* avg ca */ @@ -98,7 +98,7 @@ 'values' => $values ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ case 19: /* newsletter subscription */ $values = array( @@ -111,7 +111,7 @@ 'values' => $values ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ case 15: /* gift package */ case 16: /* recycled packaging */ @@ -130,7 +130,7 @@ 'values' => $values ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ case 21: /* origin */ $sql = 'SELECT DISTINCT(conn.http_referer) AS url FROM ' . _DB_PREFIX_ . 'connections conn @@ -151,7 +151,7 @@ 'values' => $values ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ case 27: /* city */ $sql = 'SELECT DISTINCT(TRIM(a.city)) AS city FROM ' . _DB_PREFIX_ . 'address a @@ -170,12 +170,12 @@ 'values' => $values ); - die(Tools::jsonEncode($bind)); + die(json_encode($bind)); /* break; */ default: $bind = $obj->getBinder(Tools::getValue('ID')); if ($bind != '') { - $json = Tools::jsonEncode(explode(';', $bind)); + $json = json_encode(explode(';', $bind)); die('{"return" : ' . $json . '}'); } } diff --git a/callback_campaign.php b/callback_campaign.php index 35af5f0..3464395 100644 --- a/callback_campaign.php +++ b/callback_campaign.php @@ -24,9 +24,9 @@ * International Registered Trademark & Property of PrestaShop SA */ -require_once(realpath(dirname(__FILE__) . '/../../config/config.inc.php')); +require_once(dirname(__DIR__, 2) . '/config/config.inc.php'); if (_PS_VERSION_ < '1.5' || !defined('_PS_ADMIN_DIR_')) { - require_once(realpath(dirname(__FILE__) . '/../../init.php')); + require_once(dirname(__FILE__, 3) . '/init.php'); } @@ -101,18 +101,18 @@ $res = $mj_data->data('newsletter', $campaignId, 'HTML', 'text/html', $html, 'PUT', 'LAST')->getResponse(); } - $response = array( + $response = [ 'code' => 1, 'continue' => true, 'continue_address' => $data->next_step_url, - ); + ]; } else { - $response = array( + $response = [ 'code' => 0, 'continue' => false, 'exit_url' => 'SOME URL ADDRESS', - ); + ]; } header('Content-Type: application/json'); -echo Tools::jsonEncode($response); +echo json_encode($response); diff --git a/classes/Segmentation.php b/classes/Segmentation.php index 31ef766..80f4cd9 100644 --- a/classes/Segmentation.php +++ b/classes/Segmentation.php @@ -1208,7 +1208,7 @@ public function saveFilter($post, $auto_assign = false, $replace_customer = fals $post['replace_customer'] = $replace_customer_text; $post['auto_assign'] = $auto_assign_text; $post['group_name'] = $group_name; - return Tools::jsonEncode($post); + return json_encode($post); } public function deleteFilter($id) @@ -1242,15 +1242,20 @@ public function loadFilter($id_filter) $r['getIndicSelect'] = $this->getIndicSelect($r['id_sourcecondition'], $i, $r['id_fieldcondition']); $i++; } - return Tools::jsonEncode($res); + return json_encode($res); } return false; } + /** + * @param $id_filter + * @return string + * @throws PrestaShopDatabaseException + */ public function loadFilterInfo($id_filter) { $res = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'mj_filter` WHERE `id_filter`=' . (int) $id_filter); - $json = Tools::jsonEncode($res); + $json = json_encode($res); return '{"return" : ' . $json . '}'; } @@ -1394,7 +1399,7 @@ public function initLang($id_lang = 0) } file_put_contents( $this->_path . '/translations/translation_cache_' . (int) $id_lang . '.txt', - Tools::jsonEncode($this->trad) + json_encode($this->trad) ); } } diff --git a/classes/hooks/synchronization/SingleUser.php b/classes/hooks/synchronization/SingleUser.php index ecec62f..110b136 100644 --- a/classes/hooks/synchronization/SingleUser.php +++ b/classes/hooks/synchronization/SingleUser.php @@ -34,7 +34,7 @@ class HooksSynchronizationSingleUser extends HooksSynchronizationSynchronization public function subscribe($email, $list_id = null) { $api = $this->getApi(); - $update_list_id = $list_id ? $list_id : $this->getAlreadyCreatedMasterListId(); + $update_list_id = $list_id ?: $this->getAlreadyCreatedMasterListId(); $api->resetRequest(); if (!$update_list_id || empty($update_list_id)) { diff --git a/config.xml b/config.xml index 739cbe5..6b0b53c 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ mailjet - + diff --git a/libraries/MailJet.Data.Api.class.php b/libraries/MailJet.Data.Api.class.php index b55a38e..96c78d2 100644 --- a/libraries/MailJet.Data.Api.class.php +++ b/libraries/MailJet.Data.Api.class.php @@ -579,7 +579,7 @@ private function sendRequest($Method, $Uri, $MimeType, $RawData) break; case 'JSON': - $RawData = Tools::jsonEncode($RawData); + $RawData = json_encode($RawData); curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, $RawData); curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE); diff --git a/libraries/Mailjet.Api.class.php b/libraries/Mailjet.Api.class.php index 43b3939..2e3ec14 100644 --- a/libraries/Mailjet.Api.class.php +++ b/libraries/Mailjet.Api.class.php @@ -298,13 +298,12 @@ public function data( break; case 'DELETE': curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, 'DELETE'); - /* curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, http_build_query($params, '', '&')); */ $this->_request_post = $params; - curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post)); + curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post)); curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', - 'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post))) + 'Content-Length: ' . strlen(json_encode($this->_request_post))) ); break; case 'JSON': @@ -314,11 +313,11 @@ public function data( curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "POST"); $this->_request_post = $params; - curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post)); + curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post)); curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', - 'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post))) + 'Content-Length: ' . strlen(json_encode($this->_request_post))) ); break; } @@ -613,12 +612,12 @@ private function writeCache($object, $params, $request, $result) } else { $cache = $this->_cache; } - if ($request == 'GET' && $cache != 0) { + if ($request === 'GET' && $cache != 0) { sort($params); $file = $object . '.' . hash('md5', $this->_apiKey . http_build_query($params, '', '')) . '.' . $this->_output; $data = array('timestamp' => time(), 'result' => $result); - file_put_contents($this->_cache_path . $file, Tools::jsonEncode($data)); + file_put_contents($this->_cache_path . $file, json_encode($data)); } } @@ -756,7 +755,7 @@ private function sendRequest($method = FALSE, $params = array(), $request = "GET curl_setopt($this->_curl_handle, CURLOPT_POST, count($params)); if (isset($params['Action']) && isset($params['ListID'])) { - curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($params)); + curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($params)); curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); } else { curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, http_build_query($params, '', '&')); @@ -770,27 +769,27 @@ private function sendRequest($method = FALSE, $params = array(), $request = "GET break; case 'DELETE': curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, 'DELETE'); - /* curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, http_build_query($params, '', '&')); */ $this->_request_post = $params; - curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post)); + curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post)); curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', - 'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post))) + 'Content-Length: ' . strlen(json_encode($this->_request_post))) ); break; case 'JSON': - if ($is_json_put) + if ($is_json_put) { curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "PUT"); - else + } else { curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "POST"); + } $this->_request_post = $params; - curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post)); + curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post)); curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', - 'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post))) + 'Content-Length: ' . strlen(json_encode($this->_request_post))) ); break; } diff --git a/libraries/Mailjet.Overlay.class.php b/libraries/Mailjet.Overlay.class.php index 4ad768d..61a3c28 100644 --- a/libraries/Mailjet.Overlay.class.php +++ b/libraries/Mailjet.Overlay.class.php @@ -3511,9 +3511,9 @@ public function deleteContactsList($id) ); if ($response !== FALSE) { return true;//($response); - } else { - throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]); } + + throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]); } /** diff --git a/mailjet.php b/mailjet.php index 5b3726c..9944a3e 100644 --- a/mailjet.php +++ b/mailjet.php @@ -56,9 +56,9 @@ class Mailjet extends Module { private const DEFAULT_MAIL_OPTION = 1; - public $errors_list = array(); + public $errors_list = []; public $page_name; - public $module_access = array(); + public $module_access = []; public $mj_template = null; public $mj_pages = null; public $segmentation = null; @@ -83,7 +83,7 @@ public static function setMjMailPort() /* Default account settings */ - public $account = array( + public $account = [ 'TOKEN' => '', /* Used for ajax security */ /* 'TOKEN_{id_customer}' The one used to display iframe */ 'API_KEY' => '', @@ -96,23 +96,23 @@ public static function setMjMailPort() 'AUTHENTICATION' => 0, 'MASTER_LIST_SYNCHRONIZED' => 0, 'MASTER_LIST_ID' => 0, - ); + ]; /* Triggers parameters */ - public $triggers = array( + public $triggers = [ 'active' => 0, - 'trigger' => array( - 1 => array('active' => 0), - 2 => array('active' => 0), - 3 => array('active' => 0), - 4 => array('active' => 0), - 5 => array('active' => 0), - 6 => array('active' => 0), - 7 => array('active' => 0), - 8 => array('active' => 0), - 9 => array('active' => 0) - ) - ); + 'trigger' => [ + 1 => ['active' => 0], + 2 => ['active' => 0], + 3 => ['active' => 0], + 4 => ['active' => 0], + 5 => ['active' => 0], + 6 => ['active' => 0], + 7 => ['active' => 0], + 8 => ['active' => 0], + 9 => ['active' => 0] + ] + ]; /** * @throws PrestaShopDatabaseException @@ -126,7 +126,7 @@ public function __construct() $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.5.2'; + $this->version = '3.6.0'; $this->module_key = 'c81a68225f14a65239de29ee6b78d87b'; $this->tab = 'advertising_marketing'; @@ -163,15 +163,12 @@ private function initContext() $this->context = new StdClass(); $this->context->smarty = $GLOBALS['smarty']; $this->context->cookie = $GLOBALS['cookie']; - // ###########################** $this->context->language = new Language($this->context->cookie->id_lang); $this->context->currency = new Currency($this->context->cookie->id_lang); $this->context->link = new Link(); $this->context->shop = new Shop(); } - //var_dump($this->account); die; - if (!isset($this->context->shop->domain)) { $this->context->shop->domain = Configuration::get('PS_SHOP_DOMAIN'); } @@ -192,7 +189,7 @@ public function install() $this->updateAccountSettings(); // Install SQL - $sql = array(); + $sql = []; include(_PS_MODULE_DIR_ . 'mailjet/sql/install.php'); foreach ($sql as $s) { if (!Db::getInstance()->execute($s)) { @@ -203,7 +200,7 @@ public function install() // Install Tab if (version_compare(_PS_VERSION_, '1.7', '>=')) { $tabMain = new Tab(); - $tabMain->name = array(); + $tabMain->name = []; foreach (Language::getLanguages() as $lang) { $tabMain->name[$lang['id_lang']] = $this->l('Mailjet'); } @@ -218,7 +215,7 @@ public function install() $tab = new Tab(); $tab->class_name = 'AdminMailjet'; - $tab->name = array(); + $tab->name = []; foreach (Language::getLanguages() as $lang) { $tab->name[$lang['id_lang']] = $this->l('Configure'); } @@ -232,7 +229,7 @@ public function install() } else { $tab = new Tab(); $tab->class_name = 'AdminMailjet'; - $tab->name = array(); + $tab->name = []; foreach (Language::getLanguages() as $lang) { $tab->name[$lang['id_lang']] = $this->l('Mailjet'); } @@ -260,7 +257,7 @@ public function install() && $this->registerHook('actionObjectCustomerUpdateAfter') && $this->registerHook('adminCustomers') && $this->registerHook('authentication') - && $this->registerHook('BackOfficeHeader') + && $this->registerHook('displaybackOfficeHeader') && $this->registerHook('cancelProduct') && $this->registerHook('cart') && $this->registerHook('createAccount') @@ -303,7 +300,7 @@ public function hookActionExportGDPRData($customer) return json_encode($this->l('No data')); } - $data = array(); + $data = []; $firstname = ''; $lastname = ''; if (is_object($contactData) && $contactData->Count > 0 && isset($contactData->Data[0]) && isset($contactData->Data[0]->Data)) { @@ -318,13 +315,13 @@ public function hookActionExportGDPRData($customer) continue; } } - $data[] = array( + $data[] = [ 'Email' => $email, 'Firstname' => $firstname, 'Lastname' => $lastname, 'Last campaign sent' => $lastCampaignSent->format('Y-m-d H:i:s'), 'Creation date' => $creationDate->format('Y-m-d H:i:s') - ); + ]; return json_encode($data); } @@ -344,7 +341,7 @@ public function uninstall() } // Uninstall SQL - $sql = array(); + $sql = []; include(_PS_MODULE_DIR_ . 'mailjet/sql/uninstall.php'); foreach ($sql as $s) { if (!Db::getInstance()->execute($s)) { @@ -442,6 +439,15 @@ public function hookNewOrder($params) } } + /** + * @param $params + * @return void + */ + public function hookOrderConfirmation($params) + { + //TODO implement hook in new version + } + /** * @return void */ @@ -472,7 +478,7 @@ public function hookActionControllerInitBefore() * @return false|string * @throws HooksSynchronizationException */ - public function hookBackOfficeHeader() + public function hookDisplayBackOfficeHeader() { if (Tools::getIsset('sync_list')) { $sync = new HooksSynchronizationInitial(MailjetTemplate::getApi()); @@ -508,7 +514,7 @@ public function hookBackOfficeHeader() $controller = Tools::getValue('controller'); } - if (!in_array($controller, array('AdminModules', 'adminmodules', 'AdminCustomers'))) { + if (!in_array($controller, ['AdminModules', 'adminmodules', 'AdminCustomers'])) { return ''; } @@ -516,8 +522,8 @@ public function hookBackOfficeHeader() return ''; } - $smarty_page = array(); - $nobug = array(); + $smarty_page = []; + $nobug = []; foreach ($this->mj_pages->getPages() as $name => $value) { $smarty_page['MJ_' . $name] = $name; $nobug = $value; @@ -540,7 +546,7 @@ public function hookBackOfficeHeader() $currentSender = Configuration::get('PS_SHOP_EMAIL'); $this->context->smarty->assign( - array( + [ 'MJ_base_dir' => $this->module_access['uri'], 'MJ_local_path' => $this->module_access['dir'], 'MJ_REQUEST_PAGE_TYPE' => MailJetPages::REQUEST_PAGE_TYPE, @@ -553,23 +559,27 @@ public function hookBackOfficeHeader() 'nobug' => $nobug, 'mjSenders' => $this->getOnlyEmailSenders($mjSenders), 'currentSender' => $currentSender - ) + ] ); if ($this->isAccountSet()) { $this->context->smarty->assign( - array( + [ 'MJ_tab_page' => $this->mj_pages->getPages(MailJetPages::REQUIRE_PAGE) - ) + ] ); } return $this->fetchTemplate('/views/templates/admin/', 'bo-header'); } + /** + * @param $sendersFromApi + * @return array + */ private function getOnlyEmailSenders($sendersFromApi) { - $emailSenders = array(); + $emailSenders = []; foreach ($sendersFromApi as $sender) { if (strpos($sender->Email->Email, '*') === false) { $emailSenders[] = $sender; @@ -643,7 +653,7 @@ private function getAutoAssigmentSegments() return $this; } - $formatRows = array(); + $formatRows = []; foreach ($rows as $row) { $id_filter = (int) $row['id_filter']; $formatRows[$id_filter]['mode'] = 0; @@ -717,6 +727,15 @@ public function hookActionObjectCustomerUpdateAfter($params) } } + /** + * @param $params + * @return void + */ + public function hookAdminCustomers($params) + { + //TODO implement in the future + } + public function hookActionObjectCustomerDeleteBefore($params) { $customer = $params['object']; @@ -880,6 +899,11 @@ public function hookOrderSlip($params) return $this->hookUpdateOrderStatus($params); } + public function hookRegisterGDPRConsent($params) + { + //TODO Implement this later + } + public function hookOrderReturn($params) { return $this->hookUpdateOrderStatus($params); @@ -893,7 +917,7 @@ public function hookCancelProduct($params) public function newCheckAutoAssignment($id_customer) { $formatRows = $this->getAutoAssigmentSegments(); - $filterIds = array(); + $filterIds = []; foreach ($formatRows as $filterId => $formatRow) { $obj = new Segmentation(); $sql = $obj->getQuery($formatRow, true, false, ' c.id_customer = ' . (int)$id_customer); @@ -1055,18 +1079,19 @@ public function postProcess() ($triggers = json_decode(Configuration::get('MJ_TRIGGERS'), true)) ? $triggers : $this->triggers; - Configuration::updateValue('MJ_TRIGGERS', Tools::jsonEncode($triggers)); + Configuration::updateValue('MJ_TRIGGERS', json_encode($triggers)); if (Tools::getValue('MJ_allemails_active') == '1') { // Set PS SHOP EMAIL to be selected Mailjet Sender address $account = json_decode(Configuration::get('MAILJET'), true); $account['EMAIL'] = Tools::getValue('MJ_senders'); - Configuration::updateValue('MAILJET', Tools::jsonEncode($account)); + Configuration::updateValue('MAILJET', json_encode($account)); Configuration::updateValue('PS_SHOP_EMAIL', Tools::getValue('MJ_senders')); - $this->context->smarty->assign(array( - 'currentSender' => Tools::getValue('MJ_senders') - )); + $this->context->smarty->assign([ + 'currentSender' => Tools::getValue('MJ_senders'), + 'MJ_allemails_active' => Tools::getValue('MJ_allemails_active'), + ]); $this->activateAllEmailMailjet(); $triggers['active'] = 1; @@ -1079,10 +1104,10 @@ public function postProcess() } Configuration::updateValue('MJ_ALLEMAILS', Tools::getValue('MJ_allemails_active')); - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'MJ_allemails_active' => Configuration::get('MJ_ALLEMAILS'), 'AllMailsActiveMessage' => Tools::getValue('MJ_allemails_active') ? 1 : 2 - )); + ]); } // Campaign if (Tools::isSubmit('MJ_submitCampaign')) { @@ -1214,12 +1239,12 @@ public function postProcess() // Set PS SHOP EMAIL to be selected Mailjet Sender address $account = json_decode(Configuration::get('MAILJET'), true); $account['EMAIL'] = Tools::getValue('MJ_senders'); - Configuration::updateValue('MAILJET', Tools::jsonEncode($account)); + Configuration::updateValue('MAILJET', json_encode($account)); Configuration::updateValue('PS_SHOP_EMAIL', Tools::getValue('MJ_senders')); - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'currentSender' => Tools::getValue('MJ_senders') - )); + ]); } } @@ -1239,7 +1264,7 @@ public function postProcess() if (Tools::isSubmit('MJ_triggers_export_submit')) { $triggers = - ($triggers = Configuration::get('MJ_TRIGGERS')) ? $triggers : Tools::jsonEncode($this->triggers); + ($triggers = Configuration::get('MJ_TRIGGERS')) ? $triggers : json_encode($this->triggers); header("Content-Type: plain/text"); header("Content-Disposition: Attachment; filename=Mailjet_Trigger_Templates.txt"); @@ -1296,14 +1321,14 @@ public function activateAllEmailMailjet() public static function setSMTPconnectionParams() { - $configs = array( - array('ssl://', 465), - array('tls://', 587), - array('', 587), - array('', 588), - array('tls://', 25), - array('', 25) - ); + $configs = [ + ['ssl://', 465], + ['tls://', 587], + ['', 587], + ['', 588], + ['tls://', 25], + ['', 25] + ]; $host = Configuration::get('PS_MAIL_SERVER'); @@ -1347,7 +1372,7 @@ public function getContent() $this->page_name = $this->mj_pages->getCurrentPageName(); $this->postProcess(); - $this->context->smarty->assign(array('is_landing' => false)); + $this->context->smarty->assign(['is_landing' => false]); $output = ''; if (Tools::isSubmit('submit' . $this->name)) { $configValue = (string) Tools::getValue('contact_list'); @@ -1362,10 +1387,10 @@ public function getContent() switch ($this->page_name) { case 'SETUP_LANDING': $mt = new MailjetTemplate(); - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'is_landing' => true, 'lang' => $mt->getLang() - )); + ]); $this->mj_template->fetchTemplate('setup_landing_message'); $this->mj_template->fetchTemplate('setup_landing_bt_more'); $this->mj_template->fetchTemplate('setup_landing_bt_activate'); @@ -1381,7 +1406,7 @@ public function getContent() break; case 'CONNECT_STEP_0': - $this->context->smarty->assign(array('account' => $this->account)); + $this->context->smarty->assign(['account' => $this->account]); $this->mj_template->fetchTemplate('connect_step_0'); break; @@ -1465,20 +1490,20 @@ public function getContent() $part = $this->context->shop->domain.$this->context->shop->physical_uri; $url = 'http://' . $part . 'modules/mailjet/events.php?h=' . $this->getEventsHash(); - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'MJ_events_list' => $this->setUserLinkToEvents($mj_event->fetch()), 'MJ_title_list' => $titles, - 'MJ_paging' => array( + 'MJ_paging' => [ 'total_element' => $mj_event->getTotal(), 'current_page' => $page, 'next' => (($page * MailJetEvents::LIMIT_EVENT) < $mj_event->getTotal() ? true : false), 'prev' => ($page > 1) ? true : false, 'last' => ($mj_event->getTotalPages()) - ), + ], 'MJ_all_scheme_fields' => $mj_event->getScheme(MailJetEvents::ALL_EVENTS_KEYS), 'host' => $this->context->shop->domain, 'url' => $url, - )); + ]); break; @@ -1504,50 +1529,31 @@ public function getContent() $mjSenders = $api->getSenders(null, $infos); $currentSender = Configuration::get('PS_SHOP_EMAIL'); - if (version_compare(_PS_VERSION_, '8.0', '<')) { - $this->context->smarty->assign( - array( - 'MJ_templates' => $this->mj_template->getTemplates(), - 'MJ_iframes' => $this->mj_template->getIframesURL(), - 'MJ_errors' => $this->errors_list, - 'MJ_page_name' => $this->page_name, - 'MJ_template_name' => $this->mj_pages->getTemplateName($this->page_name), - 'MJ_template_tab_name' => $this->mj_pages->getTemplateTabName($this->page_name), - 'MJ_authentication' => $this->isAccountSet(), - 'MJ_TOKEN_USER' => isset($this->account->{'TOKEN_' . $this->context->employee->id}) ? $this->account->{'TOKEN_' . $this->context->employee->id} : null, - 'MJ_user_plan' => $this->getPlan(), - 'MJ_base_dir' => $this->module_access['uri'], - 'MJ_local_path' => $this->module_access['dir'], - 'MJ_REQUEST_PAGE_TYPE' => MailJetPages::REQUEST_PAGE_TYPE, - 'MJ_ADMINMODULES_TOKEN' => Tools::getAdminTokenLite('AdminModules'), - 'MJ_tab_page' => $this->mj_pages->getPages(MailJetPages::REQUIRE_PAGE), - 'MJ_adminmodules_link' => $this->getAdminModuleLink(array()), - 'MJ_allemails_active' => Configuration::get('MJ_ALLEMAILS'), - 'MJ_TOKEN' => $this->account->TOKEN, - 'mjSenders' => $this->getOnlyEmailSenders($mjSenders), - 'currentSender' => $currentSender - ) - ); - } else { - $this->context->smarty->assign(array( + $this->context->smarty->assign( + [ 'MJ_templates' => $this->mj_template->getTemplates(), 'MJ_iframes' => $this->mj_template->getIframesURL(), 'MJ_errors' => $this->errors_list, 'MJ_page_name' => $this->page_name, 'MJ_template_name' => $this->mj_pages->getTemplateName($this->page_name), - 'MJ_local_path' => $this->module_access['dir'], 'MJ_template_tab_name' => $this->mj_pages->getTemplateTabName($this->page_name), 'MJ_authentication' => $this->isAccountSet(), - 'MJ_TOKEN_USER' => isset($this->account->{'TOKEN_' . $this->context->employee->id}) ? - $this->account->{'TOKEN_' . $this->context->employee->id} : null, + 'MJ_TOKEN_USER' => $this->account->{'TOKEN_' . $this->context->employee->id} ?? null, 'MJ_user_plan' => $this->getPlan(), - 'MJ_adminmodules_link' => $this->getAdminModuleLink(array()), + 'MJ_base_dir' => $this->module_access['uri'], + 'MJ_local_path' => $this->module_access['dir'], + 'MJ_adminmodules_link' => $this->getAdminModuleLink([]), 'MJ_REQUEST_PAGE_TYPE' => MailJetPages::REQUEST_PAGE_TYPE, - 'MJ_sync_url' => $link, + 'MJ_ADMINMODULES_TOKEN' => Tools::getAdminTokenLite('AdminModules'), + 'MJ_tab_page' => $this->mj_pages->getPages(MailJetPages::REQUIRE_PAGE), + 'MJ_allemails_active' => Configuration::get('MJ_ALLEMAILS'), + 'MJ_TOKEN' => $this->account->TOKEN, 'mjSenders' => $this->getOnlyEmailSenders($mjSenders), 'currentSender' => $currentSender, - )); - } + 'MJ_sync_url' => $link, + ] + ); + if ($this->page_name === 'CONTACTS') { $this->context->smarty->assign([ @@ -1621,9 +1627,9 @@ public function displayAccount() $is_senders = 0; $is_domains = 0; - $domains = array(); - $domainsCurrent = array(); - $senders = array(); + $domains = []; + $domainsCurrent = []; + $senders = []; if ($sendersFromApi) { foreach ($sendersFromApi as $sender) { if (strpos($sender->Email->Email, '*') !== false) { @@ -1660,20 +1666,19 @@ public function displayAccount() $countries = Country::getCountries($this->context->language->id); // Assign - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'countries' => $countries, 'infos' => $infos, 'country' => $country, 'language' => $language, 'domains' => $domains, - /* 'tracking' => $tracking, */ 'sender' => $senders, 'is_senders' => $is_senders, 'is_domains' => $is_domains, 'root_file' => $root_file, 'available_domain' => $available_domain, 'domainsCurrent' => $domainsCurrent, - )); + ]); } public function displayROI() @@ -1687,7 +1692,7 @@ public function displayROI() foreach ($campaigns as $key => $c) { if (empty($c['stats_campaign_id']) || empty($c['delivered'])) { $api->resetRequest(); - $api->campaignstatistics(array('NewsLetter' => $c['campaign_id'])); + $api->campaignstatistics(['NewsLetter' => $c['campaign_id']]); $mjc = $api->getResponse(); if (isset($mjc->Data) && isset($mjc->Data[0])) { @@ -1719,14 +1724,14 @@ public function displayROI() } } - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'trad_title' => $this->l('Title'), 'trad_sentemails' => $this->l('Sent emails'), 'trad_roiamount' => $this->l('ROI Amount'), 'trad_roipercent' => $this->l('ROI Percent'), 'trad_roi_num_sales' => $this->l('Number of sales'), 'campaigns' => $campaigns - )); + ]); } /** @@ -1751,7 +1756,7 @@ public function displayTriggers() $currentSender = Configuration::get('PS_SHOP_EMAIL'); // Assign - $this->context->smarty->assign(array( + $this->context->smarty->assign([ 'tinymce_new' => version_compare(_PS_VERSION_, '1.4.0.0'), 'tinymce_iso' => file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en', 'tinymce_pathCSS' => _THEME_CSS_DIR_, @@ -1766,7 +1771,7 @@ public function displayTriggers() 'currentSender' => $currentSender, 'sel_lang' => $sel_lang, 'cron' => $cron - )); + ]); } /** @@ -1785,7 +1790,7 @@ private function updateTriggers() } } - return Configuration::updateValue('MJ_TRIGGERS', Tools::jsonEncode($triggers)); + return Configuration::updateValue('MJ_TRIGGERS', json_encode($triggers)); } /** @@ -1821,8 +1826,8 @@ public function getTriggers() */ public function createTriggers() { - $subject = array(); - $mail = array(); + $subject = []; + $mail = []; include(_PS_MODULE_DIR_ . 'mailjet/translations/triggers_messages.php'); $languages = Language::getLanguages(); @@ -1883,10 +1888,10 @@ private function setUserLinkToEvents($events) $customer = $customerClass->getByEmail($event['email']); if (isset($customer->id) && !empty($customer->id)) { - $params = array( + $params = [ 'id_customer' => $customer->id, 'viewcustomer' => '' - ); + ]; unset($customer); $event['email'] = '' . @@ -1900,6 +1905,7 @@ private function setUserLinkToEvents($events) /** * Check the token validity + * @throws Exception */ public function checkTokenValidity() { @@ -1908,16 +1914,16 @@ public function checkTokenValidity() ($this->account->{'TIMESTAMP_' . $this->context->employee->id} <= strtotime('-1 day')) ) { $this->account->{'IP_' . $this->context->employee->id} = $_SERVER['REMOTE_ADDR']; - $this->account->{'TIMESTAMP_' . $this->context->employee->id} = strtotime('now'); + $this->account->{'TIMESTAMP_' . $this->context->employee->id} = time(); $api = MailjetTemplate::getApi(false); - $params = array( + $params = [ 'AllowedAccess' => 'campaigns,contacts,stats,pricing,account,reports', 'method' => 'JSON', - 'APIKeyALT' => $api->getAPIKey(), + 'APIKeyALT' => $api ? $api->getAPIKey(): '', 'TokenType' => 'iframe', 'IsActive' => true, - 'SentData' => Tools::jsonEncode(array('plugin' => 'prestashop-3.0')), - ); + 'SentData' => json_encode(['plugin' => 'prestashop-3.0']), + ]; $api->apitoken($params); $response = $api->getResponse(); if (!empty($response->Count) && ($response->Count > 0)) { @@ -2019,7 +2025,7 @@ public function checkAuthentication() $SECRET_KEY = Tools::getValue('mj_secret_key'); if ($this->auth($API_KEY, $SECRET_KEY) === true) { - Tools::redirectAdmin($this->getAdminModuleLink(array(MailJetPages::REQUEST_PAGE_TYPE => 'HOME'))); + Tools::redirectAdmin($this->getAdminModuleLink([MailJetPages::REQUEST_PAGE_TYPE => 'HOME'])); } } @@ -2053,12 +2059,11 @@ public function getAccountSettingsKey($key) /** * Update the account settings - * - * @return mixed + * @return bool */ public function updateAccountSettings() { - return Configuration::updateValue('MAILJET', Tools::jsonEncode($this->account)); + return Configuration::updateValue('MAILJET', json_encode($this->account)); } /** @@ -2069,11 +2074,11 @@ public function updateAccountSettings() */ public function getAdminModuleLink($params, $tab = 'AdminModules', $token = null) { - $initArray = array( + $initArray = [ 'tab' => $tab, 'configure' => $this->name, 'module_name' => $this->name - ); + ]; if (!$token) { $initArray['token'] = Tools::getAdminTokenLite($tab); @@ -2092,15 +2097,15 @@ public function getAdminModuleLink($params, $tab = 'AdminModules', $token = null public function checkMerchantSetupState() { // 1.4 ajax need the set back the token - $params = array( + $params = [ MailJetPages::REQUEST_PAGE_TYPE => 'LOGIN', 'token' => Tools::getValue('admin_token') - ); + ]; - return array( - 'result' => 1, //(bool)$this->account['ACTIVATION'], + return [ + 'result' => 1, 'url' => $this->getAdminModuleLink($params) - ); + ]; } public function checkMjAuth() @@ -2234,8 +2239,8 @@ public static function sendMail1615($subject, $message, $to) // Create a message $message = \Swift_Message::newInstance('[' . $from_name . '] ' . $subject) - ->setFrom(array($from => $from_name)) - ->setTo(array($to)) + ->setFrom([$from => $from_name]) + ->setTo([$to]) ->setBody($message, 'text/html'); // $message->addPart($message, 'text/plain', 'utf-8'); diff --git a/upgrade/Upgrade-3.6.0.php b/upgrade/Upgrade-3.6.0.php new file mode 100644 index 0000000..31d3500 --- /dev/null +++ b/upgrade/Upgrade-3.6.0.php @@ -0,0 +1,36 @@ + + * @copyright 2007-2019 PrestaShop SA + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +if (!defined('_PS_VERSION_')) { + exit; +} + +require_once(_PS_MODULE_DIR_ . 'mailjet/mailjet.php'); + +function upgrade_module_3_6_0($object) +{ + return true; +}