- 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
TODO
composer.phar
vendor
tests/_output/*
tests/acceptance.suite.yml
tests/_support/_generated/*
node_modules
.env
npm-debug.log
!tasks/**
/views/cache/**
temp
.idea
wysija-newsletters.zip
tests/javascript/testBundles
assets/css/*.css
.DS_Store
TODO
composer.phar
vendor
tests/_output/*
tests/acceptance.suite.yml
tests/_support/_generated/*
node_modules
.env
npm-debug.log
!tasks/**
/views/cache/**
temp
.idea
wysija-newsletters.zip
tests/javascript/testBundles
assets/css/*.css
assets/js/*.js

View File

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

View File

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

View File

@ -1,67 +1,67 @@
define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
"use strict";
/**
* MailPoet Ajax
**/
MailPoet.Ajax = {
version: 0.1,
options: {},
defaults: {
url: null,
controller: 'dummy',
action: 'test',
data: {},
onSuccess: function(data, textStatus, xhr) {},
onError: function(xhr, textStatus, errorThrown) {}
},
get: function(options) {
this.request('get', options);
},
post: function(options) {
this.request('post', options);
},
delete: function(options) {
this.request('delete', options);
},
init: function(options) {
// merge options
this.options = jQuery.extend({}, this.defaults, options);
if(this.options.url === null) {
this.options.url = ajaxurl+'?action=mailpoet_ajax';
}
// routing
this.options.url += '&mailpoet_controller='+this.options.controller;
this.options.url += '&mailpoet_action='+this.options.action;
},
request: function(method, options) {
// set options
this.init(options);
// make ajax request depending on method
if(method === 'get') {
jQuery.get(
this.options.url,
this.options.data,
this.options.onSuccess,
'json'
);
} else {
jQuery.ajax(
this.options.url,
{
data: JSON.stringify(this.options.data),
processData: false,
contentType: "application/json; charset=utf-8",
type : method,
dataType: 'json',
success : this.options.onSuccess,
error : this.options.onError
}
);
}
}
};
});
define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
"use strict";
/**
* MailPoet Ajax
**/
MailPoet.Ajax = {
version: 0.1,
options: {},
defaults: {
url: null,
controller: 'dummy',
action: 'test',
data: {},
onSuccess: function(data, textStatus, xhr) {},
onError: function(xhr, textStatus, errorThrown) {}
},
get: function(options) {
this.request('get', options);
},
post: function(options) {
this.request('post', options);
},
delete: function(options) {
this.request('delete', options);
},
init: function(options) {
// merge options
this.options = jQuery.extend({}, this.defaults, options);
if(this.options.url === null) {
this.options.url = ajaxurl+'?action=mailpoet_ajax';
}
// routing
this.options.url += '&mailpoet_controller='+this.options.controller;
this.options.url += '&mailpoet_action='+this.options.action;
},
request: function(method, options) {
// set options
this.init(options);
// make ajax request depending on method
if(method === 'get') {
jQuery.get(
this.options.url,
this.options.data,
this.options.onSuccess,
'json'
);
} else {
jQuery.ajax(
this.options.url,
{
data: JSON.stringify(this.options.data),
processData: false,
contentType: "application/json; charset=utf-8",
type : method,
dataType: 'json',
success : this.options.onSuccess,
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) {
// Handlebars helpers
Handlebars.registerHelper('concat', function() {
var size = (arguments.length - 1),
output = '';
for(var i = 0; i < size; i++) {
output += arguments[i];
};
return output;
});
Handlebars.registerHelper('number_format', function(value, block) {
return Number(value).toLocaleString();
});
Handlebars.registerHelper('date_format', function(timestamp, block) {
if(window.moment) {
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
return;
}
// set date format
var f = block.hash.format || "MMM Do, YYYY";
// check if we passed a timestamp
if(parseInt(timestamp, 10) == timestamp) {
return moment.unix(timestamp).format(f);
} else {
return moment.utc(timestamp).format(f);
}
} else {
return timestamp;
};
});
Handlebars.registerHelper('cycle', function(value, block) {
var values = value.split(' ');
return values[block.data.index % (values.length + 1)];
});
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this);
case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this);
case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this);
case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
case '&&':
return (v1 && v2) ? options.fn(this) : options.inverse(this);
case '||':
return (v1 || v2) ? options.fn(this) : options.inverse(this);
case 'in':
var values = v2.split(',');
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
default:
return options.inverse(this);
}
});
Handlebars.registerHelper('nl2br', function(value, block) {
return value.gsub("\n", "<br />");
});
Handlebars.registerHelper('json_encode', function(value, block) {
return JSON.stringify(value);
});
Handlebars.registerHelper('json_decode', function(value, block) {
return JSON.parse(value);
});
Handlebars.registerHelper('url', function(value, block) {
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
return url + value;
});
Handlebars.registerHelper('emailFromMailto', function(value) {
var mailtoMatchingRegex = /^mailto\:/i;
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
return value.replace(mailtoMatchingRegex, '');
} else {
return value;
}
});
Handlebars.registerHelper('lookup', function(obj, field, options) {
return obj && obj[field];
});
Handlebars.registerHelper('rsa_key', function(value, block) {
// extract all lines into an array
if(value === undefined) return '';
var lines = value.trim().split("\n");
// remove header & footer
lines.shift();
lines.pop();
// return concatenated lines
return lines.join('');
});
Handlebars.registerHelper('trim', function(value, block) {
if(value === null || value === undefined) return '';
return value.trim();
});
/**
* {{ellipsis}}
* From: https://github.com/assemble/handlebars-helpers
* @author: Jon Schlinkert <http://github.com/jonschlinkert>
* Truncate the input string and removes all HTML tags
* @param {String} str The input string.
* @param {Number} limit The number of characters to limit the string.
* @param {String} append The string to append if charaters are omitted.
* @return {String} The truncated string.
*/
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
if (append === undefined) {
append = '';
}
var sanitized = str.replace(/(<([^>]+)>)/g, '');
if (sanitized.length > limit) {
return sanitized.substr(0, limit - append.length) + append;
} else {
return sanitized;
}
});
Handlebars.registerHelper('getNumber', function (string) {
return parseInt(string, 10);
});
});
define('handlebars_helpers', ['handlebars'], function(Handlebars) {
// Handlebars helpers
Handlebars.registerHelper('concat', function() {
var size = (arguments.length - 1),
output = '';
for(var i = 0; i < size; i++) {
output += arguments[i];
};
return output;
});
Handlebars.registerHelper('number_format', function(value, block) {
return Number(value).toLocaleString();
});
Handlebars.registerHelper('date_format', function(timestamp, block) {
if(window.moment) {
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
return;
}
// set date format
var f = block.hash.format || "MMM Do, YYYY";
// check if we passed a timestamp
if(parseInt(timestamp, 10) == timestamp) {
return moment.unix(timestamp).format(f);
} else {
return moment.utc(timestamp).format(f);
}
} else {
return timestamp;
};
});
Handlebars.registerHelper('cycle', function(value, block) {
var values = value.split(' ');
return values[block.data.index % (values.length + 1)];
});
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this);
case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this);
case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this);
case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
case '&&':
return (v1 && v2) ? options.fn(this) : options.inverse(this);
case '||':
return (v1 || v2) ? options.fn(this) : options.inverse(this);
case 'in':
var values = v2.split(',');
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
default:
return options.inverse(this);
}
});
Handlebars.registerHelper('nl2br', function(value, block) {
return value.gsub("\n", "<br />");
});
Handlebars.registerHelper('json_encode', function(value, block) {
return JSON.stringify(value);
});
Handlebars.registerHelper('json_decode', function(value, block) {
return JSON.parse(value);
});
Handlebars.registerHelper('url', function(value, block) {
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
return url + value;
});
Handlebars.registerHelper('emailFromMailto', function(value) {
var mailtoMatchingRegex = /^mailto\:/i;
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
return value.replace(mailtoMatchingRegex, '');
} else {
return value;
}
});
Handlebars.registerHelper('lookup', function(obj, field, options) {
return obj && obj[field];
});
Handlebars.registerHelper('rsa_key', function(value, block) {
// extract all lines into an array
if(value === undefined) return '';
var lines = value.trim().split("\n");
// remove header & footer
lines.shift();
lines.pop();
// return concatenated lines
return lines.join('');
});
Handlebars.registerHelper('trim', function(value, block) {
if(value === null || value === undefined) return '';
return value.trim();
});
/**
* {{ellipsis}}
* From: https://github.com/assemble/handlebars-helpers
* @author: Jon Schlinkert <http://github.com/jonschlinkert>
* Truncate the input string and removes all HTML tags
* @param {String} str The input string.
* @param {Number} limit The number of characters to limit the string.
* @param {String} append The string to append if charaters are omitted.
* @return {String} The truncated string.
*/
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
if (append === undefined) {
append = '';
}
var sanitized = str.replace(/(<([^>]+)>)/g, '');
if (sanitized.length > limit) {
return sanitized.substr(0, limit - append.length) + append;
} else {
return sanitized;
}
});
Handlebars.registerHelper('getNumber', function (string) {
return parseInt(string, 10);
});
});

View File

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

View File

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

92
build
View File

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

5918
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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