Skip to content

Commit

Permalink
Fixing widget. In progress
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-mykhailenko committed Aug 6, 2022
1 parent af93e8c commit 58cff50
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 113 deletions.
4 changes: 2 additions & 2 deletions languages/mailjet-for-wordpress-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -1575,13 +1575,13 @@ msgid "email_content_after_button"
msgstr ""

msgid "contactProperties0"
msgstr "46828"
msgstr "46827"

msgid "propertyDataType0"
msgstr "0"

msgid "EnglishLabel0"
msgstr ""
msgstr "First Name"

msgid "FrenchLabel0"
msgstr ""
Expand Down
20 changes: 10 additions & 10 deletions languages/mailjet-for-wordpress-en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,13 @@ msgid "list"
msgstr "21908"

msgid "language_mandatory_email"
msgstr ""
msgstr "test@gmail.com"

msgid "language_mandatory_button"
msgstr ""

msgid "confirmation_email_message_input"
msgstr ""
msgstr "test1"

msgid "subscription_confirmed_message_input"
msgstr ""
Expand All @@ -1137,34 +1137,34 @@ msgid "already_subscribed_message_input"
msgstr ""

msgid "invalid_data_format_message_input"
msgstr ""
msgstr "sss"

msgid "generic_technical_error_message_input"
msgstr ""
msgstr "ss"

msgid "email_subject"
msgstr ""
msgstr "my subject"

msgid "email_content_title"
msgstr ""
msgstr "please, please"

msgid "email_content_main_text"
msgstr ""
msgstr "main tet"

msgid "email_content_confirm_button"
msgstr ""
msgstr "hello moto"

msgid "email_content_after_button"
msgstr ""

msgid "contactProperties0"
msgstr "46828"
msgstr "46827"

msgid "propertyDataType0"
msgstr "0"

msgid "EnglishLabel0"
msgstr ""
msgstr "First Name"

msgid "FrenchLabel0"
msgstr ""
Expand Down
4 changes: 2 additions & 2 deletions languages/mailjet-for-wordpress-es_ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -1579,13 +1579,13 @@ msgid "email_content_after_button"
msgstr ""

msgid "contactProperties0"
msgstr "46828"
msgstr "46827"

msgid "propertyDataType0"
msgstr "0"

msgid "EnglishLabel0"
msgstr ""
msgstr "First Name"

msgid "FrenchLabel0"
msgstr ""
Expand Down
4 changes: 2 additions & 2 deletions languages/mailjet-for-wordpress-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -1593,13 +1593,13 @@ msgid "email_content_after_button"
msgstr ""

msgid "contactProperties0"
msgstr "46828"
msgstr "46827"

msgid "propertyDataType0"
msgstr "0"

msgid "EnglishLabel0"
msgstr ""
msgstr "First Name"

msgid "FrenchLabel0"
msgstr ""
Expand Down
4 changes: 2 additions & 2 deletions languages/mailjet-for-wordpress-it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -1567,13 +1567,13 @@ msgid "email_content_after_button"
msgstr ""

msgid "contactProperties0"
msgstr "46828"
msgstr "46827"

msgid "propertyDataType0"
msgstr "0"

msgid "EnglishLabel0"
msgstr ""
msgstr "First Name"

msgid "FrenchLabel0"
msgstr ""
Expand Down
31 changes: 18 additions & 13 deletions src/includes/SettingsPages/SubscriptionOptionsSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,22 @@ public function mailjet_subscribe_unsub_user_to_list($subscribe, $user_id)
$contactProperties[WooCommerceSettings::WOO_PROP_ACCOUNT_CREATION_DATE] = $user->user_registered;
}
// Add the user to a contact list
if (\false === self::syncSingleContactEmailToMailjetList(get_option('mailjet_sync_list'), $user->user_email, $action, $contactProperties)) {
return \false;
if (false === self::syncSingleContactEmailToMailjetList(get_option('mailjet_sync_list'), $user->user_email, $action, $contactProperties)) {
return false;
} else {
return \true;
return true;
}
}
}
public function mailjet_subscribe_confirmation_from_widget($subscription_email, $instance, $subscription_locale, $widgetId = \false)

/**
* @param $subscription_email
* @param $instance
* @param $subscription_locale
* @param $widgetId
* @return bool|mixed|void
*/
public function mailjet_subscribe_confirmation_from_widget($subscription_email, $instance, $subscription_locale, $widgetId = false)
{
$homeUrl = get_home_url();
$language = Mailjeti18n::getCurrentUserLanguage();
Expand All @@ -340,19 +348,18 @@ public function mailjet_subscribe_confirmation_from_widget($subscription_email,
$email_subject = !empty($instance[$locale]['email_subject']) ? apply_filters('widget_email_subject', $instance[$locale]['email_subject']) : Mailjeti18n::getTranslationsFromFile($locale, 'Subscription Confirmation');
$email_title = !empty($instance[$locale]['email_content_title']) ? apply_filters('widget_email_content_title', $instance[$locale]['email_content_title']) : Mailjeti18n::getTranslationsFromFile($locale, 'Please confirm your subscription');
$email_button_value = !empty($instance[$locale]['email_content_confirm_button']) ? apply_filters('widget_email_content_confirm_button', $instance[$locale]['email_content_confirm_button']) : Mailjeti18n::getTranslationsFromFile($locale, 'Yes, subscribe me to this list');
$wpUrl = \sprintf('<a href="%s" target="_blank">%s</a>', $homeUrl, $homeUrl);
$test = \sprintf(Mailjeti18n::getTranslationsFromFile($locale, 'To receive newsletters from %s please confirm your subscription by clicking the following button:'), $wpUrl);
// $test = sprintf(__('To receive newsletters from %s please confirm your subscription by clicking the following button:', 'mailjet-for-wordpress'), $wpUrl);
$wpUrl = sprintf('<a href="%s" target="_blank">%s</a>', $homeUrl, $homeUrl);
$test = sprintf(Mailjeti18n::getTranslationsFromFile($locale, 'To receive newsletters from %s please confirm your subscription by clicking the following button:'), $wpUrl);
$email_main_text = !empty($instance[$locale]['email_content_main_text']) ? apply_filters('widget_email_content_main_text', \sprintf($instance[$locale]['email_content_main_text'], get_option('blogname'))) : $test;
$email_content_after_button = !empty($instance[$locale]['email_content_after_button']) ? $instance[$locale]['email_content_after_button'] : Mailjeti18n::getTranslationsFromFile($locale, 'If you received this email by mistake or don\'t wish to subscribe anymore, simply ignore this message.');
$properties = isset($_POST['properties']) ? $_POST['properties'] : array();
$params = array('subscription_email' => $subscription_email, 'subscription_locale' => $subscription_locale, 'list_id' => isset($instance[$subscription_locale]['list']) ? $instance[$subscription_locale]['list'] : '', 'thanks_id' => isset($instance[$language]['thank_you']) ? $instance[$language]['thank_you'] : '', 'properties' => $properties);
if ($widgetId) {
$params['widget_id'] = $widgetId;
}
$params = \http_build_query($params);
$subscriptionTemplate = apply_filters('mailjet_confirmation_email_filename', \dirname(\dirname(\dirname(__FILE__))) . '/templates/confirm-subscription-email.php');
$message = \file_get_contents($subscriptionTemplate);
$params = http_build_query($params);
$subscriptionTemplate = apply_filters('mailjet_confirmation_email_filename', dirname(dirname(dirname(__FILE__))) . '/templates/confirm-subscription-email.php');
$message = file_get_contents($subscriptionTemplate);
$permalinkStructure = get_option('permalink_structure');
if (!$thankYouPageId) {
$qm = '?';
Expand All @@ -363,7 +370,7 @@ public function mailjet_subscribe_confirmation_from_widget($subscription_email,
'__EMAIL_TITLE__' => $email_title,
'__EMAIL_HEADER__' => $email_main_text,
'__WP_URL__' => $homeUrl,
'__CONFIRM_URL__' => $thankYouURI . $qm . $params . '&mj_sub_token=' . \sha1($params . MailjetSettings::getCryptoHash()),
'__CONFIRM_URL__' => $thankYouURI . $qm . $params . '&mj_sub_token=' . sha1($params . MailjetSettings::getCryptoHash()),
'__CLICK_HERE__' => $email_button_value,
'__FROM_NAME__' => $homeUrl,
//get_option('blogname'),
Expand All @@ -375,8 +382,6 @@ public function mailjet_subscribe_confirmation_from_widget($subscription_email,
}
add_filter('wp_mail_content_type', array($this, 'set_html_content_type'));
return wp_mail($subscription_email, $email_subject, $message, array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>'));
// echo '<p class="success">' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', 'mailjet-for-wordpress') . '</p>';
// die;
}
public function getContactListsMenu()
{
Expand Down
16 changes: 9 additions & 7 deletions src/widget/WP_Mailjet_Subscribe_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MailjetWp\MailjetPlugin\Widget;

use Exception;
use MailjetWp\MailjetPlugin\Includes\MailjetApi;
use MailjetWp\MailjetPlugin\Includes\Mailjeti18n;
use MailjetWp\MailjetPlugin\Includes\MailjetLogger;
Expand Down Expand Up @@ -35,17 +36,17 @@ public function __construct()
parent::__construct($this->get_widget_slug(), __('Mailjet Subscription Widget', 'mailjet-for-wordpress'), $widget_options);
// Register site styles and scripts
add_action('admin_enqueue_scripts', array($this, 'register_widget_scripts'));
if (is_active_widget(\false, \false, $this->id_base)) {
add_action('wp_enqueue_scripts', array($this, 'register_widget_front_styles'));
add_action('wp_enqueue_scripts', array($this, 'register_widget_front_scripts'));
}

// Refreshing the widget's cached output with each new post
add_action('save_post', array($this, 'flush_widget_cache'));
add_action('deleted_post', array($this, 'flush_widget_cache'));
add_action('switch_theme', array($this, 'flush_widget_cache'));
add_action('wp_ajax_mailjet_add_contact_property', array($this, 'wp_ajax_mailjet_add_contact_property'));
add_action('wp_enqueue_scripts', array($this, 'register_widget_front_styles'));
add_action('wp_enqueue_scripts', array($this, 'register_widget_front_scripts'));
add_action('wp_ajax_send_mailjet_subscription_form', array($this, 'sendSubscriptionEmail'));
add_action('wp_ajax_nopriv_send_mailjet_subscription_form', array($this, 'sendSubscriptionEmail'));
$this->propertyData = get_site_transient('propertyData');
// Subscribe user
$this->activateConfirmSubscriptionUrl();
}
Expand All @@ -55,9 +56,9 @@ public function __construct()
*
* @since 5.0.0
*
* @return Plugin slug variable.
* @return string
*/
public function get_widget_slug()
public function get_widget_slug(): string
{
return $this->widget_slug;
}
Expand All @@ -68,6 +69,7 @@ public function get_widget_slug()
*/
public function sendSubscriptionEmail()
{
file_put_contents(__DIR__ . '/test.txt', print_r($_POST, true));
$subscriptionOptionsSettings = $this->getSubscriptionOptionsSettings();
$instances = get_option(self::WIDGETS_OPTIONS_NAME);
$locale = Mailjeti18n::getLocale();
Expand Down Expand Up @@ -594,7 +596,7 @@ private function getMailjetContactProperties()
try {
$this->mailjetContactProperties = MailjetApi::getContactProperties();
} catch (Exception $ex) {
return \false;
return false;
}
}
return $this->mailjetContactProperties;
Expand Down
10 changes: 8 additions & 2 deletions src/widget/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
'use strict';
$(function () {

var mjInitTabs = false;

$(document).on('widget-updated', function (event, widget) {
showCheckedLanguages();
eventOpenAdvancedFormModal();
Expand Down Expand Up @@ -30,7 +32,6 @@
});

$(document).on('change', '.language-select-list', function (event) {
console.log('TEST 3');
var languageListId = event.target.value;
if (languageListId === '0') {
// No contact list is selected
Expand Down Expand Up @@ -189,7 +190,9 @@
if (dataAttr !== null && typeof dataAttr !== null) {
$('#modal-' + dataAttr).slideToggle('slow');
}
eventChangeAdvancedFormTab();
if (!mjInitTabs) {
eventChangeAdvancedFormTab();
}
});

// Fires when property value is changed
Expand Down Expand Up @@ -277,6 +280,9 @@

function eventChangeAdvancedFormTab() {
const tabsTriggersContainers = document.querySelectorAll('.mj-nav-tabs');
if (typeof tabsTriggersContainers !== 'undefined' && tabsTriggersContainers.length > 0) {
mjInitTabs = true;
}
tabsTriggersContainers.forEach(function (tabsTriggersContainer) {
const modalId = '#modal-' + tabsTriggersContainer.getAttribute('data-target');
const tabsTriggers = tabsTriggersContainer.querySelectorAll('.mj-tab');
Expand Down
Loading

0 comments on commit 58cff50

Please sign in to comment.