Esempio n. 1
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);
        }
    }