Load/Save settings

- renamed all settings with dot syntax
- refactored Menu->settings()
- changed schema of settings table to allow longer setting name and value
- added getAll() static method on Setting Model to fetch all settings (with proper unserialize of value)
This commit is contained in:
Jonathan Labreuille
2015-10-15 14:22:27 +02:00
parent c8c3f09fb2
commit 34c237ce8e
14 changed files with 282 additions and 244 deletions

View File

@ -51,7 +51,7 @@ function(
return ( return (
<select <select
ref="selection" ref="selection"
id={ this.props.field.id || 'mailpoet_field_selection'} id={ this.props.field.id }
placeholder={ this.props.field.placeholder } placeholder={ this.props.field.placeholder }
multiple={ this.props.field.multiple } multiple={ this.props.field.multiple }
onChange={ this.handleChange } onChange={ this.handleChange }

View File

@ -3,8 +3,10 @@ namespace MailPoet\Config;
use \MailPoet\Models\Segment; use \MailPoet\Models\Segment;
use \MailPoet\Models\Setting; use \MailPoet\Models\Setting;
use \MailPoet\Settings\Hosts; use \MailPoet\Settings\Hosts;
use \MailPoet\Settings\Permissions; use \MailPoet\Settings\Pages;
use \MailPoet\Util\Permissions;
use \MailPoet\Util\DKIM; use \MailPoet\Util\DKIM;
use \MailPoet\Util\Charsets;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
@ -95,10 +97,9 @@ class Menu {
} }
function settings() { function settings() {
// Flags (available features on WP install) // flags (available features on WP install)
$flags = array(); $flags = array();
// check if registration is enabled
if(is_multisite()) { if(is_multisite()) {
// get multisite registration option // get multisite registration option
$registration = apply_filters( $registration = apply_filters(
@ -115,44 +116,7 @@ class Menu {
(bool)get_option('users_can_register', false); (bool)get_option('users_can_register', false);
} }
// Segments $settings = Setting::getAll();
$segments = Segment::findArray();
// Settings
$all_settings = Setting::findMany();
$settings = array();
foreach($all_settings as $setting) {
$settings[$setting->name] = $setting->value;
}
// Current user
$current_user = wp_get_current_user();
// WP Pages
$mailpoet_pages = get_posts(array('post_type' => 'mailpoet_page'));
$pages = array_merge($mailpoet_pages, get_pages());
foreach($pages as $key => $page) {
// convert page object to array so that we can add some values
$page = (array)$page;
// get page's preview url
$page['preview_url'] = get_permalink($page['ID']);
// get page's edit url
$page['edit_url'] = get_edit_post_link($page['ID']);
// update page data
$pages[$key] = $page;
}
// Charsets
$charsets = array(
'UTF-8', 'UTF-7', 'BIG5', 'ISO-2022-JP',
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3',
'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6',
'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14',
'ISO-8859-15', 'Windows-1251', 'Windows-1252'
);
// dkim: check if public/private keys have been generated // dkim: check if public/private keys have been generated
if( if(
@ -171,12 +135,12 @@ class Menu {
$data = array( $data = array(
'settings' => $settings, 'settings' => $settings,
'segments' => $segments, 'segments' => Segment::findArray(),
'pages' => $pages, 'pages' => Pages::getAll(),
'flags' => $flags, 'flags' => $flags,
'charsets' => $charsets, 'charsets' => Charsets::getAll(),
'current_user' => $current_user, 'current_user' => wp_get_current_user(),
'permissions' => Permissions::get(), 'permissions' => Permissions::getAll(),
'hosts' => array( 'hosts' => array(
'web' => Hosts::getWebHosts(), 'web' => Hosts::getWebHosts(),
'smtp' => Hosts::getSMTPHosts() 'smtp' => Hosts::getSMTPHosts()

View File

@ -60,8 +60,8 @@ class Migrator {
function settings() { function settings() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(20) NOT NULL,', 'name varchar(50) NOT NULL,',
'value varchar(255) NOT NULL,', 'value mediumtext NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,', 'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', 'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id),', 'PRIMARY KEY (id),',

View File

@ -20,10 +20,29 @@ class Setting extends Model {
if($setting === false) { if($setting === false) {
return $default; return $default;
} else { } else {
return $setting->value; if(is_serialized($setting->value)) {
return unserialize($setting->value);
} else {
return $setting->value;
}
} }
} }
public static function getAll() {
$settingsCollection = self::findMany();
$settings = array();
if(!empty($settingsCollection)) {
foreach($settingsCollection as $setting) {
$value = (is_serialized($setting->value)
? unserialize($setting->value)
: $setting->value
);
$settings[$setting->name] = $value;
}
}
return $settings;
}
public static function createOrUpdate($model) { public static function createOrUpdate($model) {
$exists = self::where('name', $model['name']) $exists = self::where('name', $model['name'])
->find_one(); ->find_one();

View File

@ -0,0 +1,14 @@
<?php
namespace MailPoet\Router;
if(!defined('ABSPATH')) exit;
class Permissions {
function __construct() {
}
function set($permissions = array()) {
$result = \MailPoet\Util\Permissions::set($permissions);
wp_send_json($result);
}
}

View File

@ -9,20 +9,24 @@ class Settings {
} }
function get() { function get() {
$settings = Setting::find_array(); $settings = Setting::getAll();
wp_send_json($settings); wp_send_json($settings);
} }
function set($args) { function set($settings = array()) {
$save = function($setting) { if(empty($settings)) {
Setting::createOrUpdate($setting); wp_send_json(false);
}; } else {
$results = array_map($save, $args); foreach($settings as $name => $value) {
if(is_array($value)) {
wp_send_json(in_array(false, $results)); $value = serialize($value);
} }
Setting::createOrUpdate(array(
function save($data = array()) { 'name' => $name,
// TODO 'value' => $value
));
}
wp_send_json(true);
}
} }
} }

23
lib/Settings/Pages.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace MailPoet\Settings;
class Pages {
static function getAll() {
$mailpoet_pages = get_posts(array(
'post_type' => 'mailpoet_page'
));
$pages = array_merge($mailpoet_pages, get_pages());
foreach($pages as $key => $page) {
$page = (array)$page;
$page['preview_url'] = get_permalink($page['ID']);
$page['edit_url'] = get_edit_post_link($page['ID']);
$pages[$key] = $page;
}
return $pages;
}
}

15
lib/Util/Charsets.php Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace MailPoet\Util;
class Charsets {
static function getAll() {
return array(
'UTF-8', 'UTF-7', 'BIG5', 'ISO-2022-JP',
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3',
'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6',
'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14',
'ISO-8859-15', 'Windows-1251', 'Windows-1252'
);
}
}

View File

@ -1,5 +1,5 @@
<?php <?php
namespace MailPoet\Settings; namespace MailPoet\Util;
class Permissions { class Permissions {
static function getCapabilities() { static function getCapabilities() {
@ -30,7 +30,7 @@ class Permissions {
return $roles; return $roles;
} }
static function get() { static function getAll() {
$roles = static::getRoles(); $roles = static::getRoles();
$capabilities = static::getCapabilities(); $capabilities = static::getCapabilities();
@ -67,28 +67,31 @@ class Permissions {
} }
static function set($permissions = array()) { static function set($permissions = array()) {
if(!empty($permissions)) { if(empty($permissions)) {
foreach($permissions as $permission) { return false;
// ignore administrator & superadmin roles }
if(in_array(
$permission['role'],
array('administrator', 'superadmin'))
) {
continue;
}
// get role foreach($permissions as $permission) {
$role = get_role($permission['role']); // ignore administrator & superadmin roles
if((bool)$permission['is_capable'] === true) { if(in_array(
// add capability to role $permission['role'],
$role->add_cap($permission['capability']); array('administrator', 'superadmin'))
} else { ) {
// remove capability to role continue;
if($role->has_cap($permission['capability'])) { }
$role->remove_cap($permission['capability']);
} // get role
$role = get_role($permission['role']);
if((bool)$permission['is_capable'] === true) {
// add capability to role
$role->add_cap($permission['capability']);
} else {
// remove capability to role
if($role->has_cap($permission['capability'])) {
$role->remove_cap($permission['capability']);
} }
} }
} }
return true;
} }
} }

View File

@ -67,41 +67,14 @@
e.preventDefault(); e.preventDefault();
// serialize form data // serialize form data
var data = $('#mailpoet_settings_form').serializeObject(), var settings_data = $('#mailpoet_settings_form').serializeObject(),
permissions = $('.mailpoet_role_permission'), permissions = $('.mailpoet_role_permission'),
data_permissions = [], permissions_data = []
has_error = false;
// check if "subscribe in comments" is enabled
if(parseInt(data.subscribe_on_comment) === 1) {
if(data.subscribe_on_comment_lists === undefined) {
$('#subscribe_on_comment_lists').next('.mailpoet_error').show();
has_error = true;
} else {
$('#subscribe_on_comment_lists').next('.mailpoet_error').hide();
}
}
// check if "subscribe in registration form" is enabled
if(parseInt(data.subscribe_on_register) === 1) {
if(data.subscribe_on_register_lists === undefined) {
$('#subscribe_on_register_lists').next('.mailpoet_error').show();
has_error = true;
} else {
$('#subscribe_on_register_lists').next('.mailpoet_error').hide();
}
}
// fail fast...
if(has_error === true) {
return false;
}
// format permissions // format permissions
for(var i = permissions.length - 1; i >= 0; i--) { for(var i = permissions.length - 1; i >= 0; i--) {
var permission = $(permissions[i]); var permission = $(permissions[i]);
data_permissions.push({ permissions_data.push({
role: permission.data('role'), role: permission.data('role'),
capability: permission.data('capability'), capability: permission.data('capability'),
is_capable: (permission.is(':checked') ? 1 : 0) is_capable: (permission.is(':checked') ? 1 : 0)
@ -109,28 +82,38 @@
}; };
// show loading screen // show loading screen
//MailPoet.Modal.loading(true); MailPoet.Modal.loading(true);
console.log(data);
console.log(data_permissions);
// // save permissions MailPoet.Ajax.post({
// mailpoet_post_wpi('settings_set_permissions.php', { permissions: data_permissions }); endpoint: 'settings',
action: 'set',
data: settings_data
}).done(function(response) {
if(response === true) {
MailPoet.Ajax.post({
endpoint: 'permissions',
action: 'set',
data: permissions_data
});
// // save settings MailPoet.Notice.success(
// mailpoet_post_json('settings_set.php', data, function(response) { "<%= __('Settings saved.') %>",
// if(response.success !== undefined && response.success === true) { { scroll: true }
// // display success message );
// MailPoet.Notice.success("<?php _e('Settings saved.'); ?>"); } else {
// } else if(response.error !== undefined) { MailPoet.Notice.error(
// MailPoet.Notice.error("<?php _e('Settings could not be saved.'); ?>"); "<%= __('Settings could not be saved.') %>",
// } { scroll: true }
);
// // hide loading screen }
// // MailPoet.Modal.loading(false); MailPoet.Modal.loading(false);
// }, function(error) { }).error(function(errors) {
// // hide loading screen MailPoet.Notice.error(
// // MailPoet.Modal.loading(false); "<%= __('An error occurred. Check your settings.') %>",
// }); { scroll: true }
);
MailPoet.Modal.loading(false);
});
}); });
// setup toggle checkboxes // setup toggle checkboxes

View File

@ -54,8 +54,8 @@
<p> <p>
<input type="text" <input type="text"
id="settings[bounce_email]" id="settings[bounce_email]"
name="bounce_email" name="bounce[address]"
value="<%= settings.bounce_email %>" value="<%= settings.bounce.address %>"
placeholder="bounce@mydomain.com" placeholder="bounce@mydomain.com"
/> />
</p> </p>
@ -80,9 +80,9 @@
<label> <label>
<input <input
type="radio" type="radio"
name="analytics" name="analytics[enabled]"
value="1" value="1"
<% if(settings.analytics) %> <% if(settings.analytics.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('Yes') %> /><%= __('Yes') %>
@ -91,9 +91,9 @@
<label> <label>
<input <input
type="radio" type="radio"
name="analytics" name="analytics[enabled]"
value="" value=""
<% if not(settings.analytics) %> <% if not(settings.analytics.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('No') %> /><%= __('No') %>
@ -104,7 +104,7 @@
<!-- charset --> <!-- charset -->
<tr> <tr>
<th scope="row"> <th scope="row">
<label for="settings[newsletter_charset]"> <label for="settings[charset]">
<%= __('Charset') %> <%= __('Charset') %>
<p class="description"> <p class="description">
<%= __('Squares or weird characters are displayed in your emails? Select the encoding for your language.') %> <%= __('Squares or weird characters are displayed in your emails? Select the encoding for your language.') %>
@ -113,11 +113,14 @@
</th> </th>
<td> <td>
<p> <p>
<select id="settings[newsletter_charset]" name="newsletter_charset"> <select
id="settings[charset]"
name="charset"
>
<% for charset in charsets %> <% for charset in charsets %>
<option <option
value="<%= charset %>" value="<%= charset %>"
<% if(settings.newsletter_charset == charset) %> <% if(settings.charset == charset) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= charset %></option> ><%= charset %></option>
@ -141,9 +144,9 @@
<label> <label>
<input <input
type="radio" type="radio"
name="debug" name="debug[enabled]"
value="1" value="1"
<% if(settings.debug) %> <% if(settings.debug.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('Yes') %> /><%= __('Yes') %>
@ -152,9 +155,9 @@
<label> <label>
<input <input
type="radio" type="radio"
name="debug" name="debug[enabled]"
value="" value=""
<% if not(settings.debug) %> <% if not(settings.debug.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('No') %> /><%= __('No') %>

View File

@ -14,17 +14,17 @@
<p> <p>
<input type="text" <input type="text"
id="settings[notification_email]" id="settings[notification_email]"
name="notification_email" name="notification[address]"
value="<%= settings.notification_email %>" value="<%= settings.notification.address %>"
placeholder="notification@mydomain.com" placeholder="notification@mydomain.com"
class="regular-text" /> class="regular-text" />
</p> </p>
<p> <p>
<label for="settings[notification_on_subscribe]"> <label for="settings[notification_on_subscribe]">
<input type="checkbox" id="settings[notification_on_subscribe]" <input type="checkbox" id="settings[notification_on_subscribe]"
name="notification_on_subscribe" name="notification[on_subscribe]"
value="1" value="1"
<% if(settings.notification_on_subscribe) %>checked="checked"<% endif %> /> <% if(settings.notification.on_subscribe) %>checked="checked"<% endif %> />
<%= __('When someone subscribes') %> <%= __('When someone subscribes') %>
</label> </label>
</p> </p>
@ -32,9 +32,9 @@
<label for="settings[notification_on_unsubscribe]"> <label for="settings[notification_on_unsubscribe]">
<input type="checkbox" <input type="checkbox"
id="settings[notification_on_unsubscribe]" id="settings[notification_on_unsubscribe]"
name="notification_on_unsubscribe" name="notification[on_unsubscribe]"
value="1" value="1"
<% if(settings.notification_on_unsubscribe) %>checked="checked"<% endif %> /> <% if(settings.notification.on_unsubscribe) %>checked="checked"<% endif %> />
<%= __('When someone unsubscribes') %> <%= __('When someone unsubscribes') %>
</label> </label>
</p> </p>
@ -42,9 +42,9 @@
<label for="settings[notification_daily_report]"> <label for="settings[notification_daily_report]">
<input type="checkbox" <input type="checkbox"
id="settings[notification_daily_report]" id="settings[notification_daily_report]"
name="notification_daily_report" name="notification[daily_report]"
value="1" value="1"
<% if(settings.notification_daily_report) %>checked="checked"<% endif %> /> <% if(settings.notification.daily_report) %>checked="checked"<% endif %> />
<%= __('Daily summary of emails sent') %> <%= __('Daily summary of emails sent') %>
</label> </label>
</p> </p>
@ -53,13 +53,13 @@
<label for="settings[from_name]"><%= __('From') %></label> <label for="settings[from_name]"><%= __('From') %></label>
<input type="text" <input type="text"
id="settings[from_name]" id="settings[from_name]"
name="from_name" name="sender[name]"
value="<%= settings.from_name %>" value="<%= settings.sender.name %>"
placeholder="<%= __('Your name') %>" /> placeholder="<%= __('Your name') %>" />
<input type="text" <input type="text"
id="settings[from_email]" id="settings[from_email]"
name="from_email" name="sender[address]"
value="<%= settings.from_email %>" value="<%= settings.sender.address %>"
placeholder="info@mydomain.com" /> placeholder="info@mydomain.com" />
</p> </p>
<!-- email notification: reply_to name & email --> <!-- email notification: reply_to name & email -->
@ -67,13 +67,13 @@
<label for="settings[notification_reply_name]"><%= __('Reply-to') %></label> <label for="settings[notification_reply_name]"><%= __('Reply-to') %></label>
<input type="text" <input type="text"
id="settings[notification_reply_name]" id="settings[notification_reply_name]"
name="notification_reply_name" name="notification[reply_to][name]"
value="<%= settings.notification_reply_name %>" value="<%= settings.notification.reply_to.name %>"
placeholder="<%= __('Your name') %>" /> placeholder="<%= __('Your name') %>" />
<input type="text" <input type="text"
id="settings[notification_reply_email]" id="settings[notification_reply_email]"
name="notification_reply_email" name="notification[reply_to][address]"
value="<%= settings.notification_reply_email %>" value="<%= settings.notification.reply_to.address %>"
placeholder="info@mydomain.com" /> placeholder="info@mydomain.com" />
</p> </p>
</td> </td>
@ -89,17 +89,24 @@
</th> </th>
<td> <td>
<p> <p>
<input data-toggle="mailpoet_subscribe_on_comment" type="checkbox" value="1" id="settings[subscribe_on_comment]" name="subscribe_on_comment" <% if(settings.subscribe_on_comment) %>checked="checked"<% endif %> /> <input
data-toggle="mailpoet_subscribe_on_comment"
type="checkbox"
value="1"
id="settings[subscribe_on_comment]"
name="subscribe[on_comment][enabled]"
<% if(settings.subscribe.on_comment.enabled) %>checked="checked"<% endif %>
/>
</p> </p>
<div id="mailpoet_subscribe_on_comment"> <div id="mailpoet_subscribe_on_comment">
<p> <p>
<input <input
type="text" type="text"
id="settings[subscribe_on_comment_label]" id="settings[subscribe_on_comment_label]"
name="subscribe_on_comment_label" name="subscribe[on_comment][label]"
class="regular-text" class="regular-text"
<%if(settings.subscribe_on_comment_label) %> <%if(settings.subscribe.on_comment.label) %>
value="<%= settings.subscribe_on_comment_label %>" value="<%= settings.subscribe.on_comment.label %>"
<% else %> <% else %>
value="<%= __('Yes, add me to your mailing list.') %>" value="<%= __('Yes, add me to your mailing list.') %>"
<% endif %> <% endif %>
@ -108,22 +115,19 @@
<p> <p>
<select <select
id="mailpoet_subscribe_on_comment_lists" id="mailpoet_subscribe_on_comment_lists"
name="subscribe_on_comment_lists[]" name="subscribe[on_comment][lists][]"
placeholder="<%= __('Choose a list') %>" placeholder="<%= __('Choose a list') %>"
multiple multiple
> >
<% for segment in segments %> <% for segment in segments %>
<option <option
value="<%= segment.id %>" value="<%= segment.id %>"
<% if(segment.id in settings.subscribe_on_comment_lists) %> <% if(segment.id in settings.subscribe.on_comment.lists) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= segment.name %></option> ><%= segment.name %></option>
<% endfor %> <% endfor %>
</select> </select>
&nbsp;<span class="mailpoet_error">
<%= __('Please select a list.') %>
</span>
</p> </p>
</div> </div>
</td> </td>
@ -148,8 +152,8 @@
type="checkbox" type="checkbox"
value="1" value="1"
id="settings[subscribe_on_register]" id="settings[subscribe_on_register]"
name="subscribe_on_register" name="subscribe[on_register][enabled]"
<% if(settings.subscribe_on_register) %> <% if(settings.subscribe.on_register.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/> />
@ -160,10 +164,10 @@
<input <input
type="text" type="text"
id="settings[subscribe_on_register_label]" id="settings[subscribe_on_register_label]"
name="subscribe_on_register_label" name="subscribe[on_register][label]"
class="regular-text" class="regular-text"
<%if(settings.subscribe_on_register_label) %> <%if(settings.subscribe.on_register.label) %>
value="<%= settings.subscribe_on_register_label %>" value="<%= settings.subscribe.on_register.label %>"
<% else %> <% else %>
value="<%= __('Yes, add me to your mailing list.') %>" value="<%= __('Yes, add me to your mailing list.') %>"
<% endif %> <% endif %>
@ -172,14 +176,14 @@
<p> <p>
<select <select
id="mailpoet_subscribe_on_register_lists" id="mailpoet_subscribe_on_register_lists"
name="subscribe_on_register_lists[]" name="subscribe[on_register][lists][]"
placeholder="<%= __('Choose a list') %>" placeholder="<%= __('Choose a list') %>"
multiple multiple
> >
<% for segment in segments %> <% for segment in segments %>
<option <option
value="<%= segment.id %>" value="<%= segment.id %>"
<% if(segment.id in settings.subscribe_on_register_lists) %> <% if(segment.id in settings.subscribe.on_register.lists) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= segment.name %></option> ><%= segment.name %></option>
@ -209,14 +213,14 @@
<p> <p>
<select <select
class="mailpoet_page_selection" class="mailpoet_page_selection"
name="subscription_edit_page" name="subscription[page]"
> >
<% for page in pages %> <% for page in pages %>
<option <option
value="<%= page.ID %>" value="<%= page.ID %>"
data-preview-url="<%= page.preview_url|raw %>" data-preview-url="<%= page.preview_url|raw %>"
data-edit-url="<%= page.edit_url|raw %>" data-edit-url="<%= page.edit_url|raw %>"
<% if(page.ID == settings.subscription_edit_page) %> <% if(page.ID == settings.subscription.page) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= page.post_title %></option> ><%= page.post_title %></option>
@ -238,14 +242,14 @@
<p> <p>
<select <select
id="mailpoet_subscription_edit_lists" id="mailpoet_subscription_edit_lists"
name="subscription_edit_lists[]" name="subscription[lists][]"
placeholder="<%= __('Leave empty to show all lists') %>" placeholder="<%= __('Leave empty to show all lists') %>"
multiple multiple
> >
<% for segment in segments %> <% for segment in segments %>
<option <option
value="<%= segment.id %>" value="<%= segment.id %>"
<% if(segment.id in settings.subscription_edit_lists) %> <% if(segment.id in settings.subscription.lists) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= segment.name %></option> ><%= segment.name %></option>

View File

@ -14,21 +14,21 @@
<input <input
type="hidden" type="hidden"
id="mta_method" id="mta_method"
name="mta_method" name="mta[method]"
value="<%= settings.mta_method %>" value="<%= settings.mta.method %>"
/> />
<!-- mta: sending frequency --> <!-- mta: sending frequency -->
<input <input
type="hidden" type="hidden"
id="mta_frequency_emails" id="mta_frequency_emails"
name="mta_frequency_emails" name="mta[frequency][emails]"
value="<%= settings.mta_frequency_emails %>" value="<%= settings.mta.frequency.emails %>"
/> />
<input <input
type="hidden" type="hidden"
id="mta_frequency_interval" id="mta_frequency_interval"
name="mta_frequency_interval" name="mta[frequency][interval]"
value="<%= settings.mta_frequency_interval %>" value="<%= settings.mta.frequency.interval %>"
/> />
<!-- dkim: public / private keys --> <!-- dkim: public / private keys -->
<input <input
@ -52,7 +52,7 @@
<ul class="mailpoet_sending_methods clearfix"> <ul class="mailpoet_sending_methods clearfix">
<li <li
data-method="mailpoet" data-method="mailpoet"
<% if(settings.mta_method == 'mailpoet') %>class="mailpoet_active"<% endif %> <% if(settings.mta.method == 'mailpoet') %>class="mailpoet_active"<% endif %>
> >
<h3> <h3>
<img <img
@ -81,7 +81,7 @@
</li> </li>
<li <li
data-method="website" data-method="website"
<% if(settings.mta_method == 'website') %>class="mailpoet_active"<% endif %> <% if(settings.mta.method == 'website') %>class="mailpoet_active"<% endif %>
> >
<h3><%= __('Your own website') %></h3> <h3><%= __('Your own website') %></h3>
@ -101,7 +101,7 @@
</li> </li>
<li <li
data-method="smtp" data-method="smtp"
<% if(settings.mta_method == 'smtp') %>class="mailpoet_active"<% endif %> <% if(settings.mta.method == 'smtp') %>class="mailpoet_active"<% endif %>
> >
<h3><%= __('Third party') %></h3> <h3><%= __('Third party') %></h3>
@ -156,16 +156,16 @@
<tbody> <tbody>
<tr> <tr>
<th scope="row"> <th scope="row">
<label for="mailpoet_account_key"> <label for="mailpoet_api_key">
<%= __('Your key') %> <%= __('Your key') %>
</label> </label>
</th> </th>
<td> <td>
<input <input
type="text" type="text"
id="mailpoet_account_key" id="mailpoet_api_key"
size="40" size="40"
name="account_key" name="api_key"
value="<%= settings.api_key %>" value="<%= settings.api_key %>"
/> />
</td> </td>
@ -193,11 +193,11 @@
<p> <p>
<label> <label>
<input type="radio" <input type="radio"
name="mta_local_method" name="mta[local_method]"
value="mail" value="mail"
<% <%
if not(settings.mta_local_method) if not(settings.mta.local_method)
or (settings.mta_local_method == 'mail') or (settings.mta.local_method == 'mail')
%>checked="checked"<% endif %> %>checked="checked"<% endif %>
/>PHP Mail />PHP Mail
</label> </label>
@ -207,10 +207,10 @@
<p> <p>
<label> <label>
<input type="radio" <input type="radio"
name="mta_local_method" name="mta[local_method]"
value="sendmail" value="sendmail"
<% <%
if(settings.mta_local_method == 'sendmail') if(settings.mta.local_method == 'sendmail')
%>checked="checked"<% endif %> %>checked="checked"<% endif %>
/>Sendmail />Sendmail
</label> </label>
@ -220,10 +220,10 @@
<p> <p>
<label> <label>
<input type="radio" <input type="radio"
name="mta_local_method" name="mta[local_method]"
value="wp_mail" value="wp_mail"
<% <%
if(settings.mta_local_method == 'wp_mail') if(settings.mta.local_method == 'wp_mail')
%>checked="checked"<% endif %> %>checked="checked"<% endif %>
/>WP Mail />WP Mail
</label> </label>
@ -239,7 +239,10 @@
<td> <td>
<p> <p>
<!-- sending frequency --> <!-- sending frequency -->
<select id="mailpoet_web_host" name="web_host"> <select
id="mailpoet_web_host"
name="web_host"
>
<option value="auto"> <option value="auto">
<%= __('Safe default values') %> <%= __('Safe default values') %>
</option> </option>
@ -329,13 +332,16 @@
<tbody> <tbody>
<tr> <tr>
<th scope="row"> <th scope="row">
<label for="mailpoet_mta_provider"> <label for="mailpoet_smtp_provider">
<%= __('Provider') %> <%= __('Provider') %>
</label> </label>
</th> </th>
<td> <td>
<!-- smtp provider --> <!-- smtp provider -->
<select id="mailpoet_mta_provider" name="mta_provider"> <select
id="mailpoet_smtp_provider"
name="smtp_provider"
>
<option data-interval="5" data-emails="100" value="manual"> <option data-interval="5" data-emails="100" value="manual">
<%= __('Custom SMTP') %> <%= __('Custom SMTP') %>
</option> </option>
@ -346,7 +352,7 @@
value="<%= host_key %>" value="<%= host_key %>"
data-emails="<%= host.emails %>" data-emails="<%= host.emails %>"
data-interval="<%= host.interval %>" data-interval="<%= host.interval %>"
<% if(settings.smtp_host == host_key) %> <% if(settings.smtp_provider == host_key) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= host.name %></option> ><%= host.name %></option>
@ -419,8 +425,8 @@
<input <input
type="text" type="text"
id="settings[mta_smtp_host]" id="settings[mta_smtp_host]"
name="mta_smtp_host" name="mta[smtp][host]"
value="<%= settings.mta.smtp_host %>" /> value="<%= settings.mta.smtp.host %>" />
</td> </td>
</tr> </tr>
<!-- smtp: login --> <!-- smtp: login -->
@ -434,8 +440,8 @@
<input <input
type="text" type="text"
id="settings[mta_smtp_login]" id="settings[mta_smtp_login]"
name="mta_smtp_login" name="mta[smtp][login]"
value="<%= settings.mta.smtp_login %>" value="<%= settings.mta.smtp.login %>"
/> />
</td> </td>
</tr> </tr>
@ -450,8 +456,8 @@
<input <input
type="password" type="password"
id="settings[mta_smtp_password]" id="settings[mta_smtp_password]"
name="mta_smtp_password" name="mta[smtp][password]"
value="<%= settings.mta.smtp_password %>" value="<%= settings.mta.smtp.password %>"
/> />
</td> </td>
</tr> </tr>
@ -466,8 +472,8 @@
<input <input
type="text" type="text"
id="settings[mta_smtp_port]" id="settings[mta_smtp_port]"
name="mta_smtp_port" name="mta[smtp][port]"
value="<%= settings.mta.smtp_port %>" value="<%= settings.mta.smtp.port %>"
/> />
</td> </td>
</tr> </tr>
@ -479,17 +485,17 @@
</label> </label>
</th> </th>
<td> <td>
<select id="settings[mta_smtp_secure]" name="mta_smtp_secure"> <select id="settings[mta_smtp_secure]" name="mta[smtp][secure]">
<option value=""><%= __('No') %></option> <option value=""><%= __('No') %></option>
<option <option
value="ssl" value="ssl"
<% if(settings.mta.smtp_secure == 'ssl') %> <% if(settings.mta.smtp.secure == 'ssl') %>
selected="selected" selected="selected"
<% endif %> <% endif %>
>SSL</option> >SSL</option>
<option <option
value="tls" value="tls"
<% if(settings.mta.smtp_secure == 'tls') %> <% if(settings.mta.smtp.secure == 'tls') %>
selected="selected" selected="selected"
<% endif %> <% endif %>
>TLS</option> >TLS</option>
@ -511,8 +517,8 @@
<input <input
type="radio" type="radio"
value="1" value="1"
name="mta_smtp_authenticate" name="mta[smtp][authenticate]"
<% if(settings.mta.smtp_authenticate) %> <% if(settings.mta.smtp.authenticate) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('Yes') %> /><%= __('Yes') %>
@ -522,8 +528,8 @@
<input <input
type="radio" type="radio"
value="" value=""
name="mta_smtp_authenticate" name="mta[smtp][authenticate]"
<% if not(settings.mta.smtp_authenticate) %> <% if not(settings.mta.smtp.authenticate) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('No') %> /><%= __('No') %>
@ -558,7 +564,7 @@
type="checkbox" type="checkbox"
value="1" value="1"
id="settings[dkim_enabled]" id="settings[dkim_enabled]"
name="dkim_enabled" name="dkim[enabled]"
<% if(settings.dkim.enabled) %>checked="checked"<% endif %> <% if(settings.dkim.enabled) %>checked="checked"<% endif %>
/> />
</p> </p>
@ -664,7 +670,7 @@
}); });
// sending frequency update based on selected provider // sending frequency update based on selected provider
$('#mailpoet_mta_provider').on('change keyup', setProviderForm); $('#mailpoet_smtp_provider').on('change keyup', setProviderForm);
$('#mailpoet_web_host').on('change keyup', renderHostSendingFrequency); $('#mailpoet_web_host').on('change keyup', renderHostSendingFrequency);
// update manual sending frequency when values are changed // update manual sending frequency when values are changed
@ -697,7 +703,7 @@
} else { } else {
if( if(
method === 'mailpoet' method === 'mailpoet'
&& $('#mailpoet_account_key').val().trim().length === 0 && $('#mailpoet_api_key').val().trim().length === 0
) { ) {
MailPoet.Notice.error( MailPoet.Notice.error(
"<%= __('You need to specify a MailPoet account key') %>" "<%= __('You need to specify a MailPoet account key') %>"
@ -740,7 +746,7 @@
}); });
// render sending frequency form // render sending frequency form
$('#mailpoet_mta_provider').trigger('change'); $('#mailpoet_smtp_provider').trigger('change');
$('#mailpoet_web_host').trigger('change'); $('#mailpoet_web_host').trigger('change');
}); });

View File

@ -17,9 +17,9 @@
<input <input
type="radio" type="radio"
class="mailpoet_signup_confirmation" class="mailpoet_signup_confirmation"
name="signup_confirmation" name="signup_confirmation[enabled]"
value="1" value="1"
<% if not(settings.signup_confirmation) %> <% if(settings.signup_confirmation.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('Yes') %> /><%= __('Yes') %>
@ -29,9 +29,9 @@
<input <input
type="radio" type="radio"
class="mailpoet_signup_confirmation" class="mailpoet_signup_confirmation"
name="signup_confirmation" name="signup_confirmation[enabled]"
value="" value=""
<% if(settings.signup_confirmation) %> <% if not(settings.signup_confirmation.enabled) %>
checked="checked" checked="checked"
<% endif %> <% endif %>
/><%= __('No') %> /><%= __('No') %>
@ -55,15 +55,15 @@
<input <input
type="text" type="text"
id="settings[signup_confirmation_from_name]" id="settings[signup_confirmation_from_name]"
name="signup_confirmation_from_name" name="signup_confirmation[from][name]"
value="<%= settings.signup_confirmation_from_name %>" value="<%= settings.signup_confirmation.from.name %>"
placeholder="<%= __('Your name') %>" placeholder="<%= __('Your name') %>"
/> />
<input <input
type="text" type="text"
id="settings[signup_confirmation_from_email]" id="settings[signup_confirmation_from_email]"
name="signup_confirmation_from_email" name="signup_confirmation[from][address]"
value="<%= settings.signup_confirmation_from_email %>" value="<%= settings.signup_confirmation.from.address %>"
placeholder="confirmation@mydomain.com" placeholder="confirmation@mydomain.com"
size="28" size="28"
/> />
@ -82,15 +82,15 @@
<input <input
type="text" type="text"
id="settings[signup_confirmation_reply_name]" id="settings[signup_confirmation_reply_name]"
name="signup_confirmation_reply_name" name="signup_confirmation[reply_to][name]"
value="<%= settings.signup_confirmation_reply_name %>" value="<%= settings.signup_confirmation.reply_to.name %>"
placeholder="<%= __('Your name') %>" placeholder="<%= __('Your name') %>"
/> />
<input <input
type="text" type="text"
id="settings[signup_confirmation_reply_email]" id="settings[signup_confirmation_reply_email]"
name="signup_confirmation_reply_email" name="signup_confirmation[reply_to][address]"
value="<%= settings.signup_confirmation_reply_email %>" value="<%= settings.signup_confirmation.reply_to.address %>"
placeholder="confirmation@mydomain.com" placeholder="confirmation@mydomain.com"
size="28" size="28"
/> />
@ -109,9 +109,9 @@
size="52" size="52"
type="text" type="text"
id="settings[signup_confirmation_email_subject]" id="settings[signup_confirmation_email_subject]"
name="signup_confirmation_email_subject" name="signup_confirmation[subject]"
<% if(settings.signup_confirmation_email_subject) %> <% if(settings.signup_confirmation.subject) %>
value="<%= settings.signup_confirmation_email_subject %>" value="<%= settings.signup_confirmation.subject %>"
<% else %> <% else %>
value="<%= value="<%=
__('Confirm your subscription to %1$s') __('Confirm your subscription to %1$s')
@ -136,9 +136,9 @@
cols="50" cols="50"
rows="15" rows="15"
id="settings[signup_confirmation_email_body]" id="settings[signup_confirmation_email_body]"
name="signup_confirmation_email_body" name="signup_confirmation[body]"
><% if(settings.signup_confirmation_email_body) %> ><% if(settings.signup_confirmation.body) %>
<%=- settings.signup_confirmation_email_body -%> <%=- settings.signup_confirmation.body -%>
<% else %> <% else %>
<%=- __("Hello!\n\nHurray! You've subscribed to our site.\nWe need you to activate your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe team!") -%> <%=- __("Hello!\n\nHurray! You've subscribed to our site.\nWe need you to activate your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe team!") -%>
<% endif %></textarea> <% endif %></textarea>
@ -158,14 +158,14 @@
<p> <p>
<select <select
class="mailpoet_page_selection" class="mailpoet_page_selection"
name="signup_confirmation_page" name="signup_confirmation[page]"
> >
<% for page in pages %> <% for page in pages %>
<option <option
value="<%= page.ID %>" value="<%= page.ID %>"
data-preview-url="<%= page.preview_url|raw %>" data-preview-url="<%= page.preview_url|raw %>"
data-edit-url="<%= page.edit_url|raw %>" data-edit-url="<%= page.edit_url|raw %>"
<% if(page.ID == settings.signup_confirmation_page) %> <% if(page.ID == settings.signup_confirmation.page) %>
selected="selected" selected="selected"
<% endif %> <% endif %>
><%= page.post_title %></option> ><%= page.post_title %></option>