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); }
private void BindForums() { ForumController fc = new ForumController(); dtForums = fc.GetForumView(PortalId, MOID, UserId, UserInfo.IsSuperUser, UserForumsList); drpForums.Items.Clear(); drpForums.Items.Insert(0, new ListItem(string.Empty, string.Empty)); int i = 0; int n = 1; int tmpGroupCount = 0; int tmpForumCount = 0; string tmpGroupKey = string.Empty; string tmpForumKey = string.Empty; foreach (DataRow dr in dtForums.Rows) { bool bView = Permissions.HasPerm(dr["CanView"].ToString(), ForumUser.UserRoles); string GroupName = Convert.ToString(dr["GroupName"]); int GroupId = Convert.ToInt32(dr["ForumGroupId"]); string GroupKey = GroupName + GroupId.ToString(); string ForumName = Convert.ToString(dr["ForumName"]); int ForumId = Convert.ToInt32(dr["ForumId"]); string ForumKey = ForumName + ForumId.ToString(); int ParentForumId = Convert.ToInt32(dr["ParentForumId"]); //TODO - Need to add support for Group Permissions and GroupHidden if (tmpGroupKey != GroupKey) { drpForums.Items.Insert(n, new ListItem(GroupName, "GROUPJUMP:" + GroupId)); n += 1; tmpGroupKey = GroupKey; } if (bView) { if (ParentForumId == 0) { drpForums.Items.Insert(n, new ListItem("--" + dr["ForumName"].ToString(), "FORUMJUMP:" + dr["ForumID"].ToString())); n += 1; n = GetSubForums(n, Convert.ToInt32(dr["ForumId"])); } } } if (GetViewType != null) { string sView = GetViewType; if (sView == "TOPICS" || sView == "TOPIC") { string sForum = "FORUMJUMP:" + ForumId; drpForums.SelectedIndex = drpForums.Items.IndexOf(drpForums.Items.FindByValue(sForum)); } } }
private void BindForums() { ForumController fc = new ForumController(); dtForums = fc.GetForumView(PortalId, MOID, UserId, UserInfo.IsSuperUser, UserForumsList); drpForums.Items.Clear(); drpForums.Items.Insert(0, new ListItem(string.Empty, string.Empty)); int i = 0; int n = 1; int tmpGroupCount = 0; int tmpForumCount = 0; string tmpGroupKey = string.Empty; string tmpForumKey = string.Empty; foreach (DataRow dr in dtForums.Rows) { bool bView = Permissions.HasPerm(dr["CanView"].ToString(), ForumUser.UserRoles); string GroupName = Convert.ToString(dr["GroupName"]); int GroupId = Convert.ToInt32(dr["ForumGroupId"]); string GroupKey = GroupName + GroupId.ToString(); string ForumName = Convert.ToString(dr["ForumName"]); if (ForumName.Length > 30) { ForumName = ForumName.Substring(0, 30) + "..."; } int ForumId = Convert.ToInt32(dr["ForumId"]); string ForumKey = ForumName + ForumId.ToString(); int ParentForumId = Convert.ToInt32(dr["ParentForumId"]); //TODO - Need to add support for Group Permissions and GroupHidden if (tmpGroupKey != GroupKey) { drpForums.Items.Insert(n, new ListItem(GroupName, "GROUPJUMP:" + GroupId)); n += 1; tmpGroupKey = GroupKey; } if (bView) { if (ParentForumId == 0) { drpForums.Items.Insert(n, new ListItem("--" + ForumName, "FORUMJUMP:" + dr["ForumID"].ToString())); n += 1; n = GetSubForums(n, Convert.ToInt32(dr["ForumId"])); } } } if (GetViewType != null) { string sView = GetViewType; if (sView == "TOPICS" || sView == "TOPIC") { string sForum = "FORUMJUMP:" + ForumId; drpForums.SelectedIndex = drpForums.Items.IndexOf(drpForums.Items.FindByValue(sForum)); } } }
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 HttpResponseMessage GetForumsList() { var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID); var fc = new ForumController(); var forumIds = fc.GetForumsForUser(forumUser.UserRoles, portalSettings.PortalId, ActiveModule.ModuleID, "CanView", true); DataTable ForumTable = fc.GetForumView(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID, userInfo.IsSuperUser, forumIds); Dictionary <string, string> rows = new Dictionary <string, string>();; foreach (DataRow dr in ForumTable.Rows) { rows.Add(dr["ForumId"].ToString(), dr["ForumName"].ToString()); } return(Request.CreateResponse(HttpStatusCode.OK, rows.ToJson())); }
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 User GetUser(int SiteId, int ModuleId, string userName) { User u = GetDNNUser(SiteId, ModuleId, userName); if (u != null) { u = FillProfile(SiteId, ModuleId, u); ForumController fc = new ForumController(); string fs = fc.GetForumsForUser(u.UserRoles, SiteId, ModuleId, "CanApprove"); if (!(string.IsNullOrEmpty(fs)) || u.IsSuperUser || u.IsAdmin) { u.Profile.IsMod = true; } else { u.Profile.IsMod = false; } } return(u); }
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" })); }
private void SetPermissions(int fId) { ForumController fc = new ForumController(); Forum f = fc.GetForum(PortalId, ModuleId, fId); bModDelete = false; bModApprove = false; bModEdit = false; bModMove = false; bCanMod = false; if (f != null) { bModDelete = Permissions.HasPerm(f.Security.ModDelete, ForumUser.UserRoles); bModApprove = Permissions.HasPerm(f.Security.ModApprove, ForumUser.UserRoles); bModMove = Permissions.HasPerm(f.Security.ModMove, ForumUser.UserRoles); bModEdit = Permissions.HasPerm(f.Security.ModEdit, ForumUser.UserRoles); if (bModDelete || bModApprove || bModMove || bModEdit) { bCanMod = true; } } }
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 User DNNGetCurrentUser(int SiteId, int ModuleId) { PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings(); User u = new User(); DotNetNuke.Entities.Users.UserInfo cu = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo(); u = LoadUser(cu); u = FillProfile(SiteId, ModuleId, u); ForumController fc = new ForumController(); string fs = fc.GetForumsForUser(u.UserRoles, SiteId, ModuleId, "CanApprove"); if (!(string.IsNullOrEmpty(fs))) { u.Profile.IsMod = true; } else { u.Profile.IsMod = false; } return(u); }
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); }
private void BindPosts() { _pageSize = (UserId > 0) ? UserDefaultPageSize : MainSettings.PageSize; if (_pageSize < 5) { _pageSize = 10; } _rowIndex = (PageId - 1) * _pageSize; // If we don't have a search string, tag or user id, there is nothing we can do so exit if (SearchText == string.Empty && Tags == string.Empty && AuthorUsername == String.Empty && AuthorUserId <= 0) { return; } // Build the list of forums to search // An intersection of the forums allows vs forums requested. var parseId = 0; var fc = new ForumController(); var sForumsAllowed = fc.GetForumsForUser(ForumUser.UserRoles, PortalId, ModuleId, "CanRead", true); // Make sure and pass strict = true here var forumsAllowed = sForumsAllowed.Split(new [] { ':', ';' }).Where(f => int.TryParse(f, out parseId)).Select(f => parseId).ToList(); var forumsRequested = Forums.Split(new[] { ':', ';' }).Where(f => int.TryParse(f, out parseId)).Select(f => parseId).ToList(); var forumsToSearch = string.Empty; // If forums requested is empty or contains and entry less than or equal to zero, return all available forums if (!forumsRequested.Any() || forumsRequested.Any(o => o <= 0)) { forumsToSearch = forumsAllowed.Aggregate(forumsToSearch, (current, f) => current + ((current.Length == 0 ? string.Empty : ":") + f)); } else { forumsToSearch = forumsRequested.Where(forumsAllowed.Contains).Aggregate(forumsToSearch, (current, f) => current + ((current.Length == 0 ? String.Empty : ":") + f)); } const int maxCacheHours = 1; var ds = DataProvider.Instance().Search(PortalId, ModuleId, UserId, SearchId, _rowIndex, _pageSize, SearchText, SearchType, SearchColumns, SearchDays, AuthorUserId, AuthorUsername, forumsToSearch, Tags, ResultType, Sort, maxCacheHours, MainSettings.FullText); var dtSummary = (ds != null) ? ds.Tables[0] : null; _searchId = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][0]) : 0; _rowCount = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][1]) : 0; _searchDuration = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][2]) : 0; _searchAge = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][3]) : 0; var totalSeconds = new TimeSpan(0, 0, 0, 0, _searchDuration.Value).TotalSeconds; var ageInMinutes = new TimeSpan(0, 0, 0, 0, _searchAge.Value).TotalMinutes; litSearchDuration.Text = string.Format(GetSharedResource("[RESX:SearchDuration]"), totalSeconds); if (ageInMinutes > 0.25) { litSearchAge.Text = string.Format(GetSharedResource("[RESX:SearchAge]"), ageInMinutes); } _parameters = null; // We reset this so we make sure to get an updated version var dtResults = (ds != null) ? ds.Tables[1] : null; if (dtResults != null && dtResults.Rows.Count > 0) { litRecordCount.Text = string.Format(GetSharedResource("[RESX:SearchRecords]"), _rowIndex + 1, _rowIndex + dtResults.Rows.Count, _rowCount); var rptResults = ResultType == 0 ? rptTopics : rptPosts; pnlMessage.Visible = false; try { rptResults.Visible = true; rptResults.DataSource = dtResults; rptResults.DataBind(); BuildPager(PagerTop); BuildPager(PagerBottom); } catch (Exception ex) { litMessage.Text = ex.Message; pnlMessage.Visible = true; rptResults.Visible = false; } } else { litMessage.Text = GetSharedResource("[RESX:SearchNoResults]"); pnlMessage.Visible = true; } }
private void BindPosts(string sort = "ASC") { _pageSize = MainSettings.PageSize; if (UserId > 0) _pageSize = UserDefaultPageSize; if (_pageSize < 5) _pageSize = 10; _rowIndex = (PageId == 1) ? 0 : ((PageId * _pageSize) - _pageSize); var db = new Data.Common(); var fc = new ForumController(); var forumIds = fc.GetForumsForUser(ForumUser.UserRoles, PortalId, ModuleId, "CanRead"); var sCrumb = "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ViewType + "=grid", "afgt=xxx" }) + "\">yyyy</a>"; sCrumb = sCrumb.Replace("xxx", "{0}").Replace("yyyy", "{1}"); if (Request.Params["afgt"] != null) { var gview = Utilities.XSSFilter(Request.Params["afgt"]).ToLowerInvariant(); switch (gview) { case "notread": if (UserId != -1) { lblHeader.Text = GetSharedResource("[RESX:NotRead]"); _dtResults = db.UI_NotReadView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) { _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); btnMarkRead.Visible = true; btnMarkRead.InnerText = GetSharedResource("[RESX:MarkAllRead]"); } } else Response.Redirect(NavigateUrl(TabId), true); break; case "unanswered": lblHeader.Text = GetSharedResource("[RESX:Unanswered]"); _dtResults = db.UI_UnansweredView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); break; case "tags": var tagId = -1; if (Request.QueryString["aftg"] != null && SimulateIsNumeric.IsNumeric(Request.QueryString["aftg"])) tagId = int.Parse(Request.QueryString["aftg"]); lblHeader.Text = GetSharedResource("[RESX:Tags]"); _dtResults = db.UI_TagsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds, tagId).Tables[0]; if (_dtResults.Rows.Count > 0) _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); break; case "mytopics": if (UserId != -1) { lblHeader.Text = GetSharedResource("[RESX:MyTopics]"); _dtResults = db.UI_MyTopicsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); } else Response.Redirect(NavigateUrl(TabId), true); break; case "activetopics": lblHeader.Text = GetSharedResource("[RESX:ActiveTopics]"); /* if (UserLastAccess != Utilities.NullDate()) { timeFrame = Convert.ToInt32(SimulateDateDiff.DateDiff(SimulateDateDiff.DateInterval.Minute, UserLastAccess, DateTime.Now)); drpTimeFrame.Items.Insert(0, new ListItem(GetDate(UserLastAccess), "~" + timeFrame.ToString())); } */ var timeFrame = Utilities.SafeConvertInt(Request.Params["ts"], 1440); if (timeFrame < 15 | timeFrame > 80640) timeFrame = 1440; drpTimeFrame.Visible = true; drpTimeFrame.SelectedIndex = drpTimeFrame.Items.IndexOf(drpTimeFrame.Items.FindByValue(timeFrame.ToString())); _dtResults = db.UI_ActiveView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, timeFrame, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) _rowCount = Convert.ToInt32(_dtResults.Rows[0]["RecordCount"]); break; default: Response.Redirect(NavigateUrl(TabId), true); break; } sCrumb = string.Format(sCrumb, gview, lblHeader.Text); if (MainSettings.UseSkinBreadCrumb) Environment.UpdateBreadCrumb(Page.Controls, sCrumb); var tempVar = BasePage; Environment.UpdateMeta(ref tempVar, "[VALUE] - " + lblHeader.Text, "[VALUE]", "[VALUE]"); } if (_dtResults != null && _dtResults.Rows.Count > 0) { litRecordCount.Text = string.Format(GetSharedResource("[RESX:SearchRecords]"), _rowIndex + 1, _rowIndex + _dtResults.Rows.Count, _rowCount); pnlMessage.Visible = false; try { rptTopics.Visible = true; rptTopics.DataSource = _dtResults; rptTopics.DataBind(); BuildPager(PagerTop); BuildPager(PagerBottom); } catch (Exception ex) { litMessage.Text = ex.Message; pnlMessage.Visible = true; rptTopics.Visible = false; } } else { litMessage.Text = GetSharedResource("[RESX:SearchNoResults]"); pnlMessage.Visible = true; } }
public User GetUser(int SiteId, int ModuleId, string userName) { User u = GetDNNUser(SiteId, ModuleId, userName); if (u != null) { u = FillProfile(SiteId, ModuleId, u); ForumController fc = new ForumController(); string fs = fc.GetForumsForUser(u.UserRoles, SiteId, ModuleId, "CanApprove"); if (! (string.IsNullOrEmpty(fs)) || u.IsSuperUser || u.IsAdmin) { u.Profile.IsMod = true; } else { u.Profile.IsMod = false; } } return u; }
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(); }
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(); }
private void GetControl(string view, string options) { try { if (!Page.IsPostBack) { plhLoader.Controls.Clear(); } ForumBase ctl = null; if (view.ToUpperInvariant() == "FORUMVIEW") { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.ForumView()); } else if (view.ToUpperInvariant() == "ADVANCED") { ctl = (ForumBase)(LoadControl("~/desktopmodules/activeforums/advanced.ascx")); } else if ((view.ToUpperInvariant() == Views.Topics.ToUpperInvariant()) || (view.ToUpperInvariant() == "topics".ToUpperInvariant())) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.TopicsView()); } else if ((view.ToUpperInvariant() == Views.Topic.ToUpperInvariant()) || (view.ToUpperInvariant() == "topic".ToUpperInvariant())) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.TopicView()); } else if (view.ToUpperInvariant() == "USERSETTINGS".ToUpperInvariant()) { string ctlPath = string.Empty; ctlPath = "~/DesktopModules/ActiveForums/controls/af_profile.ascx"; if (!(System.IO.File.Exists(Server.MapPath(ctlPath)))) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.ForumView()); } else { ctl = (ForumBase)(LoadControl(ctlPath)); } } else { // this is where af_post.ascx is used string ctlPath = string.Empty; ctlPath = "~/DesktopModules/ActiveForums/controls/af_" + view + ".ascx"; if (!(System.IO.File.Exists(Server.MapPath(ctlPath)))) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.ForumView()); } else { ctl = (ForumBase)(LoadControl(ctlPath)); } } if (ForumId > 0 & ForumInfo != null) { ctl.ForumInfo = ForumInfo; } ctl.ID = view; ctl.ForumId = ForumId; ctl.ForumModuleId = ForumModuleId; if (ForumTabId == -1) { ForumTabId = TabId; } ctl.ForumTabId = ForumTabId; ctl.ForumGroupId = ForumGroupId; ctl.DefaultForumViewTemplateId = DefaultForumViewTemplateId; ctl.DefaultTopicsViewTemplateId = DefaultTopicsViewTemplateId; ctl.DefaultTopicViewTemplateId = DefaultTopicViewTemplateId; ctl.UseTemplatePath = UseTemplatePath; ctl.TemplatePath = TemplatePath; ctl.ParentForumId = ParentForumId; if (string.IsNullOrEmpty(ForumIds)) { ForumIds = UserForumsList; } if (SocialGroupId > 0) { ForumController fc = new ForumController(); ForumIds = fc.GetForumIdsBySocialGroup(PortalId, SocialGroupId); if (string.IsNullOrEmpty(ForumIds)) { RoleController rc = new RoleController(); RoleInfo role = rc.GetRole(SocialGroupId, PortalId); //Create new forum bool isPrivate = false; if (!role.IsPublic) { isPrivate = true; } Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController(); Hashtable htSettings = objModules.GetTabModuleSettings(TabModuleId); fc.CreateGroupForum(PortalId, ModuleId, SocialGroupId, Convert.ToInt32(htSettings["ForumGroupTemplate"].ToString()), role.RoleName + " Discussions", role.Description, isPrivate, htSettings["ForumConfig"].ToString()); ForumIds = fc.GetForumIdsBySocialGroup(PortalId, SocialGroupId); } } ctl.ForumIds = ForumIds; ctl.SocialGroupId = SocialGroupId; //ctl.PostID = PostID ctl.ModuleConfiguration = this.ModuleConfiguration; if (!(options == string.Empty)) { ctl.Params = options; } ControlsConfig cc = new ControlsConfig(); cc.AppPath = Page.ResolveUrl("~/DesktopModules/ActiveForums/"); cc.ThemePath = Page.ResolveUrl("~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme + "/"); cc.TemplatePath = cc.ThemePath + "templates/"; cc.SiteId = PortalId; cc.PageId = TabId; cc.InstanceId = ModuleId; cc.User = ForumUser; string authorizedViewRoles = ModuleConfiguration.InheritViewPermissions ? TabPermissionController.GetTabPermissions(TabId, PortalId).ToString("VIEW") : ModuleConfiguration.ModulePermissions.ToString("VIEW"); cc.DefaultViewRoles = Permissions.GetRoleIds(authorizedViewRoles.Split(';'), PortalId); cc.AdminRoles = Permissions.GetRoleIds(this.ModuleConfiguration.ModulePermissions.ToString("EDIT").Split(';'), PortalId); cc.ProfileLink = ""; //GetProfileLink() cc.MembersLink = ""; // GetMembersLink() this.ControlConfig = cc; ctl.ControlConfig = cc; LinkControls(ctl.Controls); if (!(plhLoader.Controls.Contains(ctl))) { plhLoader.Controls.Add(ctl); } string sOut = null; sOut = System.Environment.NewLine + "<!-- © 2004 - 2013 DNN Corp., All Rights Reserved -->" + System.Environment.NewLine; sOut += "<!-- Active Forums 5.0 -->" + System.Environment.NewLine; Literal lit = new Literal(); lit.Text = sOut; plhLoader.Controls.Add(lit); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex); } }
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); }
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 BindPosts() { _pageSize = (UserId > 0) ? UserDefaultPageSize : MainSettings.PageSize; if (_pageSize < 5) _pageSize = 10; _rowIndex = (PageId - 1) * _pageSize; // If we don't have a search string, tag or user id, there is nothing we can do so exit if (SearchText == string.Empty && Tags == string.Empty && AuthorUsername == String.Empty && AuthorUserId <= 0) return; // Build the list of forums to search // An intersection of the forums allows vs forums requested. var parseId = 0; var fc = new ForumController(); var sForumsAllowed = fc.GetForumsForUser(ForumUser.UserRoles, PortalId, ModuleId, "CanRead", true); // Make sure and pass strict = true here var forumsAllowed = sForumsAllowed.Split(new [] {':',';'}).Where(f => int.TryParse(f, out parseId)).Select(f => parseId).ToList(); var forumsRequested = Forums.Split(new[] { ':', ';' }).Where(f => int.TryParse(f, out parseId)).Select(f => parseId).ToList(); var forumsToSearch = string.Empty; // If forums requested is empty or contains and entry less than or equal to zero, return all available forums if(!forumsRequested.Any() || forumsRequested.Any(o => o <= 0)) forumsToSearch = forumsAllowed.Aggregate(forumsToSearch, (current, f) => current + ((current.Length == 0 ? string.Empty : ":") + f)); else forumsToSearch = forumsRequested.Where(forumsAllowed.Contains).Aggregate(forumsToSearch, (current, f) => current + ((current.Length == 0 ? String.Empty : ":") + f)); const int maxCacheHours = 1; var ds = DataProvider.Instance().Search(PortalId, ModuleId, UserId, SearchId, _rowIndex, _pageSize, SearchText, SearchType, SearchColumns, SearchDays, AuthorUserId, AuthorUsername, forumsToSearch, Tags, ResultType, Sort, maxCacheHours, MainSettings.FullText); var dtSummary = (ds != null) ? ds.Tables[0] : null; _searchId = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][0]) : 0; _rowCount = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][1]) : 0; _searchDuration = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][2]) : 0; _searchAge = (dtSummary != null) ? Convert.ToInt32(dtSummary.Rows[0][3]) : 0; var totalSeconds = new TimeSpan(0, 0, 0, 0, _searchDuration.Value).TotalSeconds; var ageInMinutes = new TimeSpan(0, 0, 0, 0, _searchAge.Value).TotalMinutes; litSearchDuration.Text = string.Format(GetSharedResource("[RESX:SearchDuration]"), totalSeconds); if(ageInMinutes > 0.25) litSearchAge.Text = string.Format(GetSharedResource("[RESX:SearchAge]"), ageInMinutes); _parameters = null; // We reset this so we make sure to get an updated version var dtResults = (ds != null) ? ds.Tables[1] : null; if (dtResults != null && dtResults.Rows.Count > 0) { litRecordCount.Text = string.Format(GetSharedResource("[RESX:SearchRecords]"), _rowIndex + 1, _rowIndex + dtResults.Rows.Count, _rowCount); var rptResults = ResultType == 0 ? rptTopics : rptPosts; pnlMessage.Visible = false; try { rptResults.Visible = true; rptResults.DataSource = dtResults; rptResults.DataBind(); BuildPager(PagerTop); BuildPager(PagerBottom); } catch (Exception ex) { litMessage.Text = ex.Message; pnlMessage.Visible = true; rptResults.Visible = false; } } else { litMessage.Text = GetSharedResource("[RESX:SearchNoResults]"); pnlMessage.Visible = true; } }
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 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 BindPosts(string sort = "ASC") { _pageSize = MainSettings.PageSize; if (UserId > 0) { _pageSize = UserDefaultPageSize; } if (_pageSize < 5) { _pageSize = 10; } _rowIndex = (PageId == 1) ? 0 : ((PageId * _pageSize) - _pageSize); var db = new Data.Common(); var fc = new ForumController(); var forumIds = fc.GetForumsForUser(ForumUser.UserRoles, PortalId, ModuleId, "CanRead"); var sCrumb = "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ViewType + "=grid", "afgt=xxx" }) + "\">yyyy</a>"; sCrumb = sCrumb.Replace("xxx", "{0}").Replace("yyyy", "{1}"); if (Request.Params["afgt"] != null) { var gview = Utilities.XSSFilter(Request.Params["afgt"]).ToLowerInvariant(); switch (gview) { case "notread": if (UserId != -1) { lblHeader.Text = GetSharedResource("[RESX:NotRead]"); _dtResults = db.UI_NotReadView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) { _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); btnMarkRead.Visible = true; btnMarkRead.InnerText = GetSharedResource("[RESX:MarkAllRead]"); } } else { Response.Redirect(NavigateUrl(TabId), true); } break; case "unanswered": lblHeader.Text = GetSharedResource("[RESX:Unanswered]"); _dtResults = db.UI_UnansweredView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) { _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); } break; case "tags": var tagId = -1; if (Request.QueryString["aftg"] != null && SimulateIsNumeric.IsNumeric(Request.QueryString["aftg"])) { tagId = int.Parse(Request.QueryString["aftg"]); } lblHeader.Text = GetSharedResource("[RESX:Tags]"); _dtResults = db.UI_TagsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds, tagId).Tables[0]; if (_dtResults.Rows.Count > 0) { _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); } break; case "mytopics": if (UserId != -1) { lblHeader.Text = GetSharedResource("[RESX:MyTopics]"); _dtResults = db.UI_MyTopicsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) { _rowCount = _dtResults.Rows[0].GetInt("RecordCount"); } } else { Response.Redirect(NavigateUrl(TabId), true); } break; case "activetopics": lblHeader.Text = GetSharedResource("[RESX:ActiveTopics]"); /* * if (UserLastAccess != Utilities.NullDate()) * { * timeFrame = Convert.ToInt32(SimulateDateDiff.DateDiff(SimulateDateDiff.DateInterval.Minute, UserLastAccess, DateTime.Now)); * drpTimeFrame.Items.Insert(0, new ListItem(GetDate(UserLastAccess), "~" + timeFrame.ToString())); * } */ var timeFrame = Utilities.SafeConvertInt(Request.Params["ts"], 1440); if (timeFrame < 15 | timeFrame > 80640) { timeFrame = 1440; } drpTimeFrame.Visible = true; drpTimeFrame.SelectedIndex = drpTimeFrame.Items.IndexOf(drpTimeFrame.Items.FindByValue(timeFrame.ToString())); _dtResults = db.UI_ActiveView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, timeFrame, forumIds).Tables[0]; if (_dtResults.Rows.Count > 0) { _rowCount = Convert.ToInt32(_dtResults.Rows[0]["RecordCount"]); } break; default: Response.Redirect(NavigateUrl(TabId), true); break; } sCrumb = string.Format(sCrumb, gview, lblHeader.Text); if (MainSettings.UseSkinBreadCrumb) { Environment.UpdateBreadCrumb(Page.Controls, sCrumb); } var tempVar = BasePage; Environment.UpdateMeta(ref tempVar, "[VALUE] - " + lblHeader.Text, "[VALUE]", "[VALUE]"); } if (_dtResults != null && _dtResults.Rows.Count > 0) { litRecordCount.Text = string.Format(GetSharedResource("[RESX:SearchRecords]"), _rowIndex + 1, _rowIndex + _dtResults.Rows.Count, _rowCount); pnlMessage.Visible = false; try { rptTopics.Visible = true; rptTopics.DataSource = _dtResults; rptTopics.DataBind(); BuildPager(PagerTop); BuildPager(PagerBottom); } catch (Exception ex) { litMessage.Text = ex.Message; pnlMessage.Visible = true; rptTopics.Visible = false; } } else { litMessage.Text = GetSharedResource("[RESX:SearchNoResults]"); pnlMessage.Visible = true; } }
private void LoadDefaultForums(int PortalId, int ModuleId) { var xDoc = new System.Xml.XmlDocument(); xDoc.Load(sPath); if (xDoc != null) { System.Xml.XmlNode xRoot = xDoc.DocumentElement; System.Xml.XmlNodeList xNodeList = xRoot.SelectNodes("//defaultforums/groups/group"); if (xNodeList.Count > 0) { int i; for (i = 0; i < xNodeList.Count; i++) { var gi = new ForumGroupInfo { ModuleId = ModuleId, ForumGroupId = -1, GroupName = xNodeList[i].Attributes["groupname"].Value, Active = xNodeList[i].Attributes["active"].Value == "1", Hidden = xNodeList[i].Attributes["hidden"].Value == "1", SortOrder = i, GroupSettingsKey = "", PermissionsId = -1 }; var gc = new ForumGroupController(); int groupId; groupId = gc.Groups_Save(PortalId, gi, true); gi = gc.GetForumGroup(ModuleId, groupId); string sKey = "G:" + groupId.ToString(); string sAllowHTML = "false"; if (xNodeList[i].Attributes["allowhtml"] != null) { sAllowHTML = xNodeList[i].Attributes["allowhtml"].Value; } Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicsTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EmailAddress, string.Empty); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.UseFilter, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowPostIcon, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowEmoticons, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowScript, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.IndexContent, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowRSS, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowAttach, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachCount, "3"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxSize, "1000"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachTypeAllowed, "txt,tiff,pdf,xls,xlsx,doc,docx,ppt,pptx"); //Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachStore, "FILESYSTEM"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxHeight, "450"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxWidth, "450"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachAllowBrowseSite, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.MaxAttachHeight, "800"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.MaxAttachWidth, "800"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachInsertAllowed, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ConvertingToJpegAllowed, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowHTML, sAllowHTML); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorType, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorHeight, "350"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorWidth, "99%"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorToolbar, "bold,italic,underline,quote"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorStyle, "2"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicFormId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ReplyFormId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.QuickReplyFormId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ProfileTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.IsModerated, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.DefaultTrustLevel, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AutoTrustLevel, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModApproveTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModRejectTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModMoveTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModDeleteTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModNotifyTemplateId, "0"); if (groupId != -1) { if (xNodeList[i].HasChildNodes) { System.Xml.XmlNodeList cNodes = xNodeList[i].ChildNodes; for (int c = 0; c < cNodes.Count; c++) { var fi = new Forum(); var fc = new ForumController(); fi.ForumID = -1; fi.ModuleId = ModuleId; fi.ForumGroupId = groupId; fi.ParentForumId = 0; fi.ForumName = cNodes[c].Attributes["forumname"].Value; fi.ForumDesc = cNodes[c].Attributes["forumdesc"].Value; fi.ForumSecurityKey = "G:" + groupId.ToString(); fi.ForumSettingsKey = "G:" + groupId.ToString(); fi.Active = cNodes[c].Attributes["active"].Value == "1"; fi.Hidden = cNodes[c].Attributes["hidden"].Value == "1"; fi.SortOrder = c; fi.PermissionsId = gi.PermissionsId; fc.Forums_Save(PortalId, fi, true, true); } } } } } } }
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 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 GetForumsList() { var portalSettings = PortalSettings; var userInfo = portalSettings.UserInfo; var forumUser = new UserController().GetUser(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID); var fc = new ForumController(); var forumIds = fc.GetForumsForUser(forumUser.UserRoles, portalSettings.PortalId, ActiveModule.ModuleID, "CanView", true); DataTable ForumTable = fc.GetForumView(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID, userInfo.IsSuperUser, forumIds); Dictionary<string, string> rows = new Dictionary<string, string>();; foreach (DataRow dr in ForumTable.Rows) { rows.Add(dr["ForumId"].ToString(),dr["ForumName"].ToString()); } return Request.CreateResponse(HttpStatusCode.OK, rows.ToJson()); }
private void SetPermissions(int fId) { ForumController fc = new ForumController(); Forum f = fc.GetForum(PortalId, ModuleId, fId); bModDelete = false; bModApprove = false; bModEdit = false; bModMove = false; bCanMod = false; if (f != null) { bModDelete = Permissions.HasPerm(f.Security.ModDelete, ForumUser.UserRoles); bModApprove = Permissions.HasPerm(f.Security.ModApprove, ForumUser.UserRoles); bModMove = Permissions.HasPerm(f.Security.ModMove, ForumUser.UserRoles); bModEdit = Permissions.HasPerm(f.Security.ModEdit, ForumUser.UserRoles); if (bModDelete || bModApprove || bModMove || bModEdit) { bCanMod = true; } } }
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(); }
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); }
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 static string ParseEmailTemplate(string template, string templateName, int portalID, int moduleID, int tabID, int forumID, int topicId, int replyId, string comments, Entities.Users.UserInfo user, int userId, int timeZoneOffset) { var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); var ms = DataCache.MainSettings(moduleID); var sOut = template; // If we have a template name, load the template into sOut if (templateName != string.Empty) { if (templateName.Contains("_Subject_")) { templateName = templateName.Replace("_Subject_" + moduleID, string.Empty); var objTemplate = GetTemplateByName(templateName, moduleID, portalID); sOut = objTemplate.Subject; } else { var objTemplate = GetTemplateByName(templateName, moduleID, portalID); sOut = objTemplate.TemplateHTML; } } // Load Subject and body from topic or reply var subject = string.Empty; var body = string.Empty; var dateCreated = Utilities.NullDate(); var authorName = string.Empty; if (topicId > 0 && replyId > 0) { var ri = new ReplyController().Reply_Get(portalID, moduleID, topicId, replyId); if (ri != null) { subject = ri.Content.Subject; body = ri.Content.Body; dateCreated = ri.Content.DateCreated; authorName = ri.Content.AuthorName; } } else { var ti = new TopicsController().Topics_Get(portalID, moduleID, topicId); if (ti != null) { subject = ti.Content.Subject; body = ti.Content.Body; dateCreated = ti.Content.DateCreated; authorName = ti.Content.AuthorName; } } body = Utilities.ManageImagePath(body, Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request))); // load the forum information var fi = new ForumController().Forums_Get(forumID, -1, false); // Load the user if needed if (user == null) { var objUsers = new Entities.Users.UserController(); var objUser = objUsers.GetUser(portalID, userId); user = objUser; } // Load the user properties string sFirstName; string sLastName; string sDisplayName; string sUsername; if (user != null) { sFirstName = user.FirstName; sLastName = user.LastName; sDisplayName = user.DisplayName; sUsername = user.Username; } else { sFirstName = string.Empty; sLastName = string.Empty; sDisplayName = string.Empty; sUsername = string.Empty; } // Build the link string link; if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.IsRewriteLoaded()) { if (replyId == 0) { link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId }) : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId }); } else { link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId }) : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId }); } } else { var contentId = (replyId > 0) ? replyId : -1; link = new Data.Common().GetUrl(moduleID, -1, forumID, topicId, -1, contentId); } if (!(link.StartsWith("http"))) { if (!link.StartsWith("/")) { link = "/" + link; } if (link.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1) { link = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + link; } } // Build the forum Url var forumURL = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID }) : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topics }); // Build Moderation url var modLink = Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ViewType + "=modtopics", ParamKeys.ForumId + "=" + forumID }); if (modLink.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1) { modLink = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + modLink; } var result = new StringBuilder(sOut); result.Replace("[DISPLAYNAME]", UserProfiles.GetDisplayName(moduleID, userId, authorName, sFirstName, sLastName, sDisplayName)); result.Replace("[USERNAME]", sUsername); result.Replace("[USERID]", userId.ToString()); result.Replace("[FORUMNAME]", fi.ForumName); result.Replace("[PORTALID]", portalID.ToString()); result.Replace("[FIRSTNAME]", sFirstName); result.Replace("[LASTNAME]", sLastName); result.Replace("[FULLNAME]", sFirstName + " " + sLastName); result.Replace("[GROUPNAME]", fi.GroupName); result.Replace("[POSTDATE]", Utilities.GetDate(dateCreated, moduleID, timeZoneOffset)); result.Replace("[COMMENTS]", comments); result.Replace("[PORTALNAME]", portalSettings.PortalName); result.Replace("[MODLINK]", "<a href=\"" + modLink + "\">" + modLink + "</a>"); result.Replace("[LINK]", "<a href=\"" + link + "\">" + link + "</a>"); result.Replace("[HYPERLINK]", "<a href=\"" + link + "\">" + link + "</a>"); result.Replace("[LINKURL]", link); result.Replace("[FORUMURL]", forumURL); result.Replace("[FORUMLINK]", "<a href=\"" + forumURL + "\">" + forumURL + "</a>"); if (user != null) { result.Replace("[SENDERUSERNAME]", user.UserID.ToString()); result.Replace("[SENDERFIRSTNAME]", user.FirstName); result.Replace("[SENDERLASTNAME]", user.LastName); result.Replace("[SENDERDISPLAYNAME]", user.DisplayName); } else { result.Replace("[SENDERUSERNAME]", string.Empty); result.Replace("[SENDERFIRSTNAME]", string.Empty); result.Replace("[SENDERLASTNAME]", string.Empty); result.Replace("[SENDERDISPLAYNAME]", string.Empty); } result.Replace("[SUBJECT]", subject); result.Replace("[BODY]", body); result.Replace("[Body]", body); return(result.ToString()); }
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); }
private void LoadDefaultForums(int PortalId, int ModuleId) { var xDoc = new System.Xml.XmlDocument(); xDoc.Load(sPath); if (xDoc != null) { System.Xml.XmlNode xRoot = xDoc.DocumentElement; System.Xml.XmlNodeList xNodeList = xRoot.SelectNodes("//defaultforums/groups/group"); if (xNodeList.Count > 0) { int i; for (i = 0; i < xNodeList.Count; i++) { var gi = new ForumGroupInfo { ModuleId = ModuleId, ForumGroupId = -1, GroupName = xNodeList[i].Attributes["groupname"].Value, Active = xNodeList[i].Attributes["active"].Value == "1", Hidden = xNodeList[i].Attributes["hidden"].Value == "1", SortOrder = i, GroupSettingsKey = "", PermissionsId = -1 }; var gc = new ForumGroupController(); int groupId; groupId = gc.Groups_Save(PortalId, gi, true); gi = gc.GetForumGroup(ModuleId, groupId); string sKey = "G:" + groupId.ToString(); string sAllowHTML = "false"; if (xNodeList[i].Attributes["allowhtml"] != null) { sAllowHTML = xNodeList[i].Attributes["allowhtml"].Value; } Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicsTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EmailAddress, string.Empty); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.UseFilter, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowPostIcon, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowEmoticons, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowScript, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.IndexContent, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowRSS, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowAttach, "true"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachCount, "3"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxSize, "1000"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachTypeAllowed, ".jpg,.png,.gif,.zip"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachStore, "FILESYSTEM"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxHeight, "450"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxWidth, "450"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachUniqueFileNames, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowHTML, sAllowHTML); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorType, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorHeight, "350"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorWidth, "99%"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorToolbar, "bold,italic,underline,quote"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorStyle, "2"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicFormId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ReplyFormId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.QuickReplyFormId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ProfileTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.IsModerated, "false"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.DefaultTrustValue, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AutoTrustLevel, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModApproveTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModRejectTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModMoveTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModDeleteTemplateId, "0"); Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModNotifyTemplateId, "0"); if (groupId != -1) { if (xNodeList[i].HasChildNodes) { System.Xml.XmlNodeList cNodes = xNodeList[i].ChildNodes; for (int c = 0; c < cNodes.Count; c++) { var fi = new Forum(); var fc = new ForumController(); fi.ForumID = -1; fi.ModuleId = ModuleId; fi.ForumGroupId = groupId; fi.ParentForumId = 0; fi.ForumName = cNodes[c].Attributes["forumname"].Value; fi.ForumDesc = cNodes[c].Attributes["forumdesc"].Value; fi.ForumSecurityKey = "G:" + groupId.ToString(); fi.ForumSettingsKey = "G:" + groupId.ToString(); fi.Active = cNodes[c].Attributes["active"].Value == "1"; fi.Hidden = cNodes[c].Attributes["hidden"].Value == "1"; fi.SortOrder = c; fi.PermissionsId = gi.PermissionsId; fc.Forums_Save(PortalId, fi, true, true); } } } } } } }
public static string ParseEmailTemplate(string template, string templateName, int portalID, int moduleID, int tabID, int forumID, int topicId, int replyId, string comments, Entities.Users.UserInfo user, int userId, int timeZoneOffset) { var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); var ms = DataCache.MainSettings(moduleID); var sOut = template; // If we have a template name, load the template into sOut if (templateName != string.Empty) { if (templateName.Contains("_Subject_")) { templateName = templateName.Replace("_Subject_" + moduleID, string.Empty); var objTemplate = GetTemplateByName(templateName, moduleID, portalID); sOut = objTemplate.Subject; } else { var objTemplate = GetTemplateByName(templateName, moduleID, portalID); sOut = objTemplate.TemplateHTML; } } // Load Subject and body from topic or reply var subject = string.Empty; var body = string.Empty; var dateCreated = Utilities.NullDate(); var authorName = string.Empty; if (topicId > 0 && replyId > 0) { var ri = new ReplyController().Reply_Get(portalID, moduleID, topicId, replyId); if (ri != null) { subject = ri.Content.Subject; body = ri.Content.Body; dateCreated = ri.Content.DateCreated; authorName = ri.Content.AuthorName; } } else { var ti = new TopicsController().Topics_Get(portalID, moduleID, topicId); if (ti != null) { subject = ti.Content.Subject; body = ti.Content.Body; dateCreated = ti.Content.DateCreated; authorName = ti.Content.AuthorName; } } body = Utilities.ManageImagePath(body, Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request))); // load the forum information var fi = new ForumController().Forums_Get(forumID, -1, false); // Load the user if needed if (user == null) { var objUsers = new Entities.Users.UserController(); var objUser = objUsers.GetUser(portalID, userId); user = objUser; } // Load the user properties string sFirstName; string sLastName; string sDisplayName; string sUsername; if (user != null) { sFirstName = user.FirstName; sLastName = user.LastName; sDisplayName = user.DisplayName; sUsername = user.Username; } else { sFirstName = string.Empty; sLastName = string.Empty; sDisplayName = string.Empty; sUsername = string.Empty; } // Build the link string link; if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.IsRewriteLoaded()) { if (replyId == 0) link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId }) : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId }); else link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId }) : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId }); } else { var contentId = (replyId > 0) ? replyId : -1; link = new Data.Common().GetUrl(moduleID, -1, forumID, topicId, -1, contentId); } if (!(link.StartsWith("http"))) { if (!link.StartsWith("/")) link = "/" + link; if (link.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1) link = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + link; } // Build the forum Url var forumURL = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID }) : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topics }); // Build Moderation url var modLink = Common.Globals.NavigateURL(tabID, string.Empty, new[] {ParamKeys.ViewType + "=modtopics", ParamKeys.ForumId + "=" + forumID}); if (modLink.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1) modLink = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + modLink; var result = new StringBuilder(sOut); result.Replace("[DISPLAYNAME]", UserProfiles.GetDisplayName(moduleID, userId, authorName, sFirstName, sLastName, sDisplayName)); result.Replace("[USERNAME]", sUsername); result.Replace("[USERID]", userId.ToString()); result.Replace("[FORUMNAME]", fi.ForumName); result.Replace("[PORTALID]", portalID.ToString()); result.Replace("[FIRSTNAME]", sFirstName); result.Replace("[LASTNAME]", sLastName); result.Replace("[FULLNAME]", sFirstName + " " + sLastName); result.Replace("[GROUPNAME]", fi.GroupName); result.Replace("[POSTDATE]", Utilities.GetDate(dateCreated, moduleID, timeZoneOffset)); result.Replace("[COMMENTS]", comments); result.Replace("[PORTALNAME]", portalSettings.PortalName); result.Replace("[MODLINK]", "<a href=\"" + modLink + "\">" + modLink + "</a>"); result.Replace("[LINK]", "<a href=\"" + link + "\">" + link + "</a>"); result.Replace("[HYPERLINK]", "<a href=\"" + link + "\">" + link + "</a>"); result.Replace("[LINKURL]", link); result.Replace("[FORUMURL]", forumURL); result.Replace("[FORUMLINK]", "<a href=\"" + forumURL + "\">" + forumURL + "</a>"); // Introduced for Active Forum Email Connector plug-in Starts if (result.ToString().Contains("[EMAILCONNECTORITEMID]")) { // This Try with empty catch is introduced here because this code section is for Email Connector functionality only and this section should not // cause any issue to Active Forums functionality in case it does not run successfully. try { long itemID = GetEmailInfo(portalID, moduleID, forumID, topicId, HttpContext.Current.Request.UserHostAddress); result.Replace("[EMAILCONNECTORITEMID]", itemID.ToString()); } catch { } } // Introduced for Active Forum Email Connector plug-in Ends if (user != null) { result.Replace("[SENDERUSERNAME]", user.UserID.ToString()); result.Replace("[SENDERFIRSTNAME]", user.FirstName); result.Replace("[SENDERLASTNAME]", user.LastName); result.Replace("[SENDERDISPLAYNAME]", user.DisplayName); } else { result.Replace("[SENDERUSERNAME]", string.Empty); result.Replace("[SENDERFIRSTNAME]", string.Empty); result.Replace("[SENDERLASTNAME]", string.Empty); result.Replace("[SENDERDISPLAYNAME]", string.Empty); } result.Replace("[SUBJECT]", subject); result.Replace("[BODY]", body); result.Replace("[Body]", body); return result.ToString(); }
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 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" }); }
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 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 User DNNGetCurrentUser(int SiteId, int ModuleId) { PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings(); User u = new User(); DotNetNuke.Entities.Users.UserInfo cu = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo(); u = LoadUser(cu); u = FillProfile(SiteId, ModuleId, u); ForumController fc = new ForumController(); string fs = fc.GetForumsForUser(u.UserRoles, SiteId, ModuleId, "CanApprove"); if (! (string.IsNullOrEmpty(fs))) { u.Profile.IsMod = true; } else { u.Profile.IsMod = false; } return u; }
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 GetControl(string view, string options) { try { if (!Page.IsPostBack) { plhLoader.Controls.Clear(); } ForumBase ctl = null; if (view.ToUpperInvariant() == "FORUMVIEW") { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.ForumView()); } else if (view.ToUpperInvariant() == "ADVANCED") { ctl = (ForumBase)(LoadControl("~/desktopmodules/activeforums/advanced.ascx")); } else if ((view.ToUpperInvariant() == Views.Topics.ToUpperInvariant()) || (view.ToUpperInvariant() == "topics".ToUpperInvariant())) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.TopicsView()); } else if ((view.ToUpperInvariant() == Views.Topic.ToUpperInvariant()) || (view.ToUpperInvariant() == "topic".ToUpperInvariant())) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.TopicView()); } else if (view.ToUpperInvariant() == "USERSETTINGS".ToUpperInvariant()) { string ctlPath = string.Empty; ctlPath = "~/DesktopModules/ActiveForums/controls/af_profile.ascx"; if (!(System.IO.File.Exists(Server.MapPath(ctlPath)))) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.ForumView()); } else { ctl = (ForumBase)(LoadControl(ctlPath)); } } else { string ctlPath = string.Empty; ctlPath = "~/DesktopModules/ActiveForums/controls/af_" + view + ".ascx"; if (!(System.IO.File.Exists(Server.MapPath(ctlPath)))) { ctl = (ForumBase)(new DotNetNuke.Modules.ActiveForums.Controls.ForumView()); } else { ctl = (ForumBase)(LoadControl(ctlPath)); } } if (ForumId > 0 & ForumInfo != null) { ctl.ForumInfo = ForumInfo; } ctl.ID = view; ctl.ForumId = ForumId; ctl.ForumModuleId = ForumModuleId; if (ForumTabId == -1) { ForumTabId = TabId; } ctl.ForumTabId = ForumTabId; ctl.ForumGroupId = ForumGroupId; ctl.DefaultForumViewTemplateId = DefaultForumViewTemplateId; ctl.DefaultTopicsViewTemplateId = DefaultTopicsViewTemplateId; ctl.DefaultTopicViewTemplateId = DefaultTopicViewTemplateId; ctl.UseTemplatePath = UseTemplatePath; ctl.TemplatePath = TemplatePath; ctl.ParentForumId = ParentForumId; if (string.IsNullOrEmpty(ForumIds)) { ForumIds = UserForumsList; } if (SocialGroupId > 0) { ForumController fc = new ForumController(); ForumIds = fc.GetForumIdsBySocialGroup(PortalId, SocialGroupId); if (string.IsNullOrEmpty(ForumIds)) { RoleController rc = new RoleController(); RoleInfo role = rc.GetRole(SocialGroupId, PortalId); //Create new forum bool isPrivate = false; if (!role.IsPublic) { isPrivate = true; } Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController(); Hashtable htSettings = objModules.GetTabModuleSettings(TabModuleId); fc.CreateGroupForum(PortalId, ModuleId, SocialGroupId, Convert.ToInt32(htSettings["ForumGroupTemplate"].ToString()), role.RoleName + " Discussions", role.Description, isPrivate, htSettings["ForumConfig"].ToString()); ForumIds = fc.GetForumIdsBySocialGroup(PortalId, SocialGroupId); } } ctl.ForumIds = ForumIds; ctl.SocialGroupId = SocialGroupId; //ctl.PostID = PostID ctl.ModuleConfiguration = this.ModuleConfiguration; if (!(options == string.Empty)) { ctl.Params = options; } ControlsConfig cc = new ControlsConfig(); cc.AppPath = Page.ResolveUrl("~/DesktopModules/ActiveForums/"); cc.ThemePath = Page.ResolveUrl("~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme + "/"); cc.TemplatePath = cc.ThemePath + "templates/"; cc.SiteId = PortalId; cc.PageId = TabId; cc.InstanceId = ModuleId; cc.User = ForumUser; cc.DefaultViewRoles = Permissions.GetRoleIds(this.ModuleConfiguration.AuthorizedViewRoles.Split(';'), PortalId); cc.AdminRoles = Permissions.GetRoleIds(this.ModuleConfiguration.AuthorizedEditRoles.Split(';'), PortalId); cc.ProfileLink = ""; //GetProfileLink() cc.MembersLink = ""; // GetMembersLink() this.ControlConfig = cc; ctl.ControlConfig = cc; LinkControls(ctl.Controls); if (!(plhLoader.Controls.Contains(ctl))) { plhLoader.Controls.Add(ctl); } string sOut = null; sOut = System.Environment.NewLine + "<!-- © 2004 - 2013 DNN Corp., All Rights Reserved -->" + System.Environment.NewLine; sOut += "<!-- Active Forums 5.0 -->" + System.Environment.NewLine; Literal lit = new Literal(); lit.Text = sOut; plhLoader.Controls.Add(lit); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex); } }
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; }
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); }
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 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(); }
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" }); }