public static void SendSubscriptions(int PortalId, int ModuleId, int TabId, int ForumId, int TopicId, int ReplyId, int AuthorId) { var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false); SendSubscriptions(PortalId, ModuleId, TabId, fi, TopicId, ReplyId, AuthorId); }
public HttpResponseMessage ApprovePost(ModerationDTO dto) { var notify = NotificationsController.Instance.GetNotification(dto.NotificationId); ParseNotificationContext(notify.Context); var fc = new ForumController(); var fi = fc.Forums_Get(_forumId, -1, false, true); if (fi == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Forum Not Found" }); if (!(IsMod(_forumId))) return Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "User is not a moderator for this forum"}); if (_replyId > 0) { var rc = new ReplyController(); var reply = rc.ApproveReply(PortalSettings.PortalId, _tabId, _moduleId, _forumId, _topicId, _replyId); if (reply == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Reply Not Found" }); } else { var tc = new TopicsController(); var topic = tc.ApproveTopic(PortalSettings.PortalId, _tabId, _moduleId, _forumId, _topicId); if (topic == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Topic Not Found" }); } NotificationsController.Instance.DeleteNotification(dto.NotificationId); return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }); }
public void Topics_Move(int PortalId, int ModuleId, int ForumId, int TopicId) { SettingsInfo settings = DataCache.MainSettings(ModuleId); if (settings.URLRewriteEnabled) { try { Data.ForumsDB db = new Data.ForumsDB(); int oldForumId = -1; oldForumId = db.Forum_GetByTopicId(TopicId); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(oldForumId, -1, false); if (!(string.IsNullOrEmpty(fi.PrefixURL))) { Data.Common dbC = new Data.Common(); string sURL = dbC.GetUrl(ModuleId, fi.ForumGroupId, oldForumId, TopicId, -1, -1); if (!(string.IsNullOrEmpty(sURL))) { dbC.ArchiveURL(PortalId, fi.ForumGroupId, ForumId, TopicId, sURL); } } } catch (Exception ex) { } } DataProvider.Instance().Topics_Move(PortalId, ModuleId, ForumId, TopicId); }
public HttpResponseMessage CreateSplit(CreateSplitDTO dto) { if (dto.NewTopicId == dto.OldTopicId) { return(Request.CreateResponse(HttpStatusCode.OK)); } var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID); var fc = new ForumController(); var forum_out = fc.Forums_Get(portalSettings.PortalId, ActiveModule.ModuleID, 0, forumUser.UserId, false, true, dto.OldTopicId); var forum_in = fc.GetForum(portalSettings.PortalId, ActiveModule.ModuleID, dto.NewForumId); if (forum_out != null && forum_in != null) { var perm = false; if (forum_out == forum_in) { perm = Permissions.HasPerm(forum_out.Security.View, forumUser.UserRoles); } else { perm = Permissions.HasPerm(forum_out.Security.View, forumUser.UserRoles) && Permissions.HasPerm(forum_in.Security.View, forumUser.UserRoles); } var modSplit = Permissions.HasPerm(forum_out.Security.ModSplit, forumUser.UserRoles); if (perm && modSplit) { var tc = new TopicsController(); int topicId; if (dto.NewTopicId < 1) { var subject = Utilities.CleanString(portalSettings.PortalId, dto.Subject, false, EditorTypes.TEXTBOX, false, false, ActiveModule.ModuleID, string.Empty, false); var replies = dto.Replies.Split('|'); var rc = new DotNetNuke.Modules.ActiveForums.DAL2.ReplyController(); var firstReply = rc.Get(Convert.ToInt32(replies[0])); var cc = new ContentController(); var firstContent = cc.Get(firstReply.ContentId); topicId = tc.Topic_QuickCreate(portalSettings.PortalId, ActiveModule.ModuleID, dto.NewForumId, subject, string.Empty, firstContent.AuthorId, firstContent.AuthorName, true, Request.GetIPAddress()); tc.Replies_Split(dto.OldTopicId, topicId, dto.Replies, true); } else { topicId = dto.NewTopicId; tc.Replies_Split(dto.OldTopicId, topicId, dto.Replies, false); } } } return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage CreateSplit(CreateSplitDTO dto) { if (dto.NewTopicId == dto.OldTopicId) return Request.CreateResponse(HttpStatusCode.OK); var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID); var fc = new ForumController(); var forum_out = fc.Forums_Get(portalSettings.PortalId, ActiveModule.ModuleID, 0, forumUser.UserId, false, true, dto.OldTopicId); var forum_in = fc.GetForum(portalSettings.PortalId, ActiveModule.ModuleID, dto.NewForumId); if (forum_out != null && forum_in != null) { var perm = false; if (forum_out == forum_in) { perm = Permissions.HasPerm(forum_out.Security.View, forumUser.UserRoles); } else { perm = Permissions.HasPerm(forum_out.Security.View, forumUser.UserRoles) && Permissions.HasPerm(forum_in.Security.View, forumUser.UserRoles); } var modSplit = Permissions.HasPerm(forum_out.Security.ModSplit, forumUser.UserRoles); if (perm && modSplit) { var tc = new TopicsController(); int topicId; if (dto.NewTopicId < 1) { var subject = Utilities.CleanString(portalSettings.PortalId, dto.Subject, false, EditorTypes.TEXTBOX, false, false, ActiveModule.ModuleID, string.Empty, false); var replies = dto.Replies.Split('|'); var rc = new DotNetNuke.Modules.ActiveForums.DAL2.ReplyController(); var firstReply = rc.Get(Convert.ToInt32(replies[0])); var cc = new ContentController(); var firstContent = cc.Get(firstReply.ContentId); topicId = tc.Topic_QuickCreate(portalSettings.PortalId, ActiveModule.ModuleID, dto.NewForumId, subject, string.Empty, firstContent.AuthorId, firstContent.AuthorName, true, Request.GetIPAddress()); tc.Replies_Split(dto.OldTopicId, topicId, dto.Replies, true); } else { topicId = dto.NewTopicId; tc.Replies_Split(dto.OldTopicId, topicId, dto.Replies, false); } } } return Request.CreateResponse(HttpStatusCode.OK); }
public ReplyInfo ApproveReply(int PortalId, int TabId, int ModuleId, int ForumId, int TopicId, int ReplyId) { SettingsInfo ms = DataCache.MainSettings(ModuleId); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); ReplyController rc = new ReplyController(); ReplyInfo reply = rc.Reply_Get(PortalId, ModuleId, TopicId, ReplyId); if (reply == null) { return(null); } reply.IsApproved = true; rc.Reply_Save(PortalId, reply); TopicsController tc = new TopicsController(); tc.Topics_SaveToForum(ForumId, TopicId, PortalId, ModuleId, ReplyId); TopicInfo topic = tc.Topics_Get(PortalId, ModuleId, TopicId, ForumId, -1, false); if (fi.ModApproveTemplateId > 0 & reply.Author.AuthorId > 0) { Email oEmail = new Email(); oEmail.SendEmail(fi.ModApproveTemplateId, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, reply.Author); } Subscriptions.SendSubscriptions(PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, reply.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string fullURL = ctlUtils.BuildUrl(TabId, ModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, ForumId, TopicId, topic.TopicUrl, -1, -1, string.Empty, 1, fi.SocialGroupId); if (fullURL.Contains("~/")) { fullURL = Utilities.NavigateUrl(TabId, "", new string[] { ParamKeys.TopicId + "=" + TopicId, ParamKeys.ContentJumpId + "=" + ReplyId }); } if (fullURL.EndsWith("/")) { fullURL += "?" + ParamKeys.ContentJumpId + "=" + ReplyId; } Social amas = new Social(); amas.AddReplyToJournal(PortalId, ModuleId, ForumId, TopicId, ReplyId, reply.Author.AuthorId, fullURL, reply.Content.Subject, string.Empty, reply.Content.Body, fi.ActiveSocialSecurityOption, fi.Security.Read, fi.SocialGroupId); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return(reply); }
public void SendEmail(int TemplateId, int PortalId, int ModuleId, int TabId, int ForumId, int TopicId, int ReplyId, string Comments, Author author) { var _portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); SettingsInfo MainSettings = DataCache.MainSettings(ModuleId); string Subject; string BodyText; string BodyHTML; string sTemplate = string.Empty; var tc = new TemplateController(); TemplateInfo ti = tc.Template_Get(TemplateId, PortalId, ModuleId); Subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, author.AuthorId, _portalSettings.TimeZoneOffset); BodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, author.AuthorId, _portalSettings.TimeZoneOffset); BodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, author.AuthorId, _portalSettings.TimeZoneOffset); BodyText = BodyText.Replace("[REASON]", Comments); BodyHTML = BodyHTML.Replace("[REASON]", Comments); string sFrom; var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : _portalSettings.Email; //Send now var oEmail = new Email(); var subs = new List <SubscriptionInfo>(); var si = new SubscriptionInfo { DisplayName = author.DisplayName, Email = author.Email, FirstName = author.FirstName, LastName = author.LastName, UserId = author.AuthorId, Username = author.Username }; subs.Add(si); oEmail.UseQueue = MainSettings.MailQueue; oEmail.Recipients = subs; oEmail.Subject = Subject; oEmail.From = sFrom; oEmail.BodyText = BodyText; oEmail.BodyHTML = BodyHTML; oEmail.SmtpServer = Host.SMTPServer; // Convert.ToString(_portalSettings.HostSettings["SMTPServer"]); oEmail.SmtpUserName = Host.SMTPUsername; // Convert.ToString(_portalSettings.HostSettings["SMTPUsername"]); oEmail.SmtpPassword = Host.SMTPPassword; // Convert.ToString(_portalSettings.HostSettings["SMTPPassword"]); oEmail.SmtpAuthentication = Host.SMTPAuthentication; // Convert.ToString(_portalSettings.HostSettings["SMTPAuthentication"]); var objThread = new System.Threading.Thread(oEmail.Send); objThread.Start(); }
public ReplyInfo ApproveReply(int PortalId, int TabId, int ModuleId, int ForumId, int TopicId, int ReplyId) { SettingsInfo ms = DataCache.MainSettings(ModuleId); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); ReplyController rc = new ReplyController(); ReplyInfo reply = rc.Reply_Get(PortalId, ModuleId, TopicId, ReplyId); if (reply == null) { return null; } reply.IsApproved = true; rc.Reply_Save(PortalId, reply); TopicsController tc = new TopicsController(); tc.Topics_SaveToForum(ForumId, TopicId, PortalId, ModuleId, ReplyId); TopicInfo topic = tc.Topics_Get(PortalId, ModuleId, TopicId, ForumId, -1, false); if (fi.ModApproveTemplateId > 0 & reply.Author.AuthorId > 0) { Email oEmail = new Email(); oEmail.SendEmail(fi.ModApproveTemplateId, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, reply.Author); } Subscriptions.SendSubscriptions(PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, reply.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string fullURL = ctlUtils.BuildUrl(TabId, ModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, ForumId, TopicId, topic.TopicUrl, -1, -1, string.Empty, 1, fi.SocialGroupId); if (fullURL.Contains("~/")) { fullURL = Utilities.NavigateUrl(TabId, "", new string[] {ParamKeys.TopicId + "=" + TopicId, ParamKeys.ContentJumpId + "=" + ReplyId}); } if (fullURL.EndsWith("/")) { fullURL += "?" + ParamKeys.ContentJumpId + "=" + ReplyId; } Social amas = new Social(); amas.AddReplyToJournal(PortalId, ModuleId, ForumId, TopicId, ReplyId, reply.Author.AuthorId, fullURL, reply.Content.Subject, string.Empty, reply.Content.Body, fi.ActiveSocialSecurityOption, fi.Security.Read, fi.SocialGroupId); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return reply; }
public HttpResponseMessage ApprovePost(ModerationDTO dto) { var notify = NotificationsController.Instance.GetNotification(dto.NotificationId); ParseNotificationContext(notify.Context); var fc = new ForumController(); var fi = fc.Forums_Get(_forumId, -1, false, true); if (fi == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Forum Not Found" })); } if (!(IsMod(_forumId))) { return(Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "User is not a moderator for this forum" })); } if (_replyId > 0) { var rc = new ReplyController(); var reply = rc.ApproveReply(PortalSettings.PortalId, _tabId, _moduleId, _forumId, _topicId, _replyId); if (reply == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Reply Not Found" })); } } else { var tc = new TopicsController(); var topic = tc.ApproveTopic(PortalSettings.PortalId, _tabId, _moduleId, _forumId, _topicId); if (topic == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Topic Not Found" })); } } NotificationsController.Instance.DeleteNotification(dto.NotificationId); return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" })); }
public static void SendEmail(int templateId, int portalId, int moduleId, int tabId, int forumId, int topicId, int replyId, string comments, Author author) { var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); var mainSettings = DataCache.MainSettings(moduleId); var sTemplate = string.Empty; var tc = new TemplateController(); var ti = tc.Template_Get(templateId, portalId, moduleId); var subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, portalId, moduleId, tabId, forumId, topicId, replyId, string.Empty, author.AuthorId, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes)); var bodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, portalId, moduleId, tabId, forumId, topicId, replyId, string.Empty, author.AuthorId, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes)); var bodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, portalId, moduleId, tabId, forumId, topicId, replyId, string.Empty, author.AuthorId, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes)); bodyText = bodyText.Replace("[REASON]", comments); bodyHTML = bodyHTML.Replace("[REASON]", comments); var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, true); var sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : portalSettings.Email; //Send now var oEmail = new Email(); var subs = new List <SubscriptionInfo>(); var si = new SubscriptionInfo { DisplayName = author.DisplayName, Email = author.Email, FirstName = author.FirstName, LastName = author.LastName, UserId = author.AuthorId, Username = author.Username }; subs.Add(si); oEmail.UseQueue = mainSettings.MailQueue; oEmail.Recipients = subs; oEmail.Subject = subject; oEmail.From = sFrom; oEmail.BodyText = bodyText; oEmail.BodyHTML = bodyHTML; new Thread(oEmail.Send).Start(); }
public static void SendEmail(int templateId, int portalId, int moduleId, int tabId, int forumId, int topicId, int replyId, string comments, Author author) { var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); var mainSettings = DataCache.MainSettings(moduleId); var sTemplate = string.Empty; var tc = new TemplateController(); var ti = tc.Template_Get(templateId, portalId, moduleId); var subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, portalId, moduleId, tabId, forumId, topicId, replyId, string.Empty, author.AuthorId, portalSettings.TimeZoneOffset); var bodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, portalId, moduleId, tabId, forumId, topicId, replyId, string.Empty, author.AuthorId, portalSettings.TimeZoneOffset); var bodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, portalId, moduleId, tabId, forumId, topicId, replyId, string.Empty, author.AuthorId, portalSettings.TimeZoneOffset); bodyText = bodyText.Replace("[REASON]", comments); bodyHTML = bodyHTML.Replace("[REASON]", comments); var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, true); var sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : portalSettings.Email; //Send now var oEmail = new Email(); var subs = new List<SubscriptionInfo>(); var si = new SubscriptionInfo { DisplayName = author.DisplayName, Email = author.Email, FirstName = author.FirstName, LastName = author.LastName, UserId = author.AuthorId, Username = author.Username }; subs.Add(si); oEmail.UseQueue = mainSettings.MailQueue; oEmail.Recipients = subs; oEmail.Subject = subject; oEmail.From = sFrom; oEmail.BodyText = bodyText; oEmail.BodyHTML = bodyHTML; new Thread(oEmail.Send).Start(); }
public int Subscription_Update(int PortalId, int ModuleId, int ForumId, int TopicId, int Mode, int UserId, string UserRoles = "") { if (UserId == -1) { return -1; } if (string.IsNullOrEmpty(UserRoles)) { UserController uc = new UserController(); User uu = uc.GetUser(PortalId, ModuleId, UserId); UserRoles = uu.UserRoles; } var fc = new ForumController(); Forum fi = fc.Forums_Get(PortalId, ModuleId, ForumId, UserId, true, false, -1); if (Permissions.HasPerm(fi.Security.Subscribe, UserRoles)) { return Convert.ToInt32(DataProvider.Instance().Subscription_Update(PortalId, ModuleId, ForumId, TopicId, Mode, UserId)); } return -1; }
public HttpResponseMessage IgnorePost(ModerationDTO dto) { var notify = NotificationsController.Instance.GetNotification(dto.NotificationId); ParseNotificationContext(notify.Context); var fc = new ForumController(); var fi = fc.Forums_Get(_forumId, -1, false, true); if (fi == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Forum Not Found" })); } if (!(IsMod(_forumId))) { return(Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "User is not a moderator for this forum" })); } NotificationsController.Instance.DeleteNotification(dto.NotificationId); return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" })); }
public TopicInfo ApproveTopic(int PortalId, int TabId, int ModuleId, int ForumId, int TopicId) { SettingsInfo ms = DataCache.MainSettings(ModuleId); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); TopicsController tc = new TopicsController(); TopicInfo topic = tc.Topics_Get(PortalId, ModuleId, TopicId, ForumId, -1, false); if (topic == null) { return(null); } topic.IsApproved = true; tc.TopicSave(PortalId, topic); tc.Topics_SaveToForum(ForumId, TopicId, PortalId, ModuleId); if (fi.ModApproveTemplateId > 0 & topic.Author.AuthorId > 0) { Email oEmail = new Email(); oEmail.SendEmail(fi.ModApproveTemplateId, PortalId, ModuleId, TabId, ForumId, TopicId, 0, string.Empty, topic.Author); } Subscriptions.SendSubscriptions(PortalId, ModuleId, TabId, ForumId, TopicId, 0, topic.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string sUrl = ctlUtils.BuildUrl(TabId, ModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, TopicId, topic.TopicUrl, -1, -1, string.Empty, 1, fi.SocialGroupId); Social amas = new Social(); amas.AddTopicToJournal(PortalId, ModuleId, ForumId, TopicId, topic.Author.AuthorId, sUrl, topic.Content.Subject, string.Empty, topic.Content.Body, fi.ActiveSocialSecurityOption, fi.Security.Read, fi.SocialGroupId); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return(topic); }
public int Subscription_Update(int PortalId, int ModuleId, int ForumId, int TopicId, int Mode, int UserId, string UserRoles = "") { if (UserId == -1) { return(-1); } if (string.IsNullOrEmpty(UserRoles)) { UserController uc = new UserController(); User uu = uc.GetUser(PortalId, ModuleId, UserId); UserRoles = uu.UserRoles; } var fc = new ForumController(); Forum fi = fc.Forums_Get(PortalId, ModuleId, ForumId, UserId, true, false, -1); if (Permissions.HasPerm(fi.Security.Subscribe, UserRoles)) { return(Convert.ToInt32(DataProvider.Instance().Subscription_Update(PortalId, ModuleId, ForumId, TopicId, Mode, UserId))); } return(-1); }
public Task<HttpResponseMessage> UploadFile() { // This method uploads an attachment to a temporary directory and returns a JSON object containing information about the original file // including the temporary file name. When the post is saved/updated, the temporary file is moved to the appropriate attachment directory // Have to a reference to these variables as the internal reference isn't available. // in the async result. var request = Request; var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(ActiveModule.PortalID, ActiveModule.ModuleID, userInfo.UserID); if (!request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)); } const string uploadPath = "activeforums_Upload"; var folderManager = FolderManager.Instance; if(!folderManager.FolderExists(ActiveModule.PortalID, uploadPath)) { folderManager.AddFolder(ActiveModule.PortalID, uploadPath); } var folder = folderManager.GetFolder(ActiveModule.PortalID, uploadPath); var provider = new MultipartFormDataStreamProvider(folder.PhysicalPath); var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) throw new HttpResponseException(HttpStatusCode.InternalServerError); // Make sure a temp file was uploaded and that it exists var file = provider.FileData.FirstOrDefault(); if (file == null || string.IsNullOrWhiteSpace(file.LocalFileName) || !File.Exists(file.LocalFileName)) { return request.CreateErrorResponse(HttpStatusCode.NoContent, "No File Found"); } // Get the file name without the full path var localFileName = Path.GetFileName(file.LocalFileName).TextOrEmpty(); // Check to make sure that a forum was specified and that the the user has upload permissions // This is only an initial check, it will be done again when the file is saved to a post. int forumId; if (!int.TryParse(provider.FormData["forumId"], out forumId)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Specified"); } // Make sure that we can find the forum and that attachments are allowed var fc = new ForumController(); var forum = fc.Forums_Get(ActiveModule.PortalID, ActiveModule.ModuleID, forumId, userInfo.UserID, true, true, -1); if (forum == null || !forum.AllowAttach) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Found"); } // Make sure the user has permissions to attach files if(forumUser == null || !Permissions.HasPerm(forum.Security.Attach, forumUser.UserRoles)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not Authorized"); } // Make sure that the file size does not exceed the limit (in KB) for the forum // Have to do this since content length is not available when using MultipartFormDataStreamProvider var di = new DirectoryInfo(folder.PhysicalPath); var fileSize = di.GetFiles(localFileName)[0].Length; var maxAllowedFileSize = (long)forum.AttachMaxSize*1024; if((forum.AttachMaxSize > 0) && (fileSize > maxAllowedFileSize)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Exceeds Max File Size"); } // Get the original file name from the content disposition header var fileName = file.Headers.ContentDisposition.FileName.Replace("\"", ""); if(string.IsNullOrWhiteSpace(fileName)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Invalid File"); } // Make sure we have an acceptable extension type. // Check against both the forum configuration and the host configuration var extension = Path.GetExtension(fileName).TextOrEmpty().Replace(".", string.Empty).ToLower(); var isForumAllowedExtension = string.IsNullOrWhiteSpace(forum.AttachTypeAllowed) || forum.AttachTypeAllowed.Replace(".", "").Split(',').Any(val => val == extension); if(string.IsNullOrEmpty(extension) || !isForumAllowedExtension || !Host.AllowedExtensionWhitelist.IsAllowedExtension(extension)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "File Type Not Allowed"); } // IE<=9 Hack - can't return application/json var mediaType = "application/json"; if (!request.Headers.Accept .Any(h => h.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase))) mediaType = "text/html"; var result = new ClientAttachment() { ContentType = file.Headers.ContentType.MediaType, FileName = fileName, FileSize = fileSize, UploadId = localFileName }; return Request.CreateResponse(HttpStatusCode.Accepted, result, mediaType); }); return task; }
public static List<Entities.Users.UserInfo> GetListOfModerators(int portalId, int forumId) { var rc = new Security.Roles.RoleController(); var uc = new Entities.Users.UserController(); var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, true); if (fi == null) return null; var mods = new List<Entities.Users.UserInfo>(); SubscriptionInfo si = null; var modApprove = fi.Security.ModApprove; var modRoles = modApprove.Split('|')[0].Split(';'); foreach (var r in modRoles) { if (string.IsNullOrEmpty(r)) continue; var rid = Convert.ToInt32(r); var rName = rc.GetRole(rid, portalId).RoleName; foreach (Entities.Users.UserRoleInfo usr in rc.GetUserRolesByRoleName(portalId, rName)) { var ui = uc.GetUser(portalId, usr.UserID); if (!(mods.Contains(ui))) { mods.Add(ui); } } } return mods; }
public static void SendEmailToModerators(int templateId, int portalId, int forumId, int topicId, int replyId, int moduleID, int tabID, string comments, UserInfo user) { var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); var mainSettings = DataCache.MainSettings(moduleID); var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, true); if (fi == null) return; var subs = new List<SubscriptionInfo>(); var rc = new Security.Roles.RoleController(); var uc = new Entities.Users.UserController(); var modApprove = fi.Security.ModApprove; var modRoles = modApprove.Split('|')[0].Split(';'); foreach (var r in modRoles) { if (string.IsNullOrEmpty(r)) continue; var rid = Convert.ToInt32(r); var rName = rc.GetRole(rid, portalId).RoleName; foreach (UserRoleInfo usr in rc.GetUserRolesByRoleName(portalId, rName)) { var ui = uc.GetUser(portalId, usr.UserID); var si = new SubscriptionInfo { UserId = ui.UserID, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName }; if (! (subs.Contains(si))) { subs.Add(si); } } } if (subs.Count <= 0) return; var sTemplate = string.Empty; var tc = new TemplateController(); var ti = tc.Template_Get(templateId, portalId, moduleID); var subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, portalSettings.TimeZoneOffset); var bodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, comments, user, -1, portalSettings.TimeZoneOffset); var bodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, comments, user, -1, portalSettings.TimeZoneOffset); var sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : portalSettings.Email; var oEmail = new Email { Recipients = subs, Subject = subject, From = sFrom, BodyText = bodyText, BodyHTML = bodyHTML, UseQueue = mainSettings.MailQueue }; new Thread(oEmail.Send).Start(); }
private void cbMod_Callback(object sender, Modules.ActiveForums.Controls.CallBackEventArgs e) { SettingsInfo ms = DataCache.MainSettings(ForumModuleId); Forum fi = null; if (e.Parameters.Length > 0) { if (ForumId < 1) { SetPermissions(Convert.ToInt32(e.Parameters[1])); ForumController fc = new ForumController(); fi = fc.Forums_Get(Convert.ToInt32(e.Parameters[1]), -1, false, true); } else { fi = ForumInfo; } switch (e.Parameters[0].ToLowerInvariant()) { case "moddel": { if (bModDelete) { int delAction = ms.DeleteBehavior; int tmpForumId = -1; int tmpTopicId = -1; int tmpReplyId = -1; tmpForumId = Convert.ToInt32(e.Parameters[1]); tmpTopicId = Convert.ToInt32(e.Parameters[2]); tmpReplyId = Convert.ToInt32(e.Parameters[3]); Author auth = null; if (fi.ModDeleteTemplateId > 0) { try { //Email.SendEmail(fi.ModDeleteTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, auth); Email.SendEmailToModerators(fi.ModDeleteTemplateId, PortalId, tmpForumId, tmpTopicId, tmpReplyId, ForumModuleId, ForumTabId, string.Empty); } catch (Exception ex) { } } if (tmpForumId > 0 & tmpTopicId > 0 && tmpReplyId == 0) { TopicsController tc = new TopicsController(); TopicInfo ti = tc.Topics_Get(PortalId, ForumModuleId, tmpTopicId); if (ti != null) { auth = ti.Author; } tc.Topics_Delete(PortalId, ModuleId, tmpForumId, tmpTopicId, delAction); } else if (tmpForumId > 0 & tmpTopicId > 0 & tmpReplyId > 0) { ReplyController rc = new ReplyController(); ReplyInfo ri = rc.Reply_Get(PortalId, ForumModuleId, tmpTopicId, tmpReplyId); if (ri != null) { auth = ri.Author; } rc.Reply_Delete(PortalId, tmpForumId, tmpTopicId, tmpReplyId, delAction); } } break; } case "modreject": { int tmpForumId = 0; int tmpTopicId = 0; int tmpReplyId = 0; int tmpAuthorId = 0; tmpForumId = Convert.ToInt32(e.Parameters[1]); tmpTopicId = Convert.ToInt32(e.Parameters[2]); tmpReplyId = Convert.ToInt32(e.Parameters[3]); tmpAuthorId = Convert.ToInt32(e.Parameters[4]); ModController mc = new ModController(); mc.Mod_Reject(PortalId, ForumModuleId, UserId, tmpForumId, tmpTopicId, tmpReplyId); if (fi.ModRejectTemplateId > 0 & tmpAuthorId > 0) { DotNetNuke.Entities.Users.UserController uc = new DotNetNuke.Entities.Users.UserController(); DotNetNuke.Entities.Users.UserInfo ui = uc.GetUser(PortalId, tmpAuthorId); if (ui != null) { Author au = new Author(); au.AuthorId = tmpAuthorId; au.DisplayName = ui.DisplayName; au.Email = ui.Email; au.FirstName = ui.FirstName; au.LastName = ui.LastName; au.Username = ui.Username; Email.SendEmail(fi.ModRejectTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, au); } } break; } case "modappr": { int tmpForumId = -1; int tmpTopicId = -1; int tmpReplyId = -1; tmpForumId = Convert.ToInt32(e.Parameters[1]); tmpTopicId = Convert.ToInt32(e.Parameters[2]); tmpReplyId = Convert.ToInt32(e.Parameters[3]); string sSubject = string.Empty; string sBody = string.Empty; if (tmpForumId > 0 & tmpTopicId > 0 && tmpReplyId == 0) { TopicsController tc = new TopicsController(); TopicInfo ti = tc.Topics_Get(PortalId, ForumModuleId, tmpTopicId, tmpForumId, -1, false); if (ti != null) { sSubject = ti.Content.Subject; sBody = ti.Content.Body; ti.IsApproved = true; tc.TopicSave(PortalId, ti); tc.Topics_SaveToForum(tmpForumId, tmpTopicId, PortalId, ModuleId); //TODO: Add Audit log for who approved topic if (fi.ModApproveTemplateId > 0 & ti.Author.AuthorId > 0) { Email.SendEmail(fi.ModApproveTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, ti.Author); } Subscriptions.SendSubscriptions(PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, 0, ti.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string sUrl = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, TopicId, ti.TopicUrl, -1, -1, string.Empty, 1, -1, fi.SocialGroupId); // Utilities.NavigateUrl(ForumTabId, "", ParamKeys.ViewType & "=" & Views.Topic & "&" & ParamKeys.ForumId & "=" & ForumId, ParamKeys.TopicId & "=" & TopicId) if (sUrl.Contains("~/") || Request.QueryString["asg"] != null) { sUrl = Utilities.NavigateUrl(ForumTabId, "", ParamKeys.TopicId + "=" + TopicId); } Social amas = new Social(); if (Request.QueryString["asg"] == null & !(string.IsNullOrEmpty(MainSettings.ActiveSocialTopicsKey)) && fi.ActiveSocialEnabled) { amas.AddTopicToJournal(PortalId, ForumModuleId, ForumId, ti.TopicId, ti.Author.AuthorId, sUrl, sSubject, ti.Content.Summary, sBody, fi.ActiveSocialSecurityOption, fi.Security.Read, SocialGroupId); } else { amas.AddForumItemToJournal(PortalId, ForumModuleId, ti.Author.AuthorId, "forumtopic", sUrl, sSubject, sBody); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } } } else if (tmpForumId > 0 & tmpTopicId > 0 & tmpReplyId > 0) { ReplyController rc = new ReplyController(); ReplyInfo ri = rc.Reply_Get(PortalId, ForumModuleId, tmpTopicId, tmpReplyId); if (ri != null) { ri.IsApproved = true; sSubject = ri.Content.Subject; sBody = ri.Content.Body; rc.Reply_Save(PortalId, ri); TopicsController tc = new TopicsController(); tc.Topics_SaveToForum(tmpForumId, tmpTopicId, PortalId, ModuleId, tmpReplyId); TopicInfo ti = tc.Topics_Get(PortalId, ForumModuleId, tmpTopicId, tmpForumId, -1, false); //TODO: Add Audit log for who approved topic if (fi.ModApproveTemplateId > 0 & ri.Author.AuthorId > 0) { Email.SendEmail(fi.ModApproveTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, ri.Author); } Subscriptions.SendSubscriptions(PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, ri.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string fullURL = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, TopicId, ti.TopicUrl, -1, -1, string.Empty, 1, -1, fi.SocialGroupId); if (fullURL.Contains("~/") || Request.QueryString["asg"] != null) { fullURL = Utilities.NavigateUrl(ForumTabId, "", new string[] { ParamKeys.TopicId + "=" + TopicId, ParamKeys.ContentJumpId + "=" + tmpReplyId }); } Social amas = new Social(); if (Request.QueryString["asg"] == null & !(string.IsNullOrEmpty(MainSettings.ActiveSocialTopicsKey)) && fi.ActiveSocialEnabled && !fi.ActiveSocialTopicsOnly) { amas.AddReplyToJournal(PortalId, ForumModuleId, ForumId, ri.TopicId, ri.ReplyId, ri.Author.AuthorId, fullURL, ri.Content.Subject, string.Empty, sBody, fi.ActiveSocialSecurityOption, fi.Security.Read, fi.SocialGroupId); } else { amas.AddForumItemToJournal(PortalId, ForumModuleId, ri.Author.AuthorId, "forumreply", fullURL, sSubject, sBody); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } } } break; } } string cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); } BuildModList(); litTopics.RenderControl(e.Output); }
private void LoadForum(int forumId) { var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, false); if (fi == null) { return; } var newForum = fc.GetForum(PortalId, ModuleId, forumId, true); ctlSecurityGrid = LoadControl("~/DesktopModules/activeforums/controls/admin_securitygrid.ascx") as Controls.admin_securitygrid; if (ctlSecurityGrid != null) { ctlSecurityGrid.Perms = newForum.Security; ctlSecurityGrid.PermissionsId = newForum.PermissionsId; ctlSecurityGrid.ModuleConfiguration = ModuleConfiguration; ctlSecurityGrid.ReadOnly = newForum.InheritSecurity; plhGrid.Controls.Clear(); plhGrid.Controls.Add(ctlSecurityGrid); } txtForumName.Text = fi.ForumName; txtForumDesc.Text = fi.ForumDesc; chkActive.Checked = fi.Active; chkHidden.Checked = fi.Hidden; hidForumId.Value = fi.ForumID.ToString(); txtPrefixURL.Text = fi.PrefixURL; var groupValue = (fi.ParentForumId > 0) ? "FORUM" + fi.ParentForumId : "GROUP" + fi.ForumGroupId; Utilities.SelectListItemByValue(drpGroups, groupValue); if (fi.ForumSettingsKey == "G:" + fi.ForumGroupId) { chkInheritGroup.Checked = true; trTemplates.Attributes.Add("style", "display:none;"); } Utilities.SelectListItemByValue(drpTopicsTemplate, fi.TopicsTemplateId); Utilities.SelectListItemByValue(drpTopicTemplate, fi.TopicTemplateId); Utilities.SelectListItemByValue(drpTopicForm, fi.TopicFormId); Utilities.SelectListItemByValue(drpReplyForm, fi.ReplyFormId); //Utilities.SelectListItemByValue(drpQuickReplyForm, fi.QuickReplyFormId); Utilities.SelectListItemByValue(drpProfileDisplay, fi.ProfileTemplateId); Utilities.SelectListItemByValue(drpModApprovedTemplateId, fi.ModApproveTemplateId); Utilities.SelectListItemByValue(drpModRejectTemplateId, fi.ModRejectTemplateId); Utilities.SelectListItemByValue(drpModDeleteTemplateId, fi.ModDeleteTemplateId); Utilities.SelectListItemByValue(drpModMoveTemplateId, fi.ModMoveTemplateId); Utilities.SelectListItemByValue(drpModNotifyTemplateId, fi.ModNotifyTemplateId); Utilities.SelectListItemByValue(drpDefaultTrust, fi.DefaultTrustValue); Utilities.SelectListItemByValue(drpEditorTypes, fi.EditorType); Utilities.SelectListItemByValue(drpEditorMobile, fi.EditorMobile); Utilities.SelectListItemByValue(drpPermittedRoles, (int)fi.EditorPermittedUsers); txtAutoTrustLevel.Text = fi.AutoTrustLevel.ToString(); txtEmailAddress.Text = fi.EmailAddress; txtCreatePostCount.Text = fi.CreatePostCount.ToString(); txtReplyPostCount.Text = fi.ReplyPostCount.ToString(); rdFilterOn.Checked = fi.UseFilter; rdFilterOff.Checked = !fi.UseFilter; rdPostIconOn.Checked = fi.AllowPostIcon; rdPostIconOff.Checked = !fi.AllowPostIcon; rdEmotOn.Checked = fi.AllowEmoticons; rdEmotOff.Checked = !fi.AllowEmoticons; rdScriptsOn.Checked = fi.AllowScript; rdScriptsOff.Checked = !fi.AllowScript; rdIndexOn.Checked = fi.IndexContent; rdIndexOff.Checked = !fi.IndexContent; rdRSSOn.Checked = fi.AllowRSS; rdRSSOff.Checked = !fi.AllowRSS; rdAttachOn.Checked = fi.AllowAttach; rdAttachOff.Checked = !fi.AllowAttach; if (fi.AllowAttach) { cfgAttach.Attributes.Remove("style"); } else { cfgAttach.Attributes.Add("style", "display:none;"); } txtMaxAttach.Text = fi.AttachCount.ToString(); txtMaxAttachSize.Text = fi.AttachMaxSize.ToString(); txtAllowedTypes.Text = fi.AttachTypeAllowed; ckAllowBrowseSite.Checked = fi.AttachAllowBrowseSite; txtMaxAttachWidth.Text = fi.MaxAttachWidth.ToString(); txtMaxAttachHeight.Text = fi.MaxAttachHeight.ToString(); ckAttachInsertAllowed.Checked = fi.AttachInsertAllowed; ckConvertingToJpegAllowed.Checked = fi.ConvertingToJpegAllowed; rdHTMLOn.Checked = fi.AllowHTML; rdHTMLOff.Checked = !fi.AllowHTML; if (fi.AllowHTML) { cfgHTML.Attributes.Remove("style"); } else { cfgHTML.Attributes.Add("style", "display:none;"); } rdModOn.Checked = fi.IsModerated; rdModOff.Checked = !fi.IsModerated; if (fi.IsModerated) { cfgMod.Attributes.Remove("style"); } else { cfgMod.Attributes.Add("style", "display:none;"); } rdAutoSubOn.Checked = fi.AutoSubscribeEnabled; rdAutoSubOff.Checked = !fi.AutoSubscribeEnabled; if (fi.AutoSubscribeEnabled) { cfgAutoSub.Attributes.Remove("style"); } else { cfgAutoSub.Attributes.Add("style", "display:none;"); } rdLikesOn.Checked = fi.AllowLikes; rdLikesOff.Checked = !fi.AllowLikes; chkTopicsOnly.Checked = fi.AutoSubscribeNewTopicsOnly; txtEditorHeight.Text = (fi.EditorHeight == string.Empty) ? "400" : fi.EditorHeight; txtEditorWidth.Text = (fi.EditorWidth == string.Empty) ? "99%" : fi.EditorWidth; hidRoles.Value = fi.AutoSubscribeRoles; BindAutoSubRoles(fi.AutoSubscribeRoles); }
public Task <HttpResponseMessage> UploadFile() { // This method uploads an attachment to a temporary directory and returns a JSON object containing information about the original file // including the temporary file name. When the post is saved/updated, the temporary file is moved to the appropriate attachment directory // Have to a reference to these variables as the internal reference isn't available. // in the async result. var request = Request; var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(ActiveModule.PortalID, ActiveModule.ModuleID, userInfo.UserID); if (!request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)); } const string uploadPath = "activeforums_Upload"; var folderManager = FolderManager.Instance; if (!folderManager.FolderExists(ActiveModule.PortalID, uploadPath)) { folderManager.AddFolder(ActiveModule.PortalID, uploadPath); } var folder = folderManager.GetFolder(ActiveModule.PortalID, uploadPath); var provider = new MultipartFormDataStreamProvider(folder.PhysicalPath); var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } // Make sure a temp file was uploaded and that it exists var file = provider.FileData.FirstOrDefault(); if (file == null || string.IsNullOrWhiteSpace(file.LocalFileName) || !File.Exists(file.LocalFileName)) { return(request.CreateErrorResponse(HttpStatusCode.NoContent, "No File Found")); } // Get the file name without the full path var localFileName = Path.GetFileName(file.LocalFileName).TextOrEmpty(); // Check to make sure that a forum was specified and that the the user has upload permissions // This is only an initial check, it will be done again when the file is saved to a post. int forumId; if (!int.TryParse(provider.FormData["forumId"], out forumId)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Specified")); } // Make sure that we can find the forum and that attachments are allowed var fc = new ForumController(); var forum = fc.Forums_Get(ActiveModule.PortalID, ActiveModule.ModuleID, forumId, userInfo.UserID, true, true, -1); if (forum == null || !forum.AllowAttach) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Found")); } // Make sure the user has permissions to attach files if (forumUser == null || !Permissions.HasPerm(forum.Security.Attach, forumUser.UserRoles)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not Authorized")); } // Make sure that the file size does not exceed the limit (in KB) for the forum // Have to do this since content length is not available when using MultipartFormDataStreamProvider var di = new DirectoryInfo(folder.PhysicalPath); var fileSize = di.GetFiles(localFileName)[0].Length; var maxAllowedFileSize = (long)forum.AttachMaxSize * 1024; if ((forum.AttachMaxSize > 0) && (fileSize > maxAllowedFileSize)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Exceeds Max File Size")); } // Get the original file name from the content disposition header var fileName = file.Headers.ContentDisposition.FileName.Replace("\"", ""); if (string.IsNullOrWhiteSpace(fileName)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Invalid File")); } // Make sure we have an acceptable extension type. // Check against both the forum configuration and the host configuration var extension = Path.GetExtension(fileName).TextOrEmpty().Replace(".", string.Empty).ToLower(); var isForumAllowedExtension = string.IsNullOrWhiteSpace(forum.AttachTypeAllowed) || forum.AttachTypeAllowed.Replace(".", "").Split(',').Any(val => val == extension); if (string.IsNullOrEmpty(extension) || !isForumAllowedExtension || !Host.AllowedExtensionWhitelist.IsAllowedExtension(extension)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "File Type Not Allowed")); } const string newFileName = "{0}_{1}{2}"; var fileNameOnly = Path.GetFileNameWithoutExtension(fileName); var userFolder = folderManager.GetUserFolder(userInfo); var attachmentFolder = folderManager.GetFolder(userFolder.FolderID); var fileManager = FileManager.Instance; IFileInfo ufile = null; string sExt = Path.GetExtension(fileName); if (sExt.ToLower() == ".jpg" || sExt.ToLower() == ".bmp" || sExt.ToLower() == ".png" || sExt.ToLower() == ".jpeg") { var sExtOut = ".jpg"; ImageFormat imf, imfout = ImageFormat.Jpeg; Image img = Image.FromFile(file.LocalFileName); Image nimg; var maxWidth = forum.MaxAttachWidth; var maxHeight = forum.MaxAttachHeight; int imgWidth = img.Width; int imgHeight = img.Height; var ratioWidth = (double)imgWidth / maxWidth; var ratioHeight = (double)imgHeight / maxHeight; switch (sExt.ToLower()) { case ".png": { imf = ImageFormat.Png; if (!forum.ConvertingToJpegAllowed) { sExtOut = ".png"; imfout = ImageFormat.Png; } break; } case ".bmp": imf = ImageFormat.Bmp; break; default: imf = ImageFormat.Jpeg; break; } MemoryStream mst = new MemoryStream(); if (ratioWidth > 1 || ratioHeight > 1) { if (ratioWidth > ratioHeight) { imgWidth = maxWidth; imgHeight = (int)Math.Round(imgHeight / ratioWidth); } else if (ratioWidth < ratioHeight) { imgHeight = maxHeight; imgWidth = (int)Math.Round(imgWidth / ratioHeight); } else { imgWidth = maxWidth; imgHeight = maxHeight; } } Bitmap res = new Bitmap(imgWidth, imgHeight); using (Graphics gr = Graphics.FromImage(res)) { gr.Clear(Color.Transparent); gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.DrawImage(img, new Rectangle(0, 0, imgWidth, imgHeight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); gr.Dispose(); } img.Dispose(); res.Save(mst, imfout); res.Dispose(); var index = 0; fileName = fileNameOnly + sExtOut; while (fileManager.FileExists(attachmentFolder, fileName)) { index++; fileName = string.Format(newFileName, fileNameOnly, index, sExtOut); } ufile = fileManager.AddFile(attachmentFolder, fileName, (Stream)mst); mst.Close(); } else { using (var fileStream = new FileStream(file.LocalFileName, FileMode.Open, FileAccess.Read)) { var index = 0; while (fileManager.FileExists(attachmentFolder, fileName)) { index++; fileName = string.Format(newFileName, fileNameOnly, index, sExt); } ufile = fileManager.AddFile(attachmentFolder, fileName, fileStream); } } // IE<=9 Hack - can't return application/json var mediaType = "application/json"; if (!request.Headers.Accept.Any(h => h.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase))) { mediaType = "text/html"; } File.Delete(file.LocalFileName); if (ufile != null) { var result = new ClientAttachment() { FileId = ufile.FileId, ContentType = file.Headers.ContentType.MediaType, FileName = fileName, FileSize = ufile.Size, UploadId = localFileName, }; return(Request.CreateResponse(HttpStatusCode.Accepted, result, mediaType)); } else { return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "No File Found")); } }); return(task); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { UserController uc = new UserController(); User ui = uc.GetUser(PortalSettings.PortalId, -1); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(Convert.ToInt32(Request.Params["ForumId"]), ui.UserId, true); if (fi != null) { if (Permissions.HasPerm(fi.Security.Attach, ui.UserRoles)) { if (inpFile.HasFile) { string sFile = string.Empty; string sExt = string.Empty; int maxImgHeight = fi.AttachMaxHeight; int maxImgWidth = fi.AttachMaxWidth; string contentType = inpFile.PostedFile.ContentType; sFile = Path.GetFileName(inpFile.PostedFile.FileName).Replace(" ", "_"); sExt = Path.GetExtension(sFile); if (sFile.Length >= 250) { sFile = sFile.Replace(sExt, string.Empty); sFile = sFile.Substring(0, (250 - sExt.Length)); sFile = sFile + sExt; } sExt = sExt.Replace(".", string.Empty); if (!(fi.AttachTypeAllowed.ToString().ToLower().Contains(sExt.ToLower()))) { Response.Write("<script type=\"text/javascript\">window.top.af_setMessage('" + Utilities.GetSharedResource("[RESX:Error:BlockedFile]") + "');</script>"); return; } if (fi.AttachMaxSize > 0) { if ((inpFile.PostedFile.ContentLength / 1024.0) > fi.AttachMaxSize) { Response.Write("<script type=\"text/javascript\">window.top.af_setMessage('" + string.Format(Utilities.GetSharedResource("[RESX:Error:FileTooLarge]"), fi.AttachMaxSize) + "');</script>"); return; } } Stream inpStream = inpFile.PostedFile.InputStream; MemoryStream imgStream = new MemoryStream(); bool useMemStream = false; bool allowDownload = true; bool displayInline = false; if (sExt.ToLower() == "jpg" || sExt.ToLower() == "gif" || sExt.ToLower() == "bmp" || sExt.ToLower() == "png" || sExt.ToLower() == "jpeg") { useMemStream = true; imgStream = (MemoryStream)(Images.CreateImageForDB(inpStream, maxImgHeight, maxImgWidth)); contentType = "image/x-png"; allowDownload = false; displayInline = true; } Data.AttachController ac = new Data.AttachController(); AttachInfo ai = new AttachInfo(); ai.ContentId = -1; ai.UserID = ui.UserId; ai.ContentType = contentType; ai.DisplayInline = displayInline; ai.AllowDownload = allowDownload; ai.ParentAttachId = 0; if (fi.AttachStore == AttachStores.DATABASE) { if (useMemStream) { ai.FileSize = Convert.ToInt32(imgStream.Length); ai.FileData = imgStream.ToArray(); } else { byte[] byteData = new byte[Convert.ToInt32(inpStream.Length - 1) + 1]; inpStream.Read(byteData, 0, Convert.ToInt32(inpStream.Length)); ai.FileSize = Convert.ToInt32(inpStream.Length); ai.FileData = byteData; } ai.Filename = sFile; } else { if (useMemStream) { ai.FileSize = Convert.ToInt32(imgStream.Length); ai.Filename = SaveToFile(imgStream, sFile); } else { byte[] byteData = new byte[Convert.ToInt32(inpStream.Length) + 1]; inpStream.Read(byteData, 0, Convert.ToInt32(inpStream.Length)); ai.FileSize = Convert.ToInt32(inpStream.Length); ai.Filename = SaveToFile(inpFile, sFile); } } int attachId = ac.Attach_Save(ai); Response.Write("<script type=\"text/javascript\">window.top.af_isUploaded(" + attachId.ToString() + ");</script>"); } } else { inpFile.Visible = false; } } else { inpFile.Visible = false; } } catch (Exception ex) { Response.Write("<script type=\"text/javascript\">window.top.af_setMessage('" + ex.Message + "');</script>"); } }
public Task<HttpResponseMessage> UploadFile() { // This method uploads an attachment to a temporary directory and returns a JSON object containing information about the original file // including the temporary file name. When the post is saved/updated, the temporary file is moved to the appropriate attachment directory // Have to a reference to these variables as the internal reference isn't available. // in the async result. var request = Request; var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(ActiveModule.PortalID, ActiveModule.ModuleID, userInfo.UserID); if (!request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)); } const string uploadPath = "activeforums_Upload"; var folderManager = FolderManager.Instance; if (!folderManager.FolderExists(ActiveModule.PortalID, uploadPath)) { folderManager.AddFolder(ActiveModule.PortalID, uploadPath); } var folder = folderManager.GetFolder(ActiveModule.PortalID, uploadPath); var provider = new MultipartFormDataStreamProvider(folder.PhysicalPath); var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) throw new HttpResponseException(HttpStatusCode.InternalServerError); // Make sure a temp file was uploaded and that it exists var file = provider.FileData.FirstOrDefault(); if (file == null || string.IsNullOrWhiteSpace(file.LocalFileName) || !File.Exists(file.LocalFileName)) { return request.CreateErrorResponse(HttpStatusCode.NoContent, "No File Found"); } // Get the file name without the full path var localFileName = Path.GetFileName(file.LocalFileName).TextOrEmpty(); // Check to make sure that a forum was specified and that the the user has upload permissions // This is only an initial check, it will be done again when the file is saved to a post. int forumId; if (!int.TryParse(provider.FormData["forumId"], out forumId)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Specified"); } // Make sure that we can find the forum and that attachments are allowed var fc = new ForumController(); var forum = fc.Forums_Get(ActiveModule.PortalID, ActiveModule.ModuleID, forumId, userInfo.UserID, true, true, -1); if (forum == null || !forum.AllowAttach) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Found"); } // Make sure the user has permissions to attach files if (forumUser == null || !Permissions.HasPerm(forum.Security.Attach, forumUser.UserRoles)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not Authorized"); } // Make sure that the file size does not exceed the limit (in KB) for the forum // Have to do this since content length is not available when using MultipartFormDataStreamProvider var di = new DirectoryInfo(folder.PhysicalPath); var fileSize = di.GetFiles(localFileName)[0].Length; var maxAllowedFileSize = (long)forum.AttachMaxSize * 1024; if ((forum.AttachMaxSize > 0) && (fileSize > maxAllowedFileSize)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Exceeds Max File Size"); } // Get the original file name from the content disposition header var fileName = file.Headers.ContentDisposition.FileName.Replace("\"", ""); if (string.IsNullOrWhiteSpace(fileName)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Invalid File"); } // Make sure we have an acceptable extension type. // Check against both the forum configuration and the host configuration var extension = Path.GetExtension(fileName).TextOrEmpty().Replace(".", string.Empty).ToLower(); var isForumAllowedExtension = string.IsNullOrWhiteSpace(forum.AttachTypeAllowed) || forum.AttachTypeAllowed.Replace(".", "").Split(',').Any(val => val == extension); if (string.IsNullOrEmpty(extension) || !isForumAllowedExtension || !Host.AllowedExtensionWhitelist.IsAllowedExtension(extension)) { File.Delete(file.LocalFileName); return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "File Type Not Allowed"); } const string newFileName = "{0}_{1}{2}"; var fileNameOnly = Path.GetFileNameWithoutExtension(fileName); var userFolder = folderManager.GetUserFolder(userInfo); var attachmentFolder = folderManager.GetFolder(userFolder.FolderID); var fileManager = FileManager.Instance; IFileInfo ufile = null; string sExt = Path.GetExtension(fileName); if (sExt.ToLower() == ".jpg" || sExt.ToLower() == ".bmp" || sExt.ToLower() == ".png" || sExt.ToLower() == ".jpeg") { var sExtOut = ".jpg"; ImageFormat imf, imfout = ImageFormat.Jpeg; Image img = Image.FromFile(file.LocalFileName); Image nimg; var maxWidth = forum.MaxAttachWidth; var maxHeight = forum.MaxAttachHeight; int imgWidth = img.Width; int imgHeight = img.Height; var ratioWidth = (double)imgWidth / maxWidth; var ratioHeight = (double)imgHeight / maxHeight; switch (sExt.ToLower()) { case ".png": { imf = ImageFormat.Png; if (!forum.ConvertingToJpegAllowed) { sExtOut = ".png"; imfout = ImageFormat.Png; } break; } case ".bmp": imf = ImageFormat.Bmp; break; default: imf = ImageFormat.Jpeg; break; } MemoryStream mst = new MemoryStream(); if (ratioWidth > 1 || ratioHeight > 1) { if (ratioWidth > ratioHeight) { imgWidth = maxWidth; imgHeight = (int)Math.Round(imgHeight / ratioWidth); } else if (ratioWidth < ratioHeight) { imgHeight = maxHeight; imgWidth = (int)Math.Round(imgWidth / ratioHeight); } else { imgWidth = maxWidth; imgHeight = maxHeight; } } Bitmap res = new Bitmap(imgWidth, imgHeight); using (Graphics gr = Graphics.FromImage(res)) { gr.Clear(Color.Transparent); gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.DrawImage(img, new Rectangle(0, 0, imgWidth, imgHeight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); gr.Dispose(); } img.Dispose(); res.Save(mst, imfout); res.Dispose(); var index = 0; fileName = fileNameOnly + sExtOut; while (fileManager.FileExists(attachmentFolder, fileName)) { index++; fileName = string.Format(newFileName, fileNameOnly, index, sExtOut); } ufile = fileManager.AddFile(attachmentFolder, fileName, (Stream)mst); mst.Close(); } else { using (var fileStream = new FileStream(file.LocalFileName, FileMode.Open, FileAccess.Read)) { var index = 0; while (fileManager.FileExists(attachmentFolder, fileName)) { index++; fileName = string.Format(newFileName, fileNameOnly, index, sExt); } ufile = fileManager.AddFile(attachmentFolder, fileName, fileStream); } } // IE<=9 Hack - can't return application/json var mediaType = "application/json"; if (!request.Headers.Accept.Any(h => h.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase))) mediaType = "text/html"; File.Delete(file.LocalFileName); if (ufile != null) { var result = new ClientAttachment() { FileId = ufile.FileId, ContentType = file.Headers.ContentType.MediaType, FileName = fileName, FileSize = ufile.Size, UploadId = localFileName, }; return Request.CreateResponse(HttpStatusCode.Accepted, result, mediaType); } else { return request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "No File Found"); } }); return task; }
public HttpResponseMessage RejectPost(ModerationDTO dto) { var notify = NotificationsController.Instance.GetNotification(dto.NotificationId); ParseNotificationContext(notify.Context); var fc = new ForumController(); var fi = fc.Forums_Get(_forumId, -1, false, true); if (fi == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Forum Not Found" }); if (!(IsMod(_forumId))) return Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "User is not a moderator for this forum" }); var mc = new ModController(); mc.Mod_Reject(PortalSettings.PortalId, _moduleId, UserInfo.UserID, _forumId, _topicId, _replyId); int authorId; if (_replyId > 0) { var rc = new ReplyController(); var reply = rc.Reply_Get(PortalSettings.PortalId, _moduleId, _topicId, _replyId); if (reply == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Reply Not Found" }); authorId = reply.Content.AuthorId; } else { var tc = new TopicsController(); var topic = tc.Topics_Get(PortalSettings.PortalId, _moduleId, _topicId); if (topic == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Topic Not Found" }); authorId = topic.Content.AuthorId; } if (fi.ModRejectTemplateId > 0 && authorId > 0) { var uc = new Entities.Users.UserController(); var ui = uc.GetUser(PortalSettings.PortalId, authorId); if (ui != null) { var au = new Author { AuthorId = authorId, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName, Username = ui.Username }; Email.SendEmail(fi.ModRejectTemplateId, PortalSettings.PortalId, _moduleId, _tabId, _forumId, _topicId, _replyId, string.Empty, au); } } NotificationsController.Instance.DeleteNotification(dto.NotificationId); return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }); }
private void cbEditorAction_Callback(object sender, Controls.CallBackEventArgs e) { switch (e.Parameters[0].ToLowerInvariant()) { case "forumsave": { var fi = new Forum(); var fc = new ForumController(); var bIsNew = false; int forumGroupId; var forumSettingsKey = string.Empty; if (Utilities.SafeConvertInt(e.Parameters[1]) <= 0) { bIsNew = true; fi.ForumID = -1; } else { fi = fc.Forums_Get(PortalId, ModuleId, Utilities.SafeConvertInt(e.Parameters[1]), UserId, false, false, -1); forumSettingsKey = fi.ForumSettingsKey; } fi.ModuleId = ModuleId; fi.PortalId = PortalId; var sParentValue = e.Parameters[2]; var parentForumId = 0; if (sParentValue.Contains("GROUP")) { sParentValue = sParentValue.Replace("GROUP", string.Empty); forumGroupId = Utilities.SafeConvertInt(sParentValue); } else { parentForumId = Utilities.SafeConvertInt(sParentValue.Replace("FORUM", string.Empty)); forumGroupId = fc.Forums_GetGroupId(parentForumId); } fi.ForumGroupId = forumGroupId; fi.ParentForumId = parentForumId; fi.ForumName = e.Parameters[3]; fi.ForumDesc = e.Parameters[4]; fi.Active = Utilities.SafeConvertBool(e.Parameters[5]); fi.Hidden = Utilities.SafeConvertBool(e.Parameters[6]); fi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]); var fkey = string.IsNullOrEmpty(fi.ForumSettingsKey) ? string.Empty : fi.ForumSettingsKey; if (Utilities.SafeConvertBool(e.Parameters[8])) { var fgc = new ForumGroupController(); var fgi = fgc.GetForumGroup(ModuleId, forumGroupId); if (bIsNew) fi.PermissionsId = fgi.PermissionsId; else if (fi.ForumSettingsKey != "G:" + forumGroupId) fi.PermissionsId = fgi.PermissionsId; fi.ForumSettingsKey = "G:" + forumGroupId; } else if (bIsNew || fkey.Contains("G:")) { fi.ForumSettingsKey = string.Empty; if (fi.InheritSecurity) fi.PermissionsId = -1; } else { fi.ForumSettingsKey = "F:" + fi.ForumID; } if (forumSettingsKey != fkey && fkey.Contains("F:")) bIsNew = true; fi.PrefixURL = e.Parameters[9]; if (!(string.IsNullOrEmpty(fi.PrefixURL))) { var db = new Data.Common(); if (!(db.CheckForumURL(PortalId, ModuleId, fi.PrefixURL, fi.ForumID, fi.ForumGroupId))) fi.PrefixURL = string.Empty; } var forumId = fc.Forums_Save(PortalId, fi, bIsNew, Utilities.SafeConvertBool(e.Parameters[8])); recordId = forumId; var securityKey = string.Empty; DataCache.ClearForumGroupsCache(ModuleId); var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId); DataCache.CacheClear(cachekey); cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); hidEditorResult.Value = forumId.ToString(); break; } case "groupsave": { var bIsNew = false; var groupId = Utilities.SafeConvertInt(e.Parameters[1]); var fgc = new ForumGroupController(); var gi = (groupId > 0) ? fgc.Groups_Get(ModuleId, groupId) : new ForumGroupInfo(); var securityKey = string.Empty; if (groupId == 0) bIsNew = true; else securityKey = "G:" + groupId; gi.ModuleId = ModuleId; gi.ForumGroupId = groupId; gi.GroupName = e.Parameters[3]; gi.Active = Utilities.SafeConvertBool(e.Parameters[5]); gi.Hidden = Utilities.SafeConvertBool(e.Parameters[6]); gi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]); gi.PrefixURL = e.Parameters[9]; if (!(string.IsNullOrEmpty(gi.PrefixURL))) { var db = new Data.Common(); if (!(db.CheckGroupURL(PortalId, ModuleId, gi.PrefixURL, gi.ForumGroupId))) gi.PrefixURL = string.Empty; } gi.GroupSettingsKey = securityKey; var gc = new ForumGroupController(); groupId = gc.Groups_Save(PortalId, gi, bIsNew); recordId = groupId; DataCache.ClearForumGroupsCache(ModuleId); var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); hidEditorResult.Value = groupId.ToString(); break; } case "forumsettingssave": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); var sKey = "F:" + forumId; SaveSettings(sKey, e.Parameters); hidEditorResult.Value = forumId.ToString(); DataCache.CacheClear(forumId.ToString() + "ForumSettings"); DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId)); DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId) + "st"); var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId); DataCache.CacheClear(cachekey); break; } case "groupsettingssave": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); var sKey = "G:" + forumId; SaveSettings(sKey, e.Parameters); hidEditorResult.Value = forumId.ToString(); DataCache.CacheClear(forumId.ToString() + "GroupSettings"); DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId)); DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId) + "st"); break; } case "deleteforum": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); DataProvider.Instance().Forums_Delete(PortalId, ModuleId, forumId); var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); break; } case "deletegroup": { var groupId = Utilities.SafeConvertInt(e.Parameters[1]); DataProvider.Instance().Groups_Delete(ModuleId, groupId); var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); break; } } DataCache.CacheClear(string.Format(CacheKeys.ForumList, ModuleId)); DataCache.ClearAllForumSettingsCache(ModuleId); DataCache.CacheClear(ModuleId + "fv"); hidEditorResult.RenderControl(e.Output); }
public void SendEmailToModerators(int TemplateId, int PortalId, int ForumId, int TopicId, int ReplyId, int ModuleID, int TabID, string Comments, DotNetNuke.Entities.Users.UserInfo User) { var _portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); SettingsInfo MainSettings = DataCache.MainSettings(ModuleID); var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); if (fi == null) { return; } var subs = new List <SubscriptionInfo>(); var rc = new Security.Roles.RoleController(); var uc = new Entities.Users.UserController(); SubscriptionInfo si; string modApprove = fi.Security.ModApprove; string[] modRoles = modApprove.Split('|')[0].Split(';'); if (modRoles != null) { foreach (string r in modRoles) { if (!(string.IsNullOrEmpty(r))) { int rid = Convert.ToInt32(r); string rName = rc.GetRole(rid, PortalId).RoleName; foreach (Entities.Users.UserRoleInfo usr in rc.GetUserRolesByRoleName(PortalId, rName)) { var ui = uc.GetUser(PortalId, usr.UserID); si = new SubscriptionInfo { UserId = ui.UserID, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName }; if (!(subs.Contains(si))) { subs.Add(si); } } } } } if (subs.Count <= 0) { return; } string Subject; string BodyText; string BodyHTML; string sTemplate = string.Empty; var tc = new TemplateController(); TemplateInfo ti = tc.Template_Get(TemplateId, PortalId, ModuleID); Subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, _portalSettings.TimeZoneOffset); BodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset); BodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset); string sFrom; sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : _portalSettings.Email; var oEmail = new Email { Recipients = subs, Subject = Subject, From = sFrom, BodyText = BodyText, BodyHTML = BodyHTML, SmtpServer = Host.SMTPServer, // Convert.ToString(_portalSettings.HostSettings["SMTPServer"]), SmtpUserName = Host.SMTPUsername, // Convert.ToString(_portalSettings.HostSettings["SMTPUsername"]), SmtpPassword = Host.SMTPPassword, // Convert.ToString(_portalSettings.HostSettings["SMTPPassword"]), SmtpAuthentication = Host.SMTPAuthentication // Convert.ToString(_portalSettings.HostSettings["SMTPAuthentication"]) }; //#if SKU_ENTERPRISE oEmail.UseQueue = MainSettings.MailQueue; //#endif var objThread = new System.Threading.Thread(oEmail.Send); objThread.Start(); }
public Task <HttpResponseMessage> UploadFile() { // This method uploads an attachment to a temporary directory and returns a JSON object containing information about the original file // including the temporary file name. When the post is saved/updated, the temporary file is moved to the appropriate attachment directory // Have to a reference to these variables as the internal reference isn't available. // in the async result. var request = Request; var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(ActiveModule.PortalID, ActiveModule.ModuleID, userInfo.UserID); if (!request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)); } const string uploadPath = "activeforums_Upload"; var folderManager = FolderManager.Instance; if (!folderManager.FolderExists(ActiveModule.PortalID, uploadPath)) { folderManager.AddFolder(ActiveModule.PortalID, uploadPath); } var folder = folderManager.GetFolder(ActiveModule.PortalID, uploadPath); var provider = new MultipartFormDataStreamProvider(folder.PhysicalPath); var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } // Make sure a temp file was uploaded and that it exists var file = provider.FileData.FirstOrDefault(); if (file == null || string.IsNullOrWhiteSpace(file.LocalFileName) || !File.Exists(file.LocalFileName)) { return(request.CreateErrorResponse(HttpStatusCode.NoContent, "No File Found")); } // Get the file name without the full path var localFileName = Path.GetFileName(file.LocalFileName).TextOrEmpty(); // Check to make sure that a forum was specified and that the the user has upload permissions // This is only an initial check, it will be done again when the file is saved to a post. int forumId; if (!int.TryParse(provider.FormData["forumId"], out forumId)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Specified")); } // Make sure that we can find the forum and that attachments are allowed var fc = new ForumController(); var forum = fc.Forums_Get(ActiveModule.PortalID, ActiveModule.ModuleID, forumId, userInfo.UserID, true, true, -1); if (forum == null || !forum.AllowAttach) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Forum Not Found")); } // Make sure the user has permissions to attach files if (forumUser == null || !Permissions.HasPerm(forum.Security.Attach, forumUser.UserRoles)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not Authorized")); } // Make sure that the file size does not exceed the limit (in KB) for the forum // Have to do this since content length is not available when using MultipartFormDataStreamProvider var di = new DirectoryInfo(folder.PhysicalPath); var fileSize = di.GetFiles(localFileName)[0].Length; var maxAllowedFileSize = (long)forum.AttachMaxSize * 1024; if ((forum.AttachMaxSize > 0) && (fileSize > maxAllowedFileSize)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Exceeds Max File Size")); } // Get the original file name from the content disposition header var fileName = file.Headers.ContentDisposition.FileName.Replace("\"", ""); if (string.IsNullOrWhiteSpace(fileName)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Invalid File")); } // Make sure we have an acceptable extension type. // Check against both the forum configuration and the host configuration var extension = Path.GetExtension(fileName).TextOrEmpty().Replace(".", string.Empty).ToLower(); var isForumAllowedExtension = string.IsNullOrWhiteSpace(forum.AttachTypeAllowed) || forum.AttachTypeAllowed.Replace(".", "").Split(',').Any(val => val == extension); if (string.IsNullOrEmpty(extension) || !isForumAllowedExtension || !Host.AllowedExtensionWhitelist.IsAllowedExtension(extension)) { File.Delete(file.LocalFileName); return(request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "File Type Not Allowed")); } // IE<=9 Hack - can't return application/json var mediaType = "application/json"; if (!request.Headers.Accept.Any(h => h.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase))) { mediaType = "text/html"; } var result = new ClientAttachment() { ContentType = file.Headers.ContentType.MediaType, FileName = fileName, FileSize = fileSize, UploadId = localFileName }; return(Request.CreateResponse(HttpStatusCode.Accepted, result, mediaType)); }); return(task); }
private void cbMod_Callback(object sender, Modules.ActiveForums.Controls.CallBackEventArgs e) { SettingsInfo ms = DataCache.MainSettings(ForumModuleId); Forum fi = null; if (e.Parameters.Length > 0) { if (ForumId < 1) { SetPermissions(Convert.ToInt32(e.Parameters[1])); ForumController fc = new ForumController(); fi = fc.Forums_Get(Convert.ToInt32(e.Parameters[1]), -1, false, true); } else { fi = ForumInfo; } switch (e.Parameters[0].ToLowerInvariant()) { case "moddel": { if (bModDelete) { int delAction = ms.DeleteBehavior; int tmpForumId = -1; int tmpTopicId = -1; int tmpReplyId = -1; tmpForumId = Convert.ToInt32(e.Parameters[1]); tmpTopicId = Convert.ToInt32(e.Parameters[2]); tmpReplyId = Convert.ToInt32(e.Parameters[3]); Author auth = null; if (fi.ModDeleteTemplateId > 0) { try { Email oEmail = new Email(); oEmail.SendEmail(fi.ModDeleteTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, auth); } catch (Exception ex) { } } if (tmpForumId > 0 & tmpTopicId > 0 && tmpReplyId == 0) { TopicsController tc = new TopicsController(); TopicInfo ti = tc.Topics_Get(PortalId, ForumModuleId, tmpTopicId); if (ti != null) { auth = ti.Author; } tc.Topics_Delete(PortalId, ModuleId, tmpForumId, tmpTopicId, delAction); } else if (tmpForumId > 0 & tmpTopicId > 0 & tmpReplyId > 0) { ReplyController rc = new ReplyController(); ReplyInfo ri = rc.Reply_Get(PortalId, ForumModuleId, tmpTopicId, tmpReplyId); if (ri != null) { auth = ri.Author; } rc.Reply_Delete(PortalId, tmpForumId, tmpTopicId, tmpReplyId, delAction); } } break; } case "modreject": { int tmpForumId = 0; int tmpTopicId = 0; int tmpReplyId = 0; int tmpAuthorId = 0; tmpForumId = Convert.ToInt32(e.Parameters[1]); tmpTopicId = Convert.ToInt32(e.Parameters[2]); tmpReplyId = Convert.ToInt32(e.Parameters[3]); tmpAuthorId = Convert.ToInt32(e.Parameters[4]); ModController mc = new ModController(); mc.Mod_Reject(PortalId, ForumModuleId, UserId, tmpForumId, tmpTopicId, tmpReplyId); if (fi.ModRejectTemplateId > 0 & tmpAuthorId > 0) { DotNetNuke.Entities.Users.UserController uc = new DotNetNuke.Entities.Users.UserController(); DotNetNuke.Entities.Users.UserInfo ui = uc.GetUser(PortalId, tmpAuthorId); if (ui != null) { Author au = new Author(); au.AuthorId = tmpAuthorId; au.DisplayName = ui.DisplayName; au.Email = ui.Email; au.FirstName = ui.FirstName; au.LastName = ui.LastName; au.Username = ui.Username; Email oEmail = new Email(); oEmail.SendEmail(fi.ModRejectTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, au); } } break; } case "modappr": { int tmpForumId = -1; int tmpTopicId = -1; int tmpReplyId = -1; tmpForumId = Convert.ToInt32(e.Parameters[1]); tmpTopicId = Convert.ToInt32(e.Parameters[2]); tmpReplyId = Convert.ToInt32(e.Parameters[3]); string sSubject = string.Empty; string sBody = string.Empty; if (tmpForumId > 0 & tmpTopicId > 0 && tmpReplyId == 0) { TopicsController tc = new TopicsController(); TopicInfo ti = tc.Topics_Get(PortalId, ForumModuleId, tmpTopicId, tmpForumId, -1, false); if (ti != null) { sSubject = ti.Content.Subject; sBody = ti.Content.Body; ti.IsApproved = true; tc.TopicSave(PortalId, ti); tc.Topics_SaveToForum(tmpForumId, tmpTopicId, PortalId, ModuleId); //TODO: Add Audit log for who approved topic if (fi.ModApproveTemplateId > 0 & ti.Author.AuthorId > 0) { Email oEmail = new Email(); oEmail.SendEmail(fi.ModApproveTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, ti.Author); } Subscriptions.SendSubscriptions(PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, 0, ti.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string sUrl = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, TopicId, ti.TopicUrl, -1, -1, string.Empty, 1, fi.SocialGroupId); // Utilities.NavigateUrl(ForumTabId, "", ParamKeys.ViewType & "=" & Views.Topic & "&" & ParamKeys.ForumId & "=" & ForumId, ParamKeys.TopicId & "=" & TopicId) if (sUrl.Contains("~/") || Request.QueryString["asg"] != null) { sUrl = Utilities.NavigateUrl(ForumTabId, "", ParamKeys.TopicId + "=" + TopicId); } Social amas = new Social(); if (Request.QueryString["asg"] == null & !(string.IsNullOrEmpty(MainSettings.ActiveSocialTopicsKey)) && fi.ActiveSocialEnabled) { amas.AddTopicToJournal(PortalId, ForumModuleId, ForumId, ti.TopicId, ti.Author.AuthorId, sUrl, sSubject, ti.Content.Summary, sBody, fi.ActiveSocialSecurityOption, fi.Security.Read, SocialGroupId); } else { amas.AddForumItemToJournal(PortalId, ForumModuleId, ti.Author.AuthorId, "forumtopic", sUrl, sSubject, sBody); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } } } else if (tmpForumId > 0 & tmpTopicId > 0 & tmpReplyId > 0) { ReplyController rc = new ReplyController(); ReplyInfo ri = rc.Reply_Get(PortalId, ForumModuleId, tmpTopicId, tmpReplyId); if (ri != null) { ri.IsApproved = true; sSubject = ri.Content.Subject; sBody = ri.Content.Body; rc.Reply_Save(PortalId, ri); TopicsController tc = new TopicsController(); tc.Topics_SaveToForum(tmpForumId, tmpTopicId, PortalId, ModuleId, tmpReplyId); TopicInfo ti = tc.Topics_Get(PortalId, ForumModuleId, tmpTopicId, tmpForumId, -1, false); //TODO: Add Audit log for who approved topic if (fi.ModApproveTemplateId > 0 & ri.Author.AuthorId > 0) { Email oEmail = new Email(); oEmail.SendEmail(fi.ModApproveTemplateId, PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, string.Empty, ri.Author); } Subscriptions.SendSubscriptions(PortalId, ForumModuleId, ForumTabId, tmpForumId, tmpTopicId, tmpReplyId, ri.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string fullURL = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, TopicId, ti.TopicUrl, -1, -1, string.Empty, 1, fi.SocialGroupId); if (fullURL.Contains("~/") || Request.QueryString["asg"] != null) { fullURL = Utilities.NavigateUrl(ForumTabId, "", new string[] { ParamKeys.TopicId + "=" + TopicId, ParamKeys.ContentJumpId + "=" + tmpReplyId }); } Social amas = new Social(); if (Request.QueryString["asg"] == null & !(string.IsNullOrEmpty(MainSettings.ActiveSocialTopicsKey)) && fi.ActiveSocialEnabled && !fi.ActiveSocialTopicsOnly) { amas.AddReplyToJournal(PortalId, ForumModuleId, ForumId, ri.TopicId, ri.ReplyId, ri.Author.AuthorId, fullURL, ri.Content.Subject, string.Empty, sBody, fi.ActiveSocialSecurityOption, fi.Security.Read, fi.SocialGroupId); } else { amas.AddForumItemToJournal(PortalId, ForumModuleId, ri.Author.AuthorId, "forumreply", fullURL, sSubject, sBody); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } } } break; } } string cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); } BuildModList(); litTopics.RenderControl(e.Output); }
public static void SendSubscriptions(int PortalId, int ModuleId, int TabId, int ForumId, int TopicId, int ReplyId, int AuthorId) { var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false); SendSubscriptions(PortalId, ModuleId, TabId, fi, TopicId, ReplyId, AuthorId); }
public HttpResponseMessage RejectPost(ModerationDTO dto) { var notify = NotificationsController.Instance.GetNotification(dto.NotificationId); ParseNotificationContext(notify.Context); var fc = new ForumController(); var fi = fc.Forums_Get(_forumId, -1, false, true); if (fi == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Forum Not Found" })); } if (!(IsMod(_forumId))) { return(Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "User is not a moderator for this forum" })); } var mc = new ModController(); mc.Mod_Reject(PortalSettings.PortalId, _moduleId, UserInfo.UserID, _forumId, _topicId, _replyId); int authorId; if (_replyId > 0) { var rc = new ReplyController(); var reply = rc.Reply_Get(PortalSettings.PortalId, _moduleId, _topicId, _replyId); if (reply == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Reply Not Found" })); } authorId = reply.Content.AuthorId; } else { var tc = new TopicsController(); var topic = tc.Topics_Get(PortalSettings.PortalId, _moduleId, _topicId); if (topic == null) { return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Topic Not Found" })); } authorId = topic.Content.AuthorId; } if (fi.ModRejectTemplateId > 0 && authorId > 0) { var uc = new Entities.Users.UserController(); var ui = uc.GetUser(PortalSettings.PortalId, authorId); if (ui != null) { var au = new Author { AuthorId = authorId, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName, Username = ui.Username }; var oEmail = new Email(); oEmail.SendEmail(fi.ModRejectTemplateId, PortalSettings.PortalId, _moduleId, _tabId, _forumId, _topicId, _replyId, string.Empty, au); } } NotificationsController.Instance.DeleteNotification(dto.NotificationId); return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" })); }
public HttpResponseMessage IgnorePost(ModerationDTO dto) { var notify = NotificationsController.Instance.GetNotification(dto.NotificationId); ParseNotificationContext(notify.Context); var fc = new ForumController(); var fi = fc.Forums_Get(_forumId, -1, false, true); if (fi == null) return Request.CreateResponse(HttpStatusCode.OK, new { Message = "Forum Not Found" }); if (!(IsMod(_forumId))) return Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "User is not a moderator for this forum" }); NotificationsController.Instance.DeleteNotification(dto.NotificationId); return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }); }
public void SendEmailToModerators(int TemplateId, int PortalId, int ForumId, int TopicId, int ReplyId, int ModuleID, int TabID, string Comments, DotNetNuke.Entities.Users.UserInfo User) { var _portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); SettingsInfo MainSettings = DataCache.MainSettings(ModuleID); var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); if (fi == null) { return; } var subs = new List<SubscriptionInfo>(); var rc = new Security.Roles.RoleController(); var uc = new Entities.Users.UserController(); SubscriptionInfo si; string modApprove = fi.Security.ModApprove; string[] modRoles = modApprove.Split('|')[0].Split(';'); if (modRoles != null) { foreach (string r in modRoles) { if (! (string.IsNullOrEmpty(r))) { int rid = Convert.ToInt32(r); string rName = rc.GetRole(rid, PortalId).RoleName; foreach (Entities.Users.UserRoleInfo usr in rc.GetUserRolesByRoleName(PortalId, rName)) { var ui = uc.GetUser(PortalId, usr.UserID); si = new SubscriptionInfo { UserId = ui.UserID, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName }; if (! (subs.Contains(si))) { subs.Add(si); } } } } } if (subs.Count <= 0) { return; } string Subject; string BodyText; string BodyHTML; string sTemplate = string.Empty; var tc = new TemplateController(); TemplateInfo ti = tc.Template_Get(TemplateId, PortalId, ModuleID); Subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, _portalSettings.TimeZoneOffset); BodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset); BodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset); string sFrom; sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : _portalSettings.Email; var oEmail = new Email { Recipients = subs, Subject = Subject, From = sFrom, BodyText = BodyText, BodyHTML = BodyHTML, SmtpServer = Convert.ToString(_portalSettings.HostSettings["SMTPServer"]), SmtpUserName = Convert.ToString(_portalSettings.HostSettings["SMTPUsername"]), SmtpPassword = Convert.ToString(_portalSettings.HostSettings["SMTPPassword"]), SmtpAuthentication = Convert.ToString(_portalSettings.HostSettings["SMTPAuthentication"]) }; //#if SKU_ENTERPRISE oEmail.UseQueue = MainSettings.MailQueue; //#endif var objThread = new System.Threading.Thread(oEmail.Send); objThread.Start(); }
public static void SendEmailToModerators(int templateId, int portalId, int forumId, int topicId, int replyId, int moduleID, int tabID, string comments, UserInfo user) { var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); var mainSettings = DataCache.MainSettings(moduleID); var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, true); if (fi == null) { return; } var subs = new List <SubscriptionInfo>(); var rc = new Security.Roles.RoleController(); var rp = RoleProvider.Instance(); var uc = new Entities.Users.UserController(); var modApprove = fi.Security.ModApprove; var modRoles = modApprove.Split('|')[0].Split(';'); foreach (var r in modRoles) { if (string.IsNullOrEmpty(r)) { continue; } var rid = Convert.ToInt32(r); var rName = rc.GetRole(rid, portalId).RoleName; foreach (UserRoleInfo usr in rp.GetUserRoles(portalId, null, rName)) { var ui = uc.GetUser(portalId, usr.UserID); var si = new SubscriptionInfo { UserId = ui.UserID, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName }; if (!(subs.Contains(si))) { subs.Add(si); } } } if (subs.Count <= 0) { return; } var sTemplate = string.Empty; var tc = new TemplateController(); var ti = tc.Template_Get(templateId, portalId, moduleID); var subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes)); var bodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, comments, user, -1, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes)); var bodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, comments, user, -1, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes)); var sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : portalSettings.Email; var oEmail = new Email { Recipients = subs, Subject = subject, From = sFrom, BodyText = bodyText, BodyHTML = bodyHTML, UseQueue = mainSettings.MailQueue }; new Thread(oEmail.Send).Start(); }
private void cbEditorAction_Callback(object sender, Controls.CallBackEventArgs e) { switch (e.Parameters[0].ToLowerInvariant()) { case "forumsave": { var fi = new Forum(); var fc = new ForumController(); var bIsNew = false; int forumGroupId; var forumSettingsKey = string.Empty; if (Utilities.SafeConvertInt(e.Parameters[1]) <= 0) { bIsNew = true; fi.ForumID = -1; } else { fi = fc.Forums_Get(PortalId, ModuleId, Utilities.SafeConvertInt(e.Parameters[1]), UserId, false, false, -1); forumSettingsKey = fi.ForumSettingsKey; } fi.ModuleId = ModuleId; fi.PortalId = PortalId; var sParentValue = e.Parameters[2]; var parentForumId = 0; if (sParentValue.Contains("GROUP")) { sParentValue = sParentValue.Replace("GROUP", string.Empty); forumGroupId = Utilities.SafeConvertInt(sParentValue); } else { parentForumId = Utilities.SafeConvertInt(sParentValue.Replace("FORUM", string.Empty)); forumGroupId = fc.Forums_GetGroupId(parentForumId); } fi.ForumGroupId = forumGroupId; fi.ParentForumId = parentForumId; fi.ForumName = e.Parameters[3]; fi.ForumDesc = e.Parameters[4]; fi.Active = Utilities.SafeConvertBool(e.Parameters[5]); fi.Hidden = Utilities.SafeConvertBool(e.Parameters[6]); fi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]); var fkey = string.IsNullOrEmpty(fi.ForumSettingsKey) ? string.Empty : fi.ForumSettingsKey; if (Utilities.SafeConvertBool(e.Parameters[8])) { var fgc = new ForumGroupController(); var fgi = fgc.GetForumGroup(ModuleId, forumGroupId); if (bIsNew) { fi.PermissionsId = fgi.PermissionsId; } else if (fi.ForumSettingsKey != "G:" + forumGroupId) { fi.PermissionsId = fgi.PermissionsId; } fi.ForumSettingsKey = "G:" + forumGroupId; } else if (bIsNew || fkey.Contains("G:")) { fi.ForumSettingsKey = string.Empty; if (fi.InheritSecurity) { fi.PermissionsId = -1; } } else { fi.ForumSettingsKey = "F:" + fi.ForumID; } if (forumSettingsKey != fkey && fkey.Contains("F:")) { bIsNew = true; } fi.PrefixURL = e.Parameters[9]; if (!(string.IsNullOrEmpty(fi.PrefixURL))) { var db = new Data.Common(); if (!(db.CheckForumURL(PortalId, ModuleId, fi.PrefixURL, fi.ForumID, fi.ForumGroupId))) { fi.PrefixURL = string.Empty; } } var forumId = fc.Forums_Save(PortalId, fi, bIsNew, Utilities.SafeConvertBool(e.Parameters[8])); recordId = forumId; var securityKey = string.Empty; DataCache.ClearForumGroupsCache(ModuleId); var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId); DataCache.CacheClear(cachekey); cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); hidEditorResult.Value = forumId.ToString(); break; } case "groupsave": { var bIsNew = false; var groupId = Utilities.SafeConvertInt(e.Parameters[1]); var fgc = new ForumGroupController(); var gi = (groupId > 0) ? fgc.Groups_Get(ModuleId, groupId) : new ForumGroupInfo(); var securityKey = string.Empty; if (groupId == 0) { bIsNew = true; } else { securityKey = "G:" + groupId; } gi.ModuleId = ModuleId; gi.ForumGroupId = groupId; gi.GroupName = e.Parameters[3]; gi.Active = Utilities.SafeConvertBool(e.Parameters[5]); gi.Hidden = Utilities.SafeConvertBool(e.Parameters[6]); gi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]); gi.PrefixURL = e.Parameters[9]; if (!(string.IsNullOrEmpty(gi.PrefixURL))) { var db = new Data.Common(); if (!(db.CheckGroupURL(PortalId, ModuleId, gi.PrefixURL, gi.ForumGroupId))) { gi.PrefixURL = string.Empty; } } gi.GroupSettingsKey = securityKey; var gc = new ForumGroupController(); groupId = gc.Groups_Save(PortalId, gi, bIsNew); recordId = groupId; DataCache.ClearForumGroupsCache(ModuleId); var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); hidEditorResult.Value = groupId.ToString(); break; } case "forumsettingssave": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); var sKey = "F:" + forumId; SaveSettings(sKey, e.Parameters); hidEditorResult.Value = forumId.ToString(); DataCache.CacheClear(forumId.ToString() + "ForumSettings"); DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId)); DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId) + "st"); var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId); DataCache.CacheClear(cachekey); break; } case "groupsettingssave": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); var sKey = "G:" + forumId; SaveSettings(sKey, e.Parameters); hidEditorResult.Value = forumId.ToString(); DataCache.CacheClear(forumId.ToString() + "GroupSettings"); DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId)); DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId) + "st"); break; } case "deleteforum": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); DataProvider.Instance().Forums_Delete(PortalId, ModuleId, forumId); var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); break; } case "deletegroup": { var groupId = Utilities.SafeConvertInt(e.Parameters[1]); DataProvider.Instance().Groups_Delete(ModuleId, groupId); var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId); DataCache.CacheClearPrefix(cachekey); break; } } DataCache.CacheClear(string.Format(CacheKeys.ForumList, ModuleId)); DataCache.ClearAllForumSettingsCache(ModuleId); DataCache.CacheClear(ModuleId + "fv"); hidEditorResult.RenderControl(e.Output); }
public TopicInfo ApproveTopic(int PortalId, int TabId, int ModuleId, int ForumId, int TopicId) { SettingsInfo ms = DataCache.MainSettings(ModuleId); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); TopicsController tc = new TopicsController(); TopicInfo topic = tc.Topics_Get(PortalId, ModuleId, TopicId, ForumId, -1, false); if (topic == null) { return null; } topic.IsApproved = true; tc.TopicSave(PortalId, topic); tc.Topics_SaveToForum(ForumId, TopicId, PortalId, ModuleId); if (fi.ModApproveTemplateId > 0 & topic.Author.AuthorId > 0) { Email oEmail = new Email(); oEmail.SendEmail(fi.ModApproveTemplateId, PortalId, ModuleId, TabId, ForumId, TopicId, 0, string.Empty, topic.Author); } Subscriptions.SendSubscriptions(PortalId, ModuleId, TabId, ForumId, TopicId, 0, topic.Content.AuthorId); try { ControlUtils ctlUtils = new ControlUtils(); string sUrl = ctlUtils.BuildUrl(TabId, ModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, TopicId, topic.TopicUrl, -1, -1, string.Empty, 1, fi.SocialGroupId); Social amas = new Social(); amas.AddTopicToJournal(PortalId, ModuleId, ForumId, TopicId, topic.Author.AuthorId, sUrl, topic.Content.Subject, string.Empty, topic.Content.Body, fi.ActiveSocialSecurityOption, fi.Security.Read, fi.SocialGroupId); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return topic; }
public void SendEmail(int TemplateId, int PortalId, int ModuleId, int TabId, int ForumId, int TopicId, int ReplyId, string Comments, Author author) { var _portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); SettingsInfo MainSettings = DataCache.MainSettings(ModuleId); string Subject; string BodyText; string BodyHTML; string sTemplate = string.Empty; var tc = new TemplateController(); TemplateInfo ti = tc.Template_Get(TemplateId, PortalId, ModuleId); Subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, author.AuthorId, _portalSettings.TimeZoneOffset); BodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, author.AuthorId, _portalSettings.TimeZoneOffset); BodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, PortalId, ModuleId, TabId, ForumId, TopicId, ReplyId, string.Empty, author.AuthorId, _portalSettings.TimeZoneOffset); BodyText = BodyText.Replace("[REASON]", Comments); BodyHTML = BodyHTML.Replace("[REASON]", Comments); string sFrom; var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : _portalSettings.Email; //Send now var oEmail = new Email(); var subs = new List<SubscriptionInfo>(); var si = new SubscriptionInfo { DisplayName = author.DisplayName, Email = author.Email, FirstName = author.FirstName, LastName = author.LastName, UserId = author.AuthorId, Username = author.Username }; subs.Add(si); oEmail.UseQueue = MainSettings.MailQueue; oEmail.Recipients = subs; oEmail.Subject = Subject; oEmail.From = sFrom; oEmail.BodyText = BodyText; oEmail.BodyHTML = BodyHTML; oEmail.SmtpServer = Convert.ToString(_portalSettings.HostSettings["SMTPServer"]); oEmail.SmtpUserName = Convert.ToString(_portalSettings.HostSettings["SMTPUsername"]); oEmail.SmtpPassword = Convert.ToString(_portalSettings.HostSettings["SMTPPassword"]); oEmail.SmtpAuthentication = Convert.ToString(_portalSettings.HostSettings["SMTPAuthentication"]); var objThread = new System.Threading.Thread(oEmail.Send); objThread.Start(); }
public void Topics_Move(int PortalId, int ModuleId, int ForumId, int TopicId) { SettingsInfo settings = DataCache.MainSettings(ModuleId); if (settings.URLRewriteEnabled) { try { Data.ForumsDB db = new Data.ForumsDB(); int oldForumId = -1; oldForumId = db.Forum_GetByTopicId(TopicId); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(oldForumId, -1, false); if (! (string.IsNullOrEmpty(fi.PrefixURL))) { Data.Common dbC = new Data.Common(); string sURL = dbC.GetUrl(ModuleId, fi.ForumGroupId, oldForumId, TopicId, -1, -1); if (! (string.IsNullOrEmpty(sURL))) { dbC.ArchiveURL(PortalId, fi.ForumGroupId, ForumId, TopicId, sURL); } } } catch (Exception ex) { } } DataProvider.Instance().Topics_Move(PortalId, ModuleId, ForumId, TopicId); }
private void LoadForum(int forumId) { var fc = new ForumController(); var fi = fc.Forums_Get(forumId, -1, false, false); if (fi == null) return; var newForum = fc.GetForum(PortalId, ModuleId, forumId, true); ctlSecurityGrid = LoadControl("~/DesktopModules/activeforums/controls/admin_securitygrid.ascx") as Controls.admin_securitygrid; if(ctlSecurityGrid != null) { ctlSecurityGrid.Perms = newForum.Security; ctlSecurityGrid.PermissionsId = newForum.PermissionsId; ctlSecurityGrid.ModuleConfiguration = ModuleConfiguration; ctlSecurityGrid.ReadOnly = newForum.InheritSecurity; plhGrid.Controls.Clear(); plhGrid.Controls.Add(ctlSecurityGrid); } txtForumName.Text = fi.ForumName; txtForumDesc.Text = fi.ForumDesc; chkActive.Checked = fi.Active; chkHidden.Checked = fi.Hidden; hidForumId.Value = fi.ForumID.ToString(); txtPrefixURL.Text = fi.PrefixURL; var groupValue = (fi.ParentForumId > 0) ? "FORUM" + fi.ParentForumId : "GROUP" + fi.ForumGroupId; Utilities.SelectListItemByValue(drpGroups, groupValue); if (fi.ForumSettingsKey == "G:" + fi.ForumGroupId) { chkInheritGroup.Checked = true; trTemplates.Attributes.Add("style", "display:none;"); } Utilities.SelectListItemByValue(drpTopicsTemplate, fi.TopicsTemplateId); Utilities.SelectListItemByValue(drpTopicTemplate, fi.TopicTemplateId); Utilities.SelectListItemByValue(drpTopicForm, fi.TopicFormId); Utilities.SelectListItemByValue(drpReplyForm, fi.ReplyFormId); //Utilities.SelectListItemByValue(drpQuickReplyForm, fi.QuickReplyFormId); Utilities.SelectListItemByValue(drpProfileDisplay, fi.ProfileTemplateId); Utilities.SelectListItemByValue(drpModApprovedTemplateId, fi.ModApproveTemplateId); Utilities.SelectListItemByValue(drpModRejectTemplateId, fi.ModRejectTemplateId); Utilities.SelectListItemByValue(drpModDeleteTemplateId, fi.ModDeleteTemplateId); Utilities.SelectListItemByValue(drpModMoveTemplateId, fi.ModMoveTemplateId); Utilities.SelectListItemByValue(drpModNotifyTemplateId, fi.ModNotifyTemplateId); Utilities.SelectListItemByValue(drpDefaultTrust, fi.DefaultTrustValue); txtAutoTrustLevel.Text = fi.AutoTrustLevel.ToString(); txtEmailAddress.Text = fi.EmailAddress; txtCreatePostCount.Text = fi.CreatePostCount.ToString(); txtReplyPostCount.Text = fi.ReplyPostCount.ToString(); rdFilterOn.Checked = fi.UseFilter; rdFilterOff.Checked = !fi.UseFilter; rdPostIconOn.Checked = fi.AllowPostIcon; rdPostIconOff.Checked = !fi.AllowPostIcon; rdEmotOn.Checked = fi.AllowEmoticons; rdEmotOff.Checked = !fi.AllowEmoticons; rdScriptsOn.Checked = fi.AllowScript; rdScriptsOff.Checked = !fi.AllowScript; rdIndexOn.Checked = fi.IndexContent; rdIndexOff.Checked = !fi.IndexContent; rdRSSOn.Checked = fi.AllowRSS; rdRSSOff.Checked = !fi.AllowRSS; rdAttachOn.Checked = fi.AllowAttach; rdAttachOff.Checked = !fi.AllowAttach; rdHTMLOn.Checked = fi.AllowHTML; rdHTMLOff.Checked = !fi.AllowHTML; if (fi.AllowHTML) cfgHTML.Attributes.Remove("style"); else cfgHTML.Attributes.Add("style", "display:none;"); rdModOn.Checked = fi.IsModerated; rdModOff.Checked = !fi.IsModerated; if (fi.IsModerated) cfgMod.Attributes.Remove("style"); else cfgMod.Attributes.Add("style", "display:none;"); rdAutoSubOn.Checked = fi.AutoSubscribeEnabled; rdAutoSubOff.Checked = !fi.AutoSubscribeEnabled; if (fi.AutoSubscribeEnabled) cfgAutoSub.Attributes.Remove("style"); else cfgAutoSub.Attributes.Add("style", "display:none;"); chkTopicsOnly.Checked = fi.AutoSubscribeNewTopicsOnly; Utilities.SelectListItemByValue(drpEditorTypes, fi.EditorType); if (Convert.ToInt32(fi.EditorType).ToString() != "1") // Active Editor should not be used anymore { txtEditorToolBar.Enabled = false; drpEditorStyle.Enabled = false; } Utilities.SelectListItemByValue(drpEditorStyle, fi.EditorStyle); Utilities.SelectListItemByValue(drpPermittedRoles, (int)fi.EditorPermittedUsers); txtEditorHeight.Text = (fi.EditorHeight == string.Empty) ? "400" : fi.EditorHeight; txtEditorWidth.Text = (fi.EditorWidth == string.Empty) ? "99%" : fi.EditorWidth; txtEditorToolBar.Text = (fi.EditorToolBar == string.Empty) ? "bold,italic,underline|bulletedlist,numberedlist" : fi.EditorToolBar; hidRoles.Value = fi.AutoSubscribeRoles; BindAutoSubRoles(fi.AutoSubscribeRoles); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { UserController uc = new UserController(); User ui = uc.GetUser(PortalSettings.PortalId, -1); ForumController fc = new ForumController(); Forum fi = fc.Forums_Get(Convert.ToInt32(Request.Params["ForumId"]), ui.UserId, true); if (fi != null) { if (Permissions.HasPerm(fi.Security.Attach, ui.UserRoles)) { if (inpFile.HasFile) { string sFile = string.Empty; string sExt = string.Empty; int maxImgHeight = fi.AttachMaxHeight; int maxImgWidth = fi.AttachMaxWidth; string contentType = inpFile.PostedFile.ContentType; sFile = Path.GetFileName(inpFile.PostedFile.FileName).Replace(" ", "_"); sExt = Path.GetExtension(sFile); if (sFile.Length >= 250) { sFile = sFile.Replace(sExt, string.Empty); sFile = sFile.Substring(0, (250 - sExt.Length)); sFile = sFile + sExt; } sExt = sExt.Replace(".", string.Empty); if (!(fi.AttachTypeAllowed.ToString().ToLower().Contains(sExt.ToLower()))) { Response.Write("<script type=\"text/javascript\">window.top.af_setMessage('" + Utilities.GetSharedResource("[RESX:Error:BlockedFile]") + "');</script>"); return; } if (fi.AttachMaxSize > 0) { if ((inpFile.PostedFile.ContentLength / 1024.0) > fi.AttachMaxSize) { Response.Write("<script type=\"text/javascript\">window.top.af_setMessage('" + string.Format(Utilities.GetSharedResource("[RESX:Error:FileTooLarge]"), fi.AttachMaxSize) + "');</script>"); return; } } Stream inpStream = inpFile.PostedFile.InputStream; MemoryStream imgStream = new MemoryStream(); bool useMemStream = false; bool allowDownload = true; bool displayInline = false; if (sExt.ToLower() == "jpg" || sExt.ToLower() == "gif" || sExt.ToLower() == "bmp" || sExt.ToLower() == "png" || sExt.ToLower() == "jpeg") { useMemStream = true; imgStream = (MemoryStream)(Images.CreateImageForDB(inpStream, maxImgHeight, maxImgWidth)); contentType = "image/x-png"; allowDownload = false; displayInline = true; } Data.AttachController ac = new Data.AttachController(); AttachInfo ai = new AttachInfo(); ai.ContentId = -1; ai.UserID = ui.UserId; ai.ContentType = contentType; ai.DisplayInline = displayInline; ai.AllowDownload = allowDownload; ai.ParentAttachId = 0; if (fi.AttachStore == AttachStores.DATABASE) { if (useMemStream) { ai.FileSize = Convert.ToInt32(imgStream.Length); ai.FileData = imgStream.ToArray(); } else { byte[] byteData = new byte[Convert.ToInt32(inpStream.Length - 1) + 1]; inpStream.Read(byteData, 0, Convert.ToInt32(inpStream.Length)); ai.FileSize = Convert.ToInt32(inpStream.Length); ai.FileData = byteData; } ai.Filename = sFile; } else { if (useMemStream) { ai.FileSize = Convert.ToInt32(imgStream.Length); ai.Filename = SaveToFile(imgStream, sFile); } else { byte[] byteData = new byte[Convert.ToInt32(inpStream.Length) + 1]; inpStream.Read(byteData, 0, Convert.ToInt32(inpStream.Length)); ai.FileSize = Convert.ToInt32(inpStream.Length); ai.Filename = SaveToFile(inpFile, sFile); } } int attachId = ac.Attach_Save(ai); Response.Write("<script type=\"text/javascript\">window.top.af_isUploaded(" + attachId.ToString() + ");</script>"); } } else { inpFile.Visible = false; } } else { inpFile.Visible = false; } } catch (Exception ex) { Response.Write("<script type=\"text/javascript\">window.top.af_setMessage('" + ex.Message + "');</script>"); } }