- Moves link saving logic into Links class
This commit is contained in:
@@ -202,19 +202,11 @@ class SendingQueue {
|
|||||||
return array($rendered_newsletter, $rendered_newsletter_hash);
|
return array($rendered_newsletter, $rendered_newsletter_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processLinks($text, $newsletter_id, $queue_id) {
|
function processLinks($content, $newsletter_id, $queue_id) {
|
||||||
list($text, $processed_links) =
|
list($content, $processed_links) =
|
||||||
Links::process($text, $links = false, $process_link_shortcodes = true);
|
Links::process($content, $links = false, $process_link_shortcodes = true);
|
||||||
foreach($processed_links as $link) {
|
Links::save($processed_links, $newsletter_id, $queue_id);
|
||||||
// save extracted and processed links
|
return $content;
|
||||||
$newsletter_link = NewsletterLink::create();
|
|
||||||
$newsletter_link->newsletter_id = $newsletter_id;
|
|
||||||
$newsletter_link->queue_id = $queue_id;
|
|
||||||
$newsletter_link->hash = $link['hash'];
|
|
||||||
$newsletter_link->url = $link['url'];
|
|
||||||
$newsletter_link->save();
|
|
||||||
}
|
|
||||||
return $text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processNewsletter($newsletter, $subscriber = false, $queue) {
|
function processNewsletter($newsletter, $subscriber = false, $queue) {
|
||||||
|
@@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Newsletter\Links;
|
namespace MailPoet\Newsletter\Links;
|
||||||
|
|
||||||
|
use MailPoet\Models\NewsletterLink;
|
||||||
use MailPoet\Newsletter\Shortcodes\Shortcodes;
|
use MailPoet\Newsletter\Shortcodes\Shortcodes;
|
||||||
use MailPoet\Util\Security;
|
use MailPoet\Util\Security;
|
||||||
|
|
||||||
class Links {
|
class Links {
|
||||||
const DATA_TAG = '[mailpoet_data]';
|
const DATA_TAG = '[mailpoet_data]';
|
||||||
|
|
||||||
static function extract($content, $process_link_shortcodes = false) {
|
static function extract($content) {
|
||||||
// adopted from WP's wp_extract_urls() function & modified to work on hrefs
|
// adopted from WP's wp_extract_urls() function & modified to work on hrefs
|
||||||
# match href=' or href="
|
# match href=' or href="
|
||||||
$regex = '#(?:href.*?=.*?)(["\']?)('
|
$regex = '#(?:href.*?=.*?)(["\']?)('
|
||||||
@@ -25,8 +26,8 @@ class Links {
|
|||||||
. ')+'
|
. ')+'
|
||||||
. ')'
|
. ')'
|
||||||
. ')\\1#';
|
. ')\\1#';
|
||||||
$shortcodes = new Shortcodes();
|
|
||||||
// extract shortcodes with [url:*] format
|
// extract shortcodes with [url:*] format
|
||||||
|
$shortcodes = new Shortcodes();
|
||||||
$shortcodes = $shortcodes->extract($content, $limit = array('link'));
|
$shortcodes = $shortcodes->extract($content, $limit = array('link'));
|
||||||
// extract links
|
// extract links
|
||||||
preg_match_all($regex, $content, $links);
|
preg_match_all($regex, $content, $links);
|
||||||
@@ -42,7 +43,7 @@ class Links {
|
|||||||
$shortcodes = new Shortcodes();
|
$shortcodes = new Shortcodes();
|
||||||
$content = $shortcodes->replace($content, $limit = array('link'));
|
$content = $shortcodes->replace($content, $limit = array('link'));
|
||||||
}
|
}
|
||||||
$links = ($links) ? $links : self::extract($content, $process_link_shortcodes);
|
$links = ($links) ? $links : self::extract($content);
|
||||||
$processed_links = array();
|
$processed_links = array();
|
||||||
foreach($links as $link) {
|
foreach($links as $link) {
|
||||||
$hash = Security::generateRandomString(5);
|
$hash = Security::generateRandomString(5);
|
||||||
@@ -72,4 +73,15 @@ class Links {
|
|||||||
$content
|
$content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function save($links, $newsletter_id, $queue_id) {
|
||||||
|
foreach($links as $link) {
|
||||||
|
$newsletter_link = NewsletterLink::create();
|
||||||
|
$newsletter_link->newsletter_id = $newsletter_id;
|
||||||
|
$newsletter_link->queue_id = $queue_id;
|
||||||
|
$newsletter_link->hash = $link['hash'];
|
||||||
|
$newsletter_link->url = $link['url'];
|
||||||
|
$newsletter_link->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user