public static function parseContent($content, Campaign $campaign, ListSubscriber $subscriber, $appendBeacon = false, DeliveryServer $server = null)
{
$content = StringHelper::decodeSurroundingTags($content);
$options = Yii::app()->options;
$searchReplace = self::getCommonTagsSearchReplace($content, $campaign, $subscriber, $server);
$content = str_replace(array_keys($searchReplace), array_values($searchReplace), $content);
$content = self::getTagFilter()->apply($content, $searchReplace);
$to = isset($searchReplace['[CAMPAIGN_TO_NAME]']) ? $searchReplace['[CAMPAIGN_TO_NAME]'] : '';
$subject = isset($searchReplace['[CAMPAIGN_SUBJECT]']) ? $searchReplace['[CAMPAIGN_SUBJECT]'] : '';
// tags with params, if any...
$searchReplace = array();
if (preg_match_all('/\[([a-z_]+)([^\]]+)?\]/i', $content, $matches)) {
$matches = array_unique($matches[0]);
foreach ($matches as $tag) {
if (strpos($tag, '[DATETIME') === 0) {
$searchReplace[$tag] = self::parseDateTimeTag($tag);
} elseif (strpos($tag, '[DATE') === 0) {
$searchReplace[$tag] = self::parseDateTag($tag);
}
}
}
/**
* This is where we replace the markers from CampaignHelper::transformLinksForTracking()
* This is the only place to replace the markers that won't affect the performance
*
* @since 1.4.3
* @see CampaignHelper::transformLinksForTracking()
*/
if (!empty($server)) {
if ($server->type == 'elasticemail-web-api' || preg_match('/smtp(\d+)?\.elasticemail\.com/i', $server->hostname)) {
$unsubscribeTags = array('_UNSUBSCRIBE_URL_', '_DIRECT_UNSUBSCRIBE_URL_');
foreach ($unsubscribeTags as $unsubscribeTag) {
$pattern = sprintf('/data-unsubtag="%s" href(\s+)?=(\s+)?(\042|\047)((\s+)?(.*?)(\s+)?)(\042|\047)/i', $unsubscribeTag);
if (!preg_match_all($pattern, $content, $matches)) {
continue;
}
$pattern = '/href(\s+)?=(\s+)?(\042|\047)((\s+)?(.*?)(\s+)?)(\042|\047)/i';
$markup = array_unique($matches[0]);
foreach ($markup as $mkp) {
$_mkp = str_replace(sprintf('data-unsubtag="%s"', $unsubscribeTag), '', $mkp);
$_mkp = trim($_mkp);
$_mkp = preg_replace($pattern, 'href="{unsubscribe:$6}"', $_mkp);
$searchReplace[$mkp] = $_mkp;
}
}
}
}
//
if (!empty($searchReplace)) {
$content = str_replace(array_keys($searchReplace), array_values($searchReplace), $content);
}
// 1.4.4 -- ADD START
if (!empty($subject)) {
$searchReplace = self::getCommonTagsSearchReplace($subject, $campaign, $subscriber, $server);
$subject = str_replace(array_keys($searchReplace), array_values($searchReplace), $subject);
}
// ADD END
unset($searchReplace);
if ($appendBeacon && !empty($subscriber->subscriber_id)) {
$beaconUrl = $options->get('system.urls.frontend_absolute_url');
$beaconUrl .= 'campaigns/' . $campaign->campaign_uid . '/track-opening/' . $subscriber->subscriber_uid;
$beaconImage = CHtml::image($beaconUrl, '', array('width' => 1, 'height' => 1));
$content = str_ireplace('</body>', $beaconImage . "\n" . '</body>', $content);
}
return array($to, $subject, $content);
}