Skip to content

Commit

Permalink
Merge pull request #4500 from msant7/azure-page-css
Browse files Browse the repository at this point in the history
Azure page css
  • Loading branch information
mitchelsellers authored Feb 23, 2021
2 parents edb0fac + 91f620e commit 9db0746
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private Dictionary<string, string> 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;
}
Expand Down
30 changes: 28 additions & 2 deletions DNN Platform/Website/Default.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,18 @@ 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 styleSheet = this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString();

// Try and go through the FolderProvider first
var stylesheetFile = GetPageStylesheetFileInfo(styleSheet);
if (stylesheetFile != null)
{
ClientResourceManager.RegisterStyleSheet(this, FileManager.Instance.GetUrl(stylesheetFile));
}
else
{
ClientResourceManager.RegisterStyleSheet(this, styleSheet);
}
}

// Cookie Consent
Expand Down Expand Up @@ -737,5 +747,21 @@ private IFileInfo GetBackgroundFileInfoCallBack(CacheItemArgs itemArgs)
{
return FileManager.Instance.GetFile(this.PortalSettings.PortalId, this.PortalSettings.BackgroundFile);
}

private IFileInfo GetPageStylesheetFileInfo(string styleSheet)
{
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, styleSheet),
this.GetPageStylesheetInfoCallBack);

return file;
}

private IFileInfo GetPageStylesheetInfoCallBack(CacheItemArgs itemArgs)
{
var styleSheet = itemArgs.Params[0].ToString();
return FileManager.Instance.GetFile(this.PortalSettings.PortalId, styleSheet);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/************************************************************/
/***** SqlDataProvider *****/
/***** *****/
/***** *****/
/***** Note: To manually execute this script you must *****/
/***** perform a search and replace operation *****/
/***** for {databaseOwner} and {objectQualifier} *****/
/***** *****/
/************************************************************/

-- 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, GETDATE(), -1, GETDATE())
END

0 comments on commit 9db0746

Please sign in to comment.