From 8da27e0b74b5aa1cce4e2643f653e70fe2a37d62 Mon Sep 17 00:00:00 2001 From: netwer Date: Sat, 15 Oct 2016 13:27:07 +0300 Subject: [PATCH] some cleanup code in the private method GetSiteMaster() --- .../Web/Controls/BlogBasePage.cs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs b/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs index 3854eb632..e2732b182 100644 --- a/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs +++ b/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs @@ -1,4 +1,6 @@ -namespace BlogEngine.Core.Web.Controls +using System.IO; + +namespace BlogEngine.Core.Web.Controls { using System; using System.Web; @@ -256,34 +258,39 @@ protected override void Render(HtmlTextWriter writer) /// Path to the master page string GetSiteMaster() { - if (Request.FilePath.Contains("post.aspx", StringComparison.InvariantCultureIgnoreCase)) + if(FilePathContains("post.aspx")) { string path = $"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.Theme}/post.master"; - if (System.IO.File.Exists(Server.MapPath(path))) + if (File.Exists(Server.MapPath(path))) return path; } // if page.master exists, use it for all common pages // and site.master only for post list - if (Request.FilePath.Contains("page.aspx", StringComparison.InvariantCultureIgnoreCase) || - Request.FilePath.Contains("archive.aspx", StringComparison.InvariantCultureIgnoreCase) || - Request.FilePath.Contains("contact.aspx", StringComparison.InvariantCultureIgnoreCase) || - Request.FilePath.Contains("error.aspx", StringComparison.InvariantCultureIgnoreCase) || - Request.FilePath.Contains("error404.aspx", StringComparison.InvariantCultureIgnoreCase) || - Request.FilePath.Contains("search.aspx", StringComparison.InvariantCultureIgnoreCase)) + if (PageMasterExists) { string path = $"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.Theme}/page.master"; - if (System.IO.File.Exists(Server.MapPath(path))) + if (File.Exists(Server.MapPath(path))) return path; } var siteMaster = $"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.GetThemeWithAdjustments(null)}/site.master"; - if (System.IO.File.Exists(Server.MapPath(siteMaster))) - return siteMaster; - else - return $"{Utils.ApplicationRelativeWebRoot}Custom/Themes/Standard/site.master"; + return File.Exists(Server.MapPath(siteMaster)) + ? siteMaster + : $"{Utils.ApplicationRelativeWebRoot}Custom/Themes/Standard/site.master"; + } + + private bool PageMasterExists => FilePathContains("page.aspx") || + FilePathContains("archive.aspx") || + FilePathContains("contact.aspx") || + FilePathContains("error.aspx") || + FilePathContains("error404.aspx") || + FilePathContains("search.aspx"); + private bool FilePathContains(string path) + { + return Request.FilePath.Contains(path, StringComparison.InvariantCultureIgnoreCase); } } } \ No newline at end of file