Skip to content

Commit

Permalink
Merge pull request #129 from mailjet/DE-906-github-issue-please-relea…
Browse files Browse the repository at this point in the history
…se-the-latest-development-version

Release new version.
  • Loading branch information
oleksandr-mykhailenko authored Nov 28, 2022
2 parents 23298c9 + 1c1d512 commit 280e55a
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 40 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Happy emailing!


## Changelog
= 3.5.2 =
* Correct config file for PS version 1.7.*
* Code cleanup

= 3.5.1 =
* Fixed issue with security for ajax.php file
* Changed method Tool::jsonDecode to native php function to avoid problem in future version of prestashop
Expand Down
4 changes: 2 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<module>
<name>mailjet</name>
<displayName><![CDATA[Mailjet]]></displayName>
<version><![CDATA[3.5.1]]></version>
<version><![CDATA[3.5.2]]></version>
<description><![CDATA[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.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
</module>
</module>
126 changes: 88 additions & 38 deletions mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ class Mailjet extends Module
public $mj_mail_server = 'in-v3.mailjet.com';
public $mj_mail_port = 587;

/**
* @return mixed|string
*/
public static function setMjMailServer()
{
$mj = new Mailjet();
return $mj->mj_mail_server;
return (new Mailjet())->mj_mail_server;
}

/**
* @return int|mixed
*/
public static function setMjMailPort()
{
$mj = new Mailjet();
return $mj->mj_mail_port;
return (new Mailjet())->mj_mail_port;
}

/* Default account settings */
Expand Down Expand Up @@ -110,20 +114,19 @@ public static function setMjMailPort()
)
);

/*
* * Construct Method
/**
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/

public function __construct()
{
$this->account = json_decode(json_encode($this->account));
//$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.5.1';
$this->version = '3.5.2';
$this->module_key = 'c81a68225f14a65239de29ee6b78d87b';
$this->tab = 'advertising_marketing';

Expand All @@ -147,6 +150,11 @@ public function __construct()
$this->initContext();
}

/**
* @return void
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
private function initContext()
{
if (version_compare(_PS_VERSION_, '1.4', '>=') && class_exists('Context')) {
Expand All @@ -173,6 +181,10 @@ private function initContext()
* * Install / Uninstall Methods
*/

/**
* @return bool
* @throws PrestaShopException
*/
public function install()
{
$this->account = ($account = json_decode(Configuration::get('MAILJET'))) ? $account : $this->account;
Expand Down Expand Up @@ -268,6 +280,12 @@ public function install()
}

// Export customer gdpr data

/**
* @param $customer
* @return false|string
* @throws Mailjet_ApiException
*/
public function hookActionExportGDPRData($customer)
{
$email = $customer['email'];
Expand All @@ -291,11 +309,11 @@ public function hookActionExportGDPRData($customer)
if (is_object($contactData) && $contactData->Count > 0 && isset($contactData->Data[0]) && isset($contactData->Data[0]->Data)) {
$contactDataProperties = $contactData->Data[0]->Data;
foreach ($contactDataProperties as $propertyData) {
if ($propertyData->Name == 'firstname') {
if ($propertyData->Name === 'firstname') {
$firstname = $propertyData->Value;
continue;
}
if ($propertyData->Name == 'lastname') {
if ($propertyData->Name === 'lastname') {
$lastname = $propertyData->Value;
continue;
}
Expand All @@ -313,6 +331,11 @@ public function hookActionExportGDPRData($customer)
return json_encode($this->l('No data'));
}

/**
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function uninstall()
{
$fileTranslationCache = $this->_path . '/translations/translation_cache.txt';
Expand Down Expand Up @@ -349,6 +372,11 @@ public function uninstall()
}


/**
* @return void
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function hookHeader()
{
if (Tools::getIsset('tokp')) {
Expand Down Expand Up @@ -383,6 +411,10 @@ public function hookHeader()
}


/**
* @param $params
* @return string|void
*/
public function hookNewOrder($params)
{
if (empty($params['customer']->id)) {
Expand Down Expand Up @@ -410,6 +442,9 @@ public function hookNewOrder($params)
}
}

/**
* @return void
*/
public function hookActionControllerInitBefore()
{
if (Tools::isSubmit('subscribedmerged') && $this->isAccountSet()) {
Expand Down Expand Up @@ -475,7 +510,9 @@ public function hookBackOfficeHeader()

if (!in_array($controller, array('AdminModules', 'adminmodules', 'AdminCustomers'))) {
return '';
} elseif (Tools::getValue('configure') != $this->name) {
}

if (Tools::getValue('configure') != $this->name) {
return '';
}

Expand Down Expand Up @@ -510,7 +547,7 @@ public function hookBackOfficeHeader()
'MJ_ADMINMODULES_TOKEN' => Tools::getAdminTokenLite('AdminModules'),
'MJ_available_pages' => $smarty_page,
'MJ_tab_page' => $this->mj_pages->getPages(MailJetPages::REQUIRE_PAGE),
'MJ_adminmodules_link' => $this->getAdminModuleLink(array()),
'MJ_adminmodules_link' => $this->getAdminModuleLink([]),
'MJ_allemails_active' => Configuration::get('MJ_ALLEMAILS'),
'MJ_TOKEN' => $this->account->TOKEN,
'nobug' => $nobug,
Expand Down Expand Up @@ -1272,7 +1309,7 @@ public static function setSMTPconnectionParams()

$connected = false;

for ($i = 0; $i < count($configs); ++$i) {
for ($i = 0, $iMax = count($configs); $i < $iMax; ++$i) {
$errno = null;
$errstr = null;
$soc = @fSockOpen($configs [$i] [0] . $host, $configs [$i] [1], $errno, $errstr, 5);
Expand All @@ -1285,9 +1322,9 @@ public static function setSMTPconnectionParams()
}

if ($connected) {
if ('ssl://' == $configs [$i] [0]) {
if ('ssl://' === $configs [$i] [0]) {
Configuration::updateValue('PS_MAIL_SMTP_ENCRYPTION', 'ssl');
} elseif ('tls://' == $configs [$i] [0]) {
} elseif ('tls://' === $configs [$i] [0]) {
Configuration::updateValue('PS_MAIL_SMTP_ENCRYPTION', 'tls');
} else {
Configuration::updateValue('PS_MAIL_SMTP_ENCRYPTION', '');
Expand All @@ -1296,6 +1333,10 @@ public static function setSMTPconnectionParams()
}
}

/**
* @return string
* @throws Exception
*/
public function getContent()
{
if ($this->account->MASTER_LIST_SYNCHRONIZED == 0) {
Expand Down Expand Up @@ -1371,18 +1412,22 @@ public function getContent()
break;

case 'NEWSLETTER':
//TODO investigate what we need here
$this->displayNewsletter();
break;

case 'CAMPAIGN1':
//TODO investigate what we need here
$this->displayCampaign(1);
break;

case 'CAMPAIGN2':
//TODO investigate what we need here
$this->displayCampaign(2);
break;

case 'CAMPAIGN3':
//TODO investigate what we need here
$this->displayCampaign(3);
break;

Expand Down Expand Up @@ -1504,14 +1549,17 @@ public function getContent()
));
}

if ($this->page_name == 'CONTACTS') {
if ($this->page_name === 'CONTACTS') {
$this->context->smarty->assign([
'MJ_contact_list_form' => '<div class="center_page">' . $this->displayForm() . '</div>'
]);
}
return $output . $this->fetchTemplate('/views/templates/admin/', 'configuration');
}

/**
* @return string
*/
public function displayForm()
{
$synchronization = new HooksSynchronizationSegment(MailjetTemplate::getApi());
Expand Down Expand Up @@ -1567,7 +1615,6 @@ public function displayAccount()
$api = MailjetTemplate::getApi();

// Traitements
//$tracking = $api->getTracking();
$infos = $api->getUser();

$sendersFromApi = $api->getSenders(null, $infos);
Expand Down Expand Up @@ -1682,6 +1729,9 @@ public function displayROI()
));
}

/**
* @return void
*/
public function displayTriggers()
{
// smarty vars
Expand Down Expand Up @@ -1719,6 +1769,9 @@ public function displayTriggers()
));
}

/**
* @return bool
*/
private function updateTriggers()
{
$triggers = $this->triggers;
Expand All @@ -1735,6 +1788,9 @@ private function updateTriggers()
return Configuration::updateValue('MJ_TRIGGERS', Tools::jsonEncode($triggers));
}

/**
* @return void
*/
private function initTriggers()
{
$this->triggers =
Expand All @@ -1752,11 +1808,17 @@ private function initTriggers()
}
}

/**
* @return array|mixed
*/
public function getTriggers()
{
return $this->triggers;
}

/**
* @return void
*/
public function createTriggers()
{
$subject = array();
Expand Down Expand Up @@ -1871,31 +1933,21 @@ public function checkTokenValidity()
/**
*
* @author atanas
* @return mixed
* @return null|void
*/
protected function getPlan()
{
if (!$this->isAccountSet()) {
return null;
}
};
}

/**
* @return void
*/
public function checkPlanValidity()
{
/* $test = */
new Mailjet_ApiOverlay($this->account->API_KEY, $this->account->SECRET_KEY);
return;
/*
$plan = $test->getUserPlan();
if (Tools::getValue('MJ_request_page') != "PRICING" && ($plan->uname == "free" || $plan->uname == "bronze"))
{
// On redirige vers le pricing
//header("Location: index.php?tab=AdminModules&configure=mailjet&token=".
Tools::getValue('token')."&module_name=mailjet&MJ_request_page=PRICING");
//die();
}
*/
}

public function auth($apiKey, $secretKey)
Expand All @@ -1913,12 +1965,10 @@ public function auth($apiKey, $secretKey)

Configuration::updateValue('PS_MAIL_SERVER', $this->mj_mail_server);
Configuration::updateValue('PS_MAIL_SMTP_PORT', $this->mj_mail_port);
//Configuration::updateValue('PS_MAIL_SMTP_ENCRYPTION', 'tls');
Configuration::updateValue('PS_MAIL_USER', $apiKey);
Configuration::updateValue('PS_MAIL_PASSWD', $secretKey);
Configuration::updateValue('PS_MAIL_METHOD', 2);

//$account = json_decode(Configuration::get('MAILJET'), true);
Configuration::updateValue('PS_SHOP_EMAIL', $result->Email);
self::setSMTPconnectionParams();

Expand All @@ -1927,10 +1977,10 @@ public function auth($apiKey, $secretKey)
}

return true;
} else {
$this->errors_list[] = $this->l('Please verify that you have entered correct API and secret key.');
}

$this->errors_list[] = $this->l('Please verify that you have entered correct API and secret key.');

return false;
}

Expand Down Expand Up @@ -2014,7 +2064,7 @@ public function updateAccountSettings()
/**
* Get Admin Module link
*
* @param $params allow to add or override default key/value
* @param $params ~ allow to add or override default key/value
* @return string
*/
public function getAdminModuleLink($params, $tab = 'AdminModules', $token = null)
Expand Down
Loading

0 comments on commit 280e55a

Please sign in to comment.