Beispiel #1
0
        private void CategoryList_PreRender(object sender, System.EventArgs e)
        {
            CategoryCache cache = new CategoryCache();

            cache.Ensure(data);

            HtmlGenericControl section = new HtmlGenericControl("div");

            section.Attributes["class"] = "section";
            this.Controls.Add(section);

            HtmlGenericControl heading = new HtmlGenericControl("h3");

            heading.Controls.Add(new LiteralControl("Categories"));
            section.Controls.Add(heading);

            HtmlGenericControl list = new HtmlGenericControl("ul");

            section.Controls.Add(list);

            foreach (CategoryCacheEntry catEntry in cache.Entries)
            {
                HtmlGenericControl item = new HtmlGenericControl("li");
                list.Controls.Add(item);

                HyperLink catLink = new HyperLink();
                catLink.Text        = catEntry.Name;
                catLink.NavigateUrl = BlogXUtils.RelativeToRoot("CategoryView.aspx/" + catEntry.Name);
                item.Controls.Add(catLink);
                item.Controls.Add(new LiteralControl(" ("));
                HyperLink rssLink = new HyperLink();
                rssLink.Text        = "rss";
                rssLink.NavigateUrl = BlogXUtils.RelativeToRoot("BlogXBrowsing.asmx/GetRssCategory?categoryName=" + catEntry.Name);
                item.Controls.Add(rssLink);
                item.Controls.Add(new LiteralControl(")"));
            }
        }
        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 #3
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);
            }
        }