Compare commits
265 Commits
Author | SHA1 | Date | |
---|---|---|---|
a1441dfde6 | |||
8e7336d352 | |||
e0e2933cdf | |||
c93ec629ea | |||
d613df6558 | |||
01c9096543 | |||
f120e839dd | |||
f0ab592c04 | |||
1a269d28b3 | |||
8d4a666bf0 | |||
4a96e483a6 | |||
263a66407f | |||
c4b728f4e1 | |||
9970ad7fb6 | |||
eb380499d9 | |||
4b528549f5 | |||
a903017bc2 | |||
afd25e9174 | |||
b1bbf1b3bc | |||
9e84e8df93 | |||
df775b5a07 | |||
c9c22b9b52 | |||
93d20688ea | |||
9ebcddfa2a | |||
85995bc8a6 | |||
a8f2959bc6 | |||
36242bd580 | |||
1e7dbc8449 | |||
12c159c627 | |||
82ed7e51c5 | |||
0b3aa0d12a | |||
4d788f69aa | |||
c721843c12 | |||
d2be407ccb | |||
e6337216cf | |||
f1c396f0b0 | |||
3622bc9fcb | |||
14fe333678 | |||
cf6466197a | |||
f56bee76f2 | |||
2ec6bc8c99 | |||
4aeccb1961 | |||
bd593b1ad4 | |||
bb7812bd5d | |||
73ed070a34 | |||
9e81c48bf8 | |||
f9028d28c0 | |||
da32b243ea | |||
5092c3d328 | |||
06ad4488bf | |||
a856800e6d | |||
dfc680f3a1 | |||
a9baecc504 | |||
11e15659ac | |||
ebe440a272 | |||
853794d459 | |||
cfea13bf81 | |||
7f291d80b9 | |||
9840b55de6 | |||
ca7322933f | |||
81569e5b81 | |||
1942972282 | |||
a23aac370c | |||
99d6f74d1b | |||
a883e1176c | |||
24b98a1154 | |||
8dbb6ab79f | |||
3e7d1690bd | |||
07d533a810 | |||
499936e3ab | |||
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 | |||
8dbfe82922 | |||
7322f2151c | |||
c43d2f240d | |||
bbcd267b6f | |||
bbc4acb2a4 | |||
c89cc5a919 | |||
33075940de | |||
51c09b8360 | |||
2fbf85f371 | |||
24cb614adb | |||
55f851208b | |||
990dac7727 | |||
233020ca20 | |||
0c419cde16 | |||
35f9530d8e | |||
992fe2a6e9 | |||
c2cb88f995 | |||
ba69d659ab | |||
397d988eb1 | |||
d85f2341ec | |||
2b3c288b5f | |||
8ec28a23a7 | |||
12c9623e2f | |||
8ba9fdccbc | |||
a2ef62302f | |||
24ecc879d3 | |||
a1104a7f90 | |||
aa959810e9 | |||
45b7a79277 | |||
41c8c0dae5 | |||
2aeab7aaff | |||
4fd0c4b484 | |||
d4623cf763 | |||
181c4fed08 | |||
7884dd8389 | |||
b577d33414 | |||
70de0a01bf | |||
3b7f77d9af | |||
21847ca875 | |||
6153316047 | |||
32f8f07602 | |||
70a04d9bf6 | |||
bb1cc997cc | |||
24f96d9d7d | |||
46c7332da2 | |||
2f42f643ab | |||
63c87f3746 | |||
d4d575cda4 | |||
2cf03ec0a3 | |||
72ad98a77f | |||
b5094f568c | |||
7d224274fc | |||
f3b9f7be92 | |||
6e74f82ace | |||
831eb6af44 | |||
1e8e5aecee | |||
c0f98c9ba6 | |||
746c19d6ed | |||
894a9e8c90 | |||
8fea917337 | |||
c60425afb2 | |||
0776e9ad73 | |||
91981cc324 | |||
1906fafacb | |||
c11d95b402 | |||
b4c8fe6f45 | |||
d0e770e0fc | |||
3d6d1a4282 | |||
dc3b47db00 | |||
900d6694e2 | |||
e8074a61a5 | |||
64501a914a | |||
de70e855ad | |||
03e3b5a94b | |||
3331bed31c | |||
8c5a33a0fe | |||
01eb6c7a98 | |||
f502e0b677 | |||
a6b64a1c5d | |||
5019131b21 | |||
da483fb88f | |||
788bed4622 | |||
3fbe5423d0 | |||
8357295be2 | |||
8072b162d4 | |||
3f2f0ec1a9 | |||
5a5a777b7d | |||
6cac7f3652 | |||
6a9313107c | |||
72c9d301b7 | |||
ad925de801 | |||
1da28b7299 | |||
e837ad7014 | |||
daec56191f | |||
7bd25660df | |||
3b9821fbe1 | |||
cabe2d61b7 | |||
a6d802e2fa | |||
1732c4f634 | |||
bb77134224 | |||
f1cb64b240 | |||
3689545589 | |||
9b67c56281 | |||
dc38b19667 | |||
a574733217 | |||
b90aaa629e | |||
8de186c0e6 | |||
e3719967f9 | |||
138a631ed7 | |||
07b7636a72 | |||
a63ce3cdac | |||
f5c7bb87af | |||
2c8d925971 | |||
0c5beb2511 | |||
9c0316a87d | |||
46c1b682fa | |||
7954346a3f | |||
d87ff67f50 | |||
6642bb3bfa | |||
2cb32e7a78 | |||
fcea9adbd9 | |||
bbdd0dbb6e | |||
1b2cf7bd16 | |||
b7cfa549d5 |
16
.env.sample
16
.env.sample
@ -1,2 +1,16 @@
|
|||||||
WP_TEST_PATH="/var/www/wordpress"
|
WP_TEST_PATH="/var/www/wordpress"
|
||||||
|
WP_TEST_ENABLE_NETWORK_TESTS="true"
|
||||||
|
WP_TEST_IMPORT_MAILCHIMP_API=""
|
||||||
|
WP_TEST_IMPORT_MAILCHIMP_LISTS="" // (separated with comma)
|
||||||
|
WP_TEST_MAILER_ENABLE_SENDING="true"
|
||||||
|
WP_TEST_MAILER_AMAZON_ACCESS=""
|
||||||
|
WP_TEST_MAILER_AMAZON_SECRET=""
|
||||||
|
WP_TEST_MAILER_AMAZON_REGION=""
|
||||||
|
WP_TEST_MAILER_ELASTICEMAIL_API=""
|
||||||
|
WP_TEST_MAILER_MAILGUN_API=""
|
||||||
|
WP_TEST_MAILER_MAILGUN_DOMAIN=""
|
||||||
|
WP_TEST_MAILER_MAILPOET_API=""
|
||||||
|
WP_TEST_MAILER_SENDGRID_API=""
|
||||||
|
WP_TEST_MAILER_SMTP_HOST=""
|
||||||
|
WP_TEST_MAILER_SMTP_LOGIN=""
|
||||||
|
WP_TEST_MAILER_SMTP_PASSWORD=""
|
13
RoboFile.php
13
RoboFile.php
@ -105,7 +105,18 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
function testUnit($file = null) {
|
function testUnit($file = null) {
|
||||||
$this->loadEnv();
|
$this->loadEnv();
|
||||||
$this->_exec('vendor/bin/codecept build');
|
$this->_exec('vendor/bin/codecept build');
|
||||||
$this->_exec('vendor/bin/codecept run unit '.(($file) ? $file : ''));
|
$this->_exec('vendor/bin/codecept run unit -f '.(($file) ? $file : ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testJavascript() {
|
function testJavascript() {
|
||||||
|
@ -17,3 +17,5 @@
|
|||||||
|
|
||||||
@require 'settings'
|
@require 'settings'
|
||||||
@require 'progress_bar'
|
@require 'progress_bar'
|
||||||
|
|
||||||
|
@require 'subscribers'
|
@ -19,6 +19,8 @@ a:focus
|
|||||||
|
|
||||||
// select 2
|
// select 2
|
||||||
.select2-container
|
.select2-container
|
||||||
|
width: 25em !important
|
||||||
|
|
||||||
// textareas
|
// textareas
|
||||||
textarea.regular-text
|
textarea.regular-text
|
||||||
width: 25em !important
|
width: 25em !important
|
||||||
|
@ -125,6 +125,7 @@ handle_icon = '../img/handle.png'
|
|||||||
float: none
|
float: none
|
||||||
|
|
||||||
#mailpoet_form_toolbar
|
#mailpoet_form_toolbar
|
||||||
|
z-index: 999
|
||||||
position: absolute
|
position: absolute
|
||||||
width: 400px
|
width: 400px
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ body.mailpoet_modal_opened
|
|||||||
padding: 0
|
padding: 0
|
||||||
margin: 0
|
margin: 0
|
||||||
width: 100%
|
width: 100%
|
||||||
transition: margin 250ms ease-out
|
transition: margin 350ms ease-out
|
||||||
|
|
||||||
.mailpoet_panel_wrapper
|
.mailpoet_panel_wrapper
|
||||||
background-color: #f1f1f1
|
background-color: #f1f1f1
|
||||||
|
@ -7,7 +7,6 @@ $tool-active-secondary-color = #ffffff
|
|||||||
|
|
||||||
$tool-width = 20px
|
$tool-width = 20px
|
||||||
$master-column-tool-width = 24px
|
$master-column-tool-width = 24px
|
||||||
$layer-selector-width = 30px
|
|
||||||
|
|
||||||
.mailpoet_tools
|
.mailpoet_tools
|
||||||
position: absolute
|
position: absolute
|
||||||
@ -33,10 +32,35 @@ $layer-selector-width = 30px
|
|||||||
width: $master-column-tool-width
|
width: $master-column-tool-width
|
||||||
height: $master-column-tool-width
|
height: $master-column-tool-width
|
||||||
|
|
||||||
|
|
||||||
|
.mailpoet_delete_block_activate
|
||||||
|
max-width: 100%
|
||||||
|
max-height: $master-column-tool-width
|
||||||
|
opacity: 1
|
||||||
|
display: block
|
||||||
|
|
||||||
|
.mailpoet_delete_block_confirm,
|
||||||
|
.mailpoet_delete_block_cancel
|
||||||
|
max-width: 100%
|
||||||
|
max-height: 0
|
||||||
|
opacity: 0
|
||||||
|
overflow: hidden
|
||||||
|
display: block
|
||||||
|
|
||||||
.mailpoet_delete_block_activated
|
.mailpoet_delete_block_activated
|
||||||
width: auto
|
width: auto
|
||||||
height: auto
|
height: auto
|
||||||
|
|
||||||
|
.mailpoet_delete_block_activate
|
||||||
|
overflow: hidden
|
||||||
|
max-height: 0
|
||||||
|
opacity: 0
|
||||||
|
|
||||||
|
.mailpoet_delete_block_confirm,
|
||||||
|
.mailpoet_delete_block_cancel
|
||||||
|
max-height: $master-column-tool-width*2
|
||||||
|
opacity: 1
|
||||||
|
|
||||||
.mailpoet_tool
|
.mailpoet_tool
|
||||||
display: inline-block
|
display: inline-block
|
||||||
width: $tool-width
|
width: $tool-width
|
||||||
@ -82,9 +106,10 @@ $layer-selector-width = 30px
|
|||||||
padding: 0
|
padding: 0
|
||||||
|
|
||||||
.mailpoet_delete_block_activate
|
.mailpoet_delete_block_activate
|
||||||
max-width: 100%
|
max-width: $tool-width
|
||||||
display: inline-block
|
display: inline-block
|
||||||
opacity: 1
|
opacity: 1
|
||||||
|
animation-fade-in-and-scale-horizontally()
|
||||||
|
|
||||||
.mailpoet_delete_block_confirm,
|
.mailpoet_delete_block_confirm,
|
||||||
.mailpoet_delete_block_cancel
|
.mailpoet_delete_block_cancel
|
||||||
@ -95,12 +120,12 @@ $layer-selector-width = 30px
|
|||||||
animation-fade-in-and-scale-horizontally()
|
animation-fade-in-and-scale-horizontally()
|
||||||
|
|
||||||
.mailpoet_delete_block_activated
|
.mailpoet_delete_block_activated
|
||||||
|
height: auto
|
||||||
width: auto
|
width: auto
|
||||||
border-radius(3px)
|
border-radius(3px)
|
||||||
background-color: $warning-background-color
|
background-color: $warning-background-color
|
||||||
padding: 3px 5px
|
padding: 3px 5px
|
||||||
line-height: 1.2em
|
line-height: 1.2em
|
||||||
height: auto
|
|
||||||
|
|
||||||
.mailpoet_delete_block_activate
|
.mailpoet_delete_block_activate
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
|
@ -37,3 +37,6 @@
|
|||||||
|
|
||||||
input[type=text]
|
input[type=text]
|
||||||
vertical-align: middle
|
vertical-align: middle
|
||||||
|
|
||||||
|
.mailpoet_form_field_block
|
||||||
|
display: block
|
||||||
|
@ -38,9 +38,7 @@
|
|||||||
content: '\f142'
|
content: '\f142'
|
||||||
|
|
||||||
.mailpoet_save_show_options_icon
|
.mailpoet_save_show_options_icon
|
||||||
width: auto
|
vertical-align: middle
|
||||||
height: auto
|
|
||||||
line-height: auto
|
|
||||||
|
|
||||||
&::before
|
&::before
|
||||||
content: '\f140'
|
content: '\f140'
|
||||||
|
@ -21,3 +21,9 @@
|
|||||||
|
|
||||||
.mailpoet_automated_latest_content_display_options
|
.mailpoet_automated_latest_content_display_options
|
||||||
animation-slide-open-downwards()
|
animation-slide-open-downwards()
|
||||||
|
|
||||||
|
.mailpoet_automated_latest_content_show_amount
|
||||||
|
width: 25px
|
||||||
|
|
||||||
|
.mailpoet_automated_latest_content_content_type
|
||||||
|
width: 180px
|
||||||
|
@ -30,3 +30,8 @@ $block-hover-highlight-color = $primary-active-color
|
|||||||
|
|
||||||
.mailpoet_content
|
.mailpoet_content
|
||||||
position: relative
|
position: relative
|
||||||
|
line-height: 1.61803398875
|
||||||
|
|
||||||
|
p, h1, h2, h3, h4, h5, h6
|
||||||
|
line-height: 1.61803398875
|
||||||
|
font-style: normal
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
.mailpoet_footer_block
|
.mailpoet_footer_block
|
||||||
padding-left: 0
|
padding-left: 0
|
||||||
padding-right: 0
|
padding-right: 0
|
||||||
|
margin-bottom: 0
|
||||||
|
|
||||||
.mailpoet_content
|
.mailpoet_content
|
||||||
padding: 5px 20px
|
padding: 10px 20px
|
||||||
|
|
||||||
|
p
|
||||||
|
margin: 0
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
.mailpoet_header_block
|
.mailpoet_header_block
|
||||||
padding-left: 0
|
padding-left: 0
|
||||||
padding-right: 0
|
padding-right: 0
|
||||||
|
margin-bottom: 0
|
||||||
|
|
||||||
.mailpoet_content
|
.mailpoet_content
|
||||||
padding: 5px 20px
|
padding: 10px 20px
|
||||||
|
|
||||||
|
p
|
||||||
|
margin: 0
|
||||||
|
@ -11,9 +11,6 @@
|
|||||||
padding-right: 0
|
padding-right: 0
|
||||||
margin-bottom: 0
|
margin-bottom: 0
|
||||||
|
|
||||||
img
|
|
||||||
width: 100%
|
|
||||||
|
|
||||||
.mailpoet_content a:hover
|
.mailpoet_content a:hover
|
||||||
cursor: all-scroll
|
cursor: all-scroll
|
||||||
|
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
$text-vertical-padding = 3px
|
|
||||||
|
|
||||||
.mailpoet_text_block
|
.mailpoet_text_block
|
||||||
padding-left: 0
|
padding-left: 0
|
||||||
padding-right: 0
|
padding-right: 0
|
||||||
|
|
||||||
& > .mailpoet_content
|
& > .mailpoet_content
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
padding-top: 13px
|
padding-top: 0
|
||||||
padding-bottom: 13px
|
padding-bottom: 0px
|
||||||
padding-left: 20px
|
padding-left: 20px
|
||||||
padding-right: 20px
|
padding-right: 20px
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6
|
||||||
|
padding: 0
|
||||||
|
margin: 0
|
||||||
|
font-weight: normal
|
||||||
|
|
||||||
|
p
|
||||||
|
margin-top: 0
|
||||||
|
font-weight: normal
|
||||||
|
|
||||||
blockquote
|
blockquote
|
||||||
margin: 1em
|
margin: 1em
|
||||||
padding-left: 1em
|
padding-left: 1em
|
||||||
|
@ -129,3 +129,21 @@ body
|
|||||||
|
|
||||||
#mailpoet_modal_close
|
#mailpoet_modal_close
|
||||||
display: none
|
display: none
|
||||||
|
|
||||||
|
.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
|
||||||
|
|
||||||
|
@ -13,8 +13,9 @@ animation-background-color()
|
|||||||
|
|
||||||
animation-fade-in()
|
animation-fade-in()
|
||||||
animation-name: fadeIn
|
animation-name: fadeIn
|
||||||
animation-duration: 250ms
|
animation-duration: 300ms
|
||||||
animation-fill-mode: forwards
|
animation-fill-mode: forwards
|
||||||
|
animation-timing-function: ease-in
|
||||||
|
|
||||||
animation-fade-in-and-scale-horizontally()
|
animation-fade-in-and-scale-horizontally()
|
||||||
transition: all 250ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
|
transition: all 250ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
|
||||||
|
@ -2,3 +2,13 @@
|
|||||||
|
|
||||||
@require 'parsley'
|
@require 'parsley'
|
||||||
@require 'form_validation'
|
@require 'form_validation'
|
||||||
|
|
||||||
|
/* labels */
|
||||||
|
.mailpoet_text_label
|
||||||
|
.mailpoet_textarea_label
|
||||||
|
.mailpoet_select_label
|
||||||
|
.mailpoet_radio_label
|
||||||
|
.mailpoet_checkbox_label
|
||||||
|
.mailpoet_list_label
|
||||||
|
.mailpoet_date_label
|
||||||
|
display:block
|
||||||
|
3
assets/css/src/subscribers.styl
Normal file
3
assets/css/src/subscribers.styl
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#subscribers_container
|
||||||
|
.mailpoet_segments_unsubscribed
|
||||||
|
color: lighten(#555, 33)
|
136
assets/js/src/date.js
Normal file
136
assets/js/src/date.js
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
define('date',
|
||||||
|
[
|
||||||
|
'mailpoet',
|
||||||
|
'jquery',
|
||||||
|
'moment'
|
||||||
|
], function(
|
||||||
|
MailPoet,
|
||||||
|
jQuery,
|
||||||
|
Moment
|
||||||
|
) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
MailPoet.Date = {
|
||||||
|
version: 0.1,
|
||||||
|
options: {},
|
||||||
|
defaults: {
|
||||||
|
offset: 0,
|
||||||
|
format: 'F, d Y H:i:s'
|
||||||
|
},
|
||||||
|
init: function(options) {
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
// set UTC offset
|
||||||
|
if (
|
||||||
|
options.offset === undefined
|
||||||
|
&& window.mailpoet_date_offset !== undefined
|
||||||
|
) {
|
||||||
|
options.offset = window.mailpoet_date_offset;
|
||||||
|
}
|
||||||
|
// set date format
|
||||||
|
if (
|
||||||
|
options.format === undefined
|
||||||
|
&& window.mailpoet_date_format !== undefined
|
||||||
|
) {
|
||||||
|
options.format = window.mailpoet_date_format;
|
||||||
|
}
|
||||||
|
// merge options
|
||||||
|
this.options = jQuery.extend({}, this.defaults, options);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
format: function(date, options) {
|
||||||
|
this.init(options);
|
||||||
|
return Moment.utc(date)
|
||||||
|
.local()
|
||||||
|
.format(this.convertFormat(this.options.format));
|
||||||
|
},
|
||||||
|
short: function(date) {
|
||||||
|
return this.format(date, {
|
||||||
|
format: 'F, j Y'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
full: function(date) {
|
||||||
|
return this.format(date, {
|
||||||
|
format: 'F, j Y H:i:s'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
time: function(date) {
|
||||||
|
return this.format(date, {
|
||||||
|
format: 'H:i:s'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
convertFormat: function(format) {
|
||||||
|
const format_mappings = {
|
||||||
|
date: {
|
||||||
|
D: 'ddd',
|
||||||
|
l: 'dddd',
|
||||||
|
d: 'DD',
|
||||||
|
j: 'D',
|
||||||
|
z: 'DDDD',
|
||||||
|
N: 'E',
|
||||||
|
S: '',
|
||||||
|
M: 'MMM',
|
||||||
|
F: 'MMMM',
|
||||||
|
m: 'MM',
|
||||||
|
n: '',
|
||||||
|
t: '',
|
||||||
|
y: 'YY',
|
||||||
|
Y: 'YYYY',
|
||||||
|
H: 'HH',
|
||||||
|
h: 'hh',
|
||||||
|
g: 'h',
|
||||||
|
A: 'A',
|
||||||
|
i: 'mm',
|
||||||
|
s: 'ss',
|
||||||
|
T: 'z',
|
||||||
|
O: 'ZZ',
|
||||||
|
w: 'd',
|
||||||
|
W: 'WW'
|
||||||
|
},
|
||||||
|
strftime: {
|
||||||
|
a: 'ddd',
|
||||||
|
A: 'dddd',
|
||||||
|
b: 'MMM',
|
||||||
|
B: 'MMMM',
|
||||||
|
d: 'DD',
|
||||||
|
e: 'D',
|
||||||
|
F: 'YYYY-MM-DD',
|
||||||
|
H: 'HH',
|
||||||
|
I: 'hh',
|
||||||
|
j: 'DDDD',
|
||||||
|
k: 'H',
|
||||||
|
l: 'h',
|
||||||
|
m: 'MM',
|
||||||
|
M: 'mm',
|
||||||
|
p: 'A',
|
||||||
|
S: 'ss',
|
||||||
|
u: 'E',
|
||||||
|
w: 'd',
|
||||||
|
W: 'WW',
|
||||||
|
y: 'YY',
|
||||||
|
Y: 'YYYY',
|
||||||
|
z: 'ZZ',
|
||||||
|
Z: 'z'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const replacements = format_mappings['date'];
|
||||||
|
|
||||||
|
let outputFormat = '';
|
||||||
|
|
||||||
|
Object.keys(replacements).forEach(function(key) {
|
||||||
|
if (format.indexOf(key) !== -1) {
|
||||||
|
format = format.replace(key, '%'+key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
outputFormat = format;
|
||||||
|
Object.keys(replacements).forEach(function(key) {
|
||||||
|
if (outputFormat.indexOf('%'+key) !== -1) {
|
||||||
|
outputFormat = outputFormat.replace('%'+key, replacements[key]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return outputFormat;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
@ -1,62 +1,45 @@
|
|||||||
define([
|
define([
|
||||||
'react',
|
'react'
|
||||||
'react-checkbox-group'
|
|
||||||
],
|
],
|
||||||
function(
|
function(
|
||||||
React,
|
React
|
||||||
CheckboxGroup
|
|
||||||
) {
|
) {
|
||||||
var FormFieldCheckbox = React.createClass({
|
const FormFieldCheckbox = React.createClass({
|
||||||
|
onValueChange: function(e) {
|
||||||
|
e.target.value = this.refs.checkbox.checked ? '1' : '';
|
||||||
|
return this.props.onValueChange(e);
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var selected_values = this.props.item[this.props.field.name] || '';
|
if (this.props.field.values === undefined) {
|
||||||
if(
|
return false;
|
||||||
selected_values !== undefined
|
|
||||||
&& selected_values.constructor !== Array
|
|
||||||
) {
|
|
||||||
selected_values = selected_values.split(';').map(function(value) {
|
|
||||||
return value.trim();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
var count = Object.keys(this.props.field.values).length;
|
|
||||||
|
|
||||||
var options = Object.keys(this.props.field.values).map(
|
const isChecked = !!(this.props.item[this.props.field.name]);
|
||||||
function(value, index) {
|
const options = Object.keys(this.props.field.values).map(
|
||||||
|
(value, index) => {
|
||||||
return (
|
return (
|
||||||
<p key={ 'checkbox-' + index }>
|
<p key={ 'checkbox-' + index }>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" value={ value } />
|
<input
|
||||||
{ this.props.field.values[value] }
|
ref="checkbox"
|
||||||
|
type="checkbox"
|
||||||
|
value="1"
|
||||||
|
checked={ isChecked }
|
||||||
|
onChange={ this.onValueChange }
|
||||||
|
name={ this.props.field.name }
|
||||||
|
/>
|
||||||
|
{ this.props.field.values[value] }
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}.bind(this)
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CheckboxGroup
|
<div>
|
||||||
name={ this.props.field.name }
|
|
||||||
value={ selected_values }
|
|
||||||
ref={ this.props.field.name }
|
|
||||||
onChange={ this.handleValueChange }>
|
|
||||||
{ options }
|
{ options }
|
||||||
</CheckboxGroup>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
|
||||||
handleValueChange: function() {
|
|
||||||
var field = this.props.field.name;
|
|
||||||
var group = this.refs[field];
|
|
||||||
var selected_values = [];
|
|
||||||
|
|
||||||
if(group !== undefined) {
|
|
||||||
selected_values = group.getCheckedValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.props.onValueChange({
|
|
||||||
target: {
|
|
||||||
name: field,
|
|
||||||
value: selected_values.join(';')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
196
assets/js/src/form/fields/date.jsx
Normal file
196
assets/js/src/form/fields/date.jsx
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
define([
|
||||||
|
'react',
|
||||||
|
'moment',
|
||||||
|
], function(
|
||||||
|
React,
|
||||||
|
Moment
|
||||||
|
) {
|
||||||
|
class FormFieldDateYear extends React.Component {
|
||||||
|
render() {
|
||||||
|
const yearsRange = 100;
|
||||||
|
const years = [];
|
||||||
|
const currentYear = Moment().year();
|
||||||
|
for (let i = currentYear; i >= currentYear - yearsRange; i--) {
|
||||||
|
years.push((
|
||||||
|
<option
|
||||||
|
key={ i }
|
||||||
|
value={ i }
|
||||||
|
>{ i }</option>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
name={ this.props.name + '[year]' }
|
||||||
|
value={ this.props.year }
|
||||||
|
onChange={ this.props.onValueChange }
|
||||||
|
>
|
||||||
|
{ years }
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FormFieldDateMonth extends React.Component {
|
||||||
|
render() {
|
||||||
|
const months = [];
|
||||||
|
for (let i = 1; i <= 12; i++) {
|
||||||
|
months.push((
|
||||||
|
<option
|
||||||
|
key={ i }
|
||||||
|
value={ i }
|
||||||
|
>{ this.props.monthNames[i - 1] }</option>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
name={ this.props.name + '[month]' }
|
||||||
|
value={ this.props.month }
|
||||||
|
onChange={ this.props.onValueChange }
|
||||||
|
>
|
||||||
|
{ months }
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FormFieldDateDay extends React.Component {
|
||||||
|
render() {
|
||||||
|
const days = [];
|
||||||
|
for (let i = 1; i <= 31; i++) {
|
||||||
|
days.push((
|
||||||
|
<option
|
||||||
|
key={ i }
|
||||||
|
value={ i }
|
||||||
|
>{ i }</option>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
name={ this.props.name + '[day]' }
|
||||||
|
value={ this.props.day }
|
||||||
|
onChange={ this.props.onValueChange }
|
||||||
|
>
|
||||||
|
{ days }
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FormFieldDate extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
year: Moment().year(),
|
||||||
|
month: 1,
|
||||||
|
day: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
}
|
||||||
|
componentDidUpdate(prevProps, prevState) {
|
||||||
|
if (
|
||||||
|
(this.props.item !== undefined && prevProps.item !== undefined)
|
||||||
|
&& (this.props.item.id !== prevProps.item.id)
|
||||||
|
) {
|
||||||
|
this.extractTimeStamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
extractTimeStamp() {
|
||||||
|
const timeStamp = parseInt(this.props.item[this.props.field.name], 10);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
year: Moment.unix(timeStamp).year(),
|
||||||
|
// Moment returns the month as [0..11]
|
||||||
|
// We increment it to match PHP's mktime() which expects [1..12]
|
||||||
|
month: Moment.unix(timeStamp).month() + 1,
|
||||||
|
day: Moment.unix(timeStamp).date()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
updateTimeStamp(field) {
|
||||||
|
let newTimeStamp = Moment(
|
||||||
|
`${this.state.month}/${this.state.day}/${this.state.year}`,
|
||||||
|
'M/D/YYYY'
|
||||||
|
).valueOf();
|
||||||
|
if (!isNaN(newTimeStamp) && parseInt(newTimeStamp, 10) > 0) {
|
||||||
|
// convert milliseconds to seconds
|
||||||
|
newTimeStamp /= 1000;
|
||||||
|
return this.props.onValueChange({
|
||||||
|
target: {
|
||||||
|
name: field,
|
||||||
|
value: newTimeStamp
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onValueChange(e) {
|
||||||
|
// extract property from name
|
||||||
|
const matches = e.target.name.match(/(.*?)\[(.*?)\]/);
|
||||||
|
let field = null;
|
||||||
|
let property = null;
|
||||||
|
|
||||||
|
if (matches !== null && matches.length === 3) {
|
||||||
|
field = matches[1];
|
||||||
|
property = matches[2];
|
||||||
|
|
||||||
|
let value = parseInt(e.target.value, 10);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
[`${property}`]: value
|
||||||
|
}, () => {
|
||||||
|
this.updateTimeStamp(field);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const monthNames = window.mailpoet_month_names || [];
|
||||||
|
|
||||||
|
const dateType = this.props.field.params.date_type;
|
||||||
|
|
||||||
|
const dateSelects = dateType.split('_');
|
||||||
|
|
||||||
|
const fields = dateSelects.map(type => {
|
||||||
|
switch(type) {
|
||||||
|
case 'year':
|
||||||
|
return (<FormFieldDateYear
|
||||||
|
onValueChange={ this.onValueChange.bind(this) }
|
||||||
|
ref={ 'year' }
|
||||||
|
key={ 'year' }
|
||||||
|
name={ this.props.field.name }
|
||||||
|
year={ this.state.year }
|
||||||
|
/>);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'month':
|
||||||
|
return (<FormFieldDateMonth
|
||||||
|
onValueChange={ this.onValueChange.bind(this) }
|
||||||
|
ref={ 'month' }
|
||||||
|
key={ 'month' }
|
||||||
|
name={ this.props.field.name }
|
||||||
|
month={ this.state.month }
|
||||||
|
monthNames={ monthNames }
|
||||||
|
/>);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'day':
|
||||||
|
return (<FormFieldDateDay
|
||||||
|
onValueChange={ this.onValueChange.bind(this) }
|
||||||
|
ref={ 'day' }
|
||||||
|
key={ 'day' }
|
||||||
|
name={ this.props.field.name }
|
||||||
|
day={ this.state.day }
|
||||||
|
/>);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{fields}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return FormFieldDate;
|
||||||
|
});
|
@ -5,7 +5,8 @@ define([
|
|||||||
'form/fields/select.jsx',
|
'form/fields/select.jsx',
|
||||||
'form/fields/radio.jsx',
|
'form/fields/radio.jsx',
|
||||||
'form/fields/checkbox.jsx',
|
'form/fields/checkbox.jsx',
|
||||||
'form/fields/selection.jsx'
|
'form/fields/selection.jsx',
|
||||||
|
'form/fields/date.jsx',
|
||||||
],
|
],
|
||||||
function(
|
function(
|
||||||
React,
|
React,
|
||||||
@ -14,7 +15,8 @@ function(
|
|||||||
FormFieldSelect,
|
FormFieldSelect,
|
||||||
FormFieldRadio,
|
FormFieldRadio,
|
||||||
FormFieldCheckbox,
|
FormFieldCheckbox,
|
||||||
FormFieldSelection
|
FormFieldSelection,
|
||||||
|
FormFieldDate
|
||||||
) {
|
) {
|
||||||
var FormField = React.createClass({
|
var FormField = React.createClass({
|
||||||
renderField: function(data, inline = false) {
|
renderField: function(data, inline = false) {
|
||||||
@ -55,6 +57,10 @@ function(
|
|||||||
case 'selection':
|
case 'selection':
|
||||||
field = (<FormFieldSelection {...data} />);
|
field = (<FormFieldSelection {...data} />);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'date':
|
||||||
|
field = (<FormFieldDate {...data} />);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inline === true) {
|
if(inline === true) {
|
||||||
@ -66,10 +72,10 @@ function(
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<p key={ 'field-' + (data.index || 0) }>
|
<div key={ 'field-' + (data.index || 0) }>
|
||||||
{ field }
|
{ field }
|
||||||
{ description }
|
{ description }
|
||||||
</p>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4,13 +4,15 @@ define([
|
|||||||
function(
|
function(
|
||||||
React
|
React
|
||||||
) {
|
) {
|
||||||
var FormFieldRadio = React.createClass({
|
const FormFieldRadio = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
var selected_value = this.props.item[this.props.field.name];
|
if (this.props.field.values === undefined) {
|
||||||
var count = Object.keys(this.props.field.values).length;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var options = Object.keys(this.props.field.values).map(
|
const selected_value = this.props.item[this.props.field.name];
|
||||||
function(value, index) {
|
const options = Object.keys(this.props.field.values).map(
|
||||||
|
(value, index) => {
|
||||||
return (
|
return (
|
||||||
<p key={ 'radio-' + index }>
|
<p key={ 'radio-' + index }>
|
||||||
<label>
|
<label>
|
||||||
@ -20,11 +22,11 @@ function(
|
|||||||
value={ value }
|
value={ value }
|
||||||
onChange={ this.props.onValueChange }
|
onChange={ this.props.onValueChange }
|
||||||
name={ this.props.field.name } />
|
name={ this.props.field.name } />
|
||||||
{ this.props.field.values[value] }
|
{ this.props.field.values[value] }
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}.bind(this)
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -4,10 +4,14 @@ define([
|
|||||||
function(
|
function(
|
||||||
React
|
React
|
||||||
) {
|
) {
|
||||||
var FormFieldSelect = React.createClass({
|
const FormFieldSelect = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
var options =
|
if (this.props.field.values === undefined) {
|
||||||
Object.keys(this.props.field.values).map(function(value, index) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = Object.keys(this.props.field.values).map(
|
||||||
|
(value, index) => {
|
||||||
return (
|
return (
|
||||||
<option
|
<option
|
||||||
key={ 'option-' + index }
|
key={ 'option-' + index }
|
||||||
@ -15,7 +19,7 @@ function(
|
|||||||
{ this.props.field.values[value] }
|
{ this.props.field.values[value] }
|
||||||
</option>
|
</option>
|
||||||
);
|
);
|
||||||
}.bind(this)
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -26,7 +26,7 @@ function(
|
|||||||
&& (this.props.item.id !== prevProps.item.id)
|
&& (this.props.item.id !== prevProps.item.id)
|
||||||
) {
|
) {
|
||||||
jQuery('#'+this.refs.select.id)
|
jQuery('#'+this.refs.select.id)
|
||||||
.val(this.props.item[this.props.field.name])
|
.val(this.getSelectedValues())
|
||||||
.trigger('change');
|
.trigger('change');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -45,7 +45,11 @@ function(
|
|||||||
if(item.element && item.element.selected) {
|
if(item.element && item.element.selected) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return item.text;
|
if(item.title) {
|
||||||
|
return item.title;
|
||||||
|
} else {
|
||||||
|
return item.text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -65,15 +69,25 @@ function(
|
|||||||
|
|
||||||
select2.select2(
|
select2.select2(
|
||||||
'val',
|
'val',
|
||||||
this.props.item[this.props.field.name]
|
this.getSelectedValues()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setState({ initialized: true });
|
this.setState({ initialized: true });
|
||||||
},
|
},
|
||||||
|
getSelectedValues: function() {
|
||||||
|
if(this.props.field['selected'] !== undefined) {
|
||||||
|
return this.props.field['selected'](this.props.item);
|
||||||
|
} else if(this.props.item !== undefined && this.props.field.name !== undefined) {
|
||||||
|
return this.props.item[this.props.field.name];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
loadCachedItems: function() {
|
loadCachedItems: function() {
|
||||||
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {
|
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {
|
||||||
var items = window['mailpoet_'+this.props.field.endpoint];
|
var items = window['mailpoet_'+this.props.field.endpoint];
|
||||||
|
|
||||||
|
|
||||||
if(this.props.field['filter'] !== undefined) {
|
if(this.props.field['filter'] !== undefined) {
|
||||||
items = items.filter(this.props.field.filter);
|
items = items.filter(this.props.field.filter);
|
||||||
}
|
}
|
||||||
@ -98,31 +112,48 @@ function(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getLabel: function(item) {
|
||||||
|
if(this.props.field['getLabel'] !== undefined) {
|
||||||
|
return this.props.field.getLabel(item, this.props.item);
|
||||||
|
}
|
||||||
|
return item.name;
|
||||||
|
},
|
||||||
|
getSearchLabel: function(item) {
|
||||||
|
if(this.props.field['getSearchLabel'] !== undefined) {
|
||||||
|
return this.props.field.getSearchLabel(item, this.props.item);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
getValue: function(item) {
|
||||||
|
if(this.props.field['getValue'] !== undefined) {
|
||||||
|
return this.props.field.getValue(item, this.props.item);
|
||||||
|
}
|
||||||
|
return item.id;
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var options = this.state.items.map(function(item, index) {
|
const options = this.state.items.map((item, index) => {
|
||||||
|
let label = this.getLabel(item);
|
||||||
|
let searchLabel = this.getSearchLabel(item);
|
||||||
|
let value = this.getValue(item);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<option
|
<option
|
||||||
key={ item.id }
|
key={ 'option-'+index }
|
||||||
value={ item.id }
|
value={ value }
|
||||||
|
title={ searchLabel }
|
||||||
>
|
>
|
||||||
{ item.name }
|
{ label }
|
||||||
</option>
|
</option>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
var default_value = (
|
|
||||||
(this.props.item !== undefined && this.props.field.name !== undefined)
|
|
||||||
? this.props.item[this.props.field.name]
|
|
||||||
: null
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<select
|
<select
|
||||||
id={ this.props.field.id || this.props.field.name }
|
id={ this.props.field.id || this.props.field.name }
|
||||||
ref="select"
|
ref="select"
|
||||||
placeholder={ this.props.field.placeholder }
|
data-placeholder={ this.props.field.placeholder }
|
||||||
multiple={ this.props.field.multiple }
|
multiple={ this.props.field.multiple }
|
||||||
defaultValue={ default_value }
|
defaultValue={ this.getSelectedValues() }
|
||||||
{...this.props.field.validation}
|
{...this.props.field.validation}
|
||||||
>{ options }</select>
|
>{ options }</select>
|
||||||
);
|
);
|
||||||
|
@ -48,7 +48,7 @@ define(
|
|||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: this.props.endpoint,
|
endpoint: this.props.endpoint,
|
||||||
action: 'get',
|
action: 'get',
|
||||||
data: { id: id }
|
data: id
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response === false) {
|
if(response === false) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -617,6 +617,28 @@ var WysijaForm = {
|
|||||||
// this is a url, so do not encode the protocol
|
// this is a url, so do not encode the protocol
|
||||||
return encodeURI(str).replace(/[!'()*]/g, escape);
|
return encodeURI(str).replace(/[!'()*]/g, escape);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
updateBlock: function(field) {
|
||||||
|
var hasUpdated = false;
|
||||||
|
WysijaForm.getBlocks().each(function(b) {
|
||||||
|
if(b.block.getData().id === field.id) {
|
||||||
|
hasUpdated = true;
|
||||||
|
b.block.redraw(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasUpdated;
|
||||||
|
},
|
||||||
|
removeBlock: function(field, callback) {
|
||||||
|
var hasRemoved = false;
|
||||||
|
WysijaForm.getBlocks().each(function(b) {
|
||||||
|
if(b.block.getData().id === field.id) {
|
||||||
|
hasRemoved = true;
|
||||||
|
b.block.removeBlock(callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasRemoved;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -825,10 +847,6 @@ WysijaForm.Block = Class.create({
|
|||||||
Effect.Fade(this.element.identify(), {
|
Effect.Fade(this.element.identify(), {
|
||||||
duration: 0.2,
|
duration: 0.2,
|
||||||
afterFinish: function(effect) {
|
afterFinish: function(effect) {
|
||||||
if(effect.element.next('.mailpoet_form_block') !== undefined && callback !== false) {
|
|
||||||
// show controls of next block to allow mass delete
|
|
||||||
WysijaForm.get(effect.element.next('.mailpoet_form_block')).block.showControls();
|
|
||||||
}
|
|
||||||
// remove placeholder
|
// remove placeholder
|
||||||
if(effect.element.previous('.block_placeholder') !== undefined) {
|
if(effect.element.previous('.block_placeholder') !== undefined) {
|
||||||
effect.element.previous('.block_placeholder').remove();
|
effect.element.previous('.block_placeholder').remove();
|
||||||
|
@ -25,58 +25,49 @@ const columns = [
|
|||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
onTrash: function(response) {
|
onTrash: function(response) {
|
||||||
if(response) {
|
var count = ~~response;
|
||||||
let message = null;
|
var 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message !== null) {
|
if(count === 1) {
|
||||||
MailPoet.Notice.success(message);
|
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) {
|
onDelete: function(response) {
|
||||||
if(response) {
|
var count = ~~response;
|
||||||
let message = null;
|
var message = null;
|
||||||
if(~~response === 1) {
|
|
||||||
message = (
|
|
||||||
'1 form was permanently deleted.'
|
|
||||||
);
|
|
||||||
} else if(~~response > 1) {
|
|
||||||
message = (
|
|
||||||
'%$1d forms were permanently deleted.'
|
|
||||||
).replace('%$1d', ~~response);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message !== null) {
|
if(count === 1) {
|
||||||
MailPoet.Notice.success(message);
|
message = (
|
||||||
}
|
'1 form was permanently deleted.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
message = (
|
||||||
|
'%$1d forms were permanently deleted.'
|
||||||
|
).replace('%$1d', count);
|
||||||
}
|
}
|
||||||
|
MailPoet.Notice.success(message);
|
||||||
},
|
},
|
||||||
onRestore: function(response) {
|
onRestore: function(response) {
|
||||||
if(response) {
|
var count = ~~response;
|
||||||
let message = null;
|
var 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message !== null) {
|
if(count === 1) {
|
||||||
MailPoet.Notice.success(message);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -125,8 +116,8 @@ const FormList = React.createClass({
|
|||||||
endpoint: 'forms',
|
endpoint: 'forms',
|
||||||
action: 'create'
|
action: 'create'
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response !== false) {
|
if(response.result && response.form_id) {
|
||||||
window.location = response;
|
window.location = mailpoet_form_edit_url + response.form_id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -155,7 +146,7 @@ const FormList = React.createClass({
|
|||||||
{ segments }
|
{ segments }
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Created on">
|
<td className="column-date" data-colname="Created on">
|
||||||
<abbr>{ form.created_at }</abbr>
|
<abbr>{ MailPoet.Date.full(form.created_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -14,6 +14,9 @@ function(
|
|||||||
})
|
})
|
||||||
return this.props.onSelectFilter(filters);
|
return this.props.onSelectFilter(filters);
|
||||||
},
|
},
|
||||||
|
handleEmptyTrash: function() {
|
||||||
|
return this.props.onEmptyTrash();
|
||||||
|
},
|
||||||
getAvailableFilters: function() {
|
getAvailableFilters: function() {
|
||||||
let filters = this.props.filters;
|
let filters = this.props.filters;
|
||||||
|
|
||||||
@ -34,7 +37,7 @@ function(
|
|||||||
const available_filters = this.getAvailableFilters()
|
const available_filters = this.getAvailableFilters()
|
||||||
.map(function(filter, i) {
|
.map(function(filter, i) {
|
||||||
let default_value = false;
|
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]
|
default_value = selected_filters[filter]
|
||||||
} else {
|
} else {
|
||||||
jQuery(`select[name="${filter}"]`).val('');
|
jQuery(`select[name="${filter}"]`).val('');
|
||||||
@ -60,9 +63,10 @@ function(
|
|||||||
|
|
||||||
let button = false;
|
let button = false;
|
||||||
|
|
||||||
if(available_filters.length > 0) {
|
if (available_filters.length > 0) {
|
||||||
button = (
|
button = (
|
||||||
<input
|
<input
|
||||||
|
id="post-query-submit"
|
||||||
onClick={ this.handleFilterAction }
|
onClick={ this.handleFilterAction }
|
||||||
type="submit"
|
type="submit"
|
||||||
defaultValue="Filter"
|
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 (
|
return (
|
||||||
<div className="alignleft actions actions">
|
<div className="alignleft actions actions">
|
||||||
{ available_filters }
|
{ available_filters }
|
||||||
{ button }
|
{ button }
|
||||||
|
{ empty_trash }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -74,10 +74,11 @@ define(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var custom_actions = this.props.item_actions;
|
const custom_actions = this.props.item_actions;
|
||||||
var item_actions = false;
|
let item_actions = false;
|
||||||
|
|
||||||
if(custom_actions.length > 0) {
|
if(custom_actions.length > 0) {
|
||||||
|
let is_first = true;
|
||||||
item_actions = custom_actions.map(function(action, index) {
|
item_actions = custom_actions.map(function(action, index) {
|
||||||
if(action.display !== undefined) {
|
if(action.display !== undefined) {
|
||||||
if(action.display(this.props.item) === false) {
|
if(action.display(this.props.item) === false) {
|
||||||
@ -85,10 +86,12 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let custom_action = null;
|
||||||
|
|
||||||
if(action.name === 'trash') {
|
if(action.name === 'trash') {
|
||||||
return (
|
custom_action = (
|
||||||
<span key={ 'action-'+index } className="trash">
|
<span key={ 'action-'+index } className="trash">
|
||||||
{(index > 0) ? ' | ' : ''}
|
{(!is_first) ? ' | ' : ''}
|
||||||
<a
|
<a
|
||||||
href="javascript:;"
|
href="javascript:;"
|
||||||
onClick={ this.handleTrashItem.bind(
|
onClick={ this.handleTrashItem.bind(
|
||||||
@ -100,27 +103,27 @@ define(
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
} else if(action.refresh) {
|
} else if(action.refresh) {
|
||||||
return (
|
custom_action = (
|
||||||
<span
|
<span
|
||||||
onClick={ this.props.onRefreshItems }
|
onClick={ this.props.onRefreshItems }
|
||||||
key={ 'action-'+index } className={ action.name }>
|
key={ 'action-'+index } className={ action.name }>
|
||||||
{(index > 0) ? ' | ' : ''}
|
{(!is_first) ? ' | ' : ''}
|
||||||
{ action.link(this.props.item) }
|
{ action.link(this.props.item) }
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
} else if(action.link) {
|
} else if(action.link) {
|
||||||
return (
|
custom_action = (
|
||||||
<span
|
<span
|
||||||
key={ 'action-'+index } className={ action.name }>
|
key={ 'action-'+index } className={ action.name }>
|
||||||
{(index > 0) ? ' | ' : ''}
|
{(!is_first) ? ' | ' : ''}
|
||||||
{ action.link(this.props.item) }
|
{ action.link(this.props.item) }
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
custom_action = (
|
||||||
<span
|
<span
|
||||||
key={ 'action-'+index } className={ action.name }>
|
key={ 'action-'+index } className={ action.name }>
|
||||||
{(index > 0) ? ' | ' : ''}
|
{(!is_first) ? ' | ' : ''}
|
||||||
<a href="javascript:;" onClick={
|
<a href="javascript:;" onClick={
|
||||||
(action.onClick !== undefined)
|
(action.onClick !== undefined)
|
||||||
? action.onClick.bind(null,
|
? action.onClick.bind(null,
|
||||||
@ -132,6 +135,12 @@ define(
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(custom_action !== null && is_first === true) {
|
||||||
|
is_first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return custom_action;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
item_actions = (
|
item_actions = (
|
||||||
@ -504,10 +513,21 @@ define(
|
|||||||
this.getItems();
|
this.getItems();
|
||||||
}.bind(this));
|
}.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) {
|
handleBulkAction: function(selected_ids, params, callback) {
|
||||||
if(
|
if(
|
||||||
this.state.selection === false
|
this.state.selection === false
|
||||||
&& this.state.selected_ids.length === 0
|
&& this.state.selected_ids.length === 0
|
||||||
|
&& selected_ids !== 'all'
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -520,8 +540,10 @@ define(
|
|||||||
limit: 0,
|
limit: 0,
|
||||||
filter: this.state.filter,
|
filter: this.state.filter,
|
||||||
group: this.state.group,
|
group: this.state.group,
|
||||||
search: this.state.search,
|
search: this.state.search
|
||||||
selection: selected_ids
|
}
|
||||||
|
if(selected_ids !== 'all') {
|
||||||
|
data.listing.selection = selected_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
@ -715,7 +737,10 @@ define(
|
|||||||
<ListingFilters
|
<ListingFilters
|
||||||
filters={ this.state.filters }
|
filters={ this.state.filters }
|
||||||
filter={ this.state.filter }
|
filter={ this.state.filter }
|
||||||
onSelectFilter={ this.handleFilter } />
|
group={ this.state.group }
|
||||||
|
onSelectFilter={ this.handleFilter }
|
||||||
|
onEmptyTrash={ this.handleEmptyTrash }
|
||||||
|
/>
|
||||||
<ListingPages
|
<ListingPages
|
||||||
count={ this.state.count }
|
count={ this.state.count }
|
||||||
page={ this.state.page }
|
page={ this.state.page }
|
||||||
|
@ -7,7 +7,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
setPage: function(page) {
|
setPage: function(page) {
|
||||||
this.props.onSetPage(page);
|
this.setState({
|
||||||
|
page: null
|
||||||
|
}, function () {
|
||||||
|
this.props.onSetPage(this.constrainPage(page));
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
setFirstPage: function() {
|
setFirstPage: function() {
|
||||||
this.setPage(1);
|
this.setPage(1);
|
||||||
@ -16,10 +20,14 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
this.setPage(this.getLastPage());
|
this.setPage(this.getLastPage());
|
||||||
},
|
},
|
||||||
setPreviousPage: function() {
|
setPreviousPage: function() {
|
||||||
this.setPage(this.constrainPage(this.props.page - 1));
|
this.setPage(this.constrainPage(
|
||||||
|
parseInt(this.props.page, 10) - 1)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
setNextPage: function() {
|
setNextPage: function() {
|
||||||
this.setPage(this.constrainPage(this.props.page + 1));
|
this.setPage(this.constrainPage(
|
||||||
|
parseInt(this.props.page, 10) + 1)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
constrainPage: function(page) {
|
constrainPage: function(page) {
|
||||||
return Math.min(Math.max(1, Math.abs(~~page)), this.getLastPage());
|
return Math.min(Math.max(1, Math.abs(~~page)), this.getLastPage());
|
||||||
@ -27,14 +35,16 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
handleSetManualPage: function(e) {
|
handleSetManualPage: function(e) {
|
||||||
if(e.which === 13) {
|
if(e.which === 13) {
|
||||||
this.setPage(this.state.page);
|
this.setPage(this.state.page);
|
||||||
this.setState({ page: null });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleChangeManualPage: function(e) {
|
handleChangeManualPage: function(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
page: this.constrainPage(e.target.value)
|
page: e.target.value
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
handleBlurManualPage: function(e) {
|
||||||
|
this.setPage(e.target.value);
|
||||||
|
},
|
||||||
getLastPage: function() {
|
getLastPage: function() {
|
||||||
return Math.ceil(this.props.count / this.props.limit);
|
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 = (
|
pagination = (
|
||||||
<span className="pagination-links">
|
<span className="pagination-links">
|
||||||
{firstPage}
|
{firstPage}
|
||||||
@ -115,10 +130,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
type="text"
|
type="text"
|
||||||
onChange={ this.handleChangeManualPage }
|
onChange={ this.handleChangeManualPage }
|
||||||
onKeyUp={ this.handleSetManualPage }
|
onKeyUp={ this.handleSetManualPage }
|
||||||
|
onBlur={ this.handleBlurManualPage }
|
||||||
aria-describedby="table-paging"
|
aria-describedby="table-paging"
|
||||||
size="1"
|
size="1"
|
||||||
ref="page"
|
ref="page"
|
||||||
value={ this.state.page || this.props.page }
|
value={ pageValue }
|
||||||
name="paged"
|
name="paged"
|
||||||
id="current-page-selector"
|
id="current-page-selector"
|
||||||
className="current-page" />
|
className="current-page" />
|
||||||
|
@ -32,10 +32,10 @@ define([
|
|||||||
inclusionType: 'include', // 'include'|'exclude'
|
inclusionType: 'include', // 'include'|'exclude'
|
||||||
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
||||||
titleFormat: 'h1', // 'h1'|'h2'|'h3'|'ul'
|
titleFormat: 'h1', // 'h1'|'h2'|'h3'|'ul'
|
||||||
titlePosition: 'inTextBlock', // 'inTextBlock'|'aboveBlock',
|
|
||||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||||
titleIsLink: false, // false|true
|
titleIsLink: false, // false|true
|
||||||
imagePadded: true, // true|false
|
imageFullWidth: false, // true|false
|
||||||
|
featuredImagePosition: 'belowTitle', // 'aboveTitle'|'belowTitle'|'none'
|
||||||
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||||
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
||||||
authorPrecededBy: 'Author:',
|
authorPrecededBy: 'Author:',
|
||||||
@ -63,7 +63,7 @@ define([
|
|||||||
initialize: function() {
|
initialize: function() {
|
||||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||||
this.fetchPosts();
|
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:featuredImagePosition 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('readMoreButton'), 'change', this._scheduleFetchPosts);
|
||||||
this.listenTo(this.get('divider'), 'change', this._scheduleFetchPosts);
|
this.listenTo(this.get('divider'), 'change', this._scheduleFetchPosts);
|
||||||
},
|
},
|
||||||
@ -81,7 +81,7 @@ define([
|
|||||||
* ALC posts on each model change
|
* ALC posts on each model change
|
||||||
*/
|
*/
|
||||||
_scheduleFetchPosts: function() {
|
_scheduleFetchPosts: function() {
|
||||||
var timeout = 2000,
|
var timeout = 500,
|
||||||
that = this;
|
that = this;
|
||||||
if (this._fetchPostsTimer !== undefined) {
|
if (this._fetchPostsTimer !== undefined) {
|
||||||
clearTimeout(this._fetchPostsTimer);
|
clearTimeout(this._fetchPostsTimer);
|
||||||
@ -142,9 +142,9 @@ define([
|
|||||||
"keyup .mailpoet_automated_latest_content_show_amount": _.partial(this.changeField, "amount"),
|
"keyup .mailpoet_automated_latest_content_show_amount": _.partial(this.changeField, "amount"),
|
||||||
"change .mailpoet_automated_latest_content_content_type": _.partial(this.changeField, "contentType"),
|
"change .mailpoet_automated_latest_content_content_type": _.partial(this.changeField, "contentType"),
|
||||||
"change .mailpoet_automated_latest_content_include_or_exclude": _.partial(this.changeField, "inclusionType"),
|
"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_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_featured_image_position": _.partial(this.changeField, "featuredImagePosition"),
|
||||||
"change .mailpoet_automated_latest_content_show_author": _.partial(this.changeField, "showAuthor"),
|
"change .mailpoet_automated_latest_content_show_author": _.partial(this.changeField, "showAuthor"),
|
||||||
"keyup .mailpoet_automated_latest_content_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
"keyup .mailpoet_automated_latest_content_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
||||||
"change .mailpoet_automated_latest_content_show_categories": _.partial(this.changeField, "showCategories"),
|
"change .mailpoet_automated_latest_content_show_categories": _.partial(this.changeField, "showCategories"),
|
||||||
@ -273,12 +273,13 @@ define([
|
|||||||
},
|
},
|
||||||
changeDisplayType: function(event) {
|
changeDisplayType: function(event) {
|
||||||
var value = jQuery(event.target).val();
|
var value = jQuery(event.target).val();
|
||||||
|
|
||||||
if (value == 'titleOnly') {
|
if (value == 'titleOnly') {
|
||||||
this.$('.mailpoet_automated_latest_content_title_position_container').addClass('mailpoet_hidden');
|
|
||||||
this.$('.mailpoet_automated_latest_content_title_as_list').removeClass('mailpoet_hidden');
|
this.$('.mailpoet_automated_latest_content_title_as_list').removeClass('mailpoet_hidden');
|
||||||
|
this.$('.mailpoet_automated_latest_content_image_full_width_option').addClass('mailpoet_hidden');
|
||||||
} else {
|
} else {
|
||||||
this.$('.mailpoet_automated_latest_content_title_position_container').removeClass('mailpoet_hidden');
|
|
||||||
this.$('.mailpoet_automated_latest_content_title_as_list').addClass('mailpoet_hidden');
|
this.$('.mailpoet_automated_latest_content_title_as_list').addClass('mailpoet_hidden');
|
||||||
|
this.$('.mailpoet_automated_latest_content_image_full_width_option').removeClass('mailpoet_hidden');
|
||||||
|
|
||||||
// Reset titleFormat if it was set to List when switching away from displayType=titleOnly
|
// Reset titleFormat if it was set to List when switching away from displayType=titleOnly
|
||||||
if (this.model.get('titleFormat') === 'ul') {
|
if (this.model.get('titleFormat') === 'ul') {
|
||||||
@ -287,6 +288,12 @@ define([
|
|||||||
this.$('.mailpoet_automated_latest_content_title_as_link').removeClass('mailpoet_hidden');
|
this.$('.mailpoet_automated_latest_content_title_as_link').removeClass('mailpoet_hidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value === 'excerpt') {
|
||||||
|
this.$('.mailpoet_automated_latest_content_featured_image_position_container').removeClass('mailpoet_hidden');
|
||||||
|
} else {
|
||||||
|
this.$('.mailpoet_automated_latest_content_featured_image_position_container').addClass('mailpoet_hidden');
|
||||||
|
}
|
||||||
this.changeField('displayType', event);
|
this.changeField('displayType', event);
|
||||||
},
|
},
|
||||||
changeTitleFormat: function(event) {
|
changeTitleFormat: function(event) {
|
||||||
|
@ -133,10 +133,10 @@ define([
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
transitionIn: function() {
|
transitionIn: function() {
|
||||||
return this._transition('slideDown', 'fadeIn', 'easeIn');
|
return this._transition('slideDown', 'fadeIn', 'easeOut');
|
||||||
},
|
},
|
||||||
transitionOut: function() {
|
transitionOut: function() {
|
||||||
return this._transition('slideUp', 'fadeOut', 'easeOut');
|
return this._transition('slideUp', 'fadeOut', 'easeIn');
|
||||||
},
|
},
|
||||||
_transition: function(slideDirection, fadeDirection, easing) {
|
_transition: function(slideDirection, fadeDirection, easing) {
|
||||||
var promise = jQuery.Deferred();
|
var promise = jQuery.Deferred();
|
||||||
|
@ -32,6 +32,7 @@ define([
|
|||||||
fontColor: '#000000',
|
fontColor: '#000000',
|
||||||
fontFamily: 'Arial',
|
fontFamily: 'Arial',
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
|
fontWeight: 'normal', // 'normal'|'bold'
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -72,6 +73,7 @@ define([
|
|||||||
"change .mailpoet_field_button_font_size": _.partial(this.changeField, "styles.block.fontSize"),
|
"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_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||||
"change .mailpoet_field_button_border_color": _.partial(this.changeColorField, "styles.block.borderColor"),
|
"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)),
|
"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)),
|
"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());
|
this.$(fieldToUpdate).val(jQuery(event.target).val());
|
||||||
callable(event);
|
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({
|
Module.ButtonWidgetView = base.WidgetView.extend({
|
||||||
|
@ -41,7 +41,7 @@ define([
|
|||||||
getTemplate: function() { return templates.footerBlock; },
|
getTemplate: function() { return templates.footerBlock; },
|
||||||
modelEvents: _.extend({
|
modelEvents: _.extend({
|
||||||
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render',
|
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render',
|
||||||
}, base.BlockView.prototype.modelEvents),
|
}, _.omit(base.BlockView.prototype.modelEvents, 'change')),
|
||||||
onDragSubstituteBy: function() { return Module.FooterWidgetView; },
|
onDragSubstituteBy: function() { return Module.FooterWidgetView; },
|
||||||
onRender: function() {
|
onRender: function() {
|
||||||
this.toolsView = new Module.FooterBlockToolsView({ model: this.model });
|
this.toolsView = new Module.FooterBlockToolsView({ model: this.model });
|
||||||
@ -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",
|
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",
|
invalid_elements: "script",
|
||||||
style_formats: [
|
block_formats: 'Paragraph=p',
|
||||||
{title: 'Paragraph', block: 'p'},
|
|
||||||
],
|
|
||||||
|
|
||||||
plugins: "link textcolor mailpoet_custom_fields",
|
plugins: "link textcolor colorpicker mailpoet_custom_fields",
|
||||||
|
|
||||||
setup: function(editor) {
|
setup: function(editor) {
|
||||||
editor.on('change', function(e) {
|
editor.on('change', function(e) {
|
||||||
|
@ -41,7 +41,7 @@ define([
|
|||||||
getTemplate: function() { return templates.headerBlock; },
|
getTemplate: function() { return templates.headerBlock; },
|
||||||
modelEvents: _.extend({
|
modelEvents: _.extend({
|
||||||
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render',
|
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render',
|
||||||
}, base.BlockView.prototype.modelEvents),
|
}, _.omit(base.BlockView.prototype.modelEvents, 'change')),
|
||||||
onDragSubstituteBy: function() { return Module.HeaderWidgetView; },
|
onDragSubstituteBy: function() { return Module.HeaderWidgetView; },
|
||||||
onRender: function() {
|
onRender: function() {
|
||||||
this.toolsView = new Module.HeaderBlockToolsView({ model: this.model });
|
this.toolsView = new Module.HeaderBlockToolsView({ model: this.model });
|
||||||
@ -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",
|
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",
|
invalid_elements: "script",
|
||||||
style_formats: [
|
block_formats: 'Paragraph=p',
|
||||||
{title: 'Paragraph', block: 'p'},
|
|
||||||
],
|
|
||||||
|
|
||||||
plugins: "link textcolor mailpoet_custom_fields",
|
plugins: "link textcolor colorpicker mailpoet_custom_fields",
|
||||||
|
|
||||||
setup: function(editor) {
|
setup: function(editor) {
|
||||||
editor.on('change', function(e) {
|
editor.on('change', function(e) {
|
||||||
|
@ -20,7 +20,7 @@ define([
|
|||||||
link: 'http://example.org',
|
link: 'http://example.org',
|
||||||
src: 'no-image.png',
|
src: 'no-image.png',
|
||||||
alt: 'An image of...',
|
alt: 'An image of...',
|
||||||
padded: true, // true | false - Padded or full width
|
fullWidth: true, // true | false
|
||||||
width: '64px',
|
width: '64px',
|
||||||
height: '64px',
|
height: '64px',
|
||||||
styles: {
|
styles: {
|
||||||
@ -45,10 +45,10 @@ define([
|
|||||||
this.toolsView = new Module.ImageBlockToolsView({ model: this.model });
|
this.toolsView = new Module.ImageBlockToolsView({ model: this.model });
|
||||||
this.toolsRegion.show(this.toolsView);
|
this.toolsRegion.show(this.toolsView);
|
||||||
|
|
||||||
if (this.model.get('padded')) {
|
if (this.model.get('fullWidth')) {
|
||||||
this.$el.removeClass('mailpoet_full_image');
|
|
||||||
} else {
|
|
||||||
this.$el.addClass('mailpoet_full_image');
|
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_link": _.partial(this.changeField, "link"),
|
||||||
"keyup .mailpoet_field_image_address": _.partial(this.changeField, "src"),
|
"keyup .mailpoet_field_image_address": _.partial(this.changeField, "src"),
|
||||||
"keyup .mailpoet_field_image_alt_text": _.partial(this.changeField, "alt"),
|
"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"),
|
"change .mailpoet_field_image_alignment": _.partial(this.changeField, "styles.block.textAlign"),
|
||||||
"click .mailpoet_field_image_select_another_image": "showMediaManager",
|
"click .mailpoet_field_image_select_another_image": "showMediaManager",
|
||||||
"click .mailpoet_done_editing": "close",
|
"click .mailpoet_done_editing": "close",
|
||||||
|
@ -43,10 +43,10 @@ define([
|
|||||||
inclusionType: 'include', // 'include'|'exclude'
|
inclusionType: 'include', // 'include'|'exclude'
|
||||||
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
||||||
titleFormat: 'h1', // 'h1'|'h2'|'h3'|'ul'
|
titleFormat: 'h1', // 'h1'|'h2'|'h3'|'ul'
|
||||||
titlePosition: 'inTextBlock', // 'inTextBlock'|'aboveBlock',
|
|
||||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||||
titleIsLink: false, // false|true
|
titleIsLink: false, // false|true
|
||||||
imagePadded: true, // true|false
|
imageFullWidth: false, // true|false
|
||||||
|
featuredImagePosition: 'belowTitle', // 'aboveTitle'|'belowTitle'|'none'
|
||||||
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||||
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
||||||
authorPrecededBy: 'Author:',
|
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.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.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:featuredImagePosition 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('readMoreButton'), 'change', refreshTransformedPosts);
|
||||||
this.listenTo(this.get('divider'), 'change', refreshTransformedPosts);
|
this.listenTo(this.get('divider'), 'change', refreshTransformedPosts);
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ define([
|
|||||||
data.posts = this.get('_selectedPosts').pluck('ID');
|
data.posts = this.get('_selectedPosts').pluck('ID');
|
||||||
|
|
||||||
if (data.posts.length === 0) {
|
if (data.posts.length === 0) {
|
||||||
this.get('_transformedPosts.blocks').reset();
|
this.get('_transformedPosts').get('blocks').reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,9 +394,9 @@ define([
|
|||||||
"keyup .mailpoet_posts_show_amount": _.partial(this.changeField, "amount"),
|
"keyup .mailpoet_posts_show_amount": _.partial(this.changeField, "amount"),
|
||||||
"change .mailpoet_posts_content_type": _.partial(this.changeField, "contentType"),
|
"change .mailpoet_posts_content_type": _.partial(this.changeField, "contentType"),
|
||||||
"change .mailpoet_posts_include_or_exclude": _.partial(this.changeField, "inclusionType"),
|
"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_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_featured_image_position": _.partial(this.changeField, "featuredImagePosition"),
|
||||||
"change .mailpoet_posts_show_author": _.partial(this.changeField, "showAuthor"),
|
"change .mailpoet_posts_show_author": _.partial(this.changeField, "showAuthor"),
|
||||||
"keyup .mailpoet_posts_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
"keyup .mailpoet_posts_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
||||||
"change .mailpoet_posts_show_categories": _.partial(this.changeField, "showCategories"),
|
"change .mailpoet_posts_show_categories": _.partial(this.changeField, "showCategories"),
|
||||||
@ -448,11 +448,11 @@ define([
|
|||||||
changeDisplayType: function(event) {
|
changeDisplayType: function(event) {
|
||||||
var value = jQuery(event.target).val();
|
var value = jQuery(event.target).val();
|
||||||
if (value == 'titleOnly') {
|
if (value == 'titleOnly') {
|
||||||
this.$('.mailpoet_posts_title_position_container').addClass('mailpoet_hidden');
|
|
||||||
this.$('.mailpoet_posts_title_as_list').removeClass('mailpoet_hidden');
|
this.$('.mailpoet_posts_title_as_list').removeClass('mailpoet_hidden');
|
||||||
|
this.$('.mailpoet_posts_image_full_width_option').addClass('mailpoet_hidden');
|
||||||
} else {
|
} else {
|
||||||
this.$('.mailpoet_posts_title_position_container').removeClass('mailpoet_hidden');
|
|
||||||
this.$('.mailpoet_posts_title_as_list').addClass('mailpoet_hidden');
|
this.$('.mailpoet_posts_title_as_list').addClass('mailpoet_hidden');
|
||||||
|
this.$('.mailpoet_posts_image_full_width_option').removeClass('mailpoet_hidden');
|
||||||
|
|
||||||
// Reset titleFormat if it was set to List when switching away from displayType=titleOnly
|
// Reset titleFormat if it was set to List when switching away from displayType=titleOnly
|
||||||
if (this.model.get('titleFormat') === 'ul') {
|
if (this.model.get('titleFormat') === 'ul') {
|
||||||
@ -461,6 +461,13 @@ define([
|
|||||||
this.$('.mailpoet_posts_title_as_link').removeClass('mailpoet_hidden');
|
this.$('.mailpoet_posts_title_as_link').removeClass('mailpoet_hidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value === 'excerpt') {
|
||||||
|
this.$('.mailpoet_posts_featured_image_position_container').removeClass('mailpoet_hidden');
|
||||||
|
} else {
|
||||||
|
this.$('.mailpoet_posts_featured_image_position_container').addClass('mailpoet_hidden');
|
||||||
|
}
|
||||||
|
|
||||||
this.changeField('displayType', event);
|
this.changeField('displayType', event);
|
||||||
},
|
},
|
||||||
changeTitleFormat: function(event) {
|
changeTitleFormat: function(event) {
|
||||||
|
@ -52,21 +52,15 @@ define([
|
|||||||
inline: true,
|
inline: true,
|
||||||
|
|
||||||
menubar: false,
|
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",
|
toolbar2: "alignleft aligncenter alignright alignjustify | bullist numlist blockquote | code mailpoet_custom_fields",
|
||||||
|
|
||||||
//forced_root_block: 'p',
|
//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]",
|
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",
|
invalid_elements: "script",
|
||||||
style_formats: [
|
block_formats: 'Heading 1=h1;Heading 2=h2;Heading 3=h3;Paragraph=p',
|
||||||
{title: 'Heading 1', block: 'h1'},
|
|
||||||
{title: 'Heading 2', block: 'h2'},
|
|
||||||
{title: 'Heading 3', block: 'h3'},
|
|
||||||
|
|
||||||
{title: 'Paragraph', block: 'p'},
|
plugins: "link code textcolor colorpicker mailpoet_custom_fields",
|
||||||
],
|
|
||||||
|
|
||||||
plugins: "link code textcolor mailpoet_custom_fields",
|
|
||||||
|
|
||||||
setup: function(editor) {
|
setup: function(editor) {
|
||||||
editor.on('change', function(e) {
|
editor.on('change', function(e) {
|
||||||
|
@ -9,7 +9,7 @@ define([
|
|||||||
|
|
||||||
Module._query = function(args) {
|
Module._query = function(args) {
|
||||||
return MailPoet.Ajax.post({
|
return MailPoet.Ajax.post({
|
||||||
endpoint: 'wordpress',
|
endpoint: 'automatedLatestContent',
|
||||||
action: args.action,
|
action: args.action,
|
||||||
data: args.options || {},
|
data: args.options || {},
|
||||||
});
|
});
|
||||||
@ -63,16 +63,17 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Module.saveNewsletter = function(options) {
|
Module.saveNewsletter = function(options) {
|
||||||
return Module._query({
|
return MailPoet.Ajax.post({
|
||||||
|
endpoint: 'newsletters',
|
||||||
action: 'save',
|
action: 'save',
|
||||||
options: options,
|
data: options || {},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Module.previewNewsletter = function(options) {
|
Module.previewNewsletter = function(options) {
|
||||||
return MailPoet.Ajax.post({
|
return MailPoet.Ajax.post({
|
||||||
endpoint: 'newsletters',
|
endpoint: 'newsletters',
|
||||||
action: 'preview',
|
action: 'sendPreview',
|
||||||
data: options || {},
|
data: options || {},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ define([
|
|||||||
// Does not hold newsletter content nor newsletter styles, those are
|
// Does not hold newsletter content nor newsletter styles, those are
|
||||||
// handled by other components.
|
// handled by other components.
|
||||||
Module.NewsletterModel = SuperModel.extend({
|
Module.NewsletterModel = SuperModel.extend({
|
||||||
stale: ['body'],
|
stale: ['body', 'created_at', 'deleted_at', 'updated_at'],
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.on('change', function() {
|
this.on('change', function() {
|
||||||
App.getChannel().trigger('autoSave');
|
App.getChannel().trigger('autoSave');
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
define([
|
define([
|
||||||
'newsletter_editor/App',
|
'newsletter_editor/App',
|
||||||
|
'newsletter_editor/components/communication',
|
||||||
'mailpoet',
|
'mailpoet',
|
||||||
'notice',
|
'notice',
|
||||||
'backbone',
|
'backbone',
|
||||||
@ -8,7 +9,18 @@ define([
|
|||||||
'blob',
|
'blob',
|
||||||
'filesaver',
|
'filesaver',
|
||||||
'html2canvas'
|
'html2canvas'
|
||||||
], function(App, MailPoet, Notice, Backbone, Marionette, jQuery, Blob, FileSaver, html2canvas) {
|
], function(
|
||||||
|
App,
|
||||||
|
CommunicationComponent,
|
||||||
|
MailPoet,
|
||||||
|
Notice,
|
||||||
|
Backbone,
|
||||||
|
Marionette,
|
||||||
|
jQuery,
|
||||||
|
Blob,
|
||||||
|
FileSaver,
|
||||||
|
html2canvas
|
||||||
|
) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -17,26 +29,33 @@ define([
|
|||||||
|
|
||||||
// Save editor contents to server
|
// Save editor contents to server
|
||||||
Module.save = function() {
|
Module.save = function() {
|
||||||
App.getChannel().trigger('beforeEditorSave');
|
|
||||||
|
|
||||||
var json = App.toJSON();
|
var json = App.toJSON();
|
||||||
|
|
||||||
|
// Stringify to enable transmission of primitive non-string value types
|
||||||
|
if (!_.isUndefined(json.body)) {
|
||||||
|
json.body = JSON.stringify(json.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
App.getChannel().trigger('beforeEditorSave', json);
|
||||||
|
|
||||||
// save newsletter
|
// save newsletter
|
||||||
MailPoet.Ajax.post({
|
CommunicationComponent.saveNewsletter(json).done(function(response) {
|
||||||
endpoint: 'newsletters',
|
|
||||||
action: 'save',
|
|
||||||
data: json,
|
|
||||||
}).done(function(response) {
|
|
||||||
if(response.success !== undefined && response.success === true) {
|
if(response.success !== undefined && response.success === true) {
|
||||||
// TODO: Handle translations
|
// TODO: Handle translations
|
||||||
//MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
|
//MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
|
||||||
} else if(response.error !== undefined) {
|
} else if(response.error !== undefined) {
|
||||||
if(response.error.length === 0) {
|
if(response.error.length === 0) {
|
||||||
// TODO: Handle translations
|
// TODO: Handle translations
|
||||||
MailPoet.Notice.error("<?php _e('An unknown error occurred, please check your settings.'); ?>");
|
MailPoet.Notice.error(
|
||||||
|
"An unknown error occurred, please check your settings.",
|
||||||
|
{
|
||||||
|
scroll: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$(response.error).each(function(i, error) {
|
$(response.error).each(function(i, error) {
|
||||||
MailPoet.Notice.error(error);
|
MailPoet.Notice.error(error, { scroll: true });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,7 +67,28 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Module.getThumbnail = function(element, options) {
|
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) {
|
Module.saveTemplate = function(options) {
|
||||||
@ -58,7 +98,7 @@ define([
|
|||||||
promise.then(function(thumbnail) {
|
promise.then(function(thumbnail) {
|
||||||
var data = _.extend(options || {}, {
|
var data = _.extend(options || {}, {
|
||||||
thumbnail: thumbnail.toDataURL('image/jpeg'),
|
thumbnail: thumbnail.toDataURL('image/jpeg'),
|
||||||
body: App.getBody(),
|
body: JSON.stringify(App.getBody()),
|
||||||
});
|
});
|
||||||
|
|
||||||
return MailPoet.Ajax.post({
|
return MailPoet.Ajax.post({
|
||||||
@ -154,6 +194,7 @@ define([
|
|||||||
App.getConfig().get('translations.templateNameMissing'),
|
App.getConfig().get('translations.templateNameMissing'),
|
||||||
{
|
{
|
||||||
positionAfter: that.$el,
|
positionAfter: that.$el,
|
||||||
|
scroll: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (templateDescription === '') {
|
} else if (templateDescription === '') {
|
||||||
@ -161,6 +202,7 @@ define([
|
|||||||
App.getConfig().get('translations.templateDescriptionMissing'),
|
App.getConfig().get('translations.templateDescriptionMissing'),
|
||||||
{
|
{
|
||||||
positionAfter: that.$el,
|
positionAfter: that.$el,
|
||||||
|
scroll: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -174,6 +216,7 @@ define([
|
|||||||
App.getConfig().get('translations.templateSaved'),
|
App.getConfig().get('translations.templateSaved'),
|
||||||
{
|
{
|
||||||
positionAfter: that.$el,
|
positionAfter: that.$el,
|
||||||
|
scroll: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
@ -182,6 +225,7 @@ define([
|
|||||||
App.getConfig().get('translations.templateSaveFailed'),
|
App.getConfig().get('translations.templateSaveFailed'),
|
||||||
{
|
{
|
||||||
positionAfter: that.$el,
|
positionAfter: that.$el,
|
||||||
|
scroll: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -206,6 +250,7 @@ define([
|
|||||||
App.getConfig().get('translations.templateNameMissing'),
|
App.getConfig().get('translations.templateNameMissing'),
|
||||||
{
|
{
|
||||||
positionAfter: that.$el,
|
positionAfter: that.$el,
|
||||||
|
scroll: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (templateDescription === '') {
|
} else if (templateDescription === '') {
|
||||||
@ -213,6 +258,7 @@ define([
|
|||||||
App.getConfig().get('translations.templateDescriptionMissing'),
|
App.getConfig().get('translations.templateDescriptionMissing'),
|
||||||
{
|
{
|
||||||
positionAfter: that.$el,
|
positionAfter: that.$el,
|
||||||
|
scroll: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -225,15 +225,22 @@ define([
|
|||||||
showPreview: function() {
|
showPreview: function() {
|
||||||
var json = App.toJSON();
|
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.Modal.loading(true);
|
||||||
|
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'newsletters',
|
endpoint: 'newsletters',
|
||||||
action: 'render',
|
action: 'render',
|
||||||
data: json,
|
data: json,
|
||||||
}).done(function(response){
|
}).done(function(response){
|
||||||
console.log('Should open a new window');
|
MailPoet.Modal.loading(false);
|
||||||
window.open('data:text/html,' + encodeURIComponent(response.rendered_body), '_blank');
|
window.open('data:text/html;charset=utf-8,' + encodeURIComponent(response.rendered_body), '_blank');
|
||||||
}).fail(function(error) {
|
}).fail(function(error) {
|
||||||
console.log('Preview error', json);
|
MailPoet.Modal.loading(false);
|
||||||
alert('Something went wrong, check console');
|
alert('Something went wrong, check console');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -241,27 +248,42 @@ define([
|
|||||||
// testing sending method
|
// testing sending method
|
||||||
console.log('trying to send a preview');
|
console.log('trying to send a preview');
|
||||||
// get form data
|
// get form data
|
||||||
|
var $emailField = this.$('#mailpoet_preview_to_email');
|
||||||
var data = {
|
var data = {
|
||||||
from_name: this.$('#mailpoet_preview_from_name').val(),
|
subscriber: $emailField.val(),
|
||||||
from_email: this.$('#mailpoet_preview_from_email').val(),
|
id: App.getNewsletter().get('id'),
|
||||||
to_email: this.$('#mailpoet_preview_to_email').val(),
|
|
||||||
newsletter: App.newsletterId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (data.subscriber.length <= 0) {
|
||||||
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.newsletterPreviewEmailMissing'),
|
||||||
|
{
|
||||||
|
positionAfter: $emailField,
|
||||||
|
scroll: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// send test email
|
// send test email
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
// TODO: Migrate logic to new AJAX format
|
|
||||||
CommunicationComponent.previewNewsletter(data).done(function(response) {
|
CommunicationComponent.previewNewsletter(data).done(function(response) {
|
||||||
if(response.success !== undefined && response.success === true) {
|
if(response.result !== undefined && response.result === true) {
|
||||||
MailPoet.Notice.success(App.getConfig().get('translations.testEmailSent'));
|
MailPoet.Notice.success(App.getConfig().get('translations.newsletterPreviewSent'), { scroll: true });
|
||||||
} else if(response.error !== undefined) {
|
} else {
|
||||||
if(response.error.length === 0) {
|
if (_.isArray(response.errors)) {
|
||||||
MailPoet.Notice.error(App.getConfig().get('translations.unknownErrorOccurred'));
|
response.errors.map(function(error) {
|
||||||
} else {
|
MailPoet.Notice.error(error, { scroll: true });
|
||||||
$(response.error).each(function(i, error) {
|
|
||||||
MailPoet.Notice.error(error);
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.newsletterPreviewFailedToSend'),
|
||||||
|
{
|
||||||
|
scroll: true,
|
||||||
|
static: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
|
@ -43,58 +43,49 @@ define(
|
|||||||
|
|
||||||
var messages = {
|
var messages = {
|
||||||
onTrash: function(response) {
|
onTrash: function(response) {
|
||||||
var count = ~~response.newsletters;
|
var count = ~~response;
|
||||||
var message = null;
|
var message = null;
|
||||||
|
|
||||||
if(count === 1 || response === true) {
|
if(count === 1) {
|
||||||
message = (
|
message = (
|
||||||
'1 newsletter was moved to the trash.'
|
'1 newsletter was moved to the trash.'
|
||||||
);
|
);
|
||||||
} else if(count > 1) {
|
} else {
|
||||||
message = (
|
message = (
|
||||||
'%$1d newsletters were moved to the trash.'
|
'%$1d newsletters were moved to the trash.'
|
||||||
).replace('%$1d', count);
|
).replace('%$1d', count);
|
||||||
}
|
}
|
||||||
|
MailPoet.Notice.success(message);
|
||||||
if(message !== null) {
|
|
||||||
MailPoet.Notice.success(message);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onDelete: function(response) {
|
onDelete: function(response) {
|
||||||
var count = ~~response.newsletters;
|
var count = ~~response;
|
||||||
var message = null;
|
var message = null;
|
||||||
|
|
||||||
if(count === 1 || response === true) {
|
if(count === 1) {
|
||||||
message = (
|
message = (
|
||||||
'1 newsletter was permanently deleted.'
|
'1 newsletter was permanently deleted.'
|
||||||
);
|
);
|
||||||
} else if(count > 1) {
|
} else {
|
||||||
message = (
|
message = (
|
||||||
'%$1d newsletters were permanently deleted.'
|
'%$1d newsletters were permanently deleted.'
|
||||||
).replace('%$1d', count);
|
).replace('%$1d', count);
|
||||||
}
|
}
|
||||||
|
MailPoet.Notice.success(message);
|
||||||
if(message !== null) {
|
|
||||||
MailPoet.Notice.success(message);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onRestore: function(response) {
|
onRestore: function(response) {
|
||||||
var count = ~~response.newsletters;
|
var count = ~~response;
|
||||||
var message = null;
|
var message = null;
|
||||||
|
|
||||||
if(count === 1 || response === true) {
|
if(count === 1) {
|
||||||
message = (
|
message = (
|
||||||
'1 newsletter has been restored from the trash.'
|
'1 newsletter has been restored from the trash.'
|
||||||
);
|
);
|
||||||
} else if(count > 1) {
|
} else {
|
||||||
message = (
|
message = (
|
||||||
'%$1d newsletters have been restored from the trash.'
|
'%$1d newsletters have been restored from the trash.'
|
||||||
).replace('%$1d', count);
|
).replace('%$1d', count);
|
||||||
}
|
}
|
||||||
|
MailPoet.Notice.success(message);
|
||||||
if(message !== null) {
|
|
||||||
MailPoet.Notice.success(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -144,7 +135,7 @@ define(
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
renderStatus: function(item) {
|
renderStatus: function(item) {
|
||||||
if(item.queue === null) {
|
if(!item.queue) {
|
||||||
return (
|
return (
|
||||||
<span>Not sent yet.</span>
|
<span>Not sent yet.</span>
|
||||||
);
|
);
|
||||||
@ -217,10 +208,8 @@ define(
|
|||||||
'has-row-actions'
|
'has-row-actions'
|
||||||
);
|
);
|
||||||
|
|
||||||
var segments = mailpoet_segments.filter(function(segment) {
|
var segments = newsletter.segments.map(function(segment) {
|
||||||
return (jQuery.inArray(segment.id, newsletter.segments) !== -1);
|
return segment.name
|
||||||
}).map(function(segment) {
|
|
||||||
return segment.name;
|
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -238,10 +227,10 @@ define(
|
|||||||
{ segments }
|
{ segments }
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Subscribed on">
|
<td className="column-date" data-colname="Subscribed on">
|
||||||
<abbr>{ newsletter.created_at }</abbr>
|
<abbr>{ MailPoet.Date.full(newsletter.created_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Last modified on">
|
<td className="column-date" data-colname="Last modified on">
|
||||||
<abbr>{ newsletter.updated_at }</abbr>
|
<abbr>{ MailPoet.Date.full(newsletter.updated_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -26,7 +26,8 @@ define(
|
|||||||
"Tempt them to open your email.",
|
"Tempt them to open your email.",
|
||||||
type: 'text',
|
type: 'text',
|
||||||
validation: {
|
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);
|
return !!(!segment.deleted_at);
|
||||||
},
|
},
|
||||||
validation: {
|
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: [
|
mixins: [
|
||||||
Router.History
|
Router.History
|
||||||
],
|
],
|
||||||
|
componentDidMount: function() {
|
||||||
|
jQuery('#mailpoet_newsletter').parsley();
|
||||||
|
},
|
||||||
|
isValid: function() {
|
||||||
|
return jQuery('#mailpoet_newsletter').parsley().isValid();
|
||||||
|
},
|
||||||
handleSend: function() {
|
handleSend: function() {
|
||||||
if(jQuery('#mailpoet_newsletter').parsley().validate() === true) {
|
if(!this.isValid()) {
|
||||||
|
jQuery('#mailpoet_newsletter').parsley().validate();
|
||||||
|
} else {
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'sendingQueue',
|
endpoint: 'sendingQueue',
|
||||||
action: 'add',
|
action: 'add',
|
||||||
@ -132,9 +142,7 @@ define(
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if(response.errors) {
|
if(response.errors) {
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(response.errors);
|
||||||
response.errors.join("<br />")
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(
|
||||||
'An error occurred while trying to send. '+
|
'An error occurred while trying to send. '+
|
||||||
@ -144,14 +152,7 @@ define(
|
|||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
},
|
return false;
|
||||||
componentDidMount: function() {
|
|
||||||
if(this.isMounted()) {
|
|
||||||
jQuery('#mailpoet_newsletter').parsley();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isValid: function() {
|
|
||||||
return (jQuery('#mailpoet_newsletter').parsley().validate());
|
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
@ -166,8 +167,8 @@ define(
|
|||||||
fields={ fields }
|
fields={ fields }
|
||||||
params={ this.props.params }
|
params={ this.props.params }
|
||||||
messages={ messages }
|
messages={ messages }
|
||||||
isValid={ this.isValid }>
|
isValid={ this.isValid }
|
||||||
|
>
|
||||||
<p className="submit">
|
<p className="submit">
|
||||||
<input
|
<input
|
||||||
className="button button-primary"
|
className="button button-primary"
|
||||||
|
@ -18,12 +18,21 @@ define(
|
|||||||
|
|
||||||
var ImportTemplate = React.createClass({
|
var ImportTemplate = React.createClass({
|
||||||
saveTemplate: function(template) {
|
saveTemplate: function(template) {
|
||||||
|
|
||||||
|
// Stringify to enable transmission of primitive non-string value types
|
||||||
|
if (!_.isUndefined(template.body)) {
|
||||||
|
template.body = JSON.stringify(template.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'newsletterTemplates',
|
endpoint: 'newsletterTemplates',
|
||||||
action: 'save',
|
action: 'save',
|
||||||
data: template
|
data: template
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response === true) {
|
MailPoet.Modal.loading(false);
|
||||||
|
if(response.result === true) {
|
||||||
this.props.onImport(template);
|
this.props.onImport(template);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
response.map(function(error) {
|
||||||
@ -86,10 +95,13 @@ define(
|
|||||||
getTemplates: function() {
|
getTemplates: function() {
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
|
|
||||||
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'newsletterTemplates',
|
endpoint: 'newsletterTemplates',
|
||||||
action: 'getAll',
|
action: 'getAll',
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
|
MailPoet.Modal.loading(false);
|
||||||
if(this.isMounted()) {
|
if(this.isMounted()) {
|
||||||
|
|
||||||
if(response.length === 0) {
|
if(response.length === 0) {
|
||||||
@ -111,12 +123,19 @@ define(
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
handleSelectTemplate: function(template) {
|
handleSelectTemplate: function(template) {
|
||||||
|
var body = template.body;
|
||||||
|
|
||||||
|
// Stringify to enable transmission of primitive non-string value types
|
||||||
|
if (!_.isUndefined(body)) {
|
||||||
|
body = JSON.stringify(body);
|
||||||
|
}
|
||||||
|
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'newsletters',
|
endpoint: 'newsletters',
|
||||||
action: 'save',
|
action: 'save',
|
||||||
data: {
|
data: {
|
||||||
id: this.props.params.id,
|
id: this.props.params.id,
|
||||||
body: template.body
|
body: body
|
||||||
}
|
}
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.result === true) {
|
if(response.result === true) {
|
||||||
|
@ -29,12 +29,14 @@ define(
|
|||||||
subject: 'Draft newsletter',
|
subject: 'Draft newsletter',
|
||||||
}
|
}
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
if(response.result && response.newsletter.id) {
|
||||||
this.history.pushState(null, `/template/${response.id}`);
|
this.history.pushState(null, `/template/${response.newsletter.id}`);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -138,12 +138,14 @@ define(
|
|||||||
options: this.state,
|
options: this.state,
|
||||||
},
|
},
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
if(response.result && response.newsletter.id) {
|
||||||
this.showTemplateSelection(response.id);
|
this.showTemplateSelection(response.newsletter.id);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -32,12 +32,15 @@ define(
|
|||||||
type: 'standard',
|
type: 'standard',
|
||||||
}
|
}
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
console.log(response);
|
||||||
this.showTemplateSelection(response.id);
|
if(response.result && response.newsletter.id) {
|
||||||
|
this.showTemplateSelection(response.newsletter.id);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -111,12 +111,14 @@ define(
|
|||||||
options: this.state,
|
options: this.state,
|
||||||
},
|
},
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
if(response.result && response.newsletter.id) {
|
||||||
this.showTemplateSelection(response.id);
|
this.showTemplateSelection(response.newsletter.id);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -192,21 +192,28 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
|||||||
error: function(message, options) {
|
error: function(message, options) {
|
||||||
this.show(jQuery.extend({}, {
|
this.show(jQuery.extend({}, {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: '<p>'+message+'</p>'
|
message: '<p>'+this.formatMessage(message)+'</p>'
|
||||||
}, options));
|
}, options));
|
||||||
},
|
},
|
||||||
success: function(message, options) {
|
success: function(message, options) {
|
||||||
this.show(jQuery.extend({}, {
|
this.show(jQuery.extend({}, {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: '<p>'+message+'</p>'
|
message: '<p>'+this.formatMessage(message)+'</p>'
|
||||||
}, options));
|
}, options));
|
||||||
},
|
},
|
||||||
system: function(message, options) {
|
system: function(message, options) {
|
||||||
this.show(jQuery.extend({}, {
|
this.show(jQuery.extend({}, {
|
||||||
type: 'system',
|
type: 'system',
|
||||||
static: true,
|
static: true,
|
||||||
message: message
|
message: '<p>'+this.formatMessage(message)+'</p>'
|
||||||
}, options));
|
}, options));
|
||||||
|
},
|
||||||
|
formatMessage: function(message) {
|
||||||
|
if(Array.isArray(message)) {
|
||||||
|
return message.join('<br />');
|
||||||
|
} else {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -20,10 +20,7 @@ function(
|
|||||||
$('form.mailpoet_form').each(function() {
|
$('form.mailpoet_form').each(function() {
|
||||||
var form = $(this);
|
var form = $(this);
|
||||||
|
|
||||||
form.parsley({
|
form.parsley().on('form:submit', function(parsley) {
|
||||||
errorsWrapper: '<p></p>',
|
|
||||||
errorTemplate: '<span></span>'
|
|
||||||
}).on('form:submit', function(parsley) {
|
|
||||||
|
|
||||||
var data = form.serializeObject() || {};
|
var data = form.serializeObject() || {};
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ define(
|
|||||||
Form
|
Form
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var fields = [
|
let fields = [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
@ -25,7 +25,7 @@ define(
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
var messages = {
|
const messages = {
|
||||||
onUpdate: function() {
|
onUpdate: function() {
|
||||||
MailPoet.Notice.success('Segment successfully updated!');
|
MailPoet.Notice.success('Segment successfully updated!');
|
||||||
},
|
},
|
||||||
@ -34,7 +34,7 @@ define(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var SegmentForm = React.createClass({
|
const SegmentForm = React.createClass({
|
||||||
mixins: [
|
mixins: [
|
||||||
Router.History
|
Router.History
|
||||||
],
|
],
|
||||||
|
@ -42,58 +42,49 @@ var columns = [
|
|||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
onTrash: function(response) {
|
onTrash: function(response) {
|
||||||
if(response) {
|
var count = ~~response;
|
||||||
let message = null;
|
var 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message !== null) {
|
if(count === 1) {
|
||||||
MailPoet.Notice.success(message);
|
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) {
|
onDelete: function(response) {
|
||||||
if(response) {
|
var count = ~~response;
|
||||||
let message = null;
|
var message = null;
|
||||||
if(~~response === 1) {
|
|
||||||
message = (
|
|
||||||
'1 segment was permanently deleted.'
|
|
||||||
);
|
|
||||||
} else if(~~response > 1) {
|
|
||||||
message = (
|
|
||||||
'%$1d segments were permanently deleted.'
|
|
||||||
).replace('%$1d', ~~response);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message !== null) {
|
if(count === 1) {
|
||||||
MailPoet.Notice.success(message);
|
message = (
|
||||||
}
|
'1 segment was permanently deleted.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
message = (
|
||||||
|
'%$1d segments were permanently deleted.'
|
||||||
|
).replace('%$1d', count);
|
||||||
}
|
}
|
||||||
|
MailPoet.Notice.success(message);
|
||||||
},
|
},
|
||||||
onRestore: function(response) {
|
onRestore: function(response) {
|
||||||
if(response) {
|
var count = ~~response;
|
||||||
let message = null;
|
var 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message !== null) {
|
if(count === 1) {
|
||||||
MailPoet.Notice.success(message);
|
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 (
|
return (
|
||||||
<Link to={ `/edit/${item.id}` }>Edit</Link>
|
<Link to={ `/edit/${item.id}` }>Edit</Link>
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
display: function(segment) {
|
||||||
|
return (segment.type !== 'wp_users');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -187,16 +181,16 @@ const SegmentList = React.createClass({
|
|||||||
<abbr>{ segment.description }</abbr>
|
<abbr>{ segment.description }</abbr>
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Subscribed">
|
<td className="column-date" data-colname="Subscribed">
|
||||||
<abbr>{ segment.subscribed || 0 }</abbr>
|
<abbr>{ segment.subscribers_count.subscribed || 0 }</abbr>
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Unconfirmed">
|
<td className="column-date" data-colname="Unconfirmed">
|
||||||
<abbr>{ segment.unconfirmed || 0 }</abbr>
|
<abbr>{ segment.subscribers_count.unconfirmed || 0 }</abbr>
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Unsubscribed">
|
<td className="column-date" data-colname="Unsubscribed">
|
||||||
<abbr>{ segment.unsubscribed || 0 }</abbr>
|
<abbr>{ segment.subscribers_count.unsubscribed || 0 }</abbr>
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Created on">
|
<td className="column-date" data-colname="Created on">
|
||||||
<abbr>{ segment.created_at }</abbr>
|
<abbr>{ MailPoet.Date.full(segment.created_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -11,7 +11,6 @@ define(
|
|||||||
MailPoet,
|
MailPoet,
|
||||||
Form
|
Form
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var fields = [
|
var fields = [
|
||||||
{
|
{
|
||||||
name: 'email',
|
name: 'email',
|
||||||
@ -45,12 +44,59 @@ define(
|
|||||||
placeholder: "Select a list",
|
placeholder: "Select a list",
|
||||||
endpoint: "segments",
|
endpoint: "segments",
|
||||||
multiple: true,
|
multiple: true,
|
||||||
|
selected: function(subscriber) {
|
||||||
|
if (Array.isArray(subscriber.subscriptions) === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return subscriber.subscriptions.map(function(subscription) {
|
||||||
|
if (subscription.status === 'subscribed') {
|
||||||
|
return subscription.segment_id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
filter: function(segment) {
|
filter: function(segment) {
|
||||||
return !!(!segment.deleted_at);
|
return !!(!segment.deleted_at);
|
||||||
|
},
|
||||||
|
getSearchLabel: function(segment, subscriber) {
|
||||||
|
let label = '';
|
||||||
|
|
||||||
|
if (subscriber.subscriptions !== undefined) {
|
||||||
|
subscriber.subscriptions.map(function(subscription) {
|
||||||
|
if (segment.id === subscription.segment_id) {
|
||||||
|
label = segment.name;
|
||||||
|
|
||||||
|
if (subscription.status === 'unsubscribed') {
|
||||||
|
const unsubscribed_at = MailPoet.Date
|
||||||
|
.format(subscription.updated_at);
|
||||||
|
label += ' (Unsubscribed on '+unsubscribed_at+')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var custom_fields = window.mailpoet_custom_fields || [];
|
||||||
|
custom_fields.map(custom_field => {
|
||||||
|
let field = {
|
||||||
|
name: 'cf_' + custom_field.id,
|
||||||
|
label: custom_field.name,
|
||||||
|
type: custom_field.type
|
||||||
|
};
|
||||||
|
if (custom_field.params) {
|
||||||
|
field.params = custom_field.params;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (custom_field.params.values) {
|
||||||
|
field.values = custom_field.params.values;
|
||||||
|
}
|
||||||
|
|
||||||
|
fields.push(field);
|
||||||
|
});
|
||||||
|
|
||||||
var messages = {
|
var messages = {
|
||||||
onUpdate: function() {
|
onUpdate: function() {
|
||||||
MailPoet.Notice.success('Subscriber successfully updated!');
|
MailPoet.Notice.success('Subscriber successfully updated!');
|
||||||
|
@ -115,7 +115,7 @@ define(
|
|||||||
exportData.exportConfirmedOption = false;
|
exportData.exportConfirmedOption = false;
|
||||||
renderSegmentsAndFields(segmentsContainerElement, segments);
|
renderSegmentsAndFields(segmentsContainerElement, segments);
|
||||||
}
|
}
|
||||||
segmentsContainerElement.select2('val', selectedSegments);
|
segmentsContainerElement.val(selectedSegments).trigger('change');
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggleNextStepButton(condition) {
|
function toggleNextStepButton(condition) {
|
||||||
@ -148,7 +148,7 @@ define(
|
|||||||
.done(function (response) {
|
.done(function (response) {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
if (response.result === false) {
|
if (response.result === false) {
|
||||||
MailPoet.Notice.error(response.error);
|
MailPoet.Notice.error(response.errors);
|
||||||
} else {
|
} else {
|
||||||
resultMessage = MailPoetI18n.exportMessage
|
resultMessage = MailPoetI18n.exportMessage
|
||||||
.replace('%1$s', '<strong>' + response.data.totalExported + '</strong>')
|
.replace('%1$s', '<strong>' + response.data.totalExported + '</strong>')
|
||||||
@ -167,4 +167,4 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,18 +6,23 @@ define(
|
|||||||
'mailpoet',
|
'mailpoet',
|
||||||
'handlebars',
|
'handlebars',
|
||||||
'papaparse',
|
'papaparse',
|
||||||
'select2'
|
'select2',
|
||||||
|
'asyncqueue'
|
||||||
],
|
],
|
||||||
function (Backbone,
|
function (
|
||||||
_,
|
Backbone,
|
||||||
jQuery,
|
_,
|
||||||
MailPoet,
|
jQuery,
|
||||||
Handlebars,
|
MailPoet,
|
||||||
Papa) {
|
Handlebars,
|
||||||
|
Papa,
|
||||||
|
AsyncQueue
|
||||||
|
) {
|
||||||
if (!jQuery('#mailpoet_subscribers_import').length) {
|
if (!jQuery('#mailpoet_subscribers_import').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jQuery(document).ready(function () {
|
jQuery(document).ready(function () {
|
||||||
|
var noticeTimeout = 3000;
|
||||||
jQuery('input[name="select_method"]').attr('checked', false);
|
jQuery('input[name="select_method"]').attr('checked', false);
|
||||||
// configure router
|
// configure router
|
||||||
router = new (Backbone.Router.extend({
|
router = new (Backbone.Router.extend({
|
||||||
@ -122,7 +127,7 @@ define(
|
|||||||
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
|
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
|
||||||
if (pasteSize > maxPostSizeBytes) {
|
if (pasteSize > maxPostSizeBytes) {
|
||||||
MailPoet.Notice.error(MailPoetI18n.maxPostSizeNotice, {
|
MailPoet.Notice.error(MailPoetI18n.maxPostSizeNotice, {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -138,6 +143,14 @@ define(
|
|||||||
*/
|
*/
|
||||||
uploadElement.change(function () {
|
uploadElement.change(function () {
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.hide();
|
||||||
|
var ext = this.value.match(/\.(.+)$/);
|
||||||
|
if (ext === null || ext[1].toLowerCase() !== 'csv') {
|
||||||
|
this.value = '';
|
||||||
|
MailPoet.Notice.error(MailPoetI18n.wrongFileFormat, {
|
||||||
|
timeout: noticeTimeout,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
toggleNextStepButton(
|
toggleNextStepButton(
|
||||||
uploadProcessButtonElement,
|
uploadProcessButtonElement,
|
||||||
(this.value.trim() !== '') ? 'on' : 'off'
|
(this.value.trim() !== '') ? 'on' : 'off'
|
||||||
@ -183,8 +196,8 @@ define(
|
|||||||
}).done(function (response) {
|
}).done(function (response) {
|
||||||
if (response.result === false) {
|
if (response.result === false) {
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.hide();
|
||||||
MailPoet.Notice.error(response.error, {
|
MailPoet.Notice.error(response.errors, {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
});
|
});
|
||||||
jQuery('.mailpoet_mailchimp-key-status')
|
jQuery('.mailpoet_mailchimp-key-status')
|
||||||
.removeClass()
|
.removeClass()
|
||||||
@ -209,7 +222,7 @@ define(
|
|||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(
|
||||||
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -235,8 +248,8 @@ define(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.hide();
|
||||||
MailPoet.Notice(response.message, {
|
MailPoet.Notice.error(response.errors, {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
@ -244,7 +257,7 @@ define(
|
|||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(
|
||||||
MailPoetI18n.serverError + result.statusText.toLowerCase() + '.', {
|
MailPoetI18n.serverError + result.statusText.toLowerCase() + '.', {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -336,7 +349,7 @@ define(
|
|||||||
error: function () {
|
error: function () {
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.hide();
|
||||||
MailPoet.Notice.error(MailPoetI18n.dataProcessingError, {
|
MailPoet.Notice.error(MailPoetI18n.dataProcessingError, {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
complete: function (CSV) {
|
complete: function (CSV) {
|
||||||
@ -416,8 +429,11 @@ define(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
MailPoet.Notice.error(MailPoetI18n.noValidRecords, {
|
var errorNotice = MailPoetI18n.noValidRecords;
|
||||||
timeout: 3000,
|
errorNotice = errorNotice.replace('[link]', MailPoetI18n.csvKBLink);
|
||||||
|
errorNotice = errorNotice.replace('[/link]', '</a>');
|
||||||
|
MailPoet.Notice.error(errorNotice, {
|
||||||
|
timeout: noticeTimeout,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,7 +564,7 @@ define(
|
|||||||
if (!segmentSelectionNotice.length) {
|
if (!segmentSelectionNotice.length) {
|
||||||
MailPoet.Notice.error(MailPoetI18n.segmentSelectionRequired, {
|
MailPoet.Notice.error(MailPoetI18n.segmentSelectionRequired, {
|
||||||
static: true,
|
static: true,
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
scroll: true,
|
scroll: true,
|
||||||
id: 'segmentSelection',
|
id: 'segmentSelection',
|
||||||
hideClose: true
|
hideClose: true
|
||||||
@ -627,7 +643,7 @@ define(
|
|||||||
MailPoet.Modal.close();
|
MailPoet.Modal.close();
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(
|
||||||
MailPoetI18n.segmentCreateError + response.message + '.', {
|
MailPoetI18n.segmentCreateError + response.message + '.', {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -636,7 +652,7 @@ define(
|
|||||||
MailPoet.Modal.close();
|
MailPoet.Modal.close();
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(
|
||||||
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
||||||
timeout: 3000
|
timeout: noticeTimeout
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -721,7 +737,7 @@ define(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// reduce subscribers object if the total length is geater than the
|
// reduce subscribers object if the total length is greater than the
|
||||||
// maximum number of defined rows
|
// maximum number of defined rows
|
||||||
if (subscribers.subscribersCount > (maxRowsToShow + 1)) {
|
if (subscribers.subscribersCount > (maxRowsToShow + 1)) {
|
||||||
subscribers.subscribers.splice(
|
subscribers.subscribers.splice(
|
||||||
@ -843,7 +859,7 @@ define(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MailPoet.Notice.error(MailPoetI18n.customFieldCreateError, {
|
MailPoet.Notice.error(MailPoetI18n.customFieldCreateError, {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
@ -852,7 +868,7 @@ define(
|
|||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
MailPoet.Notice.error(
|
MailPoet.Notice.error(
|
||||||
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -917,7 +933,7 @@ define(
|
|||||||
if (!jQuery('[data-id="notice_invalidEmail"]').length) {
|
if (!jQuery('[data-id="notice_invalidEmail"]').length) {
|
||||||
MailPoet.Notice.error(MailPoetI18n.columnContainsInvalidElement, {
|
MailPoet.Notice.error(MailPoetI18n.columnContainsInvalidElement, {
|
||||||
static: true,
|
static: true,
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
scroll: true,
|
scroll: true,
|
||||||
hideClose: true,
|
hideClose: true,
|
||||||
id: 'invalidEmail'
|
id: 'invalidEmail'
|
||||||
@ -997,7 +1013,7 @@ define(
|
|||||||
if (preventNextStep && !jQuery('.mailpoet_invalidDate').length) {
|
if (preventNextStep && !jQuery('.mailpoet_invalidDate').length) {
|
||||||
MailPoet.Notice.error(MailPoetI18n.columnContainsInvalidDate, {
|
MailPoet.Notice.error(MailPoetI18n.columnContainsInvalidDate, {
|
||||||
static: true,
|
static: true,
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
scroll: true,
|
scroll: true,
|
||||||
hideClose: true,
|
hideClose: true,
|
||||||
id: 'invalidDate'
|
id: 'invalidDate'
|
||||||
@ -1037,64 +1053,98 @@ define(
|
|||||||
}
|
}
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
|
|
||||||
var subscribers = {};
|
var columns = {},
|
||||||
|
queue = new jQuery.AsyncQueue(),
|
||||||
|
batchNumber = 0,
|
||||||
|
batchSize = 2000,
|
||||||
|
timestamp = Date.now() / 1000,
|
||||||
|
subscribers = [],
|
||||||
|
importResults = {
|
||||||
|
'created': 0,
|
||||||
|
'updated': 0,
|
||||||
|
'errors': [],
|
||||||
|
'segments': []
|
||||||
|
},
|
||||||
|
splitSubscribers = function (subscribers, size) {
|
||||||
|
return subscribers.reduce(function (res, item, index) {
|
||||||
|
if (index % size === 0) {
|
||||||
|
res.push([]);
|
||||||
|
}
|
||||||
|
res[res.length - 1].push(item);
|
||||||
|
return res;
|
||||||
|
}, []);
|
||||||
|
},
|
||||||
|
subscribers = splitSubscribers(importData.step1.subscribers, batchSize);
|
||||||
|
|
||||||
_.each(jQuery('select.mailpoet_subscribers_column_data_match'),
|
_.each(jQuery('select.mailpoet_subscribers_column_data_match'),
|
||||||
function (column, index) {
|
function (column, columnIndex) {
|
||||||
var columnId = jQuery(column).data('column-id');
|
var columnId = jQuery(column).data('column-id');
|
||||||
if (columnId === 'ignore') {
|
if (columnId === 'ignore') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
subscribers[columnId] = [];
|
columns[columnId] = columnIndex;
|
||||||
_.each(importData.step1.subscribers, function (subsciber) {
|
});
|
||||||
subscribers[columnId].push(
|
|
||||||
_.chain(subsciber)
|
|
||||||
.pick(index)
|
|
||||||
.toArray()
|
|
||||||
.flatten()
|
|
||||||
.value()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
subscribers[columnId] = _.flatten(subscribers[columnId]);
|
|
||||||
});
|
|
||||||
|
|
||||||
MailPoet.Ajax.post({
|
_.each(subscribers, function () {
|
||||||
endpoint: 'ImportExport',
|
queue.add(function (queue) {
|
||||||
action: 'processImport',
|
queue.pause();
|
||||||
data: JSON.stringify({
|
MailPoet.Ajax
|
||||||
subscribers: subscribers,
|
.post({
|
||||||
segments: segmentSelectElement.val(),
|
endpoint: 'ImportExport',
|
||||||
updateSubscribers: (jQuery(':radio[name="subscriber_update_option"]:checked').val() === 'yes') ? true : false
|
action: 'processImport',
|
||||||
|
data: JSON.stringify({
|
||||||
|
columns: columns,
|
||||||
|
subscribers: subscribers[batchNumber],
|
||||||
|
timestamp: timestamp,
|
||||||
|
segments: segmentSelectElement.val(),
|
||||||
|
updateSubscribers: (jQuery(':radio[name="subscriber_update_option"]:checked').val() === 'yes') ? true : false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
if (response.result === false) {
|
||||||
|
importResults.errors.push(response.errors);
|
||||||
|
} else {
|
||||||
|
importResults.created = response.data.created;
|
||||||
|
importResults.updated = response.data.updated;
|
||||||
|
importResults.segments = response.data.segments;
|
||||||
|
}
|
||||||
|
queue.run();
|
||||||
|
})
|
||||||
|
.error(function (error) {
|
||||||
|
importResults.errors.push(
|
||||||
|
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.'
|
||||||
|
);
|
||||||
|
queue.run();
|
||||||
|
});
|
||||||
|
batchNumber++;
|
||||||
})
|
})
|
||||||
}).done(function (response) {
|
});
|
||||||
|
|
||||||
|
queue.run();
|
||||||
|
|
||||||
|
queue.onComplete(function () {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
if (response.result === false) {
|
if (importResults.errors.length > 0 && !importResults.updated && !importResults.created) {
|
||||||
MailPoet.Notice.error(response.error, {
|
MailPoet.Notice.error(_.flatten(importResults.errors), {
|
||||||
timeout: 3000,
|
timeout: noticeTimeout,
|
||||||
});
|
}
|
||||||
} else {
|
);
|
||||||
mailpoetSegments = response.data.segments;
|
}
|
||||||
response.data.segments = _.map(segmentSelectElement.select2('data'),
|
else {
|
||||||
function (data) {
|
mailpoetSegments = importResults.segments;
|
||||||
return data.name;
|
importResults.segments = _.map(segmentSelectElement.select2('data'),
|
||||||
});
|
function (data) {
|
||||||
importData.step2 = response.data;
|
return data.name;
|
||||||
|
});
|
||||||
|
importData.step2 = importResults;
|
||||||
enableSegmentSelection(mailpoetSegments);
|
enableSegmentSelection(mailpoetSegments);
|
||||||
router.navigate('step3', {trigger: true});
|
router.navigate('step3', {trigger: true});
|
||||||
}
|
}
|
||||||
}).error(function (error) {
|
|
||||||
MailPoet.Modal.loading(false);
|
|
||||||
MailPoet.Notice.error(
|
|
||||||
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.', {
|
|
||||||
timeout: 3000,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
filterSubscribers();
|
filterSubscribers();
|
||||||
enableSegmentSelection(mailpoetSegments);
|
enableSegmentSelection(mailpoetSegments);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.on('route:step3', function () {
|
router.on('route:step3', function () {
|
||||||
@ -1105,6 +1155,12 @@ define(
|
|||||||
|
|
||||||
showCurrentStep();
|
showCurrentStep();
|
||||||
|
|
||||||
|
if (importData.step2.errors.length > 0) {
|
||||||
|
MailPoet.Notice.error(_.flatten(importData.step2.errors), {
|
||||||
|
timeout: noticeTimeout,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// display statistics
|
// display statistics
|
||||||
var subscribersDataImportResultsTemplate =
|
var subscribersDataImportResultsTemplate =
|
||||||
Handlebars
|
Handlebars
|
||||||
|
@ -208,6 +208,16 @@ const bulk_actions = [
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'sendConfirmationEmail',
|
||||||
|
label: 'Resend confirmation email',
|
||||||
|
onSuccess: function(response) {
|
||||||
|
MailPoet.Notice.success(
|
||||||
|
'%$1d confirmation emails have been sent.'
|
||||||
|
.replace('%$1d', ~~response)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'trash',
|
name: 'trash',
|
||||||
label: 'Trash',
|
label: 'Trash',
|
||||||
@ -231,6 +241,15 @@ const item_actions = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const SubscriberList = React.createClass({
|
const SubscriberList = React.createClass({
|
||||||
|
getSegmentFromId: function(segment_id) {
|
||||||
|
let result = false;
|
||||||
|
mailpoet_segments.map(function(segment) {
|
||||||
|
if (segment.id === segment_id) {
|
||||||
|
result = segment;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
renderItem: function(subscriber, actions) {
|
renderItem: function(subscriber, actions) {
|
||||||
let row_classes = classNames(
|
let row_classes = classNames(
|
||||||
'manage-column',
|
'manage-column',
|
||||||
@ -255,11 +274,41 @@ const SubscriberList = React.createClass({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let segments = mailpoet_segments.filter(function(segment) {
|
let segments = false;
|
||||||
return (jQuery.inArray(segment.id, subscriber.segments) !== -1);
|
|
||||||
}).map(function(segment) {
|
if (subscriber.subscriptions.length > 0) {
|
||||||
return segment.name;
|
let subscribed_segments = [];
|
||||||
}).join(', ');
|
let unsubscribed_segments = [];
|
||||||
|
|
||||||
|
subscriber.subscriptions.map((subscription) => {
|
||||||
|
const segment = this.getSegmentFromId(subscription.segment_id);
|
||||||
|
if(segment === false) return;
|
||||||
|
if (subscription.status === 'subscribed') {
|
||||||
|
subscribed_segments.push(segment.name);
|
||||||
|
} else if (subscription.status === 'unsubscribed') {
|
||||||
|
unsubscribed_segments.push(segment.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
segments = (
|
||||||
|
<span>
|
||||||
|
<span className="mailpoet_segments_subscribed">
|
||||||
|
{ subscribed_segments.join(', ') }
|
||||||
|
{
|
||||||
|
(
|
||||||
|
subscribed_segments.length > 0
|
||||||
|
&& unsubscribed_segments.length > 0
|
||||||
|
) ? ' / ' : ''
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className="mailpoet_segments_unsubscribed"
|
||||||
|
title="Lists to which the subscriber was subscribed."
|
||||||
|
>
|
||||||
|
{ unsubscribed_segments.join(', ') }
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let avatar = false;
|
let avatar = false;
|
||||||
if(subscriber.avatar_url) {
|
if(subscriber.avatar_url) {
|
||||||
@ -292,10 +341,10 @@ const SubscriberList = React.createClass({
|
|||||||
{ segments }
|
{ segments }
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Subscribed on">
|
<td className="column-date" data-colname="Subscribed on">
|
||||||
<abbr>{ subscriber.created_at }</abbr>
|
<abbr>{ MailPoet.Date.full(subscriber.created_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
<td className="column-date" data-colname="Last modified on">
|
<td className="column-date" data-colname="Last modified on">
|
||||||
<abbr>{ subscriber.updated_at }</abbr>
|
<abbr>{ MailPoet.Date.full(subscriber.updated_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -313,6 +362,7 @@ const SubscriberList = React.createClass({
|
|||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<Listing
|
<Listing
|
||||||
|
limit={ mailpoet_listing_per_page }
|
||||||
location={ this.props.location }
|
location={ this.props.location }
|
||||||
params={ this.props.params }
|
params={ this.props.params }
|
||||||
endpoint="subscribers"
|
endpoint="subscribers"
|
||||||
|
79
assets/js/src/vendor/jquery.asyncqueue.js
vendored
Normal file
79
assets/js/src/vendor/jquery.asyncqueue.js
vendored
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the jquery plugin "asyncQueue".
|
||||||
|
*
|
||||||
|
* (c) Sebastien Roch <roch.sebastien@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
(function($){
|
||||||
|
$.AsyncQueue = function() {
|
||||||
|
var that = this,
|
||||||
|
queue = [],
|
||||||
|
failureFunc,
|
||||||
|
completeFunc,
|
||||||
|
paused = false,
|
||||||
|
lastCallbackData,
|
||||||
|
_run;
|
||||||
|
|
||||||
|
_run = function() {
|
||||||
|
var f = queue.shift();
|
||||||
|
|
||||||
|
if (f) {
|
||||||
|
f.apply(that, [that]);
|
||||||
|
if (paused === false) {
|
||||||
|
_run();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(completeFunc){
|
||||||
|
completeFunc.apply(that);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onFailure = function(func) {
|
||||||
|
failureFunc = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onComplete = function(func) {
|
||||||
|
completeFunc = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.add = function(func) {
|
||||||
|
queue.push(func);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.storeData = function(dataObject) {
|
||||||
|
lastCallbackData = dataObject;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastCallbackData = function () {
|
||||||
|
return lastCallbackData;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.run = function() {
|
||||||
|
paused = false;
|
||||||
|
_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pause = function () {
|
||||||
|
paused = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.failure = function() {
|
||||||
|
paused = true;
|
||||||
|
if (failureFunc) {
|
||||||
|
var args = [that];
|
||||||
|
for(i = 0; i < arguments.length; i++) {
|
||||||
|
args.push(arguments[i]);
|
||||||
|
}
|
||||||
|
failureFunc.apply(that, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
})(jQuery);
|
@ -19,3 +19,12 @@ modules:
|
|||||||
user: ''
|
user: ''
|
||||||
password: ''
|
password: ''
|
||||||
dump: tests/_data/dump.sql
|
dump: tests/_data/dump.sql
|
||||||
|
coverage:
|
||||||
|
enabled: true
|
||||||
|
whitelist:
|
||||||
|
include:
|
||||||
|
- lib/*
|
||||||
|
exclude:
|
||||||
|
blacklist:
|
||||||
|
include:
|
||||||
|
exclude:
|
@ -10,7 +10,8 @@
|
|||||||
"swiftmailer/swiftmailer": "^5.4",
|
"swiftmailer/swiftmailer": "^5.4",
|
||||||
"phpseclib/phpseclib": "*",
|
"phpseclib/phpseclib": "*",
|
||||||
"mtdowling/cron-expression": "^1.0",
|
"mtdowling/cron-expression": "^1.0",
|
||||||
"nesbot/carbon": "^1.21"
|
"nesbot/carbon": "^1.21",
|
||||||
|
"soundasleep/html2text": "^0.3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"codeception/codeception": "*",
|
"codeception/codeception": "*",
|
||||||
|
702
composer.lock
generated
702
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -9,13 +9,6 @@ class Activator {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
|
||||||
register_activation_hook(
|
|
||||||
Env::$file,
|
|
||||||
array($this, 'activate')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function activate() {
|
function activate() {
|
||||||
$migrator = new Migrator();
|
$migrator = new Migrator();
|
||||||
$migrator->up();
|
$migrator->up();
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
use \MailPoet\Models\Setting;
|
use \MailPoet\Models\Setting;
|
||||||
|
use \MailPoet\Util\Url;
|
||||||
|
|
||||||
class Changelog {
|
class Changelog {
|
||||||
|
function __construct() {
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
$doing_ajax = (bool)(defined('DOING_AJAX') && DOING_AJAX);
|
$doing_ajax = (bool)(defined('DOING_AJAX') && DOING_AJAX);
|
||||||
|
|
||||||
@ -42,20 +46,7 @@ class Changelog {
|
|||||||
// save version number
|
// save version number
|
||||||
Setting::setValue('version', Env::$version);
|
Setting::setValue('version', Env::$version);
|
||||||
|
|
||||||
global $wp;
|
Url::redirectWithReferer($redirect_url);
|
||||||
$current_url = home_url(add_query_arg($wp->query_string, $wp->request));
|
|
||||||
|
|
||||||
if($redirect_url !== $current_url) {
|
|
||||||
wp_safe_redirect(
|
|
||||||
add_query_arg(
|
|
||||||
array(
|
|
||||||
'mailpoet_redirect' => urlencode($current_url)
|
|
||||||
),
|
|
||||||
$redirect_url
|
|
||||||
)
|
|
||||||
);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,9 @@ class Env {
|
|||||||
self::$views_path = self::$path . '/views';
|
self::$views_path = self::$path . '/views';
|
||||||
self::$assets_path = self::$path . '/assets';
|
self::$assets_path = self::$path . '/assets';
|
||||||
self::$assets_url = plugins_url('/assets', $file);
|
self::$assets_url = plugins_url('/assets', $file);
|
||||||
self::$temp_path = wp_upload_dir()['path'];
|
$wp_upload_dir = wp_upload_dir();
|
||||||
self::$temp_URL = wp_upload_dir()['url'];
|
self::$temp_path = $wp_upload_dir['path'];
|
||||||
|
self::$temp_URL = $wp_upload_dir['url'];
|
||||||
self::$languages_path = self::$path . '/lang';
|
self::$languages_path = self::$path . '/lang';
|
||||||
self::$lib_path = self::$path . '/lib';
|
self::$lib_path = self::$path . '/lib';
|
||||||
self::$plugin_prefix = 'mailpoet_';
|
self::$plugin_prefix = 'mailpoet_';
|
||||||
@ -72,19 +73,4 @@ class Env {
|
|||||||
);
|
);
|
||||||
return implode('', $source_name);
|
return implode('', $source_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function isPluginActivated() {
|
|
||||||
$activatesPlugins = get_option('active_plugins');
|
|
||||||
$isActivated = (
|
|
||||||
in_array(
|
|
||||||
sprintf('%s/%s.php', basename(self::$path), self::$plugin_name),
|
|
||||||
$activatesPlugins
|
|
||||||
) ||
|
|
||||||
in_array(
|
|
||||||
sprintf('%s/%s.php', explode('/', plugin_basename(__FILE__))[0], self::$plugin_name),
|
|
||||||
$activatesPlugins
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return ($isActivated) ? true : false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,11 +1,89 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
use MailPoet\Cron\Workers\Scheduler;
|
||||||
|
use MailPoet\Cron\Workers\SendingQueue;
|
||||||
|
use \MailPoet\Models\Setting;
|
||||||
|
|
||||||
class Hooks {
|
class Hooks {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
$this->setupSubscribe();
|
||||||
|
$this->setupWPUsers();
|
||||||
|
$this->setupImageSize();
|
||||||
|
$this->setupListing();
|
||||||
|
$this->setupCronWorkers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupSubscribe() {
|
||||||
|
$subscribe = Setting::getValue('subscribe', array());
|
||||||
|
// Subscribe in comments
|
||||||
|
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',
|
||||||
|
'\MailPoet\Subscription\Comment::onSubmit',
|
||||||
|
60,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'wp_set_comment_status',
|
||||||
|
'\MailPoet\Subscription\Comment::onStatusUpdate',
|
||||||
|
60,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe in registration form
|
||||||
|
if(
|
||||||
|
isset($subscribe['on_register']['enabled'])
|
||||||
|
&&
|
||||||
|
(bool)$subscribe['on_register']['enabled']
|
||||||
|
) {
|
||||||
|
if(is_multisite()) {
|
||||||
|
add_action(
|
||||||
|
'signup_extra_fields',
|
||||||
|
'\MailPoet\Subscription\Registration::extendForm'
|
||||||
|
);
|
||||||
|
add_action(
|
||||||
|
'wpmu_validate_user_signup',
|
||||||
|
'\MailPoet\Subscription\Registration::onMultiSiteRegister',
|
||||||
|
60,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
add_action(
|
||||||
|
'register_form',
|
||||||
|
'\MailPoet\Subscription\Registration::extendForm'
|
||||||
|
);
|
||||||
|
add_action(
|
||||||
|
'register_post',
|
||||||
|
'\MailPoet\Subscription\Registration::onRegister',
|
||||||
|
60,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupWPUsers() {
|
||||||
// WP Users synchronization
|
// WP Users synchronization
|
||||||
add_action(
|
add_action(
|
||||||
'user_register',
|
'user_register',
|
||||||
@ -38,19 +116,50 @@ class Hooks {
|
|||||||
'\MailPoet\Segments\WP::synchronizeUser',
|
'\MailPoet\Segments\WP::synchronizeUser',
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupImageSize() {
|
||||||
add_filter(
|
add_filter(
|
||||||
'image_size_names_choose',
|
'image_size_names_choose',
|
||||||
array(
|
array($this, 'appendImageSize'),
|
||||||
$this,
|
10, 1
|
||||||
'appendImageSizes'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendImageSizes($sizes) {
|
function appendImageSize($sizes) {
|
||||||
return array_merge($sizes, array(
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupCronWorkers() {
|
||||||
|
add_action('mailpoet_cron_worker', array($this, 'runSchedulerWorker'), 10, 1);
|
||||||
|
add_action('mailpoet_cron_worker', array($this, 'runSendingQueueWorker'), 10, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function runSchedulerWorker($timer) {
|
||||||
|
$scheduler = new Scheduler($timer);
|
||||||
|
$scheduler->process();
|
||||||
|
|
||||||
|
}
|
||||||
|
function runSendingQueueWorker($timer) {
|
||||||
|
$sending_queue = new SendingQueue($timer);
|
||||||
|
$sending_queue->process();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,11 @@ namespace MailPoet\Config;
|
|||||||
use MailPoet\Models;
|
use MailPoet\Models;
|
||||||
use MailPoet\Cron\Supervisor;
|
use MailPoet\Cron\Supervisor;
|
||||||
use MailPoet\Router;
|
use MailPoet\Router;
|
||||||
use MailPoet\Models\Setting;
|
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||||
|
|
||||||
class Initializer {
|
class Initializer {
|
||||||
function __construct($params = array(
|
function __construct($params = array(
|
||||||
'file' => '',
|
'file' => '',
|
||||||
@ -18,20 +19,39 @@ class Initializer {
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
$this->setupDB();
|
$this->setupDB();
|
||||||
$this->setupActivator();
|
|
||||||
$this->setupRenderer();
|
register_activation_hook(Env::$file, array($this, 'runMigrator'));
|
||||||
$this->setupLocalizer();
|
register_activation_hook(Env::$file, array($this, 'runPopulator'));
|
||||||
$this->setupMenu();
|
|
||||||
|
add_action('plugins_loaded', array($this, 'setup'));
|
||||||
|
add_action('init', array($this, 'onInit'));
|
||||||
|
add_action('widgets_init', array($this, 'setupWidget'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
try {
|
||||||
|
$this->setupRenderer();
|
||||||
|
$this->setupLocalizer();
|
||||||
|
$this->setupMenu();
|
||||||
|
$this->setupPermissions();
|
||||||
|
$this->setupAnalytics();
|
||||||
|
$this->setupChangelog();
|
||||||
|
$this->setupShortcodes();
|
||||||
|
$this->setupHooks();
|
||||||
|
$this->setupImages();
|
||||||
|
$this->setupPublicAPI();
|
||||||
|
$this->runQueueSupervisor();
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
// if anything goes wrong during init
|
||||||
|
// automatically deactivate the plugin
|
||||||
|
deactivate_plugins(Env::$file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInit() {
|
||||||
$this->setupRouter();
|
$this->setupRouter();
|
||||||
$this->setupWidget();
|
$this->setupPages();
|
||||||
$this->setupAnalytics();
|
|
||||||
$this->setupPermissions();
|
|
||||||
$this->setupChangelog();
|
|
||||||
$this->setupPublicAPI();
|
|
||||||
$this->runQueueSupervisor();
|
$this->runQueueSupervisor();
|
||||||
$this->setupShortcodes();
|
|
||||||
$this->setupHooks();
|
|
||||||
$this->setupImages();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupDB() {
|
function setupDB() {
|
||||||
@ -39,6 +59,10 @@ class Initializer {
|
|||||||
\ORM::configure('username', Env::$db_username);
|
\ORM::configure('username', Env::$db_username);
|
||||||
\ORM::configure('password', Env::$db_password);
|
\ORM::configure('password', Env::$db_password);
|
||||||
\ORM::configure('logging', WP_DEBUG);
|
\ORM::configure('logging', WP_DEBUG);
|
||||||
|
\ORM::configure('logger', function($query, $time) {
|
||||||
|
// error_log("\n".$query."\n");
|
||||||
|
});
|
||||||
|
|
||||||
\ORM::configure('driver_options', array(
|
\ORM::configure('driver_options', array(
|
||||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
||||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET TIME_ZONE = "+00:00"'
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET TIME_ZONE = "+00:00"'
|
||||||
@ -49,8 +73,6 @@ class Initializer {
|
|||||||
$newsletters = Env::$db_prefix . 'newsletters';
|
$newsletters = Env::$db_prefix . 'newsletters';
|
||||||
$newsletter_templates = Env::$db_prefix . 'newsletter_templates';
|
$newsletter_templates = Env::$db_prefix . 'newsletter_templates';
|
||||||
$segments = Env::$db_prefix . 'segments';
|
$segments = Env::$db_prefix . 'segments';
|
||||||
$filters = Env::$db_prefix . 'filters';
|
|
||||||
$segment_filter = Env::$db_prefix . 'segment_filter';
|
|
||||||
$forms = Env::$db_prefix . 'forms';
|
$forms = Env::$db_prefix . 'forms';
|
||||||
$subscriber_segment = Env::$db_prefix . 'subscriber_segment';
|
$subscriber_segment = Env::$db_prefix . 'subscriber_segment';
|
||||||
$newsletter_segment = Env::$db_prefix . 'newsletter_segment';
|
$newsletter_segment = Env::$db_prefix . 'newsletter_segment';
|
||||||
@ -65,8 +87,6 @@ class Initializer {
|
|||||||
define('MP_SETTINGS_TABLE', $settings);
|
define('MP_SETTINGS_TABLE', $settings);
|
||||||
define('MP_NEWSLETTERS_TABLE', $newsletters);
|
define('MP_NEWSLETTERS_TABLE', $newsletters);
|
||||||
define('MP_SEGMENTS_TABLE', $segments);
|
define('MP_SEGMENTS_TABLE', $segments);
|
||||||
define('MP_FILTERS_TABLE', $filters);
|
|
||||||
define('MP_SEGMENT_FILTER_TABLE', $segment_filter);
|
|
||||||
define('MP_FORMS_TABLE', $forms);
|
define('MP_FORMS_TABLE', $forms);
|
||||||
define('MP_SUBSCRIBER_SEGMENT_TABLE', $subscriber_segment);
|
define('MP_SUBSCRIBER_SEGMENT_TABLE', $subscriber_segment);
|
||||||
define('MP_NEWSLETTER_TEMPLATES_TABLE', $newsletter_templates);
|
define('MP_NEWSLETTER_TEMPLATES_TABLE', $newsletter_templates);
|
||||||
@ -79,9 +99,14 @@ class Initializer {
|
|||||||
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupActivator() {
|
function runMigrator() {
|
||||||
$activator = new Activator();
|
$migrator = new Migrator();
|
||||||
$activator->init();
|
$migrator->up();
|
||||||
|
}
|
||||||
|
|
||||||
|
function runPopulator() {
|
||||||
|
$populator = new Populator();
|
||||||
|
$populator->up();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupRenderer() {
|
function setupRenderer() {
|
||||||
@ -95,10 +120,7 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupMenu() {
|
function setupMenu() {
|
||||||
$menu = new Menu(
|
$menu = new Menu($this->renderer, Env::$assets_url);
|
||||||
$this->renderer,
|
|
||||||
Env::$assets_url
|
|
||||||
);
|
|
||||||
$menu->init();
|
$menu->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +149,19 @@ class Initializer {
|
|||||||
$changelog->init();
|
$changelog->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupPages() {
|
||||||
|
$pages = new \MailPoet\Settings\Pages();
|
||||||
|
$pages->init();
|
||||||
|
|
||||||
|
$subscription_pages = new \MailPoet\Subscription\Pages();
|
||||||
|
$subscription_pages->init();
|
||||||
|
}
|
||||||
|
|
||||||
function setupShortcodes() {
|
function setupShortcodes() {
|
||||||
$shortcodes = new Shortcodes();
|
$shortcodes = new Shortcodes();
|
||||||
$shortcodes->init();
|
$shortcodes->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupHooks() {
|
function setupHooks() {
|
||||||
$hooks = new Hooks();
|
$hooks = new Hooks();
|
||||||
$hooks->init();
|
$hooks->init();
|
||||||
@ -146,7 +177,7 @@ class Initializer {
|
|||||||
try {
|
try {
|
||||||
$supervisor = new Supervisor();
|
$supervisor = new Supervisor();
|
||||||
$supervisor->checkDaemon();
|
$supervisor->checkDaemon();
|
||||||
} catch (\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ class Localizer {
|
|||||||
function init() {
|
function init() {
|
||||||
add_action(
|
add_action(
|
||||||
'init',
|
'init',
|
||||||
array($this, 'setup'),
|
array($this, 'setup')
|
||||||
0
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ use MailPoet\Settings\Pages;
|
|||||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
||||||
use MailPoet\Util\DKIM;
|
use MailPoet\Util\DKIM;
|
||||||
use MailPoet\Util\Permissions;
|
use MailPoet\Util\Permissions;
|
||||||
|
use MailPoet\Listing;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ class Menu {
|
|||||||
'forms'
|
'forms'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
add_submenu_page(
|
$subscribers_page = add_submenu_page(
|
||||||
'mailpoet',
|
'mailpoet',
|
||||||
__('Subscribers'),
|
__('Subscribers'),
|
||||||
__('Subscribers'),
|
__('Subscribers'),
|
||||||
@ -78,6 +79,17 @@ class Menu {
|
|||||||
'subscribers'
|
'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(
|
add_submenu_page(
|
||||||
'mailpoet',
|
'mailpoet',
|
||||||
__('Segments'),
|
__('Segments'),
|
||||||
@ -190,6 +202,8 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function welcome() {
|
function welcome() {
|
||||||
|
if((bool)(defined('DOING_AJAX') && DOING_AJAX)) return;
|
||||||
|
|
||||||
global $wp;
|
global $wp;
|
||||||
$current_url = home_url(add_query_arg($wp->query_string, $wp->request));
|
$current_url = home_url(add_query_arg($wp->query_string, $wp->request));
|
||||||
$redirect_url =
|
$redirect_url =
|
||||||
@ -240,6 +254,7 @@ class Menu {
|
|||||||
|
|
||||||
function settings() {
|
function settings() {
|
||||||
$settings = Setting::getAll();
|
$settings = Setting::getAll();
|
||||||
|
$flags = $this->_getFlags();
|
||||||
|
|
||||||
// dkim: check if public/private keys have been generated
|
// dkim: check if public/private keys have been generated
|
||||||
if(
|
if(
|
||||||
@ -258,10 +273,9 @@ class Menu {
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'segments' => Segment::getPublished()
|
'segments' => Segment::getPublic()->findArray(),
|
||||||
->findArray(),
|
|
||||||
'pages' => Pages::getAll(),
|
'pages' => Pages::getAll(),
|
||||||
'flags' => $this->_getFlags(),
|
'flags' => $flags,
|
||||||
'charsets' => Charsets::getAll(),
|
'charsets' => Charsets::getAll(),
|
||||||
'current_user' => wp_get_current_user(),
|
'current_user' => wp_get_current_user(),
|
||||||
'permissions' => Permissions::getAll(),
|
'permissions' => Permissions::getAll(),
|
||||||
@ -294,7 +308,7 @@ class Menu {
|
|||||||
} else {
|
} else {
|
||||||
// check if users can register
|
// check if users can register
|
||||||
$flags['registration_enabled'] =
|
$flags['registration_enabled'] =
|
||||||
(bool) get_option('users_can_register', false);
|
(bool)get_option('users_can_register', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $flags;
|
return $flags;
|
||||||
@ -303,8 +317,33 @@ class Menu {
|
|||||||
function subscribers() {
|
function subscribers() {
|
||||||
$data = array();
|
$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['segments'] = Segment::findArray();
|
||||||
|
|
||||||
|
$data['custom_fields'] = array_map(function($field) {
|
||||||
|
$field['params'] = unserialize($field['params']);
|
||||||
|
|
||||||
|
if(!empty($field['params']['values'])) {
|
||||||
|
$values = array();
|
||||||
|
|
||||||
|
foreach($field['params']['values'] as $value) {
|
||||||
|
$values[$value['value']] = $value['value'];
|
||||||
|
}
|
||||||
|
$field['params']['values'] = $values;
|
||||||
|
}
|
||||||
|
return $field;
|
||||||
|
}, CustomField::findArray());
|
||||||
|
|
||||||
|
$data['date_formats'] = Block\Date::getDateFormats();
|
||||||
|
$data['month_names'] = Block\Date::getMonthNames();
|
||||||
|
|
||||||
echo $this->renderer->render('subscribers/subscribers.html', $data);
|
echo $this->renderer->render('subscribers/subscribers.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +380,7 @@ class Menu {
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'customFields' => $custom_fields,
|
'customFields' => $custom_fields,
|
||||||
|
'settings' => Setting::getAll(),
|
||||||
);
|
);
|
||||||
wp_enqueue_media();
|
wp_enqueue_media();
|
||||||
wp_enqueue_script('tinymce-wplink', includes_url('js/tinymce/plugins/wplink/plugin.js'));
|
wp_enqueue_script('tinymce-wplink', includes_url('js/tinymce/plugins/wplink/plugin.js'));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||||
|
|
||||||
@ -236,10 +236,7 @@ class Migrator {
|
|||||||
'newsletter_id mediumint(9) NOT NULL,',
|
'newsletter_id mediumint(9) NOT NULL,',
|
||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'queue_id mediumint(9) NOT NULL,',
|
'queue_id mediumint(9) NOT NULL,',
|
||||||
'sent_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'sent_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'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,',
|
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
|
@ -8,6 +8,7 @@ use MailPoet\Config\PopulatorData\Templates\PostNotificationsBlankTemplate;
|
|||||||
use \MailPoet\Models\Segment;
|
use \MailPoet\Models\Segment;
|
||||||
use \MailPoet\Segments\WP;
|
use \MailPoet\Segments\WP;
|
||||||
use \MailPoet\Models\Setting;
|
use \MailPoet\Models\Setting;
|
||||||
|
use \MailPoet\Settings\Pages;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
@ -48,6 +49,29 @@ class Populator {
|
|||||||
|
|
||||||
$this->createDefaultSegments();
|
$this->createDefaultSegments();
|
||||||
$this->createDefaultSettings();
|
$this->createDefaultSettings();
|
||||||
|
$this->createMailPoetPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createMailPoetPage() {
|
||||||
|
$pages = get_posts(array(
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
'orderby' => 'date',
|
||||||
|
'order' => 'DESC',
|
||||||
|
'post_type' => 'mailpoet_page'
|
||||||
|
));
|
||||||
|
|
||||||
|
$page = null;
|
||||||
|
if(!empty($pages)) {
|
||||||
|
$page = array_shift($pages);
|
||||||
|
if(strpos($page->post_content, '[mailpoet_page]') === false) {
|
||||||
|
$page = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($page === null) {
|
||||||
|
$mailpoet_page_id = Pages::createMailPoetPage();
|
||||||
|
Setting::setValue('subscription.page', $mailpoet_page_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createDefaultSettings() {
|
private function createDefaultSettings() {
|
||||||
@ -72,6 +96,9 @@ class Populator {
|
|||||||
'name' => $user_name,
|
'name' => $user_name,
|
||||||
'address' => $current_user->user_email
|
'address' => $current_user->user_email
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// enable signup confirmation by default
|
||||||
|
Setting::setValue('signup_confirmation.enabled', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createDefaultSegments() {
|
private function createDefaultSegments() {
|
||||||
|
@ -68,7 +68,7 @@ class FranksRoastHouseTemplate {
|
|||||||
"link" => "http://www.example.com",
|
"link" => "http://www.example.com",
|
||||||
"src" => $this->template_image_url . "/header-v2.jpg",
|
"src" => $this->template_image_url . "/header-v2.jpg",
|
||||||
"alt" => __("Frank's Roast House"),
|
"alt" => __("Frank's Roast House"),
|
||||||
"padded" => false,
|
"fullWidth" => true,
|
||||||
"width" => "600px",
|
"width" => "600px",
|
||||||
"height" => "220px",
|
"height" => "220px",
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
@ -95,7 +95,7 @@ class FranksRoastHouseTemplate {
|
|||||||
"link" => "http://example.org",
|
"link" => "http://example.org",
|
||||||
"src" => $this->template_image_url . "/coffee-grain.jpg",
|
"src" => $this->template_image_url . "/coffee-grain.jpg",
|
||||||
"alt" => __("coffee-grain-3-1329675-1599x941"),
|
"alt" => __("coffee-grain-3-1329675-1599x941"),
|
||||||
"padded" => true,
|
"fullWidth" => false,
|
||||||
"width" => "1599px",
|
"width" => "1599px",
|
||||||
"height" => "777px",
|
"height" => "777px",
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
@ -139,7 +139,7 @@ class FranksRoastHouseTemplate {
|
|||||||
"link" => "http://example.org",
|
"link" => "http://example.org",
|
||||||
"src" => $this->template_image_url . "/sandwich.jpg",
|
"src" => $this->template_image_url . "/sandwich.jpg",
|
||||||
"alt" => "sandwich",
|
"alt" => "sandwich",
|
||||||
"padded" => true,
|
"fullWidth" => false,
|
||||||
"width" => "640px",
|
"width" => "640px",
|
||||||
"height" => "344px",
|
"height" => "344px",
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
@ -168,6 +168,7 @@ class FranksRoastHouseTemplate {
|
|||||||
"fontColor" => "#ffffff",
|
"fontColor" => "#ffffff",
|
||||||
"fontFamily" => "Arial",
|
"fontFamily" => "Arial",
|
||||||
"fontSize" => "14px",
|
"fontSize" => "14px",
|
||||||
|
"fontWeight" => "normal",
|
||||||
"textAlign" => "center"
|
"textAlign" => "center"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -238,7 +239,7 @@ class FranksRoastHouseTemplate {
|
|||||||
"link" => "http://example.org",
|
"link" => "http://example.org",
|
||||||
"src" => $this->template_image_url . "/map-v2.jpg",
|
"src" => $this->template_image_url . "/map-v2.jpg",
|
||||||
"alt" => __("map-v2"),
|
"alt" => __("map-v2"),
|
||||||
"padded" => true,
|
"fullWidth" => false,
|
||||||
"width" => "636px",
|
"width" => "636px",
|
||||||
"height" => "342px",
|
"height" => "342px",
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
@ -279,19 +280,19 @@ class FranksRoastHouseTemplate {
|
|||||||
"blocks" => array(
|
"blocks" => array(
|
||||||
array(
|
array(
|
||||||
"type" => "footer",
|
"type" => "footer",
|
||||||
"text" => __("<p><span style=\"color: #000000;\"><a href=\"[unsubscribeUrl]\" style=\"color: #000000;\">Unsubscribe</a> | <a href=\"[manageSubscriptionUrl]\" style=\"color: #000000;\">Manage subscription</a></span><br /><span style=\"color: #000000;\">12345 MailPoet Drive, EmailVille, 76543</span></p>"),
|
"text" => __("<p><a href=\"[unsubscribeUrl]\">Unsubscribe</a> | <a href=\"[manageSubscriptionUrl]\">Manage subscription</a><br />12345 MailPoet Drive, EmailVille, 76543</p>"),
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
"block" => array(
|
"block" => array(
|
||||||
"backgroundColor" => "#a9a7a7"
|
"backgroundColor" => "#a9a7a7"
|
||||||
),
|
),
|
||||||
"text" => array(
|
"text" => array(
|
||||||
"fontColor" => "#ffffff",
|
"fontColor" => "#000000",
|
||||||
"fontFamily" => "Arial",
|
"fontFamily" => "Arial",
|
||||||
"fontSize" => "12px",
|
"fontSize" => "12px",
|
||||||
"textAlign" => "center"
|
"textAlign" => "center"
|
||||||
),
|
),
|
||||||
"link" => array(
|
"link" => array(
|
||||||
"fontColor" => "#ffffff",
|
"fontColor" => "#000000",
|
||||||
"textDecoration" => "underline"
|
"textDecoration" => "underline"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -90,7 +90,7 @@ class PostNotificationsBlankTemplate {
|
|||||||
"link" => "http://example.org",
|
"link" => "http://example.org",
|
||||||
"src" => $this->template_image_url . "/ALC-widget-icon.png",
|
"src" => $this->template_image_url . "/ALC-widget-icon.png",
|
||||||
"alt" => __("ALC-widget-icon"),
|
"alt" => __("ALC-widget-icon"),
|
||||||
"padded" => true,
|
"fullWidth" => false,
|
||||||
"width" => "200px",
|
"width" => "200px",
|
||||||
"height" => "134px",
|
"height" => "134px",
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
@ -325,6 +325,7 @@ class PostNotificationsBlankTemplate {
|
|||||||
"fontColor" => "#ffffff",
|
"fontColor" => "#ffffff",
|
||||||
"fontFamily" => "Arial",
|
"fontFamily" => "Arial",
|
||||||
"fontSize" => "18px",
|
"fontSize" => "18px",
|
||||||
|
"fontWeight" => "normal",
|
||||||
"textAlign" => "center"
|
"textAlign" => "center"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -68,7 +68,7 @@ class WelcomeTemplate {
|
|||||||
"link" => "http://example.org",
|
"link" => "http://example.org",
|
||||||
"src" => $this->template_image_url . "/logo-header.gif",
|
"src" => $this->template_image_url . "/logo-header.gif",
|
||||||
"alt" => "logo-header",
|
"alt" => "logo-header",
|
||||||
"padded" => true,
|
"fullWidth" => false,
|
||||||
"width" => "233px",
|
"width" => "233px",
|
||||||
"height" => "118px",
|
"height" => "118px",
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
|
@ -20,7 +20,7 @@ class PublicAPI {
|
|||||||
Helpers::underscoreToCamelCase($_GET['action']) :
|
Helpers::underscoreToCamelCase($_GET['action']) :
|
||||||
false;
|
false;
|
||||||
$this->request_payload = isset($_GET['request_payload']) ?
|
$this->request_payload = isset($_GET['request_payload']) ?
|
||||||
json_decode(urldecode($_GET['request_payload']), true) :
|
unserialize(base64_decode($_GET['request_payload'])) :
|
||||||
false;
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
use \MailPoet\Models\Newsletter;
|
||||||
|
use \MailPoet\Models\Subscriber;
|
||||||
|
use \MailPoet\Models\SubscriberSegment;
|
||||||
|
|
||||||
class Shortcodes {
|
class Shortcodes {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
@ -9,6 +12,26 @@ class Shortcodes {
|
|||||||
// form widget shortcode
|
// form widget shortcode
|
||||||
add_shortcode('mailpoet_form', array($this, 'formWidget'));
|
add_shortcode('mailpoet_form', array($this, 'formWidget'));
|
||||||
add_shortcode('wysija_form', array($this, 'formWidget'));
|
add_shortcode('wysija_form', array($this, 'formWidget'));
|
||||||
|
|
||||||
|
// subscribers count shortcode
|
||||||
|
add_shortcode('mailpoet_subscribers_count', array(
|
||||||
|
$this, 'getSubscribersCount'
|
||||||
|
));
|
||||||
|
add_shortcode('wysija_subscribers_count', array(
|
||||||
|
$this, 'getSubscribersCount'
|
||||||
|
));
|
||||||
|
|
||||||
|
// archives page
|
||||||
|
add_shortcode('mailpoet_archive', array(
|
||||||
|
$this, 'getArchive'
|
||||||
|
));
|
||||||
|
|
||||||
|
add_filter('mailpoet_archive_date', array(
|
||||||
|
$this, 'renderArchiveDate'
|
||||||
|
), 2);
|
||||||
|
add_filter('mailpoet_archive_subject', array(
|
||||||
|
$this, 'renderArchiveSubject'
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formWidget($params = array()) {
|
function formWidget($params = array()) {
|
||||||
@ -23,4 +46,76 @@ class Shortcodes {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSubscribersCount($params) {
|
||||||
|
if(!empty($params['segments'])) {
|
||||||
|
$segment_ids = array_map(function($segment_id) {
|
||||||
|
return (int)trim($segment_id);
|
||||||
|
}, explode(',', $params['segments']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($segment_ids)) {
|
||||||
|
return Subscriber::filter('subscribed')->count();
|
||||||
|
} else {
|
||||||
|
return SubscriberSegment::whereIn('segment_id', $segment_ids)
|
||||||
|
->select('subscriber_id')->distinct()
|
||||||
|
->filter('subscribed')
|
||||||
|
->findResultSet()->count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArchive($params) {
|
||||||
|
if(!empty($params['segments'])) {
|
||||||
|
$segment_ids = array_map(function($segment_id) {
|
||||||
|
return (int)trim($segment_id);
|
||||||
|
}, explode(',', $params['segments']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$newsletters = array();
|
||||||
|
$html = '';
|
||||||
|
|
||||||
|
// TODO: needs more advanced newsletters in order to finish
|
||||||
|
$newsletters = Newsletter::limit(10)->orderByDesc('created_at')->findMany();
|
||||||
|
|
||||||
|
if(empty($newsletters)) {
|
||||||
|
return apply_filters(
|
||||||
|
'mailpoet_archive_no_newsletters',
|
||||||
|
__('Oops! There are no newsletters to display.')
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$title = apply_filters('mailpoet_archive_title', '');
|
||||||
|
if(!empty($title)) {
|
||||||
|
$html .= '<h3 class="mailpoet_archive_title">'.$title.'</h3>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '<ul class="mailpoet_archive">';
|
||||||
|
foreach($newsletters as $newsletter) {
|
||||||
|
$html .= '<li>'.
|
||||||
|
'<span class="mailpoet_archive_date">'.
|
||||||
|
apply_filters('mailpoet_archive_date', $newsletter).
|
||||||
|
'</span>
|
||||||
|
<span class="mailpoet_archive_subject">'.
|
||||||
|
apply_filters('mailpoet_archive_subject', $newsletter).
|
||||||
|
'</span>
|
||||||
|
</li>';
|
||||||
|
}
|
||||||
|
$html .= '</ul>';
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderArchiveDate($newsletter) {
|
||||||
|
return date_i18n(
|
||||||
|
get_option('date_format'),
|
||||||
|
strtotime($newsletter->created_at)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderArchiveSubject($newsletter) {
|
||||||
|
return '<a href="TODO" target="_blank" title="'
|
||||||
|
.esc_attr(__('Preview in new tab')).'">'
|
||||||
|
.esc_attr($newsletter->subject).
|
||||||
|
'</a>';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
use \MailPoet\Models\Subscriber;
|
|
||||||
use \MailPoet\Util\Security;
|
use \MailPoet\Util\Security;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
@ -10,30 +9,17 @@ class Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
add_action('widgets_init', array($this, 'registerWidget'));
|
$this->registerWidget();
|
||||||
|
|
||||||
if(!is_admin()) {
|
if(!is_admin()) {
|
||||||
//$this->setupActions();
|
$this->setupDependencies();
|
||||||
add_action('widgets_init', array($this, 'setupDependencies'));
|
|
||||||
} else {
|
} else {
|
||||||
add_action('widgets_init', array($this, 'setupAdminDependencies'));
|
$this->setupAdminDependencies();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerWidget() {
|
function registerWidget() {
|
||||||
register_widget('\MailPoet\Form\Widget');
|
register_widget('\MailPoet\Form\Widget');
|
||||||
|
|
||||||
// subscribers count shortcode
|
|
||||||
add_shortcode('mailpoet_subscribers_count', array(
|
|
||||||
$this, 'getSubscribersCount'
|
|
||||||
));
|
|
||||||
add_shortcode('wysija_subscribers_count', array(
|
|
||||||
$this, 'getSubscribersCount'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSubscribersCount($params) {
|
|
||||||
return Subscriber::filter('subscribed')->count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupDependencies() {
|
function setupDependencies() {
|
||||||
@ -82,6 +68,9 @@ class Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: extract this method into an Initializer
|
||||||
|
// - the "ajax" part might probably be useless
|
||||||
|
// - the "post" (non-ajax) part needs to be redone properly
|
||||||
function setupActions() {
|
function setupActions() {
|
||||||
// ajax requests
|
// ajax requests
|
||||||
add_action(
|
add_action(
|
||||||
|
78
lib/Cron/CronHelper.php
Normal file
78
lib/Cron/CronHelper.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Cron;
|
||||||
|
|
||||||
|
use MailPoet\Models\Setting;
|
||||||
|
use MailPoet\Util\Security;
|
||||||
|
|
||||||
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
class CronHelper {
|
||||||
|
const daemon_execution_limit = 20;
|
||||||
|
const daemon_execution_timeout = 35;
|
||||||
|
const daemon_request_timeout = 2;
|
||||||
|
|
||||||
|
static function createDaemon($token) {
|
||||||
|
$daemon = array(
|
||||||
|
'status' => 'starting',
|
||||||
|
'counter' => 0,
|
||||||
|
'token' => $token
|
||||||
|
);
|
||||||
|
self::saveDaemon($daemon);
|
||||||
|
return $daemon;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getDaemon() {
|
||||||
|
return Setting::getValue('cron_daemon');
|
||||||
|
}
|
||||||
|
|
||||||
|
static function saveDaemon($daemon) {
|
||||||
|
$daemon['updated_at'] = time();
|
||||||
|
return Setting::setValue(
|
||||||
|
'cron_daemon',
|
||||||
|
$daemon
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function createToken() {
|
||||||
|
return Security::generateRandomString();
|
||||||
|
}
|
||||||
|
|
||||||
|
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' => $timeout,
|
||||||
|
'user-agent' => 'MailPoet (www.mailpoet.com) Cron'
|
||||||
|
);
|
||||||
|
$result = wp_remote_get(
|
||||||
|
self::getSiteUrl() . $url,
|
||||||
|
$args
|
||||||
|
);
|
||||||
|
return wp_remote_retrieve_body($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getSiteUrl() {
|
||||||
|
// additional check for some sites running on a virtual machine or behind
|
||||||
|
// proxy where there could be different ports (e.g., host:8080 => guest:80)
|
||||||
|
|
||||||
|
// if the site URL does not contain a port, return the URL
|
||||||
|
if(!preg_match('!^https?://.*?:\d+!', site_url())) return site_url();
|
||||||
|
preg_match('!://(?P<host>.*?):(?P<port>\d+)!', site_url(), $server);
|
||||||
|
// connect to the URL with port
|
||||||
|
$fp = @fsockopen($server['host'], $server['port'], $errno, $errstr, 1);
|
||||||
|
if($fp) return site_url();
|
||||||
|
// connect to the URL without port
|
||||||
|
$fp = @fsockopen($server['host'], $server['port'], $errno, $errstr, 1);
|
||||||
|
if($fp) return preg_replace('!(?=:\d+):\d+!', '$1', site_url());
|
||||||
|
// throw an error if all connection attempts failed
|
||||||
|
throw new \Exception(__('Site URL is unreachable.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function checkExecutionTimer($timer) {
|
||||||
|
$elapsed_time = microtime(true) - $timer;
|
||||||
|
if($elapsed_time >= self::daemon_execution_limit) {
|
||||||
|
throw new \Exception(__('Maximum execution time reached.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Cron;
|
namespace MailPoet\Cron;
|
||||||
|
|
||||||
|
use MailPoet\Cron\Workers\Scheduler;
|
||||||
use MailPoet\Cron\Workers\SendingQueue;
|
use MailPoet\Cron\Workers\SendingQueue;
|
||||||
use MailPoet\Models\Setting;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Util\Security;
|
|
||||||
|
|
||||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||||
|
|
||||||
@ -13,132 +13,68 @@ class Daemon {
|
|||||||
public $daemon;
|
public $daemon;
|
||||||
public $request_payload;
|
public $request_payload;
|
||||||
public $refreshed_token;
|
public $refreshed_token;
|
||||||
public $timer;
|
const daemon_request_timeout = 5;
|
||||||
|
private $timer;
|
||||||
|
|
||||||
function __construct($request_payload = array()) {
|
function __construct($request_payload = array()) {
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
ignore_user_abort();
|
ignore_user_abort();
|
||||||
$this->daemon = $this->getDaemon();
|
$this->daemon = CronHelper::getDaemon();
|
||||||
$this->refreshed_token = $this->refreshToken();
|
$this->token = CronHelper::createToken();
|
||||||
$this->request_payload = $request_payload;
|
$this->request_payload = $request_payload;
|
||||||
$this->timer = microtime(true);
|
$this->timer = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function start() {
|
function run() {
|
||||||
if(!isset($this->request_payload['session'])) {
|
|
||||||
$this->abortWithError(__('Missing session ID.'));
|
|
||||||
}
|
|
||||||
$this->manageSession('start');
|
|
||||||
$daemon = $this->daemon;
|
$daemon = $this->daemon;
|
||||||
if(!$daemon) {
|
if(!$daemon) {
|
||||||
$this->saveDaemon(
|
$this->abortWithError(__('Daemon does not exist.'));
|
||||||
array(
|
|
||||||
'status' => 'starting',
|
|
||||||
'counter' => 0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if($daemon['status'] === 'started') {
|
|
||||||
$_SESSION['cron_daemon'] = array(
|
|
||||||
'result' => false,
|
|
||||||
'errors' => array(__('Daemon already running.'))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if($daemon['status'] === 'starting') {
|
|
||||||
$_SESSION['cron_daemon'] = 'started';
|
|
||||||
$_SESSION['cron_daemon'] = array('result' => true);
|
|
||||||
$this->manageSession('end');
|
|
||||||
$daemon['status'] = 'started';
|
|
||||||
$daemon['token'] = $this->refreshed_token;
|
|
||||||
$this->saveDaemon($daemon);
|
|
||||||
$this->callSelf();
|
|
||||||
}
|
|
||||||
$this->manageSession('end');
|
|
||||||
}
|
|
||||||
|
|
||||||
function run() {
|
|
||||||
$allowed_statuses = array(
|
|
||||||
'stopping',
|
|
||||||
'starting',
|
|
||||||
'started'
|
|
||||||
);
|
|
||||||
if(!$this->daemon || !in_array($this->daemon['status'], $allowed_statuses)) {
|
|
||||||
$this->abortWithError(__('Invalid daemon status.'));
|
|
||||||
}
|
}
|
||||||
if(!isset($this->request_payload['token']) ||
|
if(!isset($this->request_payload['token']) ||
|
||||||
$this->request_payload['token'] !== $this->daemon['token']
|
$this->request_payload['token'] !== $daemon['token']
|
||||||
) {
|
) {
|
||||||
$this->abortWithError('Invalid token.');
|
$this->abortWithError(__('Invalid or missing token.'));
|
||||||
}
|
}
|
||||||
|
$this->abortIfStopped($daemon);
|
||||||
try {
|
try {
|
||||||
$sending_queue = new SendingQueue($this->timer);
|
do_action('mailpoet_cron_worker', $this->timer);
|
||||||
$sending_queue->process();
|
} catch(\Exception $e) {
|
||||||
} catch(Exception $e) {
|
|
||||||
}
|
}
|
||||||
$elapsed_time = microtime(true) - $this->timer;
|
$elapsed_time = microtime(true) - $this->timer;
|
||||||
if($elapsed_time < 30) {
|
if($elapsed_time < CronHelper::daemon_execution_limit) {
|
||||||
sleep(30 - $elapsed_time);
|
sleep(CronHelper::daemon_execution_limit - $elapsed_time);
|
||||||
|
}
|
||||||
|
// after each execution, re-read daemon data in case it was deleted or
|
||||||
|
// its status has changed
|
||||||
|
$daemon = CronHelper::getDaemon();
|
||||||
|
if(!$daemon || $daemon['token'] !== $this->request_payload['token']) {
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
// after each execution, read daemon in case its status was modified
|
|
||||||
$daemon = $this->getDaemon();
|
|
||||||
|
|
||||||
if($daemon['status'] === 'stopping') $daemon['status'] = 'stopped';
|
|
||||||
if($daemon['status'] === 'starting') $daemon['status'] = 'started';
|
|
||||||
|
|
||||||
$daemon['token'] = $this->refreshed_token;
|
|
||||||
$daemon['counter']++;
|
$daemon['counter']++;
|
||||||
|
$this->abortIfStopped($daemon);
|
||||||
$this->saveDaemon($daemon);
|
if($daemon['status'] === 'starting') {
|
||||||
|
$daemon['status'] = 'started';
|
||||||
if($daemon['status'] === 'started') $this->callSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDaemon() {
|
|
||||||
return Setting::getValue('cron_daemon');
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveDaemon($daemon_data) {
|
|
||||||
$daemon_data['updated_at'] = time();
|
|
||||||
|
|
||||||
return Setting::setValue(
|
|
||||||
'cron_daemon',
|
|
||||||
$daemon_data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshToken() {
|
|
||||||
return Security::generateRandomString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function manageSession($action) {
|
|
||||||
switch($action) {
|
|
||||||
case 'start':
|
|
||||||
if(session_id()) {
|
|
||||||
session_write_close();
|
|
||||||
}
|
|
||||||
session_id($this->request_payload['session']);
|
|
||||||
session_start();
|
|
||||||
break;
|
|
||||||
case 'end':
|
|
||||||
session_write_close();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
$daemon['token'] = $this->token;
|
||||||
|
CronHelper::saveDaemon($daemon);
|
||||||
|
$this->callSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
function abortIfStopped($daemon) {
|
||||||
|
if($daemon['status'] === 'stopped') exit;
|
||||||
|
if($daemon['status'] === 'stopping') {
|
||||||
|
$daemon['status'] = 'stopped';
|
||||||
|
CronHelper::saveDaemon($daemon);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function abortWithError($message) {
|
||||||
|
exit('[mailpoet_cron_error:' . base64_encode($message) . ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
function callSelf() {
|
function callSelf() {
|
||||||
$payload = json_encode(array('token' => $this->refreshed_token));
|
CronHelper::accessDaemon($this->token, self::daemon_request_timeout);
|
||||||
Supervisor::accessRemoteUrl(
|
|
||||||
'/?mailpoet-api§ion=queue&action=run&request_payload=' . urlencode($payload)
|
|
||||||
);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function abortWithError($error) {
|
|
||||||
wp_send_json(
|
|
||||||
array(
|
|
||||||
'result' => false,
|
|
||||||
'errors' => array($error)
|
|
||||||
));
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,103 +1,94 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Cron;
|
namespace MailPoet\Cron;
|
||||||
|
|
||||||
use MailPoet\Config\Env;
|
|
||||||
use MailPoet\Models\Setting;
|
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Supervisor {
|
class Supervisor {
|
||||||
public $daemon;
|
public $daemon;
|
||||||
|
public $token;
|
||||||
|
public $force_run;
|
||||||
|
|
||||||
function __construct($force_start = false) {
|
function __construct($force_run = false) {
|
||||||
$this->force_start = $force_start;
|
$this->daemon = CronHelper::getDaemon();
|
||||||
if(!Env::isPluginActivated()) {
|
$this->token = CronHelper::createToken();
|
||||||
throw new \Exception(__('MailPoet is not activated.'));
|
$this->force_run = $force_run;
|
||||||
}
|
|
||||||
$this->daemon = $this->getDaemon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkDaemon() {
|
function checkDaemon() {
|
||||||
if(!$this->daemon) {
|
$daemon = $this->daemon;
|
||||||
return $this->startDaemon();
|
if(!$daemon) {
|
||||||
|
$daemon = CronHelper::createDaemon($this->token);
|
||||||
|
return $this->runDaemon($daemon);
|
||||||
}
|
}
|
||||||
if(
|
// if the daemon is stopped, return its status and do nothing
|
||||||
!$this->force_start &&
|
if(!$this->force_run &&
|
||||||
in_array($this->daemon['status'], array('stopped', 'stopping'))
|
isset($daemon['status']) &&
|
||||||
|
$daemon['status'] === 'stopped'
|
||||||
) {
|
) {
|
||||||
return $this->daemon['status'];
|
return $this->formatDaemonStatusMessage($daemon['status']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$elapsed_time = time() - (int) $daemon['updated_at'];
|
||||||
$elapsed_time = time() - (int)$this->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 < 40) {
|
if($elapsed_time < CronHelper::daemon_execution_timeout && !$this->force_run) {
|
||||||
if(!$this->force_start) {
|
return $this->formatDaemonStatusMessage($daemon['status']);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if($this->daemon['status'] === 'stopping' ||
|
|
||||||
$this->daemon['status'] === 'starting'
|
|
||||||
) {
|
|
||||||
return $this->daemon['status'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$this->daemon['status'] = 'starting';
|
// if it's been less than 40 seconds since last execution, we are
|
||||||
$this->saveDaemon($this->daemon);
|
// force-running the daemon and it's either being started or stopped,
|
||||||
return $this->startDaemon();
|
// return its status and do nothing
|
||||||
|
elseif($elapsed_time < CronHelper::daemon_execution_timeout &&
|
||||||
|
$this->force_run &&
|
||||||
|
in_array($daemon['status'], array(
|
||||||
|
'stopping',
|
||||||
|
'starting'
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
return $this->formatDaemonStatusMessage($daemon['status']);
|
||||||
|
}
|
||||||
|
// re-create (restart) daemon
|
||||||
|
CronHelper::createDaemon($this->token);
|
||||||
|
return $this->runDaemon();
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDaemon() {
|
function runDaemon() {
|
||||||
if(!session_id()) session_start();
|
$request = CronHelper::accessDaemon($this->token);
|
||||||
$sessionId = session_id();
|
preg_match('/\[(mailpoet_cron_error:.*?)\]/i', $request, $status);
|
||||||
session_write_close();
|
$daemon = CronHelper::getDaemon();
|
||||||
$_SESSION['cron_daemon'] = null;
|
if(!empty($status) || !$daemon) {
|
||||||
$requestPayload = json_encode(array('session' => $sessionId));
|
if(!$daemon) {
|
||||||
self::accessRemoteUrl(
|
$message = __('Daemon failed to run.');
|
||||||
'/?mailpoet-api§ion=queue&action=start&request_payload=' .
|
} else {
|
||||||
urlencode($requestPayload)
|
list(, $message) = explode(':', $status[0]);
|
||||||
);
|
$message = base64_decode($message);
|
||||||
session_start();
|
}
|
||||||
$daemonStatus = $_SESSION['cron_daemon'];
|
return $this->formatResultMessage(
|
||||||
unset($_SESSION['daemon']);
|
false,
|
||||||
session_write_close();
|
$message
|
||||||
return $daemonStatus;
|
);
|
||||||
|
}
|
||||||
|
return $this->formatDaemonStatusMessage($daemon['status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDaemon() {
|
private function formatDaemonStatusMessage($status) {
|
||||||
return Setting::getValue('cron_daemon');
|
return $this->formatResultMessage(
|
||||||
}
|
true,
|
||||||
|
sprintf(
|
||||||
function saveDaemon($daemon_data) {
|
__('Daemon is currently %s.'),
|
||||||
return Setting::setValue(
|
__($status)
|
||||||
'cron_daemon',
|
)
|
||||||
$daemon_data
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function accessRemoteUrl($url) {
|
private function formatResultMessage($result, $message) {
|
||||||
$args = array(
|
$formattedResult = array(
|
||||||
'timeout' => 1,
|
'result' => $result
|
||||||
'user-agent' => 'MailPoet (www.mailpoet.com) Cron'
|
|
||||||
);
|
);
|
||||||
wp_remote_get(
|
if(!$result) {
|
||||||
self::getSiteUrl() . $url,
|
$formattedResult['errors'] = array($message);
|
||||||
$args
|
} else {
|
||||||
);
|
$formattedResult['message'] = $message;
|
||||||
}
|
}
|
||||||
|
return $formattedResult;
|
||||||
static function getSiteUrl() {
|
|
||||||
// additional check for some sites running on a virtual machine or behind
|
|
||||||
// proxy where there could be different ports (e.g., host:8080 => guest:80)
|
|
||||||
|
|
||||||
// if the site URL does not contain a port, return the URL
|
|
||||||
if(!preg_match('!^https?://.*?:\d+!', site_url())) return site_url();
|
|
||||||
preg_match('!://(?P<host>.*?):(?P<port>\d+)!', site_url(), $server);
|
|
||||||
// connect to the URL with port
|
|
||||||
$fp = @fsockopen($server['host'], $server['port'], $errno, $errstr, 1);
|
|
||||||
if($fp) return site_url();
|
|
||||||
// connect to the URL without port
|
|
||||||
$fp = @fsockopen($server['host'], $server['port'], $errno, $errstr, 1);
|
|
||||||
if($fp) return preg_replace('!(?=:\d+):\d+!', '$1', site_url());
|
|
||||||
// throw an error if all connections fail
|
|
||||||
throw new \Exception(__('Site URL is unreachable.'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
27
lib/Cron/Workers/Scheduler.php
Normal file
27
lib/Cron/Workers/Scheduler.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Cron\Workers;
|
||||||
|
|
||||||
|
use MailPoet\Cron\CronHelper;
|
||||||
|
use MailPoet\Models\Setting;
|
||||||
|
use MailPoet\Util\Security;
|
||||||
|
|
||||||
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
class Scheduler {
|
||||||
|
public $timer;
|
||||||
|
|
||||||
|
function __construct($timer = false) {
|
||||||
|
$this->timer = ($timer) ? $timer : microtime(true);
|
||||||
|
CronHelper::checkExecutionTimer($this->timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
function process() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkExecutionTimer() {
|
||||||
|
$elapsed_time = microtime(true) - $this->timer;
|
||||||
|
if($elapsed_time >= CronHelper::daemon_execution_limit) {
|
||||||
|
throw new \Exception(__('Maximum execution time reached.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,123 +1,192 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Cron\Workers;
|
namespace MailPoet\Cron\Workers;
|
||||||
|
|
||||||
|
use MailPoet\Cron\CronHelper;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\NewsletterStatistics;
|
use MailPoet\Models\NewsletterStatistics;
|
||||||
|
use MailPoet\Models\Setting;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Newsletter\Renderer\Renderer;
|
use MailPoet\Newsletter\Renderer\Renderer;
|
||||||
|
use MailPoet\Newsletter\Shortcodes\Shortcodes;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
|
use MailPoet\Util\Security;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class SendingQueue {
|
class SendingQueue {
|
||||||
public $timer;
|
public $mta_config;
|
||||||
|
public $mta_log;
|
||||||
|
public $processing_method;
|
||||||
|
private $timer;
|
||||||
|
const batch_size = 50;
|
||||||
|
|
||||||
function __construct($timer = false) {
|
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);
|
$this->timer = ($timer) ? $timer : microtime(true);
|
||||||
|
CronHelper::checkExecutionTimer($this->timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
function process() {
|
function process() {
|
||||||
// TODO: implement mailer sending frequency limits
|
|
||||||
foreach($this->getQueues() as $queue) {
|
foreach($this->getQueues() as $queue) {
|
||||||
$newsletter = Newsletter::findOne($queue->newsletter_id)
|
$newsletter = Newsletter::findOne($queue->newsletter_id);
|
||||||
->asArray();
|
|
||||||
if(!$newsletter) {
|
if(!$newsletter) {
|
||||||
continue;
|
continue;
|
||||||
};
|
}
|
||||||
$mailer = $this->configureMailerForNewsletter($newsletter);
|
$queue->subscribers = (object) unserialize($queue->subscribers);
|
||||||
$newsletter = $this->renderNewsletter($newsletter);
|
if(!isset($queue->subscribers->processed)) {
|
||||||
$subscribers = json_decode($queue->subscribers, true);
|
$queue->subscribers->processed = array();
|
||||||
$subscribers_to_process = $subscribers['to_process'];
|
}
|
||||||
if(!isset($subscribers['processed'])) $subscribers['processed'] = array();
|
if(!isset($queue->subscribers->failed)) {
|
||||||
if(!isset($subscribers['failed'])) $subscribers['failed'] = array();
|
$queue->subscribers->failed = array();
|
||||||
foreach(array_chunk($subscribers_to_process, 200) as $subscriber_ids) {
|
}
|
||||||
$db_subscribers = Subscriber::whereIn('id', $subscriber_ids)
|
$newsletter = $newsletter->asArray();
|
||||||
|
$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();
|
->findArray();
|
||||||
foreach($db_subscribers as $db_subscriber) {
|
$queue->subscribers = call_user_func_array(
|
||||||
$this->checkExecutionTimer();
|
array(
|
||||||
$result = $this->sendNewsletter(
|
$this,
|
||||||
|
$this->processing_method
|
||||||
|
),
|
||||||
|
array(
|
||||||
$mailer,
|
$mailer,
|
||||||
$this->processNewsletter($newsletter),
|
$newsletter,
|
||||||
$db_subscriber);
|
$subscribers,
|
||||||
if($result) {
|
$queue
|
||||||
$this->updateStatistics($newsletter['id'], $db_subscriber['id'], $queue->id);
|
)
|
||||||
$subscribers['processed'][] = $db_subscriber['id'];
|
);
|
||||||
} else {
|
|
||||||
$subscribers['failed'][] = $db_subscriber['id'];
|
|
||||||
}
|
|
||||||
$this->updateQueue($queue, $subscribers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function processNewsletter($newsletter) {
|
function processBulkSubscribers($mailer, $newsletter, $subscribers, $queue) {
|
||||||
// TODO: replace shortcodes, etc..
|
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();
|
||||||
|
CronHelper::checkExecutionTimer($this->timer);
|
||||||
|
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);
|
||||||
|
CronHelper::checkExecutionTimer($this->timer);
|
||||||
|
}
|
||||||
|
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;
|
return $newsletter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendNewsletter($mailer, $newsletter, $subscriber) {
|
function sendNewsletter($mailer, $newsletter, $subscriber) {
|
||||||
return $mailer->mailer_instance->send(
|
return $mailer->mailer_instance->send(
|
||||||
$newsletter,
|
$newsletter,
|
||||||
$mailer->transformSubscriber($subscriber)
|
$subscriber
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatistics($newsletter_id, $subscriber_id, $queue_id) {
|
function configureMailer($newsletter) {
|
||||||
$newsletter_statistic = NewsletterStatistics::create();
|
$sender['address'] = (!empty($newsletter['sender_address'])) ?
|
||||||
$newsletter_statistic->subscriber_id = $newsletter_id;
|
$newsletter['sender_address'] :
|
||||||
$newsletter_statistic->newsletter_id = $subscriber_id;
|
false;
|
||||||
$newsletter_statistic->queue_id = $queue_id;
|
$sender['name'] = (!empty($newsletter['sender_name'])) ?
|
||||||
$newsletter_statistic->save();
|
$newsletter['sender_name'] :
|
||||||
}
|
false;
|
||||||
|
$reply_to['address'] = (!empty($newsletter['reply_to_address'])) ?
|
||||||
function updateQueue($queue, $subscribers) {
|
$newsletter['reply_to_address'] :
|
||||||
$subscribers['to_process'] = array_values(
|
false;
|
||||||
array_diff(
|
$reply_to['name'] = (!empty($newsletter['reply_to_name'])) ?
|
||||||
$subscribers['to_process'],
|
$newsletter['reply_to_name'] :
|
||||||
array_merge($subscribers['processed'], $subscribers['failed'])
|
false;
|
||||||
)
|
if(!$sender['address']) {
|
||||||
);
|
|
||||||
$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 {
|
|
||||||
$sender = false;
|
$sender = false;
|
||||||
}
|
}
|
||||||
if(!empty($newsletter['reply_to_address']) && !empty($newsletter['reply_to_name'])) {
|
if(!$reply_to['address']) {
|
||||||
$reply_to = array(
|
|
||||||
'name' => $newsletter['reply_to_name'],
|
|
||||||
'address' => $newsletter['reply_to_address']
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$reply_to = false;
|
$reply_to = false;
|
||||||
}
|
}
|
||||||
$mailer = new Mailer($method = false, $sender, $reply_to);
|
$mailer = new Mailer($method = false, $sender, $reply_to);
|
||||||
return $mailer;
|
return $mailer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkExecutionTimer() {
|
|
||||||
$elapsed_time = microtime(true) - $this->timer;
|
|
||||||
if($elapsed_time >= 30) throw new \Exception('Maximum execution time reached.');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getQueues() {
|
function getQueues() {
|
||||||
return \MailPoet\Models\SendingQueue::orderByDesc('priority')
|
return \MailPoet\Models\SendingQueue::orderByDesc('priority')
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
@ -125,10 +194,71 @@ class SendingQueue {
|
|||||||
->findResultSet();
|
->findResultSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderNewsletter($newsletter) {
|
function updateQueue($queue) {
|
||||||
$renderer = new Renderer(json_decode($newsletter['body'], true));
|
$queue = clone($queue);
|
||||||
// TODO: update once text rendering is implemented/enderer returns an array
|
$queue->subscribers->to_process = array_diff(
|
||||||
$newsletter['body'] = array('html' => $renderer->render(), 'text' => '');
|
$queue->subscribers->to_process,
|
||||||
return $newsletter;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,9 @@ abstract class Base {
|
|||||||
if($block['id'] === 'segments') {
|
if($block['id'] === 'segments') {
|
||||||
$rules['required'] = true;
|
$rules['required'] = true;
|
||||||
$rules['mincheck'] = 1;
|
$rules['mincheck'] = 1;
|
||||||
$rules['error-message'] = __('You need to select a list');
|
$rules['group'] = $block['id'];
|
||||||
|
$rules['errors-container'] = '.mailpoet_error_'.$block['id'];
|
||||||
|
$rules['required-message'] = __('You need to select a list');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($block['params']['required'])) {
|
if(!empty($block['params']['required'])) {
|
||||||
@ -29,7 +31,7 @@ abstract class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($block['type'] === 'radio') {
|
if(in_array($block['type'], array('radio', 'checkbox'))) {
|
||||||
$rules['group'] = 'custom_field_'.$block['id'];
|
$rules['group'] = 'custom_field_'.$block['id'];
|
||||||
$rules['errors-container'] = '.mailpoet_error_'.$block['id'];
|
$rules['errors-container'] = '.mailpoet_error_'.$block['id'];
|
||||||
$rules['required-message'] = __('You need to select at least one option.');
|
$rules['required-message'] = __('You need to select at least one option.');
|
||||||
|
@ -9,32 +9,39 @@ class Checkbox extends Base {
|
|||||||
$field_name = static::getFieldName($block);
|
$field_name = static::getFieldName($block);
|
||||||
$field_validation = static::getInputValidation($block);
|
$field_validation = static::getInputValidation($block);
|
||||||
|
|
||||||
// TODO: check if it still makes sense
|
|
||||||
// create hidden default value
|
|
||||||
// $html .= '<input type="hidden"name="'.$field_name.'" value="0" '.static::getInputValidation($block).'/>';
|
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= static::renderLabel($block);
|
$html .= static::renderLabel($block);
|
||||||
|
|
||||||
foreach($block['params']['values'] as $option) {
|
$options = (!empty($block['params']['values'])
|
||||||
$html .= '<label class="mailpoet_checkbox_label">';
|
? $block['params']['values']
|
||||||
|
: array()
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($options as $option) {
|
||||||
|
$html .= '<label class="mailpoet_checkbox_label">';
|
||||||
|
$html .= '<input type="hidden" name="'.$field_name.'" value="" />';
|
||||||
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
|
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
|
||||||
|
|
||||||
$html .= 'name="'.$field_name.'" ';
|
$html .= 'name="'.$field_name.'" ';
|
||||||
|
|
||||||
$html .= 'value="1" ';
|
$html .= 'value="1" ';
|
||||||
|
|
||||||
$html .= (isset($option['is_checked']) && $option['is_checked'])
|
$html .= (
|
||||||
? 'checked="checked"' : '';
|
(isset($option['is_checked']) && $option['is_checked'])
|
||||||
|
||
|
||||||
|
(self::getFieldValue($block))
|
||||||
|
) ? 'checked="checked"' : '';
|
||||||
|
|
||||||
$html .= $field_validation;
|
$html .= $field_validation;
|
||||||
|
|
||||||
$html .= ' />'.$option['value'];
|
$html .= ' /> '.esc_attr($option['value']);
|
||||||
|
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$html .= '<span class="mailpoet_error_'.$block['id'].'"></span>';
|
||||||
|
|
||||||
$html .= '</p>';
|
$html .= '</p>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
@ -33,18 +33,37 @@ class Date extends Base {
|
|||||||
// generate an array of selectors based on date format
|
// generate an array of selectors based on date format
|
||||||
$date_selectors = explode('/', $date_format);
|
$date_selectors = explode('/', $date_format);
|
||||||
|
|
||||||
|
// format value if present
|
||||||
|
$value = self::getFieldValue($block);
|
||||||
|
$day = null;
|
||||||
|
$month = null;
|
||||||
|
$year = null;
|
||||||
|
|
||||||
|
if($value) {
|
||||||
|
$day = (int)strftime('%d', $value);
|
||||||
|
$month = (int)strftime('%m', $value);
|
||||||
|
$year = (int)strftime('%Y', $value);
|
||||||
|
} else if(!empty($block['params']['is_default_today'])) {
|
||||||
|
$day = (int)strftime('%d');
|
||||||
|
$month = (int)strftime('%m');
|
||||||
|
$year = (int)strftime('%Y');
|
||||||
|
}
|
||||||
|
|
||||||
foreach($date_selectors as $date_selector) {
|
foreach($date_selectors as $date_selector) {
|
||||||
if($date_selector === 'dd') {
|
if($date_selector === 'dd') {
|
||||||
|
$block['selected'] = $day;
|
||||||
$html .= '<select class="mailpoet_date_day" ';
|
$html .= '<select class="mailpoet_date_day" ';
|
||||||
$html .= 'name="'.$field_name.'[day]" placeholder="'.__('Day').'">';
|
$html .= 'name="'.$field_name.'[day]" placeholder="'.__('Day').'">';
|
||||||
$html .= static::getDays($block);
|
$html .= static::getDays($block);
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
} else if($date_selector === 'mm') {
|
} else if($date_selector === 'mm') {
|
||||||
|
$block['selected'] = $month;
|
||||||
$html .= '<select class="mailpoet_date_month" ';
|
$html .= '<select class="mailpoet_date_month" ';
|
||||||
$html .= 'name="'.$field_name.'[month]" placeholder="'.__('Month').'">';
|
$html .= 'name="'.$field_name.'[month]" placeholder="'.__('Month').'">';
|
||||||
$html .= static::getMonths($block);
|
$html .= static::getMonths($block);
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
} else if($date_selector === 'yyyy') {
|
} else if($date_selector === 'yyyy') {
|
||||||
|
$block['selected'] = $year;
|
||||||
$html .= '<select class="mailpoet_date_year" ';
|
$html .= '<select class="mailpoet_date_year" ';
|
||||||
$html .= 'name="'.$field_name.'[year]" placeholder="'.__('Year').'">';
|
$html .= 'name="'.$field_name.'[year]" placeholder="'.__('Year').'">';
|
||||||
$html .= static::getYears($block);
|
$html .= static::getYears($block);
|
||||||
@ -84,11 +103,6 @@ class Date extends Base {
|
|||||||
'selected' => null
|
'selected' => null
|
||||||
);
|
);
|
||||||
|
|
||||||
// is default today
|
|
||||||
if(!empty($block['params']['is_default_today'])) {
|
|
||||||
$defaults['selected'] = (int)strftime('%m');
|
|
||||||
}
|
|
||||||
|
|
||||||
// merge block with defaults
|
// merge block with defaults
|
||||||
$block = array_merge($defaults, $block);
|
$block = array_merge($defaults, $block);
|
||||||
|
|
||||||
|
@ -13,9 +13,12 @@ class Radio extends Base {
|
|||||||
|
|
||||||
$html .= static::renderLabel($block);
|
$html .= static::renderLabel($block);
|
||||||
|
|
||||||
$html .= '<span class="mailpoet_error_'.$block['id'].'"></span>';
|
$options = (!empty($block['params']['values'])
|
||||||
|
? $block['params']['values']
|
||||||
|
: array()
|
||||||
|
);
|
||||||
|
|
||||||
foreach($block['params']['values'] as $option) {
|
foreach($options as $option) {
|
||||||
$html .= '<label class="mailpoet_radio_label">';
|
$html .= '<label class="mailpoet_radio_label">';
|
||||||
|
|
||||||
$html .= '<input type="radio" class="mailpoet_radio" ';
|
$html .= '<input type="radio" class="mailpoet_radio" ';
|
||||||
@ -24,15 +27,21 @@ class Radio extends Base {
|
|||||||
|
|
||||||
$html .= 'value="'.esc_attr($option['value']).'" ';
|
$html .= 'value="'.esc_attr($option['value']).'" ';
|
||||||
|
|
||||||
$html .= (isset($option['is_checked']) && $option['is_checked'])
|
$html .= (
|
||||||
? 'checked="checked"' : '';
|
(isset($option['is_checked']) && $option['is_checked'])
|
||||||
|
||
|
||||||
|
(self::getFieldValue($block) === $option['value'])
|
||||||
|
) ? 'checked="checked"' : '';
|
||||||
|
|
||||||
$html .= $field_validation;
|
$html .= $field_validation;
|
||||||
|
|
||||||
$html .= ' /> '.esc_attr($option['value']);
|
$html .= ' /> '.esc_attr($option['value']);
|
||||||
|
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$html .= '<span class="mailpoet_error_'.$block['id'].'"></span>';
|
||||||
|
|
||||||
$html .= '</p>';
|
$html .= '</p>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
@ -13,23 +13,27 @@ class Segment extends Base {
|
|||||||
|
|
||||||
$html .= static::renderLabel($block);
|
$html .= static::renderLabel($block);
|
||||||
|
|
||||||
if(!empty($block['params']['values'])) {
|
$options = (!empty($block['params']['values'])
|
||||||
// display values
|
? $block['params']['values']
|
||||||
foreach($block['params']['values'] as $segment) {
|
: array()
|
||||||
if(!isset($segment['id']) || !isset($segment['name'])) continue;
|
);
|
||||||
|
|
||||||
$is_checked = (isset($segment['is_checked']) && $segment['is_checked']) ? 'checked="checked"' : '';
|
foreach($options as $option) {
|
||||||
|
if(!isset($option['id']) || !isset($option['name'])) continue;
|
||||||
|
|
||||||
$html .= '<label class="mailpoet_checkbox_label">';
|
$is_checked = (isset($option['is_checked']) && $option['is_checked']) ? 'checked="checked"' : '';
|
||||||
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
|
|
||||||
$html .= 'name="'.$field_name.'[]" ';
|
$html .= '<label class="mailpoet_checkbox_label">';
|
||||||
$html .= 'value="'.$segment['id'].'" '.$is_checked.' ';
|
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
|
||||||
$html .= $field_validation;
|
$html .= 'name="'.$field_name.'[]" ';
|
||||||
$html .= ' />'.$segment['name'];
|
$html .= 'value="'.$option['id'].'" '.$is_checked.' ';
|
||||||
$html .= '</label>';
|
$html .= $field_validation;
|
||||||
}
|
$html .= ' /> '.esc_attr($option['name']);
|
||||||
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$html .= '<span class="mailpoet_error_'.$block['id'].'"></span>';
|
||||||
|
|
||||||
$html .= '</p>';
|
$html .= '</p>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
@ -10,9 +10,7 @@ class Select extends Base {
|
|||||||
$field_validation = static::getInputValidation($block);
|
$field_validation = static::getInputValidation($block);
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= static::renderLabel($block);
|
$html .= static::renderLabel($block);
|
||||||
|
|
||||||
$html .= '<select class="mailpoet_select" name="'.$field_name.'">';
|
$html .= '<select class="mailpoet_select" name="'.$field_name.'">';
|
||||||
|
|
||||||
if(isset($block['params']['label_within'])
|
if(isset($block['params']['label_within'])
|
||||||
@ -21,10 +19,22 @@ class Select extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach($block['params']['values'] as $option) {
|
foreach($block['params']['values'] as $option) {
|
||||||
$is_selected = (isset($option['is_checked']) && $option['is_checked'])
|
$is_selected = (
|
||||||
? 'selected="selected"' : '';
|
(isset($option['is_checked']) && $option['is_checked'])
|
||||||
$html .= '<option value="'.$option['value'].'" '.$is_selected.'>';
|
||
|
||||||
$html .= $option['value'];
|
(self::getFieldValue($block) === $option['value'])
|
||||||
|
) ? 'selected="selected"' : '';
|
||||||
|
|
||||||
|
if(is_array($option['value'])) {
|
||||||
|
$value = key($option['value']);
|
||||||
|
$label = reset($option['value']);
|
||||||
|
} else {
|
||||||
|
$value = $option['value'];
|
||||||
|
$label = $option['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '<option value="'.$value.'" '.$is_selected.'>';
|
||||||
|
$html .= esc_attr($label);
|
||||||
$html .= '</option>';
|
$html .= '</option>';
|
||||||
}
|
}
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
|
@ -6,11 +6,11 @@ class Submit extends Base {
|
|||||||
static function render($block) {
|
static function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$html .= '<input class="mailpoet_submit" type="submit" ';
|
$html .= '<p class="mailpoet_submit"><input type="submit" ';
|
||||||
|
|
||||||
$html .= 'value="'.static::getFieldLabel($block).'" ';
|
$html .= 'value="'.static::getFieldLabel($block).'" ';
|
||||||
|
|
||||||
$html .= '/>';
|
$html .= '/></p>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Input extends Base {
|
class Text extends Base {
|
||||||
|
|
||||||
static function render($block) {
|
static function render($block) {
|
||||||
$type = 'text';
|
$type = 'text';
|
||||||
@ -15,7 +15,7 @@ class Input extends Base {
|
|||||||
|
|
||||||
$html .= static::renderLabel($block);
|
$html .= static::renderLabel($block);
|
||||||
|
|
||||||
$html .= '<input type="'.$type.'" class="mailpoet_input" ';
|
$html .= '<input type="'.$type.'" class="mailpoet_text" ';
|
||||||
|
|
||||||
$html .= 'name="'.static::getFieldName($block).'" ';
|
$html .= 'name="'.static::getFieldName($block).'" ';
|
||||||
|
|
@ -13,9 +13,11 @@ class Renderer {
|
|||||||
return $html;
|
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 = '<style type="text/css">';
|
||||||
$html .= static::getStyles($form);
|
$html .= $styles->render($prefix);
|
||||||
$html .= '</style>';
|
$html .= '</style>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
@ -37,8 +39,7 @@ class Renderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private: rendering methods
|
static function renderBlocks($blocks = array()) {
|
||||||
private static function renderBlocks($blocks = array()) {
|
|
||||||
$html = '';
|
$html = '';
|
||||||
foreach ($blocks as $key => $block) {
|
foreach ($blocks as $key => $block) {
|
||||||
$html .= static::renderBlock($block)."\n";
|
$html .= static::renderBlock($block)."\n";
|
||||||
@ -47,9 +48,9 @@ class Renderer {
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function renderBlock($block = array()) {
|
static function renderBlock($block = array()) {
|
||||||
$html = '';
|
$html = '';
|
||||||
switch ($block['type']) {
|
switch($block['type']) {
|
||||||
case 'html':
|
case 'html':
|
||||||
$html .= Block\Html::render($block);
|
$html .= Block\Html::render($block);
|
||||||
break;
|
break;
|
||||||
@ -78,8 +79,8 @@ class Renderer {
|
|||||||
$html .= Block\Select::render($block);
|
$html .= Block\Select::render($block);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'input':
|
case 'text':
|
||||||
$html .= Block\Input::render($block);
|
$html .= Block\Text::render($block);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'textarea':
|
case 'textarea':
|
||||||
|
@ -22,19 +22,21 @@ class Export {
|
|||||||
), site_url());
|
), site_url());
|
||||||
|
|
||||||
// generate iframe
|
// generate iframe
|
||||||
return '<iframe '.
|
return join(' ', array(
|
||||||
'width="100%" '.
|
'<iframe',
|
||||||
'scrolling="no" '.
|
'width="100%"',
|
||||||
'frameborder="0" '.
|
'scrolling="no"',
|
||||||
'src="'.$iframe_url.'" '.
|
'frameborder="0"',
|
||||||
'class="mailpoet_form_iframe" '.
|
'src="'.$iframe_url.'"',
|
||||||
'vspace="0" '.
|
'class="mailpoet_form_iframe"',
|
||||||
'tabindex="0" '.
|
'vspace="0"',
|
||||||
'onload="javascript:(this.style.height = this.contentWindow.document.body.scrollHeight + \'px\');"'.
|
'tabindex="0"',
|
||||||
'marginwidth="0" '.
|
'onload="javascript:(this.style.height = this.contentWindow.document.body.scrollHeight + \'px\');"',
|
||||||
'marginheight="0" '.
|
'marginwidth="0"',
|
||||||
'hspace="0" '.
|
'marginheight="0"',
|
||||||
'allowtransparency="true"></iframe>';
|
'hspace="0"',
|
||||||
|
'allowtransparency="true"></iframe>'
|
||||||
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'php':
|
case 'php':
|
||||||
|
@ -17,7 +17,7 @@ class Styles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* labels */
|
/* labels */
|
||||||
.mailpoet_input_label,
|
.mailpoet_text_label,
|
||||||
.mailpoet_textarea_label,
|
.mailpoet_textarea_label,
|
||||||
.mailpoet_select_label,
|
.mailpoet_select_label,
|
||||||
.mailpoet_radio_label,
|
.mailpoet_radio_label,
|
||||||
@ -28,7 +28,7 @@ class Styles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* inputs */
|
/* inputs */
|
||||||
.mailpoet_input,
|
.mailpoet_text,
|
||||||
.mailpoet_textarea,
|
.mailpoet_textarea,
|
||||||
.mailpoet_select,
|
.mailpoet_select,
|
||||||
.mailpoet_date {
|
.mailpoet_date {
|
||||||
@ -36,9 +36,7 @@ class Styles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mailpoet_checkbox {
|
.mailpoet_checkbox {
|
||||||
display:inline;
|
|
||||||
margin-right: 5px;
|
|
||||||
vertical-align:middle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.mailpoet_validate_success {
|
.mailpoet_validate_success {
|
||||||
@ -101,7 +99,7 @@ EOL;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function stripComments($stylesheet) {
|
private function stripComments($stylesheet) {
|
||||||
// remove comments
|
// remove comments
|
||||||
return preg_replace('!/\*.*?\*/!s', '', $stylesheet);
|
return preg_replace('!/\*.*?\*/!s', '', $stylesheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +109,6 @@ EOL;
|
|||||||
|
|
||||||
private function setStyles($styles) {
|
private function setStyles($styles) {
|
||||||
$this->_styles = $styles;
|
$this->_styles = $styles;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,8 @@ class Widget extends \WP_Widget {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$form_edit_url = admin_url('admin.php?page=mailpoet-form-editor&id=');
|
||||||
|
|
||||||
// set title
|
// set title
|
||||||
$title = isset($instance['title']) ? strip_tags($instance['title']) : '';
|
$title = isset($instance['title']) ? strip_tags($instance['title']) : '';
|
||||||
|
|
||||||
@ -102,8 +104,9 @@ class Widget extends \WP_Widget {
|
|||||||
endpoint: 'forms',
|
endpoint: 'forms',
|
||||||
action: 'create'
|
action: 'create'
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response !== false) {
|
if(response.result && response.form_id) {
|
||||||
window.location = response;
|
window.location =
|
||||||
|
"<?php echo $form_edit_url; ?>" + response.form_id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
@ -151,12 +154,14 @@ class Widget extends \WP_Widget {
|
|||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
if(!empty($body)) {
|
if(!empty($body)) {
|
||||||
|
$form_id = $this->id_base.'_'.$this->number;
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'form_id' => $this->id_base.'_'.$this->number,
|
'form_id' => $form_id,
|
||||||
'form_type' => $form_type,
|
'form_type' => $form_type,
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'styles' => FormRenderer::renderStyles($form),
|
'styles' => FormRenderer::renderStyles($form, '#'.$form_id),
|
||||||
'html' => FormRenderer::renderHTML($form),
|
'html' => FormRenderer::renderHTML($form),
|
||||||
'before_widget' => (!empty($before_widget) ? $before_widget : ''),
|
'before_widget' => (!empty($before_widget) ? $before_widget : ''),
|
||||||
'after_widget' => (!empty($after_widget) ? $after_widget : ''),
|
'after_widget' => (!empty($after_widget) ? $after_widget : ''),
|
||||||
@ -194,96 +199,4 @@ class Widget extends \WP_Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// set the content filter to replace the shortcode
|
|
||||||
if(isset($_GET['mailpoet_page']) && strlen(trim($_GET['mailpoet_page'])) > 0) {
|
|
||||||
switch($_GET['mailpoet_page']) {
|
|
||||||
|
|
||||||
case 'mailpoet_form_iframe':
|
|
||||||
$id = (isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] > 0) ? (int)$_GET['mailpoet_form'] : null;
|
|
||||||
$form = Form::findOne($id);
|
|
||||||
|
|
||||||
if($form !== false) {
|
|
||||||
// render form
|
|
||||||
$output = Util\Export::get('html', $form->asArray());
|
|
||||||
// $output = do_shortcode($output);
|
|
||||||
print $output;
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// add_filter('wp_title', 'mailpoet_meta_page_title'));
|
|
||||||
add_filter('the_title', 'mailpoet_page_title', 10, 2);
|
|
||||||
add_filter('the_content', 'mailpoet_page_content', 98, 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mailpoet_page_title($title = '', $id = null) {
|
|
||||||
// get signup confirmation page id
|
|
||||||
$signup_confirmation = Setting::getValue('signup_confirmation');
|
|
||||||
$page_id = $signup_confirmation['page'];
|
|
||||||
|
|
||||||
// check if we're on the signup confirmation page
|
|
||||||
if((int)$page_id === (int)$id) {
|
|
||||||
global $post;
|
|
||||||
|
|
||||||
// disable comments
|
|
||||||
$post->comment_status = 'close';
|
|
||||||
// disable password
|
|
||||||
$post->post_password = '';
|
|
||||||
|
|
||||||
$subscriber = null;
|
|
||||||
|
|
||||||
// get subscriber key from url
|
|
||||||
$subscriber_digest = (isset($_GET['mailpoet_key']) && strlen(trim($_GET['mailpoet_key'])) === 32) ? trim($_GET['mailpoet_key']) : null;
|
|
||||||
|
|
||||||
if($subscriber_digest !== null) {
|
|
||||||
// get subscriber
|
|
||||||
// TODO: change select() to selectOne() once it's implemented
|
|
||||||
$subscribers = $mailpoet->subscribers()->select(array(
|
|
||||||
'filter' => array(
|
|
||||||
'subscriber_digest' => $subscriber_digest
|
|
||||||
),
|
|
||||||
'limit' => 1
|
|
||||||
));
|
|
||||||
|
|
||||||
if(!empty($subscribers)) {
|
|
||||||
$subscriber = array_shift($subscribers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if we have a subscriber record
|
|
||||||
if($subscriber === null) {
|
|
||||||
return __('Your confirmation link expired, please subscribe again.');
|
|
||||||
} else {
|
|
||||||
// we have a subscriber, let's check its state
|
|
||||||
switch($subscriber['subscriber_state']) {
|
|
||||||
case MailPoetSubscribers::STATE_UNCONFIRMED:
|
|
||||||
case MailPoetSubscribers::STATE_UNSUBSCRIBED:
|
|
||||||
// set subscriber state as confirmed
|
|
||||||
$mailpoet->subscribers()->update(array(
|
|
||||||
'subscriber' => $subscriber['subscriber'],
|
|
||||||
'subscriber_state' => MailPoetSubscribers::STATE_SUBSCRIBED,
|
|
||||||
'subscriber_confirmed_at' => time()
|
|
||||||
));
|
|
||||||
return __("You've subscribed");
|
|
||||||
break;
|
|
||||||
case MailPoetSubscribers::STATE_SUBSCRIBED:
|
|
||||||
return __("You've already subscribed");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $title;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mailpoet_page_content($content = '') {
|
|
||||||
if(strpos($content, '[mailpoet_page]') !== FALSE) {
|
|
||||||
$content = str_replace('[mailpoet_page]', '', $content);
|
|
||||||
}
|
|
||||||
return $content;
|
|
||||||
}
|
}
|
@ -4,6 +4,8 @@ namespace MailPoet\Listing;
|
|||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Handler {
|
class Handler {
|
||||||
|
const DEFAULT_LIMIT_PER_PAGE = 20;
|
||||||
|
|
||||||
private $data = array();
|
private $data = array();
|
||||||
private $model = null;
|
private $model = null;
|
||||||
|
|
||||||
@ -14,7 +16,10 @@ class Handler {
|
|||||||
$this->data = array(
|
$this->data = array(
|
||||||
// pagination
|
// pagination
|
||||||
'offset' => (isset($data['offset']) ? (int)$data['offset'] : 0),
|
'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
|
// searching
|
||||||
'search' => (isset($data['search']) ? $data['search'] : null),
|
'search' => (isset($data['search']) ? $data['search'] : null),
|
||||||
// sorting
|
// sorting
|
||||||
@ -84,11 +89,11 @@ class Handler {
|
|||||||
$items = $this->model
|
$items = $this->model
|
||||||
->offset($this->data['offset'])
|
->offset($this->data['offset'])
|
||||||
->limit($this->data['limit'])
|
->limit($this->data['limit'])
|
||||||
->findArray();
|
->findMany();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
'filters' => $this->model->filter('filters'),
|
'filters' => $this->model->filter('filters', $this->data['group']),
|
||||||
'groups' => $this->model->filter('groups'),
|
'groups' => $this->model->filter('groups'),
|
||||||
'items' => $items
|
'items' => $items
|
||||||
);
|
);
|
||||||
|
@ -19,82 +19,77 @@ class Mailer {
|
|||||||
$this->reply_to = $this->getReplyTo($reply_to);
|
$this->reply_to = $this->getReplyTo($reply_to);
|
||||||
$this->mailer_instance = $this->buildMailer();
|
$this->mailer_instance = $this->buildMailer();
|
||||||
}
|
}
|
||||||
|
|
||||||
function send($newsletter, $subscriber) {
|
function send($newsletter, $subscriber) {
|
||||||
$subscriber = $this->transformSubscriber($subscriber);
|
$subscriber = $this->transformSubscriber($subscriber);
|
||||||
return $this->mailer_instance->send($newsletter, $subscriber);
|
return $this->mailer_instance->send($newsletter, $subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMailer() {
|
function buildMailer() {
|
||||||
switch($this->mailer['method']) {
|
switch($this->mailer['method']) {
|
||||||
case 'AmazonSES':
|
case 'AmazonSES':
|
||||||
$mailer_instance = new $this->mailer['class'](
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->mailer['region'],
|
$this->mailer['region'],
|
||||||
$this->mailer['access_key'],
|
$this->mailer['access_key'],
|
||||||
$this->mailer['secret_key'],
|
$this->mailer['secret_key'],
|
||||||
$this->sender['from_name_email']
|
$this->sender,
|
||||||
);
|
$this->reply_to
|
||||||
break;
|
);
|
||||||
case 'ElasticEmail':
|
break;
|
||||||
$mailer_instance = new $this->mailer['class'](
|
case 'ElasticEmail':
|
||||||
$this->mailer['api_key'],
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->sender['from_email'],
|
$this->mailer['api_key'],
|
||||||
$this->sender['from_name']
|
$this->sender,
|
||||||
);
|
$this->reply_to
|
||||||
break;
|
);
|
||||||
case 'MailGun':
|
break;
|
||||||
$mailer_instance = new $this->mailer['class'](
|
case 'MailGun':
|
||||||
$this->mailer['domain'],
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->mailer['api_key'],
|
$this->mailer['domain'],
|
||||||
$this->sender['from_name_email']
|
$this->mailer['api_key'],
|
||||||
);
|
$this->sender,
|
||||||
break;
|
$this->reply_to
|
||||||
case 'MailPoet':
|
);
|
||||||
$mailer_instance = new $this->mailer['class'](
|
break;
|
||||||
$this->mailer['mailpoet_api_key'],
|
case 'MailPoet':
|
||||||
$this->sender['from_email'],
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->sender['from_name']
|
$this->mailer['mailpoet_api_key'],
|
||||||
);
|
$this->sender,
|
||||||
break;
|
$this->reply_to
|
||||||
case 'Mandrill':
|
);
|
||||||
$mailer_instance = new $this->mailer['class'](
|
break;
|
||||||
$this->mailer['api_key'],
|
case 'SendGrid':
|
||||||
$this->sender['from_email'],
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->sender['from_name']
|
$this->mailer['api_key'],
|
||||||
);
|
$this->sender,
|
||||||
break;
|
$this->reply_to
|
||||||
case 'SendGrid':
|
);
|
||||||
$mailer_instance = new $this->mailer['class'](
|
break;
|
||||||
$this->mailer['api_key'],
|
case 'PHPMail':
|
||||||
$this->sender['from_email'],
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->sender['from_name']
|
$this->sender,
|
||||||
);
|
$this->reply_to
|
||||||
break;
|
);
|
||||||
case 'WPMail':
|
break;
|
||||||
$mailer_instance = new $this->mailer['class'](
|
case 'SMTP':
|
||||||
$this->sender['from_email'],
|
$mailer_instance = new $this->mailer['class'](
|
||||||
$this->sender['from_name']
|
$this->mailer['host'],
|
||||||
);
|
$this->mailer['port'],
|
||||||
break;
|
$this->mailer['authentication'],
|
||||||
case 'SMTP':
|
$this->mailer['login'],
|
||||||
$mailer_instance = new $this->mailer['class'](
|
$this->mailer['password'],
|
||||||
$this->mailer['host'],
|
$this->mailer['encryption'],
|
||||||
$this->mailer['port'],
|
$this->sender,
|
||||||
$this->mailer['authentication'],
|
$this->reply_to
|
||||||
$this->mailer['login'],
|
);
|
||||||
$this->mailer['password'],
|
break;
|
||||||
$this->mailer['encryption'],
|
default:
|
||||||
$this->sender['from_email'],
|
throw new \Exception(__('Mailing method does not exist.'));
|
||||||
$this->sender['from_name']
|
break;
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new \Exception(__('Mailing method does not exist.'));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return $mailer_instance;
|
return $mailer_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMailer($mailer = false) {
|
function getMailer($mailer = false) {
|
||||||
if(!$mailer) {
|
if(!$mailer) {
|
||||||
$mailer = Setting::getValue('mta', null);
|
$mailer = Setting::getValue('mta', null);
|
||||||
@ -107,7 +102,7 @@ class Mailer {
|
|||||||
function getSender($sender = false) {
|
function getSender($sender = false) {
|
||||||
if(!$sender) {
|
if(!$sender) {
|
||||||
$sender = Setting::getValue('sender', null);
|
$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(
|
return array(
|
||||||
'from_name' => $sender['name'],
|
'from_name' => $sender['name'],
|
||||||
@ -126,6 +121,9 @@ class Mailer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!$reply_to['address']) {
|
||||||
|
$reply_to['address'] = $this->sender['from_email'];
|
||||||
|
}
|
||||||
return array(
|
return array(
|
||||||
'reply_to_name' => $reply_to['name'],
|
'reply_to_name' => $reply_to['name'],
|
||||||
'reply_to_email' => $reply_to['address'],
|
'reply_to_email' => $reply_to['address'],
|
||||||
|
@ -13,25 +13,27 @@ class AmazonSES {
|
|||||||
public $aws_termination_string;
|
public $aws_termination_string;
|
||||||
public $hash_algorithm;
|
public $hash_algorithm;
|
||||||
public $url;
|
public $url;
|
||||||
public $from;
|
public $sender;
|
||||||
|
public $reply_to;
|
||||||
public $date;
|
public $date;
|
||||||
public $date_without_time;
|
public $date_without_time;
|
||||||
|
|
||||||
function __construct($region, $access_key, $secret_key, $from) {
|
function __construct($region, $access_key, $secret_key, $sender, $reply_to) {
|
||||||
$this->aws_access_key = $access_key;
|
$this->aws_access_key = $access_key;
|
||||||
$this->aws_secret_key = $secret_key;
|
$this->aws_secret_key = $secret_key;
|
||||||
$this->aws_region = $region;
|
$this->aws_region = $region;
|
||||||
$this->aws_endpoint = sprintf('email.%s.amazonaws.com', $region);
|
$this->aws_endpoint = sprintf('email.%s.amazonaws.com', $this->aws_region);
|
||||||
$this->aws_signing_algorithm = 'AWS4-HMAC-SHA256';
|
$this->aws_signing_algorithm = 'AWS4-HMAC-SHA256';
|
||||||
$this->aws_service = 'ses';
|
$this->aws_service = 'ses';
|
||||||
$this->aws_termination_string = 'aws4_request';
|
$this->aws_termination_string = 'aws4_request';
|
||||||
$this->hash_algorithm = 'sha256';
|
$this->hash_algorithm = 'sha256';
|
||||||
$this->url = 'https://' . $this->aws_endpoint;
|
$this->url = 'https://' . $this->aws_endpoint;
|
||||||
$this->from = $from;
|
$this->sender = $sender;
|
||||||
|
$this->reply_to = $reply_to;
|
||||||
$this->date = gmdate('Ymd\THis\Z');
|
$this->date = gmdate('Ymd\THis\Z');
|
||||||
$this->date_without_time = gmdate('Ymd');
|
$this->date_without_time = gmdate('Ymd');
|
||||||
}
|
}
|
||||||
|
|
||||||
function send($newsletter, $subscriber) {
|
function send($newsletter, $subscriber) {
|
||||||
$result = wp_remote_post(
|
$result = wp_remote_post(
|
||||||
$this->url,
|
$this->url,
|
||||||
@ -42,15 +44,16 @@ class AmazonSES {
|
|||||||
wp_remote_retrieve_response_code($result) === 200
|
wp_remote_retrieve_response_code($result) === 200
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBody($newsletter, $subscriber) {
|
function getBody($newsletter, $subscriber) {
|
||||||
$body = array(
|
$body = array(
|
||||||
'Action' => 'SendEmail',
|
'Action' => 'SendEmail',
|
||||||
'Version' => '2010-12-01',
|
'Version' => '2010-12-01',
|
||||||
'Source' => $this->from,
|
|
||||||
'Destination.ToAddresses.member.1' => $subscriber,
|
'Destination.ToAddresses.member.1' => $subscriber,
|
||||||
|
'Source' => $this->sender['from_name_email'],
|
||||||
|
'ReplyToAddresses.member.1' => $this->reply_to['reply_to_name_email'],
|
||||||
'Message.Subject.Data' => $newsletter['subject'],
|
'Message.Subject.Data' => $newsletter['subject'],
|
||||||
'ReturnPath' => $this->from
|
'ReturnPath' => $this->sender['from_name_email'],
|
||||||
);
|
);
|
||||||
if(!empty($newsletter['body']['html'])) {
|
if(!empty($newsletter['body']['html'])) {
|
||||||
$body['Message.Body.Html.Data'] = $newsletter['body']['html'];
|
$body['Message.Body.Html.Data'] = $newsletter['body']['html'];
|
||||||
@ -60,7 +63,7 @@ class AmazonSES {
|
|||||||
}
|
}
|
||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
function request($newsletter, $subscriber) {
|
function request($newsletter, $subscriber) {
|
||||||
$body = $this->getBody($newsletter, $subscriber);
|
$body = $this->getBody($newsletter, $subscriber);
|
||||||
return array(
|
return array(
|
||||||
@ -75,7 +78,7 @@ class AmazonSES {
|
|||||||
'body' => urldecode(http_build_query($body))
|
'body' => urldecode(http_build_query($body))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function signRequest($body) {
|
function signRequest($body) {
|
||||||
$string_to_sign = $this->createStringToSign(
|
$string_to_sign = $this->createStringToSign(
|
||||||
$this->getCredentialScope(),
|
$this->getCredentialScope(),
|
||||||
@ -86,7 +89,7 @@ class AmazonSES {
|
|||||||
$string_to_sign,
|
$string_to_sign,
|
||||||
$this->getSigningKey()
|
$this->getSigningKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%s Credential=%s/%s, SignedHeaders=host;x-amz-date, Signature=%s',
|
'%s Credential=%s/%s, SignedHeaders=host;x-amz-date, Signature=%s',
|
||||||
$this->aws_signing_algorithm,
|
$this->aws_signing_algorithm,
|
||||||
@ -94,7 +97,7 @@ class AmazonSES {
|
|||||||
$this->getCredentialScope(),
|
$this->getCredentialScope(),
|
||||||
$signature);
|
$signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCredentialScope() {
|
function getCredentialScope() {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%s/%s/%s/%s',
|
'%s/%s/%s/%s',
|
||||||
@ -103,7 +106,7 @@ class AmazonSES {
|
|||||||
$this->aws_service,
|
$this->aws_service,
|
||||||
$this->aws_termination_string);
|
$this->aws_termination_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCanonicalRequest($body) {
|
function getCanonicalRequest($body) {
|
||||||
return implode("\n", array(
|
return implode("\n", array(
|
||||||
'POST',
|
'POST',
|
||||||
@ -116,7 +119,7 @@ class AmazonSES {
|
|||||||
hash($this->hash_algorithm, urldecode(http_build_query($body)))
|
hash($this->hash_algorithm, urldecode(http_build_query($body)))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStringToSign($credential_scope, $canonical_request) {
|
function createStringToSign($credential_scope, $canonical_request) {
|
||||||
return implode("\n", array(
|
return implode("\n", array(
|
||||||
$this->aws_signing_algorithm,
|
$this->aws_signing_algorithm,
|
||||||
@ -125,7 +128,7 @@ class AmazonSES {
|
|||||||
hash($this->hash_algorithm, $canonical_request)
|
hash($this->hash_algorithm, $canonical_request)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSigningKey() {
|
function getSigningKey() {
|
||||||
$date_key = hash_hmac(
|
$date_key = hash_hmac(
|
||||||
$this->hash_algorithm,
|
$this->hash_algorithm,
|
||||||
|
@ -6,13 +6,13 @@ if(!defined('ABSPATH')) exit;
|
|||||||
class ElasticEmail {
|
class ElasticEmail {
|
||||||
public $url = 'https://api.elasticemail.com/mailer/send';
|
public $url = 'https://api.elasticemail.com/mailer/send';
|
||||||
public $api_key;
|
public $api_key;
|
||||||
public $from_email;
|
public $sender;
|
||||||
public $from_name;
|
public $reply_to;
|
||||||
|
|
||||||
function __construct($api_key, $from_email, $from_name) {
|
function __construct($api_key, $sender, $reply_to) {
|
||||||
$this->api_key = $api_key;
|
$this->api_key = $api_key;
|
||||||
$this->from_email = $from_email;
|
$this->sender = $sender;
|
||||||
$this->from_name = $from_name;
|
$this->reply_to = $reply_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send($newsletter, $subscriber) {
|
function send($newsletter, $subscriber) {
|
||||||
@ -28,9 +28,11 @@ class ElasticEmail {
|
|||||||
function getBody($newsletter, $subscriber) {
|
function getBody($newsletter, $subscriber) {
|
||||||
$body = array(
|
$body = array(
|
||||||
'api_key' => $this->api_key,
|
'api_key' => $this->api_key,
|
||||||
'from' => $this->from_email,
|
|
||||||
'from_name' => $this->from_name,
|
|
||||||
'to' => $subscriber,
|
'to' => $subscriber,
|
||||||
|
'from' => $this->sender['from_email'],
|
||||||
|
'from_name' => $this->sender['from_name'],
|
||||||
|
'reply_to' => $this->reply_to['reply_to_email'],
|
||||||
|
'reply_to_name' => $this->reply_to['reply_to_name'],
|
||||||
'subject' => $newsletter['subject']
|
'subject' => $newsletter['subject']
|
||||||
);
|
);
|
||||||
if(!empty($newsletter['body']['html'])) {
|
if(!empty($newsletter['body']['html'])) {
|
||||||
|
@ -6,12 +6,14 @@ if(!defined('ABSPATH')) exit;
|
|||||||
class MailGun {
|
class MailGun {
|
||||||
public $url;
|
public $url;
|
||||||
public $api_key;
|
public $api_key;
|
||||||
public $from;
|
public $sender;
|
||||||
|
public $reply_to;
|
||||||
function __construct($domain, $api_key, $from) {
|
|
||||||
|
function __construct($domain, $api_key, $sender, $reply_to) {
|
||||||
$this->url = sprintf('https://api.mailgun.net/v3/%s/messages', $domain);
|
$this->url = sprintf('https://api.mailgun.net/v3/%s/messages', $domain);
|
||||||
$this->api_key = $api_key;
|
$this->api_key = $api_key;
|
||||||
$this->from = $from;
|
$this->sender = $sender;
|
||||||
|
$this->reply_to = $reply_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send($newsletter, $subscriber) {
|
function send($newsletter, $subscriber) {
|
||||||
@ -27,8 +29,9 @@ class MailGun {
|
|||||||
|
|
||||||
function getBody($newsletter, $subscriber) {
|
function getBody($newsletter, $subscriber) {
|
||||||
$body = array(
|
$body = array(
|
||||||
'from' => $this->from,
|
|
||||||
'to' => $subscriber,
|
'to' => $subscriber,
|
||||||
|
'from' => $this->sender['from_name_email'],
|
||||||
|
'h:Reply-To' => $this->reply_to['reply_to_name_email'],
|
||||||
'subject' => $newsletter['subject']
|
'subject' => $newsletter['subject']
|
||||||
);
|
);
|
||||||
if(!empty($newsletter['body']['html'])) {
|
if(!empty($newsletter['body']['html'])) {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user