Send confirmation email + page

This commit is contained in:
Jonathan Labreuille
2016-02-24 10:56:47 +01:00
parent cf6466197a
commit 14fe333678
5 changed files with 225 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace MailPoet\Router;
use \MailPoet\Util\Security;
use \MailPoet\Models\Subscriber;
if(!defined('ABSPATH')) exit;
@@ -17,6 +18,7 @@ class Router {
'wp_ajax_mailpoet',
array($this, 'setup')
);
$this->setupPublic();
}
function setup() {
@@ -36,6 +38,84 @@ class Router {
}
}
function setupPublic() {
if(isset($_GET['mailpoet_page'])) {
$mailpoet_page = $_GET['mailpoet_page'];
add_filter('wp_title', array($this,'setWindowTitle'));
add_filter('the_title', array($this,'setPageTitle'));
add_filter('the_content', array($this,'setPageContent'));
}
}
function setWindowTitle() {
}
function setPageTitle($title) {
$action = (isset($_GET['mailpoet_action']))
? $_GET['mailpoet_action']
: null;
switch($action) {
case 'confirm':
$token = (isset($_GET['mailpoet_token']))
? $_GET['mailpoet_token']
: null;
$email = (isset($_GET['mailpoet_email']))
? $_GET['mailpoet_email']
: null;
if(empty($token) || empty($token)) {
$title = sprintf(
__("You've subscribed to: %s"),
'demo'
);
} else {
// check token validity
if(md5(AUTH_KEY.$email) !== $token) {
$title = __('Your confirmation link expired, please subscribe again.');
} else {
$subscriber = Subscriber::findOne($email);
if($subscriber !== false) {
if($subscriber->status !== Subscriber::STATUS_SUBSCRIBED) {
$subscriber->status = Subscriber::STATUS_SUBSCRIBED;
$subscriber->save();
}
$segments = $subscriber->segments()->findMany();
$segment_names = array_map(function($segment) {
return $segment->name;
}, $segments);
$title = sprintf(
__("You've subscribed to: %s"),
join(', ', $segment_names)
);
}
}
}
break;
case 'manage':
// TODO
break;
case 'unsubscribe':
// TODO
break;
}
return $title;
}
function setPageContent($content) {
return __(
"Yup, we've added you to our list. ".
"You'll hear from us shortly."
);
}
function setToken() {
$global = '<script type="text/javascript">';
$global .= 'var mailpoet_token = "'.Security::generateToken().'";';