From 89d4304362ca12c8dcf37653d240fd5de97503c0 Mon Sep 17 00:00:00 2001 From: Michael Santoro Date: Wed, 17 Feb 2021 08:34:18 -0700 Subject: [PATCH 1/5] #4499 Take Page Stylesheet from FolderProvider, add CSS to content types --- .../FileSystem/FileContentTypeManager.cs | 1 + DNN Platform/Website/Default.aspx.cs | 41 ++++++++++++++++++- .../SqlDataProvider/09.09.01.SqlDataProvider | 12 ++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider diff --git a/DNN Platform/Library/Services/FileSystem/FileContentTypeManager.cs b/DNN Platform/Library/Services/FileSystem/FileContentTypeManager.cs index 67c6764af95..d7efa9f7ad3 100644 --- a/DNN Platform/Library/Services/FileSystem/FileContentTypeManager.cs +++ b/DNN Platform/Library/Services/FileSystem/FileContentTypeManager.cs @@ -101,6 +101,7 @@ private Dictionary GetDefaultContentTypes() contentTypes.Add("pps", "application/vnd.ms-powerpoint"); contentTypes.Add("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); contentTypes.Add("ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"); + contentTypes.Add("css", "text/css"); return contentTypes; } diff --git a/DNN Platform/Website/Default.aspx.cs b/DNN Platform/Website/Default.aspx.cs index 872a682d09f..65f10cc5017 100644 --- a/DNN Platform/Website/Default.aspx.cs +++ b/DNN Platform/Website/Default.aspx.cs @@ -632,8 +632,29 @@ 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 = Path.Combine(this.PortalSettings.HomeDirectory, this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString()); - ClientResourceManager.RegisterStyleSheet(this, customStylesheet); + 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 in the Page Header + IFileInfo fi = GetPageStylesheetFileInfo(); + if (fi != null) + { + string url = FileManager.Instance.GetUrl(fi); + if (url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) + { + string cssLink = string.Format("", url); + this.Page.Header.Controls.Add(new LiteralControl(cssLink)); + cssIncluded = true; + } + } + + // Include it as DNN always has, as a relative path through ClientResourceManager + if (!cssIncluded) + { + var customStylesheetPath = Path.Combine(this.PortalSettings.HomeDirectory, customStylesheet); + ClientResourceManager.RegisterStyleSheet(this, customStylesheetPath); + } } // Cookie Consent @@ -737,5 +758,21 @@ private IFileInfo GetBackgroundFileInfoCallBack(CacheItemArgs itemArgs) { return FileManager.Instance.GetFile(this.PortalSettings.PortalId, this.PortalSettings.BackgroundFile); } + + private IFileInfo GetPageStylesheetFileInfo() + { + string cacheKey = string.Format(Common.Utilities.DataCache.PortalCacheKey, this.PortalSettings.PortalId, "PageStylesheet" + this.PortalSettings.ActiveTab.TabID); + var file = CBO.GetCachedObject( + new CacheItemArgs(cacheKey, Common.Utilities.DataCache.PortalCacheTimeOut, Common.Utilities.DataCache.PortalCachePriority), + 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); + } } } diff --git a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider new file mode 100644 index 00000000000..63a8149c0ea --- /dev/null +++ b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider @@ -0,0 +1,12 @@ +/************************************************************/ +/***** SqlDataProvider *****/ +/***** *****/ +/***** *****/ +/***** Note: To manually execute this script you must *****/ +/***** perform a search and replace operation *****/ +/***** for {databaseOwner} and {objectQualifier} *****/ +/***** *****/ +/************************************************************/ + +-- Add CSS contnet type, this will help when a Page Style Sheet is uploaded to a folder provider such as AzureFolderProvider. +INSERT INTO {databaseOwner}[{objectQualifier}Lists] ( [ListName], [Value], [Text], [ParentID], [Level], [SortOrder], [DefinitionID], [Description], [PortalID], [SystemList], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate]) VALUES (N'ContentTypes', N'css', N'text/css', 0, 0, 0, -1, N'', -1, 1, -1, '2020-02-17 09:13:51.647', -1, '2020-02-17 09:13:51.647') From d885ef93f2b0c975a62baa962f0ecde351440d3b Mon Sep 17 00:00:00 2001 From: Michael Santoro Date: Wed, 17 Feb 2021 08:41:22 -0700 Subject: [PATCH 2/5] #4499 check if css record exists (in case a user added it to their dnn) --- .../DataProviders/SqlDataProvider/09.09.01.SqlDataProvider | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider index 63a8149c0ea..63840ef1044 100644 --- a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider +++ b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider @@ -9,4 +9,7 @@ /************************************************************/ -- Add CSS contnet type, this will help when a Page Style Sheet is uploaded to a folder provider such as AzureFolderProvider. -INSERT INTO {databaseOwner}[{objectQualifier}Lists] ( [ListName], [Value], [Text], [ParentID], [Level], [SortOrder], [DefinitionID], [Description], [PortalID], [SystemList], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate]) VALUES (N'ContentTypes', N'css', N'text/css', 0, 0, 0, -1, N'', -1, 1, -1, '2020-02-17 09:13:51.647', -1, '2020-02-17 09:13:51.647') +IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Lists WHERE ListName='ContentTypes' AND Value = 'css') +BEGIN + INSERT INTO {databaseOwner}[{objectQualifier}Lists] ( [ListName], [Value], [Text], [ParentID], [Level], [SortOrder], [DefinitionID], [Description], [PortalID], [SystemList], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate]) VALUES (N'ContentTypes', N'css', N'text/css', 0, 0, 0, -1, N'', -1, 1, -1, '2020-02-17 09:13:51.647', -1, '2020-02-17 09:13:51.647') +END From 07d7b37d580be5ffcc36ad4ad581dee1ea9a51b4 Mon Sep 17 00:00:00 2001 From: msant7 Date: Mon, 22 Feb 2021 06:04:43 -0700 Subject: [PATCH 3/5] Update DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider Co-authored-by: Brian Dukes --- .../DataProviders/SqlDataProvider/09.09.01.SqlDataProvider | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider index 63840ef1044..5bc71e40009 100644 --- a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider +++ b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider @@ -8,7 +8,7 @@ /***** *****/ /************************************************************/ --- Add CSS contnet type, this will help when a Page Style Sheet is uploaded to a folder provider such as AzureFolderProvider. +-- Add CSS content type, this will help when a Page Style Sheet is uploaded to a folder provider such as AzureFolderProvider. IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Lists WHERE ListName='ContentTypes' AND Value = 'css') BEGIN INSERT INTO {databaseOwner}[{objectQualifier}Lists] ( [ListName], [Value], [Text], [ParentID], [Level], [SortOrder], [DefinitionID], [Description], [PortalID], [SystemList], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate]) VALUES (N'ContentTypes', N'css', N'text/css', 0, 0, 0, -1, N'', -1, 1, -1, '2020-02-17 09:13:51.647', -1, '2020-02-17 09:13:51.647') From 1574d99641a0d62699c454b0e61c24fe566a03a4 Mon Sep 17 00:00:00 2001 From: msant7 Date: Mon, 22 Feb 2021 06:04:58 -0700 Subject: [PATCH 4/5] Update DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider Co-authored-by: Brian Dukes --- .../DataProviders/SqlDataProvider/09.09.01.SqlDataProvider | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider index 5bc71e40009..05b2b72ca6c 100644 --- a/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider +++ b/DNN Platform/Website/Providers/DataProviders/SqlDataProvider/09.09.01.SqlDataProvider @@ -11,5 +11,5 @@ -- Add CSS content type, this will help when a Page Style Sheet is uploaded to a folder provider such as AzureFolderProvider. IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Lists WHERE ListName='ContentTypes' AND Value = 'css') BEGIN - INSERT INTO {databaseOwner}[{objectQualifier}Lists] ( [ListName], [Value], [Text], [ParentID], [Level], [SortOrder], [DefinitionID], [Description], [PortalID], [SystemList], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate]) VALUES (N'ContentTypes', N'css', N'text/css', 0, 0, 0, -1, N'', -1, 1, -1, '2020-02-17 09:13:51.647', -1, '2020-02-17 09:13:51.647') + INSERT INTO {databaseOwner}[{objectQualifier}Lists] ( [ListName], [Value], [Text], [ParentID], [Level], [SortOrder], [DefinitionID], [Description], [PortalID], [SystemList], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate]) VALUES (N'ContentTypes', N'css', N'text/css', 0, 0, 0, -1, N'', -1, 1, -1, GETDATE(), -1, GETDATE()) END From 91f620ec197a5341c3d40183cfe6478a4f0908ea Mon Sep 17 00:00:00 2001 From: Michael Santoro Date: Tue, 23 Feb 2021 07:06:35 -0700 Subject: [PATCH 5/5] refactor including the CustomStyleSheet after fixing an issue in ClientResourceManager.Register Stylesheet --- .../ClientResourceManager.cs | 3 +- DNN Platform/Website/Default.aspx.cs | 37 +++++++------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/DNN Platform/DotNetNuke.Web.Client/ClientResourceManager.cs b/DNN Platform/DotNetNuke.Web.Client/ClientResourceManager.cs index 38d26173136..df949124bf1 100644 --- a/DNN Platform/DotNetNuke.Web.Client/ClientResourceManager.cs +++ b/DNN Platform/DotNetNuke.Web.Client/ClientResourceManager.cs @@ -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))) diff --git a/DNN Platform/Website/Default.aspx.cs b/DNN Platform/Website/Default.aspx.cs index 65f10cc5017..d37f01ad8c4 100644 --- a/DNN Platform/Website/Default.aspx.cs +++ b/DNN Platform/Website/Default.aspx.cs @@ -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 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("", 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); } } @@ -759,11 +748,11 @@ 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( - 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; @@ -771,8 +760,8 @@ private IFileInfo GetPageStylesheetFileInfo() 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); } } }