protected override void OnInit(EventArgs e) { base.OnInit(e); this.PageScriptManager.Services.Add(new ServiceReference("~/CommonFunc.asmx")); editorCSS.Attributes.Add("href", "/css/" + Page.Theme + "/editor.css"); ForumDropDown.DataSource = Forums.AllowedForumsList(Member); ForumDropDown.DataBind(); ModConfigBase controller = (ModConfigBase)ConfigHelper.ModClass("UploadConfig"); AllowedFileTypes = ""; AllowAttachments = Convert.ToBoolean(Convert.ToInt16(controller.ModConfiguration.Settings["AllowAttachments"])); AllowImageUploads = Convert.ToBoolean(Convert.ToInt16(controller.ModConfiguration.Settings["AllowImageUpload"])); FileSizeLimit = Convert.ToInt32(controller.ModConfiguration.Settings["FileSizeLimit"].ToString()); if (AllowImageUploads) { AllowedFileTypes += controller.ModConfiguration.Settings["AllowedImageTypes"].ToString(); } if (AllowAttachments) { if (AllowedFileTypes != "") { AllowedFileTypes += ","; } AllowedFileTypes += controller.ModConfiguration.Settings["AllowedAttachmentTypes"].ToString(); } if (AllowImageUploads || AllowAttachments) { string style = ""; //!ShowAttachments ? ".upload{display:none;}" : if (!Config.UserGallery || !AllowImageUploads) { style += ".browse{display:none;}"; } uploadStyle.Text = !String.IsNullOrEmpty(style) ? string.Format("<style>{0}</style>", style) : ""; } else { uploadStyle.Text = "<style>.upload{display:none;} .browse{display:none;}</style>"; } }
private void AddModControl(string modname) { modPh.Controls.Clear(); ModConfigBase controller = (ModConfigBase)ConfigHelper.ModClass(modname); if (!String.IsNullOrEmpty(controller.ModConfiguration.AdminControl)) { var adminSys = Page.LoadControl(controller.ModConfiguration.AdminControl); adminSys.ID = "modPnl"; modPh.Controls.Add(adminSys); } else { DefaultMod adminSys = (DefaultMod)Page.LoadControl("DefaultMod.ascx"); adminSys.ID = "modPnl"; adminSys.ModName = controller.Name; modPh.Controls.Add(adminSys); } }
protected override void OnInit(EventArgs e) { base.OnInit(e); page = (PageBase)this.Page; cbxSig.Checked = page.Member.UseSignature; ModConfigBase controller = (ModConfigBase)ConfigHelper.ModClass("UploadConfig"); FileSizeLimit = Convert.ToInt32(controller.ModConfiguration.Settings["FileSizeLimit"].ToString()); AllowedFileTypes = ""; AllowAttachments = Convert.ToBoolean(Convert.ToInt16(controller.ModConfiguration.Settings["AllowAttachments"])); AllowImageUploads = Convert.ToBoolean(Convert.ToInt16(controller.ModConfiguration.Settings["AllowImageUpload"])); if (AllowImageUploads) { AllowedFileTypes += controller.ModConfiguration.Settings["AllowedImageTypes"].ToString(); } if (AllowAttachments) { if (AllowedFileTypes != "") { AllowedFileTypes += ","; } AllowedFileTypes += controller.ModConfiguration.Settings["AllowedAttachmentTypes"].ToString(); } if (AllowImageUploads || AllowAttachments) { string style = ""; //!ShowAttachments ? ".upload{display:none;}" : if (!Config.UserGallery || !AllowImageUploads) { style += ".browse{display:none;}"; } uploadStyle.Text = !String.IsNullOrEmpty(style) ? string.Format("<style>{0}</style>", style) : ""; } else { uploadStyle.Text = "<style>.upload{display:none;} .browse{display:none;}</style>"; } }
private void ProcessUpload(AsyncFileUploadEventArgs e) { if (e.FileName == null) { return; } ModConfigBase controller = (ModConfigBase)ConfigHelper.ModClass("UploadConfig"); string types = ""; if (AllowAttachments) { types += controller.ModConfiguration.Settings["AllowedAttachmentTypes"].ToString(); } if (AllowImageUploads) { if (types != "") { types += ","; } types += controller.ModConfiguration.Settings["AllowedImageTypes"].ToString(); } string[] allowedTypes = types.Split(','); //int fileSizeLimit = 10; //Convert.ToInt32(controller.ModConfiguration.Settings["FileSizeLimit"].ToString()); string uploadpath = controller.ModConfiguration.Settings["FileUploadLocation"].ToString(); string filext = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName).Replace(".", ""); string contentType = AsyncFileUpload1.PostedFile.ContentType; bool allowed = false; if (contentType.Contains("image") && !AllowImageUploads) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "prohibited", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'Image upload prohibited';});", true); AsyncFileUpload1.FailedValidation = true; return; } if (!contentType.Contains("image") && !AllowAttachments) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "prohibited", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'File attachments prohibited';});", true); AsyncFileUpload1.FailedValidation = true; return; } foreach (string allowedType in allowedTypes) { if (filext == allowedType) { allowed = true; break; } } if (!allowed || (int.Parse(e.FileSize) > (FileSizeLimit * (1024 * 1024)))) { AsyncFileUpload1.FailedValidation = true; return; } var name = Path.GetFileName(e.FileName); if (contentType.Contains("image")) { uploadpath = "/Gallery"; } string savePath = Page.MapPath(String.Format("{0}/{1}/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+"))); if (File.Exists(savePath)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "exists", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'File already exists';});", true); AsyncFileUpload1.FailedValidation = true; return; } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'Uploaded size: " + e.FileSize + "';});", true); if (!Directory.Exists(Page.MapPath(String.Format("{0}/{1}", uploadpath, HttpContext.Current.User.Identity.Name)))) { Directory.CreateDirectory( Page.MapPath(String.Format("{0}/{1}", uploadpath, HttpContext.Current.User.Identity.Name))); } if (contentType.Contains("image")) { if (e.FileName != null && AllowImageUploads) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tag", "$(function() {top.$get(\"" + imageTag.ClientID + "\").innerHTML = '[img]" + String.Format("{0}/{1}/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+")) + "[/img]';});", true); } } else { if (e.FileName != null && AllowAttachments) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tag", "$(function() {top.$get(\"" + imageTag.ClientID + "\").innerHTML = '[file=" + e.FileName + "]" + String.Format("{0}/{1}/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+")) + "[/file]';});", true); } } AsyncFileUpload1.SaveAs(savePath); if (contentType.Contains("image")) { string thumbPath = Page.MapPath(String.Format("{0}/{1}/thumbnail/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+"))); if (!Directory.Exists(Page.MapPath(String.Format("{0}/{1}/thumbnail", uploadpath, HttpContext.Current.User.Identity.Name)))) { Directory.CreateDirectory(Page.MapPath(String.Format("{0}/{1}/thumbnail", uploadpath, HttpContext.Current.User.Identity.Name))); } GalleryFunctions.CreateThumbnail(savePath, thumbPath, 100); } }