- Updates front router and endpoints to use dynamic methods
This commit is contained in:
@ -9,7 +9,7 @@ class Queue {
|
|||||||
const ENDPOINT = 'queue';
|
const ENDPOINT = 'queue';
|
||||||
const ACTION_RUN = 'run';
|
const ACTION_RUN = 'run';
|
||||||
|
|
||||||
static function run($data) {
|
function run($data) {
|
||||||
$queue = new Daemon($data);
|
$queue = new Daemon($data);
|
||||||
$queue->run();
|
$queue->run();
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,16 @@ if(!defined('ABSPATH')) exit;
|
|||||||
class Subscription {
|
class Subscription {
|
||||||
const ENDPOINT = 'subscription';
|
const ENDPOINT = 'subscription';
|
||||||
|
|
||||||
static function confirm($data) {
|
function confirm($data) {
|
||||||
$subscription = new UserSubscription\Pages('confirm', $data);
|
$subscription = new UserSubscription\Pages('confirm', $data);
|
||||||
$subscription->confirm();
|
$subscription->confirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
static function manage($data) {
|
function manage($data) {
|
||||||
$subscription = new UserSubscription\Pages('manage', $data);
|
$subscription = new UserSubscription\Pages('manage', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function unsubscribe($data) {
|
function unsubscribe($data) {
|
||||||
$subscription = new UserSubscription\Pages('unsubscribe', $data);
|
$subscription = new UserSubscription\Pages('unsubscribe', $data);
|
||||||
$subscription->unsubscribe();
|
$subscription->unsubscribe();
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,17 @@ class Track {
|
|||||||
const ACTION_CLICK = 'click';
|
const ACTION_CLICK = 'click';
|
||||||
const ACTION_OPEN = 'open';
|
const ACTION_OPEN = 'open';
|
||||||
|
|
||||||
static function click($data) {
|
function click($data) {
|
||||||
$click_event = new Clicks();
|
$click_event = new Clicks();
|
||||||
return $click_event->track(self::_processTrackData($data));
|
return $click_event->track(self::_processTrackData($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function open($data) {
|
function open($data) {
|
||||||
$open_event = new Opens();
|
$open_event = new Opens();
|
||||||
return $open_event->track(self::_processTrackData($data));
|
return $open_event->track(self::_processTrackData($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _processTrackData($data) {
|
function _processTrackData($data) {
|
||||||
$data = (object)$data;
|
$data = (object)$data;
|
||||||
if(empty($data->queue_id) ||
|
if(empty($data->queue_id) ||
|
||||||
empty($data->subscriber_id) ||
|
empty($data->subscriber_id) ||
|
||||||
|
@ -12,28 +12,33 @@ class ViewInBrowser {
|
|||||||
const ENDPOINT = 'view_in_browser';
|
const ENDPOINT = 'view_in_browser';
|
||||||
const ACTION_VIEW = 'view';
|
const ACTION_VIEW = 'view';
|
||||||
|
|
||||||
static function view($data) {
|
function view($data) {
|
||||||
|
$data = $this->_processBrowserPreviewData($data);
|
||||||
$view_in_browser = new NewsletterViewInBrowser();
|
$view_in_browser = new NewsletterViewInBrowser();
|
||||||
$view_in_browser->view(self::_processBrowserPreviewData($data));
|
return $this->_displayNewsletter($view_in_browser->view($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _processBrowserPreviewData($data) {
|
function _processBrowserPreviewData($data) {
|
||||||
$data = (object)$data;
|
$data = (object)$data;
|
||||||
if(empty($data->subscriber_id) ||
|
if(empty($data->subscriber_id) ||
|
||||||
empty($data->subscriber_token) ||
|
empty($data->subscriber_token) ||
|
||||||
empty($data->newsletter_id)
|
empty($data->newsletter_id)
|
||||||
) {
|
) {
|
||||||
return false;
|
$this->_abort();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
$data->newsletter = Newsletter::findOne($data->newsletter_id);
|
$data->newsletter = Newsletter::findOne($data->newsletter_id);
|
||||||
$data->subscriber = Subscriber::findOne($data->subscriber_id);
|
$data->subscriber = Subscriber::findOne($data->subscriber_id);
|
||||||
$data->queue = ($data->queue_id) ?
|
$data->queue = ($data->queue_id) ?
|
||||||
SendingQueue::findOne($data->queue_id) :
|
SendingQueue::findOne($data->queue_id) :
|
||||||
false;
|
false;
|
||||||
return self::_validateBrowserPreviewData($data);
|
return ($this->_validateBrowserPreviewData($data)) ?
|
||||||
|
$data :
|
||||||
|
$this->_abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _validateBrowserPreviewData($data) {
|
function _validateBrowserPreviewData($data) {
|
||||||
if(!$data || !$data->subscriber || !$data->newsletter) return false;
|
if(!$data || !$data->subscriber || !$data->newsletter) return false;
|
||||||
$subscriber_token_match =
|
$subscriber_token_match =
|
||||||
Subscriber::verifyToken($data->subscriber->email, $data->subscriber_token);
|
Subscriber::verifyToken($data->subscriber->email, $data->subscriber_token);
|
||||||
@ -48,4 +53,15 @@ class ViewInBrowser {
|
|||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _displayNewsletter($rendered_newsletter) {
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
echo $rendered_newsletter;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _abort() {
|
||||||
|
status_header(404);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
@ -44,6 +44,7 @@ class Front {
|
|||||||
if(!method_exists($endpoint, $action)) {
|
if(!method_exists($endpoint, $action)) {
|
||||||
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid Router action.'));
|
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid Router action.'));
|
||||||
}
|
}
|
||||||
|
$endpoint = new $endpoint();
|
||||||
call_user_func(
|
call_user_func(
|
||||||
array(
|
array(
|
||||||
$endpoint,
|
$endpoint,
|
||||||
|
Reference in New Issue
Block a user