protected void btnDelete_Click(object sender, EventArgs e)
        {
            int forumPostID = 0;

            int.TryParse(lblForumPostID.Text, out forumPostID);
            ForumPost forumPost = ForumManager.GetPostByID(forumPostID);

            if (forumPost != null)
            {
                ForumTopic forumTopic = forumPost.Topic;
                if (!ForumManager.IsUserAllowedToDeletePost(NopContext.Current.User, forumPost))
                {
                    string loginURL = CommonHelper.GetLoginPageURL(true);
                    Response.Redirect(loginURL);
                }

                ForumManager.DeletePost(forumPost.ForumPostID);

                string url = string.Empty;
                if (forumTopic != null)
                {
                    url = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                }
                else
                {
                    url = SEOHelper.GetForumMainURL();
                }
                Response.Redirect(url);
            }
        }
Beispiel #2
0
        protected string CreatePostPager(ForumTopic forumTopic)
        {
            int pageSize = 10;

            if (ForumManager.PostsPageSize > 0)
            {
                pageSize = ForumManager.PostsPageSize;
            }
            string queryStringParam = "p";
            string result           = string.Empty;

            int NumToDisplay = 4;
            int PageCount    = (int)Math.Ceiling((double)forumTopic.NumPosts / pageSize);

            if (PageCount > 1)
            {
                if (PageCount > NumToDisplay)
                {
                    result += createLink(SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID), "1");
                    result += " ... ";
                    bool first = true;

                    for (int i = (PageCount - (NumToDisplay - 1)); i < PageCount; i++)
                    {
                        int iPost = i + 1;

                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            result += ", ";
                        }

                        result += createLink(SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID, queryStringParam, iPost), iPost.ToString());
                    }
                }
                else
                {
                    bool first = true;
                    for (int i = 0; i < PageCount; i++)
                    {
                        int iPost = i + 1;

                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            result += ", ";
                        }

                        result += createLink(SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID, queryStringParam, iPost), iPost.ToString());
                    }
                }
            }
            return(result);
        }
Beispiel #3
0
        protected void rptrLatestPosts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ForumPost forumPost = e.Item.DataItem as ForumPost;

                HyperLink hlTopic = e.Item.FindControl("hlTopic") as HyperLink;
                if (hlTopic != null)
                {
                    ForumTopic forumTopic = forumPost.Topic;
                    if (forumTopic != null)
                    {
                        hlTopic.Text        = Server.HtmlEncode(forumTopic.Subject);
                        hlTopic.NavigateUrl = SEOHelper.GetForumTopicURL(forumPost.TopicID);
                    }
                }

                Label lblPosted = e.Item.FindControl("lblPosted") as Label;
                if (lblPosted != null)
                {
                    lblPosted.Text = DateTimeHelper.ConvertToUserTime(forumPost.CreatedOn).ToString("MMMM dd, yyyy");
                }

                Label lblPost = e.Item.FindControl("lblPost") as Label;
                if (lblPost != null)
                {
                    lblPost.Text = ForumManager.FormatPostText(forumPost.Text);
                }
            }
        }
Beispiel #4
0
        protected void rptrTopics_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ForumTopic forumTopic = e.Item.DataItem as ForumTopic;
                Customer   customer   = forumTopic.User;

                HyperLink hlTopic = e.Item.FindControl("hlTopic") as HyperLink;
                if (hlTopic != null)
                {
                    hlTopic.NavigateUrl = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                    hlTopic.Text        = Server.HtmlEncode(forumTopic.Subject);
                }

                HyperLink hlTopicStarter = e.Item.FindControl("hlTopicStarter") as HyperLink;
                if (hlTopicStarter != null)
                {
                    if (CustomerManager.AllowViewingProfiles)
                    {
                        if (customer != null)
                        {
                            hlTopicStarter.Text        = Server.HtmlEncode(CustomerManager.FormatUserName(customer));
                            hlTopicStarter.NavigateUrl = SEOHelper.GetUserProfileURL(customer.CustomerID);
                        }
                    }
                    else
                    {
                        hlTopicStarter.Visible = false;
                    }
                }

                Label lblTopicStarter = e.Item.FindControl("lblTopicStarter") as Label;
                if (lblTopicStarter != null)
                {
                    if (!CustomerManager.AllowViewingProfiles)
                    {
                        if (customer != null)
                        {
                            lblTopicStarter.Text = Server.HtmlEncode(CustomerManager.FormatUserName(customer));
                        }
                    }
                    else
                    {
                        lblTopicStarter.Visible = false;
                    }
                }
            }
        }
Beispiel #5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);
                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                ForumManager.MoveTopic(forumTopic.ForumTopicID, ctrlForumSelector.SelectedForumId);
                string topicURL = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                Response.Redirect(topicURL);
            }
            catch (Exception exc)
            {
                pnlError.Visible   = true;
                lErrorMessage.Text = Server.HtmlEncode(exc.Message);
            }
        }
Beispiel #6
0
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     try
     {
         ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);
         if (forumTopic != null)
         {
             string topicUrl = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
             Response.Redirect(topicUrl);
         }
         else
         {
             Response.Redirect(SEOHelper.GetForumMainURL());
         }
     }
     catch (Exception exc)
     {
         pnlError.Visible   = true;
         lErrorMessage.Text = Server.HtmlEncode(exc.Message);
     }
 }
Beispiel #7
0
        public void BindData()
        {
            if (forumPost != null)
            {
                lblLastPostDate.Text = DateTimeHelper.ConvertToUserTime(forumPost.CreatedOn).ToString("MMMM dd, yyyy");
                ForumTopic forumTopic = forumPost.Topic;
                if (forumTopic != null)
                {
                    hlTopic.Text        = Server.HtmlEncode(ForumManager.StripTopicSubject(forumTopic.Subject));
                    hlTopic.ToolTip     = Server.HtmlEncode(forumTopic.Subject);
                    hlTopic.NavigateUrl = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                }
                Customer customer = forumPost.User;
                if (customer != null)
                {
                    if (CustomerManager.AllowViewingProfiles)
                    {
                        hlUser.Text        = Server.HtmlEncode(CustomerManager.FormatUserName(customer));
                        hlUser.NavigateUrl = SEOHelper.GetUserProfileURL(customer.CustomerID);
                        lblUser.Visible    = false;
                    }
                    else
                    {
                        lblUser.Text   = Server.HtmlEncode(CustomerManager.FormatUserName(customer));
                        hlUser.Visible = false;
                    }
                }

                pnlPostInfo.Visible = true;
                pnlNoPost.Visible   = false;
            }
            else
            {
                pnlPostInfo.Visible = false;
                pnlNoPost.Visible   = true;
            }
        }
Beispiel #8
0
        protected void rptrSearchResults_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ForumTopic forumTopic = e.Item.DataItem as ForumTopic;
                Customer   customer   = forumTopic.User;

                Panel pnlTopicImage = e.Item.FindControl("pnlTopicImage") as Panel;
                if (pnlTopicImage != null)
                {
                    switch (forumTopic.TopicType)
                    {
                    case ForumTopicTypeEnum.Normal:
                        pnlTopicImage.CssClass = "post";
                        break;

                    case ForumTopicTypeEnum.Announcement:
                        pnlTopicImage.CssClass = "postannoucement";
                        break;

                    default:
                        pnlTopicImage.CssClass = "post";
                        break;
                    }
                }

                Label lblTopicType = e.Item.FindControl("lblTopicType") as Label;
                if (lblTopicType != null)
                {
                    switch (forumTopic.TopicType)
                    {
                    case ForumTopicTypeEnum.Announcement:
                        lblTopicType.Text = string.Format("[{0}]", GetLocaleResourceString("Forum.Announcement"));
                        break;

                    default:
                        lblTopicType.Visible = false;
                        break;
                    }
                }

                HyperLink hlTopic = e.Item.FindControl("hlTopic") as HyperLink;
                if (hlTopic != null)
                {
                    hlTopic.NavigateUrl = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                    hlTopic.Text        = Server.HtmlEncode(forumTopic.Subject);
                }

                HyperLink hlTopicStarter = e.Item.FindControl("hlTopicStarter") as HyperLink;
                if (hlTopicStarter != null)
                {
                    if (CustomerManager.AllowViewingProfiles)
                    {
                        if (customer != null)
                        {
                            hlTopicStarter.Text        = Server.HtmlEncode(CustomerManager.FormatUserName(customer));
                            hlTopicStarter.NavigateUrl = SEOHelper.GetUserProfileURL(customer.CustomerID);
                        }
                    }
                    else
                    {
                        hlTopicStarter.Visible = false;
                    }
                }

                Label lblTopicStarter = e.Item.FindControl("lblTopicStarter") as Label;
                if (lblTopicStarter != null)
                {
                    if (!CustomerManager.AllowViewingProfiles)
                    {
                        if (customer != null)
                        {
                            lblTopicStarter.Text = Server.HtmlEncode(CustomerManager.FormatUserName(customer));
                        }
                    }
                    else
                    {
                        lblTopicStarter.Visible = false;
                    }
                }
            }
        }
Beispiel #9
0
        public void BindData()
        {
            hlHome.NavigateUrl       = CommonHelper.GetStoreLocation();
            hlForumsHome.NavigateUrl = SEOHelper.GetForumMainURL();

            //topic
            ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);

            if (forumTopic != null)
            {
                hlForumTopic.NavigateUrl = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                hlForumTopic.Text        = Server.HtmlEncode(forumTopic.Subject);
            }
            else
            {
                phForumTopic.Visible = false;
            }

            //forum
            Forum forum = null;

            if (forumTopic != null)
            {
                forum = ForumManager.GetForumByID(forumTopic.ForumID);
            }
            else
            {
                forum = ForumManager.GetForumByID(this.ForumID);
            }

            if (forum != null)
            {
                hlForum.NavigateUrl = SEOHelper.GetForumURL(forum);
                hlForum.Text        = Server.HtmlEncode(forum.Name);
            }
            else
            {
                phForum.Visible = false;
            }

            //forum group
            ForumGroup forumGroup = null;

            if (forum != null)
            {
                forumGroup = ForumManager.GetForumGroupByID(forum.ForumGroupID);
            }
            else
            {
                forumGroup = ForumManager.GetForumGroupByID(this.ForumGroupID);
            }

            if (forumGroup != null)
            {
                hlForumGroup.NavigateUrl = SEOHelper.GetForumGroupURL(forumGroup);
                hlForumGroup.Text        = Server.HtmlEncode(forumGroup.Name);
            }
            else
            {
                phForumTopic.Visible = false;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string text = string.Empty;

                switch (ForumManager.ForumEditor)
                {
                case EditorTypeEnum.SimpleTextBox:
                {
                    text = txtTopicBodySimple.Text.Trim();
                }
                break;

                case EditorTypeEnum.BBCodeEditor:
                {
                    text = txtTopicBodyBBCode.Text.Trim();
                }
                break;

                case EditorTypeEnum.HtmlEditor:
                {
                    text = txtTopicBodyHtml.Value;
                }
                break;

                default:
                    break;
                }

                string             subject   = txtTopicTitle.Text;
                ForumTopicTypeEnum topicType = ForumTopicTypeEnum.Normal;
                bool subscribe = cbSubscribe.Checked;

                string IPAddress = string.Empty;
                if (HttpContext.Current != null && HttpContext.Current.Request != null)
                {
                    IPAddress = HttpContext.Current.Request.UserHostAddress;
                }

                DateTime nowDT = DateTime.Now;

                if (ForumManager.IsUserAllowedToSetTopicPriority(NopContext.Current.User))
                {
                    topicType = (ForumTopicTypeEnum)Enum.ToObject(typeof(ForumTopicTypeEnum), int.Parse(ddlPriority.SelectedItem.Value));
                }

                text = text.Trim();
                if (String.IsNullOrEmpty(text))
                {
                    throw new NopException(GetLocaleResourceString("Forum.TextCannotBeEmpty"));
                }

                if (this.AddTopic)
                {
                    #region Adding topic
                    Forum forum = ForumManager.GetForumByID(this.ForumID);
                    if (forum == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainURL());
                    }

                    if (!ForumManager.IsUserAllowedToCreateTopic(NopContext.Current.User, forum))
                    {
                        string loginURL = CommonHelper.GetLoginPageURL(true);
                        Response.Redirect(loginURL);
                    }

                    subject = subject.Trim();
                    if (String.IsNullOrEmpty(subject))
                    {
                        throw new NopException(GetLocaleResourceString("Forum.TopicSubjectCannotBeEmpty"));
                    }

                    ForumTopic forumTopic = ForumManager.InsertTopic(forum.ForumID, NopContext.Current.User.CustomerID,
                                                                     topicType, subject, 0, 0, 0, 0, null, nowDT, nowDT, true);

                    ForumPost forumPost = ForumManager.InsertPost(forumTopic.ForumTopicID, NopContext.Current.User.CustomerID,
                                                                  text, IPAddress, nowDT, nowDT, false);

                    forumTopic = ForumManager.UpdateTopic(forumTopic.ForumTopicID, forumTopic.ForumID,
                                                          forumTopic.UserID, forumTopic.TopicType, forumTopic.Subject, 1,
                                                          0, forumPost.ForumPostID, forumTopic.UserID,
                                                          forumPost.CreatedOn, forumTopic.CreatedOn, nowDT);

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                    {
                        if (subscribe)
                        {
                            ForumSubscription forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                                  NopContext.Current.User.CustomerID, 0, forumTopic.ForumTopicID, nowDT);
                        }
                    }

                    string topicURL = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                    Response.Redirect(topicURL);
                    #endregion
                }
                else if (this.EditTopic)
                {
                    #region Editing topic
                    ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);
                    if (forumTopic == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainURL());
                    }

                    if (!ForumManager.IsUserAllowedToEditTopic(NopContext.Current.User, forumTopic))
                    {
                        string loginURL = CommonHelper.GetLoginPageURL(true);
                        Response.Redirect(loginURL);
                    }

                    subject = subject.Trim();
                    if (String.IsNullOrEmpty(subject))
                    {
                        throw new NopException(GetLocaleResourceString("Forum.TopicSubjectCannotBeEmpty"));
                    }

                    forumTopic = ForumManager.UpdateTopic(forumTopic.ForumTopicID, forumTopic.ForumID,
                                                          forumTopic.UserID, topicType, subject, forumTopic.NumPosts,
                                                          forumTopic.Views, forumTopic.LastPostID, forumTopic.LastPostUserID,
                                                          forumTopic.LastPostTime, forumTopic.CreatedOn, nowDT);

                    ForumPost firstPost = forumTopic.FirstPost;
                    if (firstPost != null)
                    {
                        firstPost = ForumManager.UpdatePost(firstPost.ForumPostID, firstPost.TopicID,
                                                            firstPost.UserID, text, firstPost.IPAddress, firstPost.CreatedOn, nowDT);
                    }
                    else
                    {
                        //error
                        firstPost = ForumManager.InsertPost(forumTopic.ForumTopicID,
                                                            forumTopic.UserID, text, IPAddress, forumTopic.CreatedOn, nowDT, false);
                    }

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerID))
                    {
                        ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                               0, forumTopic.ForumTopicID, 1, 0).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerID, 0, forumTopic.ForumTopicID, nowDT);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionID);
                            }
                        }
                    }

                    string topicURL = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID);
                    Response.Redirect(topicURL);
                    #endregion
                }
                else if (this.AddPost)
                {
                    #region Adding post
                    ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);
                    if (forumTopic == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainURL());
                    }

                    if (!ForumManager.IsUserAllowedToCreatePost(NopContext.Current.User, forumTopic))
                    {
                        string loginURL = CommonHelper.GetLoginPageURL(true);
                        Response.Redirect(loginURL);
                    }

                    ForumPost forumPost = ForumManager.InsertPost(this.ForumTopicID, NopContext.Current.User.CustomerID,
                                                                  text, IPAddress, nowDT, nowDT, true);

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerID))
                    {
                        ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                               0, forumPost.TopicID, 1, 0).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerID, 0, forumPost.TopicID, nowDT);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionID);
                            }
                        }
                    }


                    int pageSize = 10;
                    if (ForumManager.PostsPageSize > 0)
                    {
                        pageSize = ForumManager.PostsPageSize;
                    }
                    int    pageIndex = ForumManager.CalculateTopicPageIndex(forumPost.TopicID, pageSize, forumPost.ForumPostID);
                    string topicURL  = SEOHelper.GetForumTopicURL(forumPost.TopicID, "p", pageIndex + 1, forumPost.ForumPostID);
                    Response.Redirect(topicURL);
                    #endregion
                }
                else if (this.EditPost)
                {
                    #region Editing post
                    ForumPost forumPost = ForumManager.GetPostByID(this.ForumPostID);
                    if (forumPost == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainURL());
                    }

                    if (!ForumManager.IsUserAllowedToEditPost(NopContext.Current.User, forumPost))
                    {
                        string loginURL = CommonHelper.GetLoginPageURL(true);
                        Response.Redirect(loginURL);
                    }

                    forumPost = ForumManager.UpdatePost(forumPost.ForumPostID, forumPost.TopicID,
                                                        forumPost.UserID, text, forumPost.IPAddress, forumPost.CreatedOn, nowDT);

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerID))
                    {
                        ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                               0, forumPost.TopicID, 1, 0).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerID, 0, forumPost.TopicID, nowDT);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionID);
                            }
                        }
                    }

                    int pageSize = 10;
                    if (ForumManager.PostsPageSize > 0)
                    {
                        pageSize = ForumManager.PostsPageSize;
                    }
                    int    pageIndex = ForumManager.CalculateTopicPageIndex(forumPost.TopicID, pageSize, forumPost.ForumPostID);
                    string topicURL  = SEOHelper.GetForumTopicURL(forumPost.TopicID, "p", pageIndex + 1, forumPost.ForumPostID);
                    Response.Redirect(topicURL);
                    #endregion
                }
            }
            catch (Exception exc)
            {
                pnlError.Visible   = true;
                lErrorMessage.Text = Server.HtmlEncode(exc.Message);
            }
        }