Skip to content

Commit

Permalink
Merge pull request #199 from mailjet/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
JasenAngelov authored May 16, 2019
2 parents dd1062f + 85663ae commit b3db2d2
Show file tree
Hide file tree
Showing 25 changed files with 275 additions and 218 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
- Contributors: Mailjet
- Tags: email, marketing, signup, newsletter, widget, smtp, mailjet
- Requires at least: 3.9
- Tested up to: 5.1.1
- Stable tag: 5.0.12
- Tested up to: 5.2
- Stable tag: 5.1
- License: GPLv2 or later
- License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -172,6 +172,12 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \;

## Changelog

##### 5.1
* New integration with Contact Form 7 has been added
* Added support for custom translation files
* Multiple widgets can be added on the same page
* Various bug fixes and improvements

##### 5.0.12
* User can upload custom language translation files
* Added Contact Form 7 integration
Expand Down
Binary file modified languages/mailjet-for-wordpress-fr_FR.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion languages/mailjet-for-wordpress-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Mailjet plugin\n"
"POT-Creation-Date: 2019-04-15 16:12+0300\n"
"PO-Revision-Date: 2019-04-15 16:20+0300\n"
"PO-Revision-Date: 2019-05-16 14:24+0300\n"
"Last-Translator: \n"
"Language-Team: Ferhan Ismailov <[email protected]>\n"
"Language: fr_FR\n"
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Contributors: Mailjet
Tags: email, marketing, signup, newsletter, widget, smtp, mailjet
Requires at least: 3.9
Tested up to: 5.1.1
Stable tag: 5.0.12
Tested up to: 5.2
Stable tag: 5.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -181,6 +181,12 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \;

== Changelog ==

= 5.1 =
* New integration with Contact Form 7 has been added
* Added support for custom translation files
* Multiple widgets can be added on the same page
* Various bug fixes and improvements

= 5.0.12 =
* User can upload custom language translation files
* Added Contact Form 7 integration
Expand Down
19 changes: 19 additions & 0 deletions src/admin/partials/MailjetAdminDisplay.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace MailjetPlugin\Admin\Partials;

use MailjetPlugin\Includes\Mailjeti18n;

/**
* Provide a admin area view for the plugin
*
Expand Down Expand Up @@ -67,6 +69,23 @@ public static function getSettingsLeftMenu()
</ul>
<?php
}

public static function renderBottomLinks()
{
?>
<div class="bottom_links">
<div class="needHelpDiv">
<img src=" <?php echo plugin_dir_url(dirname(dirname(__FILE__))) . '/admin/images/need_help.png'; ?>" alt="<?php echo __('Need help?', 'mailjet-for-wordpress'); ?>" />
<?php echo __('Need help?', 'mailjet-for-wordpress' ); ?>
</div>
<?php echo '<a target="_blank" href="' . Mailjeti18n::getMailjetUserGuideLinkByLocale() . '">' . __('Read our user guide', 'mailjet-for-wordpress') . '</a>'; ?>
<?php echo '<a target="_blank" href="' . Mailjeti18n::getMailjetSupportLinkByLocale() . '">' . __('Contact our support team', 'mailjet-for-wordpress') . '</a>'; ?>
</div>
<div>
If you like Mailjet please support us with a <a href="https://wordpress.org/support/plugin/mailjet-for-wordpress/reviews/?rate=5#new-post" target="_blank"> 🟊🟊🟊🟊🟊</a> rating on WordPress.org. Thank you <img class="heart-icon" src="https://www.mailjet.com//wp-content/uploads/mailjet-coeur.png" alt="">
</div>
<?php
}
}


2 changes: 1 addition & 1 deletion src/includes/Mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct()
if (defined('MAILJET_VERSION')) {
$this->version = MAILJET_VERSION;
} else {
$this->version = '5.0.12';
$this->version = '5.1';
}
$this->plugin_name = 'mailjet';

Expand Down
58 changes: 49 additions & 9 deletions src/includes/MailjetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public static function getApiClient()

public static function getMailjetContactLists()
{
$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

$filters = [
'Limit' => '0',
Expand All @@ -82,7 +86,11 @@ public static function createMailjetContactList($listName)
return false;
}

$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

$body = [
'Name' => $listName
Expand All @@ -100,11 +108,13 @@ public static function isContactListActive($contactListId)
if (!$contactListId) {
return false;
}

try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

$filters = array(
'ID' => $contactListId
);
Expand All @@ -126,7 +136,11 @@ public static function isContactListActive($contactListId)
public static function getContactProperties()
{

$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}
$filters = array(
'limit' => 0,
'Sort' => 'Name ASC'
Expand Down Expand Up @@ -169,7 +183,11 @@ public static function createMailjetContactProperty($name, $type = "str")
return false;
}

$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

// Name: the name of the custom data field
// DataType: the type of data that is being stored (this can be either a str, int, float or bool)
Expand All @@ -194,7 +212,11 @@ public static function createMailjetContactProperty($name, $type = "str")

public static function getMailjetSenders()
{
$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

$filters = [
'Limit' => '0',
Expand All @@ -215,12 +237,14 @@ public static function getMailjetSenders()

public static function isValidAPICredentials()
{

try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}


$filters = [
'Limit' => '1'
];
Expand Down Expand Up @@ -248,7 +272,11 @@ public static function isValidAPICredentials()
*/
public static function syncMailjetContacts($contactListId, $contacts, $action = 'addforce')
{
$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

$body = [
'Action' => $action,
Expand All @@ -272,7 +300,11 @@ public static function syncMailjetContacts($contactListId, $contacts, $action =
*/
public static function syncMailjetContact($contactListId, $contact, $action = 'addforce')
{
$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}
$name = isset($contact['Properties']['firstname']) ? $contact['Properties']['firstname'] : '';
$body = [
'Name' => $name,
Expand Down Expand Up @@ -304,7 +336,11 @@ public static function checkContactSubscribedToList($email, $listId)
$exists = false;
$existsAndSubscribed = false;

$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}

$filters = [
'ContactEmail' => $email,
Expand All @@ -329,7 +365,11 @@ public static function checkContactSubscribedToList($email, $listId)

public static function getProfileName()
{
$mjApiClient = self::getApiClient();
try {
$mjApiClient = self::getApiClient();
} catch (\Exception $e) {
return false;
}
try {
$response = $mjApiClient->get(Resources::$Myprofile, []);
} catch (\GuzzleHttp\Exception\ConnectException $e) {
Expand Down
10 changes: 7 additions & 3 deletions src/includes/MailjetMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MailjetPlugin\Includes;

use MailjetIframe\MailjetIframe;
use MailjetPlugin\Admin\Partials\MailjetAdminDisplay;
use MailjetPlugin\Includes\SettingsPages\AllSetup;
use MailjetPlugin\Includes\SettingsPages\ConnectAccountSettings;
use MailjetPlugin\Includes\SettingsPages\Dashboard;
Expand Down Expand Up @@ -202,7 +203,8 @@ public function show_campaigns_page()
MailjetSettings::redirectJs(admin_url('/admin.php?page=mailjet_settings_page'));
}

echo '</div">';
echo '</div>';
MailjetAdminDisplay::renderBottomLinks();
// MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Iframe Campaigns page displayed ]');
}

Expand All @@ -229,7 +231,8 @@ public function show_stats_page()
update_option('api_credentials_ok', 0);
MailjetSettings::redirectJs(admin_url('/admin.php?page=mailjet_settings_page'));
}
echo '</div">';
echo '</div>';
MailjetAdminDisplay::renderBottomLinks();
// MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Iframe Stats page displayed ]');
}

Expand All @@ -256,7 +259,8 @@ public function show_contacts_page()
update_option('api_credentials_ok', 0);
MailjetSettings::redirectJs(admin_url('/admin.php?page=mailjet_settings_page'));
}
echo '</div">';
echo '</div>';
MailjetAdminDisplay::renderBottomLinks();
// MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Iframe Contacts page displayed ]');
}

Expand Down
2 changes: 1 addition & 1 deletion src/includes/MailjetSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private function activateCf7Url($contactListId)
$technicalIssue = Mailjeti18n::getTranslationsFromFile($locale, 'A technical issue has prevented your subscription. Please try again later.');

$contactForm7Settings = new ContactForm7Settings();
add_action('wpcf7_submit', array($contactForm7Settings, 'sendConfirmationEmail'));
add_action('wpcf7_submit', array($contactForm7Settings, 'sendConfirmationEmail'), 10, 2);
if (!empty($_GET['cf7list']) && $_GET['cf7list'] === $contactListId) {

if (empty($_GET['email'])) {
Expand Down
21 changes: 10 additions & 11 deletions src/includes/Mailjeti18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace MailjetPlugin\Includes;

use MailjetPlugin\Includes\MailjetLogger;

/**
* Define the internationalization functionality.
*
Expand All @@ -26,7 +24,7 @@ class Mailjeti18n
'Italian' => 'it_IT',
);

const DEFAULT_LANGUAGE_DIR = (WP_PLUGIN_DIR) .DIRECTORY_SEPARATOR.'mailjet-for-wordpress'.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR;
const DEFAULT_LANGUAGE_DIR = MAILJET_PLUGIN_DIR .'languages'.DIRECTORY_SEPARATOR;
const CUSTOM_LANGUAGE_DIR = (WP_CONTENT_DIR) .DIRECTORY_SEPARATOR. 'languages'. DIRECTORY_SEPARATOR .'plugins'.DIRECTORY_SEPARATOR;

/**
Expand Down Expand Up @@ -122,7 +120,7 @@ public static function getLocale()
}

// Use en_US if locale is not supported
if (!in_array($locale, array_values(self::getSupportedLanguages()))) {
if (!in_array($locale, array_values(self::getSupportedLocales()))) {
$locale = 'en_US';
}

Expand All @@ -131,12 +129,13 @@ public static function getLocale()

public static function getSupportedLocales()
{
$customLocales = self::getSupportedLanguages();
$customLocales = self::getAllSupportedLanguages();
if (empty($customLocales)){
return self::$supportedLocales;
}
$result = array_merge($customLocales, self::$supportedLocales);
$result = array_unique($result);
/*This is needed so that the language language order is preserved and the customer file is loaded with priority!*/
$result = array_merge(self::$supportedLocales, $customLocales);
$result = array_unique(array_reverse($result, true));

return array_reverse($result, true);
}
Expand All @@ -148,7 +147,7 @@ public static function getSupportedLocales()
public static function getCurrentUserLanguage()
{
$locale = self::getLocale();
$languages = array_flip(self::getSupportedLanguages());
$languages = array_flip(self::getSupportedLocales());
if (!isset($languages[$locale])) {
// return English if the language is not supported
$locale = 'en_US';
Expand Down Expand Up @@ -227,7 +226,7 @@ public static function getMailjetUserGuideLinkByLocale()
return $link;
}

private static function getSupportedLanguages()
private static function getAllSupportedLanguages()
{
$customLanguages = [];
$customLanguagesDir = (ABSPATH) . 'wp-content/languages/plugins';
Expand All @@ -237,7 +236,7 @@ private static function getSupportedLanguages()

$dir = new \DirectoryIterator($customLanguagesDir);
foreach ($dir as $fileInfo) {
if (strpos($fileInfo->getFilename(), 'mailjet-for-wordpress-') === false) {
if (strpos($fileInfo->getFilename(), 'mailjet-for-wordpress-') !== 0) {
continue;
}

Expand All @@ -247,7 +246,7 @@ private static function getSupportedLanguages()
}

$languageCode = str_replace('mailjet-for-wordpress-', '', $fileBasename);
$customLanguages['Custom-' . $languageCode] = $languageCode;
$customLanguages[$languageCode] = $languageCode;
}

return $customLanguages;
Expand Down
14 changes: 4 additions & 10 deletions src/includes/SettingsPages/AllSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MailjetPlugin\Includes\SettingsPages;

use MailjetPlugin\Includes\Mailjeti18n;
use MailjetPlugin\Admin\Partials\MailjetAdminDisplay;
use MailjetPlugin\Includes\MailjetLogger;

/**
Expand Down Expand Up @@ -64,15 +64,9 @@ public function mailjet_allsetup_page_html()
</div>

</div>

<div class="bottom_links">
<div class="needHelpDiv">
<img src=" <?php echo plugin_dir_url(dirname(dirname(__FILE__))) . '/admin/images/need_help.png'; ?>" alt="<?php echo __('Connect your Mailjet account', 'mailjet-for-wordpress'); ?>" />
<?php echo __('Need help?', 'mailjet-for-wordpress'); ?>
</div>
<?php echo '<a target="_blank" href="' . Mailjeti18n::getMailjetUserGuideLinkByLocale() . '">' . __('Read our user guide', 'mailjet-for-wordpress') . '</a>'; ?>
<?php echo '<a target="_blank" href="' . Mailjeti18n::getMailjetSupportLinkByLocale() . '">' . __('Contact our support team', 'mailjet-for-wordpress') . '</a>'; ?>
</div>
<?php
MailjetAdminDisplay::renderBottomLinks();
?>
</div>
<?php
}
Expand Down
Loading

0 comments on commit b3db2d2

Please sign in to comment.