예제 #1
0
        //+
        //- #OnPreRender -//
        protected override void OnPreRender(EventArgs e)
        {
            String link = Themelia.Web.HttpData.GetScopedItem <String>(Info.Scope, Info.CustomLink);

            //+
            if (!String.IsNullOrEmpty(link))
            {
                Minima.Service.BlogEntry blogEntry = BlogAgent.GetSingleBlogEntryByLink(this.BlogGuid, link, this.IgnoreBlogEntryFooter);
                if (blogEntry != null)
                {
                    String   labelSeries = SeriesHelper.GetBlogEntryLabelSeries(blogEntry);
                    Template template    = DataTemplateTemplateFactory.CreatePostTemplate(false, this.HidePostDateTime, this.ShowAuthorSeries, this.ShowLabelSeries, labelSeries, true, false, Minima.Service.AllowCommentStatus.Disabled, false, String.Empty);
                    String   output      = template.Interpolate(new Map(
                                                                    new MapEntry("$Title$", blogEntry.Title),
                                                                    new MapEntry("$DateTimeString$", String.Format("{0}, {1} {2}, {3}", blogEntry.PostDateTime.DayOfWeek, blogEntry.PostDateTime.ToString("MMMM"), blogEntry.PostDateTime.Day, blogEntry.PostDateTime.Year)),
                                                                    new MapEntry("$Content$", blogEntry.Content),
                                                                    new MapEntry("$AuthorSeries$", SeriesHelper.GetBlogEntryAuthorSeries(blogEntry)),
                                                                    new MapEntry("$DateTimeDisplay$", String.Format("{0}/{1}/{2} {3}", blogEntry.PostDateTime.Month, blogEntry.PostDateTime.Day, blogEntry.PostDateTime.Year, blogEntry.PostDateTime.ToShortTimeString())),
                                                                    new MapEntry("$LabelSeries$", labelSeries)
                                                                    )
                                                                );
                    output = this.CodeParserSeries.ParseCode(output);
                    //+
                    this.Controls.Add(new System.Web.UI.WebControls.Literal
                    {
                        Text = output
                    });
                }
            }
            //+
            base.OnPreRender(e);
        }
            //- @InstantiateIn -//
            public void InstantiateIn(System.Web.UI.Control container)
            {
                PlaceHolder ph = new PlaceHolder();

                ph.DataBinding += new EventHandler(delegate(Object sender, EventArgs ea)
                {
                    IDataItemContainer item = (IDataItemContainer)container;
                    String guid             = DataBinder.Eval(item.DataItem, "Guid") as String;
                    String url             = DataBinder.Eval(item.DataItem, "Url") as String;
                    String title           = DataBinder.Eval(item.DataItem, "Title") as String;
                    String content         = DataBinder.Eval(item.DataItem, "Content") as String;
                    String authorSeries    = DataBinder.Eval(item.DataItem, "AuthorSeries") as String;
                    String labelSeries     = DataBinder.Eval(item.DataItem, "LabelSeries") as String;
                    String dateTimeString  = DataBinder.Eval(item.DataItem, "DateTimeString") as String;
                    String dateTimeDisplay = DataBinder.Eval(item.DataItem, "DateTimeDisplay") as String;
                    AllowCommentStatus allowCommentStatus = (AllowCommentStatus)(DataBinder.Eval(item.DataItem, "AllowCommentStatus") ?? 0);
                    Int32 viewableCommentCount            = (DataBinder.Eval(item.DataItem, "ViewableCommentCount") as Int32?) ?? 0;
                    //+
                    HiddenField hBlogEntryGuid = new HiddenField
                    {
                        ID    = "hBlogEntryGuid",
                        Value = guid
                    };
                    ph.Controls.Add(hBlogEntryGuid);
                    //+
                    String postFooterData = String.Empty;
                    if (this.PostFooterTypeInfo != null)
                    {
                        PostFooterBase postFooter = ObjectCreator.CreateAs <PostFooterBase>(this.PostFooterTypeInfo);
                        if (postFooter != null)
                        {
                            postFooter.Data = item.DataItem;
                            System.Text.StringBuilder builder = new System.Text.StringBuilder();
                            System.IO.StringWriter writer     = new System.IO.StringWriter(builder);
                            HtmlTextWriter htmlWriter         = new HtmlTextWriter(writer);
                            postFooter.RenderControl(htmlWriter);
                            postFooterData = builder.ToString();
                        }
                    }
                    //+
                    Themelia.Template template = DataTemplateTemplateFactory.CreatePostTemplate(this.LinkHeader, this.HidePostDateTime, this.ShowAuthorSeries, this.ShowLabelSeries, labelSeries, this.IsLink, this.SupportCommenting, allowCommentStatus, !String.IsNullOrEmpty(DisabledCommentText), postFooterData);
                    //+
                    String output = template.Interpolate(new Map(
                                                             new MapEntry("$Url$", url),
                                                             new MapEntry("$Title$", title),
                                                             new MapEntry("$DateTimeString$", dateTimeString),
                                                             new MapEntry("$Content$", content),
                                                             new MapEntry("$AuthorSeries$", authorSeries),
                                                             new MapEntry("$DateTimeDisplay$", dateTimeDisplay)
                                                             )
                                                         );
                    if (!String.IsNullOrEmpty(labelSeries))
                    {
                        output = new Template(output).Interpolate(new Map(
                                                                      new MapEntry("$LabelSeries$", labelSeries)
                                                                      ));
                    }
                    if (!this.IsLink && this.SupportCommenting)
                    {
                        if (allowCommentStatus == AllowCommentStatus.Disabled)
                        {
                            if (!String.IsNullOrEmpty(this.DisabledCommentText))
                            {
                                output = new Template(output).Interpolate(new Map(
                                                                              new MapEntry("$DisabledCommentText$", this.DisabledCommentText)
                                                                              ));
                            }
                        }
                        else
                        {
                            output = new Template(output).Interpolate(new Map(
                                                                          new MapEntry("$Url$", url),
                                                                          new MapEntry("$ViewableCommentCount$", viewableCommentCount.ToString()),
                                                                          new MapEntry("$Plural$", viewableCommentCount != 1 ? "s" : String.Empty)));
                        }
                    }
                    if (!String.IsNullOrEmpty(postFooterData))
                    {
                        output = new Template(output).Interpolate(new Map(
                                                                      new MapEntry("$PostFooterData$", postFooterData)
                                                                      ));
                    }
                    ph.Controls.Add(new System.Web.UI.WebControls.Literal
                    {
                        Text = output
                    });
                });
                container.Controls.Add(ph);
            }