Ejemplo n.º 1
0
        /// <summary>
        /// Processes the text body.
        /// </summary>
        /// <param name="communication">The communication.</param>
        /// <param name="globalAttributes">The global attributes.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        /// <param name="currentPersonOverride">The current person override.</param>
        /// <returns></returns>
        public static string ProcessTextBody(Rock.Model.Communication communication,
                                             Rock.Web.Cache.GlobalAttributesCache globalAttributes,
                                             Dictionary <string, object> mergeObjects,
                                             Person currentPersonOverride = null)
        {
            string defaultPlainText = communication.GetMediumDataValue("DefaultPlainText");
            string plainTextBody    = communication.GetMediumDataValue("TextMessage");

            if (string.IsNullOrWhiteSpace(plainTextBody) && !string.IsNullOrWhiteSpace(defaultPlainText))
            {
                plainTextBody = defaultPlainText;
            }

            return(plainTextBody.ResolveMergeFields(mergeObjects, currentPersonOverride, communication.EnabledLavaCommands));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the HTML body.
        /// </summary>
        /// <param name="communication">The communication.</param>
        /// <param name="globalAttributes">The global attributes.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        /// <param name="currentPersonOverride">The current person override.</param>
        /// <returns></returns>
        public static string ProcessHtmlBody(Rock.Model.Communication communication,
                                             Rock.Web.Cache.GlobalAttributesCache globalAttributes,
                                             Dictionary <string, object> mergeObjects,
                                             Person currentPersonOverride = null)
        {
            string htmlBody = communication.GetMediumDataValue("HtmlMessage");

            if (!string.IsNullOrWhiteSpace(htmlBody))
            {
                // Get the unsubscribe content and add a merge field for it
                string unsubscribeHtml = communication.GetMediumDataValue("UnsubscribeHTML").ResolveMergeFields(mergeObjects, currentPersonOverride);
                if (mergeObjects.ContainsKey("UnsubscribeOption"))
                {
                    mergeObjects.Add("UnsubscribeOption", unsubscribeHtml);
                }
                else
                {
                    mergeObjects["UnsubscribeOption"] = unsubscribeHtml;
                }

                // Resolve merge fields
                htmlBody = htmlBody.ResolveMergeFields(mergeObjects, currentPersonOverride, communication.EnabledLavaCommands);

                // Resolve special syntax needed if option was included in global attribute
                if (Regex.IsMatch(htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]"))
                {
                    htmlBody = Regex.Replace(htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]", unsubscribeHtml);
                }

                // Add the unsubscribe option at end if it wasn't included in content
                if (!htmlBody.Contains(unsubscribeHtml))
                {
                    htmlBody += unsubscribeHtml;
                }

                // Resolve any relative paths
                string publicAppRoot = globalAttributes.GetValue("PublicApplicationRoot").EnsureTrailingForwardslash();
                htmlBody = htmlBody.Replace(@" src=""/", @" src=""" + publicAppRoot);
                htmlBody = htmlBody.Replace(@" href=""/", @" href=""" + publicAppRoot);
            }

            return(htmlBody);
        }