Skip to content

Commit

Permalink
refactor including the CustomStyleSheet after fixing an issue in Clie…
Browse files Browse the repository at this point in the history
…ntResourceManager.Register Stylesheet
  • Loading branch information
Michael Santoro committed Feb 23, 2021
1 parent 1574d99 commit 91f620e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
3 changes: 2 additions & 1 deletion DNN Platform/DotNetNuke.Web.Client/ClientResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public static void RegisterStyleSheet(Page page, string filePath, int priority,

// Some "legacy URLs" could be using their own query string versioning scheme (and we've forced them to use the new API through re-routing PageBase.RegisterStyleSheet
// Ensure that physical CSS files with query strings have their query strings removed
if (filePath.Contains(".css?"))
// Ignore absolute urls, they will not exist locally
if (!Uri.TryCreate(filePath, UriKind.Absolute, out _) && filePath.Contains(".css?"))
{
var filePathSansQueryString = RemoveQueryString(filePath);
if (File.Exists(page.Server.MapPath(filePathSansQueryString)))
Expand Down
37 changes: 13 additions & 24 deletions DNN Platform/Website/Default.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,28 +632,17 @@ private void InitializePage()
// register the custom stylesheet of current page
if (this.PortalSettings.ActiveTab.TabSettings.ContainsKey("CustomStylesheet") && !string.IsNullOrEmpty(this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString()))
{
var customStylesheet = this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString();
var cssIncluded = false;

// Try and go through the FolderProvider first, if it gives back an external url, include it
// as a <link> in the Page Header
IFileInfo fi = GetPageStylesheetFileInfo();
if (fi != null)
var styleSheet = this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString();

// Try and go through the FolderProvider first
var stylesheetFile = GetPageStylesheetFileInfo(styleSheet);
if (stylesheetFile != null)
{
string url = FileManager.Instance.GetUrl(fi);
if (url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
string cssLink = string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", url);
this.Page.Header.Controls.Add(new LiteralControl(cssLink));
cssIncluded = true;
}
ClientResourceManager.RegisterStyleSheet(this, FileManager.Instance.GetUrl(stylesheetFile));
}

// Include it as DNN always has, as a relative path through ClientResourceManager
if (!cssIncluded)
else
{
var customStylesheetPath = Path.Combine(this.PortalSettings.HomeDirectory, customStylesheet);
ClientResourceManager.RegisterStyleSheet(this, customStylesheetPath);
ClientResourceManager.RegisterStyleSheet(this, styleSheet);
}
}

Expand Down Expand Up @@ -759,20 +748,20 @@ private IFileInfo GetBackgroundFileInfoCallBack(CacheItemArgs itemArgs)
return FileManager.Instance.GetFile(this.PortalSettings.PortalId, this.PortalSettings.BackgroundFile);
}

private IFileInfo GetPageStylesheetFileInfo()
private IFileInfo GetPageStylesheetFileInfo(string styleSheet)
{
string cacheKey = string.Format(Common.Utilities.DataCache.PortalCacheKey, this.PortalSettings.PortalId, "PageStylesheet" + this.PortalSettings.ActiveTab.TabID);
string cacheKey = string.Format(Common.Utilities.DataCache.PortalCacheKey, this.PortalSettings.PortalId, "PageStylesheet" + styleSheet);
var file = CBO.GetCachedObject<Services.FileSystem.FileInfo>(
new CacheItemArgs(cacheKey, Common.Utilities.DataCache.PortalCacheTimeOut, Common.Utilities.DataCache.PortalCachePriority),
new CacheItemArgs(cacheKey, Common.Utilities.DataCache.PortalCacheTimeOut, Common.Utilities.DataCache.PortalCachePriority, styleSheet),
this.GetPageStylesheetInfoCallBack);

return file;
}

private IFileInfo GetPageStylesheetInfoCallBack(CacheItemArgs itemArgs)
{
var customStylesheet = this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString();
return FileManager.Instance.GetFile(this.PortalSettings.PortalId, customStylesheet);
var styleSheet = itemArgs.Params[0].ToString();
return FileManager.Instance.GetFile(this.PortalSettings.PortalId, styleSheet);
}
}
}

0 comments on commit 91f620e

Please sign in to comment.