Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/BVNetwork/Attend
Browse files Browse the repository at this point in the history
  • Loading branch information
Eivind committed Oct 24, 2016
2 parents 0c09dd5 + ddc349b commit 7b8cdd0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
## EPiServer Files
######################
*License.config

# NuGet Packages Directory
src/packages/
6 changes: 3 additions & 3 deletions BVNetwork.Attend.sln → src/BVNetwork.Attend.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BVNetwork.Attend", "src\BVNetwork.Attend\BVNetwork.Attend.csproj", "{6E7DC699-26A5-4BC2-A851-CBCB8DC475B0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BVNetwork.Attend", "BVNetwork.Attend\BVNetwork.Attend.csproj", "{6E7DC699-26A5-4BC2-A851-CBCB8DC475B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BVNetwork.Attend.Forms", "src\BVNetwork.Attend.Forms\BVNetwork.Attend.Forms.csproj", "{68E5D4AC-5AA7-4061-976A-9E3B24CCD009}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BVNetwork.Attend.Forms", "BVNetwork.Attend.Forms\BVNetwork.Attend.Forms.csproj", "{68E5D4AC-5AA7-4061-976A-9E3B24CCD009}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
39 changes: 39 additions & 0 deletions src/BVNetwork.Attend/Business/Email/EmailTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
using BVNetwork.Attend.Models.Pages;
using EPiServer;
using BVNetwork.Attend.Business.API;
using EPiServer.Core;
using EPiServer.ServiceLocation;
using EPiServer.Web;

namespace BVNetwork.Attend.Business.Email
{
Expand Down Expand Up @@ -169,6 +172,7 @@ public static EmailTemplate Load(EmailTemplateBlock template, EventPageBase Even
{
EmailTemplate email = new EmailTemplate();
email.HtmlBody = PopulatePropertyValues(template.MainBody != null ? template.MainBody.ToString() : string.Empty, EventPageBase, participant);
email.HtmlBody = RewriteUrls(email.HtmlBody, GetSiteUrl(EventPageBase));
email.Body = PopulatePropertyValues(template.MainTextBody, EventPageBase, participant);
email.To = PopulatePropertyValues(template.To, EventPageBase, participant);
email.From = PopulatePropertyValues(template.From, EventPageBase, participant);
Expand Down Expand Up @@ -199,6 +203,41 @@ public static string PopulatePropertyValues(string template, EventPageBase Event
return template;
}

/// <summary>
/// Make all urls fully qualified, we only care about href and src attributes here.
/// </summary>
/// <param name="mailBody"></param>
/// <returns></returns>
public static string RewriteUrls(string mailBody, string hostUrl)
{
string safeHost = hostUrl.TrimEnd('/');

mailBody = mailBody.Replace("src=\"//", "src=\"/");
mailBody = mailBody.Replace("src=\"/", "src=\"" + safeHost + "/");
mailBody = mailBody.Replace("href=\"/", "href=\"" + safeHost + "/");
return mailBody;
}

public static string GetSiteUrl(PageData page)
{
// Always look up based on page
SiteDefinitionResolver repo = ServiceLocator.Current.GetInstance<SiteDefinitionResolver>();
SiteDefinition siteDefinition = repo.GetDefinitionForContent(page.ContentLink, fallbackToWildcardMapped: true, fallbackToEmpty: false);

if (siteDefinition == null || siteDefinition.SiteUrl == null)
{
// Still haven't found it, can't go on
throw new ApplicationException("Cannot find a SiteDefinition with a valid SiteUrl for page: " +
page.ContentLink.ToString());
}

string hostUrl = siteDefinition.SiteUrl.ToString();


return hostUrl;
}


protected static string GetPropertyValue(string objectName, string propertyName, EventPageBase CurrentEvent, IParticipant CurrentParticipant)
{
object value = null;
Expand Down

0 comments on commit 7b8cdd0

Please sign in to comment.