Compare commits

...

181 Commits
0.0.2 ... 0.0.7

Author SHA1 Message Date
c0ba218949 Merge branch 'master' of github.com:mailpoet/mailpoet 2015-12-04 21:41:29 +01:00
ee85139089 Merge pull request #254 from mailpoet/queue
Sending Queue: start & track
2015-12-04 21:36:50 +01:00
b4f83fe1bd Merge pull request #257 from mailpoet/image_size
Custom newsletter image size
2015-12-04 21:22:15 +01:00
bd83001ef5 Merge pull request #258 from mailpoet/helpscout
HelpScout integration fixes
2015-12-04 21:20:28 +01:00
fb3a9f485f Merge pull request #259 from mailpoet/custom_fields
Add custom fields to newsletter editor
2015-12-04 21:20:09 +01:00
fd44776ae9 - Fixes SMTP issue 2015-12-04 14:33:43 -05:00
6dbe338b01 - Updates mailers to use HTML and/or TEXT body 2015-12-04 14:06:43 -05:00
1f06a7dd0b fixed naming of sending_queue & added validation of segments on step 3 2015-12-04 19:54:31 +01:00
37c218f782 fixed sending test email text version only 2015-12-04 19:46:44 +01:00
25016f2a8d test sending method works 2015-12-04 19:28:00 +01:00
792744a270 - Implements check for name/email in mailer router 2015-12-04 12:47:14 -05:00
c5fbfca132 Merge branch 'queue' of mailpoet:mailpoet/mailpoet into queue 2015-12-04 12:32:38 -05:00
c2fde308cb - Renames and updates sending queue worker
- Updates mailer router's send() method
2015-12-04 12:31:54 -05:00
533d9b0d38 Change custom field shortcode to follow MP2 format 2015-12-04 17:48:35 +02:00
2035b802e3 Add shortcodes for custom fields to newsletter editor 2015-12-04 17:47:18 +02:00
a5e66ec6a0 implemented sending test email 2015-12-04 16:20:07 +01:00
beb939df9e updated send with tab 2015-12-04 15:31:04 +01:00
44e342c692 Fix z-index, change icon, add instructional message 2015-12-04 15:30:59 +02:00
3a417d460f Add custom MailPoet image size for newsletters 2015-12-04 14:37:05 +02:00
1950d6661f Step 3 sender and reply to per newsletter
- added sender_address/sender_name/reply_to_address/reply_to_name
- added validation on all form fields (except checkbox and radio)
2015-12-04 12:29:11 +01:00
da6e154642 fixed conflicts 2015-12-04 11:25:06 +01:00
acebf669a7 - Updates queue worker to use mailer router for sending
- Updates mailer router to detect method type
- Rebases master
2015-12-03 22:01:33 -05:00
4a2bbe3f88 Sending Progress
- improved progress bar styles (with completed status)
- add pause/resume buttons
- fixed method case in settings.mta for MailPoet & SMTP Providers
- fixed parsley dependency
- added validation on from name & address on step 3
2015-12-03 22:01:19 -05:00
9b011c0281 - Places supervisor/daemon/worker under the new Cron class
- Updates endpoints
- Integrates queue worker with MailPoet mailer
- Fixes script activation check logic
2015-12-03 22:01:18 -05:00
bf58d8a22d Queue
- updated menu icon for our plugin
- added watchCss command to watch only CSS files
- added Status column in Newsletters listing
- added progress bar styles
- fixed issue with JS assets being loaded twice on non MP pages
- changed subscriber_ids to segment_ids in addQueue
2015-12-03 22:01:17 -05:00
72d1eb79a6 fixed too much recursion issue on selection JSX 2015-12-03 22:01:17 -05:00
bb4893c0a0 added missing messages on newsletter form 2015-12-03 22:01:16 -05:00
9929cf0aee - Adds router methods to add/delete/et queue status 2015-12-03 22:01:15 -05:00
83967e84ba - Implements starting/stopping/pausing daemon 2015-12-03 22:01:15 -05:00
9621cb3ca9 Merge pull request #253 from mailpoet/animations
Editor: Animations
2015-12-03 22:48:43 +01:00
a413f666fe Sending Progress
- improved progress bar styles (with completed status)
- add pause/resume buttons
- fixed method case in settings.mta for MailPoet & SMTP Providers
- fixed parsley dependency
- added validation on from name & address on step 3
2015-12-03 18:26:36 +01:00
d1e2c6c074 Add transition for "Delete block" icon 2015-12-03 15:53:56 +02:00
3b6a9f7a6e Add block, tool and widget transition animations 2015-12-03 14:44:32 +02:00
d2e5fb89c2 - Places supervisor/daemon/worker under the new Cron class
- Updates endpoints
- Integrates queue worker with MailPoet mailer
- Fixes script activation check logic
2015-12-02 22:48:15 -05:00
97d1e95037 Add transitions for content block addition and removal 2015-12-02 17:54:06 +02:00
48fbce22e7 Queue
- updated menu icon for our plugin
- added watchCss command to watch only CSS files
- added Status column in Newsletters listing
- added progress bar styles
- fixed issue with JS assets being loaded twice on non MP pages
- changed subscriber_ids to segment_ids in addQueue
2015-12-02 12:25:28 +01:00
916fe76795 Add transitions: sidebar contents, template preview, sidebar 2015-12-01 16:49:50 +02:00
e10310fb5c fixed too much recursion issue on selection JSX 2015-12-01 13:50:35 +01:00
367afcf814 added missing messages on newsletter form 2015-12-01 13:01:06 +01:00
67fa9e0993 - Adds router methods to add/delete/et queue status 2015-11-30 19:09:06 -05:00
d7553a5f27 Merge pull request #251 from mailpoet/newsletter_templates
Editor: Add two sample templates
2015-11-30 21:13:49 +01:00
8c847825fa - Implements starting/stopping/pausing daemon 2015-11-30 13:01:07 -05:00
d21d9b99b0 Add an option for certain templates to be read only 2015-11-30 18:23:43 +02:00
8461c13532 Include thumbnail on saved templates, add another sample template 2015-11-30 18:05:10 +02:00
3b7ffe9ba7 Update Marionette to 2.4.4 from 2.4.3 2015-11-30 13:21:28 +02:00
1724fa22c1 Merge pull request #250 from mailpoet/default_data_on_install
Default segments on install
2015-11-30 12:17:32 +01:00
01089d7a72 Bump version to 0.0.6 2015-11-27 22:00:54 +01:00
717ebfd20c Bump composer lockfile. 2015-11-27 22:00:17 +01:00
daff3d5016 Merge pull request #249 from mailpoet/sticky_kit_fix
Add back sticky-kit dependency
2015-11-27 19:14:03 +01:00
98fb838169 updated default lists' descriptions 2015-11-27 15:56:18 +01:00
f13a4dd4f3 Add back sticky-kit dependency 2015-11-27 16:44:04 +02:00
62a164e4c6 added creation of WP Users & default list on install 2015-11-27 15:27:50 +01:00
04238f3339 Phoenix Vagrant VM has been replaced with a new VM with test data. 2015-11-27 15:16:06 +01:00
bc62474f3c Merge pull request #240 from mailpoet/queue
Queue
2015-11-27 13:49:18 +01:00
98005a2a6f - Rebases master 2015-11-27 07:46:26 -05:00
b7fe8dc6d6 - Adds Daemon status (under Mailpoet->Queue) 2015-11-27 07:40:23 -05:00
436faea591 - Refactors and renames code
- Adds Queue menu option and displays status
2015-11-27 07:40:22 -05:00
4208b148b4 - Implements queue worker class 2015-11-27 07:35:16 -05:00
5ce5f0bf8a - Refactors code 2015-11-27 07:35:16 -05:00
18518de397 - Refactors some code 2015-11-27 07:35:15 -05:00
68f747211a - Adds a helper method to convert cameCase to under_score
- Removes unused method from Queue daemon
2015-11-27 07:35:15 -05:00
ebd26ddd98 - Silences fsockopen errors 2015-11-27 07:35:14 -05:00
924aa0439f - Minor regex changes
- Adds method to Env class that returns plugin activation status
- Prevents Supervisor from running if the plugin isn't activated
2015-11-27 07:35:13 -05:00
3124d6a61b - Fixes issue with ucwords() function on older PHP versions
- Updates Supervisor/Daemon to strip port from site_url() when it's
  running on localhost inside a virtual machine :)
2015-11-27 07:35:13 -05:00
149d031b52 - Adds session support
- Renames Queue to Daemon
- Updates router methods
2015-11-27 07:35:12 -05:00
fa96c4697d - Adds Queue router
- Updates logic for Queue and Supervisor
- #227
2015-11-27 07:35:12 -05:00
d46c9d5412 - Fixes issue with Supervisor when database tables do not exist 2015-11-27 07:35:11 -05:00
9ab8b1f0c5 added loading on wp users sync 2015-11-27 12:57:52 +01:00
9425ac1593 Merge pull request #244 from mailpoet/wp_users_segment
WP Users segment
2015-11-27 11:39:08 +01:00
4e32479609 Merge pull request #246 from mailpoet/import-fixes
Fixes import issues and updates code
2015-11-27 09:30:19 +01:00
7d95b38dc4 - Renames/refactors Import and Export classes/views/JS
- Updates Import and Export to ignore trashed subscribers
- Updates tests
Closes #245
2015-11-26 20:48:19 -05:00
17c83c5bd4 Merge pull request #242 from mailpoet/newsletter_templates
Newsletter template thumbnails
2015-11-26 21:26:23 +01:00
23bb2f111f Add a sample translatable template 2015-11-26 17:21:10 +02:00
4655b2c64c Switch template thumbnails to be generated in jpeg, not png 2015-11-26 17:20:34 +02:00
84fede11b8 removed dynamic lists from import 2015-11-26 16:02:53 +01:00
f37488fc0b Adds a Preview icon for previewing newsletter templates 2015-11-26 13:09:08 +02:00
20e2e03982 Hide non default segments on some pages
- added getPublic() method on Segment model
- filter out dynamic lists from add/move/remove segment in subscribers
2015-11-26 11:32:10 +01:00
a5d96f1534 WP Users list
- refactored and fixed listing issues (related to Segments)
- removed bulk actions from segments
- added synchronize methods for WP users
- Update action in segments only for WP Users list
- added "type" column to segments (default, wp_users, dynamic...)
- added "status" column to subscriber_segment table (useful soon)
2015-11-25 18:31:57 +01:00
a516eb1a95 Add overlay and newsletter thumbnail preview 2015-11-25 16:44:18 +02:00
6dd8270bec WP Users list
- migration for filters & segment_filter tables
- models for new tables
- update of Listing JSX to allow for conditional display of item actions
2015-11-24 17:12:14 +01:00
981cbd579f Fix clickable labels for editor settings views 2015-11-24 16:51:27 +02:00
52a0aae10f Add template thumbnail generation and display 2015-11-24 16:50:57 +02:00
ebca4257a6 Version bump: 0.0.5 2015-11-21 00:39:11 +01:00
c3944095bc Install npm deps in build command. 2015-11-21 00:36:12 +01:00
a1445d1b6a Vagrant Container and new build process. 2015-11-21 00:28:33 +01:00
e62c24879b Merge pull request #239 from mailpoet/revert-238-queue
Revert "Queue"
2015-11-20 23:51:19 +01:00
00f06ea202 Revert "Queue" 2015-11-20 23:51:02 +01:00
32ca24ce38 Merge pull request #238 from mailpoet/queue
Queue
2015-11-20 23:02:30 +01:00
44e3adb422 Merge pull request #235 from mailpoet/alc
Editor: ALC fixes
2015-11-20 23:00:47 +01:00
a1346ebecc Merge pull request #237 from mailpoet/changelog
welcome/update pages display logic
2015-11-20 23:00:30 +01:00
25b51d0446 - Adds queue management and supervisor. Issue #227 2015-11-20 16:20:54 -05:00
556a170903 - Bootstraps queue 2015-11-20 16:20:35 -05:00
7ac386a8e2 fixed welcome/update pages display logic 2015-11-20 13:37:52 +01:00
d91b55ec52 Include static sticky-kit library, patch it, fix sticky editor sidebar 2015-11-20 14:16:51 +02:00
786fbc36a2 Change post types to plural labels, move Posts/ALC UI elements 2015-11-19 19:08:48 +02:00
160e8b7a12 Merge pull request #232 from mailpoet/export-rename
Rename BootstrapMenu.php to BootStrapMenu.php
2015-11-19 15:01:24 +01:00
0b1f85da09 Rename BootstrapMenu.php to BootStrapMenu.php
- Renames BootStrapMenu class to use proper camelCase
2015-11-19 08:57:37 -05:00
fbc6f54ddc Merge pull request #230 from mailpoet/export
Export
2015-11-19 10:35:27 +01:00
a603e97b8c Merge pull request #229 from mailpoet/editor_posts
Editor: Posts widget
2015-11-19 10:31:31 +01:00
0875b627b6 Merge pull request #231 from mailpoet/newsletters_select_all_fix
fixed missing messages in newsletters listing
2015-11-19 10:27:45 +01:00
035784ece0 fixed missing messages in newsletters listing 2015-11-19 10:24:27 +01:00
aa93c7349f - Rebases master
- Adds tests for all Export class methods
Closes #221
2015-11-18 22:14:48 -05:00
82cf4a28fd - Updates export tests 2015-11-18 14:42:28 -05:00
832e5ef342 - Fixed minor import issue wrt to status not being set 2015-11-18 14:42:27 -05:00
e3de3a123a - Corrects exported subscriber count
- Properly exports subscribers not in any list
- Adds test for export class constructor method
Resolves #221
2015-11-18 14:42:27 -05:00
db91590159 Merge pull request #228 from mailpoet/welcome_redirect
Welcome page redirection
2015-11-18 14:33:48 +01:00
28c61fca0b Newsletters listing
- fixed listing actions on newsletters
2015-11-18 14:04:34 +01:00
e62a8c2ec5 Implement Becs' changes to Posts widget and post rendering 2015-11-18 14:44:57 +02:00
fdbd1245e3 Redirect to welcome or update page 2015-11-17 20:11:03 +01:00
0eef46db57 Fix post transformation to take titleIsLink option into account 2015-11-17 16:55:55 +02:00
080ae88a04 Fix Posts block tests 2015-11-17 16:31:57 +02:00
225be9f3cd Starting welcome page redirection 2015-11-17 13:43:25 +01:00
c9a42ebb76 Add auto-refresh of Posts block contents on option change 2015-11-17 14:40:39 +02:00
ae9b3df92d Merge pull request #223 from mailpoet/build
Fix JS lib inclusion in build step
2015-11-16 13:38:33 +01:00
63a08ebb55 Fix inclusion of js/lib/tinymce by disabling removal of node_modules/ 2015-11-16 14:27:29 +02:00
2ef5096fa9 Optimize symlinks when building. 2015-11-13 23:55:24 +01:00
95cfe2d8ec Version bump: 0.0.4. 2015-11-13 19:57:22 +01:00
49676b3fc5 Merge pull request #219 from mailpoet/export
Export
2015-11-13 18:49:32 +01:00
c96ac06423 - Moves ImportExport under Subscribers namespace
- Updates tests
2015-11-13 12:46:54 -05:00
6a3166c311 - Implements export
Closes #210
2015-11-13 12:25:33 -05:00
0017df1c2d - Work-in-progress on the UI 2015-11-13 12:25:32 -05:00
f2a0d4ce96 fixed wrong count value onGetItems in Listing 2015-11-13 12:25:32 -05:00
cb50517cbc toggle Export button depending on subscribers count 2015-11-13 12:25:31 -05:00
0fedd1779f - Moves Import and Export under ImportExport namespace
- Cretes a single BootStrapMenu class for Import and Export
- Updates tests
- Adds 2 new methods to Segments model
2015-11-13 12:25:31 -05:00
1625e1771b - Bootstraps export 2015-11-13 12:25:30 -05:00
bde78b607b Merge pull request #218 from mailpoet/listings_bugfix
Listings bugfixes & Welcome page
2015-11-13 16:01:23 +01:00
f3c58c27be set welcome page as default page 2015-11-13 15:58:36 +01:00
9fec460295 Merge pull request #220 from mailpoet/helpscout_beacon
Adds a HelpScout beacon to admin pages
2015-11-13 15:23:03 +01:00
162859529e reinstated removed tests 2015-11-13 13:56:59 +01:00
3bdaaf8368 Add a HelpScout beacon to admin pages 2015-11-13 14:45:25 +02:00
f6ab0050b2 added welcome page 2015-11-13 12:59:49 +01:00
10a20935c3 cleanup tests 2015-11-12 14:11:27 +01:00
8135b677f7 Merge pull request #216 from mailpoet/editor_layouts
Add layout settings to newsletter editor
2015-11-12 14:04:04 +01:00
90382bc86d Add layout block bg color, remove bg colors of individual columns 2015-11-11 16:55:44 +02:00
47af8939cc Merge pull request #214 from mailpoet/editor_images
Editor small image handling
2015-11-11 09:32:32 +01:00
4a0deb2182 Preserve image width for smaller than column width images 2015-11-10 18:09:36 +02:00
3a206b2c88 Adapt newsletter template selection to API change 2015-11-10 18:08:16 +02:00
70cfcbe7cc Merge pull request #209 from mailpoet/mixpanel
Add MixPanel analytics tracking
2015-11-10 10:41:24 +01:00
6342cb17bd Merge pull request #208 from mailpoet/listing_tests
Listings
2015-11-10 10:39:53 +01:00
64c35b12c8 Merge pull request #191 from mailpoet/import
Import
2015-11-09 23:23:08 +01:00
6a14f97419 Fix select2 results z-index issue for newsletter editor 2015-11-09 18:17:10 +02:00
dfec34eda9 Add Analytics integration with MixPanel 2015-11-09 18:11:06 +02:00
893231e8e5 List selection fix 2015-11-09 14:19:59 +01:00
e9110680ee Listings
- fixed selection field JSX
- fixed bulk actions (added filter function)
- added getPublished/getTrashed static methods on Model
- fixed step 3 of newsletter process
- updated save/get methods of all listing-able models to conform with the new norm
2015-11-09 13:26:33 +01:00
7b54285ca6 - Adds tests for the main Import class
- Updates tests for Env (proper host detection with port)
- Improves import
2015-11-09 00:25:24 -05:00
33ea16eb0f - Cleans up import
- Adds tests for modified models
- Adds tests for import BootStrapMenu and MailChimp classes
2015-11-08 15:57:43 -05:00
b1ae07d38e - Rebased master
- Cleaned up import & moved it under Subscribers menu
2015-11-07 21:16:38 -05:00
3f168d052f - Finishes import migration
- Updates models
- Improves Notice.js
2015-11-07 11:40:42 -05:00
158d26ef86 - Adds import's step 1 method selection logic 2015-11-07 11:31:40 -05:00
ae03ee2c46 - Bootstrapping import menu 2015-11-07 11:25:05 -05:00
ad0adb48e1 - Updates Migrator with new column for Segments
- Updates Segmnets tests
- Updates MailPoet's Notice.js with additional options
- Updates Import's router, WP menu bootstrap logic, client- and
  server-side logic
2015-11-07 11:24:02 -05:00
ff5353c894 - Completes MailChimp import 2015-11-07 11:15:49 -05:00
abb2389378 - Enables MailChimp key verification (import step 1) 2015-11-07 11:15:04 -05:00
3cf50810f9 - Fixed conflic with backbone router in settings and import
- WIP on step 1
2015-11-07 11:09:13 -05:00
20a6e6d6de - Adds import's step 1 method selection logic 2015-11-07 11:09:13 -05:00
0b1fc8f6c3 - Updates webpack config file
- Adds an option to watch/compile just the JS files with webpack
2015-11-07 11:05:48 -05:00
0a771acb02 - Bootstrapping import menu 2015-11-06 21:38:25 -05:00
0199e2c7e1 Version bump: 0.0.3 2015-11-06 21:49:28 +01:00
d1f407bf19 Merge branch 'master' of github.com:mailpoet/mailpoet 2015-11-06 21:47:49 +01:00
f18d2842b9 Version bump: 0.0.3. 2015-11-06 21:47:17 +01:00
f640cbb307 Merge pull request #203 from mailpoet/form_editor
Form editor
2015-11-06 21:39:03 +01:00
b20d92c9b1 fixed unit tests and added form model unit test 2015-11-06 18:43:56 +01:00
795485d42a fixed sortable segments in form editor 2015-11-06 16:09:56 +01:00
dfadda2d12 converted form renderer validation to Parsley 2015-11-06 16:09:56 +01:00
31305a04c0 form validation with Parsley 2015-11-06 16:09:56 +01:00
cfdb886e88 Date widget
- fixed date widget
- fixed default styles for radio inputs in form rendering
2015-11-06 16:09:09 +01:00
1ce4b16327 custom fields (create and update) 2015-11-06 16:09:09 +01:00
b12f7f29de Custom fields
- added listing of custom fields in form editor
- ability to delete a custom field
- mades changes to the form editor in order to accomodate for the new custom fields system
- fix form editor bugs
- cleanup
2015-11-06 16:09:09 +01:00
5473f94e24 List selection & subscribe
- fixed list selection widget (form editor & rendered form)
- ajax subscription works (minus sending the confirmation email)
- bug fixes / polishing / refactoring / cleanup
2015-11-06 16:09:09 +01:00
a31dce6226 fixed list selection widget + started form submission 2015-11-06 16:09:09 +01:00
d996b78561 fixed form_editor.js being ignored by git 2015-11-06 16:09:09 +01:00
c2e7513381 Form editor
- new form with default data
- load/save in form editor
- widgets -> settings form
- widgets -> shortcode for subscribers count
- widgets -> form rendering
- added useful filters to Subscribers (for status related search)
- refactor & cleanup
2015-11-06 16:09:09 +01:00
541696863e Form editor
- new/edit in forms listing goes to editor
- fixed editor dependencies (via Webpack)
- updated forms table schema
- saving/loading a form works
2015-11-06 16:09:09 +01:00
6c8d2be18c fix for selection field jsx 2015-11-06 16:08:16 +01:00
907fe585de add Form renderer and fixed Newsletter saving issue 2015-11-06 16:08:16 +01:00
e24f8c9653 forms listing complete 2015-11-06 16:08:16 +01:00
5df0475b1a Merge pull request #204 from mailpoet/newsletter_templates
Newsletter template import/export
2015-11-06 12:23:27 +01:00
cf154455e3 Add error reporting for newsletter template export fields 2015-11-05 19:11:32 +02:00
dcfe6357cf Switch to FileSaver lib for downloading Blob files, add Blob polyfill 2015-11-05 17:17:54 +02:00
983df216f3 Add basic template export 2015-11-04 18:02:55 +02:00
f750d2359f Base for template import 2015-11-03 16:33:13 +02:00
228 changed files with 18568 additions and 3459 deletions

3
.gitignore vendored
View File

@ -15,4 +15,5 @@ temp
wysija-newsletters.zip
tests/javascript/testBundles
assets/css/*.css
assets/js/*.js
assets/js/*.js
.vagrant

View File

@ -47,6 +47,19 @@ class RoboFile extends \Robo\Tasks {
->run();
}
function watchCss() {
$css_files = $this->rsearch('assets/css/src/', array('styl'));
$this->taskWatch()
->monitor($css_files, function() {
$this->compileCss();
})
->run();
}
function watchJs() {
$this->_exec('./node_modules/webpack/bin/webpack.js --watch');
}
function compileAll() {
$this->compileJs();
$this->compileCss();
@ -61,7 +74,8 @@ class RoboFile extends \Robo\Tasks {
'assets/css/src/admin.styl',
'assets/css/src/newsletter_editor/newsletter_editor.styl',
'assets/css/src/public.styl',
'assets/css/src/rtl.styl'
'assets/css/src/rtl.styl',
'assets/css/src/importExport.styl'
);
$this->_exec(join(' ', array(
@ -113,7 +127,6 @@ class RoboFile extends \Robo\Tasks {
function testFailed() {
$this->loadEnv();
$this->_exec('vendor/bin/codecept build');
$this->startPhantomJS();
$this->_exec('vendor/bin/codecept run -g failed');
}
@ -121,4 +134,4 @@ class RoboFile extends \Robo\Tasks {
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
}
}
}

View File

@ -5,7 +5,7 @@
@require 'common'
@require 'modal'
@require 'notice'
@require 'validation_engine'
@require 'parsley'
@require 'form_editor'
@require 'listing'
@ -13,4 +13,5 @@
@require 'breadcrumb'
@require 'form'
@require 'settings'
@require 'settings'
@require 'progress_bar'

View File

@ -18,6 +18,41 @@
height: 150px
margin-right: 15px
float: left
overflow: hidden
position: relative
img
min-width: 150px
min-height: 150px
height: auto
width: 110%
position: relative
top: 0
left: 50%
transform: translate(-50%, 0%)
.mailpoet_overlay
position: absolute
top: 0
left: 0
right: 0
bottom: 0
background-color: rgba(255, 255, 255, 0.0)
opacity: 0
transition: all 200ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
&:hover
background-color: rgba(255, 255, 255, 0.7)
opacity: 1
&::after
content: " "
position: absolute
top: 0
left: 0
bottom: 0
right: 0
background: url(../img/preview_magnifying_glass.svg) no-repeat center center
.mailpoet_boxes .mailpoet_description
float:left

View File

@ -26,3 +26,25 @@ textarea.regular-text
@media screen and (max-width: 782px)
.select2-container
width: 100% !important
// progress bars
progress-border-radius = 5px
progress-background = #efefef
progress-foreground = #69b1e9
progress
background-color: progress-background;
height: 2em
border: 0
width: 100%
progress::-webkit-progress-bar
background-color: progress-background;
progress::-webkit-progress-value
background-color: progress-foreground
border-radius: progress-border-radius
progress::-moz-progress-bar
background-color: progress-foreground
border-radius: progress-border-radius

View File

@ -1,3 +1,6 @@
@require 'codemirror/lib/codemirror.css'
@require 'codemirror/theme/neo.css'
icons = '../img/form_editor_icons.png'
handle_icon = '../img/handle.png'

View File

@ -0,0 +1,78 @@
.mailpoet_hidden, .mailpoet_validation_error
display none
.form-table
th
width 300px
#paste_input
width 100%
input[type="radio"]
margin-right 0.5em !important
& + span
margin-right 2.5em
span
&.mailpoet_mailchimp-key-status
&.mailpoet_mailchimp-ok
&:before
content "\2713"
color #0e90d2
margin-left 15px
&.mailpoet_mailchimp-error
&:before
content "\2717"
color #900
margin-left 15px
#subscribers_data
overflow auto
table
width auto
td
padding 0.5em
& > table
& > tbody
& > td
padding 0.5em
& > tr
&:nth-child(odd)
background #f9f9f9
.mailpoet_header
text-transform uppercase
font-weight 600
text-decoration underline
#subscribers_data th:first-child, #subscribers_data td:first-child
width 10em !important
text-align center !important
padding 0 1em 0 1em !important
vertical-align inherit !important
#subscribers_data
& > table
& > thead
& > tr
& > th
& > span
width 15em !important
.mailpoet_data_match
color #0e90d2
margin-left 0.25em
.mailpoet_import_error, .mailpoet_validation_error
color #900
tr
&.mailpoet_segments
& > td
& > a
margin-left 15px
span
&.select2-search
&.select2-search--dropdown
display none !important

View File

@ -159,23 +159,6 @@ body.mailpoet_modal_opened
margin: 0
text-align: right
.mailpoet_button
padding: 3px 15px
border: 1px solid #444
font-weight: normal
cursor: pointer
background-color: #222
color: #cfcfcf
font-size: 1em
.mailpoet_button:hover
background-color: #00aacc
color: #fff
.mailpoet_button:active
background-color: #00ccff
color: #fff
@media screen and (max-width: 782px)
#mailpoet_modal_overlay.mailpoet_panel_overlay
top: 46px

View File

@ -76,13 +76,24 @@ $layer-selector-width = 30px
display: inline-block
padding: 2px
vertical-align: top
animation-background-color()
.mailpoet_tool
padding: 0
.mailpoet_delete_block_activate
max-width: 100%
display: inline-block
opacity: 1
animation-fade-in-and-scale-horizontally()
.mailpoet_delete_block_confirm,
.mailpoet_delete_block_cancel
display: none
max-width: 0
opacity: 0
overflow: hidden
display: inline-block
animation-fade-in-and-scale-horizontally()
.mailpoet_delete_block_activated
width: auto
@ -93,11 +104,14 @@ $layer-selector-width = 30px
height: auto
.mailpoet_delete_block_activate
display: none
overflow: hidden
max-width: 0
opacity: 0
.mailpoet_delete_block_confirm,
.mailpoet_delete_block_cancel
display: inline-block
max-width: 100%
opacity: 1
.mailpoet_delete_block_confirm
color: $warning-text-color

View File

@ -52,6 +52,7 @@ $draggable-widget-z-index = 2
padding: 0
margin: 0
z-index: $draggable-widget-z-index
animation-fade-in-and-scale-up()
.mailpoet_widget_icon
padding: 0

View File

@ -45,7 +45,8 @@
&::before
content: '\f140'
.mailpoet_save_as_template_container
.mailpoet_save_as_template_container,
.mailpoet_export_template_container
border-radius(3px)
float: left
clear: both
@ -55,7 +56,8 @@
background-color: $white-color
border: 1px solid $structure-border-color
.mailpoet_save_as_template_title
.mailpoet_save_as_template_title,
.mailpoet_export_template_title
font-size: 1.1em
.mailpoet_editor_last_saved

View File

@ -32,7 +32,7 @@ $widget-icon-width = 30px
.mailpoet_region_content
max-height: 2000px
transition: max-height 0.2s ease
transition: max-height 300ms ease
padding: 0 20px
margin-top: 12px

View File

@ -18,3 +18,6 @@
& > .mailpoet_block
width: 100%
.mailpoet_automated_latest_content_display_options
animation-slide-open-downwards()

View File

@ -30,3 +30,8 @@ $block-hover-highlight-color = $primary-active-color
.mailpoet_content
position: relative
.mailpoet_block_transition_in
animation-fade-in-and-scale-up()
.mailpoet_block_transition_out
animation-fade-out-and-scale-down()

View File

@ -79,3 +79,4 @@ $three-column-width = ($newsletter-width / 3) - (2 * $column-margin)
box-shadow(inset 1px 2px 1px $primary-inactive-color)
color: #656565
border-radius(3px)
animation-background-color()

View File

@ -19,6 +19,10 @@ $divider-hover-border-color = $primary-active-color
width: 100%
border: 1px solid transparent
.mailpoet_active_divider_style
border: 1px solid $active-divider-border-color
background: $active-divider-background-color
.mailpoet_field_divider_style:hover
border: 1px solid $divider-hover-border-color

View File

@ -1,15 +1,19 @@
.mailpoet_image_block
img
vertical-align: bottom
max-width: 100%
width: auto
height: auto
&.mailpoet_full_image
padding-left: 0
padding-right: 0
margin-bottom: 0
img
width: 100%
.mailpoet_content a:hover
cursor: all-scroll
img
vertical-align: bottom
max-width: $newsletter-width
width: 100%
height: auto

View File

@ -1,15 +1,12 @@
.mailpoet_posts_block
box-shadow(none)
padding-left: 0
padding-right: 0
& > .mailpoet_content
font-size: 1em
text-align: center
background-color: $primary-active-color
margin: 20px 0
padding: 15px
box-shadow(inset 1px 2px 1px $primary-inset-shadow-color)
color: $white-color
border-radius(3px)
.mailpoet_posts_block_posts
overflow: auto
& > .mailpoet_block
width: 100%
.mailpoet_post_selection_filter_row
margin-top: 5px
@ -18,7 +15,11 @@
.mailpoet_posts_categories_and_tags
width: 100%
.mailpoet_settings_posts_show_display_options
.mailpoet_settings_posts_display_options
.mailpoet_settings_posts_selection
animation-slide-open-downwards()
.mailpoet_settings_posts_show_display_options,
.mailpoet_settings_posts_show_post_selection
display: block
margin-top: 10px

View File

@ -1,6 +1,6 @@
/* Fix select2 z-index to work with MailPoet.Modal */
.select2-dropdown
z-index: 101000
z-index: 101000 !important
/* Remove input field styles from select2 type input */
.select2-container

View File

@ -0,0 +1,53 @@
animation-slide-open-downwards()
transition: all 300ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
max-height: 2000px
opacity: 1
&.mailpoet_closed
max-height: 0
opacity: 0
overflow-y: hidden
animation-background-color()
transition: background 300ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
animation-fade-in-and-scale-up()
animation-name: fadeInAndScaleUp
animation-duration: 500ms
animation-fill-mode: forwards
animation-fade-out-and-scale-down()
animation-name: fadeOutAndScaleDown
animation-duration: 500ms
animation-fill-mode: forwards
animation-fade-in-and-scale-horizontally()
transition: all 300ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
@keyframes fadeInAndScaleUp {
0% {
opacity: 0.3
max-height: 0
overflow: hidden
}
100% {
opacity: 1
max-height: 5000px
overflow: hidden
}
}
@keyframes fadeOutAndScaleDown {
0% {
opacity: 1
max-height: 5000px
overflow: hidden
}
100% {
opacity: 0.3
max-height: 0
overflow: hidden
}
}

View File

@ -6,6 +6,7 @@
@require 'mixins/border-radius'
@require 'mixins/box-shadow'
@require 'mixins/filter-shadow'
@require 'mixins/transitions'
@require 'variables'
@require 'common'

View File

@ -0,0 +1,27 @@
input.parsley-success,
select.parsley-success,
textarea.parsley-success
color #468847
background-color #DFF0D8
border 1px solid #D6E9C6
input.parsley-error,
select.parsley-error,
textarea.parsley-error
color #B94A48
background-color #F2DEDE
border 1px solid #EED3D7
.parsley-errors-list
margin 2px 0 3px
padding 0
list-style-type none
font-size 0.9em
line-height 0.9em
opacity 0
transition all .3s ease-in
-o-transition all .3s ease-in
-moz-transition all .3s ease-in
-webkit-transition all .3s ease-in
&.filled
opacity 1

View File

@ -0,0 +1,29 @@
.mailpoet_progress
background-color: #efefef
height: 25px
padding: 0
width: 100%
margin: 0
border-radius: 5px
position: relative
.mailpoet_progress_label
position: absolute
width: 100%
text-align: center
display: inline-block
margin: 2px 0 0 0
.mailpoet_progress_bar
position: absolute
display: inline-block
height: 100%
border-radius: 3px
box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset
background-color: #34c2e3
background-image: linear-gradient(top, #34c2e3, darken(#34c2e3, 20%))
.mailpoet_progress_complete
.mailpoet_progress_bar
background-color: #fecf23
background-image: linear-gradient(top, #fecf23, #fd9215)

View File

@ -0,0 +1,3 @@
@import 'nib'
@require 'parsley'

View File

@ -1,141 +0,0 @@
lesscss-percentage(n)
(n * 100)%
popupBg = rgb(0, 87, 154, 1)
popupTextColor = rgb(255, 255, 255, 1)
borderColor = rgb(255, 255, 255, 1)
borderWidth = 1px
popupFontSize = 12px
popupRadius = 0
popupShadowWidth = 2px
popupShadowColor = rgb(51, 51, 51, 1)
/* Z-INDEX */
.formError
z-index 990
.formError .formErrorContent
z-index 991
.formError .formErrorArrow
z-index 996
.ui-dialog .formError
z-index 5000
.ui-dialog .formError .formErrorContent
z-index 5001
.ui-dialog .formError .formErrorArrow
z-index 5006
.inputContainer
position relative
float left
.formError
position absolute
top 300px
left 300px
display block
cursor pointer
text-align left
.formError.inline
position relative
top 0
left 0
display inline-block
.ajaxSubmit
padding 20px
background #55ea55
border 1px solid #999
display none
.formError .formErrorContent
width 100%
background popupBg
position relative
color popupTextColor
min-width 120px
font-size popupFontSize
border borderWidth solid borderColor
box-shadow 0 0 popupShadowWidth popupShadowColor
-moz-box-shadow 0 0 popupShadowWidth popupShadowColor
-webkit-box-shadow 0 0 popupShadowWidth popupShadowColor
-o-box-shadow 0 0 popupShadowWidth popupShadowColor
padding 4px 10px 4px 10px
border-radius popupRadius
-moz-border-radius popupRadius
-webkit-border-radius popupRadius
-o-border-radius popupRadius
.formError.inline .formErrorContent
box-shadow none
-moz-box-shadow none
-webkit-box-shadow none
-o-box-shadow none
border none
border-radius 0
-moz-border-radius 0
-webkit-border-radius 0
-o-border-radius 0
.greenPopup .formErrorContent
background #33be40
.blackPopup .formErrorContent
background #393939
color #FFF
.formError .formErrorArrow
width 15px
margin -2px 0 0 13px
position relative
body[dir='rtl'] .formError .formErrorArrow, body.rtl .formError .formErrorArrow
margin -2px 13px 0 0
.formError .formErrorArrowBottom
box-shadow none
-moz-box-shadow none
-webkit-box-shadow none
-o-box-shadow none
margin 0px 0 0 12px
top 2px
.formError .formErrorArrow div
border-left borderWidth solid borderColor
border-right borderWidth solid borderColor
box-shadow 0 ceil((popupShadowWidth / 3)) ceil((popupShadowWidth / 2)) lighten(popupShadowColor, 10%)
-moz-box-shadow 0 ceil((popupShadowWidth / 3)) ceil((popupShadowWidth / 2)) lighten(popupShadowColor, 10%)
-webkit-box-shadow 0 ceil((popupShadowWidth / 3)) ceil((popupShadowWidth / 2)) lighten(popupShadowColor, 10%)
-o-box-shadow 0 ceil((popupShadowWidth / 3)) ceil((popupShadowWidth / 2)) lighten(popupShadowColor, 10%)
font-size 0px
height 1px
background popupBg
margin 0 auto
line-height 0
font-size 0
display block
.formError .formErrorArrowBottom div
box-shadow none
-moz-box-shadow none
-webkit-box-shadow none
-o-box-shadow none
.greenPopup .formErrorArrow div
background #33be40
.blackPopup .formErrorArrow div
background #393939
color #FFF
.formError .formErrorArrow .line10
width 13px
border none
.formError .formErrorArrow .line9
width 11px
border none
.formError .formErrorArrow .line8
width 11px
.formError .formErrorArrow .line7
width 9px
.formError .formErrorArrow .line6
width 7px
.formError .formErrorArrow .line5
width 5px
.formError .formErrorArrow .line4
width 3px
.formError .formErrorArrow .line3
width ceil((borderWidth / 2))
border-left borderWidth solid borderColor
border-right borderWidth solid borderColor
border-bottom 0 solid borderColor
.formError .formErrorArrow .line2
width 3px
border none
background borderColor
.formError .formErrorArrow .line1
width 1px
border none
background borderColor

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="47.002px" height="38.003px" viewBox="0 0 47.002 38.003" enable-background="new 0 0 47.002 38.003" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#565656" d="M46.328,36.365c-1.188,1.725-3.553,2.158-5.273,0.962L25.479,26.52
c-1.104-0.763-1.674-2.007-1.631-3.257c-2.006,2.157-4.642,3.606-7.594,4.145c-3.626,0.663-7.288-0.13-10.311-2.227
c-3.024-2.098-5.054-5.253-5.714-8.887c-0.661-3.636,0.127-7.31,2.221-10.344c4.325-6.264,12.927-7.834,19.177-3.5
c5.672,3.938,7.486,11.412,4.537,17.443c1.152-0.486,2.519-0.392,3.627,0.377l15.58,10.808C47.09,32.274,47.52,34.641,46.328,36.365
z M23.235,12.09c-0.459-2.534-1.874-4.734-3.982-6.196C14.897,2.87,8.896,3.963,5.878,8.331c-3.014,4.373-1.922,10.388,2.435,13.408
c4.356,3.025,10.356,1.932,13.374-2.438C23.146,17.187,23.696,14.625,23.235,12.09z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -0,0 +1,8 @@
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
mixpanel.init("f683d388fb25fcf331f1b2b5c4449798");
if (typeof mailpoet_analytics_data === 'object') {
mixpanel.track('Wysija Usage', mailpoet_analytics_data || {});
}

4
assets/js/lib/prototype.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2
assets/js/lib/scriptaculous.min.js vendored Normal file

File diff suppressed because one or more lines are too long

98
assets/js/src/cron.jsx Normal file
View File

@ -0,0 +1,98 @@
define(
[
'react',
'react-dom',
'mailpoet'
],
function (
React,
ReactDOM,
MailPoet
) {
var CronControl = React.createClass({
getInitialState: function () {
return (cronDaemon) ? cronDaemon : null;
},
getDaemonData: function () {
MailPoet.Ajax.post({
endpoint: 'cron',
action: 'getDaemonStatus'
}).done(function (response) {
jQuery('.button-primary').removeClass('disabled');
if (!response) {
this.replaceState();
} else {
this.setState(response);
}
}.bind(this));
},
componentDidMount: function componentDidMount() {
if (this.isMounted()) {
this.getDaemonData;
setInterval(this.getDaemonData, 5000);
}
},
controlDaemon: function (action) {
jQuery('.button-primary').addClass('disabled');
MailPoet.Ajax.post({
endpoint: 'cron',
action: 'controlDaemon',
data: {'action': action}
}).done(function (response) {
if (!response) {
this.replaceState();
} else {
this.setState(response);
}
}.bind(this));
},
render: function () {
if (!this.state) {
return
<div>
Woops, daemon is not running ;\
</div>
}
switch (this.state.status) {
case 'started':
return (
<div>
<div>
Cron daemon is running.
<br/>
<br/>
It was started
<strong> {this.state.timeSinceStart} </strong> and last executed
<strong> {this.state.timeSinceUpdate} </strong> for a total of
<strong> {this.state.counter} </strong> times (once every 30 seconds, unless it was interrupted and restarted).
<br />
<br />
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'stop')}>Stop</a>&nbsp;&nbsp;
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'pause')}>Pause</a>
</div>
</div>
);
break;
case 'paused':
case 'stopped':
return (
<div>
Daemon is {this.state.status}
<br />
<br />
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'start')}>Start</a>
</div>
)
break;
}
}
});
let container = document.getElementById('cron_container');
if (container) {
ReactDOM.render(
<CronControl />,
document.getElementById('cron_status')
)
}
}
);

View File

@ -23,7 +23,9 @@ function(
name={ this.props.field.name }
id={ 'field_'+this.props.field.name }
value={ this.props.item[this.props.field.name] }
onChange={ this.props.onValueChange }>
onChange={ this.props.onValueChange }
{...this.props.field.validation}
>
{options}
</select>
);

View File

@ -1,10 +1,12 @@
define([
'react',
'react-dom',
'jquery',
'select2'
],
function(
React,
ReactDOM,
jQuery
) {
var Selection = React.createClass({
@ -16,87 +18,114 @@ function(
},
componentDidMount: function() {
this.loadCachedItems();
},
componentDidUpdate: function() {
this.setupSelect2();
},
componentDidUpdate: function(prevProps, prevState) {
if(
(this.props.item !== undefined && prevProps.item !== undefined)
&& (this.props.item.id !== prevProps.item.id)
) {
jQuery('#'+this.refs.select.id)
.val(this.props.item[this.props.field.name])
.trigger('change');
}
},
setupSelect2: function() {
if(this.state.initialized === true) {
if(
!this.props.field.multiple
|| this.state.initialized === true
|| this.refs.select === undefined
) {
return;
}
if(this.props.field.select2 && Object.keys(this.props.item).length > 0) {
var select2 = jQuery('#'+this.props.field.id).select2({
width: (this.props.width || ''),
templateResult: function(item) {
if (item.element && item.element.selected) {
return null;
} else {
return item.text;
}
var select2 = jQuery('#'+this.refs.select.id).select2({
width: (this.props.width || ''),
templateResult: function(item) {
if(item.element && item.element.selected) {
return null;
} else {
return item.text;
}
});
}
});
select2.on('change', this.handleChange)
var hasRemoved = false;
select2.on('select2:unselecting', function(e) {
hasRemoved = true;
});
select2.on('select2:opening', function(e) {
if(hasRemoved === true) {
hasRemoved = false;
e.preventDefault();
}
});
select2.select2(
'val',
this.props.item[this.props.field.name]
);
select2.on('change', this.handleChange);
this.setState({ initialized: true });
}
select2.select2(
'val',
this.props.item[this.props.field.name]
);
this.setState({ initialized: true });
},
loadCachedItems: function() {
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {
var items = window['mailpoet_'+this.props.field.endpoint];
if(this.props.field['filter'] !== undefined) {
items = items.filter(this.props.field.filter);
}
this.setState({
items: items
});
}
},
handleChange: function() {
handleChange: function(e) {
if(this.props.onValueChange !== undefined) {
if(this.props.field.multiple) {
value = jQuery('#'+this.refs.select.id).val();
} else {
value = e.target.value;
}
this.props.onValueChange({
target: {
value: jQuery('#'+this.props.field.id).select2('val'),
value: value,
name: this.props.field.name
}
});
}
return true;
},
render: function() {
if(this.state.items.length === 0) {
return false;
} else {
var options = this.state.items.map(function(item, index) {
return (
<option
key={ item.id }
value={ item.id }
>
{ item.name }
</option>
);
});
var default_value = (
(this.props.item !== undefined && this.props.field.name !== undefined)
? this.props.item[this.props.field.name]
: null
);
var options = this.state.items.map(function(item, index) {
return (
<select
id={ this.props.field.id }
placeholder={ this.props.field.placeholder }
multiple={ this.props.field.multiple }
onChange={ this.handleChange }
defaultValue={ default_value }
>{ options }</select>
<option
key={ item.id }
value={ item.id }
>
{ item.name }
</option>
);
}
});
var default_value = (
(this.props.item !== undefined && this.props.field.name !== undefined)
? this.props.item[this.props.field.name]
: null
);
return (
<select
id={ this.props.field.id || this.props.field.name }
ref="select"
placeholder={ this.props.field.placeholder }
multiple={ this.props.field.multiple }
defaultValue={ default_value }
{...this.props.field.validation}
>{ options }</select>
);
}
});

View File

@ -6,6 +6,8 @@ function(
) {
var FormFieldText = React.createClass({
render: function() {
var value = this.props.item[this.props.field.name];
if(!value) { value = null; }
return (
<input
type="text"
@ -17,10 +19,12 @@ function(
}
name={ this.props.field.name }
id={ 'field_'+this.props.field.name }
value={ this.props.item[this.props.field.name] }
value={ value }
placeholder={ this.props.field.placeholder }
defaultValue={ this.props.field.defaultValue }
onChange={ this.props.onValueChange } />
onChange={ this.props.onValueChange }
{...this.props.field.validation}
/>
);
}
});

View File

@ -15,7 +15,9 @@ function(
value={ this.props.item[this.props.field.name] }
placeholder={ this.props.field.placeholder }
defaultValue={ this.props.field.defaultValue }
onChange={ this.props.onValueChange } />
onChange={ this.props.onValueChange }
{...this.props.field.validation}
/>
);
}
});

View File

@ -68,12 +68,25 @@ define(
handleSubmit: function(e) {
e.preventDefault();
// handle validation
if(this.props.isValid !== undefined) {
if(this.props.isValid() === false) {
return;
}
}
this.setState({ loading: true });
// only get values from displayed fields
item = {};
var item = {};
this.props.fields.map(function(field) {
item[field.name] = this.state.item[field.name];
if(field['fields'] !== undefined) {
field.fields.map(function(subfield) {
item[subfield.name] = this.state.item[subfield.name];
}.bind(this));
} else {
item[field.name] = this.state.item[field.name];
}
}.bind(this));
// set id if specified
@ -88,23 +101,23 @@ define(
}).done(function(response) {
this.setState({ loading: false });
if(response === true) {
if(response.result === true) {
if(this.props.onSuccess !== undefined) {
this.props.onSuccess()
this.props.onSuccess();
} else {
this.history.pushState(null, '/')
}
if(this.props.params.id !== undefined) {
this.props.messages['updated']();
this.props.messages.onUpdate();
} else {
this.props.messages['created']();
this.props.messages.onCreate();
}
} else {
if(response === false) {
// unknown error occurred
} else {
this.setState({ errors: response });
if(response.result === false) {
if(response.errors.length > 0) {
this.setState({ errors: response.errors });
}
}
}
}.bind(this));
@ -121,13 +134,15 @@ define(
return true;
},
render: function() {
var errors = this.state.errors.map(function(error, index) {
return (
<p key={ 'error-'+index } className="mailpoet_error">
{ error }
</p>
);
});
if(this.state.errors !== undefined) {
var errors = this.state.errors.map(function(error, index) {
return (
<p key={ 'error-'+index } className="mailpoet_error">
{ error }
</p>
);
});
}
var formClasses = classNames(
'mailpoet_form',

View File

@ -1,993 +0,0 @@
/*
* name: MailPoet Form Editor
* author: Jonathan Labreuille
* company: Wysija
* framework: prototype 1.7.2
*/
'use strict';
Event.cacheDelegated = {};
Object.extend(document, (function () {
var cache = Event.cacheDelegated;
function getCacheForSelector(selector) {
return cache[selector] = cache[selector] || {};
}
function getWrappersForSelector(selector, eventName) {
var c = getCacheForSelector(selector);
return c[eventName] = c[eventName] || [];
}
function findWrapper(selector, eventName, handler) {
var c = getWrappersForSelector(selector, eventName);
return c.find(function (wrapper) {
return wrapper.handler === handler
});
}
function destroyWrapper(selector, eventName, handler) {
var c = getCacheForSelector(selector);
if (!c[eventName]) return false;
var wrapper = findWrapper(selector, eventName, handler)
c[eventName] = c[eventName].without(wrapper);
return wrapper;
}
function createWrapper(selector, eventName, handler, context) {
var wrapper, c = getWrappersForSelector(selector, eventName);
if (c.pluck('handler').include(handler)) return false;
wrapper = function (event) {
var element = event.findElement(selector);
if (element) handler.call(context || element, event, element);
};
wrapper.handler = handler;
c.push(wrapper);
return wrapper;
}
return {
delegate: function (selector, eventName, handler, context) {
var wrapper = createWrapper.apply(null, arguments);
if (wrapper) document.observe(eventName, wrapper);
return document;
},
stopDelegating: function (selector, eventName, handler) {
var length = arguments.length;
switch (length) {
case 2:
getWrappersForSelector(selector, eventName).each(function (wrapper) {
document.stopDelegating(selector, eventName, wrapper.handler);
});
break;
case 1:
Object.keys(getCacheForSelector(selector)).each(function (eventName) {
document.stopDelegating(selector, eventName);
});
break;
case 0:
Object.keys(cache).each(function (selector) {
document.stopDelegating(selector);
});
break;
default:
var wrapper = destroyWrapper.apply(null, arguments);
if (wrapper) document.stopObserving(eventName, wrapper);
}
return document;
}
}
})());
var Observable = (function () {
function getEventName(name, namespace) {
name = name.substring(2);
if (namespace) name = namespace + ':' + name;
return name.underscore().split('_').join(':');
}
function getHandlers(klass) {
var proto = klass.prototype,
namespace = proto.namespace;
return Object.keys(proto).grep(/^on/).inject($H(), function (handlers, name) {
if (name === 'onDomLoaded') return handlers;
handlers.set(getEventName(name, namespace), getWrapper(proto[name], klass));
return handlers;
});
}
function getWrapper(handler, klass) {
return function (event) {
return handler.call(new klass(this), event, event.memo);
}
}
function onDomLoad(selector, klass) {
$$(selector).each(function (element) {
new klass(element).onDomLoaded();
});
}
return {
observe: function (selector) {
if (!this.handlers) this.handlers = {};
if (this.handlers[selector]) return;
var klass = this;
if (this.prototype.onDomLoaded) document.loaded ? onDomLoad(selector, klass) : document.observe('dom:loaded', onDomLoad.curry(selector, klass));
this.handlers[selector] = getHandlers(klass).each(function (handler) {
document.delegate(selector, handler.key, handler.value);
});
},
stopObserving: function (selector) {
if (!this.handlers || !this.handlers[selector]) return;
this.handlers[selector].each(function (handler) {
document.stopDelegating(selector, handler.key, handler.value);
});
delete this.handlers[selector];
}
}
})();
// override droppables
Object.extend(Droppables, {
deactivate: Droppables.deactivate.wrap(function (proceed, drop, draggable) {
if (drop.onLeave) drop.onLeave(draggable, drop.element);
return proceed(drop);
}),
activate: Droppables.activate.wrap(function (proceed, drop, draggable) {
if (drop.onEnter) drop.onEnter(draggable, drop.element);
return proceed(drop);
}),
show: function (point, element) {
if (!this.drops.length) return;
var drop, affected = [];
this.drops.each(function (drop) {
if (Droppables.isAffected(point, element, drop)) affected.push(drop);
});
if (affected.length > 0) drop = Droppables.findDeepestChild(affected);
if (this.last_active && this.last_active !== drop) this.deactivate(this.last_active, element);
if (drop) {
Position.within(drop.element, point[0], point[1]);
if (drop.onHover) drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
if (drop !== this.last_active) Droppables.activate(drop, element);
}
},
displayArea: function(draggable) {
if(!this.drops.length) return;
// hide controls when displaying drop areas.
WysijaForm.hideBlockControls();
this.drops.each(function (drop, iterator) {
if(drop.element.hasClassName('block_placeholder')) {
drop.element.addClassName('active');
}
});
},
hideArea: function() {
if (!this.drops.length) return;
this.drops.each(function (drop, iterator) {
if(drop.element.hasClassName('block_placeholder')) {
drop.element.removeClassName('active');
} else if(drop.element.hasClassName('image_placeholder')) {
drop.element.removeClassName('active');
drop.element.up().removeClassName('active');
} else if(drop.element.hasClassName('text_placeholder')) {
drop.element.removeClassName('active');
}
});
},
reset: function (draggable) {
if (this.last_active) this.deactivate(this.last_active, draggable);
}
});
/*
Wysija History handling
POTENTIAL FEATURES:
- set a maximum number of items to be stored
*/
var WysijaHistory = {
container: 'mailpoet_form_history',
size: 30,
enqueue: function(element) {
// create deep clone (includes child elements) of passed element
var clone = element.clone(true);
// check if the field is unique
if(parseInt(clone.readAttribute('wysija_unique'), 10) === 1) {
// check if the field is already in the queue
$(WysijaHistory.container).select('[wysija_field="'+clone.readAttribute('wysija_field')+'"]').invoke('remove');
}
// check history size
if($(WysijaHistory.container).select('> div').length >= WysijaHistory.size) {
// remove oldest element (last in the list)
$(WysijaHistory.container).select('> div').last().remove();
}
// store block in history
$(WysijaHistory.container).insert({ top: clone });
},
dequeue: function() {
// pop last block off the history
var block = $(WysijaHistory.container).select('div').first();
if(block !== undefined) {
// insert block back into the editor
$(WysijaForm.options.body).insert({top: block});
}
},
clear: function() {
$(WysijaHistory.container).innerHTML = '';
},
remove: function(field) {
$(WysijaHistory.container).select('[wysija_field="'+field+'"]').invoke('remove');
}
};
/* MailPoet Form */
var WysijaForm = {
version: '0.6',
options: {
container: 'mailpoet_form_container',
editor: 'mailpoet_form_editor',
body: 'mailpoet_form_body',
toolbar: 'mailpoet_form_toolbar',
templates: 'wysija_widget_templates',
debug: false
},
toolbar: {
effect: null,
x: null,
y: null,
top: null,
left: null
},
scroll: {
top: 0,
left: 0
},
flags: {
doSave: false
},
locks: {
dragging: false,
selectingColor: false,
showingTools: false
},
encodeHtmlValue: function(str) {
return str.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
// ": fix for FileMerge because the previous line fucks up its syntax coloring
},
decodeHtmlValue: function(str) {
return str.replace(/&amp;/g, '&').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&quot;/g, '"');
// ": fix for FileMerge because the previous line fucks up its syntax coloring
},
loading: function(is_loading) {
if(is_loading) {
$(WysijaForm.options.editor).addClassName('loading');
$(WysijaForm.options.toolbar).addClassName('loading');
} else {
$(WysijaForm.options.editor).removeClassName('loading');
$(WysijaForm.options.toolbar).removeClassName('loading');
}
},
loadStatic: function(blocks) {
$A(blocks).each(function(block) {
// create block
WysijaForm.Block.create(block, $('block_placeholder'));
});
},
load: function(form) {
if(form.data === undefined) return;
// load body
if(form.data.body !== undefined) {
$A(form.data.body).each(function(block) {
// create block
WysijaForm.Block.create(block, $('block_placeholder'));
});
// load settings
var settings_elements = $('mailpoet_form_settings').getElements();
settings_elements.each(function(setting) {
// skip lists
if(setting.name === 'lists') {
return true;
} else if(setting.name === 'on_success') {
// if the input value is equal to the one stored in the settings
if(setting.value === form.data.settings[setting.name]) {
// check selected value
$(setting).checked = true;
}
} else if(form.data.settings[setting.name] !== undefined) {
if(typeof form.data.settings[setting.name] === 'string') {
setting.setValue(WysijaForm.decodeHtmlValue(form.data.settings[setting.name]));
} else {
setting.setValue(form.data.settings[setting.name]);
}
}
});
}
},
save: function() {
var position = 1,
data = {
'version': WysijaForm.version,
'settings': $('mailpoet_form_settings').serialize(true),
'body': [],
'styles': (MailPoet.CodeEditor !== undefined) ? MailPoet.CodeEditor.getValue() : null
};
// body
WysijaForm.getBlocks().each(function(b) {
var block_data = (typeof(b.block['save']) === 'function') ? b.block.save() : null;
if(block_data !== null) {
// set block position
block_data['position'] = position;
// increment position
position++;
// add block data to body
data['body'].push(block_data);
}
});
return data;
},
init: function() {
// set document scroll
info('init -> set scroll offsets');
WysijaForm.setScrollOffsets();
// position toolbar
info('init -> set toolbar position');
WysijaForm.setToolbarPosition();
// enable droppable targets
info('init -> make droppable');
WysijaForm.makeDroppable();
// enable sortable
info('init -> make sortable');
WysijaForm.makeSortable();
// hide controls
info('init -> hide controls');
WysijaForm.hideControls();
// hide settings
info('init -> hide settings');
WysijaForm.hideSettings();
// set settings buttons position
info('init -> init settings');
WysijaForm.setSettingsPosition();
// toggle widgets
info('init -> toggle widgets');
WysijaForm.toggleWidgets();
},
getFieldData: function(element) {
// get basic field data
var data = {
type: element.readAttribute('wysija_type'),
field: element.readAttribute('wysija_field'),
name: element.readAttribute('wysija_name'),
unique: parseInt(element.readAttribute('wysija_unique') || 0, 10),
static: parseInt(element.readAttribute('wysija_static') || 0, 10),
element: element,
params: ''
};
// get params (may be empty)
if(element.readAttribute('wysija_params') !== null && element.readAttribute('wysija_params').length > 0) {
data.params = JSON.parse(element.readAttribute('wysija_params'));
}
return data;
},
toggleWidgets: function() {
$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled');
// loop through each unique field already inserted in the editor and disable its toolbar equivalent
$$('#'+WysijaForm.options.editor+' [wysija_unique="1"]').each(function(element) {
var field = $$('#'+WysijaForm.options.toolbar+' [wysija_field="'+element.readAttribute('wysija_field')+'"]').first();
if(field !== undefined) {
field.addClassName('disabled');
}
});
// hide list selection if a list widget has been dragged into the editor
$('mailpoet_settings_list_selection')[(($$('#'+WysijaForm.options.editor+' [wysija_field="list"]').length > 0) === true) ? 'hide': 'show']();
},
setBlockPositions: function(event, target) {
// release dragging lock
WysijaForm.locks.dragging = false;
var index = 1;
WysijaForm.getBlocks().each(function (container) {
container.setPosition(index++);
// remove z-index value to avoid issues when resizing images
if(container['block'] !== undefined) {
container.block.element.setStyle({zIndex: ''});
}
});
if(target !== undefined) {
// get placeholders (previous placeholder matches the placeholder linked to the next block)
var block_placeholder = $(target.element.readAttribute('wysija_placeholder')),
previous_placeholder = target.element.previous('.block_placeholder');
if(block_placeholder !== null) {
// put block placeholder before the current block
target.element.insert({before: block_placeholder});
// if the next block is a wysija_block, insert previous placeholder
if(target.element.next() !== undefined && target.element.next().hasClassName('mailpoet_form_block') && previous_placeholder !== undefined) {
target.element.insert({after: previous_placeholder});
}
}
}
},
setScrollOffsets: function() {
WysijaForm.scroll = document.viewport.getScrollOffsets();
},
hideSettings: function() {
$(WysijaForm.options.container).select('.wysija_settings').invoke('hide');
},
setSettingsPosition: function() {
// get viewport offsets and dimensions
var viewportHeight = document.viewport.getHeight(),
blockPadding = 5;
$(WysijaForm.options.container).select('.wysija_settings').each(function(element) {
// get parent dimensions and position
var parentDim = element.up('.mailpoet_form_block').getDimensions(),
parentPos = element.up('.mailpoet_form_block').cumulativeOffset(),
is_visible = (parentPos.top <= (WysijaForm.scroll.top + viewportHeight)) ? true : false,
buttonMargin = 5,
relativeTop = buttonMargin;
if(is_visible) {
// desired position is set to center of viewport
var absoluteTop = parseInt(WysijaForm.scroll.top + ((viewportHeight / 2) - (element.getHeight() / 2)), 10),
parentTop = parseInt(parentPos.top - blockPadding, 10),
parentBottom = parseInt(parentPos.top + parentDim.height - blockPadding, 10);
// always center
relativeTop = parseInt((parentDim.height / 2) - (element.getHeight() / 2), 10);
}
// set position for button
$(element).setStyle({
left: parseInt((parentDim.width / 2) - (element.getWidth() / 2)) + 'px',
top: relativeTop + 'px'
});
});
},
initToolbarPosition: function() {
if(WysijaForm.toolbar.top === null) WysijaForm.toolbar.top = parseInt($(WysijaForm.options.container).positionedOffset().top);
if(WysijaForm.toolbar.y === null) WysijaForm.toolbar.y = parseInt(WysijaForm.toolbar.top);
if(isRtl) {
if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = 0;
} else {
if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = parseInt($(WysijaForm.options.container).positionedOffset().left);
}
if(WysijaForm.toolbar.x === null) WysijaForm.toolbar.x = parseInt(WysijaForm.toolbar.left + $(WysijaForm.options.container).getDimensions().width + 15);
},
setToolbarPosition: function() {
WysijaForm.initToolbarPosition();
var position = { top: WysijaForm.toolbar.y + 'px', visibility: 'visible' };
if(isRtl) {
position.right = WysijaForm.toolbar.x + 'px';
} else {
position.left = WysijaForm.toolbar.x + 'px';
}
$(WysijaForm.options.toolbar).setStyle(position);
},
updateToolbarPosition: function() {
// init toolbar position (updates scroll and toolbar y)
WysijaForm.initToolbarPosition();
// cancel previous effect
if(WysijaForm.toolbar.effect !== null) WysijaForm.toolbar.effect.cancel();
if(WysijaForm.scroll.top >= (WysijaForm.toolbar.top - 20)) {
WysijaForm.toolbar.y = parseInt(20 + WysijaForm.scroll.top);
// start effect
WysijaForm.toolbar.effect = new Effect.Move(WysijaForm.options.toolbar, {
x: WysijaForm.toolbar.x,
y: WysijaForm.toolbar.y,
mode: 'absolute',
duration: 0.2
});
} else {
$(WysijaForm.options.toolbar).setStyle({
left: WysijaForm.toolbar.x + 'px',
top: WysijaForm.toolbar.top + 'px'
});
}
},
blockDropOptions: {
accept: $w('mailpoet_form_field'), // acceptable items (classes array)
onEnter: function (draggable, droppable) {
$(droppable).addClassName('hover');
},
onLeave: function (draggable, droppable) {
$(droppable).removeClassName('hover');
},
onDrop: function (draggable, droppable) {
// custom data for images
droppable.fire('wjfe:item:drop', WysijaForm.getFieldData(draggable));
$(droppable).removeClassName('hover');
}
},
hideControls: function() {
try {
return WysijaForm.getBlocks().invoke('hideControls');
} catch(e) { return; }
},
hideTools: function() {
$$('.wysija_tools').invoke('hide');
WysijaForm.locks.showingTools = false;
},
instances: {},
get: function (element, type) {
if(type === undefined) type = 'block';
// identify element
var id = element.identify();
var instance = WysijaForm.instances[id] || new WysijaForm[type.capitalize().camelize()](id);
WysijaForm.instances[id] = instance;
return instance;
},
makeDroppable: function() {
Droppables.add('block_placeholder', WysijaForm.blockDropOptions);
},
makeSortable: function () {
var body = $(WysijaForm.options.body);
Sortable.create(body, {
tag: 'div',
only: 'mailpoet_form_block',
scroll: window,
handle: 'handle',
constraint: 'vertical'
});
Draggables.removeObserver(body);
Draggables.addObserver({
element: body,
onStart: WysijaForm.startBlockPositions,
onEnd: WysijaForm.setBlockPositions
});
},
hideBlockControls: function() {
$$('.wysija_controls').invoke('hide');
this.getBlockElements().invoke('removeClassName', 'hover');
},
getBlocks: function () {
return WysijaForm.getBlockElements().map(function (element) {
return WysijaForm.get(element);
});
},
getBlockElements: function () {
return $(WysijaForm.options.container).select('.mailpoet_form_block');
},
startBlockPositions: function(event, target) {
if(target.element.hasClassName('mailpoet_form_block')) {
// store block placeholder id for the block that is being repositionned
if(target.element.previous('.block_placeholder') !== undefined) {
target.element.writeAttribute('wysija_placeholder', target.element.previous('.block_placeholder').identify());
}
}
WysijaForm.locks.dragging = true;
},
encodeURIComponent: function(str) {
// check if it's a url and if so, prevent encoding of protocol
var regexp = new RegExp(/^http[s]?:\/\//),
protocol = regexp.exec(str);
if(protocol === null) {
// this is not a url so encode the whole thing
return encodeURIComponent(str).replace(/[!'()*]/g, escape);
} else if(protocol.length === 1) {
// this is a url, so do not encode the protocol
return encodeURI(str).replace(/[!'()*]/g, escape);
}
}
};
WysijaForm.DraggableItem = Class.create({
initialize: function (element) {
this.elementType = $(element).readAttribute('wysija_type');
this.element = $(element).down() || $(element);
this.clone = this.cloneElement();
this.insert();
},
STYLES: new Template('position: absolute; top: #{top}px; left: #{left}px;'),
cloneElement: function () {
var clone = this.element.clone(),
offset = this.element.cumulativeOffset(),
list = this.getList(),
styles = this.STYLES.evaluate({
top: offset.top - list.scrollTop,
left: offset.left - list.scrollLeft
});
clone.setStyle(styles);
clone.addClassName('mailpoet_form_widget');
clone.addClassName(this.elementType);
clone.innerHTML = this.element.innerHTML;
return clone;
},
getOffset: function () {
return this.element.offsetTop - this.getList().scrollTop;
},
getList: function () {
return this.element.up('ul');
},
insert: function () {
$$("body")[0].insert(this.clone);
},
onMousedown: function (event) {
var draggable = new Draggable(this.clone, {
scroll: window,
onStart: function () {
Droppables.displayArea(draggable);
},
onEnd: function (drag) {
drag.destroy();
drag.element.remove();
Droppables.hideArea();
},
starteffect: function (element) {
new Effect.Opacity(element, {
duration: 0.2,
from: element.getOpacity(),
to: 0.7
});
},
endeffect: Prototype.emptyFunction
});
draggable.initDrag(event);
draggable.startDrag(event);
return draggable;
}
});
Object.extend(WysijaForm.DraggableItem, Observable).observe('a[class="mailpoet_form_field"]');
WysijaForm.Block = Class.create({
/* Invoked on load */
initialize: function(element) {
info('block -> init');
this.element = $(element);
this.block = new WysijaForm.Widget(this.element);
// enable block placeholder
this.block.makeBlockDroppable();
// setup events
if(this.block['setup'] !== undefined) {
this.block.setup();
}
return this;
},
setPosition: function(position) {
this.element.writeAttribute('wysija_position', position);
},
hideControls: function() {
if(this['getControls']) {
this.element.removeClassName('hover');
this.getControls().hide();
}
},
showControls: function() {
if(this['getControls']) {
this.element.addClassName('hover');
try {
this.getControls().show();
} catch(e) {
;
}
}
},
makeBlockDroppable: function() {
if(this.isBlockDroppableEnabled() === false) {
var block_placeholder = this.getBlockDroppable();
Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions);
block_placeholder.addClassName('enabled');
}
},
removeBlockDroppable: function() {
if(this.isBlockDroppableEnabled()) {
var block_placeholder = this.getBlockDroppable();
Droppables.remove(block_placeholder.identify());
block_placeholder.removeClassName('enabled');
}
},
isBlockDroppableEnabled: function() {
// if the block_placeholder does not exist, create it
var block_placeholder = this.getBlockDroppable();
if(block_placeholder === null) {
return this.createBlockDroppable().hasClassName('enabled');
} else {
return block_placeholder.hasClassName('enabled');
}
},
createBlockDroppable: function() {
info('block -> createBlockDroppable');
this.element.insert({before: '<div class=\"block_placeholder\">'+$('block_placeholder').innerHTML+'</div>'});
return this.element.previous('.block_placeholder');
},
getBlockDroppable: function() {
if(this.element.previous() === undefined || this.element.previous().hasClassName('block_placeholder') === false) {
return null;
} else {
return this.element.previous();
}
},
getControls: function() {
return this.element.down('.wysija_controls');
},
setupControls: function() {
// enable controls
this.controls = this.getControls();
if(this.controls) {
// setup events for block controls
this.element.observe('mouseover', function() {
// special cases where controls shouldn't be displayed
if(WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true || WysijaForm.locks.showingTools === true) return;
// set block flag
this.element.addClassName('hover');
// show controls
this.showControls();
// show settings if present
if(this.element.down('.wysija_settings') !== undefined) {
this.element.down('.wysija_settings').show();
}
}.bind(this));
this.element.observe('mouseout', function() {
// special cases where controls shouldn't hide
if(WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true) return;
// hide controls
this.hideControls();
// hide settings if present
if(this.element.down('.wysija_settings') !== undefined) {
this.element.down('.wysija_settings').hide();
}
}.bind(this));
// setup click event for remove button
this.removeButton = this.controls.down('.remove') || null;
if(this.removeButton !== null) {
this.removeButton.observe('click', function() {
this.removeBlock();
this.removeButton.stopObserving('click');
}.bind(this));
}
// setup click event for settings button
this.settingsButton = this.element.down('.settings') || null;
if(this.settingsButton !== null) {
this.settingsButton.observe('click', function(event) {
// TODO: refactor
var block = $(event.target).up('.mailpoet_form_block') || null;
if(block !== null) {
var field = WysijaForm.getFieldData(block);
this.editSettings();
}
}.bind(this));
}
}
return this;
},
removeBlock: function(callback) {
info('block -> removeBlock');
// save block in history
WysijaHistory.enqueue(this.element);
Effect.Fade(this.element.identify(), {
duration: 0.2,
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
if(effect.element.previous('.block_placeholder') !== undefined) {
effect.element.previous('.block_placeholder').remove();
}
// remove element from the DOM
this.element.remove();
// reset block positions
WysijaForm.setBlockPositions();
// toggle widgets
WysijaForm.toggleWidgets();
// optional callback execution after completely removing block
if(callback !== undefined && typeof(callback) === 'function') {
callback();
}
// remove block instance
delete WysijaForm.instances[this.element.identify()];
}.bind(this)
});
}
});
/* Invoked on item dropped */
WysijaForm.Block.create = function(block, target) {
if($('form_template_'+block.type) === null) {
return false;
}
var body = $(WysijaForm.options.body),
block_template = Handlebars.compile($('form_template_block').innerHTML),
template = Handlebars.compile($('form_template_'+block.type).innerHTML),
output = '';
// set block template (depending on the block type)
block.template = template(block);
output = block_template(block);
// check if the new block is unique and if there's already an instance
// of it in the history. If so, remove its former instance from the history
if(block.unique === 1) {
WysijaHistory.remove(block.field);
}
// if the drop target was the bottom placeholder
if(target.identify() === 'block_placeholder') {
// insert block at the bottom
body.insert(output);
//block = body.childElements().last();
} else {
// insert block before the drop target
target.insert({before: output });
//block = target.previous('.mailpoet_form_block');
}
// refresh sortable items
WysijaForm.makeSortable();
// refresh block positions
WysijaForm.setBlockPositions();
// position settings
WysijaForm.setSettingsPosition();
};
document.observe('wjfe:item:drop', function(event) {
info('create block');
WysijaForm.Block.create(event.memo, event.target);
// hide block controls
info('hide controls');
WysijaForm.hideBlockControls();
// toggle widgets
setTimeout(function() {
WysijaForm.toggleWidgets();
}, 1);
});
/* Form Widget */
WysijaForm.Widget = Class.create(WysijaForm.Block, {
initialize: function(element) {
info('widget -> init');
this.element = $(element);
return this;
},
setup: function() {
info('widget -> setup');
this.setupControls();
},
save: function() {
info('widget -> save');
var data = this.getData();
if(data.element !== undefined) {
delete data.element;
}
return data;
},
setData: function(data) {
var current_data = this.getData(),
params = $H(current_data.params).merge(data.params).toObject();
// update type if it changed
if(data.type !== undefined && data.type !== current_data.type) {
this.element.writeAttribute('wysija_type', data.type);
}
// update params
this.element.writeAttribute('wysija_params', JSON.stringify(params));
},
getData: function() {
var data = WysijaForm.getFieldData(this.element);
// decode params
if(data.params.length > 0) {
data.params = JSON.parse(data.params);
}
return data;
},
getControls: function() {
return this.element.down('.wysija_controls');
},
remove: function() {
this.removeBlock();
},
redraw: function(data) {
// set parameters
this.setData(data);
var options = this.getData();
// redraw block
var block_template = Handlebars.compile($('form_template_block').innerHTML),
template = Handlebars.compile($('form_template_'+options.type).innerHTML),
data = $H(options).merge({ template: template(options) }).toObject();
this.element.replace(block_template(data));
WysijaForm.init();
},
editSettings: function() {
MailPoet.Modal.popup({
title: 'Edit field settings', // TODO: translate!
template: jQuery('#form_template_field_settings').html(),
data: this.getData(),
onSuccess: function() {
var data = jQuery('#form_field_settings').serializeObject();
this.redraw(data);
}.bind(this)
});
},
getSettings: function() {
return this.element.down('.wysija_settings');
}
});
/* When dom is loaded, initialize WysijaForm */
document.observe('dom:loaded', WysijaForm.init);
/* LOGGING */
function info(value) {
if(WysijaForm.options.debug === false) return;
if(!(window.console && console.log)) {
(function() {
var noop = function() {};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'markTimeline', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
var length = methods.length;
var console = window.console = {};
while(length--) {
console[methods[length]] = noop;
}
}());
}
try {
console.log('[DEBUG] '+value);
} catch(e) {}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +0,0 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, History } from 'react-router'
import MailPoet from 'mailpoet'
import Form from 'form/form.jsx'
const fields = [
{
name: 'name',
label: 'Name',
type: 'text'
},
{
name: 'segments',
label: 'Lists',
type: 'selection',
endpoint: 'segments'
}
]
const messages = {
updated: function() {
MailPoet.Notice.success('Form successfully updated!');
},
created: function() {
MailPoet.Notice.success('Form successfully added!');
}
}
const FormForm = React.createClass({
mixins: [
History
],
render() {
return (
<div>
<h2 className="title">
Form <a
href="javascript:;"
className="add-new-h2"
onClick={ this.history.goBack }
>Back to list</a>
</h2>
<Form
endpoint="forms"
fields={ fields }
params={ this.props.params }
messages={ messages }
onSuccess={ this.history.goBack } />
</div>
);
}
});
module.exports = FormForm

View File

@ -2,7 +2,6 @@ import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, IndexRoute } from 'react-router'
import FormList from 'forms/list.jsx'
import FormForm from 'forms/form.jsx'
import createHashHistory from 'history/lib/createHashHistory'
let history = createHashHistory({ queryKey: false })
@ -20,8 +19,6 @@ if(container) {
<Router history={ history }>
<Route path="/" component={ App }>
<IndexRoute component={ FormList } />
<Route path="new" component={ FormForm } />
<Route path="edit/:id" component={ FormForm } />
<Route path="*" component={ FormList } />
</Route>
</Router>

View File

@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Link, History } from 'react-router'
import { Router, Link } from 'react-router'
import Listing from 'listing/listing.jsx'
import classNames from 'classnames'
import MailPoet from 'mailpoet'
@ -11,6 +11,11 @@ const columns = [
label: 'Name',
sortable: true
},
{
name: 'segments',
label: 'Lists',
sortable: false
},
{
name: 'created_at',
label: 'Created on',
@ -20,57 +25,57 @@ const columns = [
const messages = {
onTrash: function(response) {
let count = ~~response.forms;
let message = null;
if(response) {
let message = null;
if(~~response === 1) {
message = (
'1 form was moved to the trash.'
);
} else if(~~response > 1) {
message = (
'%$1d forms were moved to the trash.'
).replace('%$1d', ~~response);
}
if(count === 1 || response === true) {
message = (
'1 form was moved to the trash.'
);
} else if(count > 1) {
message = (
'%$1d forms were moved to the trash.'
).replace('%$1d', count);
}
if(message !== null) {
MailPoet.Notice.success(message);
if(message !== null) {
MailPoet.Notice.success(message);
}
}
},
onDelete: function(response) {
let count = ~~response.forms;
let message = null;
if(response) {
let message = null;
if(~~response === 1) {
message = (
'1 form was permanently deleted.'
);
} else if(~~response > 1) {
message = (
'%$1d forms were permanently deleted.'
).replace('%$1d', ~~response);
}
if(count === 1 || response === true) {
message = (
'1 form was permanently deleted.'
);
} else if(count > 1) {
message = (
'%$1d forms were permanently deleted.'
).replace('%$1d', count);
}
if(message !== null) {
MailPoet.Notice.success(message);
if(message !== null) {
MailPoet.Notice.success(message);
}
}
},
onRestore: function(response) {
let count = ~~response.forms;
let message = null;
if(response) {
let message = null;
if(~~response === 1) {
message = (
'1 form has been restored from the trash.'
);
} else if(~~response > 1) {
message = (
'%$1d forms have been restored from the trash.'
).replace('%$1d', ~~response);
}
if(count === 1 || response === true) {
message = (
'1 form has been restored from the trash.'
);
} else if(count > 1) {
message = (
'%$1d forms have been restored from the trash.'
).replace('%$1d', count);
}
if(message !== null) {
MailPoet.Notice.success(message);
if(message !== null) {
MailPoet.Notice.success(message);
}
}
}
};
@ -78,34 +83,31 @@ const messages = {
const item_actions = [
{
name: 'edit',
label: 'Edit',
link: function(item) {
return (
<Link to={ `/edit/${item.id}` }>Edit</Link>
<a href={ `admin.php?page=mailpoet-form-editor&id=${item.id}` }>Edit</a>
);
}
},
{
name: 'duplicate_form',
refresh: true,
link: function(item) {
return (
<a
href="javascript:;"
onClick={ this.onDuplicate.bind(null, item) }
>Duplicate</a>
);
},
onDuplicate: function(item) {
MailPoet.Ajax.post({
label: 'Duplicate',
onClick: function(item, refresh) {
return MailPoet.Ajax.post({
endpoint: 'forms',
action: 'duplicate',
data: item.id
}).done(function() {
}).done(function(response) {
MailPoet.Notice.success(
('List "%$1s" has been duplicated.').replace('%$1s', item.name)
('Form "%$1s" has been duplicated.').replace('%$1s', response.name)
);
refresh();
});
}
},
{
name: 'trash'
}
];
@ -113,17 +115,22 @@ const bulk_actions = [
{
name: 'trash',
label: 'Trash',
getData: function() {
return {
confirm: false
}
},
onSuccess: messages.onDelete
onSuccess: messages.onTrash
}
];
const FormList = React.createClass({
renderItem: function(form, actions) {
createForm() {
MailPoet.Ajax.post({
endpoint: 'forms',
action: 'create'
}).done(function(response) {
if(response !== false) {
window.location = response;
}
});
},
renderItem(form, actions) {
let row_classes = classNames(
'manage-column',
'column-primary',
@ -157,10 +164,16 @@ const FormList = React.createClass({
return (
<div>
<h2 className="title">
Forms <Link className="add-new-h2" to="/new">New</Link>
Forms <a
className="add-new-h2"
href="javascript:;"
onClick={ this.createForm }
>New</a>
</h2>
<Listing
location={ this.props.location }
params={ this.props.params }
messages={ messages }
search={ false }
limit={ 1000 }

View File

@ -0,0 +1,3 @@
define([], function() {
!function(e,o,n){window.HSCW=o,window.HS=n,n.beacon=n.beacon||{};var t=n.beacon;t.userConfig={},t.readyQueue=[],t.config=function(e){this.userConfig=e},t.ready=function(e){this.readyQueue.push(e)},o.config={docs:{enabled:!1,baseUrl:""},contact:{enabled:!0,formId:"e5c408c7-895e-11e5-9e75-0a7d6919297d"}};var r=e.getElementsByTagName("script")[0],c=e.createElement("script");c.type="text/javascript",c.async=!0,c.src="https://djtflbt20bdde.cloudfront.net/",r.parentNode.insertBefore(c,r)}(document,window.HSCW||{},window.HS||{});
});

View File

@ -15,16 +15,16 @@ function(
this.setState({
action: e.target.value,
extra: false
});
}, function() {
var action = this.getSelectedAction();
var action = this.getSelectedAction();
// action on select callback
if(action !== null && action['onSelect'] !== undefined) {
this.setState({
extra: action.onSelect(e)
});
}
// action on select callback
if(action !== null && action['onSelect'] !== undefined) {
this.setState({
extra: action.onSelect(e)
});
}
}.bind(this));
},
handleApplyAction: function(e) {
e.preventDefault();
@ -85,7 +85,12 @@ function(
Select bulk action
</label>
<select ref="action" value={ this.state.action } onChange={this.handleChangeAction}>
<select
name="bulk_actions"
ref="action"
value={ this.state.action }
onChange={this.handleChangeAction}
>
<option value="">Bulk Actions</option>
{ this.props.bulk_actions.map(function(action, index) {
return (

View File

@ -36,7 +36,6 @@ function(
let default_value = false;
if(selected_filters[filter] !== undefined && selected_filters[filter]) {
default_value = selected_filters[filter]
} else {
jQuery(`select[name="${filter}"]`).val('');
}

View File

@ -11,7 +11,7 @@ define(['react', 'classnames'], function(React, classNames) {
column.is_primary = (index === 0);
column.sorted = (this.props.sort_by === column.name)
? this.props.sort_order
: 'asc';
: 'desc';
return (
<ListingColumn
onSort={this.props.onSort}
@ -32,6 +32,7 @@ define(['react', 'classnames'], function(React, classNames) {
</label>
<input
type="checkbox"
name="select_all"
ref="toggle"
checked={ this.props.selection }
onChange={ this.handleSelectItems } />

View File

@ -34,11 +34,9 @@ define(
};
},
handleSelectItem: function(e) {
var is_checked = jQuery(e.target).is(':checked');
this.props.onSelectItem(
parseInt(e.target.value, 10),
is_checked
e.target.checked
);
return !e.target.checked;
@ -61,11 +59,12 @@ define(
if(this.props.is_selectable === true) {
checkbox = (
<th className="check-column" scope="row">
<label className="screen-reader-text">
{ 'Select ' + this.props.item.email }</label>
<label className="screen-reader-text">{
'Select ' + this.props.item[this.props.columns[0].name]
}</label>
<input
type="checkbox"
defaultValue={ this.props.item.id }
value={ this.props.item.id }
checked={
this.props.item.selected || this.props.selection === 'all'
}
@ -80,27 +79,48 @@ define(
if(custom_actions.length > 0) {
item_actions = custom_actions.map(function(action, index) {
if(action.refresh) {
if(action.display !== undefined) {
if(action.display(this.props.item) === false) {
return;
}
}
if(action.name === 'trash') {
return (
<span key={ 'action-'+index } className="trash">
{(index > 0) ? ' | ' : ''}
<a
href="javascript:;"
onClick={ this.handleTrashItem.bind(
null,
this.props.item.id
) }>
Trash
</a>
</span>
);
} else if(action.refresh) {
return (
<span
onClick={ this.props.onRefreshItems }
key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''}
{ action.link(this.props.item) }
{(index < (custom_actions.length - 1)) ? ' | ' : ''}
</span>
);
} else if(action.link) {
return (
<span
key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''}
{ action.link(this.props.item) }
{(index < (custom_actions.length - 1)) ? ' | ' : ''}
</span>
);
} else {
return (
<span
key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''}
<a href="javascript:;" onClick={
(action.onClick !== undefined)
? action.onClick.bind(null,
@ -109,7 +129,6 @@ define(
)
: false
}>{ action.label }</a>
{(index < (custom_actions.length - 1)) ? ' | ' : ''}
</span>
);
}
@ -159,17 +178,6 @@ define(
<div>
<div className="row-actions">
{ item_actions }
{ ' | ' }
<span className="trash">
<a
href="javascript:;"
onClick={ this.handleTrashItem.bind(
null,
this.props.item.id
) }>
Trash
</a>
</span>
</div>
<button
onClick={ this.handleToggleItem.bind(null, this.props.item.id) }
@ -267,7 +275,7 @@ define(
is_selectable={ this.props.is_selectable }
item_actions={ this.props.item_actions }
group={ this.props.group }
key={ 'item-' + index }
key={ `item-${item.id}-${index}` }
item={ item } />
);
}.bind(this))}
@ -389,11 +397,17 @@ define(
if(this.isMounted()) {
const params = this.props.params || {}
this.initWithParams(params)
if(this.props.auto_refresh) {
jQuery(document).on('heartbeat-tick.mailpoet', function(e, data) {
this.getItems();
}.bind(this));
}
}
},
componentWillReceiveProps: function(nextProps) {
const params = nextProps.params || {}
//this.initWithParams(params)
this.initWithParams(params)
},
getItems: function() {
if(this.isMounted()) {
@ -420,7 +434,13 @@ define(
groups: response.groups || [],
count: response.count || 0,
loading: false
});
}, function() {
if(this.props['onGetItems'] !== undefined) {
this.props.onGetItems(
~~(this.state.groups[0]['count'])
);
}
}.bind(this));
}.bind(this));
}
},
@ -506,7 +526,7 @@ define(
MailPoet.Ajax.post({
endpoint: this.props.endpoint,
action: 'bulk_action',
action: 'bulkAction',
data: data
}).done(function(response) {
this.getItems();
@ -632,7 +652,7 @@ define(
// bulk actions
var bulk_actions = this.props.bulk_actions || [];
if(this.state.group === 'trash') {
if(this.state.group === 'trash' && bulk_actions.length > 0) {
bulk_actions = [
{
name: 'restore',

View File

@ -226,11 +226,11 @@ define([
toggleDisplayOptions: function(event) {
var el = this.$('.mailpoet_automated_latest_content_display_options'),
showControl = this.$('.mailpoet_automated_latest_content_show_display_options');
if (el.hasClass('mailpoet_hidden')) {
el.removeClass('mailpoet_hidden');
if (el.hasClass('mailpoet_closed')) {
el.removeClass('mailpoet_closed');
showControl.addClass('mailpoet_hidden');
} else {
el.addClass('mailpoet_hidden');
el.addClass('mailpoet_closed');
showControl.removeClass('mailpoet_hidden');
}
},
@ -306,7 +306,7 @@ define([
_.each(postTypes, function(type) {
select.append(jQuery('<option>', {
value: type.name,
text: type.labels.singular_name,
text: type.label,
}));
});
select.val(selectedValue);

View File

@ -48,6 +48,7 @@ define([
},
modelEvents: {
'change': 'render',
'delete': 'deleteBlock',
},
events: {
"mouseenter": "showTools",
@ -88,7 +89,9 @@ define([
this.$el.addClass('mailpoet_editor_view_' + this.cid);
},
initialize: function() {
this.on('showSettings', this.showSettings);
this.on('showSettings', this.showSettings, this);
this.on('dom:refresh', this.showBlock, this);
this._isFirstRender = true;
},
showTools: function(_event) {
if (!this.showingToolsDisabled) {
@ -121,6 +124,34 @@ define([
return newModel;
};
},
showBlock: function() {
if (this._isFirstRender) {
this.transitionIn();
this._isFirstRender = false;
}
},
deleteBlock: function() {
this.transitionOut().done(function() {
this.model.destroy();
}.bind(this));
},
transitionIn: function() {
return this._transition('mailpoet_block_transition_in');
},
transitionOut: function() {
return this._transition('mailpoet_block_transition_out');
},
_transition: function(className) {
var that = this,
promise = jQuery.Deferred();
this.$el.addClass(className);
this.$el.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd animationend', function() {
that.$el.removeClass('mailpoet_block_transition_out');
promise.resolve();
});
return promise;
},
});
Module.BlockToolsView = AugmentedView.extend({
@ -168,9 +199,9 @@ define([
},
deleteBlock: function(event) {
event.preventDefault();
this.model.destroy();
this.model.trigger('delete');
return false;
}
},
});
Module.BlockSettingsView = Marionette.LayoutView.extend({
@ -203,6 +234,9 @@ define([
changeBoolField: function(field, event) {
this.model.set(field, (jQuery(event.target).val() === 'true') ? true : false);
},
changeBoolCheckboxField: function(field, event) {
this.model.set(field, (!!jQuery(event.target).prop('checked')));
},
changeColorField: function(field, event) {
var value = jQuery(event.target).val();
if (value === '') {

View File

@ -42,16 +42,12 @@ define([
Module.ButtonBlockView = base.BlockView.extend({
className: "mailpoet_block mailpoet_button_block mailpoet_droppable_block",
getTemplate: function() { return templates.buttonBlock; },
modelEvents: {
'change': 'render',
},
onDragSubstituteBy: function() { return Module.ButtonWidgetView; },
initialize: function() {
base.BlockView.prototype.initialize.apply(this, arguments);
var that = this;
// Listen for attempts to change all dividers in one go
this._replaceButtonStylesHandler = function(data) { that.model.set(data); };
this._replaceButtonStylesHandler = function(data) { this.model.set(data); }.bind(this);
App.getChannel().on('replaceAllButtonStyles', this._replaceButtonStylesHandler);
},
onRender: function() {

View File

@ -75,7 +75,8 @@ define([
getEmptyView: function() { return Module.ContainerBlockEmptyView; },
emptyViewOptions: function() { return { renderOptions: this.renderOptions }; },
modelEvents: {
'change': 'render'
'change': 'render',
'delete': 'deleteBlock',
},
events: {
"mouseenter": "showTools",
@ -136,6 +137,8 @@ define([
},
initialize: function(options) {
this.renderOptions = _.defaults(options.renderOptions || {}, {});
this.on('dom:refresh', this.showBlock, this);
this._isFirstRender = true;
},
// Determines which view type should be used for a child
getChildView: function(model) {
@ -162,10 +165,10 @@ define([
this.toolsView = new Module.ContainerBlockToolsView({
model: this.model,
tools: {
settings: this.renderOptions.depth > 1,
settings: this.renderOptions.depth === 1,
delete: this.renderOptions.depth === 1,
move: this.renderOptions.depth === 1,
layerSelector: this.renderOptions.depth === 1,
layerSelector: false,
},
});
this.toolsRegion.show(this.toolsView);
@ -236,6 +239,34 @@ define([
return newModel;
};
},
showBlock: function() {
if (this._isFirstRender) {
this.transitionIn();
this._isFirstRender = false;
}
},
deleteBlock: function() {
this.transitionOut().done(function() {
this.model.destroy();
}.bind(this));
},
transitionIn: function() {
return this._transition('mailpoet_block_transition_in');
},
transitionOut: function() {
return this._transition('mailpoet_block_transition_out');
},
_transition: function(className) {
var that = this,
promise = jQuery.Deferred();
this.$el.addClass(className);
this.$el.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd animationend', function() {
that.$el.removeClass('mailpoet_block_transition_out');
promise.resolve();
});
return promise;
},
});
Module.ContainerBlockEmptyView = Marionette.ItemView.extend({
@ -265,6 +296,41 @@ define([
behaviors: {
ColorPickerBehavior: {},
},
regions: {
columnsSettingsRegion: '.mailpoet_container_columns_settings',
},
initialize: function() {
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
this._columnsSettingsView = new (Module.ContainerBlockColumnsSettingsView)({
collection: this.model.get('blocks'),
});
},
onRender: function() {
this.columnsSettingsRegion.show(this._columnsSettingsView);
},
});
Module.ContainerBlockColumnsSettingsView = Marionette.CollectionView.extend({
getChildView: function() { return Module.ContainerBlockColumnSettingsView; },
childViewOptions: function(model, index) {
return {
columnIndex: index,
};
},
});
Module.ContainerBlockColumnSettingsView = Marionette.ItemView.extend({
getTemplate: function() { return templates.containerBlockColumnSettings; },
initialize: function(options) {
this.columnNumber = (options.columnIndex || 0) + 1;
},
templateHelpers: function() {
return {
model: this.model.toJSON(),
columnNumber: this.columnNumber,
};
},
});
Module.OneColumnContainerWidgetView = base.WidgetView.extend({

View File

@ -66,7 +66,7 @@ define([
"keyup .mailpoet_field_image_link": _.partial(this.changeField, "link"),
"keyup .mailpoet_field_image_address": _.partial(this.changeField, "src"),
"keyup .mailpoet_field_image_alt_text": _.partial(this.changeField, "alt"),
"change .mailpoet_field_image_padded": _.partial(this.changeBoolField, "padded"),
"change .mailpoet_field_image_padded": _.partial(this.changeBoolCheckboxField, "padded"),
"change .mailpoet_field_image_alignment": _.partial(this.changeField, "styles.block.textAlign"),
"click .mailpoet_field_image_select_another_image": "showMediaManager",
"click .mailpoet_done_editing": "close",

View File

@ -31,7 +31,7 @@ define([
base = BaseBlock;
Module.PostsBlockModel = base.BlockModel.extend({
stale: ['_selectedPosts', '_availablePosts'],
stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'],
defaults: function() {
return this._getDefaults({
type: 'posts',
@ -63,6 +63,7 @@ define([
divider: {},
_selectedPosts: [],
_availablePosts: [],
_transformedPosts: new (App.getBlockTypeModel('container'))(),
}, App.getConfig().get('blockDefaults.posts'));
},
relations: function() {
@ -71,15 +72,26 @@ define([
divider: App.getBlockTypeModel('divider'),
_selectedPosts: Backbone.Collection,
_availablePosts: Backbone.Collection,
_transformedPosts: App.getBlockTypeModel('container'),
};
},
initialize: function() {
var that = this;
var that = this,
POST_REFRESH_DELAY_MS = 500,
refreshAvailablePosts = _.debounce(this.fetchAvailablePosts.bind(this), POST_REFRESH_DELAY_MS),
refreshTransformedPosts = _.debounce(this._refreshTransformedPosts.bind(this), POST_REFRESH_DELAY_MS);
// Attach Radio.Requests API primarily for highlighting
_.extend(this, Radio.Requests);
this.fetchAvailablePosts();
this.on('change:amount change:contentType change:terms change:inclusionType change:postStatus change:search change:sortBy', this._scheduleFetchAvailablePosts, this);
this.on('change:amount change:contentType change:terms change:inclusionType change:postStatus change:search change:sortBy', refreshAvailablePosts);
this.listenTo(this.get('_selectedPosts'), 'add remove reset', refreshTransformedPosts);
this.on('change:displayType change:titleFormat change:titlePosition change:titleAlignment change:titleIsLink change:imagePadded change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:showDivider', refreshTransformedPosts);
this.listenTo(this.get('readMoreButton'), 'change', refreshTransformedPosts);
this.listenTo(this.get('divider'), 'change', refreshTransformedPosts);
this.on('insertSelectedPosts', this._insertSelectedPosts, this);
},
fetchAvailablePosts: function() {
@ -93,20 +105,23 @@ define([
console.log('Posts fetchPosts error', arguments);
});
},
/**
* Batch more changes during a specific time, instead of fetching
* ALC posts on each model change
*/
_scheduleFetchAvailablePosts: function() {
var timeout = 500,
that = this;
if (this._fetchPostsTimer !== undefined) {
clearTimeout(this._fetchPostsTimer);
_refreshTransformedPosts: function() {
var that = this,
data = this.toJSON();
data.posts = this.get('_selectedPosts').pluck('ID');
if (data.posts.length === 0) {
this.get('_transformedPosts.blocks').reset();
return;
}
this._fetchPostsTimer = setTimeout(function() {
that.fetchAvailablePosts();
that._fetchPostsTimer = undefined;
}, timeout);
WordpressComponent.getTransformedPosts(data).done(function(posts) {
console.log('Transformed posts fetched', arguments);
that.get('_transformedPosts').get('blocks').reset(posts, {parse: true});
}).fail(function() {
console.log('Posts _refreshTransformedPosts error', arguments);
});
},
_insertSelectedPosts: function() {
var that = this,
@ -131,6 +146,9 @@ define([
className: "mailpoet_block mailpoet_posts_block mailpoet_droppable_block",
getTemplate: function() { return templates.postsBlock; },
modelEvents: {},
regions: _.extend({
postsRegion: '.mailpoet_posts_block_posts',
}, base.BlockView.prototype.regions),
onDragSubstituteBy: function() { return Module.PostsWidgetView; },
initialize: function() {
base.BlockView.prototype.initialize.apply(this, arguments);
@ -142,6 +160,13 @@ define([
this.toolsRegion.show(this.toolsView);
}
this.trigger('showSettings');
var ContainerView = App.getBlockTypeView('container'),
renderOptions = {
disableTextEditor: true,
disableDragAndDrop: true,
};
this.postsRegion.show(new ContainerView({ model: this.model.get('_transformedPosts'), renderOptions: renderOptions }));
},
notifyAboutSelf: function() {
return this;
@ -197,8 +222,8 @@ define([
},
switchToDisplayOptions: function() {
// Switch content view
this.$('.mailpoet_settings_posts_selection').addClass('mailpoet_hidden');
this.$('.mailpoet_settings_posts_display_options').removeClass('mailpoet_hidden');
this.$('.mailpoet_settings_posts_selection').addClass('mailpoet_closed');
this.$('.mailpoet_settings_posts_display_options').removeClass('mailpoet_closed');
// Switch controls
this.$('.mailpoet_settings_posts_show_display_options').addClass('mailpoet_hidden');
@ -206,8 +231,8 @@ define([
},
switchToPostSelection: function() {
// Switch content view
this.$('.mailpoet_settings_posts_display_options').addClass('mailpoet_hidden');
this.$('.mailpoet_settings_posts_selection').removeClass('mailpoet_hidden');
this.$('.mailpoet_settings_posts_display_options').addClass('mailpoet_closed');
this.$('.mailpoet_settings_posts_selection').removeClass('mailpoet_closed');
// Switch controls
this.$('.mailpoet_settings_posts_show_post_selection').addClass('mailpoet_hidden');
@ -216,6 +241,7 @@ define([
insertPosts: function() {
this.model.trigger('insertSelectedPosts');
this.model.destroy();
this.close();
},
});
@ -307,11 +333,6 @@ define([
},
}).trigger( 'change' );
},
onBeforeDestroy: function() {
base.BlockSettingsView.prototype.onBeforeDestroy.apply(this, arguments);
// Force close select2 if it hasn't closed yet
this.$('.mailpoet_posts_categories_and_tags').select2('close');
},
changeField: function(field, event) {
this.model.set(field, jQuery(event.target).val());
},
@ -323,7 +344,7 @@ define([
_.each(postTypes, function(type) {
select.append(jQuery('<option>', {
value: type.name,
text: type.labels.singular_name,
text: type.label,
}));
});
select.val(selectedValue);

View File

@ -103,7 +103,8 @@ define([
getTemplate: function() { return templates.socialBlock; },
childViewContainer: '.mailpoet_social',
modelEvents: {
'change': 'render'
'change': 'render',
'delete': 'deleteBlock',
},
events: {
"mouseover": "showTools",
@ -145,6 +146,10 @@ define([
arguments[0].collection = arguments[0].model.get('icons');
Marionette.CompositeView.apply(this, arguments);
},
initialize: function() {
this.on('dom:refresh', this.showBlock, this);
this._isFirstRender = true;
},
// Determines which view type should be used for a child
childView: SocialIconView,
templateHelpers: function() {
@ -194,6 +199,34 @@ define([
this.regionManager.destroy();
_.extend(this, this._buildRegions(this.regions));
},
showBlock: function() {
if (this._isFirstRender) {
this.transitionIn();
this._isFirstRender = false;
}
},
deleteBlock: function() {
this.transitionOut().done(function() {
this.model.destroy();
}.bind(this));
},
transitionIn: function() {
return this._transition('mailpoet_block_transition_in');
},
transitionOut: function() {
return this._transition('mailpoet_block_transition_out');
},
_transition: function(className) {
var that = this,
promise = jQuery.Deferred();
this.$el.addClass(className);
this.$el.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd animationend', function() {
that.$el.removeClass('mailpoet_block_transition_out');
promise.resolve();
});
return promise;
},
});
Module.SocialBlockToolsView = base.BlockToolsView.extend({

View File

@ -1,9 +1,14 @@
define([
'newsletter_editor/App',
'mailpoet',
'notice',
'backbone',
'backbone.marionette'
], function(App, MailPoet, Backbone, Marionette) {
'backbone.marionette',
'jquery',
'blob',
'filesaver',
'html2canvas'
], function(App, MailPoet, Notice, Backbone, Marionette, jQuery, Blob, FileSaver, html2canvas) {
"use strict";
@ -42,13 +47,51 @@ define([
});
};
Module.getThumbnail = function(element, options) {
return html2canvas(element, options || {});
};
Module.saveTemplate = function(options) {
return MailPoet.Ajax.post({
endpoint: 'newsletterTemplates',
action: 'save',
data: _.extend(options || {}, {
var that = this,
promise = jQuery.Deferred();
promise.then(function(thumbnail) {
var data = _.extend(options || {}, {
thumbnail: thumbnail.toDataURL('image/jpeg'),
body: App.getBody(),
}),
});
return MailPoet.Ajax.post({
endpoint: 'newsletterTemplates',
action: 'save',
data: data,
});
});
Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function(thumbnail) {
promise.resolve(thumbnail);
});
return promise;
};
Module.exportTemplate = function(options) {
var that = this;
return Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function(thumbnail) {
var data = _.extend(options || {}, {
thumbnail: thumbnail.toDataURL('image/jpeg'),
body: App.getBody(),
});
var blob = new Blob(
[JSON.stringify(data)],
{ type: 'application/json;charset=utf-8' }
);
FileSaver.saveAs(blob, 'template.json');
});
};
@ -62,7 +105,8 @@ define([
'click .mailpoet_save_template': 'toggleSaveAsTemplate',
'click .mailpoet_save_as_template': 'saveAsTemplate',
/* Export template */
'click .mailpoet_save_export': 'exportTemplate',
'click .mailpoet_save_export': 'toggleExportTemplate',
'click .mailpoet_export_template': 'exportTemplate',
},
initialize: function(options) {
App.getChannel().on('beforeEditorSave', this.beforeSave, this);
@ -117,12 +161,33 @@ define([
this.hideOptionContents();
},
toggleExportTemplate: function() {
this.$('.mailpoet_export_template_container').toggleClass('mailpoet_hidden');
this.toggleSaveOptions();
},
hideExportTemplate: function() {
this.$('.mailpoet_export_template_container').addClass('mailpoet_hidden');
},
exportTemplate: function() {
console.log('Exporting template');
this.hideOptionContents();
var templateName = this.$('.mailpoet_export_template_name').val(),
templateDescription = this.$('.mailpoet_export_template_description').val();
if (templateName === '') {
MailPoet.Notice.error(App.getConfig().get('translations.templateNameMissing'));
} else if (templateDescription === '') {
MailPoet.Notice.error(App.getConfig().get('translations.templateDescriptionMissing'));
} else {
console.log('Exporting template with ', templateName, templateDescription);
Module.exportTemplate({
name: templateName,
description: templateDescription,
});
this.hideExportTemplate();
}
},
hideOptionContents: function() {
this.hideSaveAsTemplate();
this.hideExportTemplate();
this.$('.mailpoet_save_options').addClass('mailpoet_hidden');
},
next: function() {

View File

@ -21,6 +21,10 @@ define(
label: 'Subject',
sortable: true
},
{
name: 'status',
label: 'Status'
},
{
name: 'segments',
label: 'Lists'
@ -112,12 +116,101 @@ define(
</a>
);
}
},
{
name: 'trash'
}
];
var NewsletterList = React.createClass({
renderItem: function(newsletter, actions) {
pauseSending: function(item) {
MailPoet.Ajax.post({
endpoint: 'sendingQueue',
action: 'pause',
data: item.id
}).done(function() {
jQuery('#resume_'+item.id).show();
jQuery('#pause_'+item.id).hide();
});
},
resumeSending: function(item) {
MailPoet.Ajax.post({
endpoint: 'sendingQueue',
action: 'resume',
data: item.id
}).done(function() {
jQuery('#pause_'+item.id).show();
jQuery('#resume_'+item.id).hide();
});
},
renderStatus: function(item) {
if(item.queue === null) {
return (
<span>Not sent yet.</span>
);
} else {
var progressClasses = classNames(
'mailpoet_progress',
{ 'mailpoet_progress_complete': item.queue.status === 'completed'}
);
// calculate percentage done
var percentage = Math.round(
(item.queue.count_processed * 100) / (item.queue.count_total)
);
var label = false;
if(item.queue.status === 'completed') {
label = (
<span>
Sent to {
item.queue.count_processed - item.queue.count_failed
} out of { item.queue.count_total }.
</span>
);
} else {
label = (
<span>
{ item.queue.count_processed } / { item.queue.count_total }
&nbsp;&nbsp;
<a
id={ 'resume_'+item.id }
className="button"
style={{ display: (item.queue.status === 'paused') ? 'inline-block': 'none' }}
href="javascript:;"
onClick={ this.resumeSending.bind(null, item) }
>Resume</a>
<a
id={ 'pause_'+item.id }
className="button mailpoet_pause"
style={{ display: (item.queue.status === null) ? 'inline-block': 'none' }}
href="javascript:;"
onClick={ this.pauseSending.bind(null, item) }
>Pause</a>
</span>
);
}
return (
<div>
<div className={ progressClasses }>
<span
className="mailpoet_progress_bar"
style={ { width: percentage + "%"} }
></span>
<span className="mailpoet_progress_label">
{ percentage + "%" }
</span>
</div>
<p style={{ textAlign:'center' }}>
{ label }
</p>
</div>
);
}
},
renderItem: function(newsletter, actions) {
var rowClasses = classNames(
'manage-column',
'column-primary',
@ -138,6 +231,9 @@ define(
</strong>
{ actions }
</td>
<td className="column" data-colname="Lists">
{ this.renderStatus(newsletter) }
</td>
<td className="column" data-colname="Lists">
{ segments }
</td>
@ -164,7 +260,8 @@ define(
columns={columns}
bulk_actions={ bulk_actions }
item_actions={ item_actions }
messages={ messages } />
messages={ messages }
auto_refresh={ true } />
</div>
);
}

View File

@ -35,7 +35,12 @@ define(
id: "mailpoet_segments",
endpoint: "segments",
multiple: true,
select2: true
filter: function(segment) {
return !!(!segment.deleted_at);
},
validation: {
'data-parsley-required': true
}
},
{
name: 'sender',
@ -43,17 +48,24 @@ define(
tip: "Name & email of yourself or your company.",
fields: [
{
name: 'from_name',
name: 'sender_name',
type: 'text',
placeholder: 'John Doe',
defaultValue: settings.from_name
defaultValue: (settings.sender !== undefined) ? settings.sender.name : '',
validation: {
'data-parsley-required': true
}
},
{
name: 'from_email',
name: 'sender_address',
type: 'text',
placeholder: 'john.doe@email.com',
defaultValue: settings.from_address
},
defaultValue: (settings.sender !== undefined) ? settings.sender.address : '',
validation: {
'data-parsley-required': true,
'data-parsley-type': 'email'
}
}
]
},
{
@ -66,20 +78,25 @@ define(
{
name: 'reply_to_name',
type: 'text',
placeholder: 'John Doe'
placeholder: 'John Doe',
defaultValue: (settings.reply_to !== undefined) ? settings.reply_to.name : '',
},
{
name: 'reply_to_email',
name: 'reply_to_address',
type: 'text',
placeholder: 'john.doe@email.com'
placeholder: 'john.doe@email.com',
defaultValue: (settings.reply_to !== undefined) ? settings.reply_to.address : ''
},
]
}
];
var messages = {
updated: function() {
MailPoet.Notice.success('The newsletter has been updated!');
onUpdate: function() {
MailPoet.Notice.success('Newsletter successfully updated!');
},
onCreate: function() {
MailPoet.Notice.success('Newsletter successfully added!');
}
};
@ -88,34 +105,43 @@ define(
Router.History
],
handleSend: function() {
MailPoet.Ajax.post({
endpoint: 'newsletters',
action: 'send',
data: {
id: this.props.params.id,
newsletter: jQuery('#mailpoet_newsletter').serializeObject(),
segments: jQuery('#mailpoet_segments').val()
}
}).done(function(response) {
if(response === true) {
this.history.pushState(null, '/');
if(jQuery('#mailpoet_newsletter').parsley().validate() === true) {
MailPoet.Ajax.post({
endpoint: 'sendingQueue',
action: 'add',
data: {
newsletter_id: this.props.params.id,
segments: jQuery('#mailpoet_segments').val()
}
}).done(function(response) {
if(response.result === true) {
this.history.pushState(null, '/');
MailPoet.Notice.success(
'The newsletter has been sent!'
);
} else {
if(response.errors) {
MailPoet.Notice.error(
response.errors.join("<br />")
MailPoet.Notice.success(
'The newsletter is being sent...'
);
} else {
MailPoet.Notice.error(
'An error occurred while trying to send. '+
'<a href="?page=mailpoet-settings">Check your settings.</a>'
);
if(response.errors) {
MailPoet.Notice.error(
response.errors.join("<br />")
);
} else {
MailPoet.Notice.error(
'An error occurred while trying to send. '+
'<a href="?page=mailpoet-settings">Check your settings.</a>'
);
}
}
}
}.bind(this));
}.bind(this));
}
},
componentDidMount: function() {
if(this.isMounted()) {
jQuery('#mailpoet_newsletter').parsley();
}
},
isValid: function() {
return (jQuery('#mailpoet_newsletter').parsley().validate());
},
render: function() {
return (
@ -129,7 +155,8 @@ define(
endpoint="newsletters"
fields={ fields }
params={ this.props.params }
messages={ messages }>
messages={ messages }
isValid={ this.isValid }>
<p className="submit">
<input

View File

@ -1,6 +1,7 @@
define(
[
'react',
'underscore',
'mailpoet',
'react-router',
'classnames',
@ -8,11 +9,67 @@ define(
],
function(
React,
_,
MailPoet,
Router,
classNames,
Breadcrumb
) {
var ImportTemplate = React.createClass({
saveTemplate: function(template) {
MailPoet.Ajax.post({
endpoint: 'newsletterTemplates',
action: 'save',
data: template
}).done(function(response) {
if(response === true) {
this.props.onImport(template);
} else {
response.map(function(error) {
MailPoet.Notice.error(error);
});
}
}.bind(this));
},
handleSubmit: function(e) {
e.preventDefault();
if (_.size(this.refs.templateFile.files) <= 0) return false;
var file = _.first(this.refs.templateFile.files),
reader = new FileReader(),
saveTemplate = this.saveTemplate;
reader.onload = function(e) {
try {
saveTemplate(JSON.parse(e.target.result));
} catch (err) {
MailPoet.Notice.error('This template file appears to be malformed. Please try another one.');
}
}.bind(this);
reader.readAsText(file);
},
render: function() {
return (
<div>
<h2>Import a template</h2>
<form onSubmit={this.handleSubmit}>
<input type="file" placeholder="Select a .json file to upload" ref="templateFile" />
<p className="submit">
<input
className="button button-primary"
type="submit"
value="Upload" />
</p>
</form>
</div>
);
},
});
var NewsletterTemplates = React.createClass({
mixins: [
Router.History
@ -42,7 +99,7 @@ define(
"MailPoet's Guide",
description:
"This is the standard template that comes with MailPoet.",
readonly: true
readonly: "1"
}
]
}
@ -62,11 +119,11 @@ define(
body: template.body
}
}).done(function(response) {
if(response === true) {
if(response.result === true) {
// TODO: Move this URL elsewhere
window.location = 'admin.php?page=mailpoet-newsletter-editor&id=' + this.props.params.id;
} else {
response.map(function(error) {
response.errors.map(function(error) {
MailPoet.Notice.error(error);
});
}
@ -93,6 +150,16 @@ define(
this.setState({ loading: false });
}
},
handleShowTemplate: function(template) {
MailPoet.Modal.popup({
title: template.name,
template: '<img src="{{ thumbnail }}" />',
data: template,
});
},
handleTemplateImport: function() {
this.getTemplates();
},
render: function() {
var templates = this.state.templates.map(function(template, index) {
var deleteLink = (
@ -104,11 +171,22 @@ define(
Delete
</a>
</div>
);
), thumbnail = '';
if (typeof template.thumbnail === 'string'
&& template.thumbnail.length > 0) {
thumbnail = (
<a href="javascript:;" onClick={this.handleShowTemplate.bind(null, template)}>
<img src={ template.thumbnail } />
<div className="mailpoet_overlay"></div>
</a>
);
}
return (
<li key={ 'template-'+index }>
<div className="mailpoet_thumbnail">
{ thumbnail }
</div>
<div className="mailpoet_description">
@ -132,7 +210,7 @@ define(
Preview
</a>
</div>
{ (template.readonly) ? false : deleteLink }
{ (template.readonly === "1") ? false : deleteLink }
</li>
);
}.bind(this));
@ -152,6 +230,8 @@ define(
<ul className={ boxClasses }>
{ templates }
</ul>
<ImportTemplate onImport={this.handleTemplateImport} />
</div>
);
}

View File

@ -47,6 +47,8 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
type: 'success',
message: '',
static: false,
hideClose: false,
id: null,
scroll: false,
timeout: 2000,
onOpen: null,
@ -60,6 +62,9 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
// clone element
this.element = jQuery('#mailpoet_notice_'+this.options.type).clone();
// add data-id to the element
if (this.options.id) this.element.attr('data-id', 'notice_' + this.options.id);
// remove id from clone
this.element.removeAttr('id');
@ -73,7 +78,6 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
}
// listen to remove event
var element = this.element;
jQuery(this.element).on('close', function() {
jQuery(this).fadeOut(200, function() {
// on close callback
@ -148,7 +152,7 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
// if the notice is not static, it has to disappear after a timeout
if(this.options.static === false) {
this.element.delay(this.options.timeout).trigger('close');
} else {
} else if (this.options.hideClose === false) {
this.element.append('<a href="javascript:;" class="mailpoet_notice_close"><span class="dashicons dashicons-dismiss"></span></a>');
this.element.find('.mailpoet_notice_close').on('click', function() {
jQuery(this).trigger('close');
@ -163,6 +167,14 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
hide: function(all) {
if(all !== undefined && all === true) {
jQuery('.mailpoet_notice:not([id])').trigger('close');
} else if (all !== undefined && jQuery.isArray(all)) {
for (var id in all) {
jQuery('[data-id="notice_' + all[id] + '"]')
.trigger('close');
}
} if (all !== undefined) {
jQuery('[data-id="notice_' + all + '"]')
.trigger('close');
} else {
jQuery('.mailpoet_notice.updated:not([id]), .mailpoet_notice.error:not([id])')
.trigger('close');
@ -188,4 +200,4 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
}, options));
}
};
});
});

View File

@ -1,88 +1,78 @@
define('public', ['mailpoet', 'jquery', 'jquery-validation'],
function(MailPoet, $) {
'use strict';
define([
'mailpoet',
'jquery',
'parsleyjs'
],
function(
MailPoet,
jQuery,
Parsley
) {
jQuery(function($) {
function isSameDomain(url) {
var link = document.createElement('a');
link.href = url;
return (window.location.hostname === link.hostname);
}
function formatData(raw) {
var data = {};
$.each(raw, function(index, value) {
if(value.name.endsWith('[]')) {
var value_name = value.name.substr(0, value.name.length - 2);
// it's an array
if(data[value_name] === undefined) {
data[value_name] = [];
}
data[value_name].push(value.value);
} else {
data[value.name] = value.value;
}
});
return data;
}
$(function() {
// setup form validation
$('form.mailpoet_form').each(function() {
$(this).validate({
submitHandler: function(form) {
var data = $(form).serializeArray() || {};
var form = $(this);
// clear messages
$(form).find('.mailpoet_message').html('');
form.parsley().on('form:submit', function(parsley) {
// check if we're on the same domain
if(isSameDomain(MailPoetForm.ajax_url) === false) {
// non ajax post request
return true;
} else {
// ajax request
MailPoet.Ajax.post({
url: MailPoetForm.ajax_url,
token: MailPoetForm.token,
endpoint: 'subscribers',
action: 'save',
data: formatData(data),
onSuccess: function(response) {
if(response !== true) {
// errors
$.each(response, function(index, error) {
$(form)
.find('.mailpoet_message')
.append('<p class="mailpoet_validate_error">'+
error+
'</p>');
});
} else {
// successfully subscribed
if(response.page !== undefined) {
// go to page
window.location.href = response.page;
} else if(response.message !== undefined) {
// display success message
$(form)
.find('.mailpoet_message')
.html('<p class="mailpoet_validate_success">'+
response.message+
'</p>');
}
var data = form.serializeObject() || {};
// reset form
$(form).trigger('reset');
}
// clear messages
form.find('.mailpoet_message').html('');
// check if we're on the same domain
if(isSameDomain(MailPoetForm.ajax_url) === false) {
// non ajax post request
return true;
} else {
// ajax request
MailPoet.Ajax.post({
url: MailPoetForm.ajax_url,
token: MailPoetForm.token,
endpoint: 'subscribers',
action: 'subscribe',
data: data
}).done(function(response) {
if(response.result !== true) {
// errors
$.each(response.errors, function(index, error) {
form
.find('.mailpoet_message')
.append('<p class="mailpoet_validate_error">'+
error+
'</p>');
});
} else {
// successfully subscribed
if(response.page !== undefined) {
// go to page
window.location.href = response.page;
} else if(response.message !== undefined) {
// display success message
form
.find('.mailpoet_message')
.html('<p class="mailpoet_validate_success">'+
response.message+
'</p>');
}
});
}
return false;
// reset form
form.trigger('reset');
// reset validation
parsley.reset();
}
});
}
return false;
});
});
});
}
);
});
});

View File

@ -26,10 +26,10 @@ define(
];
var messages = {
updated: function() {
onUpdate: function() {
MailPoet.Notice.success('Segment successfully updated!');
},
created: function() {
onCreate: function() {
MailPoet.Notice.success('Segment successfully added!');
}
};
@ -54,7 +54,7 @@ define(
fields={ fields }
params={ this.props.params }
messages={ messages }
onSuccess={ this.history.goBack } />
/>
</div>
);
}

View File

@ -1,5 +1,5 @@
import React from 'react'
import { Router, Route, Link } from 'react-router'
import { Router, Link } from 'react-router'
import jQuery from 'jquery'
import MailPoet from 'mailpoet'
@ -40,10 +40,10 @@ var columns = [
}
];
var messages = {
const messages = {
onTrash: function(response) {
if(response) {
var message = null;
let message = null;
if(~~response === 1) {
message = (
'1 segment was moved to the trash.'
@ -61,7 +61,7 @@ var messages = {
},
onDelete: function(response) {
if(response) {
var message = null;
let message = null;
if(~~response === 1) {
message = (
'1 segment was permanently deleted.'
@ -79,7 +79,7 @@ var messages = {
},
onRestore: function(response) {
if(response) {
var message = null;
let message = null;
if(~~response === 1) {
message = (
'1 segment has been restored from the trash.'
@ -97,7 +97,7 @@ var messages = {
}
};
var item_actions = [
const item_actions = [
{
name: 'edit',
label: 'Edit',
@ -121,6 +121,32 @@ var item_actions = [
);
refresh();
});
},
display: function(segment) {
return (segment.type !== 'wp_users');
}
},
{
name: 'synchronize_segment',
label: 'Update',
className: 'update',
onClick: function(item, refresh) {
MailPoet.Modal.loading(true);
MailPoet.Ajax.post({
endpoint: 'segments',
action: 'synchronize'
}).done(function(response) {
MailPoet.Modal.loading(false);
if(response === true) {
MailPoet.Notice.success(
('List "%$1s" has been synchronized.').replace('%$1s', item.name)
);
refresh();
}
});
},
display: function(segment) {
return (segment.type === 'wp_users');
}
},
{
@ -130,25 +156,25 @@ var item_actions = [
<a href={ item.subscribers_url }>View subscribers</a>
);
}
}
];
var bulk_actions = [
},
{
name: 'trash',
label: 'Trash',
onSuccess: messages.onTrash
display: function(segment) {
return (segment.type !== 'wp_users');
}
}
];
var SegmentList = React.createClass({
const bulk_actions = [
];
const SegmentList = React.createClass({
renderItem: function(segment, actions) {
var rowClasses = classNames(
'manage-column',
'column-primary',
'has-row-actions'
);
return (
<div>
<td className={ rowClasses }>

View File

@ -15,10 +15,10 @@ define(
MailPoet.Router = new (Backbone.Router.extend({
routes: {
'mta(/:method)': 'sendingMethod',
'mta(/:group)': 'sendingMethodGroup',
'(:tab)': 'tabs',
},
sendingMethod: function(method) {
sendingMethodGroup: function(group) {
// display mta tab
this.tabs('mta');
@ -30,13 +30,13 @@ define(
// hide "save settings" button
jQuery('.mailpoet_settings_submit').hide();
if(method === null) {
if(group === null) {
// show sending methods
jQuery('.mailpoet_sending_methods').fadeIn();
} else {
// hide DKIM option when using MailPoet's API
jQuery('#mailpoet_mta_dkim')[
(method === 'mailpoet')
(group === 'mailpoet')
? 'hide'
: 'show'
]();
@ -45,7 +45,7 @@ define(
jQuery('.mailpoet_sending_methods').hide();
// display selected sending method's settings
jQuery('.mailpoet_sending_method[data-method="'+ method +'"]').show();
jQuery('.mailpoet_sending_method[data-group="'+ group +'"]').show();
jQuery('#mailpoet_sending_method_setup').fadeIn();
}
},
@ -73,7 +73,7 @@ define(
}));
jQuery(document).ready(function() {
Backbone.history.start();
if (!Backbone.History.started) Backbone.history.start();
});
}
);

View File

@ -37,14 +37,25 @@ define(
'subscribed': 'Subscribed',
'unsubscribed': 'Unsubscribed'
}
},
{
name: 'segments',
label: 'Lists',
type: 'selection',
placeholder: "Select a list",
endpoint: "segments",
multiple: true,
filter: function(segment) {
return !!(!segment.deleted_at);
}
}
];
var messages = {
updated: function() {
onUpdate: function() {
MailPoet.Notice.success('Subscriber successfully updated!');
},
created: function() {
onCreate: function() {
MailPoet.Notice.success('Subscriber successfully added!');
}
};
@ -71,7 +82,7 @@ define(
fields={ fields }
params={ this.props.params }
messages={ messages }
onSuccess={ this.history.goBack } />
/>
</div>
);
}

View File

@ -0,0 +1,170 @@
define(
[
'underscore',
'jquery',
'mailpoet',
'handlebars',
'select2'
],
function (
_,
jQuery,
MailPoet,
Handlebars
) {
if (!jQuery("#mailpoet_subscribers_export").length) {
return;
}
jQuery(document).ready(function () {
if (!exportData.segments) {
return;
}
var subscribers_export_template =
Handlebars.compile(jQuery('#mailpoet_subscribers_export_template').html());
//render template
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(exportData));
// define reusable variables
var segmentsContainerElement = jQuery("#export_lists"),
subscriberFieldsContainerElement = jQuery("#export_columns"),
exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'),
groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'),
nextStepButton = jQuery("a.mailpoet_export_process"),
renderSegmentsAndFields = function (container, data) {
if (container.data('select2')) {
container
.html('')
.select2('destroy');
}
container
.select2({
data: data,
width: '20em',
templateResult: function (item) {
return (item.subscriberCount > 0)
? item.name + ' (' + item.subscriberCount + ')'
: item.name;
},
templateSelection: function (item) {
return (item.subscriberCount > 0)
? item.name + ' (' + item.subscriberCount + ')'
: item.name;
}
})
.on('select2:selecting', function (selectEvent) {
var selectElement = this,
selectedOptionId = selectEvent.params.args.data.id,
fieldsToExclude = [
'select',
'deselect'
];
if (_.contains(fieldsToExclude, selectedOptionId)) {
selectEvent.preventDefault();
if (selectedOptionId === 'deselect') {
jQuery(selectElement).select2('val', '');
} else {
var allOptions = [];
_.each(container.find('option'), function (field) {
if (!_.contains(fieldsToExclude, field.value)) {
allOptions.push(field.value);
}
});
jQuery(selectElement).select2('val', allOptions);
}
jQuery(selectElement).select2('close');
}
})
.on('change', function () {
if ((exportData.segments && segmentsContainerElement.select2('data').length && subscriberFieldsContainerElement.select2('data').length)
||
(!exportData.segments && subscriberFieldsContainerElement.select2('data').length)
) {
toggleNextStepButton('on');
}
else {
toggleNextStepButton('off');
}
if (segmentsContainerElement.select2('data').length > 1 && exportData.groupBySegmentOption) {
jQuery('.mailpoet_group_by_list').show();
}
else if (exportData.groupBySegmentOption) {
jQuery('.mailpoet_group_by_list').hide();
}
});
};
renderSegmentsAndFields(subscriberFieldsContainerElement, subscriberFieldsSelect2);
renderSegmentsAndFields(segmentsContainerElement, segments);
subscriberFieldsContainerElement.select2('val', [
'status',
'email',
'first_name',
'last_name'
]);
exportConfirmedOptionElement.change(function () {
var selectedSegments = segmentsContainerElement.val();
if (this.value == 1) {
exportData.exportConfirmedOption = true;
renderSegmentsAndFields(segmentsContainerElement, segmentsWithConfirmedSubscribers);
}
else {
exportData.exportConfirmedOption = false;
renderSegmentsAndFields(segmentsContainerElement, segments);
}
segmentsContainerElement.select2('val', selectedSegments);
});
function toggleNextStepButton(condition) {
var disabled = 'button-disabled';
if (condition === 'on') {
nextStepButton.removeClass(disabled);
}
else {
nextStepButton.addClass(disabled);
}
}
nextStepButton.click(function () {
if (jQuery(this).hasClass('button-disabled')) {
return;
}
MailPoet.Modal.loading(true);
MailPoet.Ajax
.post({
endpoint: 'ImportExport',
action: 'processExport',
data: JSON.stringify({
'exportConfirmedOption': exportData.exportConfirmedOption,
'exportFormatOption': jQuery(':radio[name="option_format"]:checked').val(),
'groupBySegmentOption': (groupBySegmentOptionElement.is(":visible")) ? groupBySegmentOptionElement.prop('checked') : false,
'segments': (exportData.segments) ? segmentsContainerElement.val() : false,
'subscriberFields': subscriberFieldsContainerElement.val()
})
})
.done(function (response) {
MailPoet.Modal.loading(false);
if (response.result === false) {
MailPoet.Notice.error(response.error);
} else {
resultMessage = MailPoetI18n.exportMessage
.replace('%1$s', '<strong>' + response.data.totalExported + '</strong>')
.replace('[link]', '<a href="' + response.data.exportFileURL + '" target="_blank" >')
.replace('[/link]', '</a>');
jQuery('#export_result_notice > ul > li').html(resultMessage);
jQuery('#export_result_notice').show();
window.location.href = response.data.exportFileURL;
}
})
.error(function (error) {
MailPoet.Modal.loading(false);
MailPoet.Notice.error(
MailPoetI18n.serverError + error.statusText.toLowerCase() + '.'
);
});
});
});
});

File diff suppressed because it is too large Load Diff

View File

@ -101,7 +101,12 @@ const bulk_actions = [
onSelect: function() {
let field = {
id: 'move_to_segment',
endpoint: 'segments'
endpoint: 'segments',
filter: function(segment) {
return !!(
!segment.deleted_at && segment.type === 'default'
);
}
};
return (
@ -127,7 +132,12 @@ const bulk_actions = [
onSelect: function() {
let field = {
id: 'add_to_segment',
endpoint: 'segments'
endpoint: 'segments',
filter: function(segment) {
return !!(
!segment.deleted_at && segment.type === 'default'
);
}
};
return (
@ -153,7 +163,12 @@ const bulk_actions = [
onSelect: function() {
let field = {
id: 'remove_from_segment',
endpoint: 'segments'
endpoint: 'segments',
filter: function(segment) {
return !!(
segment.type === 'default'
);
}
};
return (
@ -200,6 +215,21 @@ const bulk_actions = [
}
];
const item_actions = [
{
name: 'edit',
label: 'Edit',
link: function(item) {
return (
<Link to={ `/edit/${item.id}` }>Edit</Link>
);
}
},
{
name: 'trash'
}
];
const SubscriberList = React.createClass({
renderItem: function(subscriber, actions) {
let row_classes = classNames(
@ -270,11 +300,16 @@ const SubscriberList = React.createClass({
</div>
);
},
onGetItems: function(count) {
jQuery('#mailpoet_export_button')[(count > 0) ? 'show' : 'hide']();
},
render: function() {
return (
<div>
<h2 className="title">
Subscribers <Link className="add-new-h2" to="/new">New</Link>
<a className="add-new-h2" href="?page=mailpoet-import#step1">Import</a>
<a id="mailpoet_export_button" className="add-new-h2" href="?page=mailpoet-export">Export</a>
</h2>
<Listing
@ -284,7 +319,9 @@ const SubscriberList = React.createClass({
onRenderItem={ this.renderItem }
columns={ columns }
bulk_actions={ bulk_actions }
item_actions={ item_actions }
messages={ messages }
onGetItems={ this.onGetItems }
/>
</div>
)

View File

@ -0,0 +1,264 @@
// Generated by CoffeeScript 1.9.2
/**
@license Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net
*/
(function() {
var $, win;
$ = this.jQuery || window.jQuery;
win = $(window);
$.fn.stick_in_parent = function(opts) {
var doc, elm, enable_bottoming, fn, i, inner_scrolling, len, manual_spacer, offset_top, outer_width, parent_selector, recalc_every, sticky_class;
if (opts == null) {
opts = {};
}
sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, recalc_every = opts.recalc_every, parent_selector = opts.parent, offset_top = opts.offset_top, manual_spacer = opts.spacer, enable_bottoming = opts.bottoming;
if (offset_top == null) {
offset_top = 0;
}
if (parent_selector == null) {
parent_selector = void 0;
}
if (inner_scrolling == null) {
inner_scrolling = true;
}
if (sticky_class == null) {
sticky_class = "is_stuck";
}
doc = $(document);
if (enable_bottoming == null) {
enable_bottoming = true;
}
outer_width = function(el) {
var _el, computed, w;
if (window.getComputedStyle) {
_el = el[0];
computed = window.getComputedStyle(el[0]);
w = parseFloat(computed.getPropertyValue("width")) + parseFloat(computed.getPropertyValue("margin-left")) + parseFloat(computed.getPropertyValue("margin-right"));
if (computed.getPropertyValue("box-sizing") !== "border-box") {
w += parseFloat(computed.getPropertyValue("border-left-width")) + parseFloat(computed.getPropertyValue("border-right-width")) + parseFloat(computed.getPropertyValue("padding-left")) + parseFloat(computed.getPropertyValue("padding-right"));
}
return w;
} else {
return el.outerWidth(true);
}
};
fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) {
var bottomed, detach, fixed, last_pos, last_scroll_height, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick;
if (elm.data("sticky_kit")) {
return;
}
elm.data("sticky_kit", true);
last_scroll_height = doc.height();
parent = elm.parent();
if (parent_selector != null) {
parent = parent.closest(parent_selector);
}
if (!parent.length) {
throw "failed to find stick parent";
}
fixed = false;
bottomed = false;
spacer = manual_spacer != null ? manual_spacer && elm.closest(manual_spacer) : $("<div />");
if (spacer) {
spacer.css('position', elm.css('position'));
}
recalc = function() {
var border_top, padding_top, restore;
if (detached) {
return;
}
last_scroll_height = doc.height();
border_top = parseInt(parent.css("border-top-width"), 10);
padding_top = parseInt(parent.css("padding-top"), 10);
padding_bottom = parseInt(parent.css("padding-bottom"), 10);
parent_top = parent.offset().top + border_top + padding_top;
parent_height = parent.height();
if (fixed) {
fixed = false;
bottomed = false;
if (manual_spacer == null) {
elm.insertAfter(spacer);
spacer.detach();
}
elm.css({
position: "",
top: "",
width: "",
bottom: ""
}).removeClass(sticky_class);
restore = true;
}
top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) || 0) - offset_top;
height = elm.outerHeight(true);
el_float = elm.css("float");
if (spacer) {
spacer.css({
width: outer_width(elm),
height: height,
display: elm.css("display"),
"vertical-align": elm.css("vertical-align"),
"float": el_float
});
}
if (restore) {
return tick();
}
};
recalc();
last_pos = void 0;
offset = offset_top;
recalc_counter = recalc_every;
tick = function() {
var css, delta, recalced, scroll, will_bottom, win_height;
if (detached) {
return;
}
recalced = false;
if (recalc_counter != null) {
recalc_counter -= 1;
if (recalc_counter <= 0) {
recalc_counter = recalc_every;
recalc();
recalced = true;
}
}
if (!recalced && doc.height() !== last_scroll_height) {
recalc();
recalced = true;
}
scroll = win.scrollTop();
if (last_pos != null) {
delta = scroll - last_pos;
}
last_pos = scroll;
if (fixed) {
if (enable_bottoming) {
will_bottom = scroll + height + offset > parent_height + parent_top;
if (bottomed && !will_bottom) {
bottomed = false;
elm.css({
position: "fixed",
bottom: "",
top: offset
}).trigger("sticky_kit:unbottom");
}
}
if (scroll < top) {
fixed = false;
offset = offset_top;
if (manual_spacer == null) {
if (el_float === "left" || el_float === "right") {
elm.insertAfter(spacer);
}
spacer.detach();
}
css = {
position: "",
width: "",
top: ""
};
elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick");
}
if (inner_scrolling) {
win_height = win.height();
if (height + offset_top > win_height) {
if (!bottomed) {
offset -= delta;
offset = Math.max(win_height - height, offset);
offset = Math.min(offset_top, offset);
if (fixed) {
elm.css({
top: offset + "px"
});
}
}
}
}
} else {
if (scroll > top) {
fixed = true;
css = {
position: "fixed",
top: offset
};
css.width = elm.css("box-sizing") === "border-box" ? elm.outerWidth() + "px" : elm.width() + "px";
elm.css(css).addClass(sticky_class);
if (manual_spacer == null) {
elm.after(spacer);
if (el_float === "left" || el_float === "right") {
spacer.append(elm);
}
}
elm.trigger("sticky_kit:stick");
}
}
if (fixed && enable_bottoming) {
if (will_bottom == null) {
will_bottom = scroll + height + offset > parent_height + parent_top;
}
if (!bottomed && will_bottom) {
bottomed = true;
if (parent.css("position") === "static") {
parent.css({
position: "relative"
});
}
return elm.css({
position: "absolute",
bottom: padding_bottom,
top: "auto"
}).trigger("sticky_kit:bottom");
}
}
};
recalc_and_tick = function() {
recalc();
return tick();
};
detach = function() {
detached = true;
win.off("touchmove", tick);
win.off("scroll", tick);
win.off("resize", recalc_and_tick);
$(document.body).off("sticky_kit:recalc", recalc_and_tick);
elm.off("sticky_kit:detach", detach);
elm.removeData("sticky_kit");
elm.css({
position: "",
bottom: "",
top: "",
width: ""
});
parent.position("position", "");
if (fixed) {
if (manual_spacer == null) {
if (el_float === "left" || el_float === "right") {
elm.insertAfter(spacer);
}
spacer.remove();
}
return elm.removeClass(sticky_class);
}
};
win.on("touchmove", tick);
win.on("scroll", tick);
win.on("resize", recalc_and_tick);
$(document.body).on("sticky_kit:recalc", recalc_and_tick);
elm.on("sticky_kit:detach", detach);
return setTimeout(tick, 0);
};
for (i = 0, len = this.length; i < len; i++) {
elm = this[i];
fn($(elm));
}
return this;
};
}).call(this);

19
build
View File

@ -7,21 +7,20 @@ rm wysija-newsletters.zip;
mkdir wysija-newsletters;
# Production assets.
npm install;
./do compile:all;
# Production libraries.
rm -rf vendor;
rm composer.lock;
./composer.phar install --no-dev;
# Copy release folders.
cp -rf lang wysija-newsletters;
cp -rfL assets wysija-newsletters;
cp -rf lib wysija-newsletters;
cp -rf vendor wysija-newsletters;
cp -rf views wysija-newsletters;
rm -rf wysija-newsletters/assets/css/src;
rm -rf wysija-newsletters/assets/js/src;
cp -Rf lang wysija-newsletters;
cp -RfL assets wysija-newsletters;
cp -Rf lib wysija-newsletters;
cp -Rf vendor wysija-newsletters;
cp -Rf views wysija-newsletters;
rm -Rf wysija-newsletters/assets/css/src;
rm -Rf wysija-newsletters/assets/js/src;
# Copy release files.
cp LICENSE wysija-newsletters;
@ -37,6 +36,4 @@ zip -r wysija-newsletters.zip wysija-newsletters;
rm -rf wysija-newsletters;
# Reinstall dev dependencies.
rm composer.lock;
./composer.phar install;
./do install;

View File

@ -8,7 +8,9 @@
"tburry/pquery": "*",
"j4mie/paris": "1.5.4",
"swiftmailer/swiftmailer": "^5.4",
"phpseclib/phpseclib": "*"
"phpseclib/phpseclib": "*",
"mtdowling/cron-expression": "^1.0",
"nesbot/carbon": "^1.21"
},
"require-dev": {
"codeception/codeception": "*",

535
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
<?php
namespace MailPoet\Analytics;
class Reporter {
private $fields = array(
'Plugin Version' => 'pluginVersion',
);
function __construct() {}
function getData() {
$_this = $this;
$analytics_data = array_map(function($func) use ($_this) {
return $_this->$func();
}, $this->fields);
return $analytics_data;
}
private function pluginVersion() {
return MAILPOET_VERSION;
}
}

32
lib/Config/Analytics.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Analytics\Reporter;
use \MailPoet\Models\Setting;
if(!defined('ABSPATH')) exit;
class Analytics {
function __construct() {
}
function init() {
add_action('admin_enqueue_scripts', array($this, 'setupAdminDependencies'));
}
function setupAdminDependencies() {
if(Setting::getValue('send_analytics_now', false)) {
$analytics = new Reporter();
wp_enqueue_script(
'analytics',
Env::$assets_url . '/js/lib/analytics.js',
array(),
Env::$version
);
wp_localize_script(
'analytics',
'mailpoet_analytics_data',
$analytics->getData()
);
}
}
}

61
lib/Config/Changelog.php Normal file
View File

@ -0,0 +1,61 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Models\Setting;
class Changelog {
function init() {
$doing_ajax = (bool)(defined('DOING_AJAX') && DOING_AJAX);
// don't run any check when it's an ajax request
if($doing_ajax) {
return;
}
// don't run any check when we're not on our pages
if(
!(isset($_GET['page']))
or
(isset($_GET['page']) && strpos($_GET['page'], 'mailpoet') !== 0)
) {
return;
}
add_action(
'admin_init',
array($this, 'check')
);
}
function check() {
$version = Setting::getValue('version', null);
$redirect_url = null;
if($version === null) {
// new install
$redirect_url = admin_url('admin.php?page=mailpoet-welcome');
} else if($version !== Env::$version) {
// update
$redirect_url = admin_url('admin.php?page=mailpoet-update');
}
if($redirect_url !== null) {
// save version number
Setting::setValue('version', Env::$version);
global $wp;
$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;
}
}
}
}

View File

@ -4,53 +4,89 @@ namespace MailPoet\Config;
if(!defined('ABSPATH')) exit;
class Env {
public static $version;
public static $plugin_name;
public static $file;
public static $path;
public static $views_path;
public static $assets_path;
public static $assets_url;
public static $languages_path;
public static $lib_path;
public static $plugin_prefix;
public static $db_prefix;
public static $db_source_name;
public static $db_host;
public static $db_name;
public static $db_username;
public static $db_password;
public static $db_charset;
static $version;
static $plugin_name;
static $plugin_url;
static $plugin_path;
static $file;
static $path;
static $views_path;
static $assets_path;
static $assets_url;
static $temp_name;
static $temp_path;
static $languages_path;
static $lib_path;
static $plugin_prefix;
static $db_prefix;
static $db_source_name;
static $db_host;
static $db_socket;
static $db_port;
static $db_name;
static $db_username;
static $db_password;
static $db_charset;
public static function init($file, $version) {
static function init($file, $version) {
global $wpdb;
self::$version = $version;
self::$plugin_name = 'mailpoet';
self::$file = $file;
self::$path = dirname(self::$file);
self::$plugin_name = 'mailpoet';
self::$plugin_url = plugin_dir_url(__FILE__);
self::$views_path = self::$path . '/views';
self::$assets_path = self::$path . '/assets';
self::$assets_url = plugins_url('/assets', $file);
self::$temp_name = 'temp';
self::$temp_path = self::$path . '/' . self::$temp_name;
self::$languages_path = self::$path . '/lang';
self::$lib_path = self::$path . '/lib';
self::$plugin_prefix = 'mailpoet_';
self::$db_prefix = $wpdb->prefix . self::$plugin_prefix;
self::$db_source_name = self::dbSourceName();
self::$db_host = DB_HOST;
self::$db_port = 3306;
self::$db_socket = false;
if(preg_match('/(?=:\d+$)/', DB_HOST)) {
list(self::$db_host, self::$db_port) = explode(':', DB_HOST);
} else {
if(preg_match('/:/', DB_HOST)) {
self::$db_socket = true;
}
}
self::$db_name = DB_NAME;
self::$db_username = DB_USER;
self::$db_password = DB_PASSWORD;
self::$db_charset = $wpdb->get_charset_collate();
self::$db_source_name = self::dbSourceName(self::$db_host, self::$db_socket, self::$db_port);
}
private static function dbSourceName() {
private static function dbSourceName($host, $socket, $port) {
$source_name = array(
'mysql:host=',
DB_HOST,
(!$socket) ? 'mysql:host=' : 'mysql:unix_socket=',
$host,
';',
'port=',
$port,
';',
'dbname=',
DB_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;
}
}

56
lib/Config/Hooks.php Normal file
View File

@ -0,0 +1,56 @@
<?php
namespace MailPoet\Config;
class Hooks {
function __construct() {
}
function init() {
// WP Users synchronization
add_action(
'user_register',
'\MailPoet\Segments\WP::synchronizeUser',
1
);
add_action(
'added_existing_user',
'\MailPoet\Segments\WP::synchronizeUser',
1
);
add_action(
'profile_update',
'\MailPoet\Segments\WP::synchronizeUser',
1
);
add_action(
'delete_user',
'\MailPoet\Segments\WP::synchronizeUser',
1
);
// multisite
add_action(
'deleted_user',
'\MailPoet\Segments\WP::synchronizeUser',
1
);
add_action(
'remove_user_from_blog',
'\MailPoet\Segments\WP::synchronizeUser',
1
);
add_filter(
'image_size_names_choose',
array(
$this,
'appendImageSizes'
)
);
}
function appendImageSizes($sizes) {
return array_merge($sizes, array(
'mailpoet_newsletter_max' => __('MailPoet Newsletter'),
));
}
}

View File

@ -2,6 +2,7 @@
namespace MailPoet\Config;
use MailPoet\Models;
use MailPoet\Cron\Supervisor;
use MailPoet\Router;
if(!defined('ABSPATH')) exit;
@ -22,7 +23,13 @@ class Initializer {
$this->setupMenu();
$this->setupRouter();
$this->setupWidget();
$this->setupAnalytics();
$this->setupPermissions();
$this->setupChangelog();
$this->setupPublicAPI();
$this->runQueueSupervisor();
$this->setupHooks();
$this->setupImages();
}
function setupDB() {
@ -31,7 +38,8 @@ class Initializer {
\ORM::configure('password', Env::$db_password);
\ORM::configure('logging', WP_DEBUG);
\ORM::configure('driver_options', array(
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET TIME_ZONE = "+00:00"'
));
$subscribers = Env::$db_prefix . 'subscribers';
@ -39,6 +47,8 @@ class Initializer {
$newsletters = Env::$db_prefix . 'newsletters';
$newsletter_templates = Env::$db_prefix . 'newsletter_templates';
$segments = Env::$db_prefix . 'segments';
$filters = Env::$db_prefix . 'filters';
$segment_filter = Env::$db_prefix . 'segment_filter';
$forms = Env::$db_prefix . 'forms';
$subscriber_segment = Env::$db_prefix . 'subscriber_segment';
$newsletter_segment = Env::$db_prefix . 'newsletter_segment';
@ -46,11 +56,15 @@ class Initializer {
$subscriber_custom_field = Env::$db_prefix . 'subscriber_custom_field';
$newsletter_option_fields = Env::$db_prefix . 'newsletter_option_fields';
$newsletter_option = Env::$db_prefix . 'newsletter_option';
$sending_queues = Env::$db_prefix . 'sending_queues';
$newsletter_statistics = Env::$db_prefix . 'newsletter_statistics';
define('MP_SUBSCRIBERS_TABLE', $subscribers);
define('MP_SETTINGS_TABLE', $settings);
define('MP_NEWSLETTERS_TABLE', $newsletters);
define('MP_SEGMENTS_TABLE', $segments);
define('MP_FILTERS_TABLE', $filters);
define('MP_SEGMENT_FILTER_TABLE', $segment_filter);
define('MP_FORMS_TABLE', $forms);
define('MP_SUBSCRIBER_SEGMENT_TABLE', $subscriber_segment);
define('MP_NEWSLETTER_TEMPLATES_TABLE', $newsletter_templates);
@ -59,6 +73,8 @@ class Initializer {
define('MP_SUBSCRIBER_CUSTOM_FIELD_TABLE', $subscriber_custom_field);
define('MP_NEWSLETTER_OPTION_FIELDS_TABLE', $newsletter_option_fields);
define('MP_NEWSLETTER_OPTION_TABLE', $newsletter_option);
define('MP_SENDING_QUEUE_TABLE', $sending_queues);
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
}
function setupActivator() {
@ -94,8 +110,39 @@ class Initializer {
$widget->init();
}
function setupAnalytics() {
$widget = new Analytics();
$widget->init();
}
function setupPermissions() {
$permissions = new Permissions();
$permissions->init();
}
function setupChangelog() {
$changelog = new Changelog();
$changelog->init();
}
function setupHooks() {
$hooks = new Hooks();
$hooks->init();
}
function setupPublicAPI() {
$publicAPI = new PublicAPI();
$publicAPI->init();
}
function runQueueSupervisor() {
try {
$supervisor = new Supervisor();
$supervisor->checkDaemon();
} catch (\Exception $e) {}
}
function setupImages() {
add_image_size('mailpoet_newsletter_max', 1320);
}
}

View File

@ -1,12 +1,18 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Models\Segment;
use \MailPoet\Models\Setting;
use \MailPoet\Settings\Hosts;
use \MailPoet\Settings\Pages;
use \MailPoet\Settings\Charsets;
use \MailPoet\Util\Permissions;
use \MailPoet\Util\DKIM;
use MailPoet\Form\Block;
use MailPoet\Form\Renderer as FormRenderer;
use MailPoet\Models\CustomField;
use MailPoet\Models\Form;
use MailPoet\Models\Segment;
use MailPoet\Models\Setting;
use MailPoet\Settings\Charsets;
use MailPoet\Settings\Hosts;
use MailPoet\Settings\Pages;
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
use MailPoet\Util\DKIM;
use MailPoet\Util\Permissions;
if(!defined('ABSPATH')) exit;
@ -19,7 +25,10 @@ class Menu {
function init() {
add_action(
'admin_menu',
array($this, 'setup')
array(
$this,
'setup'
)
);
}
@ -29,7 +38,10 @@ class Menu {
'MailPoet',
'manage_options',
'mailpoet',
array($this, 'home'),
array(
$this,
'home'
),
$this->assets_url . '/img/menu_icon.png',
30
);
@ -39,7 +51,10 @@ class Menu {
__('Newsletters'),
'manage_options',
'mailpoet-newsletters',
array($this, 'newsletters')
array(
$this,
'newsletters'
)
);
add_submenu_page(
'mailpoet',
@ -47,7 +62,10 @@ class Menu {
__('Forms'),
'manage_options',
'mailpoet-forms',
array($this, 'forms')
array(
$this,
'forms'
)
);
add_submenu_page(
'mailpoet',
@ -55,7 +73,10 @@ class Menu {
__('Subscribers'),
'manage_options',
'mailpoet-subscribers',
array($this, 'subscribers')
array(
$this,
'subscribers'
)
);
add_submenu_page(
'mailpoet',
@ -63,7 +84,10 @@ class Menu {
__('Segments'),
'manage_options',
'mailpoet-segments',
array($this, 'segments')
array(
$this,
'segments'
)
);
add_submenu_page(
'mailpoet',
@ -71,32 +95,93 @@ class Menu {
__('Settings'),
'manage_options',
'mailpoet-settings',
array($this, 'settings')
array(
$this,
'settings'
)
);
add_submenu_page(
null,
__('Import'),
__('Import'),
'manage_options',
'mailpoet-import',
array(
$this,
'import'
)
);
add_submenu_page(
null,
__('Export'),
__('Export'),
'manage_options',
'mailpoet-export',
array(
$this,
'export'
)
);
// add_submenu_page(
// 'mailpoet',
// __('Newsletter editor'),
// __('Newsletter editor'),
// 'manage_options',
// 'mailpoet-newsletter-editor',
// array($this, 'newletterEditor')
// );
$this->registered_pages();
}
function registered_pages() {
global $_registered_pages;
$pages = array(
//'mailpoet-form-editor' => 'formEditor',
'mailpoet-newsletter-editor' => array($this, 'newletterForm')
add_submenu_page(
null,
__('Welcome'),
__('Welcome'),
'manage_options',
'mailpoet-welcome',
array(
$this,
'welcome'
)
);
add_submenu_page(
null,
__('Update'),
__('Update'),
'manage_options',
'mailpoet-update',
array(
$this,
'update'
)
);
add_submenu_page(
null,
__('Form editor'),
__('Form editor'),
'manage_options',
'mailpoet-form-editor',
array(
$this,
'formEditor'
)
);
add_submenu_page(
null,
__('Newsletter editor'),
__('Newsletter editor'),
'manage_options',
'mailpoet-newsletter-editor',
array(
$this,
'newletterEditor'
)
);
add_submenu_page(
'mailpoet',
__('Cron'),
__('Cron'),
'manage_options',
'mailpoet-cron',
array(
$this,
'cron'
)
);
foreach($pages as $menu_slug => $callback) {
$hookname = get_plugin_page_hookname($menu_slug, null);
if(!empty($hookname)) {
add_action($hookname, $callback);
}
$_registered_pages[$hookname] = true;
}
}
function home() {
@ -104,26 +189,56 @@ class Menu {
echo $this->renderer->render('index.html', $data);
}
function settings() {
// flags (available features on WP install)
$flags = array();
function welcome() {
global $wp;
$current_url = home_url(add_query_arg($wp->query_string, $wp->request));
$redirect_url =
(!empty($_GET['mailpoet_redirect']))
? urldecode($_GET['mailpoet_redirect'])
: wp_get_referer();
if(is_multisite()) {
// get multisite registration option
$registration = apply_filters(
'wpmu_registration_enabled',
get_site_option('registration', 'all')
);
// check if users can register
$flags['registration_enabled'] =
!(in_array($registration, array('none', 'blog')));
} else {
// check if users can register
$flags['registration_enabled'] =
(bool)get_option('users_can_register', false);
if(
$redirect_url === $current_url
or
strpos($redirect_url, 'mailpoet') === false
) {
$redirect_url = admin_url('admin.php?page=mailpoet');
}
$data = array(
'settings' => Setting::getAll(),
'current_user' => wp_get_current_user(),
'redirect_url' => $redirect_url
);
echo $this->renderer->render('welcome.html', $data);
}
function update() {
global $wp;
$current_url = home_url(add_query_arg($wp->query_string, $wp->request));
$redirect_url =
(!empty($_GET['mailpoet_redirect']))
? urldecode($_GET['mailpoet_redirect'])
: wp_get_referer();
if(
$redirect_url === $current_url
or
strpos($redirect_url, 'mailpoet') === false
) {
$redirect_url = admin_url('admin.php?page=mailpoet');
}
$data = array(
'settings' => Setting::getAll(),
'current_user' => wp_get_current_user(),
'redirect_url' => $redirect_url
);
echo $this->renderer->render('update.html', $data);
}
function settings() {
$settings = Setting::getAll();
// dkim: check if public/private keys have been generated
@ -143,9 +258,10 @@ class Menu {
$data = array(
'settings' => $settings,
'segments' => Segment::findArray(),
'segments' => Segment::getPublished()
->findArray(),
'pages' => Pages::getAll(),
'flags' => $flags,
'flags' => $this->_getFlags(),
'charsets' => Charsets::getAll(),
'current_user' => wp_get_current_user(),
'permissions' => Permissions::getAll(),
@ -158,12 +274,38 @@ class Menu {
echo $this->renderer->render('settings.html', $data);
}
private function _getFlags() {
// flags (available features on WP install)
$flags = array();
if(is_multisite()) {
// get multisite registration option
$registration = apply_filters(
'wpmu_registration_enabled',
get_site_option('registration', 'all')
);
// check if users can register
$flags['registration_enabled'] =
!(in_array($registration, array(
'none',
'blog'
)));
} else {
// check if users can register
$flags['registration_enabled'] =
(bool) get_option('users_can_register', false);
}
return $flags;
}
function subscribers() {
$data = array();
$data['segments'] = Segment::findArray();
echo $this->renderer->render('subscribers.html', $data);
echo $this->renderer->render('subscribers/subscribers.html', $data);
}
function segments() {
@ -184,20 +326,63 @@ class Menu {
$data = array();
$data['segments'] = Segment::findArray();
$settings = Setting::findArray();
$data['settings'] = array();
foreach($settings as $setting) {
$data['settings'][$setting['name']] = $setting['value'];
}
$data['settings'] = Setting::getAll();
$data['roles'] = $wp_roles->get_names();
echo $this->renderer->render('newsletters.html', $data);
}
function newletterForm() {
$data = array();
function newletterEditor() {
$custom_fields = array_map(function($field) {
return array(
'text' => $field['name'],
'shortcode' => 'field:' . $field['id'],
);
}, CustomField::findArray());
$data = array(
'customFields' => $custom_fields,
);
wp_enqueue_media();
wp_enqueue_script('tinymce-wplink', includes_url('js/tinymce/plugins/wplink/plugin.js'));
wp_enqueue_style('editor', includes_url('css/editor.css'));
echo $this->renderer->render('newsletter/form.html', $data);
}
function import() {
$import = new BootStrapMenu('import');
$data = $import->bootstrap();
echo $this->renderer->render('subscribers/importExport/import.html', $data);
}
function export() {
$export = new BootStrapMenu('export');
$data = $export->bootstrap();
echo $this->renderer->render('subscribers/importExport/export.html', $data);
}
function formEditor() {
$id = (isset($_GET['id']) ? (int) $_GET['id'] : 0);
$form = Form::findOne($id);
if($form !== false) {
$form = $form->asArray();
}
$data = array(
'form' => $form,
'pages' => Pages::getAll(),
'segments' => Segment::getPublic()
->findArray(),
'styles' => FormRenderer::getStyles($form),
'date_types' => Block\Date::getDateTypes(),
'date_formats' => Block\Date::getDateFormats()
);
echo $this->renderer->render('form/editor.html', $data);
}
function cron() {
$daemon = new \MailPoet\Cron\BootStrapMenu();
$data['daemon'] = json_encode($daemon->bootstrap());
echo $this->renderer->render('cron.html', $data);
}
}

View File

@ -21,6 +21,8 @@ class Migrator {
'subscriber_custom_field',
'newsletter_option_fields',
'newsletter_option',
'sending_queues',
'newsletter_statistics',
'forms'
);
}
@ -50,6 +52,7 @@ class Migrator {
function subscribers() {
$attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'wp_user_id bigint(20) NULL,',
'first_name tinytext NOT NULL,',
'last_name tinytext NOT NULL,',
'email varchar(150) NOT NULL,',
@ -67,7 +70,7 @@ class Migrator {
$attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(20) NOT NULL,',
'value varchar(255) NOT NULL,',
'value longtext,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id),',
@ -81,6 +84,10 @@ class Migrator {
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'subject varchar(250) NOT NULL,',
'type varchar(20) NOT NULL DEFAULT "standard",',
'sender_address varchar(150) NOT NULL,',
'sender_name varchar(150) NOT NULL,',
'reply_to_address varchar(150) NOT NULL,',
'reply_to_name varchar(150) NOT NULL,',
'preheader varchar(250) NOT NULL,',
'body longtext,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
@ -96,7 +103,9 @@ class Migrator {
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(250) NOT NULL,',
'description varchar(250) NOT NULL,',
'body longtext,',
'body LONGTEXT,',
'thumbnail LONGTEXT,',
'readonly TINYINT(1) DEFAULT 0',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id)'
@ -106,14 +115,15 @@ class Migrator {
function segments() {
$attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(90) NOT NULL,',
'description varchar(250) NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id),',
'UNIQUE KEY name (name)'
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(90) NOT NULL,',
'type varchar(90) NOT NULL DEFAULT "default",',
'description varchar(250) NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id),',
'UNIQUE KEY name (name)'
);
return $this->sqlify(__FUNCTION__, $attributes);
}
@ -123,9 +133,11 @@ class Migrator {
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'subscriber_id mediumint(9) NOT NULL,',
'segment_id mediumint(9) NOT NULL,',
'status varchar(12) NOT NULL DEFAULT "subscribed",',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id)'
'PRIMARY KEY (id),',
'UNIQUE KEY subscriber_segment (subscriber_id,segment_id)'
);
return $this->sqlify(__FUNCTION__, $attributes);
}
@ -137,7 +149,8 @@ class Migrator {
'segment_id mediumint(9) NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id)'
'PRIMARY KEY (id),',
'UNIQUE KEY newsletter_segment (newsletter_id,segment_id)'
);
return $this->sqlify(__FUNCTION__, $attributes);
}
@ -147,6 +160,7 @@ class Migrator {
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(90) NOT NULL,',
'type varchar(90) NOT NULL,',
'params longtext NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id),',
@ -163,7 +177,8 @@ class Migrator {
'value varchar(255) NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id)'
'PRIMARY KEY (id),',
'UNIQUE KEY subscriber_id_custom_field_id (subscriber_id,custom_field_id)'
);
return $this->sqlify(__FUNCTION__, $attributes);
}
@ -189,7 +204,43 @@ class Migrator {
'value varchar(255) NOT NULL,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id)'
'PRIMARY KEY (id),',
'UNIQUE KEY newsletter_id_option_field_id (newsletter_id,option_field_id)'
);
return $this->sqlify(__FUNCTION__, $attributes);
}
function sending_queues() {
$attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,',
'subscribers longtext,',
'status varchar(12) NULL DEFAULT NULL,',
'priority mediumint(9) NOT NULL DEFAULT 0,',
'count_total mediumint(9) NOT NULL DEFAULT 0,',
'count_processed mediumint(9) NOT NULL DEFAULT 0,',
'count_to_process mediumint(9) NOT NULL DEFAULT 0,',
'count_failed mediumint(9) NOT NULL DEFAULT 0,',
'processed_at TIMESTAMP NOT NULL DEFAULT 0,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
'PRIMARY KEY (id)',
);
return $this->sqlify(__FUNCTION__, $attributes);
}
function newsletter_statistics() {
$attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,',
'subscriber_id mediumint(9) NOT NULL,',
'queue_id mediumint(9) NOT NULL,',
'sent_at TIMESTAMP NOT NULL DEFAULT 0,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
'PRIMARY KEY (id)',
);
return $this->sqlify(__FUNCTION__, $attributes);
}
@ -199,6 +250,8 @@ class Migrator {
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(90) NOT NULL,',
'body longtext,',
'settings longtext,',
'styles longtext,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',

View File

@ -1,120 +1,166 @@
<?php
namespace MailPoet\Config;
if (!defined('ABSPATH')) exit;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
class Populator {
function __construct() {
$this->prefix = Env::$db_prefix;
$this->models = array(
'newsletter_option_fields',
);
}
function up() {
global $wpdb;
$_this = $this;
$populate = function($model) use($_this, $wpdb) {
$fields = $_this->$model();
$table = $_this->prefix . $model;
array_map(function($field) use ($wpdb, $table) {
$column_conditions = array_map(function($key) use ($field) {
return $key . '=' . $field[$key];
}, $field);
if ($wpdb->get_var("SELECT COUNT(*) FROM " . $table . " WHERE " . implode(' AND ', $column_conditions)) === 0) {
$wpdb->insert(
$table,
$field
);
}
}, $fields);
};
array_map(array($this, 'populate'), $this->models);
}
function newsletter_option_fields() {
return array(
array(
'name' => 'event',
'newsletter_type' => 'welcome',
),
array(
'name' => 'segment',
'newsletter_type' => 'welcome',
),
array(
'name' => 'role',
'newsletter_type' => 'welcome',
),
array(
'name' => 'afterTimeNumber',
'newsletter_type' => 'welcome',
),
array(
'name' => 'afterTimeType',
'newsletter_type' => 'welcome',
),
array(
'name' => 'intervalType',
'newsletter_type' => 'notification',
),
array(
'name' => 'timeOfDay',
'newsletter_type' => 'notification',
),
array(
'name' => 'weekDay',
'newsletter_type' => 'notification',
),
array(
'name' => 'monthDay',
'newsletter_type' => 'notification',
),
array(
'name' => 'nthWeekDay',
'newsletter_type' => 'notification',
),
);
}
private function populate($model) {
$rows = $this->$model();
$table = $this->prefix . $model;
$_this = $this;
array_map(function($row) use ($_this, $table) {
if (!$_this->rowExists($table, $row)) {
$_this->insertRow($table, $row);
}
}, $rows);
}
private function rowExists($table, $columns) {
global $wpdb;
$conditions = array_map(function($key) use ($columns) {
return $key . '=%s';
}, array_keys($columns));
return $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table WHERE " . implode(' AND ', $conditions),
array_values($columns)
)) > 0;
}
private function insertRow($table, $row) {
global $wpdb;
return $wpdb->insert(
$table,
$row
);
}
}
<?php
namespace MailPoet\Config;
use MailPoet\Config\PopulatorData\Templates\FranksRoastHouseTemplate;
use MailPoet\Config\PopulatorData\Templates\BlankTemplate;
use \MailPoet\Models\Segment;
use \MailPoet\Segments\WP;
if (!defined('ABSPATH')) exit;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
class Populator {
function __construct() {
$this->prefix = Env::$db_prefix;
$this->models = array(
'newsletter_option_fields',
'newsletter_templates',
);
}
function up() {
global $wpdb;
$_this = $this;
$populate = function($model) use($_this, $wpdb) {
$fields = $_this->$model();
$table = $_this->prefix . $model;
array_map(function($field) use ($wpdb, $table) {
$column_conditions = array_map(function($key) use ($field) {
return $key . '=' . $field[$key];
}, $field);
if ($wpdb->get_var("SELECT COUNT(*) FROM " . $table . " WHERE " . implode(' AND ', $column_conditions)) === 0) {
$wpdb->insert(
$table,
$field
);
}
}, $fields);
};
array_map(array($this, 'populate'), $this->models);
$this->createDefaultSegments();
}
private function createDefaultSegments() {
// WP Users segment
$wp_users_segment = Segment::getWPUsers();
if($wp_users_segment === false) {
// create the wp users list
$wp_users_segment = Segment::create();
$wp_users_segment->hydrate(array(
'name' => __('WordPress Users'),
'description' =>
__('The list containing all of your WordPress users.'),
'type' => 'wp_users'
));
$wp_users_segment->save();
}
// Synchronize WP Users
WP::synchronizeUsers();
// Default segment
if(Segment::where('type', 'default')->count() === 0) {
$default_segment = Segment::create();
$default_segment->hydrate(array(
'name' => __('My First List'),
'description' =>
__('The list created automatically on install of MailPoet')
));
$default_segment->save();
}
}
function newsletter_option_fields() {
return array(
array(
'name' => 'event',
'newsletter_type' => 'welcome',
),
array(
'name' => 'segment',
'newsletter_type' => 'welcome',
),
array(
'name' => 'role',
'newsletter_type' => 'welcome',
),
array(
'name' => 'afterTimeNumber',
'newsletter_type' => 'welcome',
),
array(
'name' => 'afterTimeType',
'newsletter_type' => 'welcome',
),
array(
'name' => 'intervalType',
'newsletter_type' => 'notification',
),
array(
'name' => 'timeOfDay',
'newsletter_type' => 'notification',
),
array(
'name' => 'weekDay',
'newsletter_type' => 'notification',
),
array(
'name' => 'monthDay',
'newsletter_type' => 'notification',
),
array(
'name' => 'nthWeekDay',
'newsletter_type' => 'notification',
),
);
}
private function newsletter_templates() {
return array(
(new FranksRoastHouseTemplate(Env::$assets_url))->get(),
(new BlankTemplate(Env::$assets_url))->get(),
);
}
private function populate($model) {
$rows = $this->$model();
$table = $this->prefix . $model;
$_this = $this;
array_map(function($row) use ($_this, $table) {
if (!$_this->rowExists($table, $row)) {
$_this->insertRow($table, $row);
}
}, $rows);
}
private function rowExists($table, $columns) {
global $wpdb;
$conditions = array_map(function($key) use ($columns) {
return $key . '=%s';
}, array_keys($columns));
return $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table WHERE " . implode(' AND ', $conditions),
array_values($columns)
)) > 0;
}
private function insertRow($table, $row) {
global $wpdb;
return $wpdb->insert(
$table,
$row
);
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

45
lib/Config/PublicAPI.php Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace MailPoet\Config;
use MailPoet\Cron\Daemon;
use MailPoet\Util\Helpers;
if(!defined('ABSPATH')) exit;
class PublicAPI {
function __construct() {
# http://example.com/?mailpoet-api&section=&action=&payload=
$this->api = isset($_GET['mailpoet-api']) ? true : false;
$this->section = isset($_GET['section']) ? $_GET['section'] : false;
$this->action = isset($_GET['action']) ?
Helpers::underscoreToCamelCase($_GET['action']) :
false;
$this->payload = isset($_GET['payload']) ?
json_decode(urldecode($_GET['payload']), true) :
false;
}
function init() {
if(!$this->api && !$this->section) return;
$this->_checkAndCallMethod($this, $this->section, $terminate = true);
}
function queue() {
$queue = new Daemon($this->payload);
$this->_checkAndCallMethod($queue, $this->action);
}
private function _checkAndCallMethod($class, $method, $terminate = false) {
if(!method_exists($class, $method)) {
if(!$terminate) return;
header('HTTP/1.0 404 Not Found');
exit;
}
call_user_func(
array(
$class,
$method
)
);
}
}

View File

@ -1,5 +1,6 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Models\Subscriber;
use \MailPoet\Util\Security;
if(!defined('ABSPATH')) exit;
@ -12,16 +13,39 @@ class Widget {
add_action('widgets_init', array($this, 'registerWidget'));
if(!is_admin()) {
add_action('widgets_init', array($this, 'setupActions'));
//$this->setupActions();
add_action('widgets_init', array($this, 'setupDependencies'));
} else {
add_action('widgets_init', array($this, 'setupAdminDependencies'));
}
}
function registerWidget() {
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() {
wp_enqueue_style('mailpoet_public', Env::$assets_url.'/css/public.css');
wp_enqueue_script('mailpoet_vendor',
Env::$assets_url.'/js/vendor.js',
array(),
Env::$version,
true
);
wp_enqueue_script('mailpoet_public',
Env::$assets_url.'/js/public.js',
array(),
@ -36,6 +60,28 @@ class Widget {
));
}
function setupAdminDependencies() {
if(
empty($_GET['page'])
or
isset($_GET['page']) && strpos($_GET['page'], 'mailpoet') === false
) {
wp_enqueue_script('mailpoet_vendor',
Env::$assets_url.'/js/vendor.js',
array(),
Env::$version,
true
);
wp_enqueue_script('mailpoet_admin',
Env::$assets_url.'/js/mailpoet.js',
array(),
Env::$version,
true
);
}
}
function setupActions() {
// ajax requests
add_action(
@ -55,9 +101,9 @@ class Widget {
'admin_post_mailpoet_form_subscribe',
'mailpoet_form_subscribe'
);
/*add_action(
add_action(
'init',
'mailpoet_form_subscribe'
);*/
);
}
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace MailPoet\Cron;
use Carbon\Carbon;
use MailPoet\Models\Setting;
class BootStrapMenu {
function __construct() {
$this->daemon = Setting::where('name', 'cron_daemon')
->findOne();
}
function bootStrap() {
return ($this->daemon) ?
array_merge(
array(
'timeSinceStart' =>
Carbon::createFromFormat(
'Y-m-d H:i:s',
$this->daemon->created_at,
'UTC'
)
->diffForHumans(),
'timeSinceUpdate' =>
Carbon::createFromFormat(
'Y-m-d H:i:s',
$this->daemon->updated_at,
'UTC'
)
->diffForHumans()
),
json_decode($this->daemon->value, true)
) :
"false";
}
}

132
lib/Cron/Daemon.php Normal file
View File

@ -0,0 +1,132 @@
<?php
namespace MailPoet\Cron;
use MailPoet\Cron\Workers\SendingQueue;
use MailPoet\Models\Setting;
use MailPoet\Util\Security;
require_once(ABSPATH . 'wp-includes/pluggable.php');
if(!defined('ABSPATH')) exit;
class Daemon {
function __construct($payload = array()) {
set_time_limit(0);
ignore_user_abort();
list ($this->daemon, $this->daemonData) = $this->getDaemon();
$this->refreshedToken = $this->refreshToken();
$this->payload = $payload;
$this->timer = microtime(true);
}
function start() {
if(!isset($this->payload['session'])) {
$this->abortWithError('missing session ID');
}
$this->manageSession('start');
$daemon = $this->daemon;
$daemonData = $this->daemonData;
if(!$daemon) {
$daemon = Setting::create();
$daemon->name = 'cron_daemon';
$daemonData = array(
'status' => null,
'counter' => 0
);
$daemon->value = json_encode($daemonData);
$daemon->save();
}
if($daemonData['status'] !== 'started') {
$_SESSION['cron_daemon'] = 'started';
$daemonData['status'] = 'started';
$daemonData['token'] = $this->refreshedToken;
$_SESSION['cron_daemon'] = array('result' => true);
$this->manageSession('end');
$daemon->value = json_encode($daemonData);
$daemon->save();
$this->callSelf();
} else {
$_SESSION['cron_daemon'] = array(
'result' => false,
'error' => 'already started'
);
}
$this->manageSession('end');
}
function run() {
if(!$this->daemon || $this->daemonData['status'] !== 'started') {
$this->abortWithError('not running');
}
if(!isset($this->payload['token']) ||
$this->payload['token'] !== $this->daemonData['token']
) {
$this->abortWithError('invalid token');
}
try {
$sendingQueue = new SendingQueue($this->timer);
$sendingQueue->process();
} catch(Exception $e) {
}
$elapsedTime = microtime(true) - $this->timer;
if($elapsedTime < 30) {
sleep(30 - $elapsedTime);
}
// after each execution, read daemon in case it's status was modified
list($daemon, $daemonData) = $this->getDaemon();
$daemonData['counter']++;
$daemonData['token'] = $this->refreshedToken;
$daemon->value = json_encode($daemonData);
$daemon->save();
if($daemonData['status'] === 'strated') $this->callSelf();
}
function getDaemon() {
$daemon = Setting::where('name', 'cron_daemon')
->findOne();
return array(
($daemon) ? $daemon : null,
($daemon) ? json_decode($daemon->value, true) : null
);
}
function refreshToken() {
return Security::generateRandomString();
}
function manageSession($action) {
switch($action) {
case 'start':
if(session_id()) {
session_write_close();
}
session_id($this->payload['session']);
session_start();
break;
case 'end':
session_write_close();
break;
}
}
function callSelf() {
$payload = json_encode(array('token' => $this->refreshedToken));
Supervisor::getRemoteUrl(
'/?mailpoet-api&section=queue&action=run&payload=' . urlencode($payload)
);
exit;
}
function abortWithError($error) {
wp_send_json(
array(
'result' => false,
'error' => $error
));
exit;
}
}

84
lib/Cron/Supervisor.php Normal file
View File

@ -0,0 +1,84 @@
<?php
namespace MailPoet\Cron;
use Carbon\Carbon;
use MailPoet\Config\Env;
use MailPoet\Models\Setting;
if(!defined('ABSPATH')) exit;
class Supervisor {
function __construct($forceStart = false) {
$this->forceStart = $forceStart;
if(!Env::isPluginActivated()) {
throw new \Exception('Database has not been configured.');
}
list ($this->daemon, $this->daemonData) = $this->getDaemon();
}
function checkDaemon() {
if(!$this->daemon) {
return $this->startDaemon();
}
if(!$this->forceStart && $this->daemonData['status'] === 'stopped') {
return;
}
$currentTime = Carbon::now('UTC');
$lastUpdateTime = Carbon::createFromFormat(
'Y-m-d H:i:s',
$this->daemon->updated_at, 'UTC'
);
$timeSinceLastStart = $currentTime->diffInSeconds($lastUpdateTime);
if($timeSinceLastStart < 40) return;
$this->daemonData['status'] = null;
$this->daemon->value = json_encode($this->daemonData);
$this->daemon->save();
return $this->startDaemon();
}
function startDaemon() {
if(!session_id()) session_start();
$sessionId = session_id();
session_write_close();
$_SESSION['cron_daemon'] = null;
$payload = json_encode(array('session' => $sessionId));
self::getRemoteUrl(
'/?mailpoet-api&section=queue&action=start&payload=' . urlencode($payload)
);
session_start();
$daemonStatus = $_SESSION['cron_daemon'];
unset($_SESSION['daemon']);
session_write_close();
return $daemonStatus;
}
function getDaemon() {
$daemon = Setting::where('name', 'cron_daemon')
->findOne();
$daemonData = ($daemon) ? json_decode($daemon->value, true) : false;
return array(
$daemon,
$daemonData
);
}
static function getRemoteUrl($url) {
$args = array(
'timeout' => 1,
'user-agent' => 'MailPoet (www.mailpoet.com)'
);
wp_remote_get(
self::getSiteUrl() . $url,
$args
);
}
static function getSiteUrl() {
if(preg_match('!:\d+/!', site_url())) return site_url();
preg_match('!http://(?P<host>.*?):(?P<port>\d+)!', site_url(), $server);
$fp = @fsockopen($server['host'], $server['port'], $errno, $errstr, 1);
return ($fp) ?
site_url() :
preg_replace('/(?=:\d+):\d+/', '$1', site_url());
}
}

View File

@ -0,0 +1,114 @@
<?php
namespace MailPoet\Cron\Workers;
use MailPoet\Models\Newsletter;
use MailPoet\Models\NewsletterStatistics;
use MailPoet\Models\Subscriber;
use MailPoet\Newsletter\Renderer\Renderer;
use MailPoet\Router\Mailer;
if(!defined('ABSPATH')) exit;
class SendingQueue {
function __construct($timer = false) {
$this->timer = ($timer) ? $timer : microtime(true);
}
function process() {
$queues =
\MailPoet\Models\SendingQueue::orderByDesc('priority')
->whereNull('deleted_at')
->whereNull('status')
->findResultSet();
foreach($queues as $queue) {
$newsletter = Newsletter::findOne($queue->newsletter_id);
if(!$newsletter) {
continue;
};
$newsletter = $newsletter->asArray();
$mailer = new Mailer($httpRequest = false);
if(!empty($newsletter['sender_address']) &&
!empty($newsletter['sender_name'])
) {
$mailer->fromName = $newsletter['sender_name'];
$mailer->fromEmail = $newsletter['sender_address'];
$mailer->fromNameEmail = sprintf(
'%s <%s>',
$mailer->fromName,
$mailer->fromEmail
);
}
if(!empty($newsletter['reply_to_address']) &&
!empty($newsletter['reply_to_name'])
) {
$mailer->replyToName = $newsletter['reply_to_name'];
$mailer->replyToEmail = $newsletter['reply_to_address'];
$mailer->replyToNameEmail = sprintf(
'%s <%s>',
$mailer->replyToName,
$mailer->replyToEmail
);
}
$mailer->mailer = $mailer->buildMailer();
$renderer = new Renderer(json_decode($newsletter['body'], true));
$newsletter = array(
'subject' => $newsletter['subject'],
'id' => $newsletter['id'],
'body' => array(
'html' => $renderer->renderAll(),
'text' => ''
// TODO: add text body
)
);
$subscribers = json_decode($queue->subscribers, true);
$subscribersToProcess = $subscribers['to_process'];
if(!isset($subscribers['failed'])) $subscribers['failed'] = array();
if(!isset($subscribers['processed'])) $subscribers['processed'] = array();
foreach(array_chunk($subscribersToProcess, 200) as $subscriberIds) {
$dbSubscribers = Subscriber::whereIn('id', $subscriberIds)
->findArray();
foreach($dbSubscribers as $i => $dbSubscriber) {
$this->checkExecutionTimer();
// TODO: replace shortcodes in the newsletter
$result = $mailer->mailer->send(
$newsletter,
$mailer->transformSubscriber($dbSubscriber)
);
$newsletterStatistics = NewsletterStatistics::create();
$newsletterStatistics->subscriber_id = $dbSubscriber['id'];
$newsletterStatistics->newsletter_id = $newsletter['id'];
$newsletterStatistics->queue_id = $queue->id;
$newsletterStatistics->save();
if($result) {
$subscribers['processed'][] = $dbSubscriber['id'];
} else {
$subscribers['failed'][] = $dbSubscriber['id'];
}
$subscribers['to_process'] = array_values(
array_diff(
$subscribers['to_process'],
array_merge($subscribers['processed'], $subscribers['failed'])
)
);
$queue->count_processed =
count($subscribers['processed']) + count($subscribers['failed']);
$queue->count_to_process = count($subscribers['to_process']);
$queue->count_failed = count($subscribers['failed']);
$queue->count_total =
$queue->count_processed + $queue->count_to_process;
if(!$queue->count_to_process) {
$queue->processed_at = date('Y-m-d H:i:s');
$queue->status = 'completed';
}
$queue->subscribers = json_encode($subscribers);
$queue->save();
}
}
}
}
function checkExecutionTimer() {
$elapsedTime = microtime(true) - $this->timer;
if($elapsedTime >= 28) throw new \Exception('Maximum execution time reached.');
}
}

103
lib/Form/Block/Base.php Normal file
View File

@ -0,0 +1,103 @@
<?php
namespace MailPoet\Form\Block;
abstract class Base {
protected static function getInputValidation($block) {
$rules = array();
if($block['id'] === 'email') {
$rules['required'] = true;
$rules['error-message'] = __('You need to specify a valid email address');
}
if($block['id'] === 'segments') {
$rules['required'] = true;
$rules['mincheck'] = 1;
$rules['error-message'] = __('You need to select a list');
}
if(!empty($block['params']['required'])) {
$rules['required'] = true;
}
if(!empty($block['params']['validate'])) {
if($block['params']['validate'] === 'phone') {
$rules['pattern'] = "^[\d\+\-\.\(\)\/\s]*$";
$rules['error-message'] = __('You need to specify a valid phone number');
} else {
$rules['type'] = $block['params']['validate'];
}
}
$validation = '';
if(!empty($rules)) {
$rules = array_unique($rules);
foreach($rules as $rule => $value) {
if(is_bool($value)) {
$value = ($value) ? 'true' : 'false';
}
$validation .= 'data-parsley-'.$rule.'="'.$value.'"';
}
}
return $validation;
}
protected static function renderLabel($block) {
$html = '';
if(
isset($block['params']['label_within'])
&& $block['params']['label_within']
) {
return $html;
}
if(isset($block['params']['label'])
&& strlen(trim($block['params']['label'])) > 0) {
$html .= '<label class="mailpoet_'.$block['type'].'_label">';
$html .= $block['params']['label'];
if(isset($block['params']['required']) && $block['params']['required']) {
$html .= ' <span class="mailpoet_required">*</span>';
}
$html .= '</label>';
}
return $html;
}
protected static function renderInputPlaceholder($block) {
$html = '';
// if the label is displayed as a placeholder,
if(
isset($block['params']['label_within'])
&& $block['params']['label_within']
) {
// display only label
$html .= ' placeholder="';
$html .= static::getFieldLabel($block);
// add an asterisk if it's a required field
if(isset($block['params']['required']) && $block['params']['required']) {
$html .= ' *';
}
$html .= '" ';
}
return $html;
}
// return field name depending on block data
protected static function getFieldName($block = array()) {
return $block['id'];
}
protected static function getFieldLabel($block = array()) {
return (isset($block['params']['label'])
&& strlen(trim($block['params']['label'])) > 0)
? trim($block['params']['label']) : '';
}
protected static function getFieldValue($block = array()) {
return (isset($block['params']['value'])
&& strlen(trim($block['params']['value'])) > 0)
? trim($block['params']['value']) : '';
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace MailPoet\Form\Block;
class Checkbox extends Base {
static function render($block) {
$html = '';
$field_name = static::getFieldName($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 .= static::renderLabel($block);
foreach($block['params']['values'] as $option) {
$html .= '<label class="mailpoet_checkbox_label">';
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
$html .= 'name="'.$field_name.'" ';
$html .= 'value="1" ';
$html .= (isset($option['is_checked']) && $option['is_checked'])
? 'checked="checked"' : '';
$html .= $field_validation;
$html .= ' />'.$option['value'];
$html .= '</label>';
}
$html .= '</p>';
return $html;
}
}

155
lib/Form/Block/Date.php Normal file
View File

@ -0,0 +1,155 @@
<?php
namespace MailPoet\Form\Block;
class Date extends Base {
static function render($block) {
$html = '';
$html .= '<p class="mailpoet_paragraph">';
$html .= static::renderLabel($block);
$html .= static::renderDateSelect($block);
$html .= '</p>';
return $html;
}
private static function renderDateSelect($block = array()) {
$html = '';
$field_name = static::getFieldName($block);
$field_validation = static::getInputValidation($block);
$date_formats = static::getDateFormats();
// automatically select first date format
$date_format = $date_formats[$block['params']['date_type']][0];
// set date format if specified
if(isset($block['params']['date_format'])
&& strlen(trim($block['params']['date_format'])) > 0) {
$date_format = $block['params']['date_format'];
}
// generate an array of selectors based on date format
$date_selectors = explode('/', $date_format);
foreach($date_selectors as $date_selector) {
if($date_selector === 'dd') {
$html .= '<select class="mailpoet_date_day" ';
$html .= 'name="'.$field_name.'[day]" placeholder="'.__('Day').'">';
$html .= static::getDays($block);
$html .= '</select>';
} else if($date_selector === 'mm') {
$html .= '<select class="mailpoet_date_month" ';
$html .= 'name="'.$field_name.'[month]" placeholder="'.__('Month').'">';
$html .= static::getMonths($block);
$html .= '</select>';
} else if($date_selector === 'yyyy') {
$html .= '<select class="mailpoet_date_year" ';
$html .= 'name="'.$field_name.'[year]" placeholder="'.__('Year').'">';
$html .= static::getYears($block);
$html .= '</select>';
}
}
return $html;
}
static function getDateTypes() {
return array(
'year_month_day' => __('Year, month, day'),
'year_month' => __('Year, month'),
'month' => __('Month (January, February,...)'),
'year' => __('Year')
);
}
static function getDateFormats() {
return array(
'year_month_day' => array('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy/mm/dd'),
'year_month' => array('mm/yyyy', 'yyyy/mm'),
'year' => array('yyyy'),
'month' => array('mm')
);
}
static function getMonthNames() {
return array(__('January'), __('February'), __('March'), __('April'),
__('May'), __('June'), __('July'), __('August'), __('September'),
__('October'), __('November'), __('December')
);
}
static function getMonths($block = array()) {
$defaults = array(
'selected' => null
);
// is default today
if(!empty($block['params']['is_default_today'])) {
$defaults['selected'] = (int)strftime('%m');
}
// merge block with defaults
$block = array_merge($defaults, $block);
$month_names = static::getMonthNames();
$html = '';
for($i = 1; $i < 13; $i++) {
$is_selected = ($i === $block['selected']) ? 'selected="selected"' : '';
$html .= '<option value="'.$i.'" '.$is_selected.'>';
$html .= $month_names[$i - 1];
$html .= '</option>';
}
return $html;
}
static function getYears($block = array()) {
$defaults = array(
'selected' => null,
'from' => (int)strftime('%Y') - 100,
'to' => (int)strftime('%Y')
);
// is default today
if(!empty($block['params']['is_default_today'])) {
$defaults['selected'] = (int)strftime('%Y');
}
// merge block with defaults
$block = array_merge($defaults, $block);
$html = '';
// return years as an array
for($i = (int)$block['to']; $i > (int)($block['from'] - 1); $i--) {
$is_selected = ($i === $block['selected']) ? 'selected="selected"' : '';
$html .= '<option value="'.$i.'" '.$is_selected.'>'.$i.'</option>';
}
return $html;
}
static function getDays($block = array()) {
$defaults = array(
'selected' => null
);
// is default today
if(!empty($block['params']['is_default_today'])) {
$defaults['selected'] = (int)strftime('%d');
}
// merge block with defaults
$block = array_merge($defaults, $block);
$html = '';
// return days as an array
for($i = 1; $i < 32; $i++) {
$is_selected = ($i === $block['selected']) ? 'selected="selected"' : '';
$html .= '<option value="'.$i.'" '.$is_selected.'>'.$i.'</option>';
}
return $html;
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace MailPoet\Form\Block;
class Divider {
static function render() {
return '<hr class="mailpoet_divider" />';
}
}

23
lib/Form/Block/Html.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace MailPoet\Form\Block;
class Html {
static function render($block) {
$html = '';
if(isset($block['params']['text']) && $block['params']['text']) {
$text = html_entity_decode($block['params']['text'], ENT_QUOTES);
}
if(isset($block['params']['nl2br']) && $block['params']['nl2br']) {
$text = nl2br($text);
}
$html .= '<p class="mailpoet_paragraph">';
$html .= $text;
$html .= '</p>';
return $html;
}
}

36
lib/Form/Block/Input.php Normal file
View File

@ -0,0 +1,36 @@
<?php
namespace MailPoet\Form\Block;
class Input extends Base {
static function render($block) {
$type = 'text';
if($block['id'] === 'email') {
$type = 'email';
}
$html = '';
$html .= '<p class="mailpoet_paragraph">';
$html .= static::renderLabel($block);
$html .= '<input type="'.$type.'" class="mailpoet_input" ';
$html .= 'name="'.static::getFieldName($block).'" ';
$html .= 'title="'.static::getFieldLabel($block).'" ';
$html .= 'value="'.static::getFieldValue($block).'" ';
$html .= static::renderInputPlaceholder($block);
$html .= static::getInputValidation($block);
$html .= '/>';
$html .= '</p>';
return $html;
}
}

42
lib/Form/Block/Radio.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace MailPoet\Form\Block;
class Radio extends Base {
static function render($block) {
$html = '';
$field_name = static::getFieldName($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 .= static::renderLabel($block);
foreach($block['params']['values'] as $option) {
$html .= '<label class="mailpoet_radio_label">';
$html .= '<input type="radio" class="mailpoet_radio" ';
$html .= 'name="'.$field_name.'" ';
$html .= 'value="'.$option['value'].'" ';
$html .= (isset($option['is_checked']) && $option['is_checked'])
? 'checked="checked"' : '';
$html .= $field_validation;
$html .= ' />&nbsp;'.$option['value'];
$html .= '</label>';
}
$html .= '</p>';
return $html;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace MailPoet\Form\Block;
class Segment extends Base {
static function render($block) {
$html = '';
$field_name = static::getFieldName($block);
$field_validation = static::getInputValidation($block);
$html .= '<p class="mailpoet_paragraph">';
$html .= static::renderLabel($block);
if(!empty($block['params']['values'])) {
// display values
foreach($block['params']['values'] as $segment) {
if(!isset($segment['id']) || !isset($segment['name'])) continue;
$is_checked = (isset($segment['is_checked']) && $segment['is_checked']) ? 'checked="checked"' : '';
$html .= '<label class="mailpoet_checkbox_label">';
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
$html .= 'name="'.$field_name.'[]" ';
$html .= 'value="'.$segment['id'].'" '.$is_checked.' ';
$html .= $field_validation;
$html .= ' />'.$segment['name'];
$html .= '</label>';
}
}
$html .= '</p>';
return $html;
}
}

36
lib/Form/Block/Select.php Normal file
View File

@ -0,0 +1,36 @@
<?php
namespace MailPoet\Form\Block;
class Select extends Base {
static function render($block) {
$html = '';
$field_name = static::getFieldName($block);
$field_validation = static::getInputValidation($block);
$html .= '<p class="mailpoet_paragraph">';
$html .= static::renderLabel($block);
$html .= '<select class="mailpoet_select" name="'.$field_name.'">';
if(isset($block['params']['label_within'])
&& $block['params']['label_within']) {
$html .= '<option value="">'.static::getFieldLabel($block).'</option>';
}
foreach($block['params']['values'] as $option) {
$is_selected = (isset($option['is_checked']) && $option['is_checked'])
? 'selected="selected"' : '';
$html .= '<option value="'.$option['value'].'" '.$is_selected.'>';
$html .= $option['value'];
$html .= '</option>';
}
$html .= '</select>';
$html .= '</p>';
return $html;
}
}

Some files were not shown because too many files have changed in this diff Show More