diff --git a/lib/Config/PublicAPI.php b/lib/Config/PublicAPI.php
index 1b9e5220bd..37db03a10a 100644
--- a/lib/Config/PublicAPI.php
+++ b/lib/Config/PublicAPI.php
@@ -40,8 +40,11 @@ class PublicAPI {
function track() {
try {
- $clicks = new Clicks($this->data);
- $clicks->track();
+ if ($this->action === 'click') {
+ $track_class = new Clicks($this->data);
+ }
+ if (!isset($track_class)) return;
+ $track_class->track();
} catch(\Exception $e) {
}
}
diff --git a/lib/Cron/Workers/SendingQueue.php b/lib/Cron/Workers/SendingQueue.php
index 38f1a9d51a..e362812db1 100644
--- a/lib/Cron/Workers/SendingQueue.php
+++ b/lib/Cron/Workers/SendingQueue.php
@@ -76,7 +76,7 @@ class SendingQueue {
if($queue->newsletter_rendered_body === null) {
// render newsletter
$rendered_newsletter = $this->renderNewsletter($newsletter);
- if((int) Setting::getValue('tracking.enabled') === 1) {
+ if((boolean) Setting::getValue('tracking.enabled') === true) {
// extract and replace links
$processed_newsletter = $this->processLinks(
$this->joinObject($rendered_newsletter),
@@ -205,7 +205,7 @@ class SendingQueue {
$subscriber,
$this->joinObject($data_for_shortcodes)
);
- if((int) Setting::getValue('tracking.enabled') === 1) {
+ if((boolean) Setting::getValue('tracking.enabled') === true) {
$processed_newsletter = $this->replaceLinks(
$newsletter['id'],
$subscriber['id'],
diff --git a/lib/Newsletter/Links/Links.php b/lib/Newsletter/Links/Links.php
index 80160a5f00..906445db52 100644
--- a/lib/Newsletter/Links/Links.php
+++ b/lib/Newsletter/Links/Links.php
@@ -1,6 +1,7 @@
]+'
. '[.]'
+ # conditionally match everything except for special characters after .
. '(?:'
. '\([\w\d]+\)|'
. '(?:'
@@ -32,7 +37,7 @@ class Links {
. ')'
. ')\\1#';
preg_match_all($regex, $text, $links);
- preg_match_all('/\[\w+:\w+\]/', $text, $shortcodes);
+ preg_match_all(Shortcodes::$shortcodes_regex, $text, $shortcodes);
return array_merge(
array_unique($links[2]),
array_unique($shortcodes[0])
@@ -49,7 +54,7 @@ class Links {
'url' => $link
);
$encoded_link = sprintf(
- '%s/?mailpoet&endpoint=track&data=%s',
+ '%s/?mailpoet&endpoint=track&action=click&data=%s',
home_url(),
'[mailpoet_data]-'.$hash
);
diff --git a/lib/Newsletter/Shortcodes/Categories/Subscription.php b/lib/Newsletter/Shortcodes/Categories/Subscription.php
index 143f9e56e3..44d95a8a42 100644
--- a/lib/Newsletter/Shortcodes/Categories/Subscription.php
+++ b/lib/Newsletter/Shortcodes/Categories/Subscription.php
@@ -18,37 +18,39 @@ class Subscription {
$action,
$default_value = false,
$newsletter = false,
- $subscriber = false
+ $subscriber = false,
+ $text = false,
+ $shortcode
) {
switch($action) {
case 'unsubscribe':
- return ''.__('Unsubscribe').'';
break;
case 'unsubscribe_url':
- return self::processUrl(
- $action,
+ return self::getShortcodeUrl(
+ $shortcode,
SubscriptionUrl::getUnsubscribeUrl($subscriber)
);
break;
case 'manage':
return ''.__('Manage subscription').'';
break;
case 'manage_url':
- return self::processUrl(
- $action,
+ return self::getShortcodeUrl(
+ $shortcode,
SubscriptionUrl::getManageUrl($subscriber)
);
break;
@@ -59,10 +61,9 @@ class Subscription {
}
}
- static function processUrl($action, $url) {
- if((int) Setting::getValue('tracking.enabled') === 1) {
- return sprintf('[subscription:%s]', $action);
- }
- return $url;
+ static function getShortcodeUrl($shortcode, $url) {
+ return ((boolean) Setting::getValue('tracking.enabled') === true) ?
+ $shortcode :
+ $url;
}
}
\ No newline at end of file
diff --git a/lib/Newsletter/Shortcodes/Shortcodes.php b/lib/Newsletter/Shortcodes/Shortcodes.php
index 4d6ffa64dc..d9bd7fd3d3 100644
--- a/lib/Newsletter/Shortcodes/Shortcodes.php
+++ b/lib/Newsletter/Shortcodes/Shortcodes.php
@@ -4,6 +4,7 @@ namespace MailPoet\Newsletter\Shortcodes;
class Shortcodes {
public $newsletter;
public $subscriber;
+ static $shortcodes_regex = '/\[(?:\w+):.*?\]/ism';
function __construct(
$newsletter = false,
@@ -14,7 +15,7 @@ class Shortcodes {
}
function extract($text) {
- preg_match_all('/\[(?:\w+):.*?\]/', $text, $shortcodes);
+ preg_match_all(self::$shortcodes_regex, $text, $shortcodes);
return array_unique($shortcodes[0]);
}
@@ -43,7 +44,8 @@ class Shortcodes {
$shortcode_default_value,
$this->newsletter,
$this->subscriber,
- $text
+ $text,
+ $shortcode
);
}, $shortcodes);
return $processed_shortcodes;
diff --git a/lib/Statistics/Track/Clicks.php b/lib/Statistics/Track/Clicks.php
index 7e654ff5f9..df54f3995f 100644
--- a/lib/Statistics/Track/Clicks.php
+++ b/lib/Statistics/Track/Clicks.php
@@ -5,6 +5,7 @@ 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;
@@ -37,7 +38,7 @@ class Clicks {
$statistics->count = 1;
$statistics->save();
} else {
- $statistics->count = (int) $statistics->count++;
+ $statistics->count++;
$statistics->save();
}
$url = (preg_match('/\[subscription:.*?\]/', $link->url)) ?
@@ -55,7 +56,6 @@ class Clicks {
if(preg_match('/manage/', $action)) {
$url = SubscriptionUrl::getManageUrl($subscriber);
}
- !ddd($url);
return $url;
}