- Enables MailChimp key verification (import step 1)

This commit is contained in:
MrCasual
2015-10-23 11:10:03 -04:00
parent 3cf50810f9
commit abb2389378
5 changed files with 188 additions and 168 deletions

View File

@@ -168,94 +168,94 @@ define(
// show loading indicator
MailPoet.Modal.loading(true);
/* mailpoet_get_json(
'subscribers_import_mailchimp.php',
{
'api_key': subscribers_mailchimp_key.val(), 'action': 'get_lists'
},
function (result) {
if (result.status === 'success') {
jQuery('.mailpoet_mailchimp-key-status').html('').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-ok');
if (result.data) {
subscribers_mailchimp_lists.find('input')
.select2({
data: result.data,
width: '20em',
dropdownCssClass: 'mailpoet_no-search',
placeholder: MailPoetI18n.select,
formatSelection: function (item) {
return item.name;
},
formatResult: function (item) {
return item.name;
},
multiple: true
})
.change(function () {
subscribers_mailchimp_process.closest('table').toggle((jQuery(this).select2('val').length) ? true : false);
})
.trigger('change');
subscribers_mailchimp_lists.show();
}
else {
jQuery('.mailpoet_mailchimp-key-status').html(MailPoetI18n.noMailChimpLists);
subscribers_mailchimp_lists.hide();
subscribers_mailchimp_process.closest('table').hide();
}
}
else {
MailPoet.Notice.hide();
MailPoet.Notice.error(interpret_server_message(result.message));
jQuery('.mailpoet_mailchimp-key-status').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-error');
subscribers_mailchimp_lists.hide();
subscribers_mailchimp_process.closest('table').hide();
}
// hide loading indicator
MailPoet.Modal.loading(false);
},
function (result) {
// hide loading indicator
MailPoet.Modal.loading(false);
MailPoet.Notice.error(MailPoetI18n.serverError + result.statusText.toLowerCase() + '.');
}
);*/
MailPoet.Ajax.post({
endpoint: 'import',
action: 'getMailChimpLists',
data: {api_key: subscribers_mailchimp_key.val()}
}).done(function (result) {
if (result.status === 'success') {
jQuery('.mailpoet_mailchimp-key-status').html('').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-ok');
if (result.data) {
subscribers_mailchimp_lists.find('input')
.select2({
data: result.data,
width: '20em',
dropdownCssClass: 'mailpoet_no-search',
placeholder: MailPoetI18n.select,
formatSelection: function (item) {
return item.name;
},
formatResult: function (item) {
return item.name;
},
multiple: true
})
.change(function () {
subscribers_mailchimp_process.closest('table').toggle((jQuery(this).select2('val').length) ? true : false);
})
.trigger('change');
subscribers_mailchimp_lists.show();
}
else {
jQuery('.mailpoet_mailchimp-key-status').html(MailPoetI18n.noMailChimpLists);
subscribers_mailchimp_lists.hide();
subscribers_mailchimp_process.closest('table').hide();
}
}
else {
MailPoet.Notice.hide();
MailPoet.Notice.error(interpret_server_message(result.message));
jQuery('.mailpoet_mailchimp-key-status').removeClass().addClass('mailpoet_mailchimp-key-status mailpoet_mailchimp-error');
subscribers_mailchimp_lists.hide();
subscribers_mailchimp_process.closest('table').hide();
}
// hide loading indicator
MailPoet.Modal.loading(false);
}).error(function (error) {
// hide loading indicator
MailPoet.Modal.loading(false);
MailPoet.Notice.error(MailPoetI18n.serverError + error.statusText.toLowerCase() + '.');
});
MailPoet.Modal.loading(false);
});
subscribers_mailchimp_process.click(function () {
// show loading indicator
MailPoet.Modal.loading(true);
/* mailpoet_get_json(
/* mailpoet_get_json(
'subscribers_import_mailchimp.php',
{
'api_key': subscribers_mailchimp_key.val(),
'lists': jQuery('#mailchimp_lists_select').select2('val'),
'action': 'process'
'api_key': subscribers_mailchimp_key.val(),
'lists': jQuery('#mailchimp_lists_select').select2('val'),
'action': 'process'
},
function (result) {
if (result.status === 'success') {
data_container.step_1 = result;
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() + '.');
if (result.status === 'success') {
data_container.step_1 = result;
router.navigate('step_2', {trigger: true});
}
);
subscribers_mailchimp_process.prop('disabled', false);*/
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() + '.');
}
);
subscribers_mailchimp_process.prop('disabled', false);*/
});
});
if (!Backbone.History.started) Backbone.history.start();
if (!Backbone.History.started) {
Backbone.history.start();
}
});
}
);

View File

@@ -213,14 +213,14 @@ class Menu {
echo $this->renderer->render('newsletter/form.html', $data);
}
function import() {
function import() {
$import = new Import();
$data = $import->bootstrapImportMenu();
echo $this->renderer->render('import.html', $data);
}
function formEditor() {
$id = (isset($_GET['id']) ? (int)$_GET['id'] : 0);
$form = Form::findOne($id);

View File

@@ -2,6 +2,7 @@
use MailPoet\Models\CustomField;
use MailPoet\Models\Segment;
use MailPoet\Util\Helpers;
class Import {
@@ -98,6 +99,9 @@ class Import {
$data['subscriberFields'],
$data['subscriberCustomFields']
);
$data['maximumParseSize'] = Helpers::get_maximum_post_size();
return $data;
}
}

13
lib/Router/Import.php Normal file
View 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());
}
}

View File

@@ -1,100 +1,103 @@
<?php
namespace MailPoet\Util;
/*
* Matches each symbol of PHP date format standard
* with jQuery equivalent codeword
* @author Tristan Jahier
*/
function dateformat_PHP_to_jQueryUI($php_format) {
$SYMBOLS_MATCHING = array(
// Day
'd' => 'dd',
'D' => 'D',
'j' => 'd',
'l' => 'DD',
'N' => '',
'S' => '',
'w' => '',
'z' => 'o',
// Week
'W' => '',
// Month
'F' => 'MM',
'm' => 'mm',
'M' => 'M',
'n' => 'm',
't' => '',
// Year
'L' => '',
'o' => '',
'Y' => 'yy',
'y' => 'y',
// Time
'a' => '',
'A' => '',
'B' => '',
'g' => '',
'G' => '',
'h' => '',
'H' => '',
'i' => '',
's' => '',
'u' => ''
);
$jqueryui_format = "";
$escaping = false;
for ($i = 0; $i < strlen($php_format); $i++) {
$char = $php_format[$i];
if($char === '\\') // PHP date format escaping character
{
$i++;
if($escaping) {
$jqueryui_format .= $php_format[$i];
class Helpers {
/*
* Matches each symbol of PHP date format standard
* with jQuery equivalent codeword
* @author Tristan Jahier
*/
static function dateformat_PHP_to_jQueryUI($php_format) {
$SYMBOLS_MATCHING = array(
// Day
'd' => 'dd',
'D' => 'D',
'j' => 'd',
'l' => 'DD',
'N' => '',
'S' => '',
'w' => '',
'z' => 'o',
// Week
'W' => '',
// Month
'F' => 'MM',
'm' => 'mm',
'M' => 'M',
'n' => 'm',
't' => '',
// Year
'L' => '',
'o' => '',
'Y' => 'yy',
'y' => 'y',
// Time
'a' => '',
'A' => '',
'B' => '',
'g' => '',
'G' => '',
'h' => '',
'H' => '',
'i' => '',
's' => '',
'u' => ''
);
$jqueryui_format = "";
$escaping = false;
for ($i = 0; $i < strlen($php_format); $i++) {
$char = $php_format[$i];
if($char === '\\') // PHP date format escaping character
{
$i++;
if($escaping) {
$jqueryui_format .= $php_format[$i];
} else {
$jqueryui_format .= '\'' . $php_format[$i];
}
$escaping = true;
} else {
$jqueryui_format .= '\'' . $php_format[$i];
}
$escaping = true;
} else {
if($escaping) {
$jqueryui_format .= "'";
$escaping = false;
}
if(isset($SYMBOLS_MATCHING[$char])) {
$jqueryui_format .= $SYMBOLS_MATCHING[$char];
} else {
$jqueryui_format .= $char;
if($escaping) {
$jqueryui_format .= "'";
$escaping = false;
}
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;
}
/*
* 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;
}
return $maximum_post_size_bytes;
}
/*
* Flatten multidimensional array
*/
function flatten_array($array) {
return call_user_func_array(
'array_merge_recursive', array_map('array_values', $array)
);
/*
* Flatten multidimensional array
*/
static function flatten_array($array) {
return call_user_func_array(
'array_merge_recursive', array_map('array_values', $array)
);
}
}