From: vincent@cubedesigners.com Date: Tue, 5 Jan 2016 11:21:02 +0000 (+0000) Subject: #couzy Quick hack to fix the confirmation issue X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f182300da700cd2452937d2cfedc04d0dd4957ee;p=couzy.git #couzy Quick hack to fix the confirmation issue --- diff --git a/cesaretleonie.fr/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php b/cesaretleonie.fr/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php index 883cddcf..0c9839a9 100755 --- a/cesaretleonie.fr/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php +++ b/cesaretleonie.fr/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php @@ -1,4 +1,5 @@ 5i!? {xI'; - public function __construct() - { + public function __construct() { // Set Plugin URL $chunks = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); $this->pluginUrl = WP_PLUGIN_URL . '/' . end($chunks); @@ -46,7 +45,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget 'description' => 'Allows your visitors to subscribe to one of your lists' ); - parent::__construct(FALSE, __('Mailjet Subscription widget'), $widget_ops); + parent::__construct(false, __('Mailjet Subscription widget'), $widget_ops); add_action('wp_ajax_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); add_action('wp_ajax_nopriv_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); add_action('wp_ajax_mailjet_subscribe_ajax_add_meta_property', array($this, 'wp_ajax_mailjet_subscribe_ajax_add_meta_property')); @@ -63,12 +62,11 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget foreach ($this->langs as $lang => $langProps) { $fileHandler = new FileHandler(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $langProps['locale'] . '.po'); $this->{'poParser' . $lang} = new PoParser($fileHandler); - $this->{'entries' . $lang} = $this->{'poParser' . $lang}->parse(); + $this->{'entries' . $lang} = $this->{'poParser' . $lang}->parse(); } } - function wp_ajax_mailjet_subscribe_ajax_add_meta_property() - { + function wp_ajax_mailjet_subscribe_ajax_add_meta_property() { if (!empty($_REQUEST['name']) && !empty($_REQUEST['type'])) { echo json_encode($this->api->createMetaContactProperty(array( 'name' => $_REQUEST['name'], @@ -84,9 +82,8 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget * @param void * @return (array) $this->lists */ - function getLists() - { - if ($this->lists === FALSE) { + function getLists() { + if ($this->lists === false) { $this->lists = $this->api->getContactLists(array('limit' => 0)); if (isset($this->lists->Status) && $this->lists->Status == 'ERROR') $this->lists = array(); @@ -94,8 +91,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget return $this->lists; } - function getContactMetaProperties($showMsg = true) - { + function getContactMetaProperties($showMsg = true) { $response = $this->api->getContactMetaProperties(array( 'method' => 'GET', 'limit' => 0 @@ -112,23 +108,21 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget return $response; } - function preg_array_key_exists($pattern, $array) - { + function preg_array_key_exists($pattern, $array) { return (int)preg_grep($pattern, array_keys($array)); } - function form($instance) - { + function form($instance) { global $WPMailjet; // if there are translation entries in the POST, update them - if($this->preg_array_key_exists('/msgstr/', $_POST)){ + if ($this->preg_array_key_exists('/msgstr/', $_POST)) { require_once(dirname(__FILE__) . '/libs/php.mo-master/php-mo.php'); foreach ($this->langs as $lang => $locale) { - foreach($_POST as $key => $value) { - if(substr($key, 0, 7) === 'msgstr-'){ - foreach($this->{'entries' . $lang} as $entryKey => $entryValue){ - if($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)){ + foreach ($_POST as $key => $value) { + if (substr($key, 0, 7) === 'msgstr-') { + foreach ($this->{'entries' . $lang} as $entryKey => $entryValue) { + if ($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)) { $this->{'entries' . $lang}[$entryKey]['msgstr'][0] = stripcslashes($_POST[$key]); $this->{'poParser' . $lang}->setEntry($entryKey, $this->{'entries' . $lang}[$entryKey]); } @@ -141,7 +135,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po'); } if (in_array(get_locale(), array('en_US', 'en_EN', ''))) { - foreach(array('-en_US', '-en_EN', '') as $lang) { + foreach (array('-en_US', '-en_EN', '') as $lang) { $this->poParseren->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); } @@ -150,241 +144,251 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget $fields = array('new_meta_name', 'new_meta_data_type'); $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', - 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); + 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); foreach ($fields as $prop) { ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; } - foreach($langFields as $prop){ - foreach($this->langs as $lang => $langProps){ + foreach ($langFields as $prop) { + foreach ($this->langs as $lang => $langProps) { ${$prop . $lang} = empty($instance[$prop . $lang]) ? '' : $instance[$prop . $lang]; } } ?>
-
-

Step 1 - Choose up to 3 contact properties

-
- getContactMetaProperties(); - if ($this->_userVersion === 3): ?> - Data)): ?> -
- - - -
-
Available contact properties
- -
Data)): ?> style="display:none;" > -
-
    - Data as $prop): - $lang = 'en'; - //foreach($this->langs as $lang => $langProps): ?> +
    +

    Step 1 - Choose up to 3 contact properties

    + +
    + getContactMetaProperties(); + if ($this->_userVersion === 3): ?> + Data)): ?> +
    + + + +
    +
    Available contact properties
    + +
    Data)): ?> style="display:none;" > +
    +
      + Data as $prop): + $lang = 'en'; + //foreach($this->langs as $lang => $langProps): + ?> Name, array(${'metaPropertyName1' . $lang}, ${'metaPropertyName2' . $lang}, ${'metaPropertyName3' . $lang}))): ?> -
    •     Name; ?>
    • - - - -
    -
    -
    -
    Selected properties
    -
    Arrange and sort the properties you selected to determine the way they will be shown in the widget.
    -
      -
    • Email address (mandatory)
    • - - -
    •     
    • +
    • +
      +     Name; ?>
    • + + + +
    +
    +
    +
    Selected properties
    +
    Arrange and sort the properties you selected to determine the way they will be shown in the widget.
    +
      +
    • Email address (mandatory)
    • + + +
    • +
      +     
    • - -
    -
    -
    - -
    -
    Add New Property
    -
    Click on the button below to dynamically add a new contact property to your contact list and widget.
    -
      -
    • Add a new property
    • -
    - -
    Property created. Please drag your new contact property to the Selected Properties section above.
    - -
    -
    -
    -
    - -
    -
    -
    - + +
+
-

- - -

-
-
- -

- -

-
-

Step 2 - Define your widget labels

-
-
-
    - langs as $lang => $langProps): ?> -
  • - -
  • - -
-
- langs as $lang => $langProps): ?> -
-
- /> - +
+
Add New Property
+
Click on the button below to dynamically add a new contact property to your contact list and widget.
+
    +
  • Add a new property
  • +
+ +
Property created. Please drag your new contact property to the Selected Properties section above.
+ +
+
+
+
+ +
+
+
+
- -
Please enter specific labels for your subscription widget and they - will be displayed on the front end of your website.
- _userVersion === 3): ?> -
- -
- - - -
- -
- -

- -

-

- -

- + +

- -
+
+

-

-
-

Step 3 - Customize your widget notifications

-
-
-
    - langs as $lang => $langProps): ?> -
  • - -
  • - -
-
- langs as $lang => $langProps): ?> -
-
-
Widget notifications for this language are deactivated in previous step
- Customize your widget notifications
-
- {'entries' . $lang} as $msgid => $msg): - $id = $this->entryStrToId($msgid); - $i++; - if($i === 1): - ?> -

Errors/Website notifications

- -

Subscription confirmation mail

+

Step 2 - Define your widget labels

+ +
+
+
    + langs as $lang => $langProps): ?> +
  • + +
  • + +
+
+ langs as $lang => $langProps): ?> +
+
+ /> + +
+ +
Please enter specific labels for your subscription widget and they + will be displayed on the front end of your website. +
+ _userVersion === 3): ?> +
+ +
+ + + +
+ +
-
-
+

+ +

+ +

+ +

+ +

+ +

+
+ +
+

+ + +

+
+
+ +

Step 3 - Customize your widget notifications

+ +
+
+
    + langs as $lang => $langProps): ?> +
  • + +
  • + +
+
+ langs as $lang => $langProps): ?> +
+
+
Widget notifications for this language are deactivated in previous step
+ Customize your widget notifications
+
+ {'entries' . $lang} as $msgid => $msg): + $id = $this->entryStrToId($msgid); + $i++; + if ($i === 1): + ?> +

Errors/Website notifications

+ +

Subscription confirmation mail

+ +
+
+ rows="5" cols="30"> +
+
- -
+
+
- +

-

-
0): ?> -
-
+ addMjJsGlobalVar(); } - function entryStrToId($str) - { + function entryStrToId($str) { return substr(str_replace(array(' ', '%', ':', '/', '<', '>', '"', '\\', '@', '.', '!', '?'), array('-'), $str), 0, 20); } - function update($new_instance, $old_instance) - { + function update($new_instance, $old_instance) { return $new_instance; } @@ -393,8 +397,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget * @param void * @return void */ - public function mailjet_subscribe_from_widget() - { + public function mailjet_subscribe_from_widget() { $error = empty($_POST['email']) ? 'Email field is empty' : false; $error = empty($_POST['list_id']) ? 'Missing list id' : $error; if (false !== $error) { @@ -415,12 +418,16 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget } $params = http_build_query($_POST); + + $_GET=$_POST; + $_GET['token'] = sha1($params . self::WIDGET_HASH); + $message = file_get_contents(dirname(__FILE__) . '/templates/confirm-subscription-email.php'); $emailParams = array( '__EMAIL_TITLE__' => __('Confirm your mailing list subscription', 'wp-mailjet-subscription-widget'), '__EMAIL_HEADER__' => __('Please Confirm Your Subscription To', 'wp-mailjet-subscription-widget'), '__WP_URL__' => sprintf('%s', get_site_url(), get_site_url()), - '__CONFIRM_URL__' => get_site_url() . '?' . $params . '&token=' . sha1($params . self::WIDGET_HASH), + '__CONFIRM_URL__' => get_site_url() . '?' . $params . '&token=' . $_GET['token'], '__CLICK_HERE__' => __('Click here to confirm', 'wp-mailjet-subscription-widget'), '__FROM_NAME__' => get_option('blogname'), '__IGNORE__' => __('Didn\'t ask to subscribe to this list? Or maybe you\'ve changed your mind? Then simply ignore this email and you won\'t be subscribed', 'wp-mailjet-subscription-widget'), @@ -430,18 +437,20 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget $message = str_replace($key, $value, $message); } add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); - wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message, - array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>')); - echo '

' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', - 'wp-mailjet-subscription-widget') . '

'; + /*wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message, + array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>'));*/ + /*echo '

' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', + 'wp-mailjet-subscription-widget') . '

';*/ + + $this->subscribeUser(); + die; } /** * Subscribe the user from the widget */ - function subscribeUser() - { + function subscribeUser() { // validate token $token = $_GET['token']; unset($_GET['token']); @@ -496,8 +505,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget } } - function widget($args, $instance) - { + function widget($args, $instance) { $this->getContactMetaProperties(false); // enqueue the scripts required for the widget (only if the widget is active) // scripts will appear in the footer which is good for speed @@ -514,19 +522,19 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget echo $before_widget; $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', - 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); - if(isset($fields) && is_array($fields)) - foreach($fields as $prop){ - ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; - } + 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); + if (isset($fields) && is_array($fields)) + foreach ($fields as $prop) { + ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; + } - foreach($this->langs as $lang => $langProps) { + foreach ($this->langs as $lang => $langProps) { if (get_locale() !== $langProps['locale']) { continue; } $currentLang = $lang; - foreach($langFields as $prop){ + foreach ($langFields as $prop) { if (!empty($instance[$prop . $currentLang])) { ${$prop . $currentLang} = $instance[$prop . $currentLang]; } @@ -541,7 +549,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget // If contact list is not selected then we just don't display the widget! if (!is_numeric($list_id)) { - return FALSE; + return false; } if (!empty($title)) @@ -575,9 +583,8 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget echo $after_widget; } - function validate_email($email) - { + function validate_email($email) { return (preg_match("/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/", $email) || - !preg_match("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/", $email)) ? FALSE : TRUE; + !preg_match("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/", $email)) ? false : true; } } diff --git a/mdryvescouzy.com/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php b/mdryvescouzy.com/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php index 883cddcf..102d5828 100644 --- a/mdryvescouzy.com/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php +++ b/mdryvescouzy.com/wp-content/plugins/mailjet-for-wordpress/mailjet-widget.php @@ -1,4 +1,5 @@ array('locale' => 'en_US', 'label' => 'English'), - 'fr' => array('locale' => 'fr_FR', 'label' => 'French'), - 'de' => array('locale' => 'de_DE', 'label' => 'German'), - 'es' => array('locale' => 'es_ES', 'label' => 'Spanish'), - ); - - const MAX_META_PROPERTIES = 3; - const WIDGET_HASH = '[\^=l|>5i!? {xI'; - - public function __construct() - { - // Set Plugin URL - $chunks = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); - $this->pluginUrl = WP_PLUGIN_URL . '/' . end($chunks); - - $this->locale = get_locale() === 'en_US' ? 'en_EN' : get_locale(); - - //No dependency injection possible, so we have to use this: - $this->api = new WP_Mailjet_Api(get_option('mailjet_username'), get_option('mailjet_password')); - - $widget_ops = array( - 'classname' => 'WP_Mailjet_Subscribe_Widget', - 'description' => 'Allows your visitors to subscribe to one of your lists' - ); - - parent::__construct(FALSE, __('Mailjet Subscription widget'), $widget_ops); - add_action('wp_ajax_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); - add_action('wp_ajax_nopriv_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); - add_action('wp_ajax_mailjet_subscribe_ajax_add_meta_property', array($this, 'wp_ajax_mailjet_subscribe_ajax_add_meta_property')); - - // if user clicks on the email confirm subscription link, verify the token and subscribe them - if (!empty($_GET['token'])) { - $this->subscribeUser(); - } - - require_once dirname(__FILE__) . '/libs/PHP-po-parser-master/src/Sepia/InterfaceHandler.php'; - require_once dirname(__FILE__) . '/libs/PHP-po-parser-master/src/Sepia/FileHandler.php'; - require_once dirname(__FILE__) . '/libs/PHP-po-parser-master/src/Sepia/PoParser.php'; - - foreach ($this->langs as $lang => $langProps) { - $fileHandler = new FileHandler(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $langProps['locale'] . '.po'); - $this->{'poParser' . $lang} = new PoParser($fileHandler); - $this->{'entries' . $lang} = $this->{'poParser' . $lang}->parse(); - } - } - - function wp_ajax_mailjet_subscribe_ajax_add_meta_property() - { - if (!empty($_REQUEST['name']) && !empty($_REQUEST['type'])) { - echo json_encode($this->api->createMetaContactProperty(array( - 'name' => $_REQUEST['name'], - 'dataType' => $_REQUEST['type'] - ))); - } - die; - } - - /** - * Get list of contact lists - * - * @param void - * @return (array) $this->lists - */ - function getLists() - { - if ($this->lists === FALSE) { - $this->lists = $this->api->getContactLists(array('limit' => 0)); - if (isset($this->lists->Status) && $this->lists->Status == 'ERROR') - $this->lists = array(); - } - return $this->lists; - } - - function getContactMetaProperties($showMsg = true) - { - $response = $this->api->getContactMetaProperties(array( - 'method' => 'GET', - 'limit' => 0 - )); - $this->_userVersion = 3; - if (empty($response)) { - if ($showMsg === true) { - echo '

'; - echo __('You are either v1 user or we could not fetch user contact properties. Please contact our support team to discuss migrating to v3 user where you will have contact properties available. You can still configure a Mailjet subscription widget by clicking on "Next" button and complete step2 and step3.', 'wp-mailjet-subscription-widget'); - echo '

'; - } - $this->_userVersion = 1; - } - return $response; - } - - function preg_array_key_exists($pattern, $array) - { - return (int)preg_grep($pattern, array_keys($array)); - } - - function form($instance) - { - global $WPMailjet; - - // if there are translation entries in the POST, update them - if($this->preg_array_key_exists('/msgstr/', $_POST)){ - require_once(dirname(__FILE__) . '/libs/php.mo-master/php-mo.php'); - foreach ($this->langs as $lang => $locale) { - foreach($_POST as $key => $value) { - if(substr($key, 0, 7) === 'msgstr-'){ - foreach($this->{'entries' . $lang} as $entryKey => $entryValue){ - if($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)){ - $this->{'entries' . $lang}[$entryKey]['msgstr'][0] = stripcslashes($_POST[$key]); - $this->{'poParser' . $lang}->setEntry($entryKey, $this->{'entries' . $lang}[$entryKey]); - } - } - } - } - } - foreach ($this->langs as $lang => $locale) { - $this->{'poParser' . $lang}->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po'); - phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po'); - } - if (in_array(get_locale(), array('en_US', 'en_EN', ''))) { - foreach(array('-en_US', '-en_EN', '') as $lang) { - $this->poParseren->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); - phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); - } - } - } - - $fields = array('new_meta_name', 'new_meta_data_type'); - $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', - 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); - foreach ($fields as $prop) { - ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; - } - foreach($langFields as $prop){ - foreach($this->langs as $lang => $langProps){ - ${$prop . $lang} = empty($instance[$prop . $lang]) ? '' : $instance[$prop . $lang]; - } - } - - ?> -
-
-

Step 1 - Choose up to 3 contact properties

-
- getContactMetaProperties(); - if ($this->_userVersion === 3): ?> - Data)): ?> -
- - - -
-
Available contact properties
- -
Data)): ?> style="display:none;" > -
-
    - Data as $prop): - $lang = 'en'; - //foreach($this->langs as $lang => $langProps): ?> - Name, array(${'metaPropertyName1' . $lang}, ${'metaPropertyName2' . $lang}, ${'metaPropertyName3' . $lang}))): ?> -
  •     Name; ?>
  • - - - -
-
-
-
Selected properties
-
Arrange and sort the properties you selected to determine the way they will be shown in the widget.
-
    -
  • Email address (mandatory)
  • - - -
  •     
  • - - - -
-
-
- -
-
Add New Property
-
Click on the button below to dynamically add a new contact property to your contact list and widget.
-
    -
  • Add a new property
  • -
- -
Property created. Please drag your new contact property to the Selected Properties section above.
- -
-
-
-
- -
-
-
- -
-

- - -

-
-
- -

- -

-
- -

Step 2 - Define your widget labels

-
-
-
    - langs as $lang => $langProps): ?> -
  • - -
  • - -
-
- langs as $lang => $langProps): ?> -
-
- /> - -
- -
Please enter specific labels for your subscription widget and they - will be displayed on the front end of your website.
- _userVersion === 3): ?> -
- -
- - - -
- -
- -

- -

-

- -

-

- -

-
- -
-

- - -

-
-
- -

Step 3 - Customize your widget notifications

-
-
-
    - langs as $lang => $langProps): ?> -
  • - -
  • - -
-
- langs as $lang => $langProps): ?> -
-
-
Widget notifications for this language are deactivated in previous step
- Customize your widget notifications
-
- {'entries' . $lang} as $msgid => $msg): - $id = $this->entryStrToId($msgid); - $i++; - if($i === 1): - ?> -

Errors/Website notifications

- -

Subscription confirmation mail

- -
-
+class WP_Mailjet_Subscribe_Widget extends WP_Widget { + protected $api; + private $lists = false; + private $_userVersion = false; + public $entriesen; + public $poParseren; + public $entriesfr; + public $poParserfr; + public $entriesde; + public $poParserde; + public $entrieses; + public $poParseres; + public $locale; + public $langs = array( + 'en' => array('locale' => 'en_US', 'label' => 'English'), + 'fr' => array('locale' => 'fr_FR', 'label' => 'French'), + 'de' => array('locale' => 'de_DE', 'label' => 'German'), + 'es' => array('locale' => 'es_ES', 'label' => 'Spanish'), + ); + + const MAX_META_PROPERTIES = 3; + const WIDGET_HASH = '[\^=l|>5i!? {xI'; + + public function __construct() { + // Set Plugin URL + $chunks = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); + $this->pluginUrl = WP_PLUGIN_URL . '/' . end($chunks); + + $this->locale = get_locale() === 'en_US' ? 'en_EN' : get_locale(); + + //No dependency injection possible, so we have to use this: + $this->api = new WP_Mailjet_Api(get_option('mailjet_username'), get_option('mailjet_password')); + + $widget_ops = array( + 'classname' => 'WP_Mailjet_Subscribe_Widget', + 'description' => 'Allows your visitors to subscribe to one of your lists' + ); + + parent::__construct(false, __('Mailjet Subscription widget'), $widget_ops); + add_action('wp_ajax_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); + add_action('wp_ajax_nopriv_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); + add_action('wp_ajax_mailjet_subscribe_ajax_add_meta_property', array($this, 'wp_ajax_mailjet_subscribe_ajax_add_meta_property')); + + // if user clicks on the email confirm subscription link, verify the token and subscribe them + if (!empty($_GET['token'])) { + $this->subscribeUser(); + } + + require_once dirname(__FILE__) . '/libs/PHP-po-parser-master/src/Sepia/InterfaceHandler.php'; + require_once dirname(__FILE__) . '/libs/PHP-po-parser-master/src/Sepia/FileHandler.php'; + require_once dirname(__FILE__) . '/libs/PHP-po-parser-master/src/Sepia/PoParser.php'; + + foreach ($this->langs as $lang => $langProps) { + $fileHandler = new FileHandler(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $langProps['locale'] . '.po'); + $this->{'poParser' . $lang} = new PoParser($fileHandler); + $this->{'entries' . $lang} = $this->{'poParser' . $lang}->parse(); + } + } + + function wp_ajax_mailjet_subscribe_ajax_add_meta_property() { + if (!empty($_REQUEST['name']) && !empty($_REQUEST['type'])) { + echo json_encode($this->api->createMetaContactProperty(array( + 'name' => $_REQUEST['name'], + 'dataType' => $_REQUEST['type'] + ))); + } + die; + } + + /** + * Get list of contact lists + * + * @param void + * @return (array) $this->lists + */ + function getLists() { + if ($this->lists === false) { + $this->lists = $this->api->getContactLists(array('limit' => 0)); + if (isset($this->lists->Status) && $this->lists->Status == 'ERROR') + $this->lists = array(); + } + return $this->lists; + } + + function getContactMetaProperties($showMsg = true) { + $response = $this->api->getContactMetaProperties(array( + 'method' => 'GET', + 'limit' => 0 + )); + $this->_userVersion = 3; + if (empty($response)) { + if ($showMsg === true) { + echo '

'; + echo __('You are either v1 user or we could not fetch user contact properties. Please contact our support team to discuss migrating to v3 user where you will have contact properties available. You can still configure a Mailjet subscription widget by clicking on "Next" button and complete step2 and step3.', 'wp-mailjet-subscription-widget'); + echo '

'; + } + $this->_userVersion = 1; + } + return $response; + } + + function preg_array_key_exists($pattern, $array) { + return (int)preg_grep($pattern, array_keys($array)); + } + + function form($instance) { + global $WPMailjet; + + // if there are translation entries in the POST, update them + if ($this->preg_array_key_exists('/msgstr/', $_POST)) { + require_once(dirname(__FILE__) . '/libs/php.mo-master/php-mo.php'); + foreach ($this->langs as $lang => $locale) { + foreach ($_POST as $key => $value) { + if (substr($key, 0, 7) === 'msgstr-') { + foreach ($this->{'entries' . $lang} as $entryKey => $entryValue) { + if ($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)) { + $this->{'entries' . $lang}[$entryKey]['msgstr'][0] = stripcslashes($_POST[$key]); + $this->{'poParser' . $lang}->setEntry($entryKey, $this->{'entries' . $lang}[$entryKey]); + } + } + } + } + } + foreach ($this->langs as $lang => $locale) { + $this->{'poParser' . $lang}->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po'); + phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po'); + } + if (in_array(get_locale(), array('en_US', 'en_EN', ''))) { + foreach (array('-en_US', '-en_EN', '') as $lang) { + $this->poParseren->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); + phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); + } + } + } + + $fields = array('new_meta_name', 'new_meta_data_type'); + $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', + 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); + foreach ($fields as $prop) { + ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; + } + foreach ($langFields as $prop) { + foreach ($this->langs as $lang => $langProps) { + ${$prop . $lang} = empty($instance[$prop . $lang]) ? '' : $instance[$prop . $lang]; + } + } + + ?> +
+
+

Step 1 - Choose up to 3 contact properties

+ +
+ getContactMetaProperties(); + if ($this->_userVersion === 3): ?> + Data)): ?> +
+ + + +
+
Available contact properties
+ +
Data)): ?> style="display:none;" > +
+
    + Data as $prop): + $lang = 'en'; + //foreach($this->langs as $lang => $langProps): + ?> + Name, array(${'metaPropertyName1' . $lang}, ${'metaPropertyName2' . $lang}, ${'metaPropertyName3' . $lang}))): ?> +
  • +
    +     Name; ?>
  • + + + +
+
+
+
Selected properties
+
Arrange and sort the properties you selected to determine the way they will be shown in the widget.
+
    +
  • Email address (mandatory)
  • + + +
  • +
    +     
  • + + + +
+
+
+ +
+
Add New Property
+
Click on the button below to dynamically add a new contact property to your contact list and widget.
+
    +
  • Add a new property
  • +
+ +
Property created. Please drag your new contact property to the Selected Properties section above.
+ +
+
+
+
+ +
+
+
+ +
+

+ + +

+
+
+ +

+ +

+
+ +

Step 2 - Define your widget labels

+ +
+
+
    + langs as $lang => $langProps): ?> +
  • + +
  • + +
+
+ langs as $lang => $langProps): ?> +
+
+ /> + +
+ +
Please enter specific labels for your subscription widget and they + will be displayed on the front end of your website. +
+ _userVersion === 3): ?> +
+ +
+ + + +
+ +
+ +

+ +

+ +

+ +

+ +

+ +

+
+ +
+

+ + +

+
+
+ +

Step 3 - Customize your widget notifications

+ +
+
+
    + langs as $lang => $langProps): ?> +
  • + +
  • + +
+
+ langs as $lang => $langProps): ?> +
+
+
Widget notifications for this language are deactivated in previous step
+ Customize your widget notifications
+
+ {'entries' . $lang} as $msgid => $msg): + $id = $this->entryStrToId($msgid); + $i++; + if ($i === 1): + ?> +

Errors/Website notifications

+ +

Subscription confirmation mail

+ +
+
-
- -
-
- -
-

-
-
-
-
- 0): ?> -
- addMjJsGlobalVar(); - } - - function entryStrToId($str) - { - return substr(str_replace(array(' ', '%', ':', '/', '<', '>', '"', '\\', '@', '.', '!', '?'), array('-'), $str), 0, 20); - } - - function update($new_instance, $old_instance) - { - return $new_instance; - } - - /** - * Email the collected widget data to the customer with a verification token - * @param void - * @return void - */ - public function mailjet_subscribe_from_widget() - { - $error = empty($_POST['email']) ? 'Email field is empty' : false; - $error = empty($_POST['list_id']) ? 'Missing list id' : $error; - if (false !== $error) { - _e($error, 'wp-mailjet-subscription-widget'); - die; - } - - $recipient = $this->api->findRecipient(array( - 'ContactsList' => $_POST['list_id'], - 'ContactEmail' => $_POST['email'], - )); - - if (!empty($recipient->Count) || $recipient === true) { - echo '

'; - echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet-subscription-widget'), $_POST['email']); - echo '

'; - die; - } - - $params = http_build_query($_POST); - $message = file_get_contents(dirname(__FILE__) . '/templates/confirm-subscription-email.php'); - $emailParams = array( - '__EMAIL_TITLE__' => __('Confirm your mailing list subscription', 'wp-mailjet-subscription-widget'), - '__EMAIL_HEADER__' => __('Please Confirm Your Subscription To', 'wp-mailjet-subscription-widget'), - '__WP_URL__' => sprintf('%s', get_site_url(), get_site_url()), - '__CONFIRM_URL__' => get_site_url() . '?' . $params . '&token=' . sha1($params . self::WIDGET_HASH), - '__CLICK_HERE__' => __('Click here to confirm', 'wp-mailjet-subscription-widget'), - '__FROM_NAME__' => get_option('blogname'), - '__IGNORE__' => __('Didn\'t ask to subscribe to this list? Or maybe you\'ve changed your mind? Then simply ignore this email and you won\'t be subscribed', 'wp-mailjet-subscription-widget'), - '__THANKS__' => __('Thanks,', 'wp-mailjet-subscription-widget') - ); - foreach ($emailParams as $key => $value) { - $message = str_replace($key, $value, $message); - } - add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); - wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message, - array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>')); - echo '

' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', - 'wp-mailjet-subscription-widget') . '

'; - die; - } - - /** - * Subscribe the user from the widget - */ - function subscribeUser() - { - // validate token - $token = $_GET['token']; - unset($_GET['token']); - if (sha1(http_build_query($_GET) . self::WIDGET_HASH) !== $token) { - echo '

'; - echo __('Error. Token verification failed.', 'wp-mailjet-subscription-widget'); - echo '

'; - die; - } - - $email = $_GET['email']; - - $metaProperties = $this->getContactMetaProperties(false); - $properties = array(); - if (is_object($metaProperties)) { - foreach ($metaProperties->Data as $i => $prop) { - if (!array_key_exists($prop->Name, $_GET)) { - continue; - } - $properties[] = array( - 'Name' => $prop->Name, - 'Value' => $_GET[$prop->Name] - ); - } - $this->api->updateContactData(array( - 'method' => 'JSON', - 'ID' => $email, - 'Data' => $properties - )); - } - - $result = $this->api->addContact(array( - 'Email' => $email, - 'ListID' => $_GET['list_id'] - )); - - // Check what is the response and display proper message - if (isset($result->Status)) { - if ($result->Status == 'DUPLICATE') { - echo '

'; - echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet-subscription-widget'), $email); - echo '

'; - } else if ($result->Status == 'OK') { - echo '

'; - echo sprintf(__("Thanks for subscribing with %s", 'wp-mailjet-subscription-widget'), $email); - echo '

'; - } else { - echo '

'; - echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet-subscription-widget'), $email); - echo '

'; - } - } - } - - function widget($args, $instance) - { - $this->getContactMetaProperties(false); - // enqueue the scripts required for the widget (only if the widget is active) - // scripts will appear in the footer which is good for speed - wp_enqueue_script('ajax-example', $this->pluginUrl . '/assets/js/ajax.js', array('jquery')); - wp_localize_script('ajax-example', 'WPMailjet', array( - 'ajaxurl' => admin_url('admin-ajax.php'), - 'nonce' => wp_create_nonce('ajax-example-nonce'), - 'loadingImg' => plugin_dir_url(__FILE__) . 'assets/images/loading.gif' - )); - - // output the widget itself - extract($args, EXTR_SKIP); - - echo $before_widget; - - $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', - 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); - if(isset($fields) && is_array($fields)) - foreach($fields as $prop){ - ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; - } - - - foreach($this->langs as $lang => $langProps) { - if (get_locale() !== $langProps['locale']) { - continue; - } - $currentLang = $lang; - foreach($langFields as $prop){ - if (!empty($instance[$prop . $currentLang])) { - ${$prop . $currentLang} = $instance[$prop . $currentLang]; - } - } - } - // if the widget is not configured for the current WP language, the English widget configuration is taken - $currentLang = empty($currentLang) ? 'en' : $currentLang; - - $title = apply_filters('widget_title', $instance['title' . $currentLang]); - $list_id = $instance['list_id' . $currentLang]; - $button_text = trim($instance['button_text' . $currentLang]); - - // If contact list is not selected then we just don't display the widget! - if (!is_numeric($list_id)) { - return FALSE; - } - - if (!empty($title)) - echo $before_title . $title . $after_title;; - ?> - - - -
- +
+ +
+
+ +
+

+
+
+
+
+ 0): ?> +
+ addMjJsGlobalVar(); + } + + function entryStrToId($str) { + return substr(str_replace(array(' ', '%', ':', '/', '<', '>', '"', '\\', '@', '.', '!', '?'), array('-'), $str), 0, 20); + } + + function update($new_instance, $old_instance) { + return $new_instance; + } + + /** + * Email the collected widget data to the customer with a verification token + * @param void + * @return void + */ + public function mailjet_subscribe_from_widget() { + $error = empty($_POST['email']) ? 'Email field is empty' : false; + $error = empty($_POST['list_id']) ? 'Missing list id' : $error; + if (false !== $error) { + _e($error, 'wp-mailjet-subscription-widget'); + die; + } + + $recipient = $this->api->findRecipient(array( + 'ContactsList' => $_POST['list_id'], + 'ContactEmail' => $_POST['email'], + )); + + if (!empty($recipient->Count) || $recipient === true) { + echo '

'; + echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet-subscription-widget'), $_POST['email']); + echo '

'; + die; + } + + $params = http_build_query($_POST); + + $_GET=$_POST; + $_GET['token'] = sha1($params . self::WIDGET_HASH); + + $message = file_get_contents(dirname(__FILE__) . '/templates/confirm-subscription-email.php'); + $emailParams = array( + '__EMAIL_TITLE__' => __('Confirm your mailing list subscription', 'wp-mailjet-subscription-widget'), + '__EMAIL_HEADER__' => __('Please Confirm Your Subscription To', 'wp-mailjet-subscription-widget'), + '__WP_URL__' => sprintf('%s', get_site_url(), get_site_url()), + '__CONFIRM_URL__' => get_site_url() . '?' . $params . '&token=' . $_GET['token'], + '__CLICK_HERE__' => __('Click here to confirm', 'wp-mailjet-subscription-widget'), + '__FROM_NAME__' => get_option('blogname'), + '__IGNORE__' => __('Didn\'t ask to subscribe to this list? Or maybe you\'ve changed your mind? Then simply ignore this email and you won\'t be subscribed', 'wp-mailjet-subscription-widget'), + '__THANKS__' => __('Thanks,', 'wp-mailjet-subscription-widget') + ); + foreach ($emailParams as $key => $value) { + $message = str_replace($key, $value, $message); + } + add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); + /*wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message, + array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>'));*/ + /*echo '

' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', + 'wp-mailjet-subscription-widget') . '

';*/ + + $this->subscribeUser(); + + die; + } + + /** + * Subscribe the user from the widget + */ + function subscribeUser() { + // validate token + $token = $_GET['token']; + unset($_GET['token']); + if (sha1(http_build_query($_GET) . self::WIDGET_HASH) !== $token) { + echo '

'; + echo __('Error. Token verification failed.', 'wp-mailjet-subscription-widget'); + echo '

'; + die; + } + + $email = $_GET['email']; + + $metaProperties = $this->getContactMetaProperties(false); + $properties = array(); + if (is_object($metaProperties)) { + foreach ($metaProperties->Data as $i => $prop) { + if (!array_key_exists($prop->Name, $_GET)) { + continue; + } + $properties[] = array( + 'Name' => $prop->Name, + 'Value' => $_GET[$prop->Name] + ); + } + $this->api->updateContactData(array( + 'method' => 'JSON', + 'ID' => $email, + 'Data' => $properties + )); + } + + $result = $this->api->addContact(array( + 'Email' => $email, + 'ListID' => $_GET['list_id'] + )); + + // Check what is the response and display proper message + if (isset($result->Status)) { + if ($result->Status == 'DUPLICATE') { + echo '

'; + echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet-subscription-widget'), $email); + echo '

'; + } else if ($result->Status == 'OK') { + echo '

'; + echo sprintf(__("Thanks for subscribing with %s", 'wp-mailjet-subscription-widget'), $email); + echo '

'; + } else { + echo '

'; + echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet-subscription-widget'), $email); + echo '

'; + } + } + } + + function widget($args, $instance) { + $this->getContactMetaProperties(false); + // enqueue the scripts required for the widget (only if the widget is active) + // scripts will appear in the footer which is good for speed + wp_enqueue_script('ajax-example', $this->pluginUrl . '/assets/js/ajax.js', array('jquery')); + wp_localize_script('ajax-example', 'WPMailjet', array( + 'ajaxurl' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('ajax-example-nonce'), + 'loadingImg' => plugin_dir_url(__FILE__) . 'assets/images/loading.gif' + )); + + // output the widget itself + extract($args, EXTR_SKIP); + + echo $before_widget; + + $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', + 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); + if (isset($fields) && is_array($fields)) + foreach ($fields as $prop) { + ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; + } + + + foreach ($this->langs as $lang => $langProps) { + if (get_locale() !== $langProps['locale']) { + continue; + } + $currentLang = $lang; + foreach ($langFields as $prop) { + if (!empty($instance[$prop . $currentLang])) { + ${$prop . $currentLang} = $instance[$prop . $currentLang]; + } + } + } + // if the widget is not configured for the current WP language, the English widget configuration is taken + $currentLang = empty($currentLang) ? 'en' : $currentLang; + + $title = apply_filters('widget_title', $instance['title' . $currentLang]); + $list_id = $instance['list_id' . $currentLang]; + $button_text = trim($instance['button_text' . $currentLang]); + + // If contact list is not selected then we just don't display the widget! + if (!is_numeric($list_id)) { + return false; + } + + if (!empty($title)) + echo $before_title . $title . $after_title;; + ?> + + + +
+ 5i!? {xI'; - public function __construct() - { + public function __construct() { // Set Plugin URL $chunks = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); $this->pluginUrl = WP_PLUGIN_URL . '/' . end($chunks); @@ -46,7 +45,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget 'description' => 'Allows your visitors to subscribe to one of your lists' ); - parent::__construct(FALSE, __('Mailjet Subscription widget'), $widget_ops); + parent::__construct(false, __('Mailjet Subscription widget'), $widget_ops); add_action('wp_ajax_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); add_action('wp_ajax_nopriv_mailjet_subscribe_ajax_hook', array($this, 'mailjet_subscribe_from_widget')); add_action('wp_ajax_mailjet_subscribe_ajax_add_meta_property', array($this, 'wp_ajax_mailjet_subscribe_ajax_add_meta_property')); @@ -63,12 +62,11 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget foreach ($this->langs as $lang => $langProps) { $fileHandler = new FileHandler(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $langProps['locale'] . '.po'); $this->{'poParser' . $lang} = new PoParser($fileHandler); - $this->{'entries' . $lang} = $this->{'poParser' . $lang}->parse(); + $this->{'entries' . $lang} = $this->{'poParser' . $lang}->parse(); } } - function wp_ajax_mailjet_subscribe_ajax_add_meta_property() - { + function wp_ajax_mailjet_subscribe_ajax_add_meta_property() { if (!empty($_REQUEST['name']) && !empty($_REQUEST['type'])) { echo json_encode($this->api->createMetaContactProperty(array( 'name' => $_REQUEST['name'], @@ -84,9 +82,8 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget * @param void * @return (array) $this->lists */ - function getLists() - { - if ($this->lists === FALSE) { + function getLists() { + if ($this->lists === false) { $this->lists = $this->api->getContactLists(array('limit' => 0)); if (isset($this->lists->Status) && $this->lists->Status == 'ERROR') $this->lists = array(); @@ -94,8 +91,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget return $this->lists; } - function getContactMetaProperties($showMsg = true) - { + function getContactMetaProperties($showMsg = true) { $response = $this->api->getContactMetaProperties(array( 'method' => 'GET', 'limit' => 0 @@ -112,23 +108,21 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget return $response; } - function preg_array_key_exists($pattern, $array) - { + function preg_array_key_exists($pattern, $array) { return (int)preg_grep($pattern, array_keys($array)); } - function form($instance) - { + function form($instance) { global $WPMailjet; // if there are translation entries in the POST, update them - if($this->preg_array_key_exists('/msgstr/', $_POST)){ + if ($this->preg_array_key_exists('/msgstr/', $_POST)) { require_once(dirname(__FILE__) . '/libs/php.mo-master/php-mo.php'); foreach ($this->langs as $lang => $locale) { - foreach($_POST as $key => $value) { - if(substr($key, 0, 7) === 'msgstr-'){ - foreach($this->{'entries' . $lang} as $entryKey => $entryValue){ - if($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)){ + foreach ($_POST as $key => $value) { + if (substr($key, 0, 7) === 'msgstr-') { + foreach ($this->{'entries' . $lang} as $entryKey => $entryValue) { + if ($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)) { $this->{'entries' . $lang}[$entryKey]['msgstr'][0] = stripcslashes($_POST[$key]); $this->{'poParser' . $lang}->setEntry($entryKey, $this->{'entries' . $lang}[$entryKey]); } @@ -141,7 +135,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po'); } if (in_array(get_locale(), array('en_US', 'en_EN', ''))) { - foreach(array('-en_US', '-en_EN', '') as $lang) { + foreach (array('-en_US', '-en_EN', '') as $lang) { $this->poParseren->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po'); } @@ -150,241 +144,251 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget $fields = array('new_meta_name', 'new_meta_data_type'); $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', - 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); + 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); foreach ($fields as $prop) { ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; } - foreach($langFields as $prop){ - foreach($this->langs as $lang => $langProps){ + foreach ($langFields as $prop) { + foreach ($this->langs as $lang => $langProps) { ${$prop . $lang} = empty($instance[$prop . $lang]) ? '' : $instance[$prop . $lang]; } } ?>
-
-

Step 1 - Choose up to 3 contact properties

-
- getContactMetaProperties(); - if ($this->_userVersion === 3): ?> - Data)): ?> -
- - - -
-
Available contact properties
- -
Data)): ?> style="display:none;" > -
-
    - Data as $prop): - $lang = 'en'; - //foreach($this->langs as $lang => $langProps): ?> +
    +

    Step 1 - Choose up to 3 contact properties

    + +
    + getContactMetaProperties(); + if ($this->_userVersion === 3): ?> + Data)): ?> +
    + + + +
    +
    Available contact properties
    + +
    Data)): ?> style="display:none;" > +
    +
      + Data as $prop): + $lang = 'en'; + //foreach($this->langs as $lang => $langProps): + ?> Name, array(${'metaPropertyName1' . $lang}, ${'metaPropertyName2' . $lang}, ${'metaPropertyName3' . $lang}))): ?> -
    •     Name; ?>
    • - - - -
    -
    -
    -
    Selected properties
    -
    Arrange and sort the properties you selected to determine the way they will be shown in the widget.
    -
      -
    • Email address (mandatory)
    • - - -
    •     
    • +
    • +
      +     Name; ?>
    • + + + +
    +
    +
    +
    Selected properties
    +
    Arrange and sort the properties you selected to determine the way they will be shown in the widget.
    +
      +
    • Email address (mandatory)
    • + + +
    • +
      +     
    • - -
    -
    -
    - -
    -
    Add New Property
    -
    Click on the button below to dynamically add a new contact property to your contact list and widget.
    -
      -
    • Add a new property
    • -
    - -
    Property created. Please drag your new contact property to the Selected Properties section above.
    - -
    -
    -
    -
    - -
    -
    -
    - + +
+
-

- - -

-
-
- -

- -

-
-

Step 2 - Define your widget labels

-
-
-
    - langs as $lang => $langProps): ?> -
  • - -
  • - -
-
- langs as $lang => $langProps): ?> -
-
- /> - +
+
Add New Property
+
Click on the button below to dynamically add a new contact property to your contact list and widget.
+
    +
  • Add a new property
  • +
+ +
Property created. Please drag your new contact property to the Selected Properties section above.
+ +
+
+
+
+ +
+
+
+
- -
Please enter specific labels for your subscription widget and they - will be displayed on the front end of your website.
- _userVersion === 3): ?> -
- -
- - - -
- -
- -

- -

-

- -

- + +

- -
+
+

-

-
-

Step 3 - Customize your widget notifications

-
-
-
    - langs as $lang => $langProps): ?> -
  • - -
  • - -
-
- langs as $lang => $langProps): ?> -
-
-
Widget notifications for this language are deactivated in previous step
- Customize your widget notifications
-
- {'entries' . $lang} as $msgid => $msg): - $id = $this->entryStrToId($msgid); - $i++; - if($i === 1): - ?> -

Errors/Website notifications

- -

Subscription confirmation mail

+

Step 2 - Define your widget labels

+ +
+
+
    + langs as $lang => $langProps): ?> +
  • + +
  • + +
+
+ langs as $lang => $langProps): ?> +
+
+ /> + +
+ +
Please enter specific labels for your subscription widget and they + will be displayed on the front end of your website. +
+ _userVersion === 3): ?> +
+ +
+ + + +
+ +
-
-
+

+ +

+ +

+ +

+ +

+ +

+
+ +
+

+ + +

+
+
+ +

Step 3 - Customize your widget notifications

+ +
+
+
    + langs as $lang => $langProps): ?> +
  • + +
  • + +
+
+ langs as $lang => $langProps): ?> +
+
+
Widget notifications for this language are deactivated in previous step
+ Customize your widget notifications
+
+ {'entries' . $lang} as $msgid => $msg): + $id = $this->entryStrToId($msgid); + $i++; + if ($i === 1): + ?> +

Errors/Website notifications

+ +

Subscription confirmation mail

+ +
+
+ rows="5" cols="30"> +
+
- -
+
+
- +

-

-
0): ?> -
-
+ addMjJsGlobalVar(); } - function entryStrToId($str) - { + function entryStrToId($str) { return substr(str_replace(array(' ', '%', ':', '/', '<', '>', '"', '\\', '@', '.', '!', '?'), array('-'), $str), 0, 20); } - function update($new_instance, $old_instance) - { + function update($new_instance, $old_instance) { return $new_instance; } @@ -393,8 +397,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget * @param void * @return void */ - public function mailjet_subscribe_from_widget() - { + public function mailjet_subscribe_from_widget() { $error = empty($_POST['email']) ? 'Email field is empty' : false; $error = empty($_POST['list_id']) ? 'Missing list id' : $error; if (false !== $error) { @@ -415,12 +418,16 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget } $params = http_build_query($_POST); + + $_GET=$_POST; + $_GET['token'] = sha1($params . self::WIDGET_HASH); + $message = file_get_contents(dirname(__FILE__) . '/templates/confirm-subscription-email.php'); $emailParams = array( '__EMAIL_TITLE__' => __('Confirm your mailing list subscription', 'wp-mailjet-subscription-widget'), '__EMAIL_HEADER__' => __('Please Confirm Your Subscription To', 'wp-mailjet-subscription-widget'), '__WP_URL__' => sprintf('%s', get_site_url(), get_site_url()), - '__CONFIRM_URL__' => get_site_url() . '?' . $params . '&token=' . sha1($params . self::WIDGET_HASH), + '__CONFIRM_URL__' => get_site_url() . '?' . $params . '&token=' . $_GET['token'], '__CLICK_HERE__' => __('Click here to confirm', 'wp-mailjet-subscription-widget'), '__FROM_NAME__' => get_option('blogname'), '__IGNORE__' => __('Didn\'t ask to subscribe to this list? Or maybe you\'ve changed your mind? Then simply ignore this email and you won\'t be subscribed', 'wp-mailjet-subscription-widget'), @@ -430,18 +437,20 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget $message = str_replace($key, $value, $message); } add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); - wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message, - array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>')); - echo '

' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', - 'wp-mailjet-subscription-widget') . '

'; + /*wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message, + array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>'));*/ + /*echo '

' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.', + 'wp-mailjet-subscription-widget') . '

';*/ + + $this->subscribeUser(); + die; } /** * Subscribe the user from the widget */ - function subscribeUser() - { + function subscribeUser() { // validate token $token = $_GET['token']; unset($_GET['token']); @@ -496,8 +505,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget } } - function widget($args, $instance) - { + function widget($args, $instance) { $this->getContactMetaProperties(false); // enqueue the scripts required for the widget (only if the widget is active) // scripts will appear in the footer which is good for speed @@ -514,19 +522,19 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget echo $before_widget; $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', - 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); - if(isset($fields) && is_array($fields)) - foreach($fields as $prop){ - ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; - } + 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3'); + if (isset($fields) && is_array($fields)) + foreach ($fields as $prop) { + ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop]; + } - foreach($this->langs as $lang => $langProps) { + foreach ($this->langs as $lang => $langProps) { if (get_locale() !== $langProps['locale']) { continue; } $currentLang = $lang; - foreach($langFields as $prop){ + foreach ($langFields as $prop) { if (!empty($instance[$prop . $currentLang])) { ${$prop . $currentLang} = $instance[$prop . $currentLang]; } @@ -541,7 +549,7 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget // If contact list is not selected then we just don't display the widget! if (!is_numeric($list_id)) { - return FALSE; + return false; } if (!empty($title)) @@ -575,9 +583,8 @@ class WP_Mailjet_Subscribe_Widget extends WP_Widget echo $after_widget; } - function validate_email($email) - { + function validate_email($email) { return (preg_match("/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/", $email) || - !preg_match("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/", $email)) ? FALSE : TRUE; + !preg_match("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/", $email)) ? false : true; } }