- Renamed Model to BaseModel (make it clear)

- Updated RoboFile to compile assets or else tests break
This commit is contained in:
Vlad
2015-08-17 15:54:48 +00:00
parent 61a372dd86
commit a26cbd6f41
22 changed files with 5370 additions and 5368 deletions

34
.gitignore vendored
View File

@ -1,18 +1,18 @@
.DS_Store .DS_Store
TODO TODO
composer.phar composer.phar
vendor vendor
tests/_output/* tests/_output/*
tests/acceptance.suite.yml tests/acceptance.suite.yml
tests/_support/_generated/* tests/_support/_generated/*
node_modules node_modules
.env .env
npm-debug.log npm-debug.log
!tasks/** !tasks/**
/views/cache/** /views/cache/**
temp temp
.idea .idea
wysija-newsletters.zip wysija-newsletters.zip
tests/javascript/testBundles tests/javascript/testBundles
assets/css/*.css assets/css/*.css
assets/js/*.js assets/js/*.js

View File

@ -73,12 +73,14 @@ class RoboFile extends \Robo\Tasks {
function testUnit($singleUnit = null) { function testUnit($singleUnit = null) {
$this->loadEnv(); $this->loadEnv();
$this->compileAll();
$this->_exec('vendor/bin/codecept build'); $this->_exec('vendor/bin/codecept build');
$this->_exec('vendor/bin/codecept run unit ' . (($singleUnit) ? $singleUnit : '')); $this->_exec('vendor/bin/codecept run unit ' . (($singleUnit) ? $singleUnit : ''));
} }
function testAcceptance() { function testAcceptance() {
$this->loadEnv(); $this->loadEnv();
$this->compileAll();
$this->_exec('vendor/bin/codecept build'); $this->_exec('vendor/bin/codecept build');
$this $this
->taskExec('phantomjs --webdriver=4444') ->taskExec('phantomjs --webdriver=4444')
@ -99,7 +101,7 @@ class RoboFile extends \Robo\Tasks {
} }
function testAll() { function testAll() {
$this->loadEnv(); $this->loadEnv();
$this->_exec('vendor/bin/codecept build'); $this->_exec('vendor/bin/codecept build');
$this $this
->taskexec('phantomjs --webdriver=4444') ->taskexec('phantomjs --webdriver=4444')

View File

@ -1,12 +1,12 @@
define('admin', [ define('admin', [
'mailpoet', 'mailpoet',
'jquery', 'jquery',
'handlebars', 'handlebars',
], function(MailPoet, jQuery, Handlebars) { ], function(MailPoet, jQuery, Handlebars) {
jQuery(function($) { jQuery(function($) {
// dom ready // dom ready
$(function() { $(function() {
}); });
}); });
}); });

View File

@ -1,67 +1,67 @@
define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
"use strict"; "use strict";
/** /**
* MailPoet Ajax * MailPoet Ajax
**/ **/
MailPoet.Ajax = { MailPoet.Ajax = {
version: 0.1, version: 0.1,
options: {}, options: {},
defaults: { defaults: {
url: null, url: null,
controller: 'dummy', controller: 'dummy',
action: 'test', action: 'test',
data: {}, data: {},
onSuccess: function(data, textStatus, xhr) {}, onSuccess: function(data, textStatus, xhr) {},
onError: function(xhr, textStatus, errorThrown) {} onError: function(xhr, textStatus, errorThrown) {}
}, },
get: function(options) { get: function(options) {
this.request('get', options); this.request('get', options);
}, },
post: function(options) { post: function(options) {
this.request('post', options); this.request('post', options);
}, },
delete: function(options) { delete: function(options) {
this.request('delete', options); this.request('delete', options);
}, },
init: function(options) { init: function(options) {
// merge options // merge options
this.options = jQuery.extend({}, this.defaults, options); this.options = jQuery.extend({}, this.defaults, options);
if(this.options.url === null) { if(this.options.url === null) {
this.options.url = ajaxurl+'?action=mailpoet_ajax'; this.options.url = ajaxurl+'?action=mailpoet_ajax';
} }
// routing // routing
this.options.url += '&mailpoet_controller='+this.options.controller; this.options.url += '&mailpoet_controller='+this.options.controller;
this.options.url += '&mailpoet_action='+this.options.action; this.options.url += '&mailpoet_action='+this.options.action;
}, },
request: function(method, options) { request: function(method, options) {
// set options // set options
this.init(options); this.init(options);
// make ajax request depending on method // make ajax request depending on method
if(method === 'get') { if(method === 'get') {
jQuery.get( jQuery.get(
this.options.url, this.options.url,
this.options.data, this.options.data,
this.options.onSuccess, this.options.onSuccess,
'json' 'json'
); );
} else { } else {
jQuery.ajax( jQuery.ajax(
this.options.url, this.options.url,
{ {
data: JSON.stringify(this.options.data), data: JSON.stringify(this.options.data),
processData: false, processData: false,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
type : method, type : method,
dataType: 'json', dataType: 'json',
success : this.options.onSuccess, success : this.options.onSuccess,
error : this.options.onError error : this.options.onError
} }
); );
} }
} }
}; };
}); });

File diff suppressed because it is too large Load Diff

View File

@ -1,142 +1,142 @@
define('handlebars_helpers', ['handlebars'], function(Handlebars) { define('handlebars_helpers', ['handlebars'], function(Handlebars) {
// Handlebars helpers // Handlebars helpers
Handlebars.registerHelper('concat', function() { Handlebars.registerHelper('concat', function() {
var size = (arguments.length - 1), var size = (arguments.length - 1),
output = ''; output = '';
for(var i = 0; i < size; i++) { for(var i = 0; i < size; i++) {
output += arguments[i]; output += arguments[i];
}; };
return output; return output;
}); });
Handlebars.registerHelper('number_format', function(value, block) { Handlebars.registerHelper('number_format', function(value, block) {
return Number(value).toLocaleString(); return Number(value).toLocaleString();
}); });
Handlebars.registerHelper('date_format', function(timestamp, block) { Handlebars.registerHelper('date_format', function(timestamp, block) {
if(window.moment) { if(window.moment) {
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) { if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
return; return;
} }
// set date format // set date format
var f = block.hash.format || "MMM Do, YYYY"; var f = block.hash.format || "MMM Do, YYYY";
// check if we passed a timestamp // check if we passed a timestamp
if(parseInt(timestamp, 10) == timestamp) { if(parseInt(timestamp, 10) == timestamp) {
return moment.unix(timestamp).format(f); return moment.unix(timestamp).format(f);
} else { } else {
return moment.utc(timestamp).format(f); return moment.utc(timestamp).format(f);
} }
} else { } else {
return timestamp; return timestamp;
}; };
}); });
Handlebars.registerHelper('cycle', function(value, block) { Handlebars.registerHelper('cycle', function(value, block) {
var values = value.split(' '); var values = value.split(' ');
return values[block.data.index % (values.length + 1)]; return values[block.data.index % (values.length + 1)];
}); });
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
switch (operator) { switch (operator) {
case '==': case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this); return (v1 == v2) ? options.fn(this) : options.inverse(this);
case '===': case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this); return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=': case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this); return (v1 != v2) ? options.fn(this) : options.inverse(this);
case '!==': case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this); return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<': case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this); return (v1 < v2) ? options.fn(this) : options.inverse(this);
case '<=': case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this); return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case '>': case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this); return (v1 > v2) ? options.fn(this) : options.inverse(this);
case '>=': case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this); return (v1 >= v2) ? options.fn(this) : options.inverse(this);
case '&&': case '&&':
return (v1 && v2) ? options.fn(this) : options.inverse(this); return (v1 && v2) ? options.fn(this) : options.inverse(this);
case '||': case '||':
return (v1 || v2) ? options.fn(this) : options.inverse(this); return (v1 || v2) ? options.fn(this) : options.inverse(this);
case 'in': case 'in':
var values = v2.split(','); var values = v2.split(',');
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this); return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
default: default:
return options.inverse(this); return options.inverse(this);
} }
}); });
Handlebars.registerHelper('nl2br', function(value, block) { Handlebars.registerHelper('nl2br', function(value, block) {
return value.gsub("\n", "<br />"); return value.gsub("\n", "<br />");
}); });
Handlebars.registerHelper('json_encode', function(value, block) { Handlebars.registerHelper('json_encode', function(value, block) {
return JSON.stringify(value); return JSON.stringify(value);
}); });
Handlebars.registerHelper('json_decode', function(value, block) { Handlebars.registerHelper('json_decode', function(value, block) {
return JSON.parse(value); return JSON.parse(value);
}); });
Handlebars.registerHelper('url', function(value, block) { Handlebars.registerHelper('url', function(value, block) {
var url = window.location.protocol + "//" + window.location.host + window.location.pathname; var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
return url + value; return url + value;
}); });
Handlebars.registerHelper('emailFromMailto', function(value) { Handlebars.registerHelper('emailFromMailto', function(value) {
var mailtoMatchingRegex = /^mailto\:/i; var mailtoMatchingRegex = /^mailto\:/i;
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) { if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
return value.replace(mailtoMatchingRegex, ''); return value.replace(mailtoMatchingRegex, '');
} else { } else {
return value; return value;
} }
}); });
Handlebars.registerHelper('lookup', function(obj, field, options) { Handlebars.registerHelper('lookup', function(obj, field, options) {
return obj && obj[field]; return obj && obj[field];
}); });
Handlebars.registerHelper('rsa_key', function(value, block) { Handlebars.registerHelper('rsa_key', function(value, block) {
// extract all lines into an array // extract all lines into an array
if(value === undefined) return ''; if(value === undefined) return '';
var lines = value.trim().split("\n"); var lines = value.trim().split("\n");
// remove header & footer // remove header & footer
lines.shift(); lines.shift();
lines.pop(); lines.pop();
// return concatenated lines // return concatenated lines
return lines.join(''); return lines.join('');
}); });
Handlebars.registerHelper('trim', function(value, block) { Handlebars.registerHelper('trim', function(value, block) {
if(value === null || value === undefined) return ''; if(value === null || value === undefined) return '';
return value.trim(); return value.trim();
}); });
/** /**
* {{ellipsis}} * {{ellipsis}}
* From: https://github.com/assemble/handlebars-helpers * From: https://github.com/assemble/handlebars-helpers
* @author: Jon Schlinkert <http://github.com/jonschlinkert> * @author: Jon Schlinkert <http://github.com/jonschlinkert>
* Truncate the input string and removes all HTML tags * Truncate the input string and removes all HTML tags
* @param {String} str The input string. * @param {String} str The input string.
* @param {Number} limit The number of characters to limit the string. * @param {Number} limit The number of characters to limit the string.
* @param {String} append The string to append if charaters are omitted. * @param {String} append The string to append if charaters are omitted.
* @return {String} The truncated string. * @return {String} The truncated string.
*/ */
Handlebars.registerHelper('ellipsis', function (str, limit, append) { Handlebars.registerHelper('ellipsis', function (str, limit, append) {
if (append === undefined) { if (append === undefined) {
append = ''; append = '';
} }
var sanitized = str.replace(/(<([^>]+)>)/g, ''); var sanitized = str.replace(/(<([^>]+)>)/g, '');
if (sanitized.length > limit) { if (sanitized.length > limit) {
return sanitized.substr(0, limit - append.length) + append; return sanitized.substr(0, limit - append.length) + append;
} else { } else {
return sanitized; return sanitized;
} }
}); });
Handlebars.registerHelper('getNumber', function (string) { Handlebars.registerHelper('getNumber', function (string) {
return parseInt(string, 10); return parseInt(string, 10);
}); });
}); });

View File

@ -1,9 +1,9 @@
define('mailpoet', [], function() { define('mailpoet', [], function() {
// A placeholder for MailPoet object // A placeholder for MailPoet object
var MailPoet = {}; var MailPoet = {};
// Expose MailPoet globally // Expose MailPoet globally
window.MailPoet = MailPoet; window.MailPoet = MailPoet;
return MailPoet; return MailPoet;
}); });

File diff suppressed because it is too large Load Diff

View File

@ -1,175 +1,175 @@
define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
"use strict"; "use strict";
/*================================================================================================== /*==================================================================================================
MailPoet Notice: MailPoet Notice:
description: Handles notices description: Handles notices
version: 0.2 version: 0.2
author: Jonathan Labreuille author: Jonathan Labreuille
company: Wysija company: Wysija
dependencies: jQuery dependencies: jQuery
Usage: Usage:
// success message (static: false) // success message (static: false)
MailPoet.Notice.success('Yatta!'); MailPoet.Notice.success('Yatta!');
// error message (static: false) // error message (static: false)
MailPoet.Notice.error('Boo!'); MailPoet.Notice.error('Boo!');
// system message (static: true) // system message (static: true)
MailPoet.Notice.system('You need to updated ASAP!'); MailPoet.Notice.system('You need to updated ASAP!');
Examples: Examples:
MailPoet.Notice.success('- success #1 -'); MailPoet.Notice.success('- success #1 -');
setTimeout(function() { setTimeout(function() {
MailPoet.Notice.success('- success #2 -'); MailPoet.Notice.success('- success #2 -');
setTimeout(function() { setTimeout(function() {
MailPoet.Notice.error('- error -'); MailPoet.Notice.error('- error -');
setTimeout(function() { setTimeout(function() {
MailPoet.Notice.system('- system -'); MailPoet.Notice.system('- system -');
setTimeout(function() { setTimeout(function() {
MailPoet.Notice.hide(); MailPoet.Notice.hide();
}, 2500); }, 2500);
}, 300); }, 300);
}, 400); }, 400);
}, 500); }, 500);
==================================================================================================*/ ==================================================================================================*/
MailPoet.Notice = { MailPoet.Notice = {
version: 0.2, version: 0.2,
// default options // default options
defaults: { defaults: {
type: 'success', type: 'success',
message: '', message: '',
static: false, static: false,
scroll: false, scroll: false,
timeout: 2000, timeout: 2000,
onOpen: null, onOpen: null,
onClose: null onClose: null
}, },
options: {}, options: {},
init: function(options) { init: function(options) {
// set options // set options
this.options = jQuery.extend({}, this.defaults, options); this.options = jQuery.extend({}, this.defaults, options);
// clone element // clone element
this.element = jQuery('#mailpoet_notice_'+this.options.type).clone(); this.element = jQuery('#mailpoet_notice_'+this.options.type).clone();
// remove id from clone // remove id from clone
this.element.removeAttr('id'); this.element.removeAttr('id');
// insert notice after its parent // insert notice after its parent
jQuery('#mailpoet_notice_'+this.options.type).after(this.element); jQuery('#mailpoet_notice_'+this.options.type).after(this.element);
// setup onClose callback // setup onClose callback
var onClose = null; var onClose = null;
if(this.options.onClose !== null) { if(this.options.onClose !== null) {
onClose = this.options.onClose; onClose = this.options.onClose;
} }
// listen to remove event // listen to remove event
var element = this.element; var element = this.element;
jQuery(this.element).on('close', function() { jQuery(this.element).on('close', function() {
jQuery(this).fadeOut(200, function() { jQuery(this).fadeOut(200, function() {
// on close callback // on close callback
if(onClose !== null) { if(onClose !== null) {
onClose(); onClose();
} }
// remove notice // remove notice
jQuery(this).remove(); jQuery(this).remove();
}); });
}.bind(this.element)); }.bind(this.element));
// listen to message event // listen to message event
jQuery(this.element).on('message', function(e, message) { jQuery(this.element).on('message', function(e, message) {
MailPoet.Notice.setMessage(message); MailPoet.Notice.setMessage(message);
}.bind(this.element)); }.bind(this.element));
return this; return this;
}, },
isHTML: function(str) { isHTML: function(str) {
var a = document.createElement('div'); var a = document.createElement('div');
a.innerHTML = str; a.innerHTML = str;
for(var c = a.childNodes, i = c.length; i--;) { for(var c = a.childNodes, i = c.length; i--;) {
if(c[i].nodeType == 1) return true; if(c[i].nodeType == 1) return true;
} }
return false; return false;
}, },
setMessage: function(message) { setMessage: function(message) {
// if it's not an html message, let's sugar coat the message with a fancy <p> // if it's not an html message, let's sugar coat the message with a fancy <p>
if(this.isHTML(message) === false) { if(this.isHTML(message) === false) {
message = '<p>'+message+'</p>'; message = '<p>'+message+'</p>';
} }
// set message // set message
return this.element.html(message); return this.element.html(message);
}, },
show: function(options) { show: function(options) {
// initialize // initialize
this.init(options); this.init(options);
// show notice // show notice
this.showNotice(); this.showNotice();
// return this; // return this;
}, },
showNotice: function() { showNotice: function() {
// set message // set message
this.setMessage(this.options.message); this.setMessage(this.options.message);
// make the notice appear // make the notice appear
this.element.fadeIn(200); this.element.fadeIn(200);
// if scroll option is enabled, scroll to the notice // if scroll option is enabled, scroll to the notice
if(this.options.scroll === true) { if(this.options.scroll === true) {
this.element.get(0).scrollIntoView(false); this.element.get(0).scrollIntoView(false);
} }
// if the notice is not static, it has to disappear after a timeout // if the notice is not static, it has to disappear after a timeout
if(this.options.static === false) { if(this.options.static === false) {
this.element.delay(this.options.timeout).trigger('close'); this.element.delay(this.options.timeout).trigger('close');
} else { } else {
this.element.append('<a href="javascript:;" class="mailpoet_notice_close"><span class="dashicons dashicons-dismiss"></span></a>'); 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() { this.element.find('.mailpoet_notice_close').on('click', function() {
jQuery(this).trigger('close'); jQuery(this).trigger('close');
}); });
} }
// call onOpen callback // call onOpen callback
if(this.options.onOpen !== null) { if(this.options.onOpen !== null) {
this.options.onOpen(this.element); this.options.onOpen(this.element);
} }
}, },
hide: function(all) { hide: function(all) {
if(all !== undefined && all === true) { if(all !== undefined && all === true) {
jQuery('.mailpoet_notice:not([id])').trigger('close'); jQuery('.mailpoet_notice:not([id])').trigger('close');
} else { } else {
jQuery('.mailpoet_notice.updated:not([id]), .mailpoet_notice.error:not([id])') jQuery('.mailpoet_notice.updated:not([id]), .mailpoet_notice.error:not([id])')
.trigger('close'); .trigger('close');
} }
}, },
error: function(message, options) { error: function(message, options) {
this.show(jQuery.extend({}, { this.show(jQuery.extend({}, {
type: 'error', type: 'error',
message: '<p>'+message+'</p>' message: '<p>'+message+'</p>'
}, options)); }, options));
}, },
success: function(message, options) { success: function(message, options) {
this.show(jQuery.extend({}, { this.show(jQuery.extend({}, {
type: 'success', type: 'success',
message: '<p>'+message+'</p>' message: '<p>'+message+'</p>'
}, options)); }, options));
}, },
system: function(message, options) { system: function(message, options) {
this.show(jQuery.extend({}, { this.show(jQuery.extend({}, {
type: 'system', type: 'system',
static: true, static: true,
message: message message: message
}, options)); }, options));
} }
}; };
}); });

View File

@ -1,6 +1,6 @@
jQuery(function($) { jQuery(function($) {
// dom ready // dom ready
$(function() { $(function() {
}); });
}); });

92
build
View File

@ -1,46 +1,46 @@
#!/bin/sh #!/bin/sh
# remove previouz build. # remove previouz build.
rm wysija-newsletters.zip; rm wysija-newsletters.zip;
# Create temp dir. # Create temp dir.
mkdir wysija-newsletters; mkdir wysija-newsletters;
# Cleanup Composer and NPM. # Cleanup Composer and NPM.
rm -rf vendor; rm -rf vendor;
rm -rf node_modules; rm -rf node_modules;
rm composer.lock; rm composer.lock;
# Install Composer and NPM deps. # Install Composer and NPM deps.
./composer.phar install --no-dev; ./composer.phar install --no-dev;
npm install --production; npm install --production;
# Copy release folders. # Copy release folders.
cp -rf lang wysija-newsletters; cp -rf lang wysija-newsletters;
cp -rf assets wysija-newsletters; cp -rf assets wysija-newsletters;
cp -rf lib wysija-newsletters; cp -rf lib wysija-newsletters;
cp -rf vendor wysija-newsletters; cp -rf vendor wysija-newsletters;
cp -rf views wysija-newsletters; cp -rf views wysija-newsletters;
# Copy release files. # Copy release files.
cp LICENSE wysija-newsletters; cp LICENSE wysija-newsletters;
cp index.php wysija-newsletters; cp index.php wysija-newsletters;
cp mailpoet.php wysija-newsletters; cp mailpoet.php wysija-newsletters;
cp readme.txt wysija-newsletters; cp readme.txt wysija-newsletters;
cp uninstall.php wysija-newsletters; cp uninstall.php wysija-newsletters;
cp webpack.config.js wysija-newsletters; cp webpack.config.js wysija-newsletters;
# Zip final release. # Zip final release.
zip -r wysija-newsletters.zip wysija-newsletters; zip -r wysija-newsletters.zip wysija-newsletters;
# Remove temp dir. # Remove temp dir.
rm -rf wysija-newsletters; rm -rf wysija-newsletters;
# Cleanup Composer and NPM. # Cleanup Composer and NPM.
rm -rf vendor; rm -rf vendor;
rm -rf node_modules; rm -rf node_modules;
rm composer.lock; rm composer.lock;
# Reinstall dev dependencies. # Reinstall dev dependencies.
./composer.phar install; ./composer.phar install;
./do install; ./do install;

5918
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,67 +1,67 @@
<?php <?php
namespace MailPoet\Config; namespace MailPoet\Config;
use MailPoet\Models; use MailPoet\Models;
use MailPoet\Router; use MailPoet\Router;
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
class Initializer { class Initializer {
public function __construct($params = array( public function __construct($params = array(
'file' => '', 'file' => '',
'version' => '1.0.0' 'version' => '1.0.0'
)) { )) {
Env::init($params['file'], $params['version']); Env::init($params['file'], $params['version']);
} }
function init() { function init() {
$this->setupDB(); $this->setupDB();
$this->setupActivator(); $this->setupActivator();
$this->setupRenderer(); $this->setupRenderer();
$this->setupLocalizer(); $this->setupLocalizer();
$this->setupMenu(); $this->setupMenu();
$this->setupRouter(); $this->setupRouter();
} }
function setupDB() { function setupDB() {
\ORM::configure(Env::$db_source_name); \ORM::configure(Env::$db_source_name);
\ORM::configure('username', Env::$db_username); \ORM::configure('username', Env::$db_username);
\ORM::configure('password', Env::$db_password); \ORM::configure('password', Env::$db_password);
$subscribers = Env::$db_prefix . 'subscribers'; $subscribers = Env::$db_prefix . 'subscribers';
$settings = Env::$db_prefix . 'settings'; $settings = Env::$db_prefix . 'settings';
$newsletters = Env::$db_prefix . 'newsletters'; $newsletters = Env::$db_prefix . 'newsletters';
define('MP_SUBSCRIBERS_TABLE', $subscribers); define('MP_SUBSCRIBERS_TABLE', $subscribers);
define('MP_SETTINGS_TABLE', $settings); define('MP_SETTINGS_TABLE', $settings);
define('MP_NEWSLETTERS_TABLE', $newsletters); define('MP_NEWSLETTERS_TABLE', $newsletters);
} }
function setupActivator() { function setupActivator() {
$activator = new Activator(); $activator = new Activator();
$activator->init(); $activator->init();
} }
function setupRenderer() { function setupRenderer() {
$renderer = new Renderer(); $renderer = new Renderer();
$this->renderer = $renderer->init(); $this->renderer = $renderer->init();
} }
function setupLocalizer() { function setupLocalizer() {
$localizer = new Localizer($this->renderer); $localizer = new Localizer($this->renderer);
$localizer->init(); $localizer->init();
} }
function setupMenu() { function setupMenu() {
$menu = new Menu( $menu = new Menu(
$this->renderer, $this->renderer,
Env::$assets_url Env::$assets_url
); );
$menu->init(); $menu->init();
} }
function setupRouter() { function setupRouter() {
$router = new Router\Router(); $router = new Router\Router();
$router->init(); $router->init();
} }
} }

View File

@ -3,7 +3,7 @@ namespace MailPoet\Models;
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
class Model extends \Sudzy\ValidModel { class BaseModel extends \Sudzy\ValidModel {
function __construct() { function __construct() {
$customValidators = new CustomValidator(); $customValidators = new CustomValidator();
parent::__construct($customValidators->init()); parent::__construct($customValidators->init());

View File

@ -3,7 +3,7 @@ namespace MailPoet\Models;
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
class Newsletter extends Model { class Newsletter extends BaseModel {
public static $_table = MP_NEWSLETTERS_TABLE; public static $_table = MP_NEWSLETTERS_TABLE;
function __construct() { function __construct() {

View File

@ -3,7 +3,7 @@ namespace MailPoet\Models;
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
class Setting extends Model { class Setting extends BaseModel {
public static $_table = MP_SETTINGS_TABLE; public static $_table = MP_SETTINGS_TABLE;
function __construct() { function __construct() {

View File

@ -3,7 +3,7 @@ namespace MailPoet\Models;
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
class Subscriber extends Model { class Subscriber extends BaseModel {
public static $_table = MP_SUBSCRIBERS_TABLE; public static $_table = MP_SUBSCRIBERS_TABLE;
function __construct() { function __construct() {

View File

@ -1,43 +1,43 @@
<?php <?php
namespace MailPoet\Router; namespace MailPoet\Router;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
class Router { class Router {
function __construct() { function __construct() {
} }
function init() { function init() {
add_action( add_action(
'admin_head', 'admin_head',
array($this, 'setToken') array($this, 'setToken')
); );
add_action( add_action(
'wp_ajax_mailpoet', 'wp_ajax_mailpoet',
array($this, 'setup') array($this, 'setup')
); );
} }
function setup() { function setup() {
$this->securityCheck(); $this->securityCheck();
$class = ucfirst($_POST['endpoint']); $class = ucfirst($_POST['endpoint']);
$endpoint = __NAMESPACE__ . "\\" . $class; $endpoint = __NAMESPACE__ . "\\" . $class;
$method = $_POST['method']; $method = $_POST['method'];
$args = $_POST['args']; $args = $_POST['args'];
$endpoint = new $endpoint(); $endpoint = new $endpoint();
$endpoint->$method($args); $endpoint->$method($args);
} }
function setToken() { function setToken() {
$token = wp_create_nonce('mailpoet_token'); $token = wp_create_nonce('mailpoet_token');
$global = '<script type="text/javascript">'; $global = '<script type="text/javascript">';
$global .= 'var mailpoet_token = "' . $token . '";'; $global .= 'var mailpoet_token = "' . $token . '";';
$global .= "</script>/n"; $global .= "</script>/n";
echo $global; echo $global;
} }
function securityCheck() { function securityCheck() {
if (!current_user_can('manage_options')) {die();} if (!current_user_can('manage_options')) {die();}
if (!wp_verify_nonce($_POST['token'], 'mailpoet_token')) {die();} if (!wp_verify_nonce($_POST['token'], 'mailpoet_token')) {die();}
} }
} }

View File

@ -1,18 +1,18 @@
<?php <?php
namespace MailPoet\Router; namespace MailPoet\Router;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
class Settings { class Settings {
function __construct() { function __construct() {
} }
function get($params) { function get($params) {
$data = array( $data = array(
'first_name' => 'John', 'first_name' => 'John',
'last_name' => 'Mailer', 'last_name' => 'Mailer',
'email' => 'john@mailpoet.com' 'email' => 'john@mailpoet.com'
); );
wp_send_json($params); wp_send_json($params);
} }
} }

View File

@ -1,32 +1,32 @@
<!-- system notices --> <!-- system notices -->
<div id="mailpoet_notice_system" class="mailpoet_notice update-nag" style="display:none;"></div> <div id="mailpoet_notice_system" class="mailpoet_notice update-nag" style="display:none;"></div>
<!-- main container --> <!-- main container -->
<div class="wrap"> <div class="wrap">
<!-- notices --> <!-- notices -->
<div id="mailpoet_notice_error" class="mailpoet_notice error" style="display:none;"></div> <div id="mailpoet_notice_error" class="mailpoet_notice error" style="display:none;"></div>
<div id="mailpoet_notice_success" class="mailpoet_notice updated" style="display:none;"></div> <div id="mailpoet_notice_success" class="mailpoet_notice updated" style="display:none;"></div>
<!-- title block --> <!-- title block -->
<% block title %><% endblock %> <% block title %><% endblock %>
<!-- content block --> <!-- content block -->
<% block content %><% endblock %> <% block content %><% endblock %>
</div> </div>
<!-- stylesheets --> <!-- stylesheets -->
<%= stylesheet( <%= stylesheet(
'admin.css' 'admin.css'
)%> )%>
<!-- rtl specific stylesheet --> <!-- rtl specific stylesheet -->
<% if is_rtl %> <% if is_rtl %>
<%= stylesheet('rtl.css') %> <%= stylesheet('rtl.css') %>
<% endif %> <% endif %>
<!-- javascripts --> <!-- javascripts -->
<%= javascript( <%= javascript(
'vendor.js', 'vendor.js',
'mailpoet.js', 'mailpoet.js',
'admin.js' 'admin.js'
)%> )%>
<!-- handlebars templates --> <!-- handlebars templates -->
<% block templates %><% endblock %> <% block templates %><% endblock %>

View File

@ -1,55 +1,55 @@
<% extends 'layout.html' %> <% extends 'layout.html' %>
<% block content %> <% block content %>
<h1><%= 'Settings' %></h1> <h1><%= 'Settings' %></h1>
<form id="mailpoet_settings" novalidate> <form id="mailpoet_settings" novalidate>
<p> <p>
<label> <label>
<%= __('First Name') %> <%= __('First Name') %>
<input type="text" name="first_name" /> <input type="text" name="first_name" />
</label> </label>
</p> </p>
<p> <p>
<label> <label>
<%= __('Last Name') %> <%= __('Last Name') %>
<input type="text" name="last_name" /> <input type="text" name="last_name" />
</label> </label>
</p> </p>
<p> <p>
<label> <label>
<%= __('Email') %> <%= __('Email') %>
<input type="email" name="email" /> <input type="email" name="email" />
</label> </label>
</p> </p>
<p> <p>
<input type="submit" class="button-secondary" <input type="submit" class="button-secondary"
value="<%= __('Submit') %>" value="<%= __('Submit') %>"
/> />
</p> </p>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
$.ajax({ $.ajax({
url: ajaxurl, url: ajaxurl,
type: 'post', type: 'post',
data: { data: {
action: 'mailpoet', action: 'mailpoet',
token: mailpoet_token, token: mailpoet_token,
endpoint: 'settings', endpoint: 'settings',
method: 'get', method: 'get',
args: { args: {
first_name: 'John' first_name: 'John'
} }
}, },
success : function(response) { success : function(response) {
console.log(response); console.log(response);
} }
}); });
}); });
</script> </script>
<% endblock %> <% endblock %>

View File

@ -1,84 +1,84 @@
var path = require('path'), var path = require('path'),
fs = require('fs'), fs = require('fs'),
webpack = require("webpack"), webpack = require("webpack"),
_ = require('underscore'), _ = require('underscore'),
baseConfig; baseConfig;
baseConfig = { baseConfig = {
name: 'main', name: 'main',
context: __dirname , context: __dirname ,
entry: { entry: {
vendor: ['handlebars', 'handlebars_helpers'], vendor: ['handlebars', 'handlebars_helpers'],
mailpoet: ['mailpoet', 'ajax', 'modal', 'notice'], mailpoet: ['mailpoet', 'ajax', 'modal', 'notice'],
admin: 'admin.js', admin: 'admin.js',
}, },
output: { output: {
path: './assets/js', path: './assets/js',
filename: '[name].js', filename: '[name].js',
}, },
plugins: [ plugins: [
new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.js") new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.js")
], ],
loaders: [ loaders: [
{ {
test: /\.js$/i, test: /\.js$/i,
loader: 'js' loader: 'js'
}, },
{ {
test: /\.css$/i, test: /\.css$/i,
loader: 'css' loader: 'css'
}, },
{ {
test: /\.jpe?g$|\.gif$|\.png$|\.svg$|\.woff$|\.ttf$|\.wav$|\.mp3$/i, test: /\.jpe?g$|\.gif$|\.png$|\.svg$|\.woff$|\.ttf$|\.wav$|\.mp3$/i,
loader: 'file' loader: 'file'
} }
], ],
resolve: { resolve: {
modulesDirectories: [ modulesDirectories: [
'node_modules', 'node_modules',
'assets/js/src', 'assets/js/src',
'assets/css/lib' 'assets/css/lib'
], ],
fallback: path.join(__dirname, 'node_modules'), fallback: path.join(__dirname, 'node_modules'),
alias: { alias: {
'handlebars': 'handlebars/dist/handlebars.js' 'handlebars': 'handlebars/dist/handlebars.js'
} }
}, },
resolveLoader: { resolveLoader: {
fallback: path.join(__dirname, 'node_modules'), fallback: path.join(__dirname, 'node_modules'),
alias: { alias: {
'hbs': 'handlebars-loader' 'hbs': 'handlebars-loader'
} }
}, },
externals: { externals: {
'jquery': 'jQuery', 'jquery': 'jQuery',
} }
}; };
module.exports = [ module.exports = [
baseConfig, baseConfig,
// Configuration specific for testing // Configuration specific for testing
_.extend({}, baseConfig, { _.extend({}, baseConfig, {
name: 'test', name: 'test',
entry: { entry: {
testAjax: 'testAjax.js', testAjax: 'testAjax.js',
}, },
output: { output: {
path: './tests/javascript/testBundles', path: './tests/javascript/testBundles',
filename: '[name].js', filename: '[name].js',
}, },
resolve: { resolve: {
modulesDirectories: [ modulesDirectories: [
'node_modules', 'node_modules',
'assets/js/src', 'assets/js/src',
'tests/javascript/newsletter_editor' 'tests/javascript/newsletter_editor'
], ],
fallback: path.join(__dirname, 'node_modules'), fallback: path.join(__dirname, 'node_modules'),
alias: { alias: {
'handlebars': 'handlebars/dist/handlebars.js' 'handlebars': 'handlebars/dist/handlebars.js'
} }
}, },
plugins: [], plugins: [],
}) })
]; ];