- Implements post-processing filter during rendering
This commit is contained in:
12
lib/Models/StatisticsOpens.php
Normal file
12
lib/Models/StatisticsOpens.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class StatisticsClicks extends Model {
|
||||
public static $_table = MP_STATISTICS_CLICKS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
15
lib/Newsletter/Renderer/PostProcess/OpenTracking.php
Normal file
15
lib/Newsletter/Renderer/PostProcess/OpenTracking.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Renderer\PostProcess;
|
||||
|
||||
class OpenTracking {
|
||||
static function process($template, $user_id) {
|
||||
$DOM = new \pQuery();
|
||||
$template = $DOM->query('body');
|
||||
$open_tracking_link = sprintf(
|
||||
'<img alt="" src="%s/?mailpoet&endpoint=track&action=open&data=[mailpoet_data]',
|
||||
home_url()
|
||||
);
|
||||
$template->html($template->html() . $open_tracking_link);
|
||||
return $DOM->__toString();
|
||||
}
|
||||
}
|
@ -102,6 +102,10 @@ class Renderer {
|
||||
$template->html(
|
||||
str_replace('!important', '', $template->html())
|
||||
);
|
||||
return $DOM->__toString();
|
||||
$template = apply_filters(
|
||||
'mailpoet_rendering_post_process',
|
||||
$DOM->__toString()
|
||||
);
|
||||
return $template;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ use MailPoet\Util\Helpers;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Clicks {
|
||||
class Click {
|
||||
public $url;
|
||||
|
||||
function __construct($url) {
|
||||
|
64
lib/Statistics/Track/Opens.php
Normal file
64
lib/Statistics/Track/Opens.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace MailPoet\Statistics\Track;
|
||||
|
||||
use MailPoet\Models\NewsletterLink;
|
||||
use MailPoet\Models\StatisticsClicks;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Subscription\Url as SubscriptionUrl;
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Opens {
|
||||
public $url;
|
||||
|
||||
function __construct($url) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
function track($url = false) {
|
||||
$url = ($url) ? $url : $this->url;
|
||||
if(!preg_match('/\d+-\d+-\d+$/', $url)) $this->abort();
|
||||
list ($newsletter_id, $subscriber_id, $queue_id) = explode('-', $url);
|
||||
$subscriber = Subscriber::findOne($subscriber_id);
|
||||
if(!$subscriber) return;
|
||||
$statistics = StatisticsOpens::where('link_id', $link->id)
|
||||
->where('subscriber_id', $subscriber_id)
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
->where('queue_id', $queue_id)
|
||||
->findOne();
|
||||
if(!$statistics) {
|
||||
$statistics = StatisticsClicks::create();
|
||||
$statistics->newsletter_id = $newsletter_id;
|
||||
$statistics->link_id = $link->id;
|
||||
$statistics->subscriber_id = $subscriber_id;
|
||||
$statistics->queue_id = $queue_id;
|
||||
$statistics->count = 1;
|
||||
$statistics->save();
|
||||
} else {
|
||||
$statistics->count++;
|
||||
$statistics->save();
|
||||
}
|
||||
$url = (preg_match('/\[subscription:.*?\]/', $link->url)) ?
|
||||
$this->processSubscriptionUrl($link->url, $subscriber) :
|
||||
$link->url;
|
||||
header('Location: ' . $url, true, 302);
|
||||
}
|
||||
|
||||
function processSubscriptionUrl($url, $subscriber) {
|
||||
preg_match('/\[subscription:(.*?)\]/', $url, $match);
|
||||
$action = $match[1];
|
||||
if(preg_match('/unsubscribe/', $action)) {
|
||||
$url = SubscriptionUrl::getUnsubscribeUrl($subscriber);
|
||||
}
|
||||
if(preg_match('/manage/', $action)) {
|
||||
$url = SubscriptionUrl::getManageUrl($subscriber);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
private function abort() {
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
exit;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user