- Enables MailChimp key verification (import step 1)
This commit is contained in:
@@ -168,94 +168,94 @@ define(
|
|||||||
// show loading indicator
|
// show loading indicator
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
/* mailpoet_get_json(
|
MailPoet.Ajax.post({
|
||||||
'subscribers_import_mailchimp.php',
|
endpoint: 'import',
|
||||||
{
|
action: 'getMailChimpLists',
|
||||||
'api_key': subscribers_mailchimp_key.val(), 'action': 'get_lists'
|
data: {api_key: subscribers_mailchimp_key.val()}
|
||||||
},
|
}).done(function (result) {
|
||||||
function (result) {
|
if (result.status === 'success') {
|
||||||
if (result.status === 'success') {
|
jQuery('.mailpoet_mailchimp-key-status').html('').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-ok');
|
||||||
jQuery('.mailpoet_mailchimp-key-status').html('').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-ok');
|
if (result.data) {
|
||||||
if (result.data) {
|
subscribers_mailchimp_lists.find('input')
|
||||||
subscribers_mailchimp_lists.find('input')
|
.select2({
|
||||||
.select2({
|
data: result.data,
|
||||||
data: result.data,
|
width: '20em',
|
||||||
width: '20em',
|
dropdownCssClass: 'mailpoet_no-search',
|
||||||
dropdownCssClass: 'mailpoet_no-search',
|
placeholder: MailPoetI18n.select,
|
||||||
placeholder: MailPoetI18n.select,
|
formatSelection: function (item) {
|
||||||
formatSelection: function (item) {
|
return item.name;
|
||||||
return item.name;
|
},
|
||||||
},
|
formatResult: function (item) {
|
||||||
formatResult: function (item) {
|
return item.name;
|
||||||
return item.name;
|
},
|
||||||
},
|
multiple: true
|
||||||
multiple: true
|
})
|
||||||
})
|
.change(function () {
|
||||||
.change(function () {
|
subscribers_mailchimp_process.closest('table').toggle((jQuery(this).select2('val').length) ? true : false);
|
||||||
subscribers_mailchimp_process.closest('table').toggle((jQuery(this).select2('val').length) ? true : false);
|
})
|
||||||
})
|
.trigger('change');
|
||||||
.trigger('change');
|
subscribers_mailchimp_lists.show();
|
||||||
subscribers_mailchimp_lists.show();
|
}
|
||||||
}
|
else {
|
||||||
else {
|
jQuery('.mailpoet_mailchimp-key-status').html(MailPoetI18n.noMailChimpLists);
|
||||||
jQuery('.mailpoet_mailchimp-key-status').html(MailPoetI18n.noMailChimpLists);
|
subscribers_mailchimp_lists.hide();
|
||||||
subscribers_mailchimp_lists.hide();
|
subscribers_mailchimp_process.closest('table').hide();
|
||||||
subscribers_mailchimp_process.closest('table').hide();
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
MailPoet.Notice.hide();
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.error(interpret_server_message(result.message));
|
||||||
MailPoet.Notice.error(interpret_server_message(result.message));
|
jQuery('.mailpoet_mailchimp-key-status').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-error');
|
||||||
jQuery('.mailpoet_mailchimp-key-status').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-error');
|
subscribers_mailchimp_lists.hide();
|
||||||
subscribers_mailchimp_lists.hide();
|
subscribers_mailchimp_process.closest('table').hide();
|
||||||
subscribers_mailchimp_process.closest('table').hide();
|
}
|
||||||
}
|
// hide loading indicator
|
||||||
// hide loading indicator
|
MailPoet.Modal.loading(false);
|
||||||
MailPoet.Modal.loading(false);
|
}).error(function (error) {
|
||||||
},
|
// hide loading indicator
|
||||||
function (result) {
|
MailPoet.Modal.loading(false);
|
||||||
// hide loading indicator
|
MailPoet.Notice.error(MailPoetI18n.serverError + error.statusText.toLowerCase() + '.');
|
||||||
MailPoet.Modal.loading(false);
|
});
|
||||||
MailPoet.Notice.error(MailPoetI18n.serverError + result.statusText.toLowerCase() + '.');
|
MailPoet.Modal.loading(false);
|
||||||
}
|
|
||||||
);*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
subscribers_mailchimp_process.click(function () {
|
subscribers_mailchimp_process.click(function () {
|
||||||
// show loading indicator
|
// show loading indicator
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
/* mailpoet_get_json(
|
/* mailpoet_get_json(
|
||||||
'subscribers_import_mailchimp.php',
|
'subscribers_import_mailchimp.php',
|
||||||
{
|
{
|
||||||
'api_key': subscribers_mailchimp_key.val(),
|
'api_key': subscribers_mailchimp_key.val(),
|
||||||
'lists': jQuery('#mailchimp_lists_select').select2('val'),
|
'lists': jQuery('#mailchimp_lists_select').select2('val'),
|
||||||
'action': 'process'
|
'action': 'process'
|
||||||
},
|
},
|
||||||
function (result) {
|
function (result) {
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') {
|
||||||
data_container.step_1 = result;
|
data_container.step_1 = result;
|
||||||
router.navigate('step_2', {trigger: true});
|
router.navigate('step_2', {trigger: true});
|
||||||
}
|
|
||||||
else {
|
|
||||||
MailPoet.Notice.hide();
|
|
||||||
MailPoet.Notice.error(interpret_server_message(result.message));
|
|
||||||
}
|
|
||||||
// hide loading indicator
|
|
||||||
MailPoet.Modal.loading(false);
|
|
||||||
},
|
|
||||||
function (result) {
|
|
||||||
MailPoet.Modal.loading(false);
|
|
||||||
MailPoet.Notice.error(MailPoetI18n.serverError + result.statusText.toLowerCase() + '.');
|
|
||||||
}
|
}
|
||||||
);
|
else {
|
||||||
subscribers_mailchimp_process.prop('disabled', false);*/
|
MailPoet.Notice.hide();
|
||||||
|
MailPoet.Notice.error(interpret_server_message(result.message));
|
||||||
|
}
|
||||||
|
// hide loading indicator
|
||||||
|
MailPoet.Modal.loading(false);
|
||||||
|
},
|
||||||
|
function (result) {
|
||||||
|
MailPoet.Modal.loading(false);
|
||||||
|
MailPoet.Notice.error(MailPoetI18n.serverError + result.statusText.toLowerCase() + '.');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
subscribers_mailchimp_process.prop('disabled', false);*/
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!Backbone.History.started) Backbone.history.start();
|
if (!Backbone.History.started) {
|
||||||
|
Backbone.history.start();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@@ -213,14 +213,14 @@ class Menu {
|
|||||||
echo $this->renderer->render('newsletter/form.html', $data);
|
echo $this->renderer->render('newsletter/form.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function import() {
|
function import() {
|
||||||
$import = new Import();
|
$import = new Import();
|
||||||
$data = $import->bootstrapImportMenu();
|
$data = $import->bootstrapImportMenu();
|
||||||
|
|
||||||
echo $this->renderer->render('import.html', $data);
|
echo $this->renderer->render('import.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function formEditor() {
|
function formEditor() {
|
||||||
$id = (isset($_GET['id']) ? (int)$_GET['id'] : 0);
|
$id = (isset($_GET['id']) ? (int)$_GET['id'] : 0);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use MailPoet\Models\CustomField;
|
use MailPoet\Models\CustomField;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
class Import {
|
class Import {
|
||||||
|
|
||||||
@@ -98,6 +99,9 @@ class Import {
|
|||||||
$data['subscriberFields'],
|
$data['subscriberFields'],
|
||||||
$data['subscriberCustomFields']
|
$data['subscriberCustomFields']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$data['maximumParseSize'] = Helpers::get_maximum_post_size();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
13
lib/Router/Import.php
Normal file
13
lib/Router/Import.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
|
use MailPoet\Import\MailChimp;
|
||||||
|
|
||||||
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
class Import {
|
||||||
|
function getMailChimpLists($data) {
|
||||||
|
$mailChimp = new MailChimp($data['api_key']);
|
||||||
|
wp_send_json($mailChimp->getLists());
|
||||||
|
}
|
||||||
|
}
|
@@ -1,100 +1,103 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Util;
|
namespace MailPoet\Util;
|
||||||
|
|
||||||
/*
|
class Helpers {
|
||||||
* Matches each symbol of PHP date format standard
|
|
||||||
* with jQuery equivalent codeword
|
/*
|
||||||
* @author Tristan Jahier
|
* Matches each symbol of PHP date format standard
|
||||||
*/
|
* with jQuery equivalent codeword
|
||||||
function dateformat_PHP_to_jQueryUI($php_format) {
|
* @author Tristan Jahier
|
||||||
$SYMBOLS_MATCHING = array(
|
*/
|
||||||
// Day
|
static function dateformat_PHP_to_jQueryUI($php_format) {
|
||||||
'd' => 'dd',
|
$SYMBOLS_MATCHING = array(
|
||||||
'D' => 'D',
|
// Day
|
||||||
'j' => 'd',
|
'd' => 'dd',
|
||||||
'l' => 'DD',
|
'D' => 'D',
|
||||||
'N' => '',
|
'j' => 'd',
|
||||||
'S' => '',
|
'l' => 'DD',
|
||||||
'w' => '',
|
'N' => '',
|
||||||
'z' => 'o',
|
'S' => '',
|
||||||
// Week
|
'w' => '',
|
||||||
'W' => '',
|
'z' => 'o',
|
||||||
// Month
|
// Week
|
||||||
'F' => 'MM',
|
'W' => '',
|
||||||
'm' => 'mm',
|
// Month
|
||||||
'M' => 'M',
|
'F' => 'MM',
|
||||||
'n' => 'm',
|
'm' => 'mm',
|
||||||
't' => '',
|
'M' => 'M',
|
||||||
// Year
|
'n' => 'm',
|
||||||
'L' => '',
|
't' => '',
|
||||||
'o' => '',
|
// Year
|
||||||
'Y' => 'yy',
|
'L' => '',
|
||||||
'y' => 'y',
|
'o' => '',
|
||||||
// Time
|
'Y' => 'yy',
|
||||||
'a' => '',
|
'y' => 'y',
|
||||||
'A' => '',
|
// Time
|
||||||
'B' => '',
|
'a' => '',
|
||||||
'g' => '',
|
'A' => '',
|
||||||
'G' => '',
|
'B' => '',
|
||||||
'h' => '',
|
'g' => '',
|
||||||
'H' => '',
|
'G' => '',
|
||||||
'i' => '',
|
'h' => '',
|
||||||
's' => '',
|
'H' => '',
|
||||||
'u' => ''
|
'i' => '',
|
||||||
);
|
's' => '',
|
||||||
$jqueryui_format = "";
|
'u' => ''
|
||||||
$escaping = false;
|
);
|
||||||
for ($i = 0; $i < strlen($php_format); $i++) {
|
$jqueryui_format = "";
|
||||||
$char = $php_format[$i];
|
$escaping = false;
|
||||||
if($char === '\\') // PHP date format escaping character
|
for ($i = 0; $i < strlen($php_format); $i++) {
|
||||||
{
|
$char = $php_format[$i];
|
||||||
$i++;
|
if($char === '\\') // PHP date format escaping character
|
||||||
if($escaping) {
|
{
|
||||||
$jqueryui_format .= $php_format[$i];
|
$i++;
|
||||||
|
if($escaping) {
|
||||||
|
$jqueryui_format .= $php_format[$i];
|
||||||
|
} else {
|
||||||
|
$jqueryui_format .= '\'' . $php_format[$i];
|
||||||
|
}
|
||||||
|
$escaping = true;
|
||||||
} else {
|
} else {
|
||||||
$jqueryui_format .= '\'' . $php_format[$i];
|
if($escaping) {
|
||||||
}
|
$jqueryui_format .= "'";
|
||||||
$escaping = true;
|
$escaping = false;
|
||||||
} else {
|
}
|
||||||
if($escaping) {
|
if(isset($SYMBOLS_MATCHING[$char])) {
|
||||||
$jqueryui_format .= "'";
|
$jqueryui_format .= $SYMBOLS_MATCHING[$char];
|
||||||
$escaping = false;
|
} else {
|
||||||
}
|
$jqueryui_format .= $char;
|
||||||
if(isset($SYMBOLS_MATCHING[$char])) {
|
}
|
||||||
$jqueryui_format .= $SYMBOLS_MATCHING[$char];
|
|
||||||
} else {
|
|
||||||
$jqueryui_format .= $char;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $jqueryui_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $jqueryui_format;
|
/*
|
||||||
}
|
* Determine maximum post size in bytes
|
||||||
|
*/
|
||||||
|
static function get_maximum_post_size() {
|
||||||
|
$maximum_post_size = ini_get('post_max_size');
|
||||||
|
$maximum_post_size_bytes = (int) $maximum_post_size;
|
||||||
|
$unit = strtolower($maximum_post_size[strlen($maximum_post_size) - 1]);
|
||||||
|
switch ($unit) {
|
||||||
|
case 'g':
|
||||||
|
$maximum_post_size_bytes *= 1024;
|
||||||
|
case 'm':
|
||||||
|
$maximum_post_size_bytes *= 1024;
|
||||||
|
case 'k':
|
||||||
|
$maximum_post_size_bytes *= 1024;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
return $maximum_post_size_bytes;
|
||||||
* Determine maximum post size in bytes
|
|
||||||
*/
|
|
||||||
function get_maximum_post_size() {
|
|
||||||
$maximum_post_size = ini_get('post_max_size');
|
|
||||||
$maximum_post_size_bytes = (int) $maximum_post_size;
|
|
||||||
$unit = strtolower($maximum_post_size[strlen($maximum_post_size) - 1]);
|
|
||||||
switch ($unit) {
|
|
||||||
case 'g':
|
|
||||||
$maximum_post_size_bytes *= 1024;
|
|
||||||
case 'm':
|
|
||||||
$maximum_post_size_bytes *= 1024;
|
|
||||||
case 'k':
|
|
||||||
$maximum_post_size_bytes *= 1024;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $maximum_post_size_bytes;
|
/*
|
||||||
}
|
* Flatten multidimensional array
|
||||||
|
*/
|
||||||
/*
|
static function flatten_array($array) {
|
||||||
* Flatten multidimensional array
|
return call_user_func_array(
|
||||||
*/
|
'array_merge_recursive', array_map('array_values', $array)
|
||||||
function flatten_array($array) {
|
);
|
||||||
return call_user_func_array(
|
}
|
||||||
'array_merge_recursive', array_map('array_values', $array)
|
|
||||||
);
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user