From 6c8b3956c55619dcac2c4f20a06109ee211c4eab Mon Sep 17 00:00:00 2001 From: ninianne98 Date: Mon, 8 Feb 2016 08:40:39 -0600 Subject: [PATCH] move FileDataHelper into generic web controls --- CMSAdmin/c3-admin/FileBrowser.aspx.cs | 3 +- CMSAdmin/c3-admin/FileUp.ashx.cs | 3 +- CMSAdmin/c3-admin/SiteSkinEdit.aspx.cs | 3 +- CMSAdmin/c3-admin/wp-SiteImport.aspx.cs | 5 ++- CMSCore/CMSCore.csproj | 1 - CMSCore/ConfigHelper/CMSConfigHelper.cs | 12 ++++++ .../GalleryObjects/GalleryBase.cs | 10 +---- PluginPhotoGallery/PhotoGalleryAdmin.ascx.cs | 1 + .../PhotoGalleryAdminImportWP.ascx.cs | 1 + .../PhotoGalleryAdminMetaData.ascx.cs | 14 ++----- .../Utilities => WebControls}/FileData.cs | 41 ++++++++++--------- WebControls/WebControls.csproj | 1 + 12 files changed, 51 insertions(+), 44 deletions(-) rename {CMSCore/Utilities => WebControls}/FileData.cs (92%) diff --git a/CMSAdmin/c3-admin/FileBrowser.aspx.cs b/CMSAdmin/c3-admin/FileBrowser.aspx.cs index a39f0d02..3da4f693 100644 --- a/CMSAdmin/c3-admin/FileBrowser.aspx.cs +++ b/CMSAdmin/c3-admin/FileBrowser.aspx.cs @@ -4,6 +4,7 @@ using System.Web.UI.WebControls; using Carrotware.CMS.Core; using Carrotware.CMS.UI.Controls; +using Carrotware.Web.UI.Controls; /* * CarrotCake CMS @@ -24,7 +25,7 @@ public partial class FileBrowser : AdminBasePage { public string sViewMode = String.Empty; private string defaultBrowseMode = "file"; - protected FileDataHelper helpFile = new FileDataHelper(); + protected FileDataHelper helpFile = CMSConfigHelper.GetFileDataHelper(); protected void Page_Load(object sender, EventArgs e) { try { sQueryPath = Request.QueryString["fldrpath"]; } catch { sQueryPath = @"/"; } diff --git a/CMSAdmin/c3-admin/FileUp.ashx.cs b/CMSAdmin/c3-admin/FileUp.ashx.cs index 78eaa85d..5d2d3ef0 100644 --- a/CMSAdmin/c3-admin/FileUp.ashx.cs +++ b/CMSAdmin/c3-admin/FileUp.ashx.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Web; using Carrotware.CMS.Core; +using Carrotware.Web.UI.Controls; /* * CarrotCake CMS @@ -23,7 +24,7 @@ public class FileUp : IHttpHandler { try { if (context.Request.Files != null && context.Request.Files.Count > 0) { - FileDataHelper helpFile = new FileDataHelper(); + FileDataHelper helpFile = CMSConfigHelper.GetFileDataHelper(); for (int i = 0; i < context.Request.Files.Count; i++) { HttpPostedFile file = context.Request.Files[i]; diff --git a/CMSAdmin/c3-admin/SiteSkinEdit.aspx.cs b/CMSAdmin/c3-admin/SiteSkinEdit.aspx.cs index 86582e21..16cdbcbf 100644 --- a/CMSAdmin/c3-admin/SiteSkinEdit.aspx.cs +++ b/CMSAdmin/c3-admin/SiteSkinEdit.aspx.cs @@ -6,6 +6,7 @@ using System.Web; using Carrotware.CMS.Core; using Carrotware.CMS.UI.Controls; +using Carrotware.Web.UI.Controls; /* * CarrotCake CMS @@ -20,7 +21,7 @@ namespace Carrotware.CMS.UI.Admin.c3_admin { public partial class SiteSkinEdit : AdminBasePage { - protected FileDataHelper helpFile = new FileDataHelper(); + protected FileDataHelper helpFile = CMSConfigHelper.GetFileDataHelper(); public string sTemplateFileQS = String.Empty; protected string sTemplateFile = String.Empty; protected string sFullFilePath = String.Empty; diff --git a/CMSAdmin/c3-admin/wp-SiteImport.aspx.cs b/CMSAdmin/c3-admin/wp-SiteImport.aspx.cs index e41f961d..4fe687f2 100644 --- a/CMSAdmin/c3-admin/wp-SiteImport.aspx.cs +++ b/CMSAdmin/c3-admin/wp-SiteImport.aspx.cs @@ -6,6 +6,7 @@ using System.Web.Security; using Carrotware.CMS.Core; using Carrotware.CMS.UI.Controls; +using Carrotware.Web.UI.Controls; /* * CarrotCake CMS @@ -109,9 +110,11 @@ public partial class wp_SiteImport : AdminBasePage { } lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith(SiteData.AdminFolderPath)); + lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith("/app_code/")); + lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith("/app_data/")); + lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith("/aspnet_client/")); lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith("/bin/")); lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith("/obj/")); - lstFolders.RemoveAll(f => f.FileName.ToLowerInvariant().StartsWith("/app_data/")); GeneralUtilities.BindListDefaultText(ddlFolders, lstFolders.OrderBy(f => f.FileName), null, "Folders", "-[none]-"); } diff --git a/CMSCore/CMSCore.csproj b/CMSCore/CMSCore.csproj index 1acc4788..90b7cfda 100644 --- a/CMSCore/CMSCore.csproj +++ b/CMSCore/CMSCore.csproj @@ -128,7 +128,6 @@ - diff --git a/CMSCore/ConfigHelper/CMSConfigHelper.cs b/CMSCore/ConfigHelper/CMSConfigHelper.cs index 4244943c..9abf7afc 100644 --- a/CMSCore/ConfigHelper/CMSConfigHelper.cs +++ b/CMSCore/ConfigHelper/CMSConfigHelper.cs @@ -11,6 +11,7 @@ using System.Web.UI; using System.Xml.Serialization; using Carrotware.CMS.Data; +using Carrotware.Web.UI.Controls; /* * CarrotCake CMS @@ -154,6 +155,17 @@ private enum CMSConfigFileType { } } + public static FileDataHelper GetFileDataHelper() { + string fileTypes = null; + + CarrotCakeConfig config = CarrotCakeConfig.GetConfig(); + if (config.FileManagerConfig != null && !String.IsNullOrEmpty(config.FileManagerConfig.BlockedExtensions)) { + fileTypes = config.FileManagerConfig.BlockedExtensions; + } + + return new FileDataHelper(fileTypes); + } + private static DataSet ReadDataSetConfig(CMSConfigFileType cfg, string sPath) { string sPlugCfg = "default.config"; string sRealPath = HttpContext.Current.Server.MapPath(sPath); diff --git a/PluginPhotoGallery/GalleryObjects/GalleryBase.cs b/PluginPhotoGallery/GalleryObjects/GalleryBase.cs index 0591642e..bf9c2bfc 100644 --- a/PluginPhotoGallery/GalleryObjects/GalleryBase.cs +++ b/PluginPhotoGallery/GalleryObjects/GalleryBase.cs @@ -1,18 +1,12 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; using Carrotware.CMS.Core; -using Carrotware.CMS.Interface; - +using Carrotware.Web.UI.Controls; namespace Carrotware.CMS.UI.Plugins.PhotoGallery { public class GalleryBase { - protected FileDataHelper fileHelper = new FileDataHelper(); private SiteData _site = null; @@ -28,7 +22,5 @@ public class GalleryBase { _site = value; } } - - } } \ No newline at end of file diff --git a/PluginPhotoGallery/PhotoGalleryAdmin.ascx.cs b/PluginPhotoGallery/PhotoGalleryAdmin.ascx.cs index 7900aef0..1fbbcbb7 100644 --- a/PluginPhotoGallery/PhotoGalleryAdmin.ascx.cs +++ b/PluginPhotoGallery/PhotoGalleryAdmin.ascx.cs @@ -5,6 +5,7 @@ using System.Web; using Carrotware.CMS.Core; using Carrotware.CMS.Interface; +using Carrotware.Web.UI.Controls; namespace Carrotware.CMS.UI.Plugins.PhotoGallery { diff --git a/PluginPhotoGallery/PhotoGalleryAdminImportWP.ascx.cs b/PluginPhotoGallery/PhotoGalleryAdminImportWP.ascx.cs index b55c4bcc..69a19c0c 100644 --- a/PluginPhotoGallery/PhotoGalleryAdminImportWP.ascx.cs +++ b/PluginPhotoGallery/PhotoGalleryAdminImportWP.ascx.cs @@ -6,6 +6,7 @@ using System.Web.UI.WebControls; using Carrotware.CMS.Core; using Carrotware.CMS.Interface; +using Carrotware.Web.UI.Controls; namespace Carrotware.CMS.UI.Plugins.PhotoGallery { diff --git a/PluginPhotoGallery/PhotoGalleryAdminMetaData.ascx.cs b/PluginPhotoGallery/PhotoGalleryAdminMetaData.ascx.cs index 70e32866..39c33f7e 100644 --- a/PluginPhotoGallery/PhotoGalleryAdminMetaData.ascx.cs +++ b/PluginPhotoGallery/PhotoGalleryAdminMetaData.ascx.cs @@ -1,23 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; -using Carrotware.CMS.Interface; using Carrotware.CMS.Core; - +using Carrotware.CMS.Interface; +using Carrotware.Web.UI.Controls; namespace Carrotware.CMS.UI.Plugins.PhotoGallery { - public partial class PhotoGalleryAdminMetaData : AdminModule { - Guid gTheID = Guid.Empty; + public partial class PhotoGalleryAdminMetaData : AdminModule { + private Guid gTheID = Guid.Empty; public string sImageFile = ""; protected FileDataHelper helpFile = new FileDataHelper(); protected void Page_Load(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(Request.QueryString["id"])) { gTheID = new Guid(Request.QueryString["id"].ToString()); } @@ -45,7 +41,6 @@ public partial class PhotoGalleryAdminMetaData : AdminModule { } protected void btnSave_Click(object sender, EventArgs e) { - GalleryHelper gh = new GalleryHelper(SiteID); var meta = gh.GalleryMetaDataGetByFilename(sImageFile); @@ -63,6 +58,5 @@ public partial class PhotoGalleryAdminMetaData : AdminModule { Response.Redirect(SiteData.CurrentScriptName + "?" + Request.QueryString.ToString()); } - } } \ No newline at end of file diff --git a/CMSCore/Utilities/FileData.cs b/WebControls/FileData.cs similarity index 92% rename from CMSCore/Utilities/FileData.cs rename to WebControls/FileData.cs index e383274a..2ea4c9ec 100644 --- a/CMSCore/Utilities/FileData.cs +++ b/WebControls/FileData.cs @@ -14,7 +14,7 @@ * Date: October 2011 */ -namespace Carrotware.CMS.Core { +namespace Carrotware.Web.UI.Controls { public class FileData { @@ -31,7 +31,7 @@ public class FileData { public string FileName { get; set; } public string FileExtension { get; set; } public DateTime FileDate { get; set; } - public int FileSize { get; set; } + public long FileSize { get; set; } public string FileSizeFriendly { get; set; } public string FolderPath { get; set; } public string MimeType { get; set; } @@ -65,6 +65,10 @@ public class FileDataHelper { public FileDataHelper() { } + public FileDataHelper(string blockedExts) { + _blockedTypes = blockedExts; + } + private static string _wwwpath = null; private static string WWWPath { @@ -79,25 +83,19 @@ public class FileDataHelper { } } - private string _FileTypes = null; + private string _blockedTypes = null; public List BlockedTypes { get { - if (_FileTypes == null) { - CarrotCakeConfig config = CarrotCakeConfig.GetConfig(); - if (config.FileManagerConfig != null && !string.IsNullOrEmpty(config.FileManagerConfig.BlockedExtensions)) { - _FileTypes = config.FileManagerConfig.BlockedExtensions; - } + if (_blockedTypes == null) { + _blockedTypes = "asp;aspx;ascx;asmx;svc;asax;axd;ashx;dll;pdb;exe;cs;vb;cshtml;vbhtml;master;config;xml;user;csproj;vbproj;sln"; } - if (_FileTypes == null) { - _FileTypes = "asp;aspx;ascx;asmx;svc;asax;axd;ashx;dll;pdb;exe;cs;vb;cshtml;vbhtml;master;config;xml;user;csproj;vbproj;sln"; - } - return _FileTypes.Split(';').ToList(); + return _blockedTypes.Split(';').ToList(); } } public void IncludeAllFiletypes() { - _FileTypes = String.Empty; + _blockedTypes = String.Empty; } public FileData GetFolderInfo(string sQuery, string myFile) { @@ -186,7 +184,7 @@ public class FileDataHelper { f.FileName = myFileName; f.FolderPath = MakeFilePathUniform(sP); f.FileDate = myFileDate; - f.FileSize = Convert.ToInt32(myFileSize); + f.FileSize = myFileSize; f.FileSizeFriendly = myFileSizeF; if (!string.IsNullOrEmpty(MyFile.Extension)) { f.FileExtension = MyFile.Extension.ToLowerInvariant(); @@ -356,13 +354,14 @@ where b.ToLowerInvariant().Replace(".", String.Empty) == f.FileExtension.Replace _dict.Add(".aps", "application/mime"); _dict.Add(".arc", "application/octet-stream"); _dict.Add(".arj", "application/octet-stream"); + _dict.Add(".asa", "text/asp"); + _dict.Add(".asax", "text/aspx"); + _dict.Add(".ascx", "text/aspx"); _dict.Add(".asf", "video/x-ms-asf"); _dict.Add(".asm", "text/x-asm"); - _dict.Add(".asmx", "text/asp"); - _dict.Add(".ascx", "text/asp"); + _dict.Add(".asmx", "text/aspx"); _dict.Add(".asp", "text/asp"); - _dict.Add(".aspx", "text/asp"); - _dict.Add(".asax", "text/asp"); + _dict.Add(".aspx", "text/aspx"); _dict.Add(".asx", "video/x-ms-asf"); _dict.Add(".au", "audio/basic"); _dict.Add(".avi", "video/avi"); @@ -378,10 +377,11 @@ where b.ToLowerInvariant().Replace(".", String.Empty) == f.FileExtension.Replace _dict.Add(".class", "application/java"); _dict.Add(".com", "application/octet-stream"); _dict.Add(".conf", "text/plain"); - _dict.Add(".config", "text/asp"); + _dict.Add(".config", "text/aspx"); _dict.Add(".cpp", "text/x-c"); _dict.Add(".crt", "application/x-x509-ca-cert"); _dict.Add(".csh", "application/x-csh"); + _dict.Add(".cshtml", "text/aspx"); _dict.Add(".css", "text/css"); _dict.Add(".def", "text/plain"); _dict.Add(".dir", "application/x-director"); @@ -460,10 +460,10 @@ where b.ToLowerInvariant().Replace(".", String.Empty) == f.FileExtension.Replace _dict.Add(".movie", "video/x-sgi-movie"); _dict.Add(".mp2", "video/mpeg"); _dict.Add(".mp3", "audio/mpeg3"); + _dict.Add(".mp4", "video/mp4"); _dict.Add(".mpa", "audio/mpeg"); _dict.Add(".mpeg", "video/mpeg"); _dict.Add(".mpg", "video/mpeg"); - _dict.Add(".mp4", "video/mp4"); _dict.Add(".mpga", "audio/mpeg"); _dict.Add(".mpp", "application/vnd.ms-project"); _dict.Add(".mpt", "application/x-project"); @@ -527,6 +527,7 @@ where b.ToLowerInvariant().Replace(".", String.Empty) == f.FileExtension.Replace _dict.Add(".tiff", "image/tiff"); _dict.Add(".uu", "application/octet-stream"); _dict.Add(".uue", "text/x-uuencode"); + _dict.Add(".vbhtml", "text/aspx"); _dict.Add(".vcs", "text/x-vcalendar"); _dict.Add(".vda", "application/vda"); _dict.Add(".vrml", "application/x-vrml"); diff --git a/WebControls/WebControls.csproj b/WebControls/WebControls.csproj index ba4415da..c35b964c 100644 --- a/WebControls/WebControls.csproj +++ b/WebControls/WebControls.csproj @@ -83,6 +83,7 @@ +