Пример #1
0
            //- @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);
                    //+
                    Themelia.Template template = new Themelia.Template(@"
<div class=""post"">
    <h3><a href=""{Url}"">{Title}</a></h3>");
                    if (this.HidePostDateTime == false)
                    {
                        template.AppendText(@"
    <h2 class=""date-header"">{DateTimeString}</h2>");
                    }
                    template.AppendText(@"
    <div class=""post-body"">
        <div>{Content}</div>
    </div>
    <p class=""post-footer"">");
                    if (this.ShowAuthorSeries)
                    {
                        template.AppendText("<em>posted by {AuthorSeries}");
                        //+
                        if (this.HidePostDateTime == false)
                        {
                            template.AppendText(" at {DateTimeDisplay}</em>");
                        }
                    }
                    //+
                    ph.Controls.Add(new System.Web.UI.WebControls.Literal
                    {
                        Text = 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))
                    {
                        ph.Controls.Add(new System.Web.UI.WebControls.Literal
                        {
                            Text = new Template(@"
    <p class=""post-labels"">{LabelSeries}</p>").Interpolate(
                                new Map(
                                    new MapEntry("LabelSeries", labelSeries))
                                )
                        });
                    }
                    if (!this.IsLink && this.SupportCommenting)
                    {
                        if (allowCommentStatus == AllowCommentStatus.Disabled)
                        {
                            if (!String.IsNullOrEmpty(this.DisabledCommentText))
                            {
                                ph.Controls.Add(new System.Web.UI.WebControls.Literal
                                {
                                    Text = @"<p class=""comment-count"">" + this.DisabledCommentText + @"</p>"
                                });
                            }
                        }
                        else
                        {
                            ph.Controls.Add(new System.Web.UI.WebControls.Literal
                            {
                                Text = new Template(@"
        <p class=""comment-count"">
            <a href=""{Url}"">({ViewableCommentCount} Comment{Plural})</a>
").Interpolate(new Map(
                   new MapEntry("Url", url),
                   new MapEntry("ViewableCommentCount", viewableCommentCount.ToString()),
                   new MapEntry("Plural", viewableCommentCount != 1 ? "s" : String.Empty))
               )
                            });
                            ph.Controls.Add(new System.Web.UI.WebControls.Literal
                            {
                                Text = @"
        </p>"
                            });
                        }
                    }
                    if (this.PostFooterTypeInfo != null)
                    {
                        PostFooterBase postFooter = ObjectCreator.CreateAs <PostFooterBase>(this.PostFooterTypeInfo);
                        postFooter.Data           = item.DataItem;
                        ph.Controls.Add(postFooter);
                    }
                    ph.Controls.Add(new System.Web.UI.WebControls.Literal()
                    {
                        Text = @"
    </p>
</div>"
                    });
                });
                container.Controls.Add(ph);
            }
            //- @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);
            }