Some fixes in RSS feed processing.

It is now possible to have hierarchical merge tags (separated by "."). The merge tags are now case sensitive.
Mailtrain allows passing element "mt:entries-json" in the RSS item feed. If this is detected, it parses the json structure and makes it available through RSS_ENTRY_CUSTOM_TAGS. Then it can be used as [RSS_ENTRY_CUSTOM_TAGS.field_quote_text.rendered]
This commit is contained in:
Tomas Bures 2018-12-29 11:21:25 +01:00
parent 6eead89fef
commit e786964411
5 changed files with 36 additions and 21 deletions

View file

@ -262,7 +262,8 @@ class CampaignSender {
tags['RSS_ENTRY_LINK'] = rssEntry.link;
tags['RSS_ENTRY_CONTENT'] = rssEntry.content;
tags['RSS_ENTRY_SUMMARY'] = rssEntry.summary;
tags['RSS_ENTRY_IMAGE_URL'] = rssEntry.image_url;
tags['RSS_ENTRY_IMAGE_URL'] = rssEntry.imageUrl;
tags['RSS_ENTRY_CUSTOM_TAGS'] = rssEntry.customTags;
}
return tags;
@ -311,6 +312,7 @@ class CampaignSender {
const sendConfiguration = this.sendConfiguration;
const {html, text, attachments} = await this._getMessage(campaign, list, subscriptionGrouped, mergeTags, true);
console.log(html);
const campaignAddress = [campaign.cid, list.cid, subscriptionGrouped.cid].join('.');

View file

@ -150,23 +150,31 @@ function validateEmailGetMessage(result, address, language) {
function formatMessage(campaign, list, subscription, mergeTags, message, isHTML) {
const links = getMessageLinks(campaign, list, subscription);
const getValue = key => {
key = (key || '').toString().toUpperCase().trim();
if (links.hasOwnProperty(key)) {
return links[key];
const getValue = fullKey => {
const keys = (fullKey || '').split('.');
if (links.hasOwnProperty(keys[0])) {
return links[keys[0]];
}
if (mergeTags.hasOwnProperty(key)) {
const value = (mergeTags[key] || '').toString();
const containsHTML = /<[a-z][\s\S]*>/.test(value);
return isHTML ? he.encode((containsHTML ? value : value.replace(/(?:\r\n|\r|\n)/g, '<br/>')), {
useNamedReferences: true,
allowUnsafeSymbols: true
}) : (containsHTML ? htmlToText.fromString(value) : value);
let value = mergeTags;
while (keys.length > 0) {
let key = keys.shift();
if (value.hasOwnProperty(key)) {
value = value[key];
} else {
return false;
}
}
return false;
const containsHTML = /<[a-z][\s\S]*>/.test(value);
return isHTML ? he.encode((containsHTML ? value : value.replace(/(?:\r\n|\r|\n)/g, '<br/>')), {
useNamedReferences: true,
allowUnsafeSymbols: true
}) : (containsHTML ? htmlToText.fromString(value) : value);
};
return message.replace(/\[([a-z0-9_]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => {
return message.replace(/\[([a-z0-9_.]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => {
let value = getValue(identifier);
if (value === false) {
return match;