Skip to content

Commit

Permalink
move FileDataHelper into generic web controls
Browse files Browse the repository at this point in the history
  • Loading branch information
ninianne98 committed Feb 8, 2016
1 parent 05cfd95 commit 6c8b395
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 44 deletions.
3 changes: 2 additions & 1 deletion CMSAdmin/c3-admin/FileBrowser.aspx.cs
Expand Up @@ -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
Expand All @@ -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 = @"/"; }
Expand Down
3 changes: 2 additions & 1 deletion CMSAdmin/c3-admin/FileUp.ashx.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Web;
using Carrotware.CMS.Core;
using Carrotware.Web.UI.Controls;

/*
* CarrotCake CMS
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion CMSAdmin/c3-admin/SiteSkinEdit.aspx.cs
Expand Up @@ -6,6 +6,7 @@
using System.Web;
using Carrotware.CMS.Core;
using Carrotware.CMS.UI.Controls;
using Carrotware.Web.UI.Controls;

/*
* CarrotCake CMS
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion CMSAdmin/c3-admin/wp-SiteImport.aspx.cs
Expand Up @@ -6,6 +6,7 @@
using System.Web.Security;
using Carrotware.CMS.Core;
using Carrotware.CMS.UI.Controls;
using Carrotware.Web.UI.Controls;

/*
* CarrotCake CMS
Expand Down Expand Up @@ -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]-");
}
Expand Down
1 change: 0 additions & 1 deletion CMSCore/CMSCore.csproj
Expand Up @@ -128,7 +128,6 @@
<Compile Include="Security\ProfileManager.cs" />
<Compile Include="Security\SecurityData.cs" />
<Compile Include="ConfigHelper\UserEditState.cs" />
<Compile Include="Utilities\FileData.cs" />
<Compile Include="ConfigHelper\LabeledControl.cs" />
<Compile Include="SiteContent\Widget.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
12 changes: 12 additions & 0 deletions CMSCore/ConfigHelper/CMSConfigHelper.cs
Expand Up @@ -11,6 +11,7 @@
using System.Web.UI;
using System.Xml.Serialization;
using Carrotware.CMS.Data;
using Carrotware.Web.UI.Controls;

/*
* CarrotCake CMS
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 1 addition & 9 deletions 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;
Expand All @@ -28,7 +22,5 @@ public class GalleryBase {
_site = value;
}
}


}
}
1 change: 1 addition & 0 deletions PluginPhotoGallery/PhotoGalleryAdmin.ascx.cs
Expand Up @@ -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 {

Expand Down
1 change: 1 addition & 0 deletions PluginPhotoGallery/PhotoGalleryAdminImportWP.ascx.cs
Expand Up @@ -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 {

Expand Down
14 changes: 4 additions & 10 deletions 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());
}
Expand Down Expand Up @@ -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);

Expand All @@ -63,6 +58,5 @@ public partial class PhotoGalleryAdminMetaData : AdminModule {

Response.Redirect(SiteData.CurrentScriptName + "?" + Request.QueryString.ToString());
}

}
}
41 changes: 21 additions & 20 deletions CMSCore/Utilities/FileData.cs → WebControls/FileData.cs
Expand Up @@ -14,7 +14,7 @@
* Date: October 2011
*/

namespace Carrotware.CMS.Core {
namespace Carrotware.Web.UI.Controls {

public class FileData {

Expand All @@ -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; }
Expand Down Expand Up @@ -65,6 +65,10 @@ public class FileDataHelper {

public FileDataHelper() { }

public FileDataHelper(string blockedExts) {
_blockedTypes = blockedExts;
}

private static string _wwwpath = null;

private static string WWWPath {
Expand All @@ -79,25 +83,19 @@ public class FileDataHelper {
}
}

private string _FileTypes = null;
private string _blockedTypes = null;

public List<string> 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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions WebControls/WebControls.csproj
Expand Up @@ -83,6 +83,7 @@
<Compile Include="captcha\CaptchaImage.cs" />
<Compile Include="CarrotGridPaged.cs" />
<Compile Include="EnumHelper.cs" />
<Compile Include="FileData.cs" />
<Compile Include="ReflectionUtilities.cs" />
<Compile Include="SimpleStyle.cs" />
<Compile Include="CarrotGridView\CarrotGridView.cs" />
Expand Down

0 comments on commit 6c8b395

Please sign in to comment.