Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions content-management/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/Sdl.Web.Templating/bin
/Sdl.Web.Templating/obj
/Sdl.Web.Templating/*.user
/Sdl.Web.Templating/*.suo
Sdl.Web.Templating/bin
Sdl.Web.Templating/obj
Sdl.Web.Templating/*.user
Sdl.Web.Templating/*.suo
_references/2013-sp1/*.dll
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private string ResolveXhtml(string input)
{
Component comp = (Component)Engine.GetObject(uri);
// resolve youtube video
if (comp != null)
if (comp != null && comp.Metadata != null)
{
ItemFields fields = new ItemFields(comp.Metadata, comp.MetadataSchema);
ProcessFields(fields, link);
Expand Down
Binary file added modules/SmartTarget-Module.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions web-application/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ obj
bin
*.user
*.suo
Site/system/v*.*/
packages/
mod
packages
Site/ClaimStore.aspx
Site/system/v*.*/
22 changes: 21 additions & 1 deletion web-application/Modules/Modules.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sdl.Web.Modules.Search", "Search\Sdl.Web.Modules.Search\Sdl.Web.Modules.Search.csproj", "{8FEFFF4C-0AE2-452F-89B1-36F7D2944032}"
EndProject
Expand All @@ -15,6 +15,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sdl.Web.Tridion", "..\Sdl.W
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sdl.Web.DD4T", "..\Sdl.Web.DD4T\Sdl.Web.DD4T.csproj", "{360AEC0A-3367-486A-885F-7931F32234C1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sdl.Web.Modules.SmartTarget", "SmartTarget\Sdl.Web.Modules.SmartTarget\Sdl.Web.Modules.SmartTarget.csproj", "{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sdl.Web.Modules.SmartTarget.DD4T", "SmartTarget\Sdl.Web.Modules.SmartTarget.DD4T\Sdl.Web.Modules.SmartTarget.DD4T.csproj", "{DD3A7294-291F-420D-81B0-0058AB704B8D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,6 +75,22 @@ Global
{360AEC0A-3367-486A-885F-7931F32234C1}.Tridion71Debug|Any CPU.Build.0 = Debug|Any CPU
{360AEC0A-3367-486A-885F-7931F32234C1}.Tridion71Release|Any CPU.ActiveCfg = Release|Any CPU
{360AEC0A-3367-486A-885F-7931F32234C1}.Tridion71Release|Any CPU.Build.0 = Release|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Release|Any CPU.Build.0 = Release|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Tridion71Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Tridion71Debug|Any CPU.Build.0 = Debug|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Tridion71Release|Any CPU.ActiveCfg = Release|Any CPU
{05ECDB04-EB87-4EC9-B13B-C3D5C100494C}.Tridion71Release|Any CPU.Build.0 = Release|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Release|Any CPU.Build.0 = Release|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Tridion71Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Tridion71Debug|Any CPU.Build.0 = Debug|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Tridion71Release|Any CPU.ActiveCfg = Release|Any CPU
{DD3A7294-291F-420D-81B0-0058AB704B8D}.Tridion71Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DD4T.ContentModel;
using DD4T.ContentModel.Factories;
using Tridion.ContentDelivery.DynamicContent.Query;
using Tridion.ContentDelivery.Meta;

namespace Sdl.Web.Modules.SmartTarget.DD4T.Factories
{
public class ComponentPresentationFactory : IComponentPresentationFactory
{
private IComponentFactory _componentFactory;

public ComponentPresentationFactory(IComponentFactory componentFactory)
{
_componentFactory = componentFactory;
}

public IComponentPresentation GetComponentPresentation(string componentUri, string templateUri)
{
IComponent component = null;
if (_componentFactory.TryGetComponent(componentUri, out component, templateUri))
{
var componentTcmUri = new TcmUri(componentUri);
var templateTcmUri = new TcmUri(templateUri);

var publicationCriteria = new PublicationCriteria(templateTcmUri.PublicationId);
var itemReferenceCriteria = new ItemReferenceCriteria(templateTcmUri.ItemId);
var itemTypeTypeCriteria = new ItemTypeCriteria(32);

var query = new Tridion.ContentDelivery.DynamicContent.Query.Query(
CriteriaFactory.And(new Criteria[] { publicationCriteria, itemReferenceCriteria, itemTypeTypeCriteria }));

var results = query.ExecuteEntityQuery();
if (results != null)
{
var templateMeta = (ITemplateMeta)results.FirstOrDefault();

var componentPresentation = new ComponentPresentation();
componentPresentation.Component = component as Component;
componentPresentation.IsDynamic = true;

var template = new ComponentTemplate()
{
Id = templateUri,
Title = templateMeta.Title,
OutputFormat = templateMeta.OutputFormat
};
componentPresentation.ComponentTemplate = template;
return componentPresentation;
}
}
return null;
}

public bool TryGetComponentPresentation(string componentUri, string templateUri, out IComponentPresentation componentPresentation)
{
componentPresentation = GetComponentPresentation(componentUri, templateUri);
return componentPresentation != null;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DD4T.ContentModel;

namespace Sdl.Web.Modules.SmartTarget.DD4T.Factories
{
public interface IComponentPresentationFactory
{
IComponentPresentation GetComponentPresentation(string componentUri, string templateUri);

bool TryGetComponentPresentation(string componentUri, string templateUri, out IComponentPresentation componentPresentation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Sdl.Web.Common.Models;
using Sdl.Web.DD4T.Html;
using Sdl.Web.Modules.SmartTarget.Interfaces;
using Sdl.Web.Modules.SmartTarget.Models;
using Sdl.Web.Modules.SmartTarget.Analytics;
using Sdl.Web.Mvc.Configuration;

namespace Sdl.Web.Modules.SmartTarget.DD4T.Html
{
public class SmartTargetRenderer : DD4TRenderer, ISmartTargetRenderer
{
private const string _defaultSiteEditTag = "span";

public MvcHtmlString RenderSmartTargetQuery(SmartTargetRegion region, HtmlHelper helper, string siteEditTag = _defaultSiteEditTag)
{
var siteEditOpenTag = String.Format("<{0}>", siteEditTag);
var siteEditCloseTag = String.Format("</{0}>", siteEditTag);

var xmpMarkup = new StringBuilder();
var isPreview = WebRequestContext.IsPreview;
if (isPreview)
{
xmpMarkup.AppendLine(siteEditOpenTag);
xmpMarkup.AppendLine(region.XpmMarkup);
}
if (region.HasSmartTargetContent)
{
foreach (var promotion in region.Items.Cast<SmartTargetPromotion>().Where(p => p.IsVisible))
{
if (isPreview)
{
xmpMarkup.AppendLine(siteEditOpenTag);
xmpMarkup.AppendLine(promotion.XpmMarkup);
}
foreach (var item in promotion.Items.Where(i => i.IsVisible))
{
xmpMarkup.AppendLine(RenderPromotionContent(promotion, helper));
}
if (isPreview)
{
xmpMarkup.AppendLine(siteEditCloseTag);
}
}
}
else
{
// Fallback content
foreach (var item in region.Items)
{
xmpMarkup.AppendLine(RenderEntity(item, helper).ToHtmlString());
}
}
if (isPreview)
{
xmpMarkup.AppendLine(siteEditCloseTag);
}

return MvcHtmlString.Create(xmpMarkup.ToString());
}

public MvcHtmlString RenderSmartTargetPromotion(SmartTargetPromotion promotion, HtmlHelper helper)
{
return new MvcHtmlString(RenderPromotionContent(promotion, helper));
}

private string RenderPromotionContent(SmartTargetPromotion promotion, HtmlHelper helper)
{
var renderedContent = new StringBuilder();
foreach (var item in promotion.Items.Where(i => i.IsVisible))
{
renderedContent.AppendLine(RenderEntity(item.Entity, helper).ToHtmlString());
}

if (promotion is SmartTargetExperiment)
{
var experiment = promotion as SmartTargetExperiment;
string renderedContentWithTrackedLinks = SmartTargetAnalytics.AddTrackingToLinks(renderedContent.ToString(), experiment);

SmartTargetAnalytics.TrackView(experiment);
SmartTargetAnalytics.SaveExperimentCookies(experiment);

return renderedContentWithTrackedLinks;
}
else
{
return renderedContent.ToString();
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Linq;
using System.Collections.Generic;
using DD4T.ContentModel;
using DD4T.ContentModel.Factories;
using Sdl.Web.Common.Interfaces;
using Sdl.Web.DD4T.Mapping;
using Sdl.Web.Modules.SmartTarget.DD4T.Factories;
using Sdl.Web.Modules.SmartTarget.Models;
using Sdl.Web.Modules.SmartTarget.Query;
using Sdl.Web.Modules.SmartTarget.Utils;

namespace Sdl.Web.Modules.SmartTarget.DD4T.Mapping
{
public class SmartTargetModelBuilder : DD4TModelBuilder
{
private IComponentPresentationFactory _componentPresentationFactory;

public SmartTargetModelBuilder(ILinkFactory linkFactory, IContentResolver contentResolver, IComponentPresentationFactory componentPresentationFactory)
: base(linkFactory, contentResolver)
{
_componentPresentationFactory = componentPresentationFactory;
}

protected override object CreatePage(object sourceEntity, Type type, List<object> includes)
{
var page = base.CreatePage(sourceEntity, type, includes) as Sdl.Web.Common.Models.IPage;
if (page != null)
{
Dictionary<string, string> moduleMap;
List<SmartTargetRegionConfig> regionConfigList;
if (TryGetSmartTargetRegionConfiguration(sourceEntity, out moduleMap, out regionConfigList))
{
var queryResults = SmartTargetQuery.GetPagePromotions(regionConfigList);
foreach (var queryResult in queryResults)
{
var region = new SmartTargetRegion
{
Module = moduleMap[queryResult.RegionName],
Name = queryResult.RegionName,
XpmMarkup = queryResult.XpmMarkup,
HasSmartTargetContent = queryResult.HasSmartTargetContent
};

if (region.HasSmartTargetContent)
{
foreach (var promotion in queryResult.Promotions)
{
RetrievePromotionEntities(promotion);
region.Items.Add(promotion);
}
}
else
{
var fallbackContent = page.Regions.ContainsKey(region.Name) ? page.Regions[region.Name] : null;
if (fallbackContent != null)
{
region.Items = fallbackContent.Items;
}
}
page.Regions[region.Name] = region;
}
}
}
return page;
}

private bool TryGetSmartTargetRegionConfiguration(object sourceEntity, out Dictionary<string, string> moduleMap, out List<SmartTargetRegionConfig> regionConfigList)
{
moduleMap = new Dictionary<string, string>();
regionConfigList = new List<SmartTargetRegionConfig>();

IPage page = sourceEntity as IPage;
if (page != null && page.PageTemplate.MetadataFields.ContainsKey("smartTargetRegions"))
{
foreach (var smartTargetRegion in page.PageTemplate.MetadataFields["smartTargetRegions"].EmbeddedValues)
{
string module, regionName;
ViewUtils.ParseViewName(smartTargetRegion["regionName"].Value, out module, out regionName); //Mandatory field; regionName
moduleMap[regionName] = module;

int maxItems = 0;
Int32.TryParse(smartTargetRegion["maxItems"].Value, out maxItems); //Mandatory field; maxItems

bool allowDuplicates = AllowDuplicatesValueHelper.DefaultAllowDuplicates;
if (smartTargetRegion.ContainsKey("allowDuplicates"))
{
allowDuplicates = AllowDuplicatesValueHelper.Parse(smartTargetRegion["allowDuplicates"].Value); //Optional field; allowDuplicates
}

var regionConfig = new SmartTargetRegionConfig
{
PageId = page.Id,
RegionName = regionName,
MaxItems = maxItems,
AllowDuplicates = allowDuplicates
};
regionConfigList.Add(regionConfig);
}
return true;
}
return false;
}

private void RetrievePromotionEntities(SmartTargetPromotion promotion)
{
foreach (var promotionItem in promotion.Items.Where(p => p.IsVisible))
{
IComponentPresentation componentPresentation;
if (_componentPresentationFactory.TryGetComponentPresentation(promotionItem.ComponentUri, promotionItem.TemplateUri, out componentPresentation))
{
promotionItem.Entity = componentPresentation;
}
}
}

}
}
Loading