📄 threadlist.cs
字号:
__parser.AddParsedSubObject(RenderFooterTemplate());
}
// *********************************************************************
// HandleDataBindingForImage
//
/// <summary>
/// Handle data binding for the image rendered next to the post
/// </summary>
///
// ********************************************************************/
private void HandleDataBindingForImage(Object sender, EventArgs e) {
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image) sender;
DataListItem container = (DataListItem) img.NamingContainer;
Thread thread = (Thread) container.DataItem;
if (thread.IsPopular) {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-popular.gif";
img.ToolTip = "Popular post";
} else if (thread.IsAnnouncement) {
if (thread.HasRead) {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-announce.gif";
img.ToolTip = "Announcement - post is pinned and allows no replies";
} else {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-announce_notread.gif";
img.ToolTip = "Announcement - post is pinned and allows no replies (Not Read)";
}
} else if ((thread.IsPinned) && (thread.IsLocked)) {
if (thread.HasRead) {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-pinned&locked.gif";
img.ToolTip = "Post is pinned and allows no replies";
} else {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-pinned&locked_notread.gif";
img.ToolTip = "Post is pinned and allows no replies (Not Read)";
}
} else if (thread.IsPinned) {
if (thread.HasRead) {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-pinned.gif";
img.ToolTip = "Post is pinned";
} else {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-pinned_notread.gif";
img.ToolTip = "Post is pinned (Not Read)";
}
} else if (thread.IsLocked) {
if (thread.HasRead) {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-locked.gif";
img.ToolTip = "Post allows no replies";
} else {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic-locked_notread.gif";
img.ToolTip = "Post allows no replies (Not Read)";
}
} else {
if (thread.HasRead) {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic.gif";
img.ToolTip = "Post";
} else {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/topic_notread.gif";
img.ToolTip = "Post (Not Read)";
}
}
}
// *********************************************************************
// HandleDatabindingForPostSubject
//
/// <summary>
/// Handle data binding for the post subject
/// </summary>
///
// ********************************************************************/
private void HandleDatabindingForPostSubject(Object sender, EventArgs e) {
HyperLink forumTitle = new HyperLink();
Label label;
String subject;
bool subjectTooLong = false;
PlaceHolder placeHolder = (PlaceHolder) sender;
DataListItem container = (DataListItem) placeHolder.NamingContainer;
Thread thread = (Thread) container.DataItem;
if (thread.IsAnnouncement) {
label = new Label();
label.CssClass = "normalTextSmallBold";
label.Text = "Announcement: ";
placeHolder.Controls.Add(label);
}
// Get the subject
subject = thread.Subject;
// If the subject is > 30 cut it down and there is not whitespace
if ((subject.Length > 30) && (subject.IndexOf(" ") == -1)) {
subject = subject.Substring(0, 30);
subjectTooLong = true;
} else if (subject.Length > 60) {
// We have whitespace, but the string is still exceptionally long
if (subject.Substring(30, 30).IndexOf(" ") == -1) {
subject = subject.Substring(0, 30);
subjectTooLong = true;
}
}
forumTitle.Text = subject;
forumTitle.NavigateUrl = Globals.UrlShowPost + thread.PostID;
forumTitle.CssClass = "linkSmallBold";
placeHolder.Controls.Add(forumTitle);
// Add elipses
if (subjectTooLong) {
label = new Label();
label.CssClass = "normalTextSmallBold";
label.Text = " ...";
placeHolder.Controls.Add(label);
}
// Do we have more than
if (thread.Replies >= Globals.PageSize) {
HyperLink link;
// Add the opening paren
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = " (Page: ";
placeHolder.Controls.Add(label);
// Get the total number of pages available
int totalPages = Paging.CalculateTotalPages((thread.Replies + 1), Globals.PageSize);
// Display the first 3
if (totalPages < 4) {
for (int i = 0; i < totalPages; i++) {
link = new HyperLink();
link.CssClass = "linkSmall";
link.Text = (i + 1).ToString();
link.NavigateUrl = Globals.UrlShowPost + thread.PostID + "&PageIndex=" + (i+1).ToString();
placeHolder.Controls.Add(link);
if ((i + 1) != totalPages) {
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = ", ";
placeHolder.Controls.Add(label);
}
}
}
// Do we need elipses?
if (totalPages >= 4) {
if (totalPages < 6) {
for (int i = 0; i < totalPages; i++) {
link = new HyperLink();
link.CssClass = "linkSmall";
link.Text = (i + 1).ToString();
link.NavigateUrl = Globals.UrlShowPost + thread.PostID + "&PageIndex=" + (i+1).ToString();
placeHolder.Controls.Add(link);
if ((i + 1) != totalPages) {
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = ", ";
placeHolder.Controls.Add(label);
}
}
} else {
for (int i = 0; i < 3; i++) {
link = new HyperLink();
link.CssClass = "linkSmall";
link.Text = (i + 1).ToString();
link.NavigateUrl = Globals.UrlShowPost + thread.PostID + "&PageIndex=" + (i+1).ToString();
placeHolder.Controls.Add(link);
if ((i + 1) != totalPages) {
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = ", ";
placeHolder.Controls.Add(label);
}
}
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = " ... ";
placeHolder.Controls.Add(label);
for (int i = totalPages - 2; i < totalPages; i++) {
link = new HyperLink();
link.CssClass = "linkSmall";
link.Text = (i + 1).ToString();
link.NavigateUrl = Globals.UrlShowPost + thread.PostID + "&PageIndex=" + (i+1).ToString();
placeHolder.Controls.Add(link);
if ((i + 1) != totalPages) {
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = ", ";
placeHolder.Controls.Add(label);
}
}
}
}
// Add the closing paren
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = ")";
placeHolder.Controls.Add(label);
}
}
// *********************************************************************
// HandleDatabindingForTotalReplies
//
/// <summary>
/// Handle data binding for the total replies to the post
/// </summary>
///
// ********************************************************************/
private void HandleDatabindingForTotalReplies(Object sender, EventArgs e) {
Label totalReplies = (Label) sender;
DataListItem container = (DataListItem) totalReplies.NamingContainer;
Thread thread = (Thread) container.DataItem;
if (thread.Replies == 0)
totalReplies.Text = "-";
else
totalReplies.Text = thread.Replies.ToString("n0");
}
// *********************************************************************
// HandleDatabindingForTotalViews
//
/// <summary>
/// Handle data binding for the total views for the post
/// </summary>
///
// ********************************************************************/
private void HandleDatabindingForTotalViews(Object sender, EventArgs e) {
Label totalViews = (Label) sender;
DataListItem container = (DataListItem) totalViews.NamingContainer;
Thread thread = (Thread) container.DataItem;
totalViews.Text = thread.Views.ToString("n0");
}
// *********************************************************************
// HandleDatabindingForAuthor
//
/// <summary>
/// Handle data binding for the author of the post
/// </summary>
///
// ********************************************************************/
private void HandleDatabindingForAuthor(Object sender, EventArgs e) {
HyperLink author = (HyperLink) sender;
DataListItem container = (DataListItem) author.NamingContainer;
Thread thread = (Thread) container.DataItem;
author.Text = thread.Username;
author.NavigateUrl = Globals.UrlUserProfile + thread.Username;
}
// *********************************************************************
// HandleDatabindingForPostDetails
//
/// <summary>
/// Handle data binding for the details about the most recent post
/// </summary>
///
// ********************************************************************/
private void HandleDatabindingForPostDetails (Object sender, EventArgs e) {
PlaceHolder postDetails = (PlaceHolder) sender;
DataListItem container = (DataListItem) postDetails.NamingContainer;
DateTime postDateTime;
Label postDate = new Label();
HyperLink newPost = new HyperLink();
HyperLink author = new HyperLink();
String dateFormat;
// Set the style of the lablel
postDate.CssClass = "normalTextSmaller";
// Do we have a signed in user?
if (user != null)
dateFormat = user.DateFormat;
else
dateFormat = Globals.DateFormat;
// Get the post
Thread thread = (Thread) container.DataItem;
// Get the post date
postDateTime = thread.ThreadDate;
// Is a user logged in?
if (user != null)
postDateTime = Users.AdjustForTimezone(postDateTime, user);
// Did the post occur today?
if (thread.IsAnnouncement)
postDate.Text = "<b>Announcement</b><br>by ";
else if (thread.IsPinned)
postDate.Text = "<b>Pinned Post</b><br>by ";
else if ((postDateTime.DayOfYear == DateTime.Now.DayOfYear) && (postDateTime.Year == DateTime.Now.Year))
postDate.Text = "<b>Today @ " + postDateTime.ToString(Globals.TimeFormat) + "</b><br>by ";
else
postDate.Text = postDateTime.ToString(dateFormat + " " + Globals.TimeFormat) + "<br>by ";
// Add the post
postDetails.Controls.Add(postDate);
// Add the post author
author.Text = thread.MostRecentPostAuthor;
author.CssClass = "linkSmall";
author.NavigateUrl = Globals.UrlUserProfile + thread.MostRecentPostAuthor;
postDetails.Controls.Add(author);
// Link to new post - we need to figure out what page the post is on
newPost.Text = "<img border=\"0\" src=\"" + Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/icon_mini_topic.gif\">";
if (( (thread.Replies + 1) > Globals.PageSize) && ( (user != null) && (!user.ShowPostsAscending)) ) {
int totalPages = Paging.CalculateTotalPages(thread.Replies + 1, Globals.PageSize);
// Newest post will be on the last page
newPost.NavigateUrl = Globals.UrlShowPost + thread.PostID + "&PageIndex=" + totalPages + "#" + thread.MostRecentPostID;
} else {
newPost.NavigateUrl = Globals.UrlShowPost + thread.PostID + "#" + thread.MostRecentPostID;
}
postDetails.Controls.Add(newPost);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -