⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 authorlist.cs

📁 个人博客系统
💻 CS
字号:
#region Using

using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.IO;
using BlogEngine.Core;

#endregion

namespace Controls
{
	/// <summary>
	/// Builds a authro list.
	/// </summary>
	public class AuthorList : Control
	{

		/// <summary>
		/// Initializes the <see cref="AuthorList"/> class.
		/// </summary>
		static AuthorList()
		{
			Post.Saved += delegate { _Html = null; };
		}

		#region Properties

		private bool _ShowRssIcon = true;
		/// <summary>
		/// Gets or sets whether or not to show feed icons next to the category links.
		/// </summary>
		public bool ShowRssIcon
		{
			get { return _ShowRssIcon; }
			set { _ShowRssIcon = value; }
		}

		private static object _SyncRoot = new object();

		private static string _Html;
		/// <summary>
		/// Caches the rendered HTML in the private field and first
		/// updates it when a post has been saved (new or updated).
		/// </summary>
		private string Html
		{
			get
			{
				if (_Html == null)
				{
					lock (_SyncRoot)
					{
						if (_Html == null)
						{
							HtmlGenericControl ul = BindAuthors();
							System.IO.StringWriter sw = new System.IO.StringWriter();
							ul.RenderControl(new HtmlTextWriter(sw));
							_Html = sw.ToString();
						}
					}
				}

				return _Html;
			}
		}

		#endregion

		/// <summary>
		/// Loops through all users and builds the HTML
		/// presentation.
		/// </summary>
		private HtmlGenericControl BindAuthors()
		{
			HtmlGenericControl ul = new HtmlGenericControl("ul");
			foreach (MembershipUser user in Membership.GetAllUsers())
			{
				HtmlGenericControl li = new HtmlGenericControl("li");

				if (ShowRssIcon)
				{
					HtmlImage img = new HtmlImage();
					img.Src = Utils.RelativeWebRoot + "pics/rssbutton.gif";
					img.Alt = "RSS feed for " + user.UserName;
					img.Attributes["class"] = "rssButton";

					HtmlAnchor feedAnchor = new HtmlAnchor();
					feedAnchor.HRef = Utils.RelativeWebRoot + "syndication.axd?author=" + Utils.RemoveIllegalCharacters(user.UserName);
					feedAnchor.Attributes["rel"] = "nofollow";
					feedAnchor.Controls.Add(img);

					li.Controls.Add(feedAnchor);
				}

				HtmlAnchor anc = new HtmlAnchor();
				anc.HRef = Utils.RelativeWebRoot + "author/" + user.UserName + BlogSettings.Instance.FileExtension;
				anc.InnerHtml = user.UserName + " (" + Post.GetPostsByAuthor(user.UserName).Count + ")";
				anc.Title = "Author: " + user.UserName;

				li.Controls.Add(anc);
				ul.Controls.Add(li);
			}

			return ul;
		}

		/// <summary>
		/// Renders the control.
		/// </summary>
		public override void RenderControl(HtmlTextWriter writer)
		{
			writer.Write(Html);
			writer.Write(Environment.NewLine);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -