Compare commits
71 Commits
Author | SHA1 | Date | |
---|---|---|---|
580ac989aa | |||
acf300160d | |||
983df4ee13 | |||
03c782d4ab | |||
0daf7e12c1 | |||
6a2e18a0e1 | |||
316d5ab183 | |||
eb6bba5961 | |||
b5864adf06 | |||
9bce50a633 | |||
365a53cf27 | |||
31a4575d43 | |||
1ae584c4e7 | |||
aac2cd6eb8 | |||
9874e1c371 | |||
16b1c0dc41 | |||
9223fbf478 | |||
eb27de36f4 | |||
636fa38ab6 | |||
9b1503dc7a | |||
2ac3b00af6 | |||
5fcdbfe826 | |||
67036ddb61 | |||
6c0f6a07cd | |||
8139a7dd0a | |||
97adfc14c0 | |||
4ed703a351 | |||
2aee853406 | |||
854736fac7 | |||
841c69af59 | |||
56b4688f93 | |||
e60bc7c387 | |||
6094a83f4b | |||
91ddb98f56 | |||
27d5972306 | |||
6088497433 | |||
0d894a6fef | |||
57f0b88299 | |||
5121dbe0c8 | |||
f874ffc19c | |||
e928a5c2bc | |||
d11badf3ce | |||
3006c982cb | |||
b29e31fdd6 | |||
bc42c8e280 | |||
409697ee64 | |||
cfb4265971 | |||
13d78aac05 | |||
6f176f4e6c | |||
9b584296a5 | |||
5ea87c5eed | |||
7522084ccb | |||
214aa60d0e | |||
7a049ce1b7 | |||
94d293deb7 | |||
bd2d38d757 | |||
abec524daa | |||
cac6beb4ac | |||
cac995e15b | |||
b26380fd10 | |||
6c6a4070be | |||
8b001d820b | |||
2ae3d8ebdf | |||
459ec21f9d | |||
9c7790d07e | |||
f9c5b99e46 | |||
95b0b39366 | |||
4b6fa0e760 | |||
67a3440ced | |||
0de372344a | |||
7a04eeb650 |
@ -108,11 +108,12 @@ class RoboFile extends \Robo\Tasks {
|
||||
$this->_exec('vendor/bin/codecept run unit -f '.(($file) ? $file : ''));
|
||||
}
|
||||
|
||||
function testCoverage() {
|
||||
function testCoverage($file = null) {
|
||||
$this->loadEnv();
|
||||
$this->_exec('vendor/bin/codecept build');
|
||||
$this->_exec(join(' ', array(
|
||||
'vendor/bin/codecept run',
|
||||
(($file) ? $file : ''),
|
||||
'--coverage',
|
||||
'--coverage-html'
|
||||
)));
|
||||
|
@ -38,9 +38,7 @@
|
||||
content: '\f142'
|
||||
|
||||
.mailpoet_save_show_options_icon
|
||||
width: auto
|
||||
height: auto
|
||||
line-height: auto
|
||||
vertical-align: middle
|
||||
|
||||
&::before
|
||||
content: '\f140'
|
||||
|
@ -21,3 +21,9 @@
|
||||
|
||||
.mailpoet_automated_latest_content_display_options
|
||||
animation-slide-open-downwards()
|
||||
|
||||
.mailpoet_automated_latest_content_show_amount
|
||||
width: 25px
|
||||
|
||||
.mailpoet_automated_latest_content_content_type
|
||||
width: 180px
|
||||
|
@ -11,9 +11,6 @@
|
||||
padding-right: 0
|
||||
margin-bottom: 0
|
||||
|
||||
img
|
||||
width: 100%
|
||||
|
||||
.mailpoet_content a:hover
|
||||
cursor: all-scroll
|
||||
|
||||
|
@ -133,3 +133,17 @@ body
|
||||
.wrap > .mailpoet_notice,
|
||||
.update-nag
|
||||
margin-left: 2px + 15px !important
|
||||
|
||||
/* Make a button group */
|
||||
.mailpoet_button_group
|
||||
|
||||
.button:first-child
|
||||
border-right: 0
|
||||
border-top-right-radius: 0
|
||||
border-bottom-right-radius: 0
|
||||
|
||||
.button:last-child
|
||||
border-left: 0
|
||||
border-top-left-radius: 0
|
||||
border-bottom-left-radius: 0
|
||||
|
||||
|
@ -10,10 +10,13 @@ function(
|
||||
return this.props.onValueChange(e);
|
||||
},
|
||||
render: function() {
|
||||
const isChecked = !!(this.props.item[this.props.field.name]);
|
||||
if (this.props.field.values === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const isChecked = !!(this.props.item[this.props.field.name]);
|
||||
const options = Object.keys(this.props.field.values).map(
|
||||
function(value, index) {
|
||||
(value, index) => {
|
||||
return (
|
||||
<p key={ 'checkbox-' + index }>
|
||||
<label>
|
||||
@ -29,7 +32,7 @@ function(
|
||||
</label>
|
||||
</p>
|
||||
);
|
||||
}.bind(this)
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -4,12 +4,15 @@ define([
|
||||
function(
|
||||
React
|
||||
) {
|
||||
var FormFieldRadio = React.createClass({
|
||||
const FormFieldRadio = React.createClass({
|
||||
render: function() {
|
||||
var selected_value = this.props.item[this.props.field.name];
|
||||
if (this.props.field.values === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var options = Object.keys(this.props.field.values).map(
|
||||
function(value, index) {
|
||||
const selected_value = this.props.item[this.props.field.name];
|
||||
const options = Object.keys(this.props.field.values).map(
|
||||
(value, index) => {
|
||||
return (
|
||||
<p key={ 'radio-' + index }>
|
||||
<label>
|
||||
@ -23,7 +26,7 @@ function(
|
||||
</label>
|
||||
</p>
|
||||
);
|
||||
}.bind(this)
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -4,10 +4,14 @@ define([
|
||||
function(
|
||||
React
|
||||
) {
|
||||
var FormFieldSelect = React.createClass({
|
||||
const FormFieldSelect = React.createClass({
|
||||
render: function() {
|
||||
var options =
|
||||
Object.keys(this.props.field.values).map(function(value, index) {
|
||||
if (this.props.field.values === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const options = Object.keys(this.props.field.values).map(
|
||||
(value, index) => {
|
||||
return (
|
||||
<option
|
||||
key={ 'option-' + index }
|
||||
@ -15,7 +19,7 @@ function(
|
||||
{ this.props.field.values[value] }
|
||||
</option>
|
||||
);
|
||||
}.bind(this)
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -25,58 +25,49 @@ const columns = [
|
||||
|
||||
const messages = {
|
||||
onTrash: function(response) {
|
||||
if(response) {
|
||||
let message = null;
|
||||
if(~~response === 1) {
|
||||
message = (
|
||||
'1 form was moved to the trash.'
|
||||
);
|
||||
} else if(~~response > 1) {
|
||||
message = (
|
||||
'%$1d forms were moved to the trash.'
|
||||
).replace('%$1d', ~~response);
|
||||
}
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 form was moved to the trash.'
|
||||
);
|
||||
} else {
|
||||
message = (
|
||||
'%$1d forms were moved to the trash.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
},
|
||||
onDelete: function(response) {
|
||||
if(response) {
|
||||
let message = null;
|
||||
if(~~response === 1) {
|
||||
message = (
|
||||
'1 form was permanently deleted.'
|
||||
);
|
||||
} else if(~~response > 1) {
|
||||
message = (
|
||||
'%$1d forms were permanently deleted.'
|
||||
).replace('%$1d', ~~response);
|
||||
}
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 form was permanently deleted.'
|
||||
);
|
||||
} else {
|
||||
message = (
|
||||
'%$1d forms were permanently deleted.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
},
|
||||
onRestore: function(response) {
|
||||
if(response) {
|
||||
let message = null;
|
||||
if(~~response === 1) {
|
||||
message = (
|
||||
'1 form has been restored from the trash.'
|
||||
);
|
||||
} else if(~~response > 1) {
|
||||
message = (
|
||||
'%$1d forms have been restored from the trash.'
|
||||
).replace('%$1d', ~~response);
|
||||
}
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 form has been restored from the trash.'
|
||||
);
|
||||
} else {
|
||||
message = (
|
||||
'%$1d forms have been restored from the trash.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,9 @@ function(
|
||||
})
|
||||
return this.props.onSelectFilter(filters);
|
||||
},
|
||||
handleEmptyTrash: function() {
|
||||
return this.props.onEmptyTrash();
|
||||
},
|
||||
getAvailableFilters: function() {
|
||||
let filters = this.props.filters;
|
||||
|
||||
@ -34,7 +37,7 @@ function(
|
||||
const available_filters = this.getAvailableFilters()
|
||||
.map(function(filter, i) {
|
||||
let default_value = false;
|
||||
if(selected_filters[filter] !== undefined && selected_filters[filter]) {
|
||||
if (selected_filters[filter] !== undefined && selected_filters[filter]) {
|
||||
default_value = selected_filters[filter]
|
||||
} else {
|
||||
jQuery(`select[name="${filter}"]`).val('');
|
||||
@ -60,9 +63,10 @@ function(
|
||||
|
||||
let button = false;
|
||||
|
||||
if(available_filters.length > 0) {
|
||||
if (available_filters.length > 0) {
|
||||
button = (
|
||||
<input
|
||||
id="post-query-submit"
|
||||
onClick={ this.handleFilterAction }
|
||||
type="submit"
|
||||
defaultValue="Filter"
|
||||
@ -70,10 +74,23 @@ function(
|
||||
);
|
||||
}
|
||||
|
||||
let empty_trash = false;
|
||||
if (this.props.group === 'trash') {
|
||||
empty_trash = (
|
||||
<input
|
||||
onClick={ this.handleEmptyTrash }
|
||||
type="submit"
|
||||
value="Empty Trash"
|
||||
className="button"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="alignleft actions actions">
|
||||
{ available_filters }
|
||||
{ button }
|
||||
{ empty_trash }
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -74,10 +74,11 @@ define(
|
||||
);
|
||||
}
|
||||
|
||||
var custom_actions = this.props.item_actions;
|
||||
var item_actions = false;
|
||||
const custom_actions = this.props.item_actions;
|
||||
let item_actions = false;
|
||||
|
||||
if(custom_actions.length > 0) {
|
||||
let is_first = true;
|
||||
item_actions = custom_actions.map(function(action, index) {
|
||||
if(action.display !== undefined) {
|
||||
if(action.display(this.props.item) === false) {
|
||||
@ -85,10 +86,12 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
let custom_action = null;
|
||||
|
||||
if(action.name === 'trash') {
|
||||
return (
|
||||
custom_action = (
|
||||
<span key={ 'action-'+index } className="trash">
|
||||
{(index > 0) ? ' | ' : ''}
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
<a
|
||||
href="javascript:;"
|
||||
onClick={ this.handleTrashItem.bind(
|
||||
@ -100,27 +103,27 @@ define(
|
||||
</span>
|
||||
);
|
||||
} else if(action.refresh) {
|
||||
return (
|
||||
custom_action = (
|
||||
<span
|
||||
onClick={ this.props.onRefreshItems }
|
||||
key={ 'action-'+index } className={ action.name }>
|
||||
{(index > 0) ? ' | ' : ''}
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
{ action.link(this.props.item) }
|
||||
</span>
|
||||
);
|
||||
} else if(action.link) {
|
||||
return (
|
||||
custom_action = (
|
||||
<span
|
||||
key={ 'action-'+index } className={ action.name }>
|
||||
{(index > 0) ? ' | ' : ''}
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
{ action.link(this.props.item) }
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
custom_action = (
|
||||
<span
|
||||
key={ 'action-'+index } className={ action.name }>
|
||||
{(index > 0) ? ' | ' : ''}
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
<a href="javascript:;" onClick={
|
||||
(action.onClick !== undefined)
|
||||
? action.onClick.bind(null,
|
||||
@ -132,6 +135,12 @@ define(
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if(custom_action !== null && is_first === true) {
|
||||
is_first = false;
|
||||
}
|
||||
|
||||
return custom_action;
|
||||
}.bind(this));
|
||||
} else {
|
||||
item_actions = (
|
||||
@ -504,10 +513,21 @@ define(
|
||||
this.getItems();
|
||||
}.bind(this));
|
||||
},
|
||||
handleEmptyTrash: function() {
|
||||
this.handleBulkAction('all', {
|
||||
action: 'delete',
|
||||
group: 'trash'
|
||||
}, function(response) {
|
||||
MailPoet.Notice.success(
|
||||
MailPoetI18n.permanentlyDeleted.replace('%d', response)
|
||||
);
|
||||
});
|
||||
},
|
||||
handleBulkAction: function(selected_ids, params, callback) {
|
||||
if(
|
||||
this.state.selection === false
|
||||
&& this.state.selected_ids.length === 0
|
||||
&& selected_ids !== 'all'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -520,8 +540,10 @@ define(
|
||||
limit: 0,
|
||||
filter: this.state.filter,
|
||||
group: this.state.group,
|
||||
search: this.state.search,
|
||||
selection: selected_ids
|
||||
search: this.state.search
|
||||
}
|
||||
if(selected_ids !== 'all') {
|
||||
data.listing.selection = selected_ids;
|
||||
}
|
||||
|
||||
MailPoet.Ajax.post({
|
||||
@ -715,7 +737,10 @@ define(
|
||||
<ListingFilters
|
||||
filters={ this.state.filters }
|
||||
filter={ this.state.filter }
|
||||
onSelectFilter={ this.handleFilter } />
|
||||
group={ this.state.group }
|
||||
onSelectFilter={ this.handleFilter }
|
||||
onEmptyTrash={ this.handleEmptyTrash }
|
||||
/>
|
||||
<ListingPages
|
||||
count={ this.state.count }
|
||||
page={ this.state.page }
|
||||
|
@ -7,7 +7,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
||||
}
|
||||
},
|
||||
setPage: function(page) {
|
||||
this.props.onSetPage(page);
|
||||
this.setState({
|
||||
page: null
|
||||
}, function () {
|
||||
this.props.onSetPage(this.constrainPage(page));
|
||||
}.bind(this));
|
||||
},
|
||||
setFirstPage: function() {
|
||||
this.setPage(1);
|
||||
@ -16,10 +20,14 @@ define(['react', 'classnames'], function(React, classNames) {
|
||||
this.setPage(this.getLastPage());
|
||||
},
|
||||
setPreviousPage: function() {
|
||||
this.setPage(this.constrainPage(this.props.page - 1));
|
||||
this.setPage(this.constrainPage(
|
||||
parseInt(this.props.page, 10) - 1)
|
||||
);
|
||||
},
|
||||
setNextPage: function() {
|
||||
this.setPage(this.constrainPage(this.props.page + 1));
|
||||
this.setPage(this.constrainPage(
|
||||
parseInt(this.props.page, 10) + 1)
|
||||
);
|
||||
},
|
||||
constrainPage: function(page) {
|
||||
return Math.min(Math.max(1, Math.abs(~~page)), this.getLastPage());
|
||||
@ -27,14 +35,16 @@ define(['react', 'classnames'], function(React, classNames) {
|
||||
handleSetManualPage: function(e) {
|
||||
if(e.which === 13) {
|
||||
this.setPage(this.state.page);
|
||||
this.setState({ page: null });
|
||||
}
|
||||
},
|
||||
handleChangeManualPage: function(e) {
|
||||
this.setState({
|
||||
page: this.constrainPage(e.target.value)
|
||||
page: e.target.value
|
||||
});
|
||||
},
|
||||
handleBlurManualPage: function(e) {
|
||||
this.setPage(e.target.value);
|
||||
},
|
||||
getLastPage: function() {
|
||||
return Math.ceil(this.props.count / this.props.limit);
|
||||
},
|
||||
@ -101,6 +111,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
||||
);
|
||||
}
|
||||
|
||||
let pageValue = this.props.page;
|
||||
if(this.state.page !== null) {
|
||||
pageValue = this.state.page;
|
||||
}
|
||||
|
||||
pagination = (
|
||||
<span className="pagination-links">
|
||||
{firstPage}
|
||||
@ -115,10 +130,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
||||
type="text"
|
||||
onChange={ this.handleChangeManualPage }
|
||||
onKeyUp={ this.handleSetManualPage }
|
||||
onBlur={ this.handleBlurManualPage }
|
||||
aria-describedby="table-paging"
|
||||
size="1"
|
||||
ref="page"
|
||||
value={ this.state.page || this.props.page }
|
||||
value={ pageValue }
|
||||
name="paged"
|
||||
id="current-page-selector"
|
||||
className="current-page" />
|
||||
|
@ -35,7 +35,7 @@ define([
|
||||
titlePosition: 'inTextBlock', // 'inTextBlock'|'aboveBlock',
|
||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||
titleIsLink: false, // false|true
|
||||
imagePadded: true, // true|false
|
||||
imageFullWidth: false, // true|false
|
||||
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
||||
authorPrecededBy: 'Author:',
|
||||
@ -63,7 +63,7 @@ define([
|
||||
initialize: function() {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
this.fetchPosts();
|
||||
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:titlePosition change:titleAlignment change:titleIsLink change:imagePadded change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._scheduleFetchPosts, this);
|
||||
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:titlePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._scheduleFetchPosts, this);
|
||||
this.listenTo(this.get('readMoreButton'), 'change', this._scheduleFetchPosts);
|
||||
this.listenTo(this.get('divider'), 'change', this._scheduleFetchPosts);
|
||||
},
|
||||
@ -144,7 +144,7 @@ define([
|
||||
"change .mailpoet_automated_latest_content_include_or_exclude": _.partial(this.changeField, "inclusionType"),
|
||||
"change .mailpoet_automated_latest_content_title_position": _.partial(this.changeField, "titlePosition"),
|
||||
"change .mailpoet_automated_latest_content_title_alignment": _.partial(this.changeField, "titleAlignment"),
|
||||
"change .mailpoet_automated_latest_content_image_padded": _.partial(this.changeBoolField, "imagePadded"),
|
||||
"change .mailpoet_automated_latest_content_image_full_width": _.partial(this.changeBoolField, "imageFullWidth"),
|
||||
"change .mailpoet_automated_latest_content_show_author": _.partial(this.changeField, "showAuthor"),
|
||||
"keyup .mailpoet_automated_latest_content_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
||||
"change .mailpoet_automated_latest_content_show_categories": _.partial(this.changeField, "showCategories"),
|
||||
|
@ -32,6 +32,7 @@ define([
|
||||
fontColor: '#000000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: '16px',
|
||||
fontWeight: 'normal', // 'normal'|'bold'
|
||||
textAlign: 'center',
|
||||
},
|
||||
},
|
||||
@ -72,6 +73,7 @@ define([
|
||||
"change .mailpoet_field_button_font_size": _.partial(this.changeField, "styles.block.fontSize"),
|
||||
"change .mailpoet_field_button_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"change .mailpoet_field_button_border_color": _.partial(this.changeColorField, "styles.block.borderColor"),
|
||||
"change .mailpoet_field_button_font_weight": "changeFontWeight",
|
||||
|
||||
"input .mailpoet_field_button_border_width": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width_input', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
"change .mailpoet_field_button_border_width": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width_input', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
@ -128,6 +130,13 @@ define([
|
||||
this.$(fieldToUpdate).val(jQuery(event.target).val());
|
||||
callable(event);
|
||||
},
|
||||
changeFontWeight: function(event) {
|
||||
var checked = !!jQuery(event.target).prop('checked');
|
||||
this.model.set(
|
||||
'styles.block.fontWeight',
|
||||
(checked) ? jQuery(event.target).val() : 'normal'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Module.ButtonWidgetView = base.WidgetView.extend({
|
||||
|
@ -60,11 +60,9 @@ define([
|
||||
|
||||
valid_elements: "p[class|style],span[class|style],a[href|class|title|target|style],strong[class|style],em[class|style],strike,br",
|
||||
invalid_elements: "script",
|
||||
style_formats: [
|
||||
{title: 'Paragraph', block: 'p'},
|
||||
],
|
||||
block_formats: 'Paragraph=p',
|
||||
|
||||
plugins: "link textcolor mailpoet_custom_fields",
|
||||
plugins: "link textcolor colorpicker mailpoet_custom_fields",
|
||||
|
||||
setup: function(editor) {
|
||||
editor.on('change', function(e) {
|
||||
|
@ -60,11 +60,9 @@ define([
|
||||
|
||||
valid_elements: "p[class|style],span[class|style],a[href|class|title|target|style],strong[class|style],em[class|style],strike,br",
|
||||
invalid_elements: "script",
|
||||
style_formats: [
|
||||
{title: 'Paragraph', block: 'p'},
|
||||
],
|
||||
block_formats: 'Paragraph=p',
|
||||
|
||||
plugins: "link textcolor mailpoet_custom_fields",
|
||||
plugins: "link textcolor colorpicker mailpoet_custom_fields",
|
||||
|
||||
setup: function(editor) {
|
||||
editor.on('change', function(e) {
|
||||
|
@ -20,7 +20,7 @@ define([
|
||||
link: 'http://example.org',
|
||||
src: 'no-image.png',
|
||||
alt: 'An image of...',
|
||||
padded: true, // true | false - Padded or full width
|
||||
fullWidth: true, // true | false
|
||||
width: '64px',
|
||||
height: '64px',
|
||||
styles: {
|
||||
@ -45,10 +45,10 @@ define([
|
||||
this.toolsView = new Module.ImageBlockToolsView({ model: this.model });
|
||||
this.toolsRegion.show(this.toolsView);
|
||||
|
||||
if (this.model.get('padded')) {
|
||||
this.$el.removeClass('mailpoet_full_image');
|
||||
} else {
|
||||
if (this.model.get('fullWidth')) {
|
||||
this.$el.addClass('mailpoet_full_image');
|
||||
} else {
|
||||
this.$el.removeClass('mailpoet_full_image');
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -64,7 +64,7 @@ define([
|
||||
"keyup .mailpoet_field_image_link": _.partial(this.changeField, "link"),
|
||||
"keyup .mailpoet_field_image_address": _.partial(this.changeField, "src"),
|
||||
"keyup .mailpoet_field_image_alt_text": _.partial(this.changeField, "alt"),
|
||||
"change .mailpoet_field_image_padded": _.partial(this.changeBoolCheckboxField, "padded"),
|
||||
"change .mailpoet_field_image_full_width": _.partial(this.changeBoolCheckboxField, "fullWidth"),
|
||||
"change .mailpoet_field_image_alignment": _.partial(this.changeField, "styles.block.textAlign"),
|
||||
"click .mailpoet_field_image_select_another_image": "showMediaManager",
|
||||
"click .mailpoet_done_editing": "close",
|
||||
|
@ -46,7 +46,7 @@ define([
|
||||
titlePosition: 'inTextBlock', // 'inTextBlock'|'aboveBlock',
|
||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||
titleIsLink: false, // false|true
|
||||
imagePadded: true, // true|false
|
||||
imageFullWidth: false, // true|false
|
||||
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
||||
authorPrecededBy: 'Author:',
|
||||
@ -88,7 +88,7 @@ define([
|
||||
this.on('change:amount change:contentType change:terms change:inclusionType change:postStatus change:search change:sortBy', refreshAvailablePosts);
|
||||
|
||||
this.listenTo(this.get('_selectedPosts'), 'add remove reset', refreshTransformedPosts);
|
||||
this.on('change:displayType change:titleFormat change:titlePosition change:titleAlignment change:titleIsLink change:imagePadded change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:showDivider', refreshTransformedPosts);
|
||||
this.on('change:displayType change:titleFormat change:titlePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:showDivider', refreshTransformedPosts);
|
||||
this.listenTo(this.get('readMoreButton'), 'change', refreshTransformedPosts);
|
||||
this.listenTo(this.get('divider'), 'change', refreshTransformedPosts);
|
||||
|
||||
@ -111,7 +111,7 @@ define([
|
||||
data.posts = this.get('_selectedPosts').pluck('ID');
|
||||
|
||||
if (data.posts.length === 0) {
|
||||
this.get('_transformedPosts.blocks').reset();
|
||||
this.get('_transformedPosts').get('blocks').reset();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -396,7 +396,7 @@ define([
|
||||
"change .mailpoet_posts_include_or_exclude": _.partial(this.changeField, "inclusionType"),
|
||||
"change .mailpoet_posts_title_position": _.partial(this.changeField, "titlePosition"),
|
||||
"change .mailpoet_posts_title_alignment": _.partial(this.changeField, "titleAlignment"),
|
||||
"change .mailpoet_posts_image_padded": _.partial(this.changeBoolField, "imagePadded"),
|
||||
"change .mailpoet_posts_image_full_width": _.partial(this.changeBoolField, "imageFullWidth"),
|
||||
"change .mailpoet_posts_show_author": _.partial(this.changeField, "showAuthor"),
|
||||
"keyup .mailpoet_posts_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
||||
"change .mailpoet_posts_show_categories": _.partial(this.changeField, "showCategories"),
|
||||
|
@ -52,21 +52,15 @@ define([
|
||||
inline: true,
|
||||
|
||||
menubar: false,
|
||||
toolbar1: "styleselect bold italic forecolor | link unlink",
|
||||
toolbar1: "formatselect bold italic forecolor | link unlink",
|
||||
toolbar2: "alignleft aligncenter alignright alignjustify | bullist numlist blockquote | code mailpoet_custom_fields",
|
||||
|
||||
//forced_root_block: 'p',
|
||||
valid_elements: "p[class|style],span[class|style],a[href|class|title|target|style],h1[class|style],h2[class|style],h3[class|style],ol[class|style],ul[class|style],li[class|style],strong[class|style],em[class|style],strike,br,blockquote[class|style],table[class|style],tr[class|style],th[class|style],td[class|style]",
|
||||
invalid_elements: "script",
|
||||
style_formats: [
|
||||
{title: 'Heading 1', block: 'h1'},
|
||||
{title: 'Heading 2', block: 'h2'},
|
||||
{title: 'Heading 3', block: 'h3'},
|
||||
block_formats: 'Heading 1=h1;Heading 2=h2;Heading 3=h3;Paragraph=p',
|
||||
|
||||
{title: 'Paragraph', block: 'p'},
|
||||
],
|
||||
|
||||
plugins: "link code textcolor mailpoet_custom_fields",
|
||||
plugins: "link code textcolor colorpicker mailpoet_custom_fields",
|
||||
|
||||
setup: function(editor) {
|
||||
editor.on('change', function(e) {
|
||||
|
@ -67,7 +67,28 @@ define([
|
||||
};
|
||||
|
||||
Module.getThumbnail = function(element, options) {
|
||||
return html2canvas(element, options || {});
|
||||
var promise = html2canvas(element, options || {});
|
||||
|
||||
return promise.then(function(oldCanvas) {
|
||||
// Temporary workaround for html2canvas-alpha2.
|
||||
// Removes 1px left transparent border from resulting canvas.
|
||||
|
||||
var oldContext = oldCanvas.getContext('2d'),
|
||||
newCanvas = document.createElement("canvas"),
|
||||
newContext = newCanvas.getContext("2d"),
|
||||
leftBorderWidth = 1;
|
||||
|
||||
newCanvas.width = oldCanvas.width;
|
||||
newCanvas.height = oldCanvas.height;
|
||||
|
||||
newContext.drawImage(
|
||||
oldCanvas,
|
||||
leftBorderWidth, 0, oldCanvas.width - leftBorderWidth, oldCanvas.height,
|
||||
0, 0, oldCanvas.width, oldCanvas.height
|
||||
);
|
||||
|
||||
return newCanvas;
|
||||
});
|
||||
};
|
||||
|
||||
Module.saveTemplate = function(options) {
|
||||
|
@ -225,6 +225,11 @@ define([
|
||||
showPreview: function() {
|
||||
var json = App.toJSON();
|
||||
|
||||
// Stringify to enable transmission of primitive non-string value types
|
||||
if (!_.isUndefined(json.body)) {
|
||||
json.body = JSON.stringify(json.body);
|
||||
}
|
||||
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'newsletters',
|
||||
action: 'render',
|
||||
|
@ -43,58 +43,49 @@ define(
|
||||
|
||||
var messages = {
|
||||
onTrash: function(response) {
|
||||
var count = ~~response.newsletters;
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(count === 1 || response === true) {
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 newsletter was moved to the trash.'
|
||||
);
|
||||
} else if(count > 1) {
|
||||
} else {
|
||||
message = (
|
||||
'%$1d newsletters were moved to the trash.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
},
|
||||
onDelete: function(response) {
|
||||
var count = ~~response.newsletters;
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(count === 1 || response === true) {
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 newsletter was permanently deleted.'
|
||||
);
|
||||
} else if(count > 1) {
|
||||
} else {
|
||||
message = (
|
||||
'%$1d newsletters were permanently deleted.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
},
|
||||
onRestore: function(response) {
|
||||
var count = ~~response.newsletters;
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(count === 1 || response === true) {
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 newsletter has been restored from the trash.'
|
||||
);
|
||||
} else if(count > 1) {
|
||||
} else {
|
||||
message = (
|
||||
'%$1d newsletters have been restored from the trash.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,8 @@ define(
|
||||
"Tempt them to open your email.",
|
||||
type: 'text',
|
||||
validation: {
|
||||
'data-parsley-required': true
|
||||
'data-parsley-required': true,
|
||||
'data-parsley-required-message': 'You need to specify a subject.'
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -42,7 +43,8 @@ define(
|
||||
return !!(!segment.deleted_at);
|
||||
},
|
||||
validation: {
|
||||
'data-parsley-required': true
|
||||
'data-parsley-required': true,
|
||||
'data-parsley-required-message': 'You need to select a segment.'
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -107,8 +109,16 @@ define(
|
||||
mixins: [
|
||||
Router.History
|
||||
],
|
||||
componentDidMount: function() {
|
||||
jQuery('#mailpoet_newsletter').parsley();
|
||||
},
|
||||
isValid: function() {
|
||||
return jQuery('#mailpoet_newsletter').parsley().isValid();
|
||||
},
|
||||
handleSend: function() {
|
||||
if(jQuery('#mailpoet_newsletter').parsley().validate() === true) {
|
||||
if(!this.isValid()) {
|
||||
jQuery('#mailpoet_newsletter').parsley().validate();
|
||||
} else {
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'sendingQueue',
|
||||
action: 'add',
|
||||
@ -132,9 +142,7 @@ define(
|
||||
);
|
||||
} else {
|
||||
if(response.errors) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.join("<br />")
|
||||
);
|
||||
MailPoet.Notice.error(response.errors);
|
||||
} else {
|
||||
MailPoet.Notice.error(
|
||||
'An error occurred while trying to send. '+
|
||||
@ -144,6 +152,7 @@ define(
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
return false;
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
@ -158,6 +167,7 @@ define(
|
||||
fields={ fields }
|
||||
params={ this.props.params }
|
||||
messages={ messages }
|
||||
isValid={ this.isValid }
|
||||
>
|
||||
<p className="submit">
|
||||
<input
|
||||
|
@ -24,11 +24,14 @@ define(
|
||||
template.body = JSON.stringify(template.body);
|
||||
}
|
||||
|
||||
MailPoet.Modal.loading(true);
|
||||
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'newsletterTemplates',
|
||||
action: 'save',
|
||||
data: template
|
||||
}).done(function(response) {
|
||||
MailPoet.Modal.loading(false);
|
||||
if(response.result === true) {
|
||||
this.props.onImport(template);
|
||||
} else {
|
||||
@ -92,10 +95,13 @@ define(
|
||||
getTemplates: function() {
|
||||
this.setState({ loading: true });
|
||||
|
||||
MailPoet.Modal.loading(true);
|
||||
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'newsletterTemplates',
|
||||
action: 'getAll',
|
||||
}).done(function(response) {
|
||||
MailPoet.Modal.loading(false);
|
||||
if(this.isMounted()) {
|
||||
|
||||
if(response.length === 0) {
|
||||
|
@ -192,21 +192,28 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
error: function(message, options) {
|
||||
this.show(jQuery.extend({}, {
|
||||
type: 'error',
|
||||
message: '<p>'+message+'</p>'
|
||||
message: '<p>'+this.formatMessage(message)+'</p>'
|
||||
}, options));
|
||||
},
|
||||
success: function(message, options) {
|
||||
this.show(jQuery.extend({}, {
|
||||
type: 'success',
|
||||
message: '<p>'+message+'</p>'
|
||||
message: '<p>'+this.formatMessage(message)+'</p>'
|
||||
}, options));
|
||||
},
|
||||
system: function(message, options) {
|
||||
this.show(jQuery.extend({}, {
|
||||
type: 'system',
|
||||
static: true,
|
||||
message: message
|
||||
message: '<p>'+this.formatMessage(message)+'</p>'
|
||||
}, options));
|
||||
},
|
||||
formatMessage: function(message) {
|
||||
if(Array.isArray(message)) {
|
||||
return message.join('<br />');
|
||||
} else {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -12,7 +12,7 @@ define(
|
||||
Form
|
||||
) {
|
||||
|
||||
var fields = [
|
||||
let fields = [
|
||||
{
|
||||
name: 'name',
|
||||
label: 'Name',
|
||||
@ -25,7 +25,7 @@ define(
|
||||
}
|
||||
];
|
||||
|
||||
var messages = {
|
||||
const messages = {
|
||||
onUpdate: function() {
|
||||
MailPoet.Notice.success('Segment successfully updated!');
|
||||
},
|
||||
@ -34,7 +34,7 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
var SegmentForm = React.createClass({
|
||||
const SegmentForm = React.createClass({
|
||||
mixins: [
|
||||
Router.History
|
||||
],
|
||||
|
@ -42,58 +42,49 @@ var columns = [
|
||||
|
||||
const messages = {
|
||||
onTrash: function(response) {
|
||||
if(response) {
|
||||
let message = null;
|
||||
if(~~response === 1) {
|
||||
message = (
|
||||
'1 segment was moved to the trash.'
|
||||
);
|
||||
} else if(~~response > 1) {
|
||||
message = (
|
||||
'%$1d segments were moved to the trash.'
|
||||
).replace('%$1d', ~~response);
|
||||
}
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 segment was moved to the trash.'
|
||||
);
|
||||
} else {
|
||||
message = (
|
||||
'%$1d segments were moved to the trash.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
},
|
||||
onDelete: function(response) {
|
||||
if(response) {
|
||||
let message = null;
|
||||
if(~~response === 1) {
|
||||
message = (
|
||||
'1 segment was permanently deleted.'
|
||||
);
|
||||
} else if(~~response > 1) {
|
||||
message = (
|
||||
'%$1d segments were permanently deleted.'
|
||||
).replace('%$1d', ~~response);
|
||||
}
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 segment was permanently deleted.'
|
||||
);
|
||||
} else {
|
||||
message = (
|
||||
'%$1d segments were permanently deleted.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
},
|
||||
onRestore: function(response) {
|
||||
if(response) {
|
||||
let message = null;
|
||||
if(~~response === 1) {
|
||||
message = (
|
||||
'1 segment has been restored from the trash.'
|
||||
);
|
||||
} else if(~~response > 1) {
|
||||
message = (
|
||||
'%$1d segments have been restored from the trash.'
|
||||
).replace('%$1d', ~~response);
|
||||
}
|
||||
var count = ~~response;
|
||||
var message = null;
|
||||
|
||||
if(message !== null) {
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
if(count === 1) {
|
||||
message = (
|
||||
'1 segment has been restored from the trash.'
|
||||
);
|
||||
} else {
|
||||
message = (
|
||||
'%$1d segments have been restored from the trash.'
|
||||
).replace('%$1d', count);
|
||||
}
|
||||
MailPoet.Notice.success(message);
|
||||
}
|
||||
};
|
||||
|
||||
@ -105,6 +96,9 @@ const item_actions = [
|
||||
return (
|
||||
<Link to={ `/edit/${item.id}` }>Edit</Link>
|
||||
);
|
||||
},
|
||||
display: function(segment) {
|
||||
return (segment.type !== 'wp_users');
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ define(
|
||||
.done(function (response) {
|
||||
MailPoet.Modal.loading(false);
|
||||
if (response.result === false) {
|
||||
MailPoet.Notice.error(response.error);
|
||||
MailPoet.Notice.error(response.errors);
|
||||
} else {
|
||||
resultMessage = MailPoetI18n.exportMessage
|
||||
.replace('%1$s', '<strong>' + response.data.totalExported + '</strong>')
|
||||
|
@ -193,7 +193,7 @@ define(
|
||||
}).done(function (response) {
|
||||
if (response.result === false) {
|
||||
MailPoet.Notice.hide();
|
||||
MailPoet.Notice.error(response.error, {
|
||||
MailPoet.Notice.error(response.errors, {
|
||||
timeout: 3000,
|
||||
});
|
||||
jQuery('.mailpoet_mailchimp-key-status')
|
||||
@ -245,7 +245,7 @@ define(
|
||||
}
|
||||
else {
|
||||
MailPoet.Notice.hide();
|
||||
MailPoet.Notice(response.message, {
|
||||
MailPoet.Notice.error(response.errors, {
|
||||
timeout: 3000,
|
||||
});
|
||||
}
|
||||
@ -1082,7 +1082,7 @@ define(
|
||||
}).done(function (response) {
|
||||
MailPoet.Modal.loading(false);
|
||||
if (response.result === false) {
|
||||
MailPoet.Notice.error(response.error, {
|
||||
MailPoet.Notice.error(response.errors, {
|
||||
timeout: 3000,
|
||||
});
|
||||
} else {
|
||||
|
@ -313,6 +313,7 @@ const SubscriberList = React.createClass({
|
||||
</h2>
|
||||
|
||||
<Listing
|
||||
limit={ mailpoet_listing_per_page }
|
||||
location={ this.props.location }
|
||||
params={ this.props.params }
|
||||
endpoint="subscribers"
|
||||
|
144
composer.lock
generated
144
composer.lock
generated
@ -160,23 +160,23 @@
|
||||
},
|
||||
{
|
||||
"name": "mtdowling/cron-expression",
|
||||
"version": "v1.0.4",
|
||||
"version": "v1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mtdowling/cron-expression.git",
|
||||
"reference": "fd92e883195e5dfa77720b1868cf084b08be4412"
|
||||
"reference": "c9ee7886f5a12902b225a1a12f36bb45f9ab89e5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mtdowling/cron-expression/zipball/fd92e883195e5dfa77720b1868cf084b08be4412",
|
||||
"reference": "fd92e883195e5dfa77720b1868cf084b08be4412",
|
||||
"url": "https://api.github.com/repos/mtdowling/cron-expression/zipball/c9ee7886f5a12902b225a1a12f36bb45f9ab89e5",
|
||||
"reference": "c9ee7886f5a12902b225a1a12f36bb45f9ab89e5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.*"
|
||||
"phpunit/phpunit": "~4.0|~5.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@ -200,7 +200,7 @@
|
||||
"cron",
|
||||
"schedule"
|
||||
],
|
||||
"time": "2015-01-11 23:07:46"
|
||||
"time": "2016-01-26 21:23:30"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
@ -547,16 +547,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.0.1",
|
||||
"version": "v1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "49ff736bd5d41f45240cec77b44967d76e0c3d25"
|
||||
"reference": "1289d16209491b584839022f29257ad859b8532d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/49ff736bd5d41f45240cec77b44967d76e0c3d25",
|
||||
"reference": "49ff736bd5d41f45240cec77b44967d76e0c3d25",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/1289d16209491b584839022f29257ad859b8532d",
|
||||
"reference": "1289d16209491b584839022f29257ad859b8532d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -568,7 +568,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
"dev-master": "1.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@ -602,7 +602,7 @@
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2015-11-20 09:19:13"
|
||||
"time": "2016-01-20 09:13:37"
|
||||
},
|
||||
{
|
||||
"name": "symfony/translation",
|
||||
@ -722,16 +722,16 @@
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v1.23.3",
|
||||
"version": "v1.24.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "ae53fc2c312fdee63773b75cb570304f85388b08"
|
||||
"reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/ae53fc2c312fdee63773b75cb570304f85388b08",
|
||||
"reference": "ae53fc2c312fdee63773b75cb570304f85388b08",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8",
|
||||
"reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -744,7 +744,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.23-dev"
|
||||
"dev-master": "1.24-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@ -779,22 +779,22 @@
|
||||
"keywords": [
|
||||
"templating"
|
||||
],
|
||||
"time": "2016-01-11 14:02:19"
|
||||
"time": "2016-01-25 21:22:18"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "codeception/codeception",
|
||||
"version": "2.1.5",
|
||||
"version": "2.1.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Codeception/Codeception.git",
|
||||
"reference": "4ee562f421fd404139dd7b73ae46d075396a4baf"
|
||||
"reference": "b199941f5e59d1e7fd32d78296c8ab98db873d89"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/4ee562f421fd404139dd7b73ae46d075396a4baf",
|
||||
"reference": "4ee562f421fd404139dd7b73ae46d075396a4baf",
|
||||
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/b199941f5e59d1e7fd32d78296c8ab98db873d89",
|
||||
"reference": "b199941f5e59d1e7fd32d78296c8ab98db873d89",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -861,7 +861,7 @@
|
||||
"functional testing",
|
||||
"unit testing"
|
||||
],
|
||||
"time": "2015-12-20 12:11:42"
|
||||
"time": "2016-02-09 22:27:48"
|
||||
},
|
||||
{
|
||||
"name": "codeception/verify",
|
||||
@ -1328,22 +1328,24 @@
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
"version": "v1.5.0",
|
||||
"version": "v1.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpspec/prophecy.git",
|
||||
"reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7"
|
||||
"reference": "3c91bdf81797d725b14cb62906f9a4ce44235972"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7",
|
||||
"reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7",
|
||||
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972",
|
||||
"reference": "3c91bdf81797d725b14cb62906f9a4ce44235972",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/instantiator": "^1.0.2",
|
||||
"php": "^5.3|^7.0",
|
||||
"phpdocumentor/reflection-docblock": "~2.0",
|
||||
"sebastian/comparator": "~1.1"
|
||||
"sebastian/comparator": "~1.1",
|
||||
"sebastian/recursion-context": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "~2.0"
|
||||
@ -1351,7 +1353,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4.x-dev"
|
||||
"dev-master": "1.5.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@ -1384,7 +1386,7 @@
|
||||
"spy",
|
||||
"stub"
|
||||
],
|
||||
"time": "2015-08-13 10:07:40"
|
||||
"time": "2016-02-15 07:46:21"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
@ -1628,16 +1630,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "4.8.21",
|
||||
"version": "4.8.23",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "ea76b17bced0500a28098626b84eda12dbcf119c"
|
||||
"reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ea76b17bced0500a28098626b84eda12dbcf119c",
|
||||
"reference": "ea76b17bced0500a28098626b84eda12dbcf119c",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6e351261f9cd33daf205a131a1ba61c6d33bd483",
|
||||
"reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1696,7 +1698,7 @@
|
||||
"testing",
|
||||
"xunit"
|
||||
],
|
||||
"time": "2015-12-12 07:45:58"
|
||||
"time": "2016-02-11 14:56:33"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit-mock-objects",
|
||||
@ -2227,16 +2229,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/browser-kit",
|
||||
"version": "v3.0.1",
|
||||
"version": "v3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/browser-kit.git",
|
||||
"reference": "334a58c0def6dfcbe4bb57c6d2a8c06c6cc77679"
|
||||
"reference": "dde849a0485b70a24b36f826ed3fb95b904d80c3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/334a58c0def6dfcbe4bb57c6d2a8c06c6cc77679",
|
||||
"reference": "334a58c0def6dfcbe4bb57c6d2a8c06c6cc77679",
|
||||
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/dde849a0485b70a24b36f826ed3fb95b904d80c3",
|
||||
"reference": "dde849a0485b70a24b36f826ed3fb95b904d80c3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2280,7 +2282,7 @@
|
||||
],
|
||||
"description": "Symfony BrowserKit Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2015-12-26 13:39:53"
|
||||
"time": "2016-01-27 11:34:55"
|
||||
},
|
||||
{
|
||||
"name": "symfony/config",
|
||||
@ -2394,16 +2396,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/css-selector",
|
||||
"version": "v3.0.1",
|
||||
"version": "v3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/css-selector.git",
|
||||
"reference": "4613311fd46e146f506403ce2f8a0c71d402d2a3"
|
||||
"reference": "6605602690578496091ac20ec7a5cbd160d4dff4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/css-selector/zipball/4613311fd46e146f506403ce2f8a0c71d402d2a3",
|
||||
"reference": "4613311fd46e146f506403ce2f8a0c71d402d2a3",
|
||||
"url": "https://api.github.com/repos/symfony/css-selector/zipball/6605602690578496091ac20ec7a5cbd160d4dff4",
|
||||
"reference": "6605602690578496091ac20ec7a5cbd160d4dff4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2443,20 +2445,20 @@
|
||||
],
|
||||
"description": "Symfony CssSelector Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2015-12-05 17:45:07"
|
||||
"time": "2016-01-27 05:14:46"
|
||||
},
|
||||
{
|
||||
"name": "symfony/dom-crawler",
|
||||
"version": "v3.0.1",
|
||||
"version": "v3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/dom-crawler.git",
|
||||
"reference": "7c622b0c9fb8bdb146d6dfa86c5f91dcbfdbc11d"
|
||||
"reference": "b693a9650aa004576b593ff2e91ae749dc90123d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/7c622b0c9fb8bdb146d6dfa86c5f91dcbfdbc11d",
|
||||
"reference": "7c622b0c9fb8bdb146d6dfa86c5f91dcbfdbc11d",
|
||||
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/b693a9650aa004576b593ff2e91ae749dc90123d",
|
||||
"reference": "b693a9650aa004576b593ff2e91ae749dc90123d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2499,7 +2501,7 @@
|
||||
],
|
||||
"description": "Symfony DomCrawler Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2015-12-26 13:42:31"
|
||||
"time": "2016-01-25 09:56:57"
|
||||
},
|
||||
{
|
||||
"name": "symfony/event-dispatcher",
|
||||
@ -2735,16 +2737,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/intl",
|
||||
"version": "v3.0.1",
|
||||
"version": "v3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/intl.git",
|
||||
"reference": "9abd5cd590211c35cda87591f0dee856b7a16125"
|
||||
"reference": "7fa23b8f2ddd96260f0154946b69eb0f2c2ce7bc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/intl/zipball/9abd5cd590211c35cda87591f0dee856b7a16125",
|
||||
"reference": "9abd5cd590211c35cda87591f0dee856b7a16125",
|
||||
"url": "https://api.github.com/repos/symfony/intl/zipball/7fa23b8f2ddd96260f0154946b69eb0f2c2ce7bc",
|
||||
"reference": "7fa23b8f2ddd96260f0154946b69eb0f2c2ce7bc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2806,7 +2808,7 @@
|
||||
"l10n",
|
||||
"localization"
|
||||
],
|
||||
"time": "2015-12-05 11:13:14"
|
||||
"time": "2016-01-27 05:14:46"
|
||||
},
|
||||
{
|
||||
"name": "symfony/options-resolver",
|
||||
@ -2864,16 +2866,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-intl-icu",
|
||||
"version": "v1.0.1",
|
||||
"version": "v1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-intl-icu.git",
|
||||
"reference": "2deb44160e1c886241c06602b12b98779f728177"
|
||||
"reference": "66b0bb4abda229bc073eff6bbc8f2685bdaac165"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/2deb44160e1c886241c06602b12b98779f728177",
|
||||
"reference": "2deb44160e1c886241c06602b12b98779f728177",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/66b0bb4abda229bc073eff6bbc8f2685bdaac165",
|
||||
"reference": "66b0bb4abda229bc073eff6bbc8f2685bdaac165",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2883,7 +2885,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
"dev-master": "1.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@ -2915,7 +2917,7 @@
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2015-11-04 20:28:58"
|
||||
"time": "2016-01-20 09:13:37"
|
||||
},
|
||||
{
|
||||
"name": "symfony/process",
|
||||
@ -2968,16 +2970,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/property-access",
|
||||
"version": "v3.0.1",
|
||||
"version": "v3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/property-access.git",
|
||||
"reference": "9bb9f79ade13196fadd0b98504117f117d8221ad"
|
||||
"reference": "95363dbabd606e404b6c75095669993bf7ddae4b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/property-access/zipball/9bb9f79ade13196fadd0b98504117f117d8221ad",
|
||||
"reference": "9bb9f79ade13196fadd0b98504117f117d8221ad",
|
||||
"url": "https://api.github.com/repos/symfony/property-access/zipball/95363dbabd606e404b6c75095669993bf7ddae4b",
|
||||
"reference": "95363dbabd606e404b6c75095669993bf7ddae4b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -3024,7 +3026,7 @@
|
||||
"property path",
|
||||
"reflection"
|
||||
],
|
||||
"time": "2015-12-23 08:00:11"
|
||||
"time": "2016-01-03 15:35:16"
|
||||
},
|
||||
{
|
||||
"name": "symfony/routing",
|
||||
@ -3183,16 +3185,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
"version": "v3.0.1",
|
||||
"version": "v3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/yaml.git",
|
||||
"reference": "3df409958a646dad2bc5046c3fb671ee24a1a691"
|
||||
"reference": "3cf0709d7fe936e97bee9e954382e449003f1d9a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/yaml/zipball/3df409958a646dad2bc5046c3fb671ee24a1a691",
|
||||
"reference": "3df409958a646dad2bc5046c3fb671ee24a1a691",
|
||||
"url": "https://api.github.com/repos/symfony/yaml/zipball/3cf0709d7fe936e97bee9e954382e449003f1d9a",
|
||||
"reference": "3cf0709d7fe936e97bee9e954382e449003f1d9a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -3228,7 +3230,7 @@
|
||||
],
|
||||
"description": "Symfony Yaml Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2015-12-26 13:39:53"
|
||||
"time": "2016-02-02 13:44:19"
|
||||
},
|
||||
{
|
||||
"name": "twig/extensions",
|
||||
|
@ -7,12 +7,31 @@ class Hooks {
|
||||
}
|
||||
|
||||
function init() {
|
||||
$this->setupSubscribe();
|
||||
$this->setupWPUsers();
|
||||
$this->setupImageSize();
|
||||
$this->setupListing();
|
||||
}
|
||||
|
||||
function setupSubscribe() {
|
||||
$subscribe = Setting::getValue('subscribe', array());
|
||||
// Subscribe in comments
|
||||
if((bool)Setting::getValue('subscribe.on_comment.enabled')) {
|
||||
add_action(
|
||||
'comment_form_after_fields',
|
||||
'\MailPoet\Subscription\Comment::extendForm'
|
||||
);
|
||||
if(
|
||||
isset($subscribe['on_comment']['enabled'])
|
||||
&&
|
||||
(bool)$subscribe['on_comment']['enabled']
|
||||
) {
|
||||
if(is_user_logged_in()) {
|
||||
add_action(
|
||||
'comment_form_field_comment',
|
||||
'\MailPoet\Subscription\Comment::extendLoggedInForm'
|
||||
);
|
||||
} else {
|
||||
add_action(
|
||||
'comment_form_after_fields',
|
||||
'\MailPoet\Subscription\Comment::extendLoggedOutForm'
|
||||
);
|
||||
}
|
||||
|
||||
add_action(
|
||||
'comment_post',
|
||||
@ -30,7 +49,11 @@ class Hooks {
|
||||
}
|
||||
|
||||
// Subscribe in registration form
|
||||
if((bool)Setting::getValue('subscribe.on_register.enabled')) {
|
||||
if(
|
||||
isset($subscribe['on_register']['enabled'])
|
||||
&&
|
||||
(bool)$subscribe['on_register']['enabled']
|
||||
) {
|
||||
if(is_multisite()) {
|
||||
add_action(
|
||||
'signup_extra_fields',
|
||||
@ -55,7 +78,9 @@ class Hooks {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setupWPUsers() {
|
||||
// WP Users synchronization
|
||||
add_action(
|
||||
'user_register',
|
||||
@ -88,19 +113,35 @@ class Hooks {
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
function setupImageSize() {
|
||||
add_filter(
|
||||
'image_size_names_choose',
|
||||
array(
|
||||
$this,
|
||||
'appendImageSizes'
|
||||
)
|
||||
array($this, 'appendImageSize'),
|
||||
10, 1
|
||||
);
|
||||
}
|
||||
|
||||
function appendImageSizes($sizes) {
|
||||
function appendImageSize($sizes) {
|
||||
return array_merge($sizes, array(
|
||||
'mailpoet_newsletter_max' => __('MailPoet Newsletter'),
|
||||
'mailpoet_newsletter_max' => __('MailPoet Newsletter')
|
||||
));
|
||||
}
|
||||
|
||||
function setupListing() {
|
||||
add_filter(
|
||||
'set-screen-option',
|
||||
array($this, 'setScreenOption'),
|
||||
10, 3
|
||||
);
|
||||
}
|
||||
|
||||
function setScreenOption($status, $option, $value) {
|
||||
if(preg_match('/^mailpoet_(.*)_per_page$/', $option)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Initializer {
|
||||
register_activation_hook(Env::$file, array($this, 'runMigrator'));
|
||||
register_activation_hook(Env::$file, array($this, 'runPopulator'));
|
||||
|
||||
add_action('init', array($this, 'setup'));
|
||||
add_action('plugins_loaded', array($this, 'setup'));
|
||||
add_action('widgets_init', array($this, 'setupWidget'));
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ class Initializer {
|
||||
\ORM::configure('username', Env::$db_username);
|
||||
\ORM::configure('password', Env::$db_password);
|
||||
\ORM::configure('logging', WP_DEBUG);
|
||||
|
||||
\ORM::configure('driver_options', array(
|
||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET TIME_ZONE = "+00:00"'
|
||||
@ -66,8 +67,6 @@ class Initializer {
|
||||
$newsletters = Env::$db_prefix . 'newsletters';
|
||||
$newsletter_templates = Env::$db_prefix . 'newsletter_templates';
|
||||
$segments = Env::$db_prefix . 'segments';
|
||||
$filters = Env::$db_prefix . 'filters';
|
||||
$segment_filter = Env::$db_prefix . 'segment_filter';
|
||||
$forms = Env::$db_prefix . 'forms';
|
||||
$subscriber_segment = Env::$db_prefix . 'subscriber_segment';
|
||||
$newsletter_segment = Env::$db_prefix . 'newsletter_segment';
|
||||
@ -82,8 +81,6 @@ class Initializer {
|
||||
define('MP_SETTINGS_TABLE', $settings);
|
||||
define('MP_NEWSLETTERS_TABLE', $newsletters);
|
||||
define('MP_SEGMENTS_TABLE', $segments);
|
||||
define('MP_FILTERS_TABLE', $filters);
|
||||
define('MP_SEGMENT_FILTER_TABLE', $segment_filter);
|
||||
define('MP_FORMS_TABLE', $forms);
|
||||
define('MP_SUBSCRIBER_SEGMENT_TABLE', $subscriber_segment);
|
||||
define('MP_NEWSLETTER_TEMPLATES_TABLE', $newsletter_templates);
|
||||
|
@ -11,8 +11,7 @@ class Localizer {
|
||||
function init() {
|
||||
add_action(
|
||||
'init',
|
||||
array($this, 'setup'),
|
||||
0
|
||||
array($this, 'setup')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ use MailPoet\Settings\Pages;
|
||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
||||
use MailPoet\Util\DKIM;
|
||||
use MailPoet\Util\Permissions;
|
||||
use MailPoet\Listing;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -67,7 +68,7 @@ class Menu {
|
||||
'forms'
|
||||
)
|
||||
);
|
||||
add_submenu_page(
|
||||
$subscribers_page = add_submenu_page(
|
||||
'mailpoet',
|
||||
__('Subscribers'),
|
||||
__('Subscribers'),
|
||||
@ -78,6 +79,17 @@ class Menu {
|
||||
'subscribers'
|
||||
)
|
||||
);
|
||||
// add limit per page to screen options
|
||||
add_action('load-'.$subscribers_page, function() {
|
||||
add_screen_option('per_page', array(
|
||||
'label' => _x(
|
||||
'Number of subscribers per page',
|
||||
'subscribers per page (screen options)'
|
||||
),
|
||||
'option' => 'mailpoet_subscribers_per_page'
|
||||
));
|
||||
});
|
||||
|
||||
add_submenu_page(
|
||||
'mailpoet',
|
||||
__('Segments'),
|
||||
@ -305,6 +317,14 @@ class Menu {
|
||||
function subscribers() {
|
||||
$data = array();
|
||||
|
||||
// listing: limit per page
|
||||
$listing_per_page = get_user_meta(
|
||||
get_current_user_id(), 'mailpoet_subscribers_per_page', true
|
||||
);
|
||||
$data['per_page'] = (!empty($listing_per_page))
|
||||
? (int)$listing_per_page
|
||||
: Listing\Handler::DEFAULT_LIMIT_PER_PAGE;
|
||||
|
||||
$data['segments'] = Segment::findArray();
|
||||
|
||||
$data['custom_fields'] = array_map(function($field) {
|
||||
|
@ -236,10 +236,7 @@ class Migrator {
|
||||
'newsletter_id mediumint(9) NOT NULL,',
|
||||
'subscriber_id mediumint(9) NOT NULL,',
|
||||
'queue_id mediumint(9) NOT NULL,',
|
||||
'sent_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,',
|
||||
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
|
||||
'sent_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'PRIMARY KEY (id)',
|
||||
);
|
||||
return $this->sqlify(__FUNCTION__, $attributes);
|
||||
|
@ -68,7 +68,7 @@ class FranksRoastHouseTemplate {
|
||||
"link" => "http://www.example.com",
|
||||
"src" => $this->template_image_url . "/header-v2.jpg",
|
||||
"alt" => __("Frank's Roast House"),
|
||||
"padded" => false,
|
||||
"fullWidth" => true,
|
||||
"width" => "600px",
|
||||
"height" => "220px",
|
||||
"styles" => array(
|
||||
@ -95,7 +95,7 @@ class FranksRoastHouseTemplate {
|
||||
"link" => "http://example.org",
|
||||
"src" => $this->template_image_url . "/coffee-grain.jpg",
|
||||
"alt" => __("coffee-grain-3-1329675-1599x941"),
|
||||
"padded" => true,
|
||||
"fullWidth" => false,
|
||||
"width" => "1599px",
|
||||
"height" => "777px",
|
||||
"styles" => array(
|
||||
@ -139,7 +139,7 @@ class FranksRoastHouseTemplate {
|
||||
"link" => "http://example.org",
|
||||
"src" => $this->template_image_url . "/sandwich.jpg",
|
||||
"alt" => "sandwich",
|
||||
"padded" => true,
|
||||
"fullWidth" => false,
|
||||
"width" => "640px",
|
||||
"height" => "344px",
|
||||
"styles" => array(
|
||||
@ -168,6 +168,7 @@ class FranksRoastHouseTemplate {
|
||||
"fontColor" => "#ffffff",
|
||||
"fontFamily" => "Arial",
|
||||
"fontSize" => "14px",
|
||||
"fontWeight" => "normal",
|
||||
"textAlign" => "center"
|
||||
)
|
||||
)
|
||||
@ -238,7 +239,7 @@ class FranksRoastHouseTemplate {
|
||||
"link" => "http://example.org",
|
||||
"src" => $this->template_image_url . "/map-v2.jpg",
|
||||
"alt" => __("map-v2"),
|
||||
"padded" => true,
|
||||
"fullWidth" => false,
|
||||
"width" => "636px",
|
||||
"height" => "342px",
|
||||
"styles" => array(
|
||||
|
@ -90,7 +90,7 @@ class PostNotificationsBlankTemplate {
|
||||
"link" => "http://example.org",
|
||||
"src" => $this->template_image_url . "/ALC-widget-icon.png",
|
||||
"alt" => __("ALC-widget-icon"),
|
||||
"padded" => true,
|
||||
"fullWidth" => false,
|
||||
"width" => "200px",
|
||||
"height" => "134px",
|
||||
"styles" => array(
|
||||
@ -325,6 +325,7 @@ class PostNotificationsBlankTemplate {
|
||||
"fontColor" => "#ffffff",
|
||||
"fontFamily" => "Arial",
|
||||
"fontSize" => "18px",
|
||||
"fontWeight" => "normal",
|
||||
"textAlign" => "center"
|
||||
)
|
||||
)
|
||||
|
@ -68,7 +68,7 @@ class WelcomeTemplate {
|
||||
"link" => "http://example.org",
|
||||
"src" => $this->template_image_url . "/logo-header.gif",
|
||||
"alt" => "logo-header",
|
||||
"padded" => true,
|
||||
"fullWidth" => false,
|
||||
"width" => "233px",
|
||||
"height" => "118px",
|
||||
"styles" => array(
|
||||
|
@ -7,8 +7,9 @@ use MailPoet\Util\Security;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class CronHelper {
|
||||
static $daemon_execution_limit = 30;
|
||||
static $daemon_timeout_limit = 30;
|
||||
const daemon_execution_limit = 20;
|
||||
const daemon_execution_timeout = 35;
|
||||
const daemon_request_timeout = 2;
|
||||
|
||||
static function createDaemon($token) {
|
||||
$daemon = array(
|
||||
@ -36,12 +37,12 @@ class CronHelper {
|
||||
return Security::generateRandomString();
|
||||
}
|
||||
|
||||
static function accessDaemon($token) {
|
||||
static function accessDaemon($token, $timeout = self::daemon_request_timeout) {
|
||||
$payload = serialize(array('token' => $token));
|
||||
$url = '/?mailpoet-api§ion=queue&action=run&request_payload=' .
|
||||
base64_encode($payload);
|
||||
$args = array(
|
||||
'timeout' => 1,
|
||||
'timeout' => $timeout,
|
||||
'user-agent' => 'MailPoet (www.mailpoet.com) Cron'
|
||||
);
|
||||
$result = wp_remote_get(
|
||||
|
@ -11,6 +11,7 @@ class Daemon {
|
||||
public $daemon;
|
||||
public $request_payload;
|
||||
public $refreshed_token;
|
||||
const daemon_request_timeout = 5;
|
||||
private $timer;
|
||||
|
||||
function __construct($request_payload = array()) {
|
||||
@ -36,11 +37,11 @@ class Daemon {
|
||||
try {
|
||||
$sending_queue = new SendingQueue($this->timer);
|
||||
$sending_queue->process();
|
||||
} catch(Exception $e) {
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
$elapsed_time = microtime(true) - $this->timer;
|
||||
if($elapsed_time < CronHelper::$daemon_execution_limit) {
|
||||
sleep(CronHelper::$daemon_execution_limit - $elapsed_time);
|
||||
if($elapsed_time < CronHelper::daemon_execution_limit) {
|
||||
sleep(CronHelper::daemon_execution_limit - $elapsed_time);
|
||||
}
|
||||
// after each execution, re-read daemon data in case it was deleted or
|
||||
// its status has changed
|
||||
@ -72,7 +73,7 @@ class Daemon {
|
||||
}
|
||||
|
||||
function callSelf() {
|
||||
CronHelper::accessDaemon($this->token);
|
||||
CronHelper::accessDaemon($this->token, self::daemon_request_timeout);
|
||||
exit;
|
||||
}
|
||||
}
|
@ -31,13 +31,13 @@ class Supervisor {
|
||||
$elapsed_time = time() - (int) $daemon['updated_at'];
|
||||
// if it's been less than 40 seconds since last execution and we're not
|
||||
// force-running the daemon, return its status and do nothing
|
||||
if($elapsed_time < CronHelper::$daemon_timeout_limit && !$this->force_run) {
|
||||
if($elapsed_time < CronHelper::daemon_execution_timeout && !$this->force_run) {
|
||||
return $this->formatDaemonStatusMessage($daemon['status']);
|
||||
}
|
||||
// if it's been less than 40 seconds since last execution, we are
|
||||
// force-running the daemon and it's either being started or stopped,
|
||||
// return its status and do nothing
|
||||
elseif($elapsed_time < CronHelper::$daemon_timeout_limit &&
|
||||
elseif($elapsed_time < CronHelper::daemon_execution_timeout &&
|
||||
$this->force_run &&
|
||||
in_array($daemon['status'], array(
|
||||
'stopping',
|
||||
|
@ -5,125 +5,186 @@ use MailPoet\Cron\CronHelper;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\NewsletterStatistics;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Newsletter\Renderer\Renderer;
|
||||
use MailPoet\Newsletter\Shortcodes\Shortcodes;
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class SendingQueue {
|
||||
public $mta_config;
|
||||
public $mta_log;
|
||||
public $processing_method;
|
||||
private $timer;
|
||||
const batch_size = 50;
|
||||
|
||||
function __construct($timer = false) {
|
||||
$this->mta_config = $this->getMailerConfig();
|
||||
$this->mta_log = $this->getMailerLog();
|
||||
$this->processing_method = ($this->mta_config['method'] === 'MailPoet') ?
|
||||
'processBulkSubscribers' :
|
||||
'processIndividualSubscriber';
|
||||
$this->timer = ($timer) ? $timer : microtime(true);
|
||||
}
|
||||
|
||||
function process() {
|
||||
// TODO: implement mailer sending frequency limits
|
||||
foreach($this->getQueues() as $queue) {
|
||||
$newsletter = Newsletter::findOne($queue->newsletter_id);
|
||||
if(!$newsletter) {
|
||||
continue;
|
||||
};
|
||||
}
|
||||
$queue->subscribers = (object) unserialize($queue->subscribers);
|
||||
if(!isset($queue->subscribers->processed)) {
|
||||
$queue->subscribers->processed = array();
|
||||
}
|
||||
if(!isset($queue->subscribers->failed)) {
|
||||
$queue->subscribers->failed = array();
|
||||
}
|
||||
$newsletter = $newsletter->asArray();
|
||||
$mailer = $this->configureMailerForNewsletter($newsletter);
|
||||
$subscribers = json_decode($queue->subscribers, true);
|
||||
$subscribers_to_process = $subscribers['to_process'];
|
||||
if(!isset($subscribers['processed'])) $subscribers['processed'] = array();
|
||||
if(!isset($subscribers['failed'])) $subscribers['failed'] = array();
|
||||
foreach(array_chunk($subscribers_to_process, 200) as $subscriber_ids) {
|
||||
$db_subscribers = Subscriber::whereIn('id', $subscriber_ids)
|
||||
$newsletter['body'] = $this->renderNewsletter($newsletter);
|
||||
$mailer = $this->configureMailer($newsletter);
|
||||
foreach(array_chunk($queue->subscribers->to_process, self::batch_size) as
|
||||
$subscribers_ids) {
|
||||
$subscribers = Subscriber::whereIn('id', $subscribers_ids)
|
||||
->findArray();
|
||||
foreach($db_subscribers as $db_subscriber) {
|
||||
$this->checkExecutionTimer();
|
||||
$result = $this->sendNewsletter(
|
||||
$queue->subscribers = call_user_func_array(
|
||||
array(
|
||||
$this,
|
||||
$this->processing_method
|
||||
),
|
||||
array(
|
||||
$mailer,
|
||||
$this->processNewsletter($newsletter, $db_subscriber),
|
||||
$db_subscriber);
|
||||
if($result) {
|
||||
$this->updateStatistics($newsletter['id'], $db_subscriber['id'], $queue->id);
|
||||
$subscribers['processed'][] = $db_subscriber['id'];
|
||||
} else {
|
||||
$subscribers['failed'][] = $db_subscriber['id'];
|
||||
}
|
||||
$this->updateQueue($queue, $subscribers);
|
||||
}
|
||||
$newsletter,
|
||||
$subscribers,
|
||||
$queue
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processNewsletter($newsletter, $subscriber) {
|
||||
$rendered_newsletter = $this->renderNewsletter($newsletter);
|
||||
$shortcodes = new Shortcodes($rendered_newsletter['body']['html'], $newsletter, $subscriber);
|
||||
$processed_newsletter['body']['html'] = $shortcodes->replace();
|
||||
$shortcodes = new Shortcodes($rendered_newsletter['body']['text'], $newsletter, $subscriber);
|
||||
$processed_newsletter['body']['text'] = $shortcodes->replace();
|
||||
$processed_newsletter['subject'] = $rendered_newsletter['subject'];
|
||||
return $processed_newsletter;
|
||||
function processBulkSubscribers($mailer, $newsletter, $subscribers, $queue) {
|
||||
foreach($subscribers as $subscriber) {
|
||||
$processed_newsletters[] =
|
||||
$this->processNewsletter($newsletter, $subscriber);
|
||||
$transformed_subscribers[] =
|
||||
$mailer->transformSubscriber($subscriber);
|
||||
}
|
||||
$result = $this->sendNewsletter(
|
||||
$mailer,
|
||||
$processed_newsletters,
|
||||
$transformed_subscribers
|
||||
);
|
||||
$subscribers_ids = Helpers::arrayColumn($subscribers, 'id');
|
||||
if(!$result) {
|
||||
$queue->subscribers->failed = array_merge(
|
||||
$queue->subscribers->failed,
|
||||
$subscribers_ids
|
||||
);
|
||||
} else {
|
||||
$newsletter_statistics =
|
||||
array_map(function ($data) use ($newsletter, $subscribers_ids, $queue) {
|
||||
return array(
|
||||
$newsletter['id'],
|
||||
$subscribers_ids[$data],
|
||||
$queue->id
|
||||
);
|
||||
}, range(0, count($transformed_subscribers) - 1));
|
||||
$newsletter_statistics = Helpers::flattenArray($newsletter_statistics);
|
||||
$this->updateMailerLog();
|
||||
$this->updateNewsletterStatistics($newsletter_statistics);
|
||||
$queue->subscribers->processed = array_merge(
|
||||
$queue->subscribers->processed,
|
||||
$subscribers_ids
|
||||
);
|
||||
}
|
||||
$this->updateQueue($queue);
|
||||
$this->checkSendingLimit();
|
||||
$this->checkExecutionTimer();
|
||||
return $queue->subscribers;
|
||||
}
|
||||
|
||||
function processIndividualSubscriber($mailer, $newsletter, $subscribers, $queue) {
|
||||
foreach($subscribers as $subscriber) {
|
||||
$this->checkSendingLimit();
|
||||
$processed_newsletter = $this->processNewsletter($newsletter, $subscriber);
|
||||
$transformed_subscriber = $mailer->transformSubscriber($subscriber);
|
||||
$result = $this->sendNewsletter(
|
||||
$mailer,
|
||||
$processed_newsletter,
|
||||
$transformed_subscriber
|
||||
);
|
||||
if(!$result) {
|
||||
$queue->subscribers->failed[] = $subscriber['id'];;
|
||||
} else {
|
||||
$queue->subscribers->processed[] = $subscriber['id'];
|
||||
$newsletter_statistics = array(
|
||||
$newsletter['id'],
|
||||
$subscriber['id'],
|
||||
$queue->id
|
||||
);
|
||||
$this->updateMailerLog();
|
||||
$this->updateNewsletterStatistics($newsletter_statistics);
|
||||
}
|
||||
$this->updateQueue($queue);
|
||||
$this->checkExecutionTimer();
|
||||
}
|
||||
return $queue->subscribers;
|
||||
}
|
||||
|
||||
function updateNewsletterStatistics($data) {
|
||||
return NewsletterStatistics::createMultiple($data);
|
||||
}
|
||||
|
||||
function renderNewsletter($newsletter) {
|
||||
$renderer = new Renderer($newsletter);
|
||||
return $renderer->render();
|
||||
}
|
||||
|
||||
function processNewsletter($newsletter, $subscriber = false) {
|
||||
$divider = '***MailPoet***';
|
||||
$shortcodes = new Shortcodes(
|
||||
implode($divider, $newsletter['body']),
|
||||
$newsletter,
|
||||
$subscriber
|
||||
);
|
||||
list($newsletter['body']['html'], $newsletter['body']['text']) =
|
||||
explode($divider, $shortcodes->replace());
|
||||
return $newsletter;
|
||||
}
|
||||
|
||||
function sendNewsletter($mailer, $newsletter, $subscriber) {
|
||||
return $mailer->mailer_instance->send(
|
||||
$newsletter,
|
||||
$mailer->transformSubscriber($subscriber)
|
||||
$subscriber
|
||||
);
|
||||
}
|
||||
|
||||
function updateStatistics($newsletter_id, $subscriber_id, $queue_id) {
|
||||
$newsletter_statistic = NewsletterStatistics::create();
|
||||
$newsletter_statistic->subscriber_id = $newsletter_id;
|
||||
$newsletter_statistic->newsletter_id = $subscriber_id;
|
||||
$newsletter_statistic->queue_id = $queue_id;
|
||||
$newsletter_statistic->save();
|
||||
}
|
||||
|
||||
function updateQueue($queue, $subscribers) {
|
||||
$subscribers['to_process'] = array_values(
|
||||
array_diff(
|
||||
$subscribers['to_process'],
|
||||
array_merge($subscribers['processed'], $subscribers['failed'])
|
||||
)
|
||||
);
|
||||
$queue->count_processed =
|
||||
count($subscribers['processed']) + count($subscribers['failed']);
|
||||
$queue->count_to_process = count($subscribers['to_process']);
|
||||
$queue->count_failed = count($subscribers['failed']);
|
||||
$queue->count_total =
|
||||
$queue->count_processed + $queue->count_to_process;
|
||||
if(!$queue->count_to_process) {
|
||||
$queue->processed_at = date('Y-m-d H:i:s');
|
||||
$queue->status = 'completed';
|
||||
}
|
||||
$queue->subscribers = json_encode($subscribers);
|
||||
$queue->save();
|
||||
}
|
||||
|
||||
function configureMailerForNewsletter($newsletter) {
|
||||
if(!empty($newsletter['sender_address']) && !empty($newsletter['sender_name'])) {
|
||||
$sender = array(
|
||||
'name' => $newsletter['sender_name'],
|
||||
'address' => $newsletter['sender_address']
|
||||
);
|
||||
} else {
|
||||
function configureMailer($newsletter) {
|
||||
$sender['address'] = (!empty($newsletter['sender_address'])) ?
|
||||
$newsletter['sender_address'] :
|
||||
false;
|
||||
$sender['name'] = (!empty($newsletter['sender_name'])) ?
|
||||
$newsletter['sender_name'] :
|
||||
false;
|
||||
$reply_to['address'] = (!empty($newsletter['reply_to_address'])) ?
|
||||
$newsletter['reply_to_address'] :
|
||||
false;
|
||||
$reply_to['name'] = (!empty($newsletter['reply_to_name'])) ?
|
||||
$newsletter['reply_to_name'] :
|
||||
false;
|
||||
if(!$sender['address']) {
|
||||
$sender = false;
|
||||
}
|
||||
if(!empty($newsletter['reply_to_address']) && !empty($newsletter['reply_to_name'])) {
|
||||
$reply_to = array(
|
||||
'name' => $newsletter['reply_to_name'],
|
||||
'address' => $newsletter['reply_to_address']
|
||||
);
|
||||
} else {
|
||||
if(!$reply_to['address']) {
|
||||
$reply_to = false;
|
||||
}
|
||||
$mailer = new Mailer($method = false, $sender, $reply_to);
|
||||
return $mailer;
|
||||
}
|
||||
|
||||
function checkExecutionTimer() {
|
||||
$elapsed_time = microtime(true) - $this->timer;
|
||||
if($elapsed_time >= CronHelper::$daemon_execution_limit) throw new \Exception(__('Maximum execution time reached.'));
|
||||
}
|
||||
|
||||
function getQueues() {
|
||||
return \MailPoet\Models\SendingQueue::orderByDesc('priority')
|
||||
->whereNull('deleted_at')
|
||||
@ -131,9 +192,78 @@ class SendingQueue {
|
||||
->findResultSet();
|
||||
}
|
||||
|
||||
function renderNewsletter($newsletter) {
|
||||
$renderer = new Renderer($newsletter);
|
||||
$newsletter['body'] = $renderer->render();
|
||||
return $newsletter;
|
||||
function updateQueue($queue) {
|
||||
$queue = clone($queue);
|
||||
$queue->subscribers->to_process = array_diff(
|
||||
$queue->subscribers->to_process,
|
||||
array_merge(
|
||||
$queue->subscribers->processed,
|
||||
$queue->subscribers->failed
|
||||
)
|
||||
);
|
||||
$queue->subscribers->to_process = array_values($queue->subscribers->to_process);
|
||||
$queue->count_processed =
|
||||
count($queue->subscribers->processed) + count($queue->subscribers->failed);
|
||||
$queue->count_to_process = count($queue->subscribers->to_process);
|
||||
$queue->count_failed = count($queue->subscribers->failed);
|
||||
$queue->count_total =
|
||||
$queue->count_processed + $queue->count_to_process;
|
||||
if(!$queue->count_to_process) {
|
||||
$queue->processed_at = date('Y-m-d H:i:s');
|
||||
$queue->status = 'completed';
|
||||
}
|
||||
$queue->subscribers = serialize((array) $queue->subscribers);
|
||||
$queue->save();
|
||||
}
|
||||
|
||||
function updateMailerLog() {
|
||||
$this->mta_log['sent']++;
|
||||
return Setting::setValue('mta_log', $this->mta_log);
|
||||
}
|
||||
|
||||
function getMailerConfig() {
|
||||
$mta_config = Setting::getValue('mta');
|
||||
if(!$mta_config) {
|
||||
throw new \Exception(__('Mailer is not configured.'));
|
||||
}
|
||||
return $mta_config;
|
||||
}
|
||||
|
||||
function getMailerLog() {
|
||||
$mta_log = Setting::getValue('mta_log');
|
||||
if(!$mta_log) {
|
||||
$mta_log = array(
|
||||
'sent' => 0,
|
||||
'started' => time()
|
||||
);
|
||||
Setting::setValue('mta_log', $mta_log);
|
||||
}
|
||||
return $mta_log;
|
||||
}
|
||||
|
||||
function checkSendingLimit() {
|
||||
$frequency_interval = (int) $this->mta_config['frequency']['interval'] * 60;
|
||||
$frequency_limit = (int) $this->mta_config['frequency']['emails'];
|
||||
$elapsed_time = time() - (int) $this->mta_log['started'];
|
||||
if($this->mta_log['sent'] === $frequency_limit &&
|
||||
$elapsed_time <= $frequency_interval
|
||||
) {
|
||||
throw new \Exception(__('Sending frequency limit reached.'));
|
||||
}
|
||||
if($elapsed_time > $frequency_interval) {
|
||||
$this->mta_log = array(
|
||||
'sent' => 0,
|
||||
'started' => time()
|
||||
);
|
||||
Setting::setValue('mta_log', $this->mta_log);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function checkExecutionTimer() {
|
||||
$elapsed_time = microtime(true) - $this->timer;
|
||||
if($elapsed_time >= CronHelper::daemon_execution_limit) {
|
||||
throw new \Exception(__('Maximum execution time reached.'));
|
||||
}
|
||||
}
|
||||
}
|
@ -13,9 +13,11 @@ class Renderer {
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function renderStyles($form = array()) {
|
||||
static function renderStyles($form = array(), $prefix = null) {
|
||||
$styles = new Util\Styles(static::getStyles($form));
|
||||
|
||||
$html = '<style type="text/css">';
|
||||
$html .= static::getStyles($form);
|
||||
$html .= $styles->render($prefix);
|
||||
$html .= '</style>';
|
||||
|
||||
return $html;
|
||||
|
@ -101,7 +101,7 @@ EOL;
|
||||
}
|
||||
|
||||
private function stripComments($stylesheet) {
|
||||
// remove comments
|
||||
// remove comments
|
||||
return preg_replace('!/\*.*?\*/!s', '', $stylesheet);
|
||||
}
|
||||
|
||||
@ -111,7 +111,6 @@ EOL;
|
||||
|
||||
private function setStyles($styles) {
|
||||
$this->_styles = $styles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -154,12 +154,14 @@ class Widget extends \WP_Widget {
|
||||
$output = '';
|
||||
|
||||
if(!empty($body)) {
|
||||
$form_id = $this->id_base.'_'.$this->number;
|
||||
|
||||
$data = array(
|
||||
'form_id' => $this->id_base.'_'.$this->number,
|
||||
'form_id' => $form_id,
|
||||
'form_type' => $form_type,
|
||||
'form' => $form,
|
||||
'title' => $title,
|
||||
'styles' => FormRenderer::renderStyles($form),
|
||||
'styles' => FormRenderer::renderStyles($form, '#'.$form_id),
|
||||
'html' => FormRenderer::renderHTML($form),
|
||||
'before_widget' => (!empty($before_widget) ? $before_widget : ''),
|
||||
'after_widget' => (!empty($after_widget) ? $after_widget : ''),
|
||||
|
@ -4,6 +4,8 @@ namespace MailPoet\Listing;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Handler {
|
||||
const DEFAULT_LIMIT_PER_PAGE = 20;
|
||||
|
||||
private $data = array();
|
||||
private $model = null;
|
||||
|
||||
@ -14,7 +16,10 @@ class Handler {
|
||||
$this->data = array(
|
||||
// pagination
|
||||
'offset' => (isset($data['offset']) ? (int)$data['offset'] : 0),
|
||||
'limit' => (isset($data['limit']) ? (int)$data['limit'] : 50),
|
||||
'limit' => (isset($data['limit'])
|
||||
? (int)$data['limit']
|
||||
: self::DEFAULT_LIMIT_PER_PAGE
|
||||
),
|
||||
// searching
|
||||
'search' => (isset($data['search']) ? $data['search'] : null),
|
||||
// sorting
|
||||
|
@ -102,7 +102,7 @@ class Mailer {
|
||||
function getSender($sender = false) {
|
||||
if(!$sender) {
|
||||
$sender = Setting::getValue('sender', null);
|
||||
if(!$sender) throw new \Exception(__('Sender name and email are not configured.'));
|
||||
if(!$sender['address']) throw new \Exception(__('Sender name and email are not configured.'));
|
||||
}
|
||||
return array(
|
||||
'from_name' => $sender['name'],
|
||||
|
@ -20,11 +20,9 @@ class CustomField extends Model {
|
||||
$model = parent::asArray();
|
||||
|
||||
if(isset($model['params'])) {
|
||||
$model['params'] = (
|
||||
is_array($this->params)
|
||||
$model['params'] = (is_array($this->params))
|
||||
? $this->params
|
||||
: unserialize($this->params)
|
||||
);
|
||||
: unserialize($this->params);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?php namespace MailPoet\Models;
|
||||
|
||||
class CustomValidator {
|
||||
function __construct() {
|
||||
$this->validator = new \Sudzy\Engine();
|
||||
}
|
||||
|
||||
function init() {
|
||||
$this->validator
|
||||
->addValidator('isString', function ($val) {
|
||||
return is_string($val);
|
||||
});
|
||||
|
||||
return $this->validator;
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Filter extends Model {
|
||||
static $_table = MP_FILTERS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('name', array(
|
||||
'required' => __('You need to specify a name.')
|
||||
));
|
||||
}
|
||||
|
||||
function delete() {
|
||||
// delete all relations to subscribers
|
||||
SegmentFilter::where('filter_id', $this->id)->deleteMany();
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
function segments() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__.'\Segment',
|
||||
__NAMESPACE__.'\SegmentFilter',
|
||||
'filter_id',
|
||||
'segment_id'
|
||||
);
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = array()) {
|
||||
$filter = false;
|
||||
|
||||
if(isset($data['id']) && (int)$data['id'] > 0) {
|
||||
$filter = self::findOne((int)$data['id']);
|
||||
}
|
||||
|
||||
if($filter === false) {
|
||||
$filter = self::create();
|
||||
$filter->hydrate($data);
|
||||
} else {
|
||||
unset($data['id']);
|
||||
$filter->set($data);
|
||||
}
|
||||
|
||||
$filter->save();
|
||||
return $filter;
|
||||
}
|
||||
}
|
@ -17,36 +17,30 @@ class Form extends Model {
|
||||
function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
$model['body'] = (
|
||||
is_serialized($this->body)
|
||||
$model['body'] = (is_serialized($this->body))
|
||||
? unserialize($this->body)
|
||||
: $this->body
|
||||
);
|
||||
$model['settings'] = (
|
||||
is_serialized($this->settings)
|
||||
: $this->body;
|
||||
$model['settings'] = (is_serialized($this->settings))
|
||||
? unserialize($this->settings)
|
||||
: $this->settings
|
||||
);
|
||||
: $this->settings;
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
function save() {
|
||||
$this->set('body', (
|
||||
is_serialized($this->body)
|
||||
$this->set('body', (is_serialized($this->body))
|
||||
? $this->body
|
||||
: serialize($this->body)
|
||||
));
|
||||
$this->set('settings', (
|
||||
is_serialized($this->settings)
|
||||
);
|
||||
$this->set('settings', (is_serialized($this->settings))
|
||||
? $this->settings
|
||||
: serialize($this->settings)
|
||||
));
|
||||
);
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
return $orm->where_like('name', '%'.$search.'%');
|
||||
return $orm->whereLike('name', '%'.$search.'%');
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
@ -67,9 +61,8 @@ class Form extends Model {
|
||||
static function groupBy($orm, $group = null) {
|
||||
if($group === 'trash') {
|
||||
return $orm->whereNotNull('deleted_at');
|
||||
} else {
|
||||
$orm = $orm->whereNull('deleted_at');
|
||||
}
|
||||
return $orm->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = array()) {
|
||||
@ -87,7 +80,6 @@ class Form extends Model {
|
||||
$form->set($data);
|
||||
}
|
||||
|
||||
$form->save();
|
||||
return $form;
|
||||
return $form->save();
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ class Model extends \Sudzy\ValidModel {
|
||||
|
||||
function __construct() {
|
||||
$this->_errors = array();
|
||||
$customValidators = new CustomValidator();
|
||||
parent::__construct($customValidators->init());
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
static function create() {
|
||||
@ -42,7 +41,24 @@ class Model extends \Sudzy\ValidModel {
|
||||
} catch(\Sudzy\ValidationException $e) {
|
||||
$this->setError($e->getValidationErrors());
|
||||
} catch(\PDOException $e) {
|
||||
$this->setError($e->getMessage());
|
||||
switch($e->getCode()) {
|
||||
case 23000:
|
||||
preg_match("/for key \'(.*?)\'/i", $e->getMessage(), $matches);
|
||||
if(isset($matches[1])) {
|
||||
$column = $matches[1];
|
||||
$this->setError(
|
||||
sprintf(
|
||||
__('Another record already exists. Please specify a different "%1$s".'),
|
||||
$column
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->setError($e->getMessage());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->setError($e->getMessage());
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
$this->setError($e->getMessage());
|
||||
}
|
||||
@ -54,19 +70,23 @@ class Model extends \Sudzy\ValidModel {
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
$models = $orm->findResultSet();
|
||||
$models->set_expr('deleted_at', 'NOW()')->save();
|
||||
return $models->count();
|
||||
$model = get_called_class();
|
||||
return self::bulkAction($orm, function($ids) use($model) {
|
||||
self::rawExecute(join(' ', array(
|
||||
'UPDATE `'.$model::$_table.'`',
|
||||
'SET `deleted_at`=NOW()',
|
||||
'WHERE `id` IN ('.rtrim(str_repeat('?,', count($ids)), ',').')'
|
||||
)),
|
||||
$ids
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
$models = $orm->findMany();
|
||||
$count = 0;
|
||||
foreach($models as $model) {
|
||||
$model->delete();
|
||||
$count++;
|
||||
}
|
||||
return $count;
|
||||
$model = get_called_class();
|
||||
return self::bulkAction($orm, function($ids) use($model) {
|
||||
$model::whereIn('id', $ids)->deleteMany();
|
||||
});
|
||||
}
|
||||
|
||||
function restore() {
|
||||
@ -74,9 +94,37 @@ class Model extends \Sudzy\ValidModel {
|
||||
}
|
||||
|
||||
static function bulkRestore($orm) {
|
||||
$models = $orm->findResultSet();
|
||||
$models->set_expr('deleted_at', 'NULL')->save();
|
||||
return $models->count();
|
||||
$model = get_called_class();
|
||||
return self::bulkAction($orm, function($ids) use($model) {
|
||||
self::rawExecute(join(' ', array(
|
||||
'UPDATE `'.$model::$_table.'`',
|
||||
'SET `deleted_at`=NULL',
|
||||
'WHERE `id` IN ('.rtrim(str_repeat('?,', count($ids)), ',').')'
|
||||
)),
|
||||
$ids
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
static function bulkAction($orm, $callback = false) {
|
||||
$total = $orm->count();
|
||||
|
||||
if($total > 0) {
|
||||
$models = $orm->select('id')
|
||||
->offset(null)
|
||||
->limit(null)
|
||||
->findArray();
|
||||
|
||||
$ids = array_map(function($model) {
|
||||
return (int)$model['id'];
|
||||
}, $models);
|
||||
|
||||
if(is_callable($callback)) {
|
||||
$callback($ids);
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
function duplicate($data = array()) {
|
||||
|
@ -97,14 +97,13 @@ class Newsletter extends Model {
|
||||
}
|
||||
|
||||
static function filterBy($orm, $filters = null) {
|
||||
if(empty($filters)) {
|
||||
return $orm;
|
||||
}
|
||||
foreach($filters as $key => $value) {
|
||||
if($key === 'segment') {
|
||||
$segment = Segment::findOne($value);
|
||||
if($segment !== false) {
|
||||
$orm = $segment->newsletters();
|
||||
if(!empty($filters)) {
|
||||
foreach($filters as $key => $value) {
|
||||
if($key === 'segment') {
|
||||
$segment = Segment::findOne($value);
|
||||
if($segment !== false) {
|
||||
$orm = $segment->newsletters();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,16 @@ class NewsletterStatistics extends Model {
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
static function createMultiple($data) {
|
||||
return self::rawExecute(
|
||||
'INSERT INTO `' . NewsletterStatistics::$_table . '` ' .
|
||||
'(newsletter_id, subscriber_id, queue_id) ' .
|
||||
'VALUES ' . rtrim(
|
||||
str_repeat('(?,?,?), ', count($data)/3),
|
||||
', '
|
||||
),
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
@ -122,6 +122,7 @@ class Segment extends Model {
|
||||
->group_by(self::$_table.'.id')
|
||||
->group_by(self::$_table.'.name')
|
||||
->where(self::$_table.'.type', 'default')
|
||||
->whereNull(self::$_table.'.deleted_at')
|
||||
->findArray();
|
||||
}
|
||||
|
||||
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class SegmentFilter extends Model {
|
||||
public static $_table = MP_SEGMENT_FILTER_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
@ -15,7 +15,8 @@ class SendingQueue extends Model {
|
||||
return false;
|
||||
} else {
|
||||
$this->set('status', 'paused');
|
||||
return $this->save();
|
||||
$this->save();
|
||||
return ($this->getErrors() === false && $this->id() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,12 +25,14 @@ class SendingQueue extends Model {
|
||||
return $this->complete();
|
||||
} else {
|
||||
$this->set_expr('status', 'NULL');
|
||||
return $this->save();
|
||||
$this->save();
|
||||
return ($this->getErrors() === false && $this->id() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
function complete() {
|
||||
$this->set('status', 'completed');
|
||||
return $this->save();
|
||||
$this->save();
|
||||
return ($this->getErrors() === false && $this->id() > 0);
|
||||
}
|
||||
}
|
@ -35,6 +35,9 @@ class Setting extends Model {
|
||||
|
||||
if($setting !== $default) {
|
||||
for($i = 0, $count = count($keys); $i < $count; $i++) {
|
||||
if(!is_array($setting)) {
|
||||
$setting = array();
|
||||
}
|
||||
if(array_key_exists($keys[$i], $setting)) {
|
||||
$setting = $setting[$keys[$i]];
|
||||
} else {
|
||||
@ -67,13 +70,6 @@ class Setting extends Model {
|
||||
$last_key = array_pop($keys);
|
||||
|
||||
foreach($keys as $key) {
|
||||
if(!is_array($current_value)) {
|
||||
$current_value = array();
|
||||
}
|
||||
|
||||
if(!array_key_exists($key, $current_value)) {
|
||||
$current_value = array($key => array());
|
||||
}
|
||||
$current_value =& $current_value[$key];
|
||||
}
|
||||
if(is_scalar($current_value)) {
|
||||
@ -100,16 +96,20 @@ class Setting extends Model {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public static function createOrUpdate($model) {
|
||||
$exists = self::where('name', $model['name'])->findOne();
|
||||
public static function createOrUpdate($data = array()) {
|
||||
$setting = false;
|
||||
|
||||
if($exists === false) {
|
||||
$new_model = self::create();
|
||||
$new_model->hydrate($model);
|
||||
return $new_model->save();
|
||||
if(isset($data['name'])) {
|
||||
$setting = self::where('name', $data['name'])->findOne();
|
||||
}
|
||||
|
||||
$exists->value = $model['value'];
|
||||
return $exists->save();
|
||||
if($setting === false) {
|
||||
$setting = self::create();
|
||||
$setting->hydrate($data);
|
||||
} else {
|
||||
$setting->value = $data['value'];
|
||||
}
|
||||
|
||||
return $setting->save();
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,26 @@ class Subscriber extends Model {
|
||||
}
|
||||
|
||||
function addToSegments(array $segment_ids = array()) {
|
||||
$segments = Segment::whereIn('id', $segment_ids)->findMany();
|
||||
foreach($segments as $segment) {
|
||||
$association = SubscriberSegment::create();
|
||||
$association->subscriber_id = $this->id;
|
||||
$association->segment_id = $segment->id;
|
||||
$association->save();
|
||||
$wp_users_segment = Segment::getWPUsers();
|
||||
|
||||
if($wp_users_segment !== false) {
|
||||
// delete all relations to segments except WP users
|
||||
SubscriberSegment::where('subscriber_id', $this->id)
|
||||
->whereNotEqual('segment_id', $wp_users_segment->id)
|
||||
->deleteMany();
|
||||
} else {
|
||||
// delete all relations to segments
|
||||
SubscriberSegment::where('subscriber_id', $this->id)->deleteMany();
|
||||
}
|
||||
|
||||
if(!empty($segment_ids)) {
|
||||
$segments = Segment::whereIn('id', $segment_ids)->findMany();
|
||||
foreach($segments as $segment) {
|
||||
$association = SubscriberSegment::create();
|
||||
$association->subscriber_id = $this->id;
|
||||
$association->segment_id = $segment->id;
|
||||
$association->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +67,7 @@ class Subscriber extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
$subscriber = static::createOrUpdate($subscriber_data);
|
||||
$subscriber = self::createOrUpdate($subscriber_data);
|
||||
|
||||
if($subscriber !== false && $subscriber->id() > 0) {
|
||||
// restore deleted subscriber
|
||||
@ -92,20 +106,25 @@ class Subscriber extends Model {
|
||||
$segments = Segment::orderByAsc('name')->findMany();
|
||||
$segment_list = array();
|
||||
$segment_list[] = array(
|
||||
'label' => __('All lists'),
|
||||
'label' => __('All segments'),
|
||||
'value' => ''
|
||||
);
|
||||
$segment_list[] = array(
|
||||
'label' => sprintf(
|
||||
__('Subscribers without a segment (%d)'),
|
||||
self::filter('withoutSegments')->count()
|
||||
),
|
||||
'value' => 'none'
|
||||
);
|
||||
|
||||
foreach($segments as $segment) {
|
||||
$subscribers_count = $segment->subscribers()
|
||||
->whereNull('deleted_at')
|
||||
->count();
|
||||
if($subscribers_count > 0) {
|
||||
$segment_list[] = array(
|
||||
'label' => sprintf('%s (%d)', $segment->name, $subscribers_count),
|
||||
'value' => $segment->id()
|
||||
);
|
||||
}
|
||||
$segment_list[] = array(
|
||||
'label' => sprintf('%s (%d)', $segment->name, $subscribers_count),
|
||||
'value' => $segment->id()
|
||||
);
|
||||
}
|
||||
|
||||
$filters = array(
|
||||
@ -121,9 +140,13 @@ class Subscriber extends Model {
|
||||
}
|
||||
foreach($filters as $key => $value) {
|
||||
if($key === 'segment') {
|
||||
$segment = Segment::findOne($value);
|
||||
if($segment !== false) {
|
||||
return $segment->subscribers();
|
||||
if($value === 'none') {
|
||||
return self::filter('withoutSegments');
|
||||
} else {
|
||||
$segment = Segment::findOne($value);
|
||||
if($segment !== false) {
|
||||
return $segment->subscribers();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,27 +158,27 @@ class Subscriber extends Model {
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Subscriber::getPublished()->count()
|
||||
'count' => self::getPublished()->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'subscribed',
|
||||
'label' => __('Subscribed'),
|
||||
'count' => Subscriber::filter('subscribed')->count()
|
||||
'count' => self::filter('subscribed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'unconfirmed',
|
||||
'label' => __('Unconfirmed'),
|
||||
'count' => Subscriber::filter('unconfirmed')->count()
|
||||
'count' => self::filter('unconfirmed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'unsubscribed',
|
||||
'label' => __('Unsubscribed'),
|
||||
'count' => Subscriber::filter('unsubscribed')->count()
|
||||
'count' => self::filter('unsubscribed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Subscriber::getTrashed()->count()
|
||||
'count' => self::getTrashed()->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -226,17 +249,24 @@ class Subscriber extends Model {
|
||||
$subscriber = false;
|
||||
|
||||
if(isset($data['id']) && (int)$data['id'] > 0) {
|
||||
$subscriber = static::findOne((int)$data['id']);
|
||||
$subscriber = self::findOne((int)$data['id']);
|
||||
unset($data['id']);
|
||||
}
|
||||
|
||||
if($subscriber === false && !empty($data['email'])) {
|
||||
$subscriber = static::where('email', $data['email'])->findOne();
|
||||
$subscriber = self::where('email', $data['email'])->findOne();
|
||||
if($subscriber !== false) {
|
||||
unset($data['email']);
|
||||
}
|
||||
}
|
||||
|
||||
// segments
|
||||
$segment_ids = false;
|
||||
if(array_key_exists('segments', $data)) {
|
||||
$segment_ids = (array)$data['segments'];
|
||||
unset($data['segments']);
|
||||
}
|
||||
|
||||
// custom fields
|
||||
$custom_fields = array();
|
||||
|
||||
@ -248,7 +278,7 @@ class Subscriber extends Model {
|
||||
}
|
||||
|
||||
if($subscriber === false) {
|
||||
$subscriber = static::create();
|
||||
$subscriber = self::create();
|
||||
$subscriber->hydrate($data);
|
||||
} else {
|
||||
$subscriber->set($data);
|
||||
@ -260,6 +290,9 @@ class Subscriber extends Model {
|
||||
$subscriber->setCustomField($custom_field_id, $value);
|
||||
}
|
||||
}
|
||||
if($segment_ids !== false) {
|
||||
$subscriber->addToSegments($segment_ids);
|
||||
}
|
||||
}
|
||||
return $subscriber;
|
||||
}
|
||||
@ -388,7 +421,6 @@ class Subscriber extends Model {
|
||||
}
|
||||
|
||||
static function bulkAddToList($orm, $data = array()) {
|
||||
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
@ -412,6 +444,15 @@ class Subscriber extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
return parent::bulkAction($orm, function($ids) {
|
||||
// delete subscribers
|
||||
Subscriber::whereIn('id', $ids)->deleteMany();
|
||||
// delete subscribers' relations to segments
|
||||
SubscriberSegment::whereIn('subscriber_id', $ids)->deleteMany();
|
||||
});
|
||||
}
|
||||
|
||||
static function subscribed($orm) {
|
||||
return $orm
|
||||
->whereNull('deleted_at')
|
||||
@ -430,6 +471,19 @@ class Subscriber extends Model {
|
||||
->where('status', 'unconfirmed');
|
||||
}
|
||||
|
||||
static function withoutSegments($orm) {
|
||||
return $orm->select(MP_SUBSCRIBERS_TABLE.'.*')
|
||||
->leftOuterJoin(
|
||||
MP_SUBSCRIBER_SEGMENT_TABLE,
|
||||
array(
|
||||
MP_SUBSCRIBERS_TABLE.'.id',
|
||||
'=',
|
||||
MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id'
|
||||
)
|
||||
)
|
||||
->whereNull(MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id');
|
||||
}
|
||||
|
||||
static function createMultiple($columns, $values) {
|
||||
return self::rawExecute(
|
||||
'INSERT INTO `' . self::$_table . '` ' .
|
||||
|
@ -22,12 +22,12 @@ class PostTransformer {
|
||||
$content = $content_manager->filterContent($content);
|
||||
|
||||
$structure_transformer = new StructureTransformer();
|
||||
$structure = $structure_transformer->transform($content, $this->args['imagePadded'] === 'true');
|
||||
$structure = $structure_transformer->transform($content, $this->args['imageFullWidth'] === 'true');
|
||||
|
||||
$structure = $this->appendFeaturedImage(
|
||||
$post,
|
||||
$this->args['displayType'],
|
||||
$this->args['imagePadded'] === 'true',
|
||||
$this->args['imageFullWidth'] === 'true',
|
||||
$structure
|
||||
);
|
||||
$structure = $this->appendPostTitle($post, $structure);
|
||||
@ -36,7 +36,7 @@ class PostTransformer {
|
||||
return $structure;
|
||||
}
|
||||
|
||||
private function appendFeaturedImage($post, $display_type, $image_padded, $structure) {
|
||||
private function appendFeaturedImage($post, $display_type, $image_full_width, $structure) {
|
||||
if ($display_type === 'full') {
|
||||
// No featured images for full posts
|
||||
return $structure;
|
||||
@ -45,7 +45,7 @@ class PostTransformer {
|
||||
$featured_image = $this->getFeaturedImage(
|
||||
$post->ID,
|
||||
$post->post_title,
|
||||
(bool)$image_padded
|
||||
(bool)$image_full_width
|
||||
);
|
||||
|
||||
if (is_array($featured_image)) {
|
||||
@ -55,7 +55,7 @@ class PostTransformer {
|
||||
return $structure;
|
||||
}
|
||||
|
||||
private function getFeaturedImage($post_id, $post_title, $image_padded) {
|
||||
private function getFeaturedImage($post_id, $post_title, $image_full_width) {
|
||||
if(has_post_thumbnail($post_id)) {
|
||||
$thumbnail_id = get_post_thumbnail_id($post_id);
|
||||
|
||||
@ -81,7 +81,7 @@ class PostTransformer {
|
||||
'link' => get_permalink($post_id),
|
||||
'src' => $image_info[0],
|
||||
'alt' => $alt_text,
|
||||
'padded' => $image_padded,
|
||||
'fullWidth' => $image_full_width,
|
||||
'width' => $image_info[1],
|
||||
'height' => $image_info[2],
|
||||
'styles' => array(
|
||||
|
@ -7,11 +7,11 @@ if(!defined('ABSPATH')) exit;
|
||||
|
||||
class StructureTransformer {
|
||||
|
||||
function transform($content, $image_padded) {
|
||||
function transform($content, $image_full_width) {
|
||||
$root = pQuery::parseStr($content);
|
||||
|
||||
$this->hoistImagesToRoot($root);
|
||||
$structure = $this->transformTagsToBlocks($root, $image_padded);
|
||||
$structure = $this->transformTagsToBlocks($root, $image_full_width);
|
||||
$structure = $this->mergeNeighboringBlocks($structure);
|
||||
return $structure;
|
||||
}
|
||||
@ -44,8 +44,8 @@ class StructureTransformer {
|
||||
* Transforms HTML tags into their respective JSON objects,
|
||||
* turns other root children into text blocks
|
||||
*/
|
||||
private function transformTagsToBlocks($root, $image_padded) {
|
||||
return array_map(function($item) use ($image_padded) {
|
||||
private function transformTagsToBlocks($root, $image_full_width) {
|
||||
return array_map(function($item) use ($image_full_width) {
|
||||
if ($item->tag === 'img' || $item->tag === 'a' && $item->query('img')) {
|
||||
if ($item->tag === 'a') {
|
||||
$link = $item->getAttribute('href');
|
||||
@ -60,7 +60,7 @@ class StructureTransformer {
|
||||
'link' => $link,
|
||||
'src' => $image->getAttribute('src'),
|
||||
'alt' => $image->getAttribute('alt'),
|
||||
'padded' => $image_padded,
|
||||
'fullWidth' => $image_full_width,
|
||||
'width' => $image->getAttribute('width'),
|
||||
'height' => $image->getAttribute('height'),
|
||||
'styles' => array(
|
||||
|
@ -6,10 +6,12 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||
|
||||
class Image {
|
||||
static function render($element, $columnCount) {
|
||||
$element = self::getImageDimensions($element, $columnCount);
|
||||
$element['width'] = (int) $element['width'];
|
||||
$element['height'] = (int) $element['height'];
|
||||
$element = self::adjustImageDimensions($element, $columnCount);
|
||||
$template = '
|
||||
<tr>
|
||||
<td class="mailpoet_image ' . $element['paddedClass'] . '" align="center" valign="top">
|
||||
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded' : '') . '" align="center" valign="top">
|
||||
<img style="max-width:' . $element['width'] . 'px;" src="' . $element['src'] . '"
|
||||
width="' . $element['width'] . '" height="' . $element['height'] . '" alt="' . $element['alt'] . '"/>
|
||||
</td>
|
||||
@ -17,25 +19,22 @@ class Image {
|
||||
return $template;
|
||||
}
|
||||
|
||||
static function getImageDimensions($element, $column_count) {
|
||||
static function adjustImageDimensions($element, $column_count) {
|
||||
$column_width = ColumnsHelper::columnWidth($column_count);
|
||||
$padded_width = StylesHelper::$padding_width * 2;
|
||||
// resize image if it's wider than the column width
|
||||
if((int) $element['width'] >= $column_width) {
|
||||
$ratio = (int) $element['width'] / $column_width;
|
||||
// scale image to fit column width
|
||||
if($element['width'] > $column_width) {
|
||||
$ratio = $element['width'] / $column_width;
|
||||
$element['width'] = $column_width;
|
||||
$element['height'] = ceil((int) $element['height'] / $ratio);
|
||||
$element['height'] = (int) ceil($element['height'] / $ratio);
|
||||
}
|
||||
if($element['padded'] == "true" && $element['width'] >= $column_width) {
|
||||
// resize image if the padded option is on
|
||||
$ratio = (int) $element['width'] / ((int) $element['width'] - $padded_width);
|
||||
$element['width'] = (int) $element['width'] - $padded_width;
|
||||
$element['height'] = ceil((int) $element['height'] / $ratio);
|
||||
$element['paddedClass'] = 'mailpoet_padded';
|
||||
} else {
|
||||
$element['width'] = (int) $element['width'];
|
||||
$element['height'] = (int) $element['height'];
|
||||
$element['paddedClass'] = '';
|
||||
// resize image if the image is padded and wider than padded column width
|
||||
if($element['fullWidth'] === false &&
|
||||
$element['width'] > ($column_width - $padded_width)
|
||||
) {
|
||||
$ratio = $element['width'] / ($column_width - $padded_width);
|
||||
$element['width'] = $column_width - $padded_width;
|
||||
$element['height'] = (int) ceil($element['height'] / $ratio);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
@ -280,4 +280,4 @@ class Newsletters {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Router {
|
||||
$endpoint = new $endpoint();
|
||||
$response = $endpoint->$method($data);
|
||||
wp_send_json($response);
|
||||
} catch(Exception $e) {
|
||||
} catch(\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
exit;
|
||||
}
|
||||
|
@ -66,20 +66,19 @@ class Segments {
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$errors = array();
|
||||
$result = false;
|
||||
|
||||
$segment = Segment::createOrUpdate($data);
|
||||
$errors = $segment->getErrors();
|
||||
|
||||
if($segment !== false && !$segment->id()) {
|
||||
$errors = $segment->getValidationErrors();
|
||||
if(!empty($errors)) {
|
||||
return array(
|
||||
'result' => false,
|
||||
'errors' => $errors
|
||||
);
|
||||
} else {
|
||||
$result = true;
|
||||
return array(
|
||||
'result' => true
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'result' => $result,
|
||||
'errors' => $errors
|
||||
);
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
|
@ -13,25 +13,21 @@ class SendingQueue {
|
||||
try {
|
||||
new Mailer(false);
|
||||
} catch(\Exception $e) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array($e->getMessage())
|
||||
)
|
||||
return array(
|
||||
'result' => false,
|
||||
'errors' => array($e->getMessage())
|
||||
);
|
||||
}
|
||||
|
||||
$queue = \MailPoet\Models\SendingQueue::where('newsletter_id', $data['newsletter_id'])
|
||||
->whereNull('status')
|
||||
$queue = \MailPoet\Models\SendingQueue::whereNull('status')
|
||||
->where('newsletter_id', $data['newsletter_id'])
|
||||
->findArray();
|
||||
if(count($queue)) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Send operation is already in progress.'))
|
||||
)
|
||||
|
||||
if(!empty($queue)) {
|
||||
return array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Send operation is already in progress.'))
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$queue = \MailPoet\Models\SendingQueue::create();
|
||||
$queue->newsletter_id = $data['newsletter_id'];
|
||||
@ -40,50 +36,39 @@ class SendingQueue {
|
||||
->findMany();
|
||||
|
||||
foreach($segments as $segment) {
|
||||
$subscriber_ids = array_merge($subscriber_ids, Helpers::arrayColumn(
|
||||
$segment->subscribers()
|
||||
->findArray(),
|
||||
'id'
|
||||
));
|
||||
$subscriber_ids = array_merge(
|
||||
$subscriber_ids,
|
||||
Helpers::arrayColumn(
|
||||
$segment->subscribers()->findArray(), 'id'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(empty($subscriber_ids)) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('There are no subscribers.'))
|
||||
)
|
||||
return array(
|
||||
'result' => false,
|
||||
'errors' => array(__('There are no subscribers.'))
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$subscriber_ids = array_unique($subscriber_ids);
|
||||
$queue->subscribers = json_encode(
|
||||
$queue->subscribers = serialize(
|
||||
array(
|
||||
'to_process' => $subscriber_ids
|
||||
)
|
||||
);
|
||||
$queue->count_total = $queue->count_to_process = count($subscriber_ids);
|
||||
$result = $queue->save();
|
||||
if($result === false) {
|
||||
$errors = array(__('Queue could not be created.'));
|
||||
|
||||
if(!empty($queue->getValidationErrors())) {
|
||||
$errors = array_merge($errors, $queue->getValidationErrors());
|
||||
}
|
||||
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => $errors
|
||||
)
|
||||
$queue->save();
|
||||
$errors = $queue->getErrors();
|
||||
if(!empty($errors)) {
|
||||
return array(
|
||||
'result' => false,
|
||||
'errors' => $errors
|
||||
);
|
||||
} else {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => true,
|
||||
'data' => array($queue->id)
|
||||
)
|
||||
return array(
|
||||
'result' => true,
|
||||
'data' => array($queue->id)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -94,14 +79,15 @@ class SendingQueue {
|
||||
|
||||
if($newsletter !== false) {
|
||||
$queue = $newsletter->getQueue();
|
||||
if($queue !== false && $queue->id() > 0) {
|
||||
|
||||
if($queue !== false) {
|
||||
$result = $queue->pause();
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json(array(
|
||||
return array(
|
||||
'result' => $result
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
function resume($newsletter_id) {
|
||||
@ -110,125 +96,14 @@ class SendingQueue {
|
||||
|
||||
if($newsletter !== false) {
|
||||
$queue = $newsletter->getQueue();
|
||||
if($queue !== false && $queue->id() > 0) {
|
||||
|
||||
if($queue !== false) {
|
||||
$result = $queue->resume();
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json(array(
|
||||
return array(
|
||||
'result' => $result
|
||||
));
|
||||
}
|
||||
|
||||
function addQueues($data) {
|
||||
$newsletterIds = Helpers::arrayColumn($data, 'newsletter_id');
|
||||
$queues = \MailPoet\Models\SendingQueue::whereIn('newsletter_id', $newsletterIds)
|
||||
->whereNull('status')
|
||||
->findArray();
|
||||
if(count($queues)) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Send operation is already in progress.'))
|
||||
)
|
||||
);
|
||||
}
|
||||
$result = array_map(function ($queueData) {
|
||||
$queue = \MailPoet\Models\SendingQueue::create();
|
||||
$queue->newsletter_id = $queueData['newsletter_id'];
|
||||
$queue->subscribers = json_encode(
|
||||
array(
|
||||
'to_process' => $queueData['subscribers']
|
||||
)
|
||||
);
|
||||
$queue->count_total = $queue->count_to_process = count($queueData['subscribers']);
|
||||
$queue->save();
|
||||
return array(
|
||||
'newsletter_id' => $queue->newsletter_id,
|
||||
'queue_id' => $queue->id
|
||||
);
|
||||
}, $data);
|
||||
$result = Helpers::arrayColumn($result, 'queue_id', 'newsletter_id');
|
||||
wp_send_json(
|
||||
count($data) != count($result) ?
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Some queues could not be created.')),
|
||||
'data' => $result
|
||||
) :
|
||||
array(
|
||||
'result' => true,
|
||||
'data' => $result
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function deleteQueue($data) {
|
||||
$queue = \MailPoet\Models\SendingQueue::whereNull('deleted_at')
|
||||
->findOne($data['queue_id']);
|
||||
if(!$queue) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Queue not found.'))
|
||||
)
|
||||
);
|
||||
}
|
||||
$queue->deleted_at = 'Y-m-d H:i:s';
|
||||
$queue->save();
|
||||
wp_send_json(array('result' => true));
|
||||
}
|
||||
|
||||
function deleteQueues($data) {
|
||||
$queues = \MailPoet\Models\SendingQueue::whereNull('deleted_at')
|
||||
->whereIn('id', $data['queue_ids'])
|
||||
->findResultSet();
|
||||
if(!$queues->count()) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Queues not found.'))
|
||||
)
|
||||
);
|
||||
}
|
||||
foreach($queues as $queue) {
|
||||
$queue->deleted_at = 'Y-m-d H:i:s';
|
||||
$queue->save();
|
||||
}
|
||||
wp_send_json(array('result' => true));
|
||||
}
|
||||
|
||||
function getQueueStatus($data) {
|
||||
$queue = \MailPoet\Models\SendingQueue::whereNull('deleted_at')
|
||||
->findOne($data['queue_id'])
|
||||
->asArray();
|
||||
wp_send_json(
|
||||
!$queue ?
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Queue not found.'))
|
||||
) :
|
||||
array(
|
||||
'result' => true,
|
||||
'data' => $queue
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function getQueuesStatus($data) {
|
||||
$queues = \MailPoet\Models\SendingQueue::whereNull('deleted_at')
|
||||
->whereIn('id', $data['queue_ids'])
|
||||
->findArray();
|
||||
wp_send_json(
|
||||
!$queues ?
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('Queue not found.'))
|
||||
) :
|
||||
array(
|
||||
'result' => true,
|
||||
'data' => $queues
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ class Setup {
|
||||
$activator->deactivate();
|
||||
$activator->activate();
|
||||
$result = true;
|
||||
} catch(Exception $e) {
|
||||
} catch(\Exception $e) {
|
||||
$result = false;
|
||||
}
|
||||
return array(
|
||||
|
@ -57,13 +57,6 @@ class Subscribers {
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$segment_ids = array();
|
||||
|
||||
if(isset($data['segments'])) {
|
||||
$segment_ids = (array)$data['segments'];
|
||||
unset($data['segments']);
|
||||
}
|
||||
|
||||
$subscriber = Subscriber::createOrUpdate($data);
|
||||
$errors = $subscriber->getErrors();
|
||||
|
||||
@ -73,9 +66,6 @@ class Subscribers {
|
||||
'errors' => $errors
|
||||
);
|
||||
} else {
|
||||
if(!empty($segment_ids)) {
|
||||
$subscriber->addToSegments($segment_ids);
|
||||
}
|
||||
return array(
|
||||
'result' => true
|
||||
);
|
||||
|
@ -47,9 +47,9 @@ class WP {
|
||||
}
|
||||
$subscriber = Subscriber::createOrUpdate($data);
|
||||
|
||||
if($subscriber !== false && $subscriber->id()) {
|
||||
if($subscriber->getErrors() === false && $subscriber->id > 0) {
|
||||
if($segment !== false) {
|
||||
$segment->addSubscriber($subscriber->id());
|
||||
$segment->addSubscriber($subscriber->id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -17,6 +17,7 @@ class Export {
|
||||
public $segments;
|
||||
public $subscribers_without_segment;
|
||||
public $subscriber_fields;
|
||||
public $export_path;
|
||||
public $export_file;
|
||||
public $export_file_URL;
|
||||
public $profiler_start;
|
||||
@ -28,19 +29,23 @@ class Export {
|
||||
$this->segments = $data['segments'];
|
||||
$this->subscribers_without_segment = array_search(0, $this->segments);
|
||||
$this->subscriber_fields = $data['subscriber_fields'];
|
||||
$this->export_path = Env::$temp_path;
|
||||
$this->export_file = $this->getExportFile($this->export_format_option);
|
||||
$this->export_file_URL = $this->getExportFileURL($this->export_file);
|
||||
$this->profiler_start = microtime(true);
|
||||
}
|
||||
|
||||
function process() {
|
||||
$subscribers = $this->getSubscribers();
|
||||
$subscriber_custom_fields = $this->getSubscriberCustomFields();
|
||||
$formatted_subscriber_fields = $this->formatSubscriberFields(
|
||||
$this->subscriber_fields,
|
||||
$subscriber_custom_fields
|
||||
);
|
||||
try {
|
||||
if(is_writable($this->export_path) === false) {
|
||||
throw new \Exception(__("Couldn't save export file on the server."));
|
||||
}
|
||||
$subscribers = $this->getSubscribers();
|
||||
$subscriber_custom_fields = $this->getSubscriberCustomFields();
|
||||
$formatted_subscriber_fields = $this->formatSubscriberFields(
|
||||
$this->subscriber_fields,
|
||||
$subscriber_custom_fields
|
||||
);
|
||||
if($this->export_format_option === 'csv') {
|
||||
$CSV_file = fopen($this->export_file, 'w');
|
||||
$format_CSV = function($row) {
|
||||
@ -104,7 +109,7 @@ class Export {
|
||||
);
|
||||
$writer->writeToFile($this->export_file);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
} catch(\Exception $e) {
|
||||
return array(
|
||||
'result' => false,
|
||||
'errors' => array($e->getMessage())
|
||||
@ -178,7 +183,7 @@ class Export {
|
||||
|
||||
function getExportFile($format) {
|
||||
return sprintf(
|
||||
Env::$temp_path . '/MailPoet_export_%s.%s',
|
||||
$this->export_path . '/MailPoet_export_%s.%s',
|
||||
substr(md5(time()), 0, 4),
|
||||
$format
|
||||
);
|
||||
|
@ -5,19 +5,19 @@ use MailPoet\Util\Helpers;
|
||||
|
||||
class MailChimp {
|
||||
function __construct($APIKey, $lists = false) {
|
||||
$this->APIKey = $this->getAPIKey($APIKey);
|
||||
$this->maxPostSize = Helpers::getMaxPostSize('bytes');
|
||||
$this->dataCenter = $this->getDataCenter($this->APIKey);
|
||||
$this->listsURL = 'https://%s.api.mailchimp.com/2.0/lists/list?apikey=%s';
|
||||
$this->exportURL = 'https://%s.api.mailchimp.com/export/1.0/list/?apikey=%s&id=%s';
|
||||
$this->api_key = $this->getAPIKey($APIKey);
|
||||
$this->max_post_size = Helpers::getMaxPostSize('bytes');
|
||||
$this->data_center = $this->getDataCenter($this->api_key);
|
||||
$this->lists_url = 'https://%s.api.mailchimp.com/2.0/lists/list?apikey=%s';
|
||||
$this->export_url = 'https://%s.api.mailchimp.com/export/1.0/list/?apikey=%s&id=%s';
|
||||
}
|
||||
|
||||
function getLists() {
|
||||
if(!$this->APIKey || !$this->dataCenter) {
|
||||
if(!$this->api_key || !$this->data_center) {
|
||||
return $this->processError('API');
|
||||
}
|
||||
|
||||
$connection = @fopen(sprintf($this->listsURL, $this->dataCenter, $this->APIKey), 'r');
|
||||
$connection = @fopen(sprintf($this->lists_url, $this->data_center, $this->api_key), 'r');
|
||||
|
||||
if(!$connection) {
|
||||
return $this->processError('connection');
|
||||
@ -52,7 +52,7 @@ class MailChimp {
|
||||
}
|
||||
|
||||
function getSubscribers($lists = array()) {
|
||||
if(!$this->APIKey || !$this->dataCenter) {
|
||||
if(!$this->api_key || !$this->data_center) {
|
||||
return $this->processError('API');
|
||||
}
|
||||
|
||||
@ -60,9 +60,9 @@ class MailChimp {
|
||||
return $this->processError('lists');
|
||||
}
|
||||
|
||||
$bytesFetched = 0;
|
||||
$bytes_fetched = 0;
|
||||
foreach ($lists as $list) {
|
||||
$url = sprintf($this->exportURL, $this->dataCenter, $this->APIKey, $list);
|
||||
$url = sprintf($this->export_url, $this->data_center, $this->api_key, $list);
|
||||
$connection = @fopen($url, 'r');
|
||||
if(!$connection) {
|
||||
return $this->processError('connection');
|
||||
@ -78,10 +78,10 @@ class MailChimp {
|
||||
if(is_object($header) && isset($header->error)) {
|
||||
return $this->processError('lists');
|
||||
}
|
||||
if(!isset($headerHash)) {
|
||||
$headerHash = md5(implode(',', $header));
|
||||
if(!isset($header_hash)) {
|
||||
$header_hash = md5(implode(',', $header));
|
||||
} else {
|
||||
if(md5(implode(',', $header) !== $headerHash)) {
|
||||
if(md5(implode(',', $header) !== $header_hash)) {
|
||||
return $this->processError('headers');
|
||||
}
|
||||
}
|
||||
@ -91,8 +91,8 @@ class MailChimp {
|
||||
$i++;
|
||||
}
|
||||
|
||||
$bytesFetched += strlen($buffer);
|
||||
if($bytesFetched > $this->maxPostSize) {
|
||||
$bytes_fetched += strlen($buffer);
|
||||
if($bytes_fetched > $this->max_post_size) {
|
||||
return $this->processError('size');
|
||||
|
||||
}
|
||||
@ -119,8 +119,9 @@ class MailChimp {
|
||||
}
|
||||
|
||||
function getDataCenter($APIKey) {
|
||||
if (!preg_match('/-[a-zA-Z0-9]{3,}/', $APIKey)) return false;
|
||||
// double parantheses: http://phpsadness.com/sad/51
|
||||
return ($APIKey) ? end((explode('-', $APIKey))) : false;
|
||||
return end((explode('-', $APIKey)));
|
||||
}
|
||||
|
||||
function getAPIKey($APIKey) {
|
||||
@ -150,7 +151,7 @@ class MailChimp {
|
||||
}
|
||||
return array(
|
||||
'result' => false,
|
||||
'error' => $errorMessage
|
||||
'errors' => array($errorMessage)
|
||||
);
|
||||
}
|
||||
}
|
@ -8,13 +8,22 @@ class Comment {
|
||||
const APPROVED = 1;
|
||||
const PENDING_APPROVAL = 0;
|
||||
|
||||
static function extendForm() {
|
||||
static function extendLoggedInForm($field) {
|
||||
$field .= self::getSubscriptionField();
|
||||
return $field;
|
||||
}
|
||||
|
||||
static function extendLoggedOutForm() {
|
||||
echo self::getSubscriptionField();
|
||||
}
|
||||
|
||||
static function getSubscriptionField() {
|
||||
$label = Setting::getValue(
|
||||
'subscribe.on_comment.label',
|
||||
__('Yes, add me to your mailing list.')
|
||||
);
|
||||
|
||||
print '<p class="comment-form-mailpoet">
|
||||
return '<p class="comment-form-mailpoet">
|
||||
<label for="mailpoet_subscribe_on_comment">
|
||||
<input
|
||||
type="checkbox"
|
||||
|
@ -12,7 +12,7 @@ class DKIM {
|
||||
'public' => self::trimKey($rsa_keys['publickey']),
|
||||
'private' => self::trimKey($rsa_keys['privatekey'])
|
||||
);
|
||||
} catch(Exception $e) {
|
||||
} catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class Engine
|
||||
*/
|
||||
public function addValidator($label, $function)
|
||||
{
|
||||
if (isset($this->_checks[$label])) throw Exception();
|
||||
if (isset($this->_checks[$label])) throw \Exception();
|
||||
$this->setValidator($label, $function);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ namespace MailPoet\Util;
|
||||
* @license MIT License
|
||||
* */
|
||||
|
||||
if (!class_exists('ZipArchive')) { throw new Exception('ZipArchive not found'); }
|
||||
if (!class_exists('ZipArchive')) { throw new \Exception('ZipArchive not found'); }
|
||||
|
||||
class XLSXWriter
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ if(!defined('ABSPATH')) exit;
|
||||
use \MailPoet\Config\Initializer;
|
||||
/*
|
||||
* Plugin Name: MailPoet
|
||||
* Version: 0.0.14
|
||||
* Version: 0.0.17
|
||||
* Plugin URI: http://www.mailpoet.com
|
||||
* Description: MailPoet Newsletters.
|
||||
* Author: MailPoet
|
||||
@ -22,7 +22,7 @@ use \MailPoet\Config\Initializer;
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
define('MAILPOET_VERSION', '0.0.14');
|
||||
define('MAILPOET_VERSION', '0.0.17');
|
||||
|
||||
$initializer = new Initializer(array(
|
||||
'file' => __FILE__,
|
||||
|
@ -14,6 +14,7 @@ $models = array(
|
||||
'NewsletterSegment',
|
||||
'NewsletterTemplate',
|
||||
'Segment',
|
||||
'SendingQueue',
|
||||
'Setting',
|
||||
'Subscriber',
|
||||
'SubscriberCustomField',
|
||||
|
@ -71,7 +71,7 @@ define([
|
||||
});
|
||||
|
||||
it('has image width', function () {
|
||||
expect(model.get('imagePadded')).to.be.a('boolean');
|
||||
expect(model.get('imageFullWidth')).to.be.a('boolean');
|
||||
});
|
||||
|
||||
it('has an option to display author', function () {
|
||||
@ -126,7 +126,7 @@ define([
|
||||
titlePosition: 'aboveBlock', // 'inTextBlock'|'aboveBlock',
|
||||
titleAlignment: 'right', // 'left'|'center'|'right'
|
||||
titleIsLink: true, // false|true
|
||||
imagePadded: false, // true|false
|
||||
imageFullWidth: false, // true|false
|
||||
showAuthor: 'belowText', // 'no'|'aboveText'|'belowText'
|
||||
authorPrecededBy: 'Custom config author preceded by',
|
||||
showCategories: 'belowText', // 'no'|'aboveText'|'belowText'
|
||||
@ -172,7 +172,7 @@ define([
|
||||
expect(model.get('titlePosition')).to.equal('aboveBlock');
|
||||
expect(model.get('titleAlignment')).to.equal('right');
|
||||
expect(model.get('titleIsLink')).to.equal(true);
|
||||
expect(model.get('imagePadded')).to.equal(false);
|
||||
expect(model.get('imageFullWidth')).to.equal(false);
|
||||
expect(model.get('showAuthor')).to.equal('belowText');
|
||||
expect(model.get('authorPrecededBy')).to.equal('Custom config author preceded by');
|
||||
expect(model.get('showCategories')).to.equal('belowText');
|
||||
@ -346,8 +346,8 @@ define([
|
||||
|
||||
it('changes the model if image alignment changes', function () {
|
||||
var newValue = false;
|
||||
view.$('.mailpoet_automated_latest_content_image_padded').val(newValue).change();
|
||||
expect(model.get('imagePadded')).to.equal(newValue);
|
||||
view.$('.mailpoet_automated_latest_content_image_full_width').val(newValue).change();
|
||||
expect(model.get('imageFullWidth')).to.equal(newValue);
|
||||
});
|
||||
|
||||
it('changes the model if show author changes', function () {
|
||||
|
@ -63,6 +63,10 @@ define([
|
||||
expect(model.get('styles.block.fontSize')).to.match(/^\d+px$/);
|
||||
});
|
||||
|
||||
it("has a text font weight", function () {
|
||||
expect(model.get('styles.block.fontWeight')).to.match(/^(bold|normal)$/);
|
||||
});
|
||||
|
||||
it("has width", function () {
|
||||
expect(model.get('styles.block.width')).to.match(/^\d+px$/);
|
||||
});
|
||||
@ -78,7 +82,7 @@ define([
|
||||
});
|
||||
|
||||
it("triggers autosave if any attribute changes", function () {
|
||||
var mock = sinon.mock().exactly(11).withArgs('autoSave');
|
||||
var mock = sinon.mock().exactly(12).withArgs('autoSave');
|
||||
EditorApplication.getChannel = sinon.stub().returns({
|
||||
trigger: mock,
|
||||
});
|
||||
@ -93,6 +97,7 @@ define([
|
||||
model.set('styles.block.fontColor', '#345678');
|
||||
model.set('styles.block.fontFamily', 'Some other style');
|
||||
model.set('styles.block.fontSize', '10px');
|
||||
model.set('styles.block.fontWeight', 'bold');
|
||||
mock.verify();
|
||||
});
|
||||
|
||||
@ -114,6 +119,7 @@ define([
|
||||
fontColor: '#345678',
|
||||
fontFamily: 'Tahoma',
|
||||
fontSize: '30px',
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -133,6 +139,7 @@ define([
|
||||
expect(model.get('styles.block.fontColor')).to.equal('#345678');
|
||||
expect(model.get('styles.block.fontFamily')).to.equal('Tahoma');
|
||||
expect(model.get('styles.block.fontSize')).to.equal('30px');
|
||||
expect(model.get('styles.block.fontWeight')).to.equal('bold');
|
||||
});
|
||||
});
|
||||
|
||||
@ -179,6 +186,7 @@ define([
|
||||
fontColor: '#345678',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: '12px',
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -235,6 +243,10 @@ define([
|
||||
it('has a specified font size', function () {
|
||||
expect(view.$('.mailpoet_editor_button').css('font-size')).to.equal(model.get('styles.block.fontSize'));
|
||||
});
|
||||
|
||||
it('has a specified font weight', function () {
|
||||
expect(view.$('.mailpoet_editor_button').css('font-weight')).to.equal(model.get('styles.block.fontWeight'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -318,6 +330,12 @@ define([
|
||||
expect(model.get('styles.block.fontSize')).to.equal(newValue);
|
||||
});
|
||||
|
||||
it('updates the model when font weight changes', function () {
|
||||
var newValue = 'bold';
|
||||
view.$('.mailpoet_field_button_font_weight').prop('checked', true).change();
|
||||
expect(model.get('styles.block.fontWeight')).to.equal(newValue);
|
||||
});
|
||||
|
||||
it('updates the model when background color changes', function () {
|
||||
var newValue = '#cccccc';
|
||||
|
||||
|
@ -30,8 +30,8 @@ define([
|
||||
expect(model.get('alt')).to.be.a('string');
|
||||
});
|
||||
|
||||
it('can be padded', function () {
|
||||
expect(model.get('padded')).to.be.a('boolean');
|
||||
it('can be full width', function () {
|
||||
expect(model.get('fullWidth')).to.be.a('boolean');
|
||||
});
|
||||
|
||||
it('has a width', function () {
|
||||
@ -61,7 +61,7 @@ define([
|
||||
model.set('link', 'http://example.net');
|
||||
model.set('src', 'someNewImage.png');
|
||||
model.set('alt', 'Some alt text');
|
||||
model.set('padded', false);
|
||||
model.set('fullWidth', false);
|
||||
model.set('width', '63px');
|
||||
model.set('height', '61px');
|
||||
model.set('styles.block.textAlign', 'right');
|
||||
@ -76,7 +76,7 @@ define([
|
||||
link: 'http://example.org/customConfigPage',
|
||||
src: 'http://example.org/someCustomConfigImage.png',
|
||||
alt: 'Custom config alt',
|
||||
padded: false,
|
||||
fullWidth: false,
|
||||
width: '1234px',
|
||||
height: '2345px',
|
||||
styles: {
|
||||
@ -92,7 +92,7 @@ define([
|
||||
expect(model.get('link')).to.equal('http://example.org/customConfigPage');
|
||||
expect(model.get('src')).to.equal('http://example.org/someCustomConfigImage.png');
|
||||
expect(model.get('alt')).to.equal('Custom config alt');
|
||||
expect(model.get('padded')).to.equal(false);
|
||||
expect(model.get('fullWidth')).to.equal(false);
|
||||
expect(model.get('width')).to.equal('1234px');
|
||||
expect(model.get('height')).to.equal('2345px');
|
||||
expect(model.get('styles.block.textAlign')).to.equal('right');
|
||||
@ -182,8 +182,8 @@ define([
|
||||
|
||||
it('updates the model when padding changes', function () {
|
||||
var newValue = 'false';
|
||||
view.$('.mailpoet_field_image_padded').prop('checked', false).change();
|
||||
expect(model.get('padded')).to.equal(false);
|
||||
view.$('.mailpoet_field_image_full_width').prop('checked', false).change();
|
||||
expect(model.get('fullWidth')).to.equal(false);
|
||||
});
|
||||
|
||||
it.skip('closes the sidepanel after "Done" is clicked', function() {
|
||||
|
@ -1,8 +1,9 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'newsletter_editor/blocks/posts'
|
||||
], function(EditorApplication, CommunicationComponent, PostsBlock) {
|
||||
'newsletter_editor/blocks/posts',
|
||||
'newsletter_editor/blocks/container'
|
||||
], function(EditorApplication, CommunicationComponent, PostsBlock, ContainerBlock) {
|
||||
|
||||
describe('Posts', function () {
|
||||
Backbone.Radio = {
|
||||
@ -74,7 +75,7 @@ define([
|
||||
});
|
||||
|
||||
it('has image specific alignment', function () {
|
||||
expect(model.get('imagePadded')).to.be.a('boolean');
|
||||
expect(model.get('imageFullWidth')).to.be.a('boolean');
|
||||
});
|
||||
|
||||
it('has an option to display author', function () {
|
||||
@ -129,7 +130,7 @@ define([
|
||||
titlePosition: 'aboveBlock', // 'inTextBlock'|'aboveBlock',
|
||||
titleAlignment: 'right', // 'left'|'center'|'right'
|
||||
titleIsLink: true, // false|true
|
||||
imagePadded: false, // true|false
|
||||
imageFullWidth: false, // true|false
|
||||
//imageAlignment: 'right', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
showAuthor: 'belowText', // 'no'|'aboveText'|'belowText'
|
||||
authorPrecededBy: 'Custom config author preceded by',
|
||||
@ -176,7 +177,7 @@ define([
|
||||
expect(model.get('titlePosition')).to.equal('aboveBlock');
|
||||
expect(model.get('titleAlignment')).to.equal('right');
|
||||
expect(model.get('titleIsLink')).to.equal(true);
|
||||
expect(model.get('imagePadded')).to.equal(false);
|
||||
expect(model.get('imageFullWidth')).to.equal(false);
|
||||
expect(model.get('showAuthor')).to.equal('belowText');
|
||||
expect(model.get('authorPrecededBy')).to.equal('Custom config author preceded by');
|
||||
expect(model.get('showCategories')).to.equal('belowText');
|
||||
@ -255,7 +256,7 @@ define([
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {},
|
||||
});
|
||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
|
||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(ContainerBlock.ContainerBlockModel);
|
||||
model = new (PostsBlock.PostsBlockModel)();
|
||||
view = new (PostsBlock.PostsBlockSettingsView)({model: model});
|
||||
});
|
||||
@ -318,8 +319,8 @@ define([
|
||||
|
||||
it('changes the model if image alignment changes', function () {
|
||||
var newValue = false;
|
||||
view.$('.mailpoet_posts_image_padded').val(newValue).change();
|
||||
expect(model.get('imagePadded')).to.equal(newValue);
|
||||
view.$('.mailpoet_posts_image_full_width').val(newValue).change();
|
||||
expect(model.get('imageFullWidth')).to.equal(newValue);
|
||||
});
|
||||
|
||||
it('changes the model if show author changes', function () {
|
||||
|
@ -147,7 +147,11 @@ define([
|
||||
},
|
||||
},
|
||||
'newsletter_editor/App': EditorApplication,
|
||||
'html2canvas': function() { return html2canvasMock; },
|
||||
'html2canvas': function() {
|
||||
return {
|
||||
then: function() { return html2canvasMock; }
|
||||
};
|
||||
},
|
||||
});
|
||||
var view = new (module.SaveView)();
|
||||
view.render();
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Listing;
|
||||
use MailPoet\Models\Subscriber;
|
||||
|
||||
class ListingCest {
|
||||
function _before() {
|
||||
@ -22,18 +23,17 @@ class ListingCest {
|
||||
}
|
||||
|
||||
function itShouldGroup(UnitTester $I) {
|
||||
$I->generateSubscribers(10);
|
||||
$I->generateSubscribers(20, array('status' => 'unsubscribed'));
|
||||
$I->generateSubscribers(30, array('status' => 'subscribed'));
|
||||
$I->generateSubscribers(1);
|
||||
$I->generateSubscribers(2, array('status' => 'unsubscribed'));
|
||||
$I->generateSubscribers(3, array('status' => 'subscribed'));
|
||||
|
||||
$listing = new Listing\Handler(
|
||||
'\MailPoet\Models\Subscriber',
|
||||
array('group' => 'subscribed')
|
||||
);
|
||||
$result = $listing->get();
|
||||
|
||||
expect($result['groups'])->notEmpty();
|
||||
expect($result['count'])->equals(30);
|
||||
expect($result['count'])->equals(3);
|
||||
}
|
||||
|
||||
function itShouldSearch(UnitTester $I) {
|
||||
@ -52,11 +52,7 @@ class ListingCest {
|
||||
expect($result['count'])->equals(1);
|
||||
}
|
||||
|
||||
function itShouldPaginate(UnitTester $I) {
|
||||
|
||||
}
|
||||
|
||||
function _after() {
|
||||
|
||||
Subscriber::deleteMany();
|
||||
}
|
||||
}
|
||||
|
@ -6,16 +6,16 @@ use MailPoet\Models\SubscriberCustomField;
|
||||
|
||||
class CustomFieldCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'name' => 'DOB',
|
||||
'type' => 'date',
|
||||
'params' => 'none'
|
||||
'name' => 'City',
|
||||
'type' => 'text',
|
||||
'params' => array(
|
||||
'label' => 'What is your city?'
|
||||
)
|
||||
);
|
||||
$this->customField = CustomField::create();
|
||||
$this->customField->hydrate($this->data);
|
||||
$this->saved = $this->customField->save();
|
||||
$this->subscribersData = array(
|
||||
$this->custom_field = CustomField::createOrUpdate($this->data);
|
||||
|
||||
$this->subscribers = array(
|
||||
array(
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Mailer',
|
||||
@ -30,20 +30,26 @@ class CustomFieldCest {
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
expect($this->saved->id() > 0)->true();
|
||||
expect($this->saved->getErrors())->false();
|
||||
expect($this->custom_field->id() > 0)->true();
|
||||
expect($this->custom_field->getErrors())->false();
|
||||
}
|
||||
|
||||
function itCanHaveName() {
|
||||
expect($this->customField->name)->equals($this->data['name']);
|
||||
function itHasAName() {
|
||||
expect($this->custom_field->name)->equals($this->data['name']);
|
||||
}
|
||||
|
||||
function itCanHaveType() {
|
||||
expect($this->customField->type)->equals($this->data['type']);
|
||||
function itHasAType() {
|
||||
expect($this->custom_field->type)->equals($this->data['type']);
|
||||
}
|
||||
|
||||
function itCanHaveParams() {
|
||||
expect($this->customField->params)->equals($this->data['params']);
|
||||
function itHasSerializedParams() {
|
||||
$params = unserialize($this->custom_field->params);
|
||||
expect($params)->equals($this->data['params']);
|
||||
}
|
||||
|
||||
function itCanDecodeParams() {
|
||||
$custom_field = $this->custom_field->asArray();
|
||||
expect($custom_field['params'])->equals($this->data['params']);
|
||||
}
|
||||
|
||||
function itHasToBeValid() {
|
||||
@ -58,75 +64,64 @@ class CustomFieldCest {
|
||||
}
|
||||
|
||||
function itHasACreatedAtOnCreation() {
|
||||
$customField = CustomField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($customField->created_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
$custom_field = CustomField::findOne($this->custom_field->id);
|
||||
expect($custom_field->created_at)->notNull();
|
||||
expect($custom_field->created_at)->notEquals('0000-00-00 00:00:00');
|
||||
}
|
||||
|
||||
function itHasAnUpdatedAtOnCreation() {
|
||||
$customField = CustomField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($customField->updated_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
}
|
||||
|
||||
function itKeepsTheCreatedAtOnUpdate() {
|
||||
$customField = CustomField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$old_created_at = $customField->created_at;
|
||||
$customField->name = 'new name';
|
||||
$customField->save();
|
||||
expect($old_created_at)->equals($customField->created_at);
|
||||
$custom_field = CustomField::findOne($this->custom_field->id);
|
||||
expect($custom_field->updated_at)
|
||||
->equals($custom_field->created_at);
|
||||
}
|
||||
|
||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||
$customField = CustomField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$update_time = time();
|
||||
$customField->name = 'new name';
|
||||
$customField->save();
|
||||
$time_difference = strtotime($customField->updated_at) >= $update_time;
|
||||
expect($time_difference)->equals(true);
|
||||
$custom_field = CustomField::findOne($this->custom_field->id);
|
||||
$created_at = $custom_field->created_at;
|
||||
|
||||
sleep(1);
|
||||
|
||||
$custom_field->name = 'Country';
|
||||
$custom_field->save();
|
||||
|
||||
$updated_custom_field = CustomField::findOne($custom_field->id);
|
||||
expect($updated_custom_field->created_at)->equals($created_at);
|
||||
$is_time_updated = (
|
||||
$updated_custom_field->updated_at > $updated_custom_field->created_at
|
||||
);
|
||||
expect($is_time_updated)->true();
|
||||
}
|
||||
|
||||
function itCanHaveManySubscribers() {
|
||||
foreach ($this->subscribersData as $data) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate($data);
|
||||
$subscriber->save();
|
||||
foreach($this->subscribers as $subscriber) {
|
||||
$subscriber = Subscriber::createOrUpdate($subscriber);
|
||||
|
||||
$association = SubscriberCustomField::create();
|
||||
$association->subscriber_id = $subscriber->id;
|
||||
$association->custom_field_id = $this->customField->id;
|
||||
$association->custom_field_id = $this->custom_field->id;
|
||||
$association->save();
|
||||
}
|
||||
$customField = CustomField::findOne($this->customField->id);
|
||||
$subscribers = $customField->subscribers()
|
||||
->findArray();
|
||||
$custom_field = CustomField::findOne($this->custom_field->id);
|
||||
$subscribers = $custom_field->subscribers()->findArray();
|
||||
expect(count($subscribers))->equals(2);
|
||||
}
|
||||
|
||||
function itCanStoreCustomFieldValue() {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate($this->subscribersData[0]);
|
||||
$subscriber->save();
|
||||
function itCanHaveAValue() {
|
||||
$subscriber = Subscriber::createOrUpdate($this->subscribers[0]);
|
||||
|
||||
$association = SubscriberCustomField::create();
|
||||
$association->subscriber_id = $subscriber->id;
|
||||
$association->custom_field_id = $this->customField->id;
|
||||
$association->custom_field_id = $this->custom_field->id;
|
||||
$association->value = '12/12/2012';
|
||||
$association->save();
|
||||
$customField = CustomField::findOne($this->customField->id);
|
||||
$subscriber = $customField->subscribers()
|
||||
->findOne();
|
||||
$custom_field = CustomField::findOne($this->custom_field->id);
|
||||
$subscriber = $custom_field->subscribers()->findOne();
|
||||
expect($subscriber->value)->equals($association->value);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(CustomField::$_table)
|
||||
->deleteMany();
|
||||
ORM::forTable(Subscriber::$_table)
|
||||
->deleteMany();
|
||||
ORM::forTable(SubscriberCustomField::$_table)
|
||||
->deleteMany();
|
||||
CustomField::deleteMany();
|
||||
Subscriber::deleteMany();
|
||||
SubscriberCustomField::deleteMany();
|
||||
}
|
||||
}
|
@ -3,19 +3,14 @@ use MailPoet\Models\Form;
|
||||
|
||||
class FormCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'name' => 'my form',
|
||||
);
|
||||
|
||||
$this->form = Form::create();
|
||||
$this->form->hydrate($this->data);
|
||||
$this->saved = $this->form->save();
|
||||
$this->form = Form::createOrUpdate(array(
|
||||
'name' => 'My Form'
|
||||
));
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
expect($this->saved->id() > 0)->true();
|
||||
expect($this->saved->getErrors())->false();
|
||||
expect($this->form->id() > 0)->true();
|
||||
expect($this->form->getErrors())->false();
|
||||
}
|
||||
|
||||
function itHasToBeValid() {
|
||||
@ -27,60 +22,79 @@ class FormCest {
|
||||
expect($errors[0])->equals('You need to specify a name.');
|
||||
}
|
||||
|
||||
function itCanBeGrouped() {
|
||||
$forms = Form::filter('groupBy', 'all')->findArray();
|
||||
expect($forms)->count(1);
|
||||
|
||||
$forms = Form::filter('groupBy', 'trash')->findArray();
|
||||
expect($forms)->count(0);
|
||||
|
||||
$this->form->trash();
|
||||
$forms = Form::filter('groupBy', 'trash')->findArray();
|
||||
expect($forms)->count(1);
|
||||
|
||||
$forms = Form::filter('groupBy', 'all')->findArray();
|
||||
expect($forms)->count(0);
|
||||
|
||||
$this->form->restore();
|
||||
$forms = Form::filter('groupBy', 'all')->findArray();
|
||||
expect($forms)->count(1);
|
||||
}
|
||||
|
||||
function itCanBeSearched() {
|
||||
$form = Form::filter('search', 'my F')->findOne();
|
||||
expect($form->name)->equals('My Form');
|
||||
}
|
||||
|
||||
function itHasACreatedAtOnCreation() {
|
||||
$form = Form::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($form->created_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
$form = Form::findOne($this->form->id);
|
||||
expect($form->created_at)->notNull();
|
||||
expect($form->created_at)->notEquals('0000-00-00 00:00:00');
|
||||
}
|
||||
|
||||
function itHasAnUpdatedAtOnCreation() {
|
||||
$form = Form::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($form->updated_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
}
|
||||
|
||||
function itKeepsTheCreatedAtOnUpdate() {
|
||||
$form = Form::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$old_created_at = $form->created_at;
|
||||
$form->name = 'new name';
|
||||
$form->save();
|
||||
expect($old_created_at)->equals($form->created_at);
|
||||
$form = Form::findOne($this->form->id);
|
||||
expect($form->updated_at)
|
||||
->equals($form->created_at);
|
||||
}
|
||||
|
||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||
$form = Form::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$update_time = time();
|
||||
$form = Form::findOne($this->form->id);
|
||||
$created_at = $form->created_at;
|
||||
|
||||
sleep(1);
|
||||
|
||||
$form->name = 'new name';
|
||||
$form->save();
|
||||
$time_difference = strtotime($form->updated_at) >= $update_time;
|
||||
expect($time_difference)->equals(true);
|
||||
|
||||
$updated_form = Form::findOne($form->id);
|
||||
expect($updated_form->created_at)->equals($created_at);
|
||||
$is_time_updated = (
|
||||
$updated_form->updated_at > $updated_form->created_at
|
||||
);
|
||||
expect($is_time_updated)->true();
|
||||
}
|
||||
|
||||
function itCanCreateOrUpdate() {
|
||||
$is_created = Form::createOrUpdate(array(
|
||||
'name' => 'new form'
|
||||
$created_form = Form::createOrUpdate(array(
|
||||
'name' => 'Created Form'
|
||||
));
|
||||
expect($is_created)->notEquals(false);
|
||||
expect($is_created->getValidationErrors())->isEmpty();
|
||||
expect($created_form->id > 0)->true();
|
||||
expect($created_form->getErrors())->false();
|
||||
|
||||
$form = Form::where('name', 'new form')->findOne();
|
||||
expect($form->name)->equals('new form');
|
||||
$form = Form::findOne($created_form->id);
|
||||
expect($form->name)->equals('Created Form');
|
||||
|
||||
$is_updated = Form::createOrUpdate(array(
|
||||
'id' => $form->id,
|
||||
'name' => 'updated form'
|
||||
'id' => $created_form->id,
|
||||
'name' => 'Updated Form'
|
||||
));
|
||||
$form = Form::where('name', 'updated form')->findOne();
|
||||
expect($form->name)->equals('updated form');
|
||||
$form = Form::findOne($created_form->id);
|
||||
expect($form->name)->equals('Updated Form');
|
||||
}
|
||||
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Form::$_table)
|
||||
->deleteMany();
|
||||
Form::deleteMany();
|
||||
}
|
||||
}
|
||||
|
@ -2,76 +2,109 @@
|
||||
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\NewsletterSegment;
|
||||
use MailPoet\Models\NewsletterOptionField;
|
||||
use MailPoet\Models\NewsletterOption;
|
||||
|
||||
class NewsletterCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'subject' => 'new newsletter',
|
||||
'type' => 'standard',
|
||||
'body' => 'body',
|
||||
'preheader' => 'preheader'
|
||||
);
|
||||
$this->newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My Standard Newsletter',
|
||||
'preheader' => 'Pre Header',
|
||||
'type' => 'standard'
|
||||
));
|
||||
|
||||
$newsletter = Newsletter::create();
|
||||
$newsletter->hydrate($this->data);
|
||||
$this->newsletter = $newsletter;
|
||||
$this->saved = $newsletter->save();
|
||||
$this->segment_1 = Segment::createOrUpdate(array(
|
||||
'name' => 'Segment 1'
|
||||
));
|
||||
$association = NewsletterSegment::create();
|
||||
$association->newsletter_id = $this->newsletter->id;
|
||||
$association->segment_id = $this->segment_1->id;
|
||||
$association->save();
|
||||
|
||||
$this->segment_2 = Segment::createOrUpdate(array(
|
||||
'name' => 'Segment 2'
|
||||
));
|
||||
$association = NewsletterSegment::create();
|
||||
$association->newsletter_id = $this->newsletter->id;
|
||||
$association->segment_id = $this->segment_2->id;
|
||||
$association->save();
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
expect($this->saved->id() > 0)->true();
|
||||
expect($this->saved->getErrors())->false();
|
||||
expect($this->newsletter->id() > 0)->true();
|
||||
expect($this->newsletter->getErrors())->false();
|
||||
}
|
||||
|
||||
function itHasSubject() {
|
||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
||||
->findOne();
|
||||
expect($newsletter->subject)->equals($this->data['subject']);
|
||||
function itHasASubject() {
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
expect($newsletter->subject)->equals($this->newsletter->subject);
|
||||
}
|
||||
|
||||
function itHasType() {
|
||||
$newsletter = Newsletter::where('type', $this->data['type'])
|
||||
->findOne();
|
||||
expect($newsletter->type)->equals($this->data['type']);
|
||||
function itHasAType() {
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
expect($newsletter->type)->equals($this->newsletter->type);
|
||||
}
|
||||
|
||||
function itHasBody() {
|
||||
$newsletter = Newsletter::where('body', $this->data['body'])
|
||||
->findOne();
|
||||
expect($newsletter->body)->equals($this->data['body']);
|
||||
function itHasABody() {
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
expect($newsletter->body)->equals($this->newsletter->body);
|
||||
}
|
||||
|
||||
function itHasPreheader() {
|
||||
$newsletter = Newsletter::where('preheader', $this->data['preheader'])
|
||||
->findOne();
|
||||
expect($newsletter->preheader)->equals($this->data['preheader']);
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
expect($newsletter->preheader)->equals($this->newsletter->preheader);
|
||||
}
|
||||
|
||||
function itCanHaveASegment() {
|
||||
$segmentData = array(
|
||||
'name' => 'my first list'
|
||||
);
|
||||
function itHasACreatedAtOnCreation() {
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
expect($newsletter->created_at)->notNull();
|
||||
expect($newsletter->created_at)->notEquals('0000-00-00 00:00:00');
|
||||
}
|
||||
|
||||
$segment = Segment::create();
|
||||
$segment->hydrate($segmentData);
|
||||
$segment->save();
|
||||
function itHasAnUpdatedAtOnCreation() {
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
expect($newsletter->updated_at)
|
||||
->equals($newsletter->created_at);
|
||||
}
|
||||
|
||||
$newsletter = Newsletter::create();
|
||||
$newsletter->hydrate($this->data);
|
||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||
$created_at = $newsletter->created_at;
|
||||
|
||||
sleep(1);
|
||||
|
||||
$newsletter->subject = 'New Subject';
|
||||
$newsletter->save();
|
||||
|
||||
$association = NewsletterSegment::create();
|
||||
$association->newsletter_id = $newsletter->id();
|
||||
$association->segment_id = $segment->id();
|
||||
$association->save();
|
||||
$updated_newsletter = Newsletter::findOne($newsletter->id);
|
||||
expect($updated_newsletter->created_at)->equals($created_at);
|
||||
$is_time_updated = (
|
||||
$updated_newsletter->updated_at > $updated_newsletter->created_at
|
||||
);
|
||||
expect($is_time_updated)->true();
|
||||
}
|
||||
|
||||
$newsletter = Newsletter::findOne($newsletter->id);
|
||||
$newsletterSegment = $newsletter->segments()->findOne();
|
||||
expect($newsletterSegment->id)->equals($segment->id);
|
||||
function itCanBeQueued() {
|
||||
$queue = $this->newsletter->getQueue();
|
||||
expect($queue)->false();
|
||||
|
||||
$sending_queue = SendingQueue::create();
|
||||
$sending_queue->newsletter_id = $this->newsletter->id;
|
||||
$sending_queue->save();
|
||||
|
||||
$queue = $this->newsletter->getQueue();
|
||||
expect($queue->id() > 0)->true();
|
||||
}
|
||||
|
||||
function itCanHaveSegments() {
|
||||
$newsletter_segments = $this->newsletter->segments()->findArray();
|
||||
expect($newsletter_segments)->count(2);
|
||||
expect($newsletter_segments[0]['id'])->equals($this->segment_1->id);
|
||||
expect($newsletter_segments[0]['name'])->equals('Segment 1');
|
||||
expect($newsletter_segments[1]['id'])->equals($this->segment_2->id);
|
||||
expect($newsletter_segments[1]['name'])->equals('Segment 2');
|
||||
}
|
||||
|
||||
function itCanCreateOrUpdate() {
|
||||
@ -97,6 +130,54 @@ class NewsletterCest {
|
||||
expect($newsletter->subject)->equals('updated newsletter');
|
||||
}
|
||||
|
||||
function itCannotSetAnEmptyDeletedAt() {
|
||||
$this->newsletter->deleted_at = '';
|
||||
$newsletter = $this->newsletter->save();
|
||||
expect($newsletter->deleted_at)->equals('NULL');
|
||||
}
|
||||
|
||||
function itCanBeFilteredBySegment() {
|
||||
// no filter
|
||||
$newsletters = Newsletter::filter('filterBy')->findArray();
|
||||
expect($newsletters)->count(1);
|
||||
|
||||
// filter by segment
|
||||
$newsletters = Newsletter::filter('filterBy', array(
|
||||
'segment' => $this->segment_1->id
|
||||
))->findArray();
|
||||
|
||||
expect($newsletters)->count(1);
|
||||
expect($newsletters[0]['subject'])->equals($this->newsletter->subject);
|
||||
|
||||
// remove all segment relations to newsletters
|
||||
NewsletterSegment::deleteMany();
|
||||
|
||||
$newsletters = Newsletter::filter('filterBy', array(
|
||||
'segment' => $this->segment_1->id
|
||||
))->findArray();
|
||||
|
||||
expect($newsletters)->isEmpty();
|
||||
}
|
||||
|
||||
function itCanBeGrouped() {
|
||||
$newsletters = Newsletter::filter('groupBy', 'all')->findArray();
|
||||
expect($newsletters)->count(1);
|
||||
|
||||
$newsletters = Newsletter::filter('groupBy', 'trash')->findArray();
|
||||
expect($newsletters)->count(0);
|
||||
|
||||
$this->newsletter->trash();
|
||||
$newsletters = Newsletter::filter('groupBy', 'trash')->findArray();
|
||||
expect($newsletters)->count(1);
|
||||
|
||||
$newsletters = Newsletter::filter('groupBy', 'all')->findArray();
|
||||
expect($newsletters)->count(0);
|
||||
|
||||
$this->newsletter->restore();
|
||||
$newsletters = Newsletter::filter('groupBy', 'all')->findArray();
|
||||
expect($newsletters)->count(1);
|
||||
}
|
||||
|
||||
function itHasSearchFilter() {
|
||||
Newsletter::createOrUpdate(
|
||||
array(
|
||||
@ -110,16 +191,16 @@ class NewsletterCest {
|
||||
}
|
||||
|
||||
function itCanHaveOptions() {
|
||||
$newsletterOptionFieldData = array(
|
||||
$newsletter_options = array(
|
||||
'name' => 'Event',
|
||||
'newsletter_type' => 'welcome',
|
||||
);
|
||||
$optionField = NewsletterOptionField::create();
|
||||
$optionField->hydrate($newsletterOptionFieldData);
|
||||
$optionField->save();
|
||||
$option_field = NewsletterOptionField::create();
|
||||
$option_field->hydrate($newsletter_options);
|
||||
$option_field->save();
|
||||
$association = NewsletterOption::create();
|
||||
$association->newsletter_id = $this->newsletter->id;
|
||||
$association->option_field_id = $optionField->id;
|
||||
$association->option_field_id = $option_field->id;
|
||||
$association->value = 'list';
|
||||
$association->save();
|
||||
$newsletter = Newsletter::filter('filterWithOptions')
|
||||
@ -128,7 +209,7 @@ class NewsletterCest {
|
||||
}
|
||||
|
||||
function itCanFilterOptions() {
|
||||
$newsletterOptionFieldData = array(
|
||||
$newsletter_options = array(
|
||||
array(
|
||||
'name' => 'Event',
|
||||
'newsletter_type' => 'welcome',
|
||||
@ -138,13 +219,13 @@ class NewsletterCest {
|
||||
'newsletter_type' => 'welcome',
|
||||
)
|
||||
);
|
||||
foreach ($newsletterOptionFieldData as $data) {
|
||||
$optionField = NewsletterOptionField::create();
|
||||
$optionField->hydrate($data);
|
||||
$optionField->save();
|
||||
$createdOptionFields[] = $optionField->asArray();
|
||||
foreach ($newsletter_options as $data) {
|
||||
$option_field = NewsletterOptionField::create();
|
||||
$option_field->hydrate($data);
|
||||
$option_field->save();
|
||||
$createdOptionFields[] = $option_field->asArray();
|
||||
}
|
||||
$newsletterOptionData = array(
|
||||
$newsletter_options = array(
|
||||
array(
|
||||
'newsletter_id' => $this->newsletter->id,
|
||||
'option_field_id' => $createdOptionFields[0]['id'],
|
||||
@ -156,12 +237,12 @@ class NewsletterCest {
|
||||
'value' => '1'
|
||||
)
|
||||
);
|
||||
foreach ($newsletterOptionData as $data) {
|
||||
foreach($newsletter_options as $data) {
|
||||
$association = NewsletterOption::create();
|
||||
$association->hydrate($data);
|
||||
$association->save();
|
||||
$createdAssociations[] = $association->asArray();
|
||||
}
|
||||
|
||||
$newsletter = Newsletter::filter('filterWithOptions')
|
||||
->filter('filterSearchCustomFields', array(
|
||||
array(
|
||||
@ -200,11 +281,11 @@ class NewsletterCest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(NewsletterOption::$_table)
|
||||
->deleteMany();
|
||||
ORM::forTable(NewsletterOptionField::$_table)
|
||||
->deleteMany();
|
||||
ORM::for_table(Newsletter::$_table)
|
||||
->deleteMany();
|
||||
NewsletterOption::deleteMany();
|
||||
NewsletterOptionField::deleteMany();
|
||||
Newsletter::deleteMany();
|
||||
Segment::deleteMany();
|
||||
NewsletterSegment::deleteMany();
|
||||
SendingQueue::deleteMany();
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ use MailPoet\Models\NewsletterOptionField;
|
||||
|
||||
class NewsletterOptionFieldCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'name' => 'Event',
|
||||
'newsletter_type' => 'welcome'
|
||||
);
|
||||
$this->option_field = NewsletterOptionField::create();
|
||||
$this->option_field->hydrate($this->data);
|
||||
$this->saved = $this->option_field->save();
|
||||
$option = NewsletterOptionField::create();
|
||||
$option->hydrate($this->data);
|
||||
$this->option_field = $option->save();
|
||||
|
||||
$this->newsletter_data = array(
|
||||
array(
|
||||
'subject' => 'Test newsletter 1',
|
||||
@ -31,20 +31,17 @@ class NewsletterOptionFieldCest {
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
expect($this->saved->id() > 0)->true();
|
||||
expect($this->saved->getErrors())->false();
|
||||
expect($this->option_field->id() > 0)->true();
|
||||
expect($this->option_field->getErrors())->false();
|
||||
}
|
||||
|
||||
function itHasName() {
|
||||
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
expect($option_field->name)->equals($this->data['name']);
|
||||
expect($this->option_field->name)->equals($this->data['name']);
|
||||
}
|
||||
|
||||
function itHasNewsletterType() {
|
||||
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
expect($option_field->newsletter_type)->equals($this->data['newsletter_type']);
|
||||
expect($this->option_field->newsletter_type)
|
||||
->equals($this->data['newsletter_type']);
|
||||
}
|
||||
|
||||
function itHasToBeValid() {
|
||||
@ -58,36 +55,31 @@ class NewsletterOptionFieldCest {
|
||||
}
|
||||
|
||||
function itHasACreatedAtOnCreation() {
|
||||
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($option_field->created_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
$option_field = NewsletterOptionField::findOne($this->option_field->id);
|
||||
expect($option_field->created_at)->notNull();
|
||||
expect($option_field->created_at)->notEquals('0000-00-00 00:00:00');
|
||||
}
|
||||
|
||||
function itHasAnUpdatedAtOnCreation() {
|
||||
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($option_field->updated_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
}
|
||||
|
||||
function itKeepsTheCreatedAtOnUpdate() {
|
||||
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$old_created_at = $option_field->created_at;
|
||||
$option_field->name = 'new name';
|
||||
$option_field->save();
|
||||
expect($old_created_at)->equals($option_field->created_at);
|
||||
$option_field = NewsletterOptionField::findOne($this->option_field->id);
|
||||
expect($option_field->updated_at)
|
||||
->equals($option_field->created_at);
|
||||
}
|
||||
|
||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$update_time = time();
|
||||
$option_field = NewsletterOptionField::findOne($this->option_field->id);
|
||||
$created_at = $option_field->created_at;
|
||||
|
||||
sleep(1);
|
||||
|
||||
$option_field->name = 'new name';
|
||||
$option_field->save();
|
||||
$time_difference = strtotime($option_field->updated_at) >= $update_time;
|
||||
expect($time_difference)->equals(true);
|
||||
|
||||
$updated_option_field = NewsletterOptionField::findOne($option_field->id);
|
||||
$is_time_updated = (
|
||||
$updated_option_field->updated_at > $updated_option_field->created_at
|
||||
);
|
||||
expect($is_time_updated)->true();
|
||||
}
|
||||
|
||||
function itCanHaveManyNewsletters() {
|
||||
|
@ -4,7 +4,6 @@ use MailPoet\Models\NewsletterTemplate;
|
||||
|
||||
class NewsletterTemplateCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'name' => 'Some template',
|
||||
'description' => 'My nice template',
|
||||
|
@ -8,11 +8,12 @@ use MailPoet\Models\SubscriberSegment;
|
||||
|
||||
class SegmentCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'name' => 'some name',
|
||||
'description' => 'some description'
|
||||
);
|
||||
$this->segment = Segment::createOrUpdate($this->data);
|
||||
|
||||
$this->subscribers_data = array(
|
||||
array(
|
||||
'first_name' => 'John',
|
||||
@ -37,7 +38,6 @@ class SegmentCest {
|
||||
'type' => 'standard'
|
||||
)
|
||||
);
|
||||
$this->segment = Segment::createOrUpdate($this->data);
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
@ -56,7 +56,9 @@ class SegmentCest {
|
||||
$errors = $result->getErrors();
|
||||
|
||||
expect(is_array($errors))->true();
|
||||
expect($errors[0])->contains('Duplicate');
|
||||
expect($errors[0])->equals(
|
||||
'Another record already exists. Please specify a different "name".'
|
||||
);
|
||||
}
|
||||
|
||||
function itCanHaveDescription() {
|
||||
@ -74,36 +76,32 @@ class SegmentCest {
|
||||
}
|
||||
|
||||
function itHasACreatedAtOnCreation() {
|
||||
$segment = Segment::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($segment->created_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
$segment = Segment::findOne($this->segment->id);
|
||||
expect($segment->created_at)->notNull();
|
||||
expect($segment->created_at)->notEquals('0000-00-00 00:00:00');
|
||||
}
|
||||
|
||||
function itHasAnUpdatedAtOnCreation() {
|
||||
$segment = Segment::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($segment->updated_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
}
|
||||
|
||||
function itKeepsTheCreatedAtOnUpdate() {
|
||||
$segment = Segment::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$old_created_at = $segment->created_at;
|
||||
$segment->name = 'new name';
|
||||
$segment->save();
|
||||
expect($old_created_at)->equals($segment->created_at);
|
||||
$segment = Segment::findOne($this->segment->id);
|
||||
expect($segment->updated_at)
|
||||
->equals($segment->created_at);
|
||||
}
|
||||
|
||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||
$segment = Segment::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$update_time = time();
|
||||
$segment = Segment::findOne($this->segment->id);
|
||||
$created_at = $segment->created_at;
|
||||
|
||||
sleep(1);
|
||||
|
||||
$segment->name = 'new name';
|
||||
$segment->save();
|
||||
$time_difference = strtotime($segment->updated_at) >= $update_time;
|
||||
expect($time_difference)->equals(true);
|
||||
|
||||
$updated_segment = Segment::findOne($segment->id);
|
||||
expect($updated_segment->created_at)->equals($created_at);
|
||||
$is_time_updated = (
|
||||
$updated_segment->updated_at > $updated_segment->created_at
|
||||
);
|
||||
expect($is_time_updated)->true();
|
||||
}
|
||||
|
||||
function itCanCreateOrUpdate() {
|
||||
|
@ -2,63 +2,61 @@
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class SettingCest {
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'name' => 'sending_method',
|
||||
'value' => 'smtp'
|
||||
);
|
||||
|
||||
$setting = Setting::create();
|
||||
$setting->hydrate($this->data);
|
||||
$this->saved = $setting->save();
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
expect($this->saved->id() > 0)->true();
|
||||
expect($this->saved->getErrors())->false();
|
||||
$setting = Setting::createOrUpdate(array(
|
||||
'name' => 'key',
|
||||
'value' => 'val'
|
||||
));
|
||||
expect($setting->id() > 0)->true();
|
||||
expect($setting->getErrors())->false();
|
||||
}
|
||||
|
||||
function itHasToBeValid() {
|
||||
$invalid_setting = Setting::create();
|
||||
$result = $invalid_setting->save();
|
||||
$errors = $result->getErrors();
|
||||
$invalid_setting = Setting::createOrUpdate();
|
||||
$errors = $invalid_setting->getErrors();
|
||||
|
||||
expect(is_array($errors))->true();
|
||||
expect($errors)->notEmpty();
|
||||
expect($errors[0])->equals('You need to specify a name.');
|
||||
}
|
||||
|
||||
function itHasACreatedAtOnCreation() {
|
||||
$setting = Setting::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($setting->created_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
function itCanGetAllSettings() {
|
||||
Setting::setValue('key_1', 'value_1');
|
||||
Setting::setValue('key_2', 'value_2');
|
||||
Setting::setValue('key_3', array(
|
||||
'subkey_1' => 'subvalue_1',
|
||||
'subkey_2' => 'subvalue_2'
|
||||
));
|
||||
|
||||
$settings = Setting::getAll();
|
||||
expect(array_keys($settings))->count(3);
|
||||
expect($settings['key_1'])->equals('value_1');
|
||||
expect($settings['key_2'])->equals('value_2');
|
||||
expect($settings['key_3'])->equals(array(
|
||||
'subkey_1' => 'subvalue_1',
|
||||
'subkey_2' => 'subvalue_2'
|
||||
));
|
||||
}
|
||||
|
||||
function itHasAnUpdatedAtOnCreation() {
|
||||
$setting = Setting::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$time_difference = strtotime($setting->updated_at) >= $this->before_time;
|
||||
expect($time_difference)->equals(true);
|
||||
}
|
||||
function itReturnsDefaultValueIfNotSet() {
|
||||
// try to get an "unknown" key
|
||||
$setting = Setting::getValue('unknown_key', 'default_value');
|
||||
expect($setting)->equals('default_value');
|
||||
|
||||
function itKeepsTheCreatedAtOnUpdate() {
|
||||
$setting = Setting::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$old_created_at = $setting->created_at;
|
||||
$setting->value = 'http_api';
|
||||
$setting->save();
|
||||
expect($old_created_at)->equals($setting->created_at);
|
||||
}
|
||||
// setting a "known" key
|
||||
$setting = Setting::setValue('known_key', 'actual_value');
|
||||
expect($setting)->equals(true);
|
||||
|
||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||
$setting = Setting::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
$update_time = time();
|
||||
$setting->value = 'http_api';
|
||||
$setting->save();
|
||||
$time_difference = strtotime($setting->updated_at) >= $update_time;
|
||||
expect($time_difference)->equals(true);
|
||||
// try to get a "known" key
|
||||
$setting = Setting::getValue('known_key', 'default_value');
|
||||
expect($setting)->equals('actual_value');
|
||||
|
||||
// try to get an "unknown" subkey of a "known" key
|
||||
$setting = Setting::getValue('known_key.unknown_subkey', 'default_value');
|
||||
expect($setting)->equals('default_value');
|
||||
|
||||
// try to get an "unknown" subkey of an "unknown" key
|
||||
$setting = Setting::getValue('unknown_key.unknown_subkey', 'default_value');
|
||||
expect($setting)->equals('default_value');
|
||||
}
|
||||
|
||||
function itCanCreateOrUpdate() {
|
||||
@ -109,7 +107,6 @@ class SettingCest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Setting::$_table)
|
||||
->deleteMany();
|
||||
Setting::deleteMany();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class NewsletterRendererCest {
|
||||
$this->DOM_parser = new \pQuery();
|
||||
}
|
||||
|
||||
|
||||
function itRendersCompleteNewsletter() {
|
||||
$template = $this->renderer->render();
|
||||
expect(isset($template['html']))->true();
|
||||
@ -125,17 +126,33 @@ class NewsletterRendererCest {
|
||||
expect($DOM('tr > td > img', 0)->attr('style'))->notEmpty();
|
||||
}
|
||||
|
||||
function itAdjustImageSizeBasedOnColumnWidth() {
|
||||
$newsletter = json_decode($this->newsletter['body'], true);
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
||||
$template['width'] = '800px';
|
||||
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 2));
|
||||
// 800px resized to 330px (2-column layout) and 40px padding applied
|
||||
expect($DOM('tr > td > img', 0)->attr('width'))->equals(290);
|
||||
$template['width'] = '280px';
|
||||
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 2));
|
||||
// 280px image should not be resized and padding should not be applied
|
||||
expect($DOM('tr > td > img', 0)->attr('width'))->equals(280);
|
||||
function itAdjustsImageDimensions() {
|
||||
// image gets scaled down when image width > column width
|
||||
$image = array(
|
||||
'width' => 800,
|
||||
'height' => 600,
|
||||
'fullWidth' => true
|
||||
);
|
||||
$new_image_dimensions = Image::adjustImageDimensions($image, $columnCount = 1);
|
||||
expect($new_image_dimensions['width'])->equals(660);
|
||||
expect($new_image_dimensions['height'])->equals(495);
|
||||
// nothing happens when image width = column width
|
||||
$image['width'] = 661;
|
||||
$new_image_dimensions = Image::adjustImageDimensions($image, $columnCount = 1);
|
||||
expect($new_image_dimensions['width'])->equals(660);
|
||||
// nothing happens when image width < column width
|
||||
$image['width'] = 659;
|
||||
$new_image_dimensions = Image::adjustImageDimensions($image, $columnCount = 1);
|
||||
expect($new_image_dimensions['width'])->equals(659);
|
||||
// image is reduced by 40px when it's width > padded column width
|
||||
$image['width'] = 621;
|
||||
$image['fullWidth'] = false;
|
||||
$new_image_dimensions = Image::adjustImageDimensions($image, $columnCount = 1);
|
||||
expect($new_image_dimensions['width'])->equals(620);
|
||||
// nothing happens when image with < padded column width
|
||||
$image['width'] = 619;
|
||||
$new_image_dimensions = Image::adjustImageDimensions($image, $columnCount = 1);
|
||||
expect($new_image_dimensions['width'])->equals(619);
|
||||
}
|
||||
|
||||
function itRendersText() {
|
||||
|
@ -44,7 +44,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/660.png",
|
||||
"alt": "660",
|
||||
"padded": true,
|
||||
"fullWidth": false,
|
||||
"width": "660px",
|
||||
"height": "250px",
|
||||
"styles": {
|
||||
@ -199,7 +199,7 @@
|
||||
"link": "http://example.org",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/660.png",
|
||||
"alt": "660",
|
||||
"padded": false,
|
||||
"fullWidth": true,
|
||||
"width": "660px",
|
||||
"height": "250px",
|
||||
"styles": {
|
||||
@ -235,7 +235,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/330x125.png",
|
||||
"alt": "330x125",
|
||||
"padded": true,
|
||||
"fullWidth": false,
|
||||
"width": "330px",
|
||||
"height": "125px",
|
||||
"styles": {
|
||||
@ -390,7 +390,7 @@
|
||||
"link": "http://example.org",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/330x125.png",
|
||||
"alt": "330x125",
|
||||
"padded": false,
|
||||
"fullWidth": true,
|
||||
"width": "330px",
|
||||
"height": "125px",
|
||||
"styles": {
|
||||
@ -415,7 +415,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/330x125-copy-150x57.png",
|
||||
"alt": "330x125 copy",
|
||||
"padded": true,
|
||||
"fullWidth": false,
|
||||
"width": "150px",
|
||||
"height": "57px",
|
||||
"styles": {
|
||||
@ -561,7 +561,7 @@
|
||||
"link": "http://example.org",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/330x125.png",
|
||||
"alt": "330x125",
|
||||
"padded": false,
|
||||
"fullWidth": true,
|
||||
"width": "330px",
|
||||
"height": "125px",
|
||||
"styles": {
|
||||
@ -606,7 +606,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/220x83-copy.png",
|
||||
"alt": "220x83 copy",
|
||||
"padded": true,
|
||||
"fullWidth": false,
|
||||
"width": "100px",
|
||||
"height": "38px",
|
||||
"styles": {
|
||||
@ -761,7 +761,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/220x83.png",
|
||||
"alt": "220x83",
|
||||
"padded": false,
|
||||
"fullWidth": true,
|
||||
"width": "220px",
|
||||
"height": "83px",
|
||||
"styles": {
|
||||
@ -786,7 +786,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/220x83.png",
|
||||
"alt": "220x83",
|
||||
"padded": true,
|
||||
"fullWidth": false,
|
||||
"width": "220px",
|
||||
"height": "83px",
|
||||
"styles": {
|
||||
@ -941,7 +941,7 @@
|
||||
"link": "http://example.org",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/220x83.png",
|
||||
"alt": "220x83",
|
||||
"padded": false,
|
||||
"fullWidth": true,
|
||||
"width": "220px",
|
||||
"height": "83px",
|
||||
"styles": {
|
||||
@ -966,7 +966,7 @@
|
||||
"link": "",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/220x83.png",
|
||||
"alt": "220x83",
|
||||
"padded": true,
|
||||
"fullWidth": false,
|
||||
"width": "220px",
|
||||
"height": "83px",
|
||||
"styles": {
|
||||
@ -1121,7 +1121,7 @@
|
||||
"link": "http://example.org",
|
||||
"src": "http://test.mailpoet.net/wp-content/uploads/2015/12/220x83.png",
|
||||
"alt": "220x83",
|
||||
"padded": false,
|
||||
"fullWidth": true,
|
||||
"width": "220px",
|
||||
"height": "83px",
|
||||
"styles": {
|
||||
@ -1215,4 +1215,4 @@
|
||||
"backgroundColor": "#333333"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,13 +69,17 @@ class CustomFieldsCest {
|
||||
|
||||
function itCanDeleteACustomField() {
|
||||
$custom_field = CustomField::where('type', 'date')->findOne();
|
||||
$custom_field_id = $custom_field->id();
|
||||
|
||||
$router = new CustomFields();
|
||||
$response = $router->delete($custom_field->id());
|
||||
$response = $router->delete($custom_field_id);
|
||||
expect($response['result'])->true();
|
||||
|
||||
$custom_field = CustomField::where('type', 'date')->findOne();
|
||||
expect($custom_field)->false();
|
||||
|
||||
$response = $router->delete($custom_field_id);
|
||||
expect($response['result'])->false();
|
||||
}
|
||||
|
||||
function itCanSaveACustomField() {
|
||||
@ -120,6 +124,6 @@ class CustomFieldsCest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(CustomField::$_table)->deleteMany();
|
||||
CustomField::deleteMany();
|
||||
}
|
||||
}
|
@ -165,6 +165,28 @@ class FormsCest {
|
||||
expect($duplicated_form->name)->equals('Copy of '.$form->name);
|
||||
}
|
||||
|
||||
function itCanBulkDeleteForms() {
|
||||
expect(Form::count())->equals(3);
|
||||
|
||||
$forms = Form::findMany();
|
||||
foreach($forms as $form) {
|
||||
$form->trash();
|
||||
}
|
||||
|
||||
$router = new Forms();
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(3);
|
||||
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(0);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
Form::deleteMany();
|
||||
Segment::deleteMany();
|
||||
|
@ -7,20 +7,22 @@ use \MailPoet\Models\Segment;
|
||||
|
||||
class NewslettersCest {
|
||||
function _before() {
|
||||
$this->newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My Standard Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
|
||||
$this->post_notification = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My Post Notification',
|
||||
'type' => 'notification'
|
||||
));
|
||||
}
|
||||
|
||||
function itCanGetANewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
expect($newsletter->id() > 0)->true();
|
||||
|
||||
$router = new Newsletters();
|
||||
|
||||
$response = $router->get($newsletter->id());
|
||||
|
||||
expect($response['id'])->equals($newsletter->id());
|
||||
$response = $router->get($this->newsletter->id());
|
||||
expect($response['id'])->equals($this->newsletter->id());
|
||||
|
||||
$response = $router->get('not_an_id');
|
||||
expect($response)->false();
|
||||
@ -50,82 +52,57 @@ class NewslettersCest {
|
||||
}
|
||||
|
||||
function itCanSaveAnExistingNewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
expect($newsletter->id() > 0)->true();
|
||||
|
||||
$router = new Newsletters();
|
||||
$newsletter_data = $newsletter->asArray();
|
||||
$newsletter_data = $this->newsletter->asArray();
|
||||
$newsletter_data['subject'] = 'My Updated Newsletter';
|
||||
|
||||
$response = $router->save($newsletter_data);
|
||||
expect($response['result'])->true();
|
||||
|
||||
$updated_newsletter = Newsletter::findOne($newsletter->id());
|
||||
$updated_newsletter = Newsletter::findOne($this->newsletter->id());
|
||||
expect($updated_newsletter->subject)->equals('My Updated Newsletter');
|
||||
}
|
||||
|
||||
function itCanRestoreANewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
expect($newsletter->id() > 0)->true();
|
||||
$this->newsletter->trash();
|
||||
|
||||
$newsletter->trash();
|
||||
|
||||
expect($newsletter->deleted_at)->notNull();
|
||||
expect($this->newsletter->deleted_at)->notNull();
|
||||
|
||||
$router = new Newsletters();
|
||||
$router->restore($newsletter->id());
|
||||
$router->restore($this->newsletter->id());
|
||||
|
||||
$restored_subscriber = Newsletter::findOne($newsletter->id());
|
||||
$restored_subscriber = Newsletter::findOne($this->newsletter->id());
|
||||
expect($restored_subscriber->deleted_at)->null();
|
||||
}
|
||||
|
||||
function itCanTrashANewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
expect($newsletter->id() > 0)->true();
|
||||
|
||||
$router = new Newsletters();
|
||||
$response = $router->trash($newsletter->id());
|
||||
$response = $router->trash($this->newsletter->id());
|
||||
expect($response)->true();
|
||||
|
||||
$trashed_subscriber = Newsletter::findOne($newsletter->id());
|
||||
$trashed_subscriber = Newsletter::findOne($this->newsletter->id());
|
||||
expect($trashed_subscriber->deleted_at)->notNull();
|
||||
}
|
||||
|
||||
function itCanDeleteANewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
expect($newsletter->id() > 0)->true();
|
||||
|
||||
$router = new Newsletters();
|
||||
$response = $router->delete($newsletter->id());
|
||||
$response = $router->delete($this->newsletter->id());
|
||||
expect($response)->equals(1);
|
||||
|
||||
expect(Newsletter::findOne($newsletter->id()))->false();
|
||||
expect(Newsletter::findOne($this->newsletter->id()))->false();
|
||||
}
|
||||
|
||||
function itCanDuplicateANewsletter() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
expect($newsletter->id() > 0)->true();
|
||||
|
||||
$router = new Newsletters();
|
||||
$response = $router->duplicate($newsletter->id());
|
||||
expect($response['subject'])->equals('Copy of My First Newsletter');
|
||||
$response = $router->duplicate($this->newsletter->id());
|
||||
expect($response['subject'])->equals('Copy of My Standard Newsletter');
|
||||
expect($response['type'])->equals('standard');
|
||||
expect($response['body'])->equals($newsletter->body);
|
||||
expect($response['body'])->equals($this->newsletter->body);
|
||||
|
||||
$response = $router->duplicate($this->post_notification->id());
|
||||
expect($response['subject'])->equals('Copy of My Post Notification');
|
||||
expect($response['type'])->equals('notification');
|
||||
expect($response['body'])->equals($this->post_notification->body);
|
||||
}
|
||||
|
||||
function itCanCreateANewsletter() {
|
||||
@ -151,38 +128,29 @@ class NewslettersCest {
|
||||
$segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
$segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
|
||||
$newsletter_1 = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
$newsletter_2 = Newsletter::createOrUpdate(array(
|
||||
'subject' => 'My Second Newsletter',
|
||||
'type' => 'standard'
|
||||
));
|
||||
|
||||
$newsletter_segment = NewsletterSegment::create();
|
||||
$newsletter_segment->hydrate(array(
|
||||
'newsletter_id' => $newsletter_1->id(),
|
||||
'newsletter_id' => $this->newsletter->id(),
|
||||
'segment_id' => $segment_1->id()
|
||||
));
|
||||
$newsletter_segment->save();
|
||||
|
||||
$newsletter_segment = NewsletterSegment::create();
|
||||
$newsletter_segment->hydrate(array(
|
||||
'newsletter_id' => $newsletter_1->id(),
|
||||
'newsletter_id' => $this->newsletter->id(),
|
||||
'segment_id' => $segment_2->id()
|
||||
));
|
||||
$newsletter_segment->save();
|
||||
|
||||
$newsletter_segment = NewsletterSegment::create();
|
||||
$newsletter_segment->hydrate(array(
|
||||
'newsletter_id' => $newsletter_2->id(),
|
||||
'newsletter_id' => $this->post_notification->id(),
|
||||
'segment_id' => $segment_2->id()
|
||||
));
|
||||
$newsletter_segment->save();
|
||||
|
||||
$router = new Newsletters();
|
||||
$response = $router->listing(array('sort'));
|
||||
$response = $router->listing();
|
||||
|
||||
expect($response)->hasKey('filters');
|
||||
expect($response)->hasKey('groups');
|
||||
@ -190,8 +158,8 @@ class NewslettersCest {
|
||||
expect($response['count'])->equals(2);
|
||||
expect($response['items'])->count(2);
|
||||
|
||||
expect($response['items'][0]['subject'])->equals('My First Newsletter');
|
||||
expect($response['items'][1]['subject'])->equals('My Second Newsletter');
|
||||
expect($response['items'][0]['subject'])->equals('My Standard Newsletter');
|
||||
expect($response['items'][1]['subject'])->equals('My Post Notification');
|
||||
expect($response['items'][0]['segments'])->equals(array(
|
||||
$segment_1->id(),
|
||||
$segment_2->id()
|
||||
@ -201,6 +169,28 @@ class NewslettersCest {
|
||||
));
|
||||
}
|
||||
|
||||
function itCanBulkDeleteNewsletters() {
|
||||
expect(Newsletter::count())->equals(2);
|
||||
|
||||
$newsletters = Newsletter::findMany();
|
||||
foreach($newsletters as $newsletter) {
|
||||
$newsletter->trash();
|
||||
}
|
||||
|
||||
$router = new Newsletters();
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(2);
|
||||
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(0);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
Newsletter::deleteMany();
|
||||
Segment::deleteMany();
|
||||
|
@ -4,14 +4,12 @@ use \MailPoet\Models\Segment;
|
||||
|
||||
class SegmentsCest {
|
||||
function _before() {
|
||||
Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
Segment::createOrUpdate(array('name' => 'Segment 3'));
|
||||
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
$this->segment_3 = Segment::createOrUpdate(array('name' => 'Segment 3'));
|
||||
}
|
||||
|
||||
function itCanGetASegment() {
|
||||
$segment = Segment::where('name', 'Segment 1')->findOne();
|
||||
|
||||
$router = new Segments();
|
||||
|
||||
$response = $router->get(/* missing id */);
|
||||
@ -20,8 +18,8 @@ class SegmentsCest {
|
||||
$response = $router->get('not_an_id');
|
||||
expect($response)->false();
|
||||
|
||||
$response = $router->get($segment->id());
|
||||
expect($response['name'])->equals($segment->name);
|
||||
$response = $router->get($this->segment_1->id());
|
||||
expect($response['name'])->equals($this->segment_1->name);
|
||||
}
|
||||
|
||||
function itCanGetListingData() {
|
||||
@ -33,9 +31,9 @@ class SegmentsCest {
|
||||
expect($response['count'])->equals(3);
|
||||
expect($response['items'])->count(3);
|
||||
|
||||
expect($response['items'][0]['name'])->equals('Segment 1');
|
||||
expect($response['items'][1]['name'])->equals('Segment 2');
|
||||
expect($response['items'][2]['name'])->equals('Segment 3');
|
||||
expect($response['items'][0]['name'])->equals($this->segment_1->name);
|
||||
expect($response['items'][1]['name'])->equals($this->segment_2->name);
|
||||
expect($response['items'][2]['name'])->equals($this->segment_3->name);
|
||||
}
|
||||
|
||||
function itCanSaveASegment() {
|
||||
@ -55,57 +53,83 @@ class SegmentsCest {
|
||||
expect($segment->name)->equals($segment_data['name']);
|
||||
}
|
||||
|
||||
function itCanRestoreASegment() {
|
||||
$segment = Segment::where('name', 'Segment 1')->findOne();
|
||||
$segment->trash();
|
||||
function itCannotSaveDuplicate() {
|
||||
$duplicate_entry = array(
|
||||
'name' => 'Segment 1'
|
||||
);
|
||||
|
||||
$trashed_segment = Segment::findOne($segment->id());
|
||||
$router = new Segments();
|
||||
$response = $router->save($duplicate_entry);
|
||||
expect($response['result'])->false();
|
||||
expect($response['errors'][0])->equals(
|
||||
'Another record already exists. Please specify a different "name".'
|
||||
);
|
||||
}
|
||||
|
||||
function itCanRestoreASegment() {
|
||||
$this->segment_1->trash();
|
||||
|
||||
$trashed_segment = Segment::findOne($this->segment_1->id());
|
||||
expect($trashed_segment->deleted_at)->notNull();
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->restore($segment->id());
|
||||
$response = $router->restore($this->segment_1->id());
|
||||
expect($response)->true();
|
||||
|
||||
$restored_segment = Segment::findOne($segment->id());
|
||||
$restored_segment = Segment::findOne($this->segment_1->id());
|
||||
expect($restored_segment->deleted_at)->null();
|
||||
}
|
||||
|
||||
function itCanTrashASegment() {
|
||||
$segment = Segment::where('name', 'Segment 1')->findOne();
|
||||
expect($segment->deleted_at)->null();
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->trash($segment->id());
|
||||
$response = $router->trash($this->segment_2->id());
|
||||
expect($response)->true();
|
||||
|
||||
$trashed_segment = Segment::findOne($segment->id());
|
||||
$trashed_segment = Segment::findOne($this->segment_2->id());
|
||||
expect($trashed_segment->deleted_at)->notNull();
|
||||
}
|
||||
|
||||
function itCanDeleteASegment() {
|
||||
$segment = Segment::where('name', 'Segment 2')->findOne();
|
||||
expect($segment->deleted_at)->null();
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->delete($segment->id());
|
||||
$response = $router->delete($this->segment_3->id());
|
||||
expect($response)->equals(1);
|
||||
|
||||
$deleted_segment = Segment::findOne($segment->id());
|
||||
$deleted_segment = Segment::findOne($this->segment_3->id());
|
||||
expect($deleted_segment)->false();
|
||||
}
|
||||
|
||||
function itCanDuplicateASegment() {
|
||||
$segment = Segment::where('name', 'Segment 3')->findOne();
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->duplicate($segment->id());
|
||||
expect($response['name'])->equals('Copy of '.$segment->name);
|
||||
$response = $router->duplicate($this->segment_1->id());
|
||||
expect($response['name'])->equals('Copy of '.$this->segment_1->name);
|
||||
|
||||
$duplicated_segment = Segment::findOne($response['id']);
|
||||
expect($duplicated_segment->name)->equals('Copy of '.$segment->name);
|
||||
expect($duplicated_segment->name)->equals('Copy of '.$this->segment_1->name);
|
||||
}
|
||||
|
||||
function itCanBulkDeleteSegments() {
|
||||
expect(Segment::count())->equals(3);
|
||||
|
||||
$segments = Segment::findMany();
|
||||
foreach($segments as $segment) {
|
||||
$segment->trash();
|
||||
}
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(3);
|
||||
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(0);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Segment::$_table)->deleteMany();
|
||||
Segment::deleteMany();
|
||||
}
|
||||
}
|
@ -6,18 +6,33 @@ use \MailPoet\Models\Segment;
|
||||
|
||||
class SubscribersCest {
|
||||
function _before() {
|
||||
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
|
||||
$this->subscriber_1 = Subscriber::createOrUpdate(array(
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
));
|
||||
$this->subscriber_2 = Subscriber::createOrUpdate(array(
|
||||
'email' => 'jane.doe@mailpoet.com',
|
||||
'first_name' => 'Jane',
|
||||
'last_name' => 'Doe',
|
||||
'segments' => array(
|
||||
$this->segment_1->id(),
|
||||
$this->segment_2->id()
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
function itCanGetASubscriber() {
|
||||
$subscriber = Subscriber::createOrUpdate(array(
|
||||
'email' => 'john.doe@mailpoet.com'
|
||||
));
|
||||
expect($subscriber->id() > 0)->true();
|
||||
|
||||
$router = new Subscribers();
|
||||
|
||||
$response = $router->get($subscriber->id());
|
||||
expect($response['id'])->equals($subscriber->id());
|
||||
$response = $router->get($this->subscriber_1->id());
|
||||
expect($response['id'])->equals($this->subscriber_1->id());
|
||||
expect($response['email'])->equals($this->subscriber_1->email);
|
||||
expect($response['first_name'])->equals($this->subscriber_1->first_name);
|
||||
expect($response['last_name'])->equals($this->subscriber_1->last_name);
|
||||
|
||||
$response = $router->get('not_an_id');
|
||||
expect($response)->false();
|
||||
@ -30,7 +45,11 @@ class SubscribersCest {
|
||||
$valid_data = array(
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
'last_name' => 'Doe',
|
||||
'segments' => array(
|
||||
$this->segment_1->id(),
|
||||
$this->segment_2->id()
|
||||
)
|
||||
);
|
||||
|
||||
$router = new Subscribers();
|
||||
@ -38,6 +57,12 @@ class SubscribersCest {
|
||||
expect($response['result'])->true();
|
||||
expect($response)->hasntKey('errors');
|
||||
|
||||
$subscriber = Subscriber::where('email', 'john.doe@mailpoet.com')->findOne();
|
||||
$subscriber_segments = $subscriber->segments()->findMany();
|
||||
expect($subscriber_segments)->count(2);
|
||||
expect($subscriber_segments[0]->name)->equals($this->segment_1->name);
|
||||
expect($subscriber_segments[1]->name)->equals($this->segment_2->name);
|
||||
|
||||
$response = $router->save(/* missing data */);
|
||||
expect($response['result'])->false();
|
||||
expect($response['errors'][0])->equals('You need to enter your email address.');
|
||||
@ -54,80 +79,73 @@ class SubscribersCest {
|
||||
}
|
||||
|
||||
function itCanSaveAnExistingSubscriber() {
|
||||
$subscriber = Subscriber::createOrUpdate(array(
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
));
|
||||
expect($subscriber->id() > 0)->true();
|
||||
|
||||
$router = new Subscribers();
|
||||
|
||||
$subscriber_data = $subscriber->asArray();
|
||||
|
||||
$subscriber_data['email'] = 'jane.doe@mailpoet.com';
|
||||
$subscriber_data['first_name'] = 'Jane';
|
||||
$subscriber_data = $this->subscriber_2->asArray();
|
||||
unset($subscriber_data['created_at']);
|
||||
$subscriber_data['segments'] = array($this->segment_1->id());
|
||||
$subscriber_data['first_name'] = 'Super Jane';
|
||||
|
||||
$response = $router->save($subscriber_data);
|
||||
expect($response['result'])->true();
|
||||
|
||||
$updated_subscriber = Subscriber::findOne($subscriber->id());
|
||||
$updated_subscriber = Subscriber::findOne($this->subscriber_2->id());
|
||||
expect($updated_subscriber->email)->equals('jane.doe@mailpoet.com');
|
||||
expect($updated_subscriber->first_name)->equals('Jane');
|
||||
expect($updated_subscriber->first_name)->equals('Super Jane');
|
||||
}
|
||||
|
||||
function itCanRestoreASubscriber() {
|
||||
$subscriber = Subscriber::createOrUpdate(array(
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
));
|
||||
expect($subscriber->id() > 0)->true();
|
||||
$this->subscriber_1->trash();
|
||||
|
||||
$subscriber->trash();
|
||||
|
||||
expect($subscriber->deleted_at)->notNull();
|
||||
expect($this->subscriber_1->deleted_at)->notNull();
|
||||
|
||||
$router = new Subscribers();
|
||||
$router->restore($subscriber->id());
|
||||
$router->restore($this->subscriber_1->id());
|
||||
|
||||
$restored_subscriber = Subscriber::findOne($subscriber->id());
|
||||
$restored_subscriber = Subscriber::findOne($this->subscriber_1->id());
|
||||
expect($restored_subscriber->deleted_at)->null();
|
||||
}
|
||||
|
||||
function itCanTrashASubscriber() {
|
||||
$subscriber = Subscriber::createOrUpdate(array(
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
));
|
||||
expect($subscriber->id() > 0)->true();
|
||||
|
||||
$router = new Subscribers();
|
||||
$response = $router->trash($subscriber->id());
|
||||
$response = $router->trash($this->subscriber_2->id());
|
||||
expect($response)->true();
|
||||
|
||||
$trashed_subscriber = Subscriber::findOne($subscriber->id());
|
||||
$trashed_subscriber = Subscriber::findOne($this->subscriber_2->id());
|
||||
expect($trashed_subscriber->deleted_at)->notNull();
|
||||
}
|
||||
|
||||
function itCanDeleteASubscriber() {
|
||||
$subscriber = Subscriber::createOrUpdate(array(
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
));
|
||||
expect($subscriber->id() > 0)->true();
|
||||
|
||||
$router = new Subscribers();
|
||||
$response = $router->delete($subscriber->id());
|
||||
$response = $router->delete($this->subscriber_1->id());
|
||||
expect($response)->equals(1);
|
||||
|
||||
expect(Subscriber::findOne($subscriber->id()))->false();
|
||||
expect(Subscriber::findOne($this->subscriber_1->id()))->false();
|
||||
}
|
||||
|
||||
function itCanBulkDeleteSubscribers() {
|
||||
expect(Subscriber::count())->equals(2);
|
||||
|
||||
$subscribers = Subscriber::findMany();
|
||||
foreach($subscribers as $subscriber) {
|
||||
$subscriber->trash();
|
||||
}
|
||||
|
||||
$router = new Subscribers();
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(2);
|
||||
|
||||
$response = $router->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
expect($response)->equals(0);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Segment::$_table)->deleteMany();
|
||||
ORM::forTable(Subscriber::$_table)->deleteMany();
|
||||
Segment::deleteMany();
|
||||
Subscriber::deleteMany();
|
||||
}
|
||||
}
|
@ -211,6 +211,13 @@ class ExportCest {
|
||||
expect(count($subscribers))->equals(2);
|
||||
}
|
||||
|
||||
function itRequiresWritableExportFile() {
|
||||
$this->export->export_path = '/fake_folder';
|
||||
$result = $this->export->process();
|
||||
expect($result['errors'][0])
|
||||
->equals("Couldn't save export file on the server.");
|
||||
}
|
||||
|
||||
function itCanProcess() {
|
||||
$this->export->export_file = $this->export->getExportFile('csv');
|
||||
$this->export->export_format_option = 'csv';
|
||||
|
@ -4,43 +4,40 @@ use MailPoet\Subscribers\ImportExport\Import\MailChimp;
|
||||
|
||||
class MailChimpCest {
|
||||
function __construct() {
|
||||
$this->APIKey = getenv('WP_TEST_IMPORT_MAILCHIMP_API') ?
|
||||
getenv('WP_TEST_IMPORT_MAILCHIMP_API') :
|
||||
'1234567890';
|
||||
$this->mailChimp = new MailChimp($this->APIKey);
|
||||
$this->lists = getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS') ?
|
||||
explode(",", getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS')) :
|
||||
array(
|
||||
'one',
|
||||
'two'
|
||||
);
|
||||
$this->api_key = getenv('WP_TEST_IMPORT_MAILCHIMP_API');
|
||||
$this->mailchimp = new MailChimp($this->api_key);
|
||||
$this->lists = explode(",", getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS'));
|
||||
}
|
||||
|
||||
function itCanGetAPIKey() {
|
||||
expect($this->mailChimp->getAPIKey($this->APIKey))->equals($this->APIKey);
|
||||
expect($this->mailChimp->getAPIKey('somekey'))->false();
|
||||
function itValidatesAPIKey() {
|
||||
$valid_api_key_format = '12345678901234567890123456789012-ab1';
|
||||
expect($this->mailchimp->getAPIKey($valid_api_key_format))
|
||||
->equals($valid_api_key_format);
|
||||
expect($this->mailchimp->getAPIKey('invalid_api_key_format'))->false();
|
||||
}
|
||||
|
||||
function itCanGetDatacenter() {
|
||||
expect($this->mailChimp->getDataCenter($this->APIKey))->equals(
|
||||
explode('-', $this->APIKey)[1]
|
||||
);
|
||||
$valid_api_key_format = '12345678901234567890123456789012-ab1';
|
||||
$data_center = 'ab1';
|
||||
expect($this->mailchimp->getDataCenter($valid_api_key_format))
|
||||
->equals($data_center);
|
||||
}
|
||||
|
||||
function itFailsWithIncorrectAPIKey() {
|
||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||
$mailChimp = clone($this->mailChimp);
|
||||
$mailChimp->APIKey = false;
|
||||
$lists = $mailChimp->getLists();
|
||||
$mailchimp = clone($this->mailchimp);
|
||||
$mailchimp->api_key = false;
|
||||
$lists = $mailchimp->getLists();
|
||||
expect($lists['result'])->false();
|
||||
expect($lists['error'])->contains('API');
|
||||
$subscribers = $mailChimp->getLists();
|
||||
expect($lists['errors'][0])->contains('API');
|
||||
$subscribers = $mailchimp->getLists();
|
||||
expect($subscribers['result'])->false();
|
||||
expect($subscribers['error'])->contains('API');
|
||||
expect($subscribers['errors'][0])->contains('API');
|
||||
}
|
||||
|
||||
function itCanGetLists() {
|
||||
$lists = $this->mailChimp->getLists();
|
||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||
$lists = $this->mailchimp->getLists();
|
||||
expect($lists['result'])->true();
|
||||
expect(count($lists['data']))->equals(2);
|
||||
expect(isset($lists['data'][0]['id']))->true();
|
||||
@ -49,17 +46,17 @@ class MailChimpCest {
|
||||
|
||||
function itFailsWithIncorrectLists() {
|
||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||
$subscribers = $this->mailChimp->getSubscribers();
|
||||
$subscribers = $this->mailchimp->getSubscribers();
|
||||
expect($subscribers['result'])->false();
|
||||
expect($subscribers['error'])->contains('lists');
|
||||
$subscribers = $this->mailChimp->getSubscribers(array(12));
|
||||
expect($subscribers['errors'][0])->contains('lists');
|
||||
$subscribers = $this->mailchimp->getSubscribers(array(12));
|
||||
expect($subscribers['result'])->false();
|
||||
expect($subscribers['error'])->contains('lists');
|
||||
expect($subscribers['errors'][0])->contains('lists');
|
||||
}
|
||||
|
||||
function itCanGetSubscribers() {
|
||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||
$subscribers = $this->mailChimp->getSubscribers(array($this->lists[0]));
|
||||
$subscribers = $this->mailchimp->getSubscribers(array($this->lists[0]));
|
||||
expect($subscribers['result'])->true();
|
||||
expect(isset($subscribers['data']['invalid']))->true();
|
||||
expect(isset($subscribers['data']['duplicate']))->true();
|
||||
@ -70,17 +67,17 @@ class MailChimpCest {
|
||||
|
||||
function itFailsWhenListHeadersDontMatch() {
|
||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||
$subscribers = $this->mailChimp->getSubscribers($this->lists);
|
||||
$subscribers = $this->mailchimp->getSubscribers($this->lists);
|
||||
expect($subscribers['result'])->false();
|
||||
expect($subscribers['error'])->contains('header');
|
||||
expect($subscribers['errors'][0])->contains('header');
|
||||
}
|
||||
|
||||
function itFailsWhenSubscribersDataTooLarge() {
|
||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||
$mailChimp = clone($this->mailChimp);
|
||||
$mailChimp->maxPostSize = 10;
|
||||
$subscribers = $mailChimp->getSubscribers($this->lists);
|
||||
$mailchimp = clone($this->mailchimp);
|
||||
$mailchimp->max_post_size = 10;
|
||||
$subscribers = $mailchimp->getSubscribers($this->lists);
|
||||
expect($subscribers['result'])->false();
|
||||
expect($subscribers['error'])->contains('large');
|
||||
expect($subscribers['errors'][0])->contains('large');
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user