Exemple #1
0
        public YafAlbum.ReturnClass HandleMultiQuote(
            [NotNull] string buttonId,
            [NotNull] bool multiquoteButton,
            [NotNull] int messageId,
            [NotNull] int topicId,
            [NotNull] string buttonCssClass)
        {
            var yafSession = this.Get<IYafSession>();

            var multiQuote = new MultiQuote { MessageID = messageId, TopicID = topicId };

            if (multiquoteButton)
            {
                if (yafSession.MultiQuoteIds != null)
                {
                    if (!yafSession.MultiQuoteIds.Any(m => m.MessageID.Equals(messageId)))
                    {
                        yafSession.MultiQuoteIds.Add(multiQuote);
                    }
                }
                else
                {
                    yafSession.MultiQuoteIds = new List<MultiQuote> { multiQuote };
                }

                buttonCssClass += " Checked";
            }
            else
            {
                if (yafSession.MultiQuoteIds != null && yafSession.MultiQuoteIds.Any(m => m.MessageID.Equals(messageId)))
                {
                    yafSession.MultiQuoteIds.Remove(multiQuote);
                }

                buttonCssClass = "MultiQuoteButton";
            }

            return new YafAlbum.ReturnClass { Id = buttonId, NewTitle = buttonCssClass };
        }
Exemple #2
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </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 Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            this.PageContext.QueryIDs = new QueryStringIDHelper(new[] { "m", "t", "q", "page" }, false);

            TypedMessageList currentMessage = null;
            DataRow topicInfo = LegacyDb.topic_info(this.PageContext.PageTopicID);

            // we reply to a post with a quote
            if (this.QuotedMessageID != null)
            {
                currentMessage =
                    LegacyDb.MessageList(this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("q").ToType<int>())
                        .FirstOrDefault();

                this.OriginalMessage = currentMessage.Message;

                if (currentMessage.TopicID.ToType<int>() != this.PageContext.PageTopicID)
                {
                    YafBuildLink.AccessDenied();
                }

                if (!this.CanQuotePostCheck(topicInfo))
                {
                    YafBuildLink.AccessDenied();
                }

                this.PollGroupId = currentMessage.PollID.ToType<int>().IsNullOrEmptyDBField()
                    ? 0
                    : currentMessage.PollID;

                // if this is a quoted message (a new reply with a quote)  we should transfer the TopicId value only to return
                this.PollList.TopicId = this.TopicID.ToType<int>();

                if (this.TopicID == null)
                {
                    this.PollList.TopicId = currentMessage.TopicID.ToType<int>().IsNullOrEmptyDBField()
                        ? 0
                        : currentMessage.TopicID.ToType<int>();
                }
            }
            else if (this.EditMessageID != null)
            {
                currentMessage = LegacyDb.MessageList(this.EditMessageID.ToType<int>()).FirstOrDefault();

                this.OriginalMessage = currentMessage.Message;

                this._ownerUserId = currentMessage.UserID.ToType<int>();

                if (!this.CanEditPostCheck(currentMessage, topicInfo))
                {
                    YafBuildLink.AccessDenied();
                }

                this.PollGroupId = currentMessage.PollID.ToType<int>().IsNullOrEmptyDBField()
                    ? 0
                    : currentMessage.PollID;

                // we edit message and should transfer both the message ID and TopicID for PageLinks. 
                this.PollList.EditMessageId = this.EditMessageID.ToType<int>();

                if (this.TopicID == null)
                {
                    this.PollList.TopicId = currentMessage.TopicID.ToType<int>().IsNullOrEmptyDBField()
                        ? 0
                        : currentMessage.TopicID.ToType<int>();
                }
            }

            if (this.PageContext.PageForumID == 0)
            {
                YafBuildLink.AccessDenied();
            }

            if (this.Get<HttpRequestBase>()["t"] == null && this.Get<HttpRequestBase>()["m"] == null
                && !this.PageContext.ForumPostAccess)
            {
                YafBuildLink.AccessDenied();
            }

            if (this.Get<HttpRequestBase>()["t"] != null && !this.PageContext.ForumReplyAccess)
            {
                YafBuildLink.AccessDenied();
            }

            // Message.EnableRTE = PageContext.BoardSettings.AllowRichEdit;
            this._forumEditor.StyleSheet = this.Get<ITheme>().BuildThemePath("theme.css");
            this._forumEditor.BaseDir = "{0}Scripts".FormatWith(YafForumInfo.ForumClientFileRoot);

            this.Title.Text = this.GetText("NEWTOPIC");

            if (this.Get<YafBoardSettings>().MaxPostSize == 0)
            {
                this.LocalizedLblMaxNumberOfPost.Visible = false;
            }
            else
            {
                this.LocalizedLblMaxNumberOfPost.Visible = true;
                this.LocalizedLblMaxNumberOfPost.Param0 =
                    this.Get<YafBoardSettings>().MaxPostSize.ToString(CultureInfo.InvariantCulture);
            }

            if (!this.IsPostBack)
            {
                if (this.Get<YafBoardSettings>().EnableTopicDescription)
                {
                    this.DescriptionRow.Visible = true;
                }

                // helper bool -- true if this is a completely new topic...
                bool isNewTopic = (this.TopicID == null) && (this.QuotedMessageID == null)
                                  && (this.EditMessageID == null);

                this.Priority.Items.Add(new ListItem(this.GetText("normal"), "0"));
                this.Priority.Items.Add(new ListItem(this.GetText("sticky"), "1"));
                this.Priority.Items.Add(new ListItem(this.GetText("announcement"), "2"));
                this.Priority.SelectedIndex = 0;

                if (this.Get<YafBoardSettings>().EnableTopicStatus)
                {
                    this.StatusRow.Visible = true;

                    this.TopicStatus.Items.Add(new ListItem("   ", "-1"));

                    foreach (DataRow row in LegacyDb.TopicStatus_List(this.PageContext.PageBoardID).Rows)
                    {
                        var text = this.GetText("TOPIC_STATUS", row["TopicStatusName"].ToString());

                        this.TopicStatus.Items.Add(
                            new ListItem(
                                text.IsSet() ? text : row["DefaultDescription"].ToString(),
                                row["TopicStatusName"].ToString()));
                    }

                    this.TopicStatus.SelectedIndex = 0;
                }

                // Allow the Styling of Topic Titles only for Mods or Admins
                if (this.Get<YafBoardSettings>().UseStyledTopicTitles
                    && (this.PageContext.ForumModeratorAccess || this.PageContext.IsAdmin))
                {
                    this.StyleRow.Visible = true;
                }
                else
                {
                    this.StyleRow.Visible = false;
                }

                this.EditReasonRow.Visible = false;

                this.PriorityRow.Visible = this.PageContext.ForumPriorityAccess;

                // Show post to blog option only to a new post
                this.BlogRow.Visible = this.Get<YafBoardSettings>().AllowPostToBlog && isNewTopic
                                       && !this.PageContext.IsGuest;

                // update options...
                this.PostOptions1.Visible = !this.PageContext.IsGuest;
                this.PostOptions1.PersistantOptionVisible = this.PageContext.ForumPriorityAccess;
                this.PostOptions1.AttachOptionVisible = this.PageContext.ForumUploadAccess;
                this.PostOptions1.WatchOptionVisible = !this.PageContext.IsGuest;
                this.PostOptions1.PollOptionVisible = this.PageContext.ForumPollAccess && isNewTopic;

                ////this.Attachments1.Visible = !this.PageContext.IsGuest;

                // get topic and forum information
                /*DataRow topicInfo = LegacyDb.topic_info(this.PageContext.PageTopicID);
                                using (DataTable dt = LegacyDb.forum_list(this.PageContext.PageBoardID, this.PageContext.PageForumID))
                                {
                                        DataRow forumInfo = dt.Rows[0];
                                }*/

                if (!this.PageContext.IsGuest)
                {
                    /*this.Attachments1.Visible = this.PageContext.ForumUploadAccess;
                                        this.Attachments1.Forum = forumInfo;
                                        this.Attachments1.Topic = topicInfo;
                                        // todo message id*/
                    this.PostOptions1.WatchChecked = this.PageContext.PageTopicID > 0
                        ? this.TopicWatchedId(this.PageContext.PageUserID, this.PageContext.PageTopicID).HasValue
                        : new CombinedUserDataHelper(this.PageContext.PageUserID).AutoWatchTopics;
                }

                if ((this.PageContext.IsGuest && this.Get<YafBoardSettings>().EnableCaptchaForGuests)
                    || (this.Get<YafBoardSettings>().EnableCaptchaForPost && !this.PageContext.IsCaptchaExcluded))
                {
                    this.imgCaptcha.ImageUrl = "{0}resource.ashx?c=1".FormatWith(YafForumInfo.ForumClientFileRoot);
                    this.tr_captcha1.Visible = true;
                    this.tr_captcha2.Visible = true;
                }

                if (this.PageContext.Settings.LockedForum == 0)
                {
                    this.PageLinks.AddRoot();
                    this.PageLinks.AddLink(
                        this.PageContext.PageCategoryName,
                        YafBuildLink.GetLink(ForumPages.forum, "c={0}", this.PageContext.PageCategoryID));
                }

                this.PageLinks.AddForum(this.PageContext.PageForumID);

                // check if it's a reply to a topic...
                if (this.TopicID != null)
                {
                    this.InitReplyToTopic();

                    this.PollList.TopicId = this.TopicID.ToType<int>();
                }

                // If currentRow != null, we are quoting a post in a new reply, or editing an existing post
                if (currentMessage != null)
                {
                    this.OriginalMessage = currentMessage.Message;

                    if (this.QuotedMessageID != null)
                    {
                        if (this.Get<IYafSession>().MultiQuoteIds != null)
                        {
                            var quoteId = this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("q").ToType<int>();
                            var multiQuote = new MultiQuote { MessageID = quoteId, TopicID = this.PageContext.PageTopicID };

                            if (
                                !this.Get<IYafSession>()
                                    .MultiQuoteIds.Any(m => m.MessageID.Equals(quoteId)))
                            {
                                this.Get<IYafSession>()
                                    .MultiQuoteIds.Add(
                                        multiQuote);
                            }

                            var messages = LegacyDb.post_list(
                                this.TopicID,
                                this.PageContext.PageUserID,
                                this.PageContext.PageUserID,
                                0,
                                false,
                                false,
                                false,
                                DateTimeHelper.SqlDbMinTime(),
                                DateTime.UtcNow,
                                DateTimeHelper.SqlDbMinTime(),
                                DateTime.UtcNow,
                                0,
                                500,
                                1,
                                0,
                                0,
                                false,
                                0);

                            // quoting a reply to a topic...
                            foreach (
                                TypedMessageList msg in
                                    this.Get<IYafSession>()
                                        .MultiQuoteIds.Select(
                                            item =>
                                            messages.AsEnumerable()
                                                .Select(t => new TypedMessageList(t))
                                                .Where(m => m.MessageID == item.MessageID))
                                        .SelectMany(quotedMessage => quotedMessage))
                            {
                                this.InitQuotedReply(msg);
                            }

                            // Clear Multiquotes
                            this.Get<IYafSession>().MultiQuoteIds = null;
                        }
                        else
                        {
                            this.InitQuotedReply(currentMessage);
                        }

                        this.PollList.TopicId = this.TopicID.ToType<int>();
                    }
                    else if (this.EditMessageID != null)
                    {
                        // editing a message...
                        this.InitEditedPost(currentMessage);
                        this.PollList.EditMessageId = this.EditMessageID.ToType<int>();
                    }

                    this.PollGroupId = currentMessage.PollID.ToType<int>().IsNullOrEmptyDBField()
                        ? 0
                        : currentMessage.PollID.ToType<int>();
                }

                // add the "New Topic" page link last...
                if (isNewTopic)
                {
                    this.PageLinks.AddLink(this.GetText("NEWTOPIC"));
                }

                // form user is only for "Guest"
                this.From.Text = this.Get<IUserDisplayName>().GetName(this.PageContext.PageUserID);
                if (this.User != null)
                {
                    this.FromRow.Visible = false;
                }

                /*   if (this.TopicID == null)
                                {
                                        this.PollList.TopicId = (currentRow["TopicID"].IsNullOrEmptyDBField() ? 0 : Convert.ToInt32(currentRow["TopicID"]));
                                } */
            }

            this.PollList.PollGroupId = this.PollGroupId;
        }