Beispiel #1
0
        public DayExtra GetDayExtra(DateTime date)
        {
            DayExtra ex = data.GetDayExtra(date);

            ex.Load();
            return(ex);
        }
        private void add_Click(object sender, System.EventArgs e)
        {
            if (SiteConfig.GetSiteConfig().CommentSpamGuard)
            {
                string word = SiteConfig.GetCommentWords()[(int)ViewState["spamCode"]];
                if (!word.Equals(securityWord.Text))
                {
                    // UNDONE : Should show an error page...
                    //
                    return;
                }
            }

            string entryId = ViewState["entryId"].ToString().ToUpper();

            if (rememberMe.Checked)
            {
                Response.Cookies.Add(new HttpCookie("name", name.Text));
                Response.Cookies.Add(new HttpCookie("email", email.Text));
                Response.Cookies.Add(new HttpCookie("homepage", homepage.Text));
            }
            EntryIdCache ecache = new EntryIdCache();

            ecache.Ensure(data);

            DateTime dateFound = new DateTime();
            bool     found     = false;

            foreach (EntryIdCacheEntry ece in ecache.Entries)
            {
                if (ece.EntryId.ToUpper() == entryId)
                {
                    dateFound = ece.Date;
                    entryId   = ece.EntryId;
                    found     = true;
                    break;
                }
            }

            if (found)
            {
                if (SiteConfig.GetSiteConfig().AllowComments)
                {
                    DayExtra extra = data.GetDayExtra(dateFound);
                    extra.Load();
                    Comment c = new Comment();
                    c.Initialize();
                    c.Author         = name.Text;
                    c.AuthorEmail    = email.Text;
                    c.AuthorHomepage = homepage.Text;
                    c.Content        = Server.HtmlEncode(comment.Text);
                    c.TargetEntryId  = entryId;
                    extra.Comments.Add(c);
                    extra.Save();

                    data.IncrementExtraChange();
                }

                name.Text     = "";
                email.Text    = "";
                homepage.Text = "";
                comment.Text  = "";
                Response.Redirect("default.aspx", false);
            }
        }
        private void CommentView_PreRender(object sender, System.EventArgs e)
        {
            string       entryId = (string)ViewState["entryId"];
            EntryIdCache ecache  = new EntryIdCache();

            ecache.Ensure(data);
            Control root = comments;

            DateTime found = new DateTime();

            foreach (EntryIdCacheEntry ece in ecache.Entries)
            {
                if (ece.EntryId.ToUpper() == entryId)
                {
                    found   = ece.Date;
                    entryId = ece.EntryId;
                    break;
                }
            }

            bool     obfuscateEmail = SiteConfig.GetSiteConfig().ObfuscateEmail;
            DayExtra extra          = data.GetDayExtra(found);

            extra.Load();

            foreach (DayEntry day in data.Days)
            {
                if (day.Date == found)
                {
                    day.Load();
                    foreach (Entry entry in day.Entries)
                    {
                        if (entry.EntryId == entryId)
                        {
                            EntryView entryView = (EntryView)LoadControl("EntryView.ascx");
                            entryView.Data  = data;
                            entryView.Entry = entry;
                            entryView.Extra = extra;
                            comments.Controls.Add(entryView);
                        }
                    }
                }
            }

            commentSpamGuard.Visible = SiteConfig.GetSiteConfig().CommentSpamGuard;
            if (SiteConfig.GetSiteConfig().CommentSpamGuard)
            {
                System.Security.Cryptography.RandomNumberGenerator r = System.Security.Cryptography.RandomNumberGenerator.Create();
                byte[] randomData = new byte[4];
                r.GetBytes(randomData);
                int code = 0;
                for (int i = 0; i < randomData.Length; i++)
                {
                    code += randomData[i];
                }
                code = code % SiteConfig.GetCommentWords().Length;
                securityWordImage.ImageUrl = BlogXUtils.RelativeToRoot("verifyimagegen.ashx?code=" + code);
                ViewState["spamCode"]      = code;
            }


            foreach (Comment c in extra.GetCommentsFor(entryId))
            {
                SingleCommentView view = (SingleCommentView)LoadControl("SingleCommentView.ascx");
                view.Comment        = c;
                view.ObfuscateEmail = obfuscateEmail;
                root.Controls.Add(view);
            }
        }
Beispiel #4
0
        private void Page_PreRender(object sender, System.EventArgs e)
        {
            Control            root         = this;
            HtmlGenericControl entryControl = new HtmlGenericControl("div");

            entryControl.Attributes["class"] = "entry";
            root.Controls.Add(entryControl);

            HtmlGenericControl entryTitle = new HtmlGenericControl("h3");

            entryTitle.Attributes["class"] = "entryTitle";
            if (EntryTitleAsLink)
            {
                HyperLink entryTitleLink = new HyperLink();
                entryTitleLink.NavigateUrl = BlogXUtils.RelativeToRoot("PermaLink.aspx/" + entry.EntryId);
                entryTitleLink.Text        = entry.Title;
                entryTitle.Controls.Add(entryTitleLink);
            }
            else
            {
                entryTitle.Controls.Add(new LiteralControl(entry.Title));
            }
            entryControl.Controls.Add(entryTitle);

            HtmlGenericControl entryBody = new HtmlGenericControl("div");

            entryBody.Attributes["class"] = "entryBody";
            entryBody.Controls.Add(new LiteralControl(entry.Content));
            entryControl.Controls.Add(entryBody);

            HtmlGenericControl entryFooter = new HtmlGenericControl("p");

            entryFooter.Attributes["class"] = "entryFooter";
            entryControl.Controls.Add(entryFooter);

            HyperLink entryDate = new HyperLink();

            entryDate.CssClass    = "permalink";
            entryDate.NavigateUrl = BlogXUtils.RelativeToRoot("PermaLink.aspx/" + entry.EntryId);
            entryDate.Text        = entry.Created.ToString(dateFormat);
            entryFooter.Controls.Add(entryDate);


            if (SiteConfig.GetSiteConfig().AllowComments)
            {
                entryFooter.Controls.Add(new LiteralControl(" | "));

                extra.Load();
                CommentCollection  entryComments = extra.GetCommentsFor(entry.EntryId);
                HtmlGenericControl comments      = new HtmlGenericControl("span");
                comments.Attributes["class"] = "comments";

                if (entryComments.Count == 0)
                {
                    HyperLink comment = new HyperLink();
                    comment.Text        = "Add comment";
                    comment.NavigateUrl = BlogXUtils.RelativeToRoot("CommentView.aspx/" + entry.EntryId);
                    comments.Controls.Add(comment);
                }
                else
                {
                    HyperLink comment = new HyperLink();
                    comment.Text        = "Comments [" + entryComments.Count + "]";
                    comment.NavigateUrl = BlogXUtils.RelativeToRoot("CommentView.aspx/" + entry.EntryId);
                    comments.Controls.Add(comment);
                }
                entryFooter.Controls.Add(comments);
            }


            if (entry.Categories != null && entry.Categories.Length > 0)
            {
                entryFooter.Controls.Add(new LiteralControl(" | "));

                HtmlGenericControl categories = new HtmlGenericControl("span");
                categories.Attributes["class"] = "categories";

                foreach (string cat in entry.GetSplitCategories())
                {
                    categories.Controls.Add(new LiteralControl(" #"));

                    HyperLink category = new HyperLink();
                    category.Text        = cat;
                    category.NavigateUrl = BlogXUtils.RelativeToRoot("CategoryView.aspx/" + cat);
                    categories.Controls.Add(category);
                }

                entryFooter.Controls.Add(categories);
            }
        }