private void cbAttach_Callback(object sender, Modules.ActiveForums.Controls.CallBackEventArgs e) { string attachIds = e.Parameters[1].ToString(); switch (e.Parameters[0].ToLowerInvariant()) { case "delcont": { if (SimulateIsNumeric.IsNumeric(e.Parameters[2])) { int aid = Convert.ToInt32(e.Parameters[2]); int uid = -1; if (SimulateIsNumeric.IsNumeric(e.Parameters[3])) { uid = Convert.ToInt32(e.Parameters[3]); } if ((uid == this.UserId && !(this.UserId == -1)) | Permissions.HasPerm(ForumInfo.Security.ModDelete, ForumUser.UserRoles) || UserInfo.IsSuperUser) { Data.AttachController adb = new Data.AttachController(); adb.Attach_Delete(aid, ContentId); //ac.Attach_Delete(aid, -1, uid) } } break; } case "thumb": { if (SimulateIsNumeric.IsNumeric(e.Parameters[2])) { int aid = Convert.ToInt32(e.Parameters[2]); Data.AttachController ac = new Data.AttachController(); int uid = -1; if (SimulateIsNumeric.IsNumeric(e.Parameters[3])) { uid = Convert.ToInt32(e.Parameters[3]); } AttachInfo ai = ac.Attach_Get(aid, -1, uid, false); if (ai != null) { int w = Convert.ToInt32(e.Parameters[4]); int h = Convert.ToInt32(e.Parameters[5]); System.IO.MemoryStream imgStream = new System.IO.MemoryStream(); string fpath = string.Empty; int fileSize = 0; string tmpFilename = string.Empty; if (ai.FileData != null) { byte[] bindata = null; bindata = (byte[])ai.FileData; System.IO.MemoryStream memStream = new System.IO.MemoryStream(bindata); imgStream = (System.IO.MemoryStream)(Images.CreateImageForDB(memStream, h, w)); fileSize = Convert.ToInt32(imgStream.Length); tmpFilename = "thumb_" + ai.Filename; } else { fpath = Server.MapPath(PortalSettings.HomeDirectory + "activeforums_Attach/"); //fpath &= "thumb_" & ai.Filename tmpFilename = "thumb_" + ai.Filename; string sFullFile = fpath + tmpFilename; int i = 0; while (File.Exists(sFullFile)) { i += 1; tmpFilename = i.ToString().PadLeft(3, '0') + "_thumb_" + ai.Filename; sFullFile = fpath + tmpFilename; } File.Copy(fpath + ai.Filename, sFullFile); Images.CreateImage(sFullFile, h, w); fileSize = (int)new FileInfo(sFullFile).Length; } AttachInfo aiThumb = new AttachInfo(); aiThumb.ContentId = -1; aiThumb.UserID = ai.UserID; aiThumb.Filename = tmpFilename; aiThumb.ContentType = "image/x-png"; aiThumb.FileSize = fileSize; if (ForumInfo.AttachStore == AttachStores.DATABASE) { aiThumb.FileData = imgStream.ToArray(); //File.Delete(fpath & "thumb_" & ai.Filename) } aiThumb.ParentAttachId = aid; int thumbId = ac.Attach_Save(aiThumb); attachIds += thumbId.ToString() + ";"; BindMyFiles(); if (Convert.ToBoolean(e.Parameters[4])) { string strHost = DotNetNuke.Common.Globals.AddHTTP(DotNetNuke.Common.Globals.GetDomainName(Request)) + "/"; string s = "<script type=\"text/javascript\">"; string sInsert = string.Empty; if (ForumInfo.AllowHTML && ForumInfo.EditorType != EditorTypes.TEXTBOX) { sInsert = "<a href=\"" + strHost + "DesktopModules/ActiveForums/viewer.aspx?portalid=" + PortalId + "&moduleid=" + ModuleId + "&attachid=" + aid + "\" target=\"_blank\"><img src=" + strHost + "DesktopModules/ActiveForums/viewer.aspx?portalid=" + PortalId + "&moduleid=" + ModuleId + "&attachid=" + thumbId + " border=0 /></a>"; } else { sInsert = "[THUMBNAIL:" + thumbId.ToString() + ":" + aid + "]"; } s += "amaf_insertHTML('" + sInsert + "');"; s += "</script>"; LiteralControl litScript = new LiteralControl(); litScript.Text = s; plhAttach.Controls.Add(litScript); } } } break; } case "inline": { if (SimulateIsNumeric.IsNumeric(e.Parameters[2])) { int aid = Convert.ToInt32(e.Parameters[2]); Data.AttachController ac = new Data.AttachController(); int uid = -1; if (SimulateIsNumeric.IsNumeric(e.Parameters[3])) { uid = Convert.ToInt32(e.Parameters[3]); } AttachInfo ai = ac.Attach_Get(aid, -1, uid, false); if (ai != null) { int opt = Convert.ToInt32(e.Parameters[4]); if (opt == 0) { ai.DisplayInline = true; ai.AllowDownload = false; } else { if (ai.AllowDownload) { ai.DisplayInline = true; ai.AllowDownload = false; } else { ai.DisplayInline = false; ai.AllowDownload = true; } } ac.Attach_Save(ai); } } break; } } BindAttach(attachIds); System.IO.StringWriter stringWriter = new System.IO.StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); plhAttach.RenderControl(htmlWriter); string html = stringWriter.GetStringBuilder().ToString(); html = Utilities.LocalizeControl(html); LiteralControl lit = new LiteralControl(); lit.Text = html; lit.RenderControl(e.Output); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); //Put user code to initialize the page here try { byte[] bindata = null; bool canView = false; string sContentType = string.Empty; if (!Page.IsPostBack) { int AttachId = 0; int intPortalID = 0; int intModuleID = 0; if (Request.Params["AttachID"] != null) { if (SimulateIsNumeric.IsNumeric(Request.Params["AttachID"])) { AttachId = Int32.Parse(Request.Params["AttachID"]); } else { AttachId = 0; } } else { AttachId = 0; } if (Request.Params["PortalID"] != null) { if (SimulateIsNumeric.IsNumeric(Request.Params["PortalID"])) { intPortalID = Int32.Parse(Request.Params["PortalID"]); } else { intPortalID = 0; } } else { intPortalID = 0; } if (Request.Params["ModuleID"] != null) { if (SimulateIsNumeric.IsNumeric(Request.Params["ModuleID"])) { intModuleID = Int32.Parse(Request.Params["ModuleID"]); } else { intModuleID = -1; } } else { intModuleID = -1; } IFileManager _fileManager = FileManager.Instance; IFileInfo _file = null; if (AttachId > 0) { DotNetNuke.Entities.Users.UserInfo ui = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo(); //DotNetNuke.Modules.ActiveForums.Settings.LoadUser(objUserInfo.UserID, intPortalID, intModuleID) UserController uc = new UserController(); User u = uc.GetUser(intPortalID, intModuleID); Data.AttachController ac = new Data.AttachController(); AttachInfo ai = null; try { if (Request.UrlReferrer.AbsolutePath.Contains("HtmlEditorProviders") | (Request.UrlReferrer.AbsolutePath.Contains("afv") & Request.UrlReferrer.AbsolutePath.Contains("post"))) { ai = ac.Attach_Get(AttachId, -1, ui.UserID, false); } else { ai = ac.Attach_Get(AttachId, -1, ui.UserID, true); } } catch (Exception ex) { ai = ac.Attach_Get(AttachId, -1, ui.UserID, true); } if (ai == null) { ai = new AttachInfo(); _file = _fileManager.GetFile(AttachId); ai.AttachID = _file.FileId; ai.AllowDownload = true; ai.Filename = _file.FileName; ai.FileUrl = _file.PhysicalPath; ai.CanRead = "0;1;-3;-1;|||"; ai.ContentType = _file.ContentType; } if (ai != null & u != null) { Response.ContentType = ai.ContentType.ToString(); if (ai.FileData != null) { if (Permissions.HasAccess(ai.CanRead, u.UserRoles)) { bindata = (byte[])ai.FileData; Response.BinaryWrite(bindata); Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.HtmlEncode(ai.Filename.ToString())); } } else { if (Permissions.HasAccess(ai.CanRead, u.UserRoles)) { string fpath = string.Empty; string fName = string.Empty; if (string.IsNullOrEmpty(ai.FileUrl)) { fpath = Server.MapPath(PortalSettings.HomeDirectory + "activeforums_Attach/"); fpath += ai.Filename; fName = System.IO.Path.GetFileName(fpath); } else { _file = _fileManager.GetFile(ai.AttachID); fpath = _file.PhysicalPath; fName = _file.FileName; } if (System.IO.File.Exists(fpath)) { //Dim vpath As String //vpath = PortalSettings.HomeDirectory & "activeforums_Attach/" & Server.HtmlEncode(ai.Filename) FileStream fs = new FileStream(fpath, FileMode.Open, FileAccess.Read); long contentLength = 0; if (fs != null) { bindata = GetStreamAsByteArray(fs); fs.Close(); } string sExt = System.IO.Path.GetExtension(fName); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.HtmlEncode(fName)); Response.AddHeader("Content-Length", bindata.LongLength.ToString()); sContentType = ai.ContentType; switch (sExt.ToLowerInvariant()) { case ".png": sContentType = "image/png"; break; case ".jpg": case ".jpeg": sContentType = "image/jpeg"; break; case ".gif": sContentType = "image/gif"; break; case ".bmp": sContentType = "image/bmp"; break; } Response.ContentType = sContentType; Response.OutputStream.Write(bindata, 0, bindata.Length); Response.End(); } else { fpath = Server.MapPath(PortalSettings.HomeDirectory + "NTForums_Attach/"); fpath += ai.Filename; if (System.IO.File.Exists(fpath)) { string vpath = null; vpath = PortalSettings.HomeDirectory + "activeforums_Attach/" + Server.HtmlEncode(ai.Filename); Response.Redirect(Page.ResolveUrl(vpath)); } } } } } } } } catch (Exception ex) { } }