public static void FillPost(IDataReader dr, BSPost bsPost)
    {
        bsPost.Title        = dr["Title"].ToString();
        bsPost.PostID       = Convert.ToInt32(dr["PostID"]);
        bsPost.Code         = dr["Code"].ToString();
        bsPost.Content      = dr["Content"].ToString();
        bsPost.State        = (PostStates)Convert.ToInt16(dr["State"]);
        bsPost.AddComment   = Convert.ToBoolean(dr["AddComment"]);
        bsPost.Categories   = bsPost.GetCategoriesHtml();
        bsPost.Tags         = bsPost.GetTagsHtml();
        bsPost.CommentCount = bsPost.GetComments(CommentStates.Approved).Count;
        bsPost.ReadCount    = Convert.ToInt32(dr["ReadCount"]);
        bsPost.UserID       = Convert.ToInt32(dr["UserID"]);
        bsPost.UserName     = BSUser.GetUser(bsPost.UserID).UserName;
        bsPost.Date         = Convert.ToDateTime(dr["CreateDate"]);
        bsPost.UpdateDate   = dr["ModifyDate"] == DBNull.Value
                              ? Convert.ToDateTime(dr["CreateDate"])
                              : Convert.ToDateTime(dr["ModifyDate"]);
        bsPost.Link         = BSHelper.GetLink(bsPost);
        bsPost.Type         = (PostTypes)Convert.ToInt16(dr["Type"]);
        bsPost.Show         = (PostVisibleTypes)Convert.ToInt16(dr["Show"]);
        bsPost.ParentID     = Convert.ToInt32(dr["ParentID"]);
        bsPost.LanguageCode = Convert.ToString(dr["LanguageCode"]);

        bsPost.Metas = BSMeta.GetMetas(bsPost.PostID);
    }
示例#2
0
    public override void DataBind()
    {
        Post.Code = BSHelper.CreateCode(Post.Title);
        Post.Link = BSHelper.GetLink(Post);

        bool anyId = !String.IsNullOrEmpty(HttpContext.Current.Request["PostID"]) || !String.IsNullOrEmpty(HttpContext.Current.Request["Code"]);

        if (anyId)
        {
            Post.Content = Post.Content.Replace("<!--pagebreak -->", "<a id=\"continue\" name=\"continue\"></a>");
            Post.Content = Post.Content.Replace("<!-- pagebreak -->", "<a id=\"continue\" name=\"continue\"></a>");
        }
        else if (Post.Content.Contains("<!--pagebreak -->"))
        {
            Post.Content  = TagCloser(Post.Content.Substring(0, Post.Content.IndexOf("<!--pagebreak -->")));
            Post.Content += String.Format("<a id=\"continue_{0}\" class=\"continue\" href=\"{1}#continue\">{2}</a>", Post.PostID, Post.Link, Language.Get["Continue"]);
        }
        else if (Post.Content.Contains("<!-- pagebreak -->"))
        {
            Post.Content  = TagCloser(Post.Content.Substring(0, Post.Content.IndexOf("<!-- pagebreak -->")));
            Post.Content += String.Format("<a id=\"continue_{0}\" class=\"continue\" href=\"{1}#continue\">{2}</a>", Post.PostID, Post.Link, Language.Get["Continue"]);
        }

        if (Page.User != null && Page.User.IsInRole("admin"))
        {
            const string strHideStyle = "style=\"display:none;\"";
            Post.Content = "<div class=\"post-edit\"><div class=\"post-edit-box\">"
                           + "<a href=\"" + ResolveUrl("~/Admin/" + (Post.Type == 0 ? "Posts" : "Pages") + ".aspx?PostID=" + Post.PostID) + "\">" + Language.Get["Edit"] + "</a>"
                           + "<a " + (Post.State == PostStates.Removed ? strHideStyle : "") + " id=\"post_trash_" + Post.PostID + "\" href=\"javascript:;\" onclick=\"Blogsa.TrashPost(this," + Post.PostID + ");\">" + Language.Get["Trash"] + "</a>"
                           + "<a " + (Post.State == PostStates.Published ? strHideStyle : "") + " id=\"post_publish_" + Post.PostID + "\" href=\"javascript:;\" onclick=\"Blogsa.PublishPost(this," + Post.PostID + ");\">" + Language.Get["Publish"] + "</a>"
                           + "<a " + (Post.State == PostStates.Draft ? strHideStyle : "") + " id=\"post_draft_" + Post.PostID + "\" href=\"javascript:;\" onclick=\"Blogsa.DraftPost(this," + Post.PostID + ");\">" + Language.Get["Draft"] + "</a>"
                           + "<span></span>"
                           + "</div>"
                           + Post.Content + "</div>";
        }

        PlaceHolder ph = (PlaceHolder)this.FindControl("Content");

        if (ph != null)
        {
            Regex         rex         = new Regex("<!--widget-(\\w{0,120})-->");
            List <string> lstContents = new List <string>();

            foreach (Match item in rex.Matches(Post.Content))
            {
                int iStart = Post.Content.IndexOf(item.Value);
                lstContents.Add(Post.Content.Substring(0, iStart));
                lstContents.Add(item.Value);
                Post.Content = Post.Content.Substring(iStart + item.Value.Length, Post.Content.Length - iStart - item.Value.Length);
            }
            lstContents.Add(Post.Content);

            for (int i = 0; i < lstContents.Count; i++)
            {
                string str = lstContents[i];
                if (rex.Match(str).Success)
                {
                    ph.Controls.Add(this.LoadControl("~/Widgets/" + str.Substring(11, str.Length - 14) + "/View.ascx"));
                }
                else
                {
                    Literal lt = new Literal();
                    lt.Text = str;
                    ph.Controls.Add(lt);
                }
            }
        }

        BSPost.CurrentPost = this.Post;
        CancelEventArgs eventArgs = new CancelEventArgs();

        BSPost.OnShowing(this.Post, eventArgs);

        if (!eventArgs.Cancel)
        {
            base.DataBind();
            BSPost.OnShowed(this.Post, EventArgs.Empty);
        }
    }