- Updates link tracking to use the same Public API data format as other
endpoints
This commit is contained in:
@@ -26,7 +26,7 @@ class PublicAPI {
|
|||||||
Helpers::underscoreToCamelCase($_GET['action']) :
|
Helpers::underscoreToCamelCase($_GET['action']) :
|
||||||
false;
|
false;
|
||||||
$this->data = isset($_GET['data']) ?
|
$this->data = isset($_GET['data']) ?
|
||||||
$_GET['data'] :
|
unserialize(base64_decode($_GET['data'])) :
|
||||||
false;
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class PublicAPI {
|
|||||||
|
|
||||||
function queue() {
|
function queue() {
|
||||||
try {
|
try {
|
||||||
$queue = new Daemon($this->_decodeData());
|
$queue = new Daemon($this->data);
|
||||||
$this->_checkAndCallMethod($queue, $this->action);
|
$this->_checkAndCallMethod($queue, $this->action);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ class PublicAPI {
|
|||||||
|
|
||||||
function subscription() {
|
function subscription() {
|
||||||
try {
|
try {
|
||||||
$subscription = new Subscription\Pages($this->action, $this->_decodeData());
|
$subscription = new Subscription\Pages($this->action, $this->data);
|
||||||
$this->_checkAndCallMethod($subscription, $this->action);
|
$this->_checkAndCallMethod($subscription, $this->action);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ class PublicAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function viewInBrowser() {
|
function viewInBrowser() {
|
||||||
$viewer = new ViewInBrowser($this->_decodeData());
|
$viewer = new ViewInBrowser($this->data);
|
||||||
$viewer->view();
|
$viewer->view();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,12 +80,4 @@ class PublicAPI {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _decodeData() {
|
|
||||||
if($this->data !== false) {
|
|
||||||
return unserialize(base64_decode($this->data));
|
|
||||||
} else {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -118,7 +118,7 @@ class SendingQueue {
|
|||||||
function processBulkSubscribers($mailer, $newsletter, $subscribers, $queue) {
|
function processBulkSubscribers($mailer, $newsletter, $subscribers, $queue) {
|
||||||
foreach($subscribers as $subscriber) {
|
foreach($subscribers as $subscriber) {
|
||||||
$processed_newsletters[] =
|
$processed_newsletters[] =
|
||||||
$this->processNewsletter($newsletter, $subscriber, $queue);
|
$this->processNewsletterBeforeSending($newsletter, $subscriber, $queue);
|
||||||
if(!$queue->newsletter_rendered_subject) {
|
if(!$queue->newsletter_rendered_subject) {
|
||||||
$queue->newsletter_rendered_subject = $processed_newsletters[0]['subject'];
|
$queue->newsletter_rendered_subject = $processed_newsletters[0]['subject'];
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ class SendingQueue {
|
|||||||
function processIndividualSubscriber($mailer, $newsletter, $subscribers, $queue) {
|
function processIndividualSubscriber($mailer, $newsletter, $subscribers, $queue) {
|
||||||
foreach($subscribers as $subscriber) {
|
foreach($subscribers as $subscriber) {
|
||||||
$this->checkSendingLimit();
|
$this->checkSendingLimit();
|
||||||
$processed_newsletter = $this->processNewsletter($newsletter, $subscriber, $queue);
|
$processed_newsletter = $this->processNewsletterBeforeSending($newsletter, $subscriber, $queue);
|
||||||
if(!$queue->newsletter_rendered_subject) {
|
if(!$queue->newsletter_rendered_subject) {
|
||||||
$queue->newsletter_rendered_subject = $processed_newsletter['subject'];
|
$queue->newsletter_rendered_subject = $processed_newsletter['subject'];
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ class SendingQueue {
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processNewsletter($newsletter, $subscriber = false, $queue) {
|
function processNewsletterBeforeSending($newsletter, $subscriber = false, $queue) {
|
||||||
$data_for_shortcodes = array(
|
$data_for_shortcodes = array(
|
||||||
$newsletter['subject'],
|
$newsletter['subject'],
|
||||||
$newsletter['body']['html'],
|
$newsletter['body']['html'],
|
||||||
|
@@ -76,11 +76,23 @@ class Links {
|
|||||||
$queue_id,
|
$queue_id,
|
||||||
$content
|
$content
|
||||||
) {
|
) {
|
||||||
return str_replace(
|
$regex = sprintf('/data=(%s(?:-\w+)?)/', preg_quote(self::DATA_TAG));
|
||||||
self::DATA_TAG,
|
preg_match_all($regex, $content, $links);
|
||||||
sprintf('%s-%s-%s', $newsletter_id, $subscriber_id, $queue_id),
|
foreach($links[1] as $link) {
|
||||||
$content
|
$hash = null;
|
||||||
|
if(preg_match('/-/', $link)) {
|
||||||
|
list(, $hash) = explode('-', $link);
|
||||||
|
}
|
||||||
|
$data = array(
|
||||||
|
'newsletter' => $newsletter_id,
|
||||||
|
'subscriber' => $subscriber_id,
|
||||||
|
'queue' => $queue_id,
|
||||||
|
'hash' => $hash
|
||||||
);
|
);
|
||||||
|
$data = rtrim(base64_encode(serialize($data)), '=');
|
||||||
|
$content = str_replace($link, $data, $content);
|
||||||
|
}
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function save($links, $newsletter_id, $queue_id) {
|
static function save($links, $newsletter_id, $queue_id) {
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Newsletter\Renderer\PostProcess;
|
namespace MailPoet\Newsletter\Renderer\PostProcess;
|
||||||
|
|
||||||
|
use MailPoet\Newsletter\Links\Links;
|
||||||
|
|
||||||
class OpenTracking {
|
class OpenTracking {
|
||||||
static function process($template) {
|
static function process($template) {
|
||||||
$DOM = new \pQuery();
|
$DOM = new \pQuery();
|
||||||
@@ -9,7 +11,7 @@ class OpenTracking {
|
|||||||
$open_tracking_link = sprintf(
|
$open_tracking_link = sprintf(
|
||||||
'<img alt="" class="" src="%s/%s"/>',
|
'<img alt="" class="" src="%s/%s"/>',
|
||||||
home_url(),
|
home_url(),
|
||||||
htmlentities('?mailpoet&endpoint=track&action=open&data=[mailpoet_data]')
|
esc_attr('?mailpoet&endpoint=track&action=open&data=' . Links::DATA_TAG)
|
||||||
);
|
);
|
||||||
$template->html($template->html() . $open_tracking_link);
|
$template->html($template->html() . $open_tracking_link);
|
||||||
return $DOM->__toString();
|
return $DOM->__toString();
|
||||||
|
@@ -12,20 +12,18 @@ use MailPoet\Subscription\Url as SubscriptionUrl;
|
|||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Clicks {
|
class Clicks {
|
||||||
public $url;
|
public $data;
|
||||||
|
|
||||||
function __construct($url) {
|
function __construct($data) {
|
||||||
$this->url = $url;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function track($url = false) {
|
function track($data = false) {
|
||||||
$url = ($url) ? $url : $this->url;
|
$data = ($data) ? $data : $this->data;
|
||||||
if(!preg_match('/\d+-\d+-\d+-[a-zA-Z0-9]/', $url)) $this->abort();
|
$newsletter = $this->getNewsletter($data['newsletter']);
|
||||||
list ($newsletter_id, $subscriber_id, $queue_id, $hash) = explode('-', $url);
|
$subscriber = $this->getSubscriber($data['subscriber']);
|
||||||
$newsletter = $this->getNewsletter($newsletter_id);
|
$queue = $this->getQueue($data['queue']);
|
||||||
$subscriber = $this->getSubscriber($subscriber_id);
|
$link = $this->getLink($data['hash']);
|
||||||
$queue = $this->getQueue($queue_id);
|
|
||||||
$link = $this->getLink($hash);
|
|
||||||
if(!$subscriber || !$newsletter || !$link || !$queue) {
|
if(!$subscriber || !$newsletter || !$link || !$queue) {
|
||||||
$this->abort();
|
$this->abort();
|
||||||
}
|
}
|
||||||
@@ -36,7 +34,7 @@ class Clicks {
|
|||||||
->findOne();
|
->findOne();
|
||||||
if(!$statistics) {
|
if(!$statistics) {
|
||||||
// track open event in case it did not register
|
// track open event in case it did not register
|
||||||
$open = new Opens($url, $display_image = false);
|
$open = new Opens($data, $display_image = false);
|
||||||
$open->track();
|
$open->track();
|
||||||
$statistics = StatisticsClicks::create();
|
$statistics = StatisticsClicks::create();
|
||||||
$statistics->newsletter_id = $newsletter['id'];
|
$statistics->newsletter_id = $newsletter['id'];
|
||||||
|
@@ -17,22 +17,20 @@ class Opens {
|
|||||||
|
|
||||||
function track($data = false) {
|
function track($data = false) {
|
||||||
$data = ($data) ? $data : $this->data;
|
$data = ($data) ? $data : $this->data;
|
||||||
if(!preg_match('/\d+-\d+-\d+/', $data)) $this->abort();
|
$subscriber = Subscriber::findOne($data['subscriber']);
|
||||||
list ($newsletter_id, $subscriber_id, $queue_id) = explode('-', $data);
|
|
||||||
$subscriber = Subscriber::findOne($subscriber_id);
|
|
||||||
if(!$subscriber) return;
|
if(!$subscriber) return;
|
||||||
$statistics = StatisticsOpens::where('subscriber_id', $subscriber_id)
|
$statistics = StatisticsOpens::where('subscriber_id', $subscriber->id)
|
||||||
->where('newsletter_id', $newsletter_id)
|
->where('newsletter_id', $data['newsletter'])
|
||||||
->where('queue_id', $queue_id)
|
->where('queue_id', $data['queue'])
|
||||||
->findOne();
|
->findOne();
|
||||||
if(!$statistics) {
|
if(!$statistics) {
|
||||||
$statistics = StatisticsOpens::create();
|
$statistics = StatisticsOpens::create();
|
||||||
$statistics->newsletter_id = $newsletter_id;
|
$statistics->newsletter_id = $data['newsletter'];
|
||||||
$statistics->subscriber_id = $subscriber_id;
|
$statistics->subscriber_id = $data['subscriber'];
|
||||||
$statistics->queue_id = $queue_id;
|
$statistics->queue_id = $data['queue'];
|
||||||
$statistics->save();
|
$statistics->save();
|
||||||
}
|
}
|
||||||
if ($this->display_image) {
|
if($this->display_image) {
|
||||||
// return 1x1 pixel transparent gif image
|
// return 1x1 pixel transparent gif image
|
||||||
header('Content-Type: image/gif');
|
header('Content-Type: image/gif');
|
||||||
echo "\x47\x49\x46\x38\x37\x61\x1\x0\x1\x0\x80\x0\x0\xfc\x6a\x6c\x0\x0\x0\x2c\x0\x0\x0\x0\x1\x0\x1\x0\x0\x2\x2\x44\x1\x0\x3b";
|
echo "\x47\x49\x46\x38\x37\x61\x1\x0\x1\x0\x80\x0\x0\xfc\x6a\x6c\x0\x0\x0\x2c\x0\x0\x0\x0\x1\x0\x1\x0\x0\x2\x2\x44\x1\x0\x3b";
|
||||||
|
Reference in New Issue
Block a user