Moved lib/API to lib/Router
- renamed lib/API/API.php to lib/Router/Front.php - updated namespaces in various file to account for namespace change
This commit is contained in:
89
lib/Router/Front.php
Normal file
89
lib/Router/Front.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Front {
|
||||
public $api_request;
|
||||
public $endpoint;
|
||||
public $action;
|
||||
public $data;
|
||||
const NAME = 'mailpoet_api';
|
||||
const RESPONSE_ERROR = 404;
|
||||
|
||||
function __construct($api_data = false) {
|
||||
$api_data = ($api_data) ? $api_data : $_GET;
|
||||
$this->api_request = isset($api_data[self::NAME]);
|
||||
$this->endpoint = isset($api_data['endpoint']) ?
|
||||
Helpers::underscoreToCamelCase($api_data['endpoint']) :
|
||||
false;
|
||||
$this->action = isset($api_data['action']) ?
|
||||
Helpers::underscoreToCamelCase($api_data['action']) :
|
||||
false;
|
||||
$this->data = isset($api_data['data']) ?
|
||||
self::decodeRequestData($api_data['data']) :
|
||||
false;
|
||||
}
|
||||
|
||||
function init() {
|
||||
$endpoint = ucfirst($this->endpoint);
|
||||
if(!$this->api_request) return;
|
||||
if(!$this->endpoint || !class_exists($endpoint)) {
|
||||
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid Router endpoint.'));
|
||||
}
|
||||
$this->callEndpoint(
|
||||
$endpoint,
|
||||
$this->action,
|
||||
$this->data
|
||||
);
|
||||
}
|
||||
|
||||
function callEndpoint($endpoint, $action, $data) {
|
||||
if(!method_exists($endpoint, $action)) {
|
||||
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid Router action.'));
|
||||
}
|
||||
call_user_func(
|
||||
array(
|
||||
$endpoint,
|
||||
$action
|
||||
),
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
static function decodeRequestData($data) {
|
||||
$data = base64_decode($data);
|
||||
|
||||
if(is_serialized($data)) {
|
||||
$data = unserialize($data);
|
||||
}
|
||||
|
||||
if(!is_array($data)) {
|
||||
$data = array();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
static function encodeRequestData($data) {
|
||||
return rtrim(base64_encode(serialize($data)), '=');
|
||||
}
|
||||
|
||||
static function buildRequest($endpoint, $action, $data) {
|
||||
$data = self::encodeRequestData($data);
|
||||
$params = array(
|
||||
self::NAME => '',
|
||||
'endpoint' => $endpoint,
|
||||
'action' => $action,
|
||||
'data' => $data
|
||||
);
|
||||
return add_query_arg($params, home_url());
|
||||
}
|
||||
|
||||
static function terminateRequest($code, $message) {
|
||||
status_header($code, $message);
|
||||
exit;
|
||||
}
|
||||
}
|
16
lib/Router/Queue.php
Normal file
16
lib/Router/Queue.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
|
||||
use MailPoet\Cron\Daemon;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Queue {
|
||||
const ENDPOINT = 'queue';
|
||||
const ACTION_RUN = 'run';
|
||||
|
||||
static function run($data) {
|
||||
$queue = new Daemon($data);
|
||||
$queue->run();
|
||||
}
|
||||
}
|
24
lib/Router/Subscription.php
Normal file
24
lib/Router/Subscription.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
|
||||
use MailPoet\Subscription as UserSubscription;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Subscription {
|
||||
const ENDPOINT = 'subscription';
|
||||
|
||||
static function confirm($data) {
|
||||
$subscription = new UserSubscription\Pages('confirm', $data);
|
||||
$subscription->confirm();
|
||||
}
|
||||
|
||||
static function manage($data) {
|
||||
$subscription = new UserSubscription\Pages('manage', $data);
|
||||
}
|
||||
|
||||
static function unsubscribe($data) {
|
||||
$subscription = new UserSubscription\Pages('unsubscribe', $data);
|
||||
$subscription->unsubscribe();
|
||||
}
|
||||
}
|
23
lib/Router/Track.php
Normal file
23
lib/Router/Track.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
|
||||
use MailPoet\Statistics\Track\Clicks;
|
||||
use MailPoet\Statistics\Track\Opens;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Track {
|
||||
const ENDPOINT = 'track';
|
||||
const ACTION_CLICK = 'click';
|
||||
const ACTION_OPEN = 'open';
|
||||
|
||||
static function click($data) {
|
||||
$clicks = new Clicks($data);
|
||||
$clicks->track();
|
||||
}
|
||||
|
||||
static function open($data) {
|
||||
$opens = new Opens($data);
|
||||
$opens->track();
|
||||
}
|
||||
}
|
16
lib/Router/ViewInBrowser.php
Normal file
16
lib/Router/ViewInBrowser.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
|
||||
use MailPoet\Newsletter\ViewInBrowser as NewsletterViewInBrowser;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class ViewInBrowser {
|
||||
const ENDPOINT = 'view_in_browser';
|
||||
const ACTION_VIEW = 'view';
|
||||
|
||||
static function view($data) {
|
||||
$viewer = new NewsletterViewInBrowser($data);
|
||||
$viewer->view();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user