- 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']) :
|
||||
false;
|
||||
$this->data = isset($_GET['data']) ?
|
||||
$_GET['data'] :
|
||||
unserialize(base64_decode($_GET['data'])) :
|
||||
false;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class PublicAPI {
|
||||
|
||||
function queue() {
|
||||
try {
|
||||
$queue = new Daemon($this->_decodeData());
|
||||
$queue = new Daemon($this->data);
|
||||
$this->_checkAndCallMethod($queue, $this->action);
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class PublicAPI {
|
||||
|
||||
function subscription() {
|
||||
try {
|
||||
$subscription = new Subscription\Pages($this->action, $this->_decodeData());
|
||||
$subscription = new Subscription\Pages($this->action, $this->data);
|
||||
$this->_checkAndCallMethod($subscription, $this->action);
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class PublicAPI {
|
||||
}
|
||||
|
||||
function viewInBrowser() {
|
||||
$viewer = new ViewInBrowser($this->_decodeData());
|
||||
$viewer = new ViewInBrowser($this->data);
|
||||
$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) {
|
||||
foreach($subscribers as $subscriber) {
|
||||
$processed_newsletters[] =
|
||||
$this->processNewsletter($newsletter, $subscriber, $queue);
|
||||
$this->processNewsletterBeforeSending($newsletter, $subscriber, $queue);
|
||||
if(!$queue->newsletter_rendered_subject) {
|
||||
$queue->newsletter_rendered_subject = $processed_newsletters[0]['subject'];
|
||||
}
|
||||
@@ -162,7 +162,7 @@ class SendingQueue {
|
||||
function processIndividualSubscriber($mailer, $newsletter, $subscribers, $queue) {
|
||||
foreach($subscribers as $subscriber) {
|
||||
$this->checkSendingLimit();
|
||||
$processed_newsletter = $this->processNewsletter($newsletter, $subscriber, $queue);
|
||||
$processed_newsletter = $this->processNewsletterBeforeSending($newsletter, $subscriber, $queue);
|
||||
if(!$queue->newsletter_rendered_subject) {
|
||||
$queue->newsletter_rendered_subject = $processed_newsletter['subject'];
|
||||
}
|
||||
@@ -213,7 +213,7 @@ class SendingQueue {
|
||||
return $content;
|
||||
}
|
||||
|
||||
function processNewsletter($newsletter, $subscriber = false, $queue) {
|
||||
function processNewsletterBeforeSending($newsletter, $subscriber = false, $queue) {
|
||||
$data_for_shortcodes = array(
|
||||
$newsletter['subject'],
|
||||
$newsletter['body']['html'],
|
||||
|
@@ -10,7 +10,7 @@ class Links {
|
||||
|
||||
static function extract($content) {
|
||||
// adopted from WP's wp_extract_urls() function & modified to work on hrefs
|
||||
# match href=' or href="
|
||||
# match href=' or href="
|
||||
$regex = '#(?:href.*?=.*?)(["\']?)('
|
||||
# match http://
|
||||
. '(?:([\w-]+:)?//?)'
|
||||
@@ -76,11 +76,23 @@ class Links {
|
||||
$queue_id,
|
||||
$content
|
||||
) {
|
||||
return str_replace(
|
||||
self::DATA_TAG,
|
||||
sprintf('%s-%s-%s', $newsletter_id, $subscriber_id, $queue_id),
|
||||
$content
|
||||
);
|
||||
$regex = sprintf('/data=(%s(?:-\w+)?)/', preg_quote(self::DATA_TAG));
|
||||
preg_match_all($regex, $content, $links);
|
||||
foreach($links[1] as $link) {
|
||||
$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) {
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Renderer\PostProcess;
|
||||
|
||||
use MailPoet\Newsletter\Links\Links;
|
||||
|
||||
class OpenTracking {
|
||||
static function process($template) {
|
||||
$DOM = new \pQuery();
|
||||
@@ -9,7 +11,7 @@ class OpenTracking {
|
||||
$open_tracking_link = sprintf(
|
||||
'<img alt="" class="" src="%s/%s"/>',
|
||||
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);
|
||||
return $DOM->__toString();
|
||||
|
@@ -12,20 +12,18 @@ use MailPoet\Subscription\Url as SubscriptionUrl;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Clicks {
|
||||
public $url;
|
||||
public $data;
|
||||
|
||||
function __construct($url) {
|
||||
$this->url = $url;
|
||||
function __construct($data) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
function track($url = false) {
|
||||
$url = ($url) ? $url : $this->url;
|
||||
if(!preg_match('/\d+-\d+-\d+-[a-zA-Z0-9]/', $url)) $this->abort();
|
||||
list ($newsletter_id, $subscriber_id, $queue_id, $hash) = explode('-', $url);
|
||||
$newsletter = $this->getNewsletter($newsletter_id);
|
||||
$subscriber = $this->getSubscriber($subscriber_id);
|
||||
$queue = $this->getQueue($queue_id);
|
||||
$link = $this->getLink($hash);
|
||||
function track($data = false) {
|
||||
$data = ($data) ? $data : $this->data;
|
||||
$newsletter = $this->getNewsletter($data['newsletter']);
|
||||
$subscriber = $this->getSubscriber($data['subscriber']);
|
||||
$queue = $this->getQueue($data['queue']);
|
||||
$link = $this->getLink($data['hash']);
|
||||
if(!$subscriber || !$newsletter || !$link || !$queue) {
|
||||
$this->abort();
|
||||
}
|
||||
@@ -36,7 +34,7 @@ class Clicks {
|
||||
->findOne();
|
||||
if(!$statistics) {
|
||||
// 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();
|
||||
$statistics = StatisticsClicks::create();
|
||||
$statistics->newsletter_id = $newsletter['id'];
|
||||
|
@@ -17,22 +17,20 @@ class Opens {
|
||||
|
||||
function track($data = false) {
|
||||
$data = ($data) ? $data : $this->data;
|
||||
if(!preg_match('/\d+-\d+-\d+/', $data)) $this->abort();
|
||||
list ($newsletter_id, $subscriber_id, $queue_id) = explode('-', $data);
|
||||
$subscriber = Subscriber::findOne($subscriber_id);
|
||||
$subscriber = Subscriber::findOne($data['subscriber']);
|
||||
if(!$subscriber) return;
|
||||
$statistics = StatisticsOpens::where('subscriber_id', $subscriber_id)
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
->where('queue_id', $queue_id)
|
||||
$statistics = StatisticsOpens::where('subscriber_id', $subscriber->id)
|
||||
->where('newsletter_id', $data['newsletter'])
|
||||
->where('queue_id', $data['queue'])
|
||||
->findOne();
|
||||
if(!$statistics) {
|
||||
$statistics = StatisticsOpens::create();
|
||||
$statistics->newsletter_id = $newsletter_id;
|
||||
$statistics->subscriber_id = $subscriber_id;
|
||||
$statistics->queue_id = $queue_id;
|
||||
$statistics->newsletter_id = $data['newsletter'];
|
||||
$statistics->subscriber_id = $data['subscriber'];
|
||||
$statistics->queue_id = $data['queue'];
|
||||
$statistics->save();
|
||||
}
|
||||
if ($this->display_image) {
|
||||
if($this->display_image) {
|
||||
// return 1x1 pixel transparent gif image
|
||||
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";
|
||||
|
Reference in New Issue
Block a user