protected void Page_Load(object sender, EventArgs e) { _settings = ForumManager.GetSettings(SettingsID); _categoryRepeater.DataSource = Categories; _categoryRepeater.ItemDataBound += new RepeaterItemEventHandler(CategoryRepeater_ItemDataBound); _categoryRepeater.DataBind(); }
public override FileUploadHandler.FileUploadResult ProcessUpload(HttpContext context) { var result = new FileUploadResult() { Success = false }; try { if (ProgressFileUploader.HasFilesToUpload(context)) { var settingsID = new Guid(context.Request["SettingsID"]); var settings = ForumManager.GetSettings(settingsID); var thread = ForumDataProvider.GetThreadByID(TenantProvider.CurrentTenantID, Convert.ToInt32(context.Request["ThreadID"])); if (thread == null) { return(result); } var forumManager = settings.ForumManager; var offsetPhysicalPath = string.Empty; forumManager.GetAttachmentVirtualDirPath(thread, settingsID, new Guid(context.Request["UserID"]), out offsetPhysicalPath); var file = new ProgressFileUploader.FileToUpload(context); var newFileName = GetFileName(file.FileName); var origFileName = newFileName; var i = 1; var store = forumManager.GetStore(); while (store.IsFile(offsetPhysicalPath + "\\" + newFileName)) { var ind = origFileName.LastIndexOf("."); newFileName = ind != -1 ? origFileName.Insert(ind, "_" + i.ToString()) : origFileName + "_" + i.ToString(); i++; } result.FileName = newFileName; result.FileURL = store.Save(offsetPhysicalPath + "\\" + newFileName, file.InputStream).ToString(); result.Data = new { OffsetPhysicalPath = offsetPhysicalPath + "\\" + newFileName, FileName = newFileName, Size = file.ContentLength, ContentType = file.FileContentType, SettingsID = settingsID }; result.Success = true; } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
protected void Page_Load(object sender, EventArgs e) { var settings = ForumManager.GetSettings(SettingsID); Topics = new List <Topic>(); if (ThreadID == 0) { Response.Redirect(settings.StartPageAbsolutePath); } int currentPageNumber = 0; if (!String.IsNullOrEmpty(Request["p"])) { try { currentPageNumber = Convert.ToInt32(Request["p"]); } catch { currentPageNumber = 0; } } if (currentPageNumber <= 0) { currentPageNumber = 1; } int topicCountInThread = 0; Topics = ForumDataProvider.GetTopics(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID, ThreadID, currentPageNumber, settings.TopicCountOnPage, out topicCountInThread); ForumDataProvider.SetThreadVisit(TenantProvider.CurrentTenantID, ThreadID); int i = 0; foreach (Topic topic in Topics) { TopicControl topicControl = (TopicControl)LoadControl(settings.UserControlsVirtualPath + "/TopicControl.ascx"); topicControl.Topic = topic; topicControl.SettingsID = SettingsID; topicControl.IsEven = (i % 2 == 0); this.topicListHolder.Controls.Add(topicControl); i++; } PageNavigator pageNavigator = new PageNavigator() { PageUrl = settings.LinkProvider.TopicList(ThreadID), CurrentPageNumber = currentPageNumber, EntryCountOnPage = settings.TopicCountOnPage, VisiblePageCount = 5, EntryCount = topicCountInThread }; bottomPageNavigatorHolder.Controls.Add(pageNavigator); }
public AjaxResponse DoDeleteTopic(int idTopic, Guid settingsID) { _forumManager = ForumManager.GetForumManager(settingsID); var resp = new AjaxResponse { rs2 = idTopic.ToString() }; var topic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (topic == null) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicDelete, topic)) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } var topicName = HttpUtility.HtmlEncode(topic.Title); var threadID = topic.ThreadID; var threadName = topic.ThreadTitle; try { List <int> removedPostIDs; var attachmantOffsetPhysicalPaths = ForumDataProvider.RemoveTopic(TenantProvider.CurrentTenantID, topic.ID, out removedPostIDs); resp.rs1 = "1"; resp.rs3 = Resources.ForumUCResource.SuccessfullyDeleteTopicMessage; _forumManager.RemoveAttachments(attachmantOffsetPhysicalPaths.ToArray()); removedPostIDs.ForEach(idPost => CommonControlsConfigurer.FCKUploadsRemoveForItem(_forumManager.Settings.FileStoreModuleID, idPost.ToString())); var settings = ForumManager.GetSettings(settingsID); if (settings != null && settings.ActivityPublisher != null) { settings.ActivityPublisher.DeleteTopic(threadID, topicName, threadName); } } catch (Exception ex) { resp.rs1 = "0"; resp.rs3 = ex.Message.HtmlEncode(); } return(resp); }
public AjaxResponse DoStickyTopic(int idTopic, Guid settingsID) { _forumManager = ForumManager.GetForumManager(settingsID); var resp = new AjaxResponse(); resp.rs2 = idTopic.ToString(); var topic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (topic == null) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicSticky, topic)) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } topic.Sticky = !topic.Sticky; try { ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, topic.ID, topic.Title, topic.Sticky, topic.Closed); resp.rs1 = "1"; if (topic.Sticky) { resp.rs3 = Resources.ForumUCResource.SuccessfullyStickyTopicMessage; } else { resp.rs3 = Resources.ForumUCResource.SuccessfullyClearStickyTopicMessage; } var settings = ForumManager.GetSettings(settingsID); if (settings != null && settings.ActivityPublisher != null) { settings.ActivityPublisher.TopicSticky(topic); } } catch (Exception e) { resp.rs1 = "0"; resp.rs3 = HttpUtility.HtmlEncode(e.Message); } return(resp); }
protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(GetType()); _settings = ForumManager.GetSettings(SettingsID); _forumManager = _settings.ForumManager; _postCSSClass = IsEven ? "tintMedium" : ""; _messageCSSClass = "forum_mesBox"; if (!Post.IsApproved && _forumManager.ValidateAccessSecurityAction(ForumAction.ApprovePost, Post)) { _messageCSSClass = "tintDangerous forum_mesBox"; } }
public bool VoteCallback(string pollID, List <string> selectedVariantIDs, string additionalParams, out string errorMessage) { errorMessage = ""; var settingsID = new Guid(additionalParams.Split(',')[0]); int idQuestion = Convert.ToInt32(additionalParams.Split(',')[1]); var _forumManager = ForumManager.GetForumManager(settingsID); List <int> variantIDs = new List <int>(0); foreach (string id in selectedVariantIDs) { if (!String.IsNullOrEmpty(id)) { variantIDs.Add(Convert.ToInt32(id)); } } var q = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, idQuestion); if (SetupInfo.WorkMode == WorkMode.Promo || q == null || !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q) || ForumDataProvider.IsUserVote(TenantProvider.CurrentTenantID, idQuestion, SecurityContext.CurrentAccount.ID)) { errorMessage = Resources.ForumUCResource.ErrorAccessDenied; return(false); } try { ForumDataProvider.PollVote(TenantProvider.CurrentTenantID, idQuestion, variantIDs); } catch (Exception e) { errorMessage = e.Message.HtmlEncode(); return(false); } var settings = ForumManager.GetSettings(settingsID); if (settings != null && settings.ActivityPublisher != null) { settings.ActivityPublisher.Vote(q.Name, q.TopicID); } return(true); }
public AjaxResponse Preview(string text, Guid settingsID) { _settings = ForumManager.GetSettings(settingsID); UserInfo currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"tintLight borderBase clearFix\" style=\"padding:10px 0px; border-top:none; border-left:none; border-right:none;\">"); sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" style='width:100%;'>"); sb.Append("<tr valign=\"top\">"); sb.Append("<td align=\"center\" style='width:180px; padding:0px 5px;'>"); sb.Append("<div class=\"forum_postBoxUserSection\" style=\"overflow: hidden; width:150px;\">"); sb.Append("<a class=\"linkHeader\" href=\"" + CommonLinkUtility.GetUserProfile(currentUser.ID, _settings.ProductID) + "\">" + currentUser.DisplayUserName() + "</a>"); sb.Append("<div style=\"margin:5px 0px;\" class=\"textMediumDescribe\">"); sb.Append(HttpUtility.HtmlEncode(currentUser.Title)); sb.Append("</div>"); sb.Append("<a href=" + CommonLinkUtility.GetUserProfile(currentUser.ID, _settings.ProductID) + ">"); sb.Append(_settings.ForumManager.GetHTMLImgUserAvatar(currentUser.ID)); sb.Append("</a>"); sb.Append("</div>"); sb.Append("</td>"); //post sb.Append("<td>"); sb.Append("<div style='margin-bottom:5px; padding:0px 5px;'>"); sb.Append(DateTimeService.DateTime2StringPostStyle(DateTimeService.CurrentDate())); sb.Append("</div>"); var previewID = Guid.NewGuid().ToString(); sb.Append("<div id=\"forum_message_" + previewID + "\" class=\"forum_mesBox\" style=\"width:550px;\">"); sb.Append(text); sb.Append("</div>"); sb.Append("</td></tr></table>"); sb.Append("</div>"); AjaxResponse resp = new AjaxResponse(); resp.rs1 = sb.ToString(); return(resp); }
public string CancelPost(Guid settingsID, string itemID) { var _settings = ForumManager.GetSettings(settingsID); if (String.IsNullOrEmpty(itemID) == false) { CommonControlsConfigurer.FCKEditingCancel(_settings.FileStoreModuleID, itemID); } else { CommonControlsConfigurer.FCKEditingCancel(_settings.FileStoreModuleID); } if (httpContext != null && httpContext.Request != null && httpContext.Request.UrlReferrer != null && !string.IsNullOrEmpty(httpContext.Request.UrlReferrer.Query)) { var q = httpContext.Request.UrlReferrer.Query; var start = q.IndexOf("t="); if (start == -1) { start = q.IndexOf("f="); } start += 2; var end = q.IndexOf("&", start, StringComparison.CurrentCultureIgnoreCase); if (end == -1) { end = q.Length; } var t = q.Substring(start, end - start); return((q.IndexOf("t=") > 0 ? _settings.PostPageAbsolutePath + "t=" : _settings.TopicPageAbsolutePath + "f=") + t); } else { return(_settings.StartPageAbsolutePath); } }
protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(this.GetType()); _settings = ForumManager.GetSettings(SettingsID); _forumManager = _settings.ForumManager; TopicCSSClass = IsEven ? "tintMedium" : ""; if (!Topic.IsApproved && _forumManager.ValidateAccessSecurityAction(ForumAction.ApprovePost, Topic)) { TopicCSSClass = "tintDangerous"; } _imageURL = _forumManager.GetTopicImage(Topic); _tagsPanel.Visible = (Topic.Tags != null && Topic.Tags.Count > 0); tagRepeater.DataSource = Topic.Tags; tagRepeater.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { var settings = ForumManager.GetSettings(SettingsID); PageSize = string.IsNullOrEmpty(Request["size"]) ? 20 : Convert.ToInt32(Request["size"]); //var pageSize = PageSize; Topics = new List <Topic>(); if (ThreadID == 0) { Response.Redirect(settings.StartPageAbsolutePath); } int currentPageNumber = 0; if (!String.IsNullOrEmpty(Request["p"])) { try { currentPageNumber = Convert.ToInt32(Request["p"]); } catch { currentPageNumber = 0; } } if (currentPageNumber <= 0) { currentPageNumber = 1; } int topicCountInThread = 0; Topics = ForumDataProvider.GetTopics(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID, ThreadID, currentPageNumber, PageSize, out topicCountInThread); ForumDataProvider.SetThreadVisit(TenantProvider.CurrentTenantID, ThreadID); int i = 0; foreach (Topic topic in Topics) { TopicControl topicControl = (TopicControl)LoadControl(settings.UserControlsVirtualPath + "/TopicControl.ascx"); topicControl.Topic = topic; topicControl.SettingsID = SettingsID; topicControl.IsEven = (i % 2 == 0); this.topicListHolder.Controls.Add(topicControl); i++; } PageSize = string.IsNullOrEmpty(Request["size"]) ? 20 : Convert.ToInt32(Request["size"]); var pageSize = PageSize; PageNavigator pageNavigator = new PageNavigator() { PageUrl = string.Format( CultureInfo.CurrentCulture, "{0}?&f={1}&size={2}", VirtualPathUtility.ToAbsolute("~/products/community/modules/forum/topics.aspx"), ThreadID, pageSize ), //settings.LinkProvider.TopicList(ThreadID), CurrentPageNumber = currentPageNumber, EntryCountOnPage = pageSize, //settings.TopicCountOnPage, VisiblePageCount = 5, EntryCount = topicCountInThread }; TopicPagesCount = pageNavigator.EntryCount; var pageCount = (int)(TopicPagesCount / pageSize + 1); if (pageCount < pageNavigator.CurrentPageNumber) { pageNavigator.CurrentPageNumber = pageCount; } bottomPageNavigatorHolder.Controls.Add(pageNavigator); InitScripts(); }
protected void Page_Load(object sender, EventArgs e) { _settings = ForumManager.GetSettings(SettingsID); _forumManager = _settings.ForumManager; Utility.RegisterTypeForAjax(typeof(TagSuggest)); _subject = ""; int idTopic = 0; if (!String.IsNullOrEmpty(Request[_settings.TopicParamName])) { try { idTopic = Convert.ToInt32(Request[_settings.TopicParamName]); } catch { idTopic = 0; } } if (idTopic == 0) { Response.Redirect(_forumManager.PreviousPage.Url); return; } EditableTopic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (EditableTopic == null) { Response.Redirect(_forumManager.PreviousPage.Url); return; } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicEdit, EditableTopic)) { Response.Redirect(_forumManager.PreviousPage.Url); return; } _subject = EditableTopic.Title; foreach (Tag tag in EditableTopic.Tags) { _tagString += tag.Name + ","; _tagValues += tag.Name + "@" + tag.ID.ToString() + "$"; } _tagString = _tagString.TrimEnd(','); _tagValues = _tagValues.TrimEnd('$'); if (EditableTopic.Type == TopicType.Informational) { _pollMaster.Visible = false; } else { _pollMaster.QuestionFieldID = "forum_subject"; if (IsPostBack == false) { var question = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, EditableTopic.QuestionID); _pollMaster.Singleton = (question.Type == QuestionType.OneAnswer); _pollMaster.Name = question.Name; _pollMaster.ID = question.ID.ToString(); foreach (var variant in question.AnswerVariants) { _pollMaster.AnswerVariants.Add(new ASC.Web.Controls.PollFormMaster.AnswerViarint() { ID = variant.ID.ToString(), Name = variant.Name }); } } } #region IsPostBack if (IsPostBack) { if (EditableTopic.Type == TopicType.Informational) { _subject = Request["forum_subject"].Trim(); } else { _subject = (_pollMaster.Name ?? "").Trim(); } if (String.IsNullOrEmpty(_subject)) { _subject = ""; _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorSubjectEmpty + "</div>"; return; } if (EditableTopic.Type == TopicType.Poll && _pollMaster.AnswerVariants.Count < 2) { _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorPollVariantCount + "</div>"; return; } if (!String.IsNullOrEmpty(Request["forum_tags"])) { _tagString = Request["forum_tags"].Trim(); } else { _tagString = ""; } if (!String.IsNullOrEmpty(Request["forum_search_tags"])) { _tagValues = Request["forum_search_tags"].Trim(); } EditableTopic.Title = _subject; if (_forumManager.ValidateAccessSecurityAction(ForumAction.TagCreate, new Thread() { ID = EditableTopic.ThreadID })) { var removeTags = EditableTopic.Tags; EditableTopic.Tags = CreateTags(); removeTags.RemoveAll(t => EditableTopic.Tags.Find(nt => nt.ID == t.ID) != null); foreach (var tag in EditableTopic.Tags) { if (tag.ID == 0) { ForumDataProvider.CreateTag(TenantProvider.CurrentTenantID, EditableTopic.ID, tag.Name, tag.IsApproved); } else { ForumDataProvider.AttachTagToTopic(TenantProvider.CurrentTenantID, tag.ID, EditableTopic.ID); } } removeTags.ForEach(t => { ForumDataProvider.RemoveTagFromTopic(TenantProvider.CurrentTenantID, t.ID, EditableTopic.ID); }); } try { if (EditableTopic.Type == TopicType.Poll) { List <AnswerVariant> variants = new List <AnswerVariant>(); int i = 1; foreach (var answVariant in _pollMaster.AnswerVariants) { variants.Add(new AnswerVariant() { ID = (String.IsNullOrEmpty(answVariant.ID) ? 0 : Convert.ToInt32(answVariant.ID)), Name = answVariant.Name, SortOrder = i - 1 }); i++; } ForumDataProvider.UpdatePoll(TenantProvider.CurrentTenantID, EditableTopic.QuestionID, _pollMaster.Singleton ? QuestionType.OneAnswer : QuestionType.SeveralAnswer, EditableTopic.Title, variants); } ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, EditableTopic.ID, EditableTopic.Title, EditableTopic.Sticky, EditableTopic.Closed); if (_settings.ActivityPublisher != null) { _settings.ActivityPublisher.EditTopic(EditableTopic); } _errorMessage = "<div class=\"okBox\">" + Resources.ForumUCResource.SuccessfullyEditTopicMessage + "</div>"; return; } catch (Exception ex) { _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>"; return; } } #endregion }
protected void Page_Load(object sender, EventArgs e) { _settings = ForumManager.GetSettings(SettingsID); _forumManager = _settings.ForumManager; PostPageSize = string.IsNullOrEmpty(Request["size"]) ? 20 : Convert.ToInt32(Request["size"]); if (Topic == null) { Response.Redirect(_settings.StartPageAbsolutePath); } if ((new Thread { ID = Topic.ThreadID }).Visible == false) { Response.Redirect(_settings.StartPageAbsolutePath); } int currentPageNumber = 0; if (!String.IsNullOrEmpty(Request["p"])) { try { currentPageNumber = Convert.ToInt32(Request["p"]); } catch { currentPageNumber = 0; } } if (currentPageNumber <= 0) { currentPageNumber = 1; } int postCountInTopic; var posts = ForumDataProvider.GetPosts(TenantProvider.CurrentTenantID, Topic.ID, currentPageNumber, PostPageSize, out postCountInTopic); var postId = 0; if (!string.IsNullOrEmpty(Request["post"])) { try { postId = Convert.ToInt32(Request["post"]); } catch { postId = 0; } } if (postId != 0) { var allposts = ForumDataProvider.GetPostIDs(TenantProvider.CurrentTenantID, Topic.ID); var idx = -1; for (var j = 0; j < allposts.Count; j++) { if (allposts[j] != postId) { continue; } idx = j; break; } if (idx != -1) { var page = idx / 20 + 1; Response.Redirect("posts.aspx?t=" + Topic.ID + "&size=20&p=" + page + "#" + postId); } } PostPagesCount = postCountInTopic; var pageSize = PostPageSize; var pageNavigator = new PageNavigator { PageUrl = string.Format( CultureInfo.CurrentCulture, "{0}?&t={1}&size={2}", VirtualPathUtility.ToAbsolute("~/products/community/modules/forum/posts.aspx"), Topic.ID, pageSize ), //_settings.LinkProvider.PostList(Topic.ID), CurrentPageNumber = currentPageNumber, EntryCountOnPage = pageSize, VisiblePageCount = 5, EntryCount = postCountInTopic }; bottomPageNavigatorHolder.Controls.Add(pageNavigator); var i = 0; foreach (var post in posts) { var postControl = (PostControl)LoadControl(_settings.UserControlsVirtualPath + "/PostControl.ascx"); postControl.Post = post; postControl.IsEven = (i % 2 == 0); postControl.SettingsID = SettingsID; postControl.CurrentPageNumber = currentPageNumber; postControl.PostsCount = Topic.PostCount; postListHolder.Controls.Add(postControl); i++; } ForumDataProvider.SetTopicVisit(Topic); InitScripts(); if (Topic.Type != TopicType.Poll) { return; } var q = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, Topic.QuestionID); if (q == null) { return; } var isVote = ForumDataProvider.IsUserVote(TenantProvider.CurrentTenantID, q.ID, SecurityContext.CurrentAccount.ID); var pollForm = new PollForm { VoteHandlerType = typeof(PollVoteHandler), Answered = isVote || Topic.Closed || !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q), Name = q.Name, PollID = q.ID.ToString(), Singleton = (q.Type == QuestionType.OneAnswer), AdditionalParams = _settings.ID.ToString() + "," + q.ID.ToString() }; foreach (var variant in q.AnswerVariants) { pollForm.AnswerVariants.Add(new PollForm.AnswerViarint { ID = variant.ID.ToString(), Name = variant.Name, VoteCount = variant.AnswerCount }); } pollHolder.Controls.Add(new Literal { Text = "<div style='position:relative; padding-left:20px; margin-bottom:15px;'>" }); pollHolder.Controls.Add(pollForm); pollHolder.Controls.Add(new Literal { Text = "</div>" }); }
public void InitView() { _settings = ForumManager.GetSettings(SettingsID); TopicList = ForumDataProvider.GetLastUpdateTopics(TenantProvider.CurrentTenantID, MaxTopicCount); }
public void RemoveAttachment(Guid settingsID, string offsetPath) { var _settings = ForumManager.GetSettings(settingsID); _settings.ForumManager.RemoveAttachments(offsetPath); }
protected void Page_Load(object sender, EventArgs e) { _settings = ForumManager.GetSettings(SettingsID); _forumManager = _settings.ForumManager; if (this.Topic == null) { Response.Redirect(_settings.StartPageAbsolutePath); } if ((new Thread() { ID = Topic.ThreadID }).Visible == false) { Response.Redirect(_settings.StartPageAbsolutePath); } int currentPageNumber = 0; if (!String.IsNullOrEmpty(Request["p"])) { try { currentPageNumber = Convert.ToInt32(Request["p"]); } catch { currentPageNumber = 0; } } if (currentPageNumber <= 0) { currentPageNumber = 1; } int postCountInTopic = 0; var posts = ForumDataProvider.GetPosts(TenantProvider.CurrentTenantID, Topic.ID, currentPageNumber, _settings.PostCountOnPage, out postCountInTopic); PageNavigator pageNavigator = new PageNavigator() { PageUrl = _settings.LinkProvider.PostList(Topic.ID), CurrentPageNumber = currentPageNumber, EntryCountOnPage = _settings.PostCountOnPage, VisiblePageCount = 5, EntryCount = postCountInTopic }; bottomPageNavigatorHolder.Controls.Add(pageNavigator); int i = 0; foreach (Post post in posts) { PostControl postControl = (PostControl)LoadControl(_settings.UserControlsVirtualPath + "/PostControl.ascx"); postControl.Post = post; postControl.IsEven = (i % 2 == 0); postControl.SettingsID = SettingsID; postControl.CurrentPageNumber = currentPageNumber; postControl.PostsCount = Topic.PostCount; this.postListHolder.Controls.Add(postControl); i++; } ForumDataProvider.SetTopicVisit(Topic); if (Topic.Type == TopicType.Poll) { var q = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, Topic.QuestionID); if (q == null) { return; } var isVote = ForumDataProvider.IsUserVote(TenantProvider.CurrentTenantID, q.ID, SecurityContext.CurrentAccount.ID); var pollForm = new PollForm(); pollForm.VoteHandlerType = typeof(PollVoteHandler); pollForm.Answered = isVote || Topic.Closed || !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q) || ASC.Core.SecurityContext.DemoMode || (SetupInfo.WorkMode == WorkMode.Promo); pollForm.Name = q.Name; pollForm.PollID = q.ID.ToString(); pollForm.Singleton = (q.Type == QuestionType.OneAnswer); pollForm.AdditionalParams = _settings.ID.ToString() + "," + q.ID.ToString(); foreach (var variant in q.AnswerVariants) { pollForm.AnswerVariants.Add(new PollForm.AnswerViarint() { ID = variant.ID.ToString(), Name = variant.Name, VoteCount = variant.AnswerCount }); } pollHolder.Controls.Add(new Literal() { Text = "<div style='position:relative; padding-left:20px; margin-bottom:15px;'>" }); pollHolder.Controls.Add(pollForm); pollHolder.Controls.Add(new Literal() { Text = "</div>" }); } }
protected void Page_Load(object sender, EventArgs e) { _mobileVer = ASC.Web.Core.Mobile.MobileDetector.IsRequestMatchesMobile(this.Context); _settings = ForumManager.GetSettings(SettingsID); _forumManager = _settings.ForumManager; _currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); Utility.RegisterTypeForAjax(typeof(TagSuggest)); Utility.RegisterTypeForAjax(this.GetType()); Utility.RegisterTypeForAjax(typeof(PostControl)); _uploadSwitchHolder.Controls.Add(new FileUploaderModeSwitcher()); FCKeditor.BasePath = VirtualPathUtility.ToAbsolute(CommonControlsConfigurer.FCKEditorBasePath); FCKeditor.ToolbarSet = "ForumToolbar"; FCKeditor.EditorAreaCSS = WebSkin.GetUserSkin().BaseCSSFileAbsoluteWebPath; FCKeditor.Visible = !_mobileVer; PostType = NewPostType.Topic; PostAction = PostAction.Normal; int idTopic = 0; int idThread = 0; if (!String.IsNullOrEmpty(Request[_settings.TopicParamName])) { try { idTopic = Convert.ToInt32(Request[_settings.TopicParamName]); } catch { idTopic = 0; } if (idTopic == 0) { Response.Redirect(_settings.StartPageAbsolutePath); return; } else { PostType = NewPostType.Post; } } else if (!String.IsNullOrEmpty(Request[_settings.ThreadParamName])) { try { idThread = Convert.ToInt32(Request[_settings.ThreadParamName]); } catch { idThread = 0; } if (idThread == 0) { Response.Redirect(_settings.StartPageAbsolutePath); return; } else { PostType = NewPostType.Topic; } int topicType = 0; try { topicType = Convert.ToInt32(Request[_settings.PostParamName]); } catch { topicType = 0; } if (topicType == 1) { PostType = NewPostType.Poll; } } else { int topicType = 0; try { topicType = Convert.ToInt32(Request[_settings.PostParamName]); } catch { topicType = 0; } if (topicType == 1) { PostType = NewPostType.Poll; } if (IsPostBack) { if (!String.IsNullOrEmpty(Request["forum_thread_id"])) { try { idThread = Convert.ToInt32(Request["forum_thread_id"]); } catch { idThread = 0; } } } else { ForumDataProvider.GetThreadCategories(TenantProvider.CurrentTenantID, out _categories, out _threads); foreach (var thread in _threads) { bool isAllow = false; if (PostType == NewPostType.Topic) { isAllow = _forumManager.ValidateAccessSecurityAction(ForumAction.TopicCreate, thread); } else if (PostType == NewPostType.Poll) { isAllow = _forumManager.ValidateAccessSecurityAction(ForumAction.PollCreate, thread); } if (isAllow) { idThread = thread.ID; Thread = thread; break; } } } if (idThread == 0) { Response.Redirect(_settings.StartPageAbsolutePath); return; } _isSelectForum = true; } if (PostType == NewPostType.Topic || PostType == NewPostType.Poll) { if (Thread == null) { Thread = ForumDataProvider.GetThreadByID(TenantProvider.CurrentTenantID, idThread); } if (Thread == null) { Response.Redirect(_settings.StartPageAbsolutePath); return; } if (Thread.Visible == false) { Response.Redirect(_settings.StartPageAbsolutePath); } _threadForAttachFiles = Thread.ID; if (PostType == NewPostType.Topic) { if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicCreate, Thread)) { Response.Redirect(_settings.StartPageAbsolutePath); return; } this.Page.Title = this.NewTopicPageTitle; } else if (PostType == NewPostType.Poll) { if (!_forumManager.ValidateAccessSecurityAction(ForumAction.PollCreate, Thread)) { Response.Redirect(_settings.StartPageAbsolutePath); return; } this.Page.Title = this.NewPollPageTitle; } } else if (PostType == NewPostType.Post) { int parentPostId = 0; this.Page.Title = this.NewPostPageTitle; if (!String.IsNullOrEmpty(Request[_settings.ActionParamName]) && !String.IsNullOrEmpty(Request[_settings.PostParamName])) { try { PostAction = (PostAction)Convert.ToInt32(Request[_settings.ActionParamName]); } catch { PostAction = PostAction.Normal; } try { parentPostId = Convert.ToInt32(Request[_settings.PostParamName]); } catch { parentPostId = 0; PostAction = PostAction.Normal; } } Topic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (Topic == null) { Response.Redirect(_settings.StartPageAbsolutePath); return; } if (new Thread() { ID = Topic.ThreadID }.Visible == false) { Response.Redirect(_settings.StartPageAbsolutePath); return; } var recentPosts = ForumDataProvider.GetRecentTopicPosts(TenantProvider.CurrentTenantID, Topic.ID, 5, (PostAction == PostAction.Normal || PostAction == PostAction.Edit) ? 0 : parentPostId); if (recentPosts.Count > 0) { Label titleRecentPosts = new Label(); titleRecentPosts.Text = "<div class=\"headerPanel\" style='margin-top:20px;'>" + Resources.ForumUCResource.RecentPostFromTopic + "</div>"; _recentPostsHolder.Controls.Add(titleRecentPosts); int i = 0; foreach (Post post in recentPosts) { PostControl postControl = (PostControl)LoadControl(_settings.UserControlsVirtualPath + "/PostControl.ascx"); postControl.Post = post; postControl.SettingsID = SettingsID; postControl.IsEven = (i % 2 == 0); _recentPostsHolder.Controls.Add(postControl); i++; } } _threadForAttachFiles = Topic.ThreadID; if (PostAction == PostAction.Quote || PostAction == PostAction.Reply || PostAction == PostAction.Normal) { if (!_forumManager.ValidateAccessSecurityAction(ForumAction.PostCreate, Topic)) { Response.Redirect(_settings.StartPageAbsolutePath); return; } if (PostAction == PostAction.Quote || PostAction == PostAction.Reply) { ParentPost = ForumDataProvider.GetPostByID(TenantProvider.CurrentTenantID, parentPostId); if (ParentPost == null) { Response.Redirect(_settings.StartPageAbsolutePath); return; } } _subject = Topic.Title; if (PostAction == PostAction.Quote) { _text = String.Format(@"<div class=""mainQuote""> <div class=""quoteCaption""><span class=""bold"">{0}</span> {1}</div> <div id=""quote"" > <div class=""bord""><div class=""t""><div class=""r""> <div class=""b""><div class=""l""><div class=""c""> <div class=""reducer""> {2} </div> </div></div></div> </div></div></div> </div> </div><br/>", ParentPost.Poster.DisplayUserName(), Resources.ForumUCResource.QuoteCaptioon_Wrote + ":", ParentPost.Text); } if (PostAction == PostAction.Reply) { _text = "<span class=\"headerPanel\">To: " + ParentPost.Poster.DisplayUserName() + "</span><br/><br/>"; } } else if (PostAction == PostAction.Edit) { EditedPost = ForumDataProvider.GetPostByID(TenantProvider.CurrentTenantID, parentPostId); if (EditedPost == null) { Response.Redirect(_settings.StartPageAbsolutePath); return; } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.PostEdit, EditedPost)) { Response.Redirect("default.aspx"); return; } Topic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, EditedPost.TopicID); _text = EditedPost.Text; _subject = EditedPost.Subject; } } if (!IsPostBack && !_mobileVer) { FCKeditor.Value = _text; } if (PostType != NewPostType.Poll) { _pollMaster.Visible = false; } else { _pollMaster.QuestionFieldID = "forum_subject"; } if (IsPostBack) { _attachmentsString = Request["forum_attachments"] ?? ""; #region IsPostBack if (PostType == NewPostType.Topic) { _subject = string.IsNullOrEmpty(Request["forum_subject"]) ? string.Empty : Request["forum_subject"].Trim(); } else if (PostType == NewPostType.Poll) { _subject = string.IsNullOrEmpty(_pollMaster.Name) ? string.Empty : _pollMaster.Name.Trim(); } if (String.IsNullOrEmpty(_subject) && PostType != NewPostType.Post) { _subject = ""; _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorSubjectEmpty + "</div>"; return; } if (!String.IsNullOrEmpty(Request["forum_tags"])) { Regex r = new Regex(@"\s*,\s*", RegexOptions.Compiled); _tagString = r.Replace(Request["forum_tags"].Trim(), ","); } if (!String.IsNullOrEmpty(Request["forum_search_tags"])) { _tagValues = Request["forum_search_tags"].Trim(); } _text = Request["forum_text"].Trim(); if (String.IsNullOrEmpty(_text)) { _text = ""; _errorMessage = "<script type='text/javascript'>jq(document).ready (function(){ForumManager.ShowInfoMessage('" + Resources.ForumUCResource.ErrorTextEmpty + "');});</script>"; return; } else { _text = _text.Replace("<br />", "<br />\r\n").TrimEnd('\r', '\n'); } if (String.IsNullOrEmpty(Request["forum_topSubscription"])) { _subscribeViewType = SubscriveViewType.Disable; } else { if (String.Equals(Request["forum_topSubscription"], "1", StringComparison.InvariantCultureIgnoreCase)) { _subscribeViewType = SubscriveViewType.Checked; } else { _subscribeViewType = SubscriveViewType.Unchecked; } } if (PostType == NewPostType.Post) { if (PostAction == PostAction.Edit) { EditedPost.Subject = _subject; EditedPost.Text = _text; EditedPost.Formatter = _formatter; try { ForumDataProvider.UpdatePost(TenantProvider.CurrentTenantID, EditedPost.ID, EditedPost.Subject, EditedPost.Text, EditedPost.Formatter); if (IsAllowCreateAttachment) { CreateAttachments(EditedPost); } CommonControlsConfigurer.FCKEditingComplete(_settings.FileStoreModuleID, EditedPost.ID.ToString(), EditedPost.Text, true); var redirectUrl = _settings.PostPageAbsolutePath + "&t=" + EditedPost.TopicID.ToString() + "&p=1#" + EditedPost.ID.ToString(); Response.Redirect(redirectUrl); return; } catch (Exception ex) { _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>"; return; } } else { var post = new Post(Topic.Title, _text); post.TopicID = Topic.ID; post.ParentPostID = ParentPost == null ? 0 : ParentPost.ID; post.Formatter = _formatter; post.IsApproved = _forumManager.ValidateAccessSecurityAction(ForumAction.ApprovePost, Topic); try { post.ID = ForumDataProvider.CreatePost(TenantProvider.CurrentTenantID, post.TopicID, post.ParentPostID, post.Subject, post.Text, post.IsApproved, post.Formatter); Topic.PostCount++; CommonControlsConfigurer.FCKEditingComplete(_settings.FileStoreModuleID, post.ID.ToString(), post.Text, false); if (IsAllowCreateAttachment) { CreateAttachments(post); } NotifyAboutNewPost(post); if (_subscribeViewType != SubscriveViewType.Disable) { _forumManager.PresenterFactory.GetPresenter <ISubscriberView>().SetView(this); if (this.GetSubscriptionState != null) { this.GetSubscriptionState(this, new SubscribeEventArgs(SubscriptionConstants.NewPostInTopic, Topic.ID.ToString(), SecurityContext.CurrentAccount.ID)); } if (this.IsSubscribe && _subscribeViewType == SubscriveViewType.Unchecked) { if (this.UnSubscribe != null) { this.UnSubscribe(this, new SubscribeEventArgs(SubscriptionConstants.NewPostInTopic, Topic.ID.ToString(), SecurityContext.CurrentAccount.ID)); } } else if (!this.IsSubscribe && _subscribeViewType == SubscriveViewType.Checked) { if (this.Subscribe != null) { this.Subscribe(this, new SubscribeEventArgs(SubscriptionConstants.NewPostInTopic, Topic.ID.ToString(), SecurityContext.CurrentAccount.ID)); } } } int numb_page = Convert.ToInt32(Math.Ceiling(Topic.PostCount / (_settings.PostCountOnPage * 1.0))); var postURL = _settings.LinkProvider.Post(post.ID, Topic.ID, numb_page); if (_settings.ActivityPublisher != null) { _settings.ActivityPublisher.NewPost(post, Topic.Title, Topic.ThreadID, postURL); } Response.Redirect(postURL); return; } catch (Exception ex) { _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>"; return; } #endregion } } if (PostType == NewPostType.Topic || PostType == NewPostType.Poll) { if (PostType == NewPostType.Poll && _pollMaster.AnswerVariants.Count < 2) { _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorPollVariantCount + "</div>"; return; } try { var topic = new Topic(_subject, TopicType.Informational); topic.ThreadID = Thread.ID; topic.Tags = CreateTags(Thread); topic.Type = (PostType == NewPostType.Poll ? TopicType.Poll : TopicType.Informational); topic.ID = ForumDataProvider.CreateTopic(TenantProvider.CurrentTenantID, topic.ThreadID, topic.Title, topic.Type); Topic = topic; foreach (var tag in topic.Tags) { if (tag.ID == 0) { ForumDataProvider.CreateTag(TenantProvider.CurrentTenantID, topic.ID, tag.Name, tag.IsApproved); } else { ForumDataProvider.AttachTagToTopic(TenantProvider.CurrentTenantID, tag.ID, topic.ID); } } var post = new Post(topic.Title, _text); post.TopicID = topic.ID; post.ParentPostID = 0; post.Formatter = _formatter; post.IsApproved = _forumManager.ValidateAccessSecurityAction(ForumAction.ApprovePost, Topic); post.ID = ForumDataProvider.CreatePost(TenantProvider.CurrentTenantID, post.TopicID, post.ParentPostID, post.Subject, post.Text, post.IsApproved, post.Formatter); CommonControlsConfigurer.FCKEditingComplete(_settings.FileStoreModuleID, post.ID.ToString(), post.Text, false); if (IsAllowCreateAttachment) { CreateAttachments(post); } if (PostType == NewPostType.Poll) { var answerVariants = new List <string>(); foreach (var answVariant in _pollMaster.AnswerVariants) { answerVariants.Add(answVariant.Name); } topic.QuestionID = ForumDataProvider.CreatePoll(TenantProvider.CurrentTenantID, topic.ID, _pollMaster.Singleton ? QuestionType.OneAnswer : QuestionType.SeveralAnswer, topic.Title, answerVariants); } NotifyAboutNewPost(post); if (_subscribeViewType == SubscriveViewType.Checked) { _forumManager.PresenterFactory.GetPresenter <ISubscriberView>().SetView(this); if (this.Subscribe != null) { this.Subscribe(this, new SubscribeEventArgs(SubscriptionConstants.NewPostInTopic, topic.ID.ToString(), SecurityContext.CurrentAccount.ID)); } } if (_settings.ActivityPublisher != null) { _settings.ActivityPublisher.NewTopic(topic); } Response.Redirect(_settings.LinkProvider.Post(post.ID, topic.ID, 1)); return; } catch (Exception ex) { _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>"; return; } } } else { _forumManager.PresenterFactory.GetPresenter <ISubscriberView>().SetView(this); if (PostType == NewPostType.Poll || PostType == NewPostType.Topic) { if (this.GetSubscriptionState != null) { this.GetSubscriptionState(this, new SubscribeEventArgs(SubscriptionConstants.NewPostInThread, Thread.ID.ToString(), SecurityContext.CurrentAccount.ID)); } if (this.IsSubscribe) { _subscribeViewType = SubscriveViewType.Disable; } else { _subscribeViewType = SubscriveViewType.Checked; } } else if (PostType == NewPostType.Post && PostAction != PostAction.Edit) { if (this.GetSubscriptionState != null) { this.GetSubscriptionState(this, new SubscribeEventArgs(SubscriptionConstants.NewPostInThread, Topic.ThreadID.ToString(), SecurityContext.CurrentAccount.ID)); } if (this.IsSubscribe) { _subscribeViewType = SubscriveViewType.Disable; } else { if (SubscriptionConstants.SubscriptionProvider.IsUnsubscribe(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), SecurityContext.CurrentAccount.Name), SubscriptionConstants.NewPostInTopic, Topic.ID.ToString())) { _subscribeViewType = SubscriveViewType.Unchecked; } else { _subscribeViewType = SubscriveViewType.Checked; } } } else { _subscribeViewType = SubscriveViewType.Disable; } } }