Пример #1
0
        /// <summary>
        /// Formats the forum link.
        /// </summary>
        /// <param name="forumId">
        /// The forum ID.
        /// </param>
        /// <param name="forumName">
        /// Name of the forum.
        /// </param>
        /// <returns>
        /// The format forum link.
        /// </returns>
        protected string FormatForumLink([NotNull] object forumId, [NotNull] object forumName)
        {
            if (forumId.ToString() == string.Empty || forumName.ToString() == string.Empty)
            {
                return(string.Empty);
            }

            return
                ($"<a target=\"_top\" href=\"{BuildLink.GetForumLink(forumId.ToType<int>(), forumName.ToString())}\">{forumName}</a>");
        }
Пример #2
0
        /// <summary>
        /// Maps the search document to data.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="userAccessList">The user access list.</param>
        /// <returns>
        /// Returns the Search Message
        /// </returns>
        private static SearchMessage MapSearchDocumentToData(Document doc, List <vaccess> userAccessList)
        {
            var forumId = doc.Get("ForumId").ToType <int>();

            if (!userAccessList.Any() || !userAccessList.Exists(v => v.ForumID == forumId && v.ReadAccess))
            {
                return(null);
            }

            return(new SearchMessage
            {
                Topic = doc.Get("Topic"),
                TopicId = doc.Get("TopicId").ToType <int>(),
                TopicUrl = BuildLink.GetTopicLink(doc.Get("TopicId").ToType <int>(), doc.Get("Topic")),
                Posted = doc.Get("Posted"),
                UserId = doc.Get("UserId").ToType <int>(),
                UserName = doc.Get("Author"),
                UserDisplayName = doc.Get("AuthorDisplay"),
                ForumName = doc.Get("ForumName"),
                ForumUrl = BuildLink.GetForumLink(doc.Get("ForumId").ToType <int>(), doc.Get("ForumName")),
                UserStyle = doc.Get("AuthorStyle")
            });
        }
Пример #3
0
        /// <summary>
        /// Adds the forum links.
        /// </summary>
        /// <param name="pageLinks">The page links.</param>
        /// <param name="forumId">The forum id.</param>
        /// <param name="noForumLink">The no forum link.</param>
        /// <returns>Returns the page links</returns>
        public static PageLinks AddForum(this PageLinks pageLinks, int forumId, bool noForumLink = false)
        {
            CodeContracts.VerifyNotNull(pageLinks, "pageLinks");

            if (BoardContext.Current.PageParentForumID.HasValue)
            {
                var parent = BoardContext.Current.GetRepository <Forum>()
                             .GetById(BoardContext.Current.PageParentForumID.Value);

                if (parent != null)
                {
                    pageLinks.AddLink(parent.Name, BuildLink.GetForumLink(parent.ID, parent.Name));
                }
            }

            if (BoardContext.Current.PageForumID == forumId)
            {
                pageLinks.AddLink(
                    BoardContext.Current.PageForumName,
                    noForumLink ? string.Empty : BuildLink.GetForumLink(forumId, BoardContext.Current.PageForumName));
            }

            return(pageLinks);
        }
Пример #4
0
        /// <summary>
        /// Handles the PostReply click including: Replying, Editing and New post.
        /// </summary>
        /// <param name="sender">
        /// The Sender Object.
        /// </param>
        /// <param name="e">
        /// The Event Arguments.
        /// </param>
        protected void PostReply_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.IsPostReplyVerified())
            {
                return;
            }

            var isPossibleSpamMessage = false;

            // Check for SPAM
            if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess &&
                !this.PageContext.BoardSettings.SpamServiceType.Equals(0))
            {
                // Check content for spam
                if (
                    this.Get <ISpamCheck>().CheckPostForSpam(
                        this.PageContext.IsGuest ? this.From.Text : this.PageContext.User.DisplayOrUserName(),
                        this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                        BBCodeHelper.StripBBCode(
                            HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(this.forumEditor.Text)))
                        .RemoveMultipleWhitespace(),
                        this.PageContext.IsGuest ? null : this.PageContext.MembershipUser.Email,
                        out var spamResult))
                {
                    var description =
                        $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.User.DisplayOrUserName())}";

                    switch (this.PageContext.BoardSettings.SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            description);
                        break;

                    case 1:
                        isPossibleSpamMessage = true;
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            $"{description}, it was flagged as unapproved post.");
                        break;

                    case 2:
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            $"{description}, post was rejected");
                        this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);
                        return;

                    case 3:
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            $"{description}, user was deleted and banned");

                        this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.MembershipUser,
                            this.PageContext.User.IP);

                        return;
                    }
                }
            }

            if (this.Get <ISpamCheck>().ContainsSpamUrls(this.forumEditor.Text))
            {
                return;
            }

            // update the last post time...
            this.Get <ISession>().LastPost = DateTime.UtcNow.AddSeconds(30);

            // Edit existing post
            var editMessage = this.PostReplyHandleEditPost();

            // Check if message is approved
            var isApproved = editMessage.MessageFlags.IsApproved;

            var messageId = editMessage.ID;

            // vzrus^ the poll access controls are enabled and this is a new topic - we add the variables
            var attachPollParameter = string.Empty;
            var returnForum         = string.Empty;

            if (this.PageContext.ForumPollAccess && this.PostOptions1.PollOptionVisible)
            {
                // new topic poll token
                attachPollParameter = $"&t={this.PageContext.PageTopicID}";

                // new return forum poll token
                returnForum = $"&f={this.PageContext.PageForumID}";
            }

            // Create notification emails
            if (isApproved)
            {
                if (attachPollParameter.IsNotSet() || !this.PostOptions1.PollChecked)
                {
                    // regular redirect...
                    BuildLink.Redirect(ForumPages.Posts, "m={0}&name={1}#post{0}", messageId, this.PageContext.PageTopicName);
                }
                else
                {
                    // poll edit redirect...
                    BuildLink.Redirect(ForumPages.PollEdit, "{0}", attachPollParameter);
                }
            }
            else
            {
                // Not Approved
                if (this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost)
                {
                    // not approved, notify moderators
                    this.Get <ISendNotification>()
                    .ToModeratorsThatMessageNeedsApproval(
                        this.PageContext.PageForumID,
                        messageId.ToType <int>(),
                        isPossibleSpamMessage);
                }

                // 't' variable is required only for poll and this is a attach poll token for attachments page
                if (!this.PostOptions1.PollChecked)
                {
                    attachPollParameter = string.Empty;
                }

                // Tell user that his message will have to be approved by a moderator
                var url = BuildLink.GetForumLink(this.PageContext.PageForumID, this.PageContext.PageForumName);

                if (this.PageContext.PageTopicID > 0 && this.topic.NumPosts > 1)
                {
                    url = BuildLink.GetTopicLink(this.PageContext.PageTopicID, this.PageContext.PageTopicName);
                }

                if (attachPollParameter.Length <= 0)
                {
                    BuildLink.Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url));
                }
                else
                {
                    BuildLink.Redirect(ForumPages.PollEdit, "&ra=1{0}{1}", attachPollParameter, returnForum);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Handles the PostReply click including: Replying, Editing and New post.
        /// </summary>
        /// <param name="sender">
        /// The Sender Object.
        /// </param>
        /// <param name="e">
        /// The Event Arguments.
        /// </param>
        protected void PostReply_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.IsPostReplyVerified())
            {
                return;
            }

            if (this.IsPostReplyDelay())
            {
                return;
            }

            var isPossibleSpamMessage = false;

            // Check for SPAM
            if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess &&
                !this.PageContext.BoardSettings.SpamServiceType.Equals(0))
            {
                // Check content for spam
                if (
                    this.Get <ISpamCheck>().CheckPostForSpam(
                        this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName,
                        this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                        BBCodeHelper.StripBBCode(
                            HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(this.forumEditor.Text)))
                        .RemoveMultipleWhitespace(),
                        this.PageContext.IsGuest ? null : this.PageContext.MembershipUser.Email,
                        out var spamResult))
                {
                    switch (this.PageContext.BoardSettings.SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}",
                            EventLogTypes.SpamMessageDetected);
                        break;

                    case 1:
                        this.spamApproved     = false;
                        isPossibleSpamMessage = true;
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, it was flagged as unapproved post.",
                            EventLogTypes.SpamMessageDetected);
                        break;

                    case 2:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, post was rejected",
                            EventLogTypes.SpamMessageDetected);
                        this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);
                        return;

                    case 3:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, user was deleted and banned",
                            EventLogTypes.SpamMessageDetected);

                        this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.MembershipUser,
                            this.PageContext.CurrentUser.IP);

                        return;
                    }
                }
            }

            // Check posts for urls if the user has only x posts
            if (BoardContext.Current.CurrentUser.NumPosts
                <= BoardContext.Current.Get <BoardSettings>().IgnoreSpamWordCheckPostCount&&
                !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess)
            {
                var urlCount = UrlHelper.CountUrls(this.forumEditor.Text);

                if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls)
                {
                    var spamResult =
                        $"The user posted {urlCount} urls but allowed only {this.PageContext.BoardSettings.AllowedNumberOfUrls}";

                    switch (this.PageContext.BoardSettings.SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}",
                            EventLogTypes.SpamMessageDetected);
                        break;

                    case 1:
                        this.spamApproved     = false;
                        isPossibleSpamMessage = true;
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, it was flagged as unapproved post.",
                            EventLogTypes.SpamMessageDetected);
                        break;

                    case 2:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, post was rejected",
                            EventLogTypes.SpamMessageDetected);
                        this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);
                        return;

                    case 3:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, user was deleted and banned",
                            EventLogTypes.SpamMessageDetected);

                        this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.MembershipUser,
                            this.PageContext.CurrentUser.IP);

                        return;
                    }
                }
            }

            // update the last post time...
            this.Get <ISession>().LastPost = DateTime.UtcNow.AddSeconds(30);

            // New Topic
            var messageId = this.PostReplyHandleNewPost(out var newTopic);

            // Check if message is approved
            var isApproved = this.GetRepository <Message>().GetById(messageId.ToType <int>()).MessageFlags.IsApproved;

            // vzrus^ the poll access controls are enabled and this is a new topic - we add the variables
            var attachPollParameter = string.Empty;
            var returnForum         = string.Empty;

            if (this.PageContext.ForumPollAccess && this.PostOptions1.PollOptionVisible)
            {
                // new topic poll token
                attachPollParameter = $"&t={newTopic}";

                // new return forum poll token
                returnForum = $"&f={this.PageContext.PageForumID}";
            }

            // Create notification emails
            if (isApproved)
            {
                this.Get <ISendNotification>().ToWatchingUsers(messageId.ToType <int>());

                if (!this.PageContext.IsGuest && this.PageContext.CurrentUser.Activity)
                {
                    // Handle Mentions
                    BBCodeHelper.FindMentions(this.forumEditor.Text).ForEach(
                        user =>
                    {
                        var userId = this.Get <IUserDisplayName>().GetId(user).Value;

                        if (userId != this.PageContext.PageUserID)
                        {
                            this.Get <IActivityStream>().AddMentionToStream(
                                userId,
                                newTopic.ToType <int>(),
                                messageId.ToType <int>(),
                                this.PageContext.PageUserID);
                        }
                    });

                    // Handle User Quoting
                    BBCodeHelper.FindUserQuoting(this.forumEditor.Text).ForEach(
                        user =>
                    {
                        var userId = this.Get <IUserDisplayName>().GetId(user).Value;

                        if (userId != this.PageContext.PageUserID)
                        {
                            this.Get <IActivityStream>().AddQuotingToStream(
                                userId,
                                newTopic.ToType <int>(),
                                messageId.ToType <int>(),
                                this.PageContext.PageUserID);
                        }
                    });

                    this.Get <IActivityStream>().AddTopicToStream(
                        Config.IsDotNetNuke ? this.PageContext.PageForumID : this.PageContext.PageUserID,
                        newTopic,
                        messageId.ToType <int>(),
                        this.TopicSubjectTextBox.Text,
                        this.forumEditor.Text);

                    // Add tags
                    if (this.Tags.Text.IsSet())
                    {
                        var tags = this.Tags.Text.Split(',');

                        var boardTags = this.GetRepository <Tag>().GetByBoardId();

                        tags.ForEach(
                            tag =>
                        {
                            var existTag = boardTags.FirstOrDefault(t => t.TagName == tag);

                            if (existTag != null)
                            {
                                // add to topic
                                this.GetRepository <TopicTag>().Add(
                                    existTag.ID,
                                    newTopic.ToType <int>());
                            }
                            else
                            {
                                // save new Tag
                                var newTagId = this.GetRepository <Tag>().Add(tag);

                                // add to topic
                                this.GetRepository <TopicTag>().Add(newTagId, newTopic.ToType <int>());
                            }
                        });
                    }
                }

                if (attachPollParameter.IsNotSet() || !this.PostOptions1.PollChecked)
                {
                    // regular redirect...
                    BuildLink.Redirect(ForumPages.Posts, "m={0}&name={1}#post{0}", messageId, newTopic.ToType <int>());
                }
                else
                {
                    // poll edit redirect...
                    BuildLink.Redirect(ForumPages.PollEdit, "{0}", attachPollParameter);
                }
            }
            else
            {
                // Not Approved
                if (this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost)
                {
                    // not approved, notify moderators
                    this.Get <ISendNotification>()
                    .ToModeratorsThatMessageNeedsApproval(
                        this.PageContext.PageForumID,
                        messageId.ToType <int>(),
                        isPossibleSpamMessage);
                }

                // 't' variable is required only for poll and this is a attach poll token for attachments page
                if (!this.PostOptions1.PollChecked)
                {
                    attachPollParameter = string.Empty;
                }

                // Tell user that his message will have to be approved by a moderator
                var url = BuildLink.GetForumLink(this.PageContext.PageForumID, this.PageContext.PageForumName);

                if (attachPollParameter.Length <= 0)
                {
                    BuildLink.Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url));
                }
                else
                {
                    BuildLink.Redirect(ForumPages.PollEdit, "&ra=1{0}{1}", attachPollParameter, returnForum);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// The quick reply_ click.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void QuickReplyClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            try
            {
                if (this.quickReplyEditor.Text.Length <= 0)
                {
                    this.PageContext.PageElements.RegisterJsBlockStartup(
                        "openModalJs",
                        JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                    this.PageContext.AddLoadMessage(this.GetText("EMPTY_MESSAGE"), MessageTypes.warning);

                    return;
                }

                // No need to check whitespace if they are actually posting something
                if (this.Get <BoardSettings>().MaxPostSize > 0 &&
                    this.quickReplyEditor.Text.Length >= this.Get <BoardSettings>().MaxPostSize)
                {
                    this.PageContext.PageElements.RegisterJsBlockStartup(
                        "openModalJs",
                        JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                    this.PageContext.AddLoadMessage(this.GetText("ISEXCEEDED"), MessageTypes.warning);

                    return;
                }

                if (this.EnableCaptcha() && !CaptchaHelper.IsValid(this.tbCaptcha.Text.Trim()))
                {
                    this.PageContext.PageElements.RegisterJsBlockStartup(
                        "openModalJs",
                        JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                    this.PageContext.AddLoadMessage(this.GetText("BAD_CAPTCHA"), MessageTypes.warning);

                    return;
                }

                if (!(this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess) &&
                    this.Get <BoardSettings>().PostFloodDelay > 0)
                {
                    if (this.PageContext.Get <ISession>().LastPost
                        > DateTime.UtcNow.AddSeconds(-this.Get <BoardSettings>().PostFloodDelay))
                    {
                        this.PageContext.PageElements.RegisterJsBlockStartup(
                            "openModalJs",
                            JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                        this.PageContext.AddLoadMessage(
                            this.GetTextFormatted(
                                "wait",
                                (this.PageContext.Get <ISession>().LastPost
                                 - DateTime.UtcNow.AddSeconds(-this.Get <BoardSettings>().PostFloodDelay)).Seconds),
                            MessageTypes.warning);

                        return;
                    }
                }

                this.PageContext.Get <ISession>().LastPost = DateTime.UtcNow;

                // post message...
                var  message = this.quickReplyEditor.Text;
                long topicId = this.PageContext.PageTopicID;

                // SPAM Check

                // Check if Forum is Moderated
                var isForumModerated = false;

                var dt = this.GetRepository <Forum>().List(
                    this.PageContext.PageBoardID,
                    this.PageContext.PageForumID);

                var forumInfo = dt.FirstOrDefault();

                if (forumInfo != null)
                {
                    isForumModerated = this.CheckForumModerateStatus(forumInfo);
                }

                var spamApproved          = true;
                var isPossibleSpamMessage = false;

                // Check for SPAM
                if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess &&
                    !this.Get <BoardSettings>().SpamServiceType.Equals(0))
                {
                    // Check content for spam
                    if (this.Get <ISpamCheck>().CheckPostForSpam(
                            this.PageContext.IsGuest ? "Guest" : this.PageContext.User.DisplayOrUserName(),
                            this.PageContext.Get <HttpRequestBase>().GetUserRealIPAddress(),
                            this.quickReplyEditor.Text,
                            this.PageContext.IsGuest ? null : this.PageContext.MembershipUser.Email,
                            out var spamResult))
                    {
                        var description =
                            $@"Spam Check detected possible SPAM ({spamResult})
                               posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.User.DisplayOrUserName())}";

                        switch (this.Get <BoardSettings>().SpamMessageHandling)
                        {
                        case 0:
                            this.Logger.SpamMessageDetected(
                                this.PageContext.PageUserID,
                                description);
                            break;

                        case 1:
                            spamApproved          = false;
                            isPossibleSpamMessage = true;
                            this.Logger.SpamMessageDetected(
                                this.PageContext.PageUserID,
                                $"{description}, it was flagged as unapproved post");
                            break;

                        case 2:
                            this.Logger.SpamMessageDetected(
                                this.PageContext.PageUserID,
                                $"{description}, post was rejected");

                            this.PageContext.PageElements.RegisterJsBlockStartup(
                                "openModalJs",
                                JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                            this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);

                            return;

                        case 3:
                            this.Logger.SpamMessageDetected(
                                this.PageContext.PageUserID,
                                $"{description}, user was deleted and bannded");

                            this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                                this.PageContext.PageUserID,
                                this.PageContext.MembershipUser,
                                this.PageContext.User.IP);

                            return;
                        }
                    }

                    if (this.Get <ISpamCheck>().ContainsSpamUrls(this.quickReplyEditor.Text))
                    {
                        return;
                    }

                    if (!this.PageContext.IsGuest)
                    {
                        this.UpdateWatchTopic(this.PageContext.PageUserID, this.PageContext.PageTopicID);
                    }
                }

                // If Forum is Moderated
                if (isForumModerated)
                {
                    spamApproved = false;
                }

                // Bypass Approval if Admin or Moderator
                if (this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess)
                {
                    spamApproved = true;
                }

                var messageFlags = new MessageFlags
                {
                    IsHtml     = this.quickReplyEditor.UsesHTML,
                    IsBBCode   = this.quickReplyEditor.UsesBBCode,
                    IsApproved = spamApproved
                };

                // Bypass Approval if Admin or Moderator.
                var messageId = this.GetRepository <Message>().SaveNew(
                    topicId,
                    this.PageContext.PageUserID,
                    message,
                    null,
                    this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                    DateTime.UtcNow,
                    null,
                    messageFlags);

                // Check to see if the user has enabled "auto watch topic" option in his/her profile.
                if (this.PageContext.User.AutoWatchTopics)
                {
                    var watchTopicId = this.GetRepository <WatchTopic>().Check(
                        this.PageContext.PageUserID,
                        this.PageContext.PageTopicID);

                    if (!watchTopicId.HasValue)
                    {
                        // subscribe to this topic
                        this.GetRepository <WatchTopic>().Add(this.PageContext.PageUserID, this.PageContext.PageTopicID);
                    }
                }

                if (messageFlags.IsApproved)
                {
                    // send new post notification to users watching this topic/forum
                    this.Get <ISendNotification>().ToWatchingUsers(messageId.ToType <int>());

                    if (!this.PageContext.IsGuest && this.PageContext.User.Activity)
                    {
                        this.Get <IActivityStream>().AddReplyToStream(
                            this.PageContext.PageForumID,
                            this.PageContext.PageTopicID,
                            messageId.ToType <int>(),
                            this.PageContext.PageTopicName,
                            message);
                    }

                    // redirect to newly posted message
                    BuildLink.Redirect(
                        ForumPages.Posts,
                        "m={0}&name={1}&#post{0}",
                        messageId,
                        this.PageContext.PageTopicName);
                }
                else
                {
                    if (this.Get <BoardSettings>().EmailModeratorsOnModeratedPost)
                    {
                        // not approved, notify moderators
                        this.Get <ISendNotification>().ToModeratorsThatMessageNeedsApproval(
                            this.PageContext.PageForumID,
                            messageId.ToType <int>(),
                            isPossibleSpamMessage);
                    }

                    var url = BuildLink.GetForumLink(this.PageContext.PageForumID, this.PageContext.PageForumName);

                    BuildLink.Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url));
                }
            }
            catch (Exception exception)
            {
                if (exception.GetType() != typeof(ThreadAbortException))
                {
                    this.Logger.Log(this.PageContext.PageUserID, this, exception);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Maps the search document to data.
        /// </summary>
        /// <param name="highlighter">The highlighter.</param>
        /// <param name="analyzer">The analyzer.</param>
        /// <param name="doc">The document.</param>
        /// <param name="userAccessList">The user access list.</param>
        /// <returns>
        /// Returns the Search Message
        /// </returns>
        private SearchMessage MapSearchDocumentToData(
            Highlighter highlighter,
            Analyzer analyzer,
            Document doc,
            List <vaccess> userAccessList)
        {
            var forumId = doc.Get("ForumId").ToType <int>();

            if (!userAccessList.Any() || !userAccessList.Exists(v => v.ForumID == forumId && v.ReadAccess))
            {
                return(null);
            }

            var flags        = doc.Get("Flags").ToType <int>();
            var messageFlags = new MessageFlags(flags);

            var formattedMessage = this.Get <IFormatMessage>().Format(
                doc.Get("MessageId").ToType <int>(),
                doc.Get("Message"),
                messageFlags);

            formattedMessage = this.Get <IBBCode>().FormatMessageWithCustomBBCode(
                formattedMessage,
                new MessageFlags(flags),
                doc.Get("UserId").ToType <int>(),
                doc.Get("MessageId").ToType <int>());

            var message = formattedMessage;

            try
            {
                message = GetHighlight(highlighter, analyzer, "Message", message);
            }
            catch (Exception)
            {
                // Ignore
                message = formattedMessage;
            }
            finally
            {
                if (message.IsNotSet())
                {
                    message = formattedMessage;
                }
            }

            string topic;

            try
            {
                topic = GetHighlight(highlighter, analyzer, "Topic", doc.Get("Topic"));
            }
            catch (Exception)
            {
                topic = doc.Get("Topic");
            }

            return(new SearchMessage
            {
                MessageId = doc.Get("MessageId").ToType <int>(),
                Message = message,
                Flags = flags,
                Posted = doc.Get("Posted"),
                UserName = doc.Get("Author"),
                UserId = doc.Get("UserId").ToType <int>(),
                TopicId = doc.Get("TopicId").ToType <int>(),
                Topic = topic.IsSet() ? topic : doc.Get("Topic"),
                TopicTags = doc.Get("TopicTags"),
                ForumId = doc.Get("ForumId").ToType <int>(),
                Description = doc.Get("Description"),
                TopicUrl =
                    BuildLink.GetTopicLink(
                        doc.Get("TopicId").ToType <int>(),
                        topic.IsSet() ? topic : doc.Get("Topic")),
                MessageUrl =
                    BuildLink.GetLink(
                        ForumPages.Posts,
                        "m={0}&name={1}#post{0}",
                        doc.Get("MessageId").ToType <int>(),
                        topic.IsSet() ? topic : doc.Get("Topic")),
                ForumUrl = BuildLink.GetForumLink(doc.Get("ForumId").ToType <int>(), doc.Get("ForumName")),
                UserDisplayName = doc.Get("AuthorDisplay"),
                ForumName = doc.Get("ForumName"),
                UserStyle = doc.Get("AuthorStyle")
            });
        }
Пример #8
0
        /// <summary>
        /// The latest posts_ item data bound.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void LatestPosts_ItemDataBound([NotNull] object sender, [NotNull] RepeaterItemEventArgs e)
        {
            // populate the controls here...
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var item = (dynamic)e.Item.DataItem;

            var topicSubject = this.Get <IBadWordReplace>().Replace(this.HtmlEncode((string)item.Topic));

            // get the controls
            var postIcon            = e.Item.FindControlAs <Label>("PostIcon");
            var textMessageLink     = e.Item.FindControlAs <ThemeButton>("TextMessageLink");
            var forumLink           = e.Item.FindControlAs <ThemeButton>("ForumLink");
            var info                = e.Item.FindControlAs <ThemeButton>("Info");
            var lastUserLink        = new UserLink();
            var lastPostedDateLabel = new DisplayDateTime {
                Format = DateTimeFormat.BothTopic
            };

            var topicStyle = (string)item.Styles;

            var styles = this.PageContext.BoardSettings.UseStyledTopicTitles && topicStyle.IsSet()
                ? this.Get <IStyleTransform>().Decode((string)item.Styles)
                : string.Empty;

            if (styles.IsSet())
            {
                textMessageLink.Attributes.Add("style", styles);
            }

            textMessageLink.Text = topicSubject;

            var startedByText = this.GetTextFormatted(
                "VIEW_TOPIC_STARTED_BY",
                this.PageContext.BoardSettings.EnableDisplayName ? (string)item.UserDisplayName : (string)item.UserName);

            var inForumText = this.GetTextFormatted("IN_FORUM", this.HtmlEncode((string)item.Forum));

            textMessageLink.TitleNonLocalized = $"{startedByText} {inForumText}";
            textMessageLink.NavigateUrl       = BuildLink.GetLink(
                ForumPages.Posts,
                "t={0}&name={1}",
                item.TopicID,
                topicSubject);

            forumLink.Text        = $"({item.Forum})";
            forumLink.NavigateUrl = BuildLink.GetForumLink(item.ForumID, item.Forum);

            lastUserLink.UserID      = item.LastUserID;
            lastUserLink.Style       = item.LastUserStyle;
            lastUserLink.Suspended   = item.LastUserSuspended;
            lastUserLink.ReplaceName = this.PageContext.BoardSettings.EnableDisplayName
                ? item.LastUserDisplayName
                : item.LastUserName;

            lastPostedDateLabel.DateTime = item.LastPosted;

            var lastRead = this.Get <IReadTrackCurrentUser>().GetForumTopicRead(
                (int)item.ForumID,
                (int)item.TopicID,
                (DateTime?)item.LastForumAccess ?? DateTimeHelper.SqlDbMinTime(),
                (DateTime?)item.LastTopicAccess ?? DateTimeHelper.SqlDbMinTime());

            if ((DateTime)item.LastPosted > lastRead)
            {
                postIcon.Visible  = true;
                postIcon.CssClass = "badge bg-success";

                postIcon.Text = this.GetText("NEW_MESSAGE");
            }

            var lastPostedDateTime = (DateTime)item.LastPosted;

            var formattedDatetime = this.PageContext.BoardSettings.ShowRelativeTime
                                        ? lastPostedDateTime.ToString(
                "yyyy-MM-ddTHH:mm:ssZ",
                CultureInfo.InvariantCulture)
                                        : this.Get <IDateTime>().Format(
                DateTimeFormat.BothTopic,
                lastPostedDateTime);

            var span = this.PageContext.BoardSettings.ShowRelativeTime ? @"<span class=""popover-timeago"">" : "<span>";

            info.TextLocalizedTag  = "by";
            info.TextLocalizedPage = "DEFAULT";
            info.ParamText0        = this.PageContext.BoardSettings.EnableDisplayName
                                  ? item.UserDisplayName
                                  : item.UserName;

            info.DataContent = $@"
                          {lastUserLink.RenderToString()}
                          <span class=""fa-stack"">
                                                    <i class=""fa fa-calendar-day fa-stack-1x text-secondary""></i>
                                                    <i class=""fa fa-circle fa-badge-bg fa-inverse fa-outline-inverse""></i>
                                                    <i class=""fa fa-clock fa-badge text-secondary""></i>
                                                </span>&nbsp;{span}{formattedDatetime}</span>
                         ";
        }
Пример #9
0
        /// <summary>
        /// The latest posts_ item data bound.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void LatestPosts_ItemDataBound([NotNull] object sender, [NotNull] RepeaterItemEventArgs e)
        {
            // populate the controls here...
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var currentRow = (DataRowView)e.Item.DataItem;

            var topicSubject = this.Get <IBadWordReplace>().Replace(this.HtmlEncode(currentRow["Topic"]));

            // make message url...
            var messageUrl = BuildLink.GetLinkNotEscaped(
                ForumPages.Posts,
                "m={0}&name={1}#post{0}",
                currentRow["LastMessageID"],
                topicSubject);

            // get the controls
            var postIcon                   = e.Item.FindControlAs <Label>("PostIcon");
            var textMessageLink            = e.Item.FindControlAs <HyperLink>("TextMessageLink");
            var forumLink                  = e.Item.FindControlAs <HyperLink>("ForumLink");
            var info                       = e.Item.FindControlAs <ThemeButton>("Info");
            var imageMessageLink           = e.Item.FindControlAs <ThemeButton>("GoToLastPost");
            var imageLastUnreadMessageLink = e.Item.FindControlAs <ThemeButton>("GoToLastUnread");
            var lastUserLink               = new UserLink();
            var lastPostedDateLabel        = new DisplayDateTime {
                Format = DateTimeFormat.BothTopic
            };

            var styles = this.Get <BoardSettings>().UseStyledTopicTitles
                             ? this.Get <IStyleTransform>().DecodeStyleByString(currentRow["Styles"].ToString())
                             : string.Empty;

            if (styles.IsSet())
            {
                textMessageLink.Attributes.Add("style", styles);
            }

            textMessageLink.Text = topicSubject;

            var startedByText = this.GetTextFormatted(
                "VIEW_TOPIC_STARTED_BY",
                currentRow[this.Get <BoardSettings>().EnableDisplayName ? "UserDisplayName" : "UserName"].ToString());

            var inForumText = this.GetTextFormatted("IN_FORUM", this.HtmlEncode(currentRow["Forum"].ToString()));

            textMessageLink.ToolTip =
                $"{startedByText} {inForumText}";
            textMessageLink.Attributes.Add("data-toggle", "tooltip");

            textMessageLink.NavigateUrl = BuildLink.GetLinkNotEscaped(
                ForumPages.Posts,
                "t={0}&name={1}&find=unread",
                currentRow["TopicID"],
                topicSubject);

            imageMessageLink.NavigateUrl = messageUrl;

            forumLink.Text        = $"({currentRow["Forum"]})";
            forumLink.NavigateUrl = BuildLink.GetForumLink(
                currentRow["ForumID"].ToType <int>(),
                currentRow["Forum"].ToString());

            if (imageLastUnreadMessageLink.Visible)
            {
                imageLastUnreadMessageLink.NavigateUrl = BuildLink.GetLinkNotEscaped(
                    ForumPages.Posts,
                    "t={0}&name={1}&find=unread",
                    currentRow["TopicID"],
                    topicSubject);
            }

            // Just in case...
            if (currentRow["LastUserID"] != DBNull.Value)
            {
                lastUserLink.UserID      = currentRow["LastUserID"].ToType <int>();
                lastUserLink.Style       = currentRow["LastUserStyle"].ToString();
                lastUserLink.ReplaceName = this.Get <BoardSettings>().EnableDisplayName
                              ? currentRow["LastUserDisplayName"].ToString()
                              : currentRow["LastUserName"].ToString();
            }

            if (currentRow["LastPosted"] != DBNull.Value)
            {
                lastPostedDateLabel.DateTime = currentRow["LastPosted"];

                var lastRead =
                    this.Get <IReadTrackCurrentUser>().GetForumTopicRead(
                        currentRow["ForumID"].ToType <int>(),
                        currentRow["TopicID"].ToType <int>(),
                        currentRow["LastForumAccess"].ToType <DateTime?>() ?? DateTimeHelper.SqlDbMinTime(),
                        currentRow["LastTopicAccess"].ToType <DateTime?>() ?? DateTimeHelper.SqlDbMinTime());

                if (DateTime.Parse(currentRow["LastPosted"].ToString()) > lastRead)
                {
                    postIcon.Visible  = true;
                    postIcon.CssClass = "badge badge-success";

                    postIcon.Text = this.GetText("NEW_MESSAGE");
                }
            }

            var lastPostedDateTime = currentRow["LastPosted"].ToType <DateTime>();

            var formattedDatetime = this.Get <BoardSettings>().ShowRelativeTime
                                        ? lastPostedDateTime.ToString(
                "yyyy-MM-ddTHH:mm:ssZ",
                CultureInfo.InvariantCulture)
                                        : this.Get <IDateTime>().Format(
                DateTimeFormat.BothTopic,
                lastPostedDateTime);

            var span = this.Get <BoardSettings>().ShowRelativeTime ? @"<span class=""popover-timeago"">" : "<span>";

            info.TextLocalizedTag  = "by";
            info.TextLocalizedPage = "DEFAULT";
            info.ParamText0        = this.Get <BoardSettings>().EnableDisplayName
                                  ? currentRow["LastUserDisplayName"].ToString()
                                  : currentRow["LastUserName"].ToString();

            info.DataContent = $@"
                          {lastUserLink.RenderToString()}
                          <span class=""fa-stack"">
                                                    <i class=""fa fa-calendar-day fa-stack-1x text-secondary""></i>
                                                    <i class=""fa fa-circle fa-badge-bg fa-inverse fa-outline-inverse""></i>
                                                    <i class=""fa fa-clock fa-badge text-secondary""></i>
                                                </span>&nbsp;{span}{formattedDatetime}</span>
                         ";
        }