用windows live writer写的

本文涉及的产品
视频直播,500GB 1个月
简介:

关于配置

发布配置

http://你的blog地址/metawebblog.axd

 

#region Using

using System;
using System.Web;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BlogEngine.Core;

#endregion

public partial class archive : BlogEngine.Core.Web.Controls.BlogBasePage
{
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack && !IsCallback)
    {
            CreateMenu();
      CreateArchive();
      AddTotals();
    }

    Page.Title = Server.HtmlEncode(Resources.labels.archive);
    base.AddMetaTag("description", Resources.labels.archive + " | " + BlogSettings.Instance.Name);
  }

    /// <summary>
    /// Creates the category top menu.
    /// </summary>
  private void CreateMenu()
  {
    foreach (Category cat in Category.Categories)
    {
            AddCategoryToMenu(cat.Title);
    }
  }

    private void AddCategoryToMenu(string title)
    {
        HtmlAnchor a = new HtmlAnchor();
        a.InnerHtml = Server.HtmlEncode(title);
        a.HRef = "#" + Utils.RemoveIllegalCharacters(title);
        a.Attributes.Add("rel", "directory");

        HtmlGenericControl li = new HtmlGenericControl("li");
        li.Controls.Add(a);
        ulMenu.Controls.Add(li);
    }

    /// <summary>
    /// Sorts the categories.
    /// </summary>
    /// <param name="categories">The categories.</param>
  private SortedDictionary<string, Guid> SortCategories(Dictionary<Guid, string> categories)
  {
    SortedDictionary<string, Guid> dic = new SortedDictionary<string, Guid>();
    foreach (Category cat in Category.Categories)
    {
      dic.Add(cat.Title, cat.Id);
    }

    return dic;
  }

  private void CreateArchive()
  {
    foreach (Category cat in Category.Categories)
    {
      string name = cat.Title;
            List<Post> list = Post.GetPostsByCategory(cat.Id).FindAll(delegate(Post p) { return p.IsVisible; });

            HtmlGenericControl h2 = CreateRowHeader(cat.Id, name, list.Count);
      phArchive.Controls.Add(h2);

      HtmlTable table = CreateTable(name);
      foreach (Post post in list)
      {
                CreateTableRow(table, post);
      }

      phArchive.Controls.Add(table);
    }

        List<Post> noCatList = Post.Posts.FindAll(delegate(Post p) { return p.Categories.Count == 0; });
        if (noCatList.Count > 0)
        {
            string name = Resources.labels.uncategorized;
            HtmlGenericControl h2 = CreateRowHeader(Guid.NewGuid(), name, noCatList.Count);
            phArchive.Controls.Add(h2);

            HtmlTable table = CreateTable(name);
            foreach (Post post in noCatList)
            {
                CreateTableRow(table, post);
            }

            phArchive.Controls.Add(table);

            AddCategoryToMenu(name);
        }
  }

    private static HtmlGenericControl CreateRowHeader(Guid id, string name, int count)
    {
        HtmlAnchor feed = new HtmlAnchor();
        feed.HRef = Utils.RelativeWebRoot + "category/syndication.axd?category=" + id.ToString();

        HtmlImage img = new HtmlImage();
        img.Src = Utils.RelativeWebRoot + "pics/rssbutton.gif";
        img.Alt = "RSS";

        feed.Controls.Add(img);

        HtmlGenericControl h2 = new HtmlGenericControl("h2");
        h2.Attributes["id"] = Utils.RemoveIllegalCharacters(name);
        h2.Controls.Add(feed);

        Control header = new LiteralControl(name + " (" + count + ")");
        h2.Controls.Add(header);
        return h2;
    }

    private static void CreateTableRow(HtmlTable table, Post post)
    {
        HtmlTableRow row = new HtmlTableRow();

        HtmlTableCell date = new HtmlTableCell();
        date.InnerHtml = post.DateCreated.ToString("yyyy-MM-dd");
        date.Attributes.Add("class", "date");
        row.Cells.Add(date);

        HtmlTableCell title = new HtmlTableCell();
        title.InnerHtml = string.Format("<a href=\"{0}\">{1}</a>", post.RelativeLink, post.Title);
        title.Attributes.Add("class", "title");
        row.Cells.Add(title);

        if (BlogSettings.Instance.IsCommentsEnabled)
        {
            HtmlTableCell comments = new HtmlTableCell();
            comments.InnerHtml = post.ApprovedComments.Count.ToString();
            comments.Attributes.Add("class", "comments");
            row.Cells.Add(comments);
        }

        if (BlogSettings.Instance.EnableRating)
        {
            HtmlTableCell rating = new HtmlTableCell();
            rating.InnerHtml = post.Raters == 0 ? "None" : Math.Round(post.Rating, 1).ToString();
            rating.Attributes.Add("class", "rating");
            row.Cells.Add(rating);
        }

        table.Rows.Add(row);
    }

  private HtmlTable CreateTable(string name)
  {
    HtmlTable table = new HtmlTable();
    table.Attributes.Add("summary", name);

    HtmlTableRow header = new HtmlTableRow();

    HtmlTableCell date = new HtmlTableCell("th");
    date.InnerHtml = base.Translate("date");
    header.Cells.Add(date);

    HtmlTableCell title = new HtmlTableCell("th");
    title.InnerHtml = base.Translate("title");
    header.Cells.Add(title);

    if (BlogSettings.Instance.IsCommentsEnabled)
    {
      HtmlTableCell comments = new HtmlTableCell("th");
      comments.InnerHtml = base.Translate("comments");
      comments.Attributes.Add("class", "comments");
      header.Cells.Add(comments);
    }

    if (BlogSettings.Instance.EnableRating)
    {
      HtmlTableCell rating = new HtmlTableCell("th");
      rating.InnerHtml = base.Translate("rating");
      rating.Attributes.Add("class", "rating");
      header.Cells.Add(rating);
    }

    table.Rows.Add(header);

    return table;
  }

  private void AddTotals()
  {
    int comments = 0;
    int raters = 0;
    foreach (Post post in Post.Posts)
    {
      comments += post.ApprovedComments.Count;
      raters += post.Raters;
    }

    ltPosts.Text = Post.Posts.Count + " " + Resources.labels.posts.ToLowerInvariant();
    if (BlogSettings.Instance.IsCommentsEnabled)
      ltComments.Text = comments + " " + Resources.labels.comments.ToLowerInvariant();

    if (BlogSettings.Instance.EnableRating)
      ltRaters.Text = raters + " " + Resources.labels.raters.ToLowerInvariant();
  }
}
转载请注明出处[ http://samlin.cnblogs.com/] 
作者赞赏
 


刚做的招标网: 八爪鱼招标网 请大家多意见


本文转自Sam Lin博客博客园博客,原文链接:http://www.cnblogs.com/samlin/archive/2009/07/29/1533980.html,如需转载请自行联系原作者
目录
相关文章
|
API C++ Windows
【Live555】Live555 Windows下使用VS2017编译教程
【Live555】Live555 Windows下使用VS2017编译教程
【Live555】Live555 Windows下使用VS2017编译教程
|
数据建模 C++ Windows
live555开发笔记(一):live555介绍、windows上msvc2017编译和工程模板
live555开发笔记(一):live555介绍、windows上msvc2017编译和工程模板
live555开发笔记(一):live555介绍、windows上msvc2017编译和工程模板
|
PHP
MAC &#19978;&#30340; Live Writer : ecto
ecto 在这里: http://illuminex.com/ecto/ 它是一款 MAC 上的 live writer,对我来说,没有 writer 之类的工具,我就宁可不写博客。 测试插入图片 测试插入代码 Something is wrong with the XAMPP installation :-( 本文基于Creative Commons Attribution 2.5 China Mainland License发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名http://www.cnblogs.com/luminji(包含链接)。
881 0
|
数据安全/隐私保护 数据格式 JSON
测试Live Writer写日志
/** * @author ZhangYi */ var LOGIN_WIN_STATE = 0;//多次调用且不关闭,会出现bug function getLoginWin(para) { if(LOGIN_WIN_STATE || document.
662 0
|
监控 Windows
Windows Live Writer的使用
帮助地址在这里:space.cnblogs.com/forum/topic/8550/ 博客园支持SyntaxHighlighter代码着色,可以用相应的Live Writer代码着色插件进行代码着色。
922 0
Live Writer 还可以写博客耶
原来好多东西都是可以整合的。
507 0