Esempio n. 1
0
        private void EditTopic()
        {
            #region check for changes to poll

            var pollregex = new Regex(@"(?<poll>\[poll=\x22(?<question>.+?)\x22](?<answers>.+?)\[\/poll])",
                                      RegexOptions.Singleline);

            if (pollregex.IsMatch(Message.Text))
            {
                string topicPoll = pollregex.Match(Message.Text).Value;
                if (topicPoll == "" || topicPoll == "remove")
                {
                    if (_thisTopic.PollId.HasValue)
                    {
                        Polls.DeleteTopicPoll(_thisTopic.PollId.Value);
                    }
                }
                else if (_thisTopic.Forum.AllowPolls)
                {
                    var answers = new Regex(@"\[\*=(?<sort>[0-9]+)](?<answer>.+?)\[/\*]",
                                            RegexOptions.Singleline | RegexOptions.ExplicitCapture);
                    string question = "";
                    var    choices  = new SortedList <int, string>();

                    MatchCollection mc = pollregex.Matches(topicPoll);
                    if (mc.Count > 0)
                    {
                        foreach (Match m in mc)
                        {
                            question = m.Groups["question"].Value;
                            string answer = m.Groups["answers"].Value;

                            MatchCollection ans = answers.Matches(answer);
                            foreach (Match match in ans)
                            {
                                choices.Add(Convert.ToInt32(match.Groups["sort"].Value), match.Groups["answer"].Value);
                            }
                        }
                        if (_thisTopic.PollId.HasValue)
                        {
                            Polls.UpdateTopicPoll(_thisTopic.PollId.Value, question, choices);
                        }
                    }
                }
                Message.Text = pollregex.Replace(Message.Text, "");
            }

            #endregion

            int oldforumId = _thisTopic.ForumId;
            Topics.Update(_thisTopic.Id, Message.Text, tbxSubject.Text, Member, IsAdministrator, cbxSig.Checked);
            if (ForumDropDown.SelectedValue != oldforumId.ToString() && ForumDiv.Visible)
            {
                //move the topic
                int forumid = Convert.ToInt32(ForumDropDown.SelectedValue);
                Topics.ChangeTopicForum(_thisTopic.Id, forumid);
                Snitz.BLL.Admin.UpdateForumCounts();
                object obj = -1;
                Cache["RefreshKey"] = obj;
                _thisTopic.Author   = Members.GetAuthor(_thisTopic.AuthorId);

                if (Config.MoveNotify && _thisTopic.Author.Status != 0)
                {
                    _forum = Forums.GetForum(forumid);
                    string mailFile   = ConfigurationManager.AppSettings["TopicMoveEmail"];
                    string strSubject = "Sent From " + Regex.Replace(Config.ForumTitle, @"&\w+;", "") + ": Topic move notification";

                    var builder = new UriBuilder("http",
                                                 Request.Url.DnsSafeHost,
                                                 Request.Url.Port, Page.ResolveUrl("~/Content/Forums/forum.aspx"), string.Format("?FORUM={0}", _forum.Id));

                    var    file    = new StreamReader(mailFile);
                    string msgBody = file.ReadToEnd();
                    msgBody = msgBody.Replace("<%UserName%>", _thisTopic.AuthorName);
                    msgBody = msgBody.Replace("<%ForumUrl%>", Config.ForumTitle);
                    msgBody = msgBody.Replace("<%TopicSubject%>", _thisTopic.Subject);
                    msgBody = msgBody.Replace("<%MovedTo%>", _forum.Subject);
                    msgBody = msgBody.Replace("<%URL%>", builder.Uri.AbsoluteUri);

                    var mailsender = new SnitzEmail
                    {
                        toUser   = new MailAddress(_thisTopic.Author.Email, _thisTopic.AuthorName),
                        FromUser = "******",
                        subject  = strSubject,
                        IsHtml   = true,
                        msgBody  = msgBody
                    };
                    mailsender.Send();
                }
            }
            if (cbxLock.Checked && _inModeratedList)
            {
                Topics.SetTopicStatus(_thisTopic.Id, (int)Enumerators.PostStatus.Closed);
            }
            if (_inModeratedList)
            {
                Topics.MakeSticky(_thisTopic.Id, cbxSticky.Checked);
            }

            if (pingSiteMap)
            {
                Ping("");
            }
            InvalidateForumCache();
            Response.Redirect("/Content/Forums/topic.aspx?TOPIC=" + _thisTopic.Id);
        }