📄 forumformatter.cs
字号:
else
{
icon = "forum_status.gif";
alt = ResourceManager.GetString("NoUnreadPosts");
}
}
break;
}
return String.Format(forumStatusIcon, alt, imagePath + icon);
}
#endregion
#region Format last post display
public static string FormatLastPost (Thread thread) {
return FormatLastPost( thread.MostRecentPostID, thread.Replies, thread.ThreadDate, thread.MostRecentPostAuthorID, thread.MostRecentPostAuthor, thread.Subject, false );
}
public static string FormatLastPost (Forum forum) {
return FormatLastPost( forum, false );
}
public static string FormatLastPost (Forum forum, bool displaySubject) {
return FormatLastPost( forum.MostRecentPostID, forum.MostRecentThreadReplies, forum.MostRecentPostDate, forum.MostRecentPostAuthorID, forum.MostRecentPostAuthor, forum.MostRecentPostSubject, displaySubject );
}
public static string FormatLastPost (int postID, int replies, DateTime postDate, int authorID, string author, string subject, bool DisplaySubject) {
string postToday;
string postYesterday;
string postTodayAnonymous;
string postYesterdayAnonymous;
string dateFormat;
string formatString = "";
object[] formatElements = new object[6];
string subjectFormat = "<b><a title=\"{5}\" href=\"{3}\">{4}</a></b><br>";
string temp = "";
postToday = "<b>" + ResourceManager.GetString("TodayAt") + " {0}</b>";
postYesterday = "<b>" + ResourceManager.GetString("YesterdayAt") + " {0}</b>";
postTodayAnonymous = "<b>" + ResourceManager.GetString("TodayAt") + " {0}</b>";
postYesterdayAnonymous = "<b>" + ResourceManager.GetString("YesterdayAt") + " {0}</b>";
// Do we have an author
//
if (author == string.Empty)
author = ResourceManager.GetString("DefaultAnonymousUsername");
// Populate the object array for the string formatter
//
formatElements[0] = postDate;
formatElements[1] = Globals.GetSiteUrls().UserProfile( authorID );
formatElements[2] = Formatter.CheckStringLength(author, 16);
// Attempt to get the currently signed in user
//
User user = CSContext.Current.User;
if (replies > CSContext.Current.SiteSettings.PostsPerPage)
{
int page;
if (user.PostSortOrder == SortOrder.Descending)
page = 1;
else
page = 1 + replies / CSContext.Current.SiteSettings.PostsPerPage;
formatElements[3] = Globals.GetSiteUrls().PostPaged(postID, page);
}
else
{
formatElements[3] = Globals.GetSiteUrls().PostInPage(postID, postID);
}
if (postDate < DateTime.Now.AddYears(-20) )
return ResourceManager.GetString("NumberWhenZero");
// Do we have a signed in user? If so, adjust it.
//
if (!user.IsAnonymous)
{
postDate = user.GetTimezone(postDate);
formatElements[0] = postDate;
dateFormat = user.Profile.DateFormat;
}
else
{
dateFormat = CSContext.Current.SiteSettings.DateFormat;
}
// prefix the formatString with the subject if asked
//
if (DisplaySubject)
{
// Used to grab the subject of the postID.
//
formatString = subjectFormat + ResourceManager.GetString("ForumGroupView_Legend_LastPostBy") + "<a href=\"{1}\">{2}</a><br>";
// For some reason, CheckStringLength doesn't work here.
//
if (Globals.HtmlDecode(subject).Length > 25)
{
//formatElements[4] = Globals.HtmlDecode(subject).Substring(0, 22) + "...";
formatElements[4] = Globals.HtmlEncode(Globals.HtmlDecode(subject).Substring(0, 22)) + "...";
formatElements[5] = subject;
}
else
{
formatElements[4] = subject;
formatElements[5] = subject;
}
}
else
{
formatString = ResourceManager.GetString("ForumGroupView_Legend_LastPostBy") + "<a href=\"{1}\">{2}</a> <a href=\"{3}\"><img border=\"0\" src=\"" + Globals.GetSkinPath() + "/images/icon_mini_topic.gif\"></a><br>";
formatElements[4] = "";
formatElements[5] = "";
}
// Format the post if it occurred today
//
DateTime userLocalTime = user.GetTimezone(DateTime.Now);
if ((postDate.DayOfYear == userLocalTime.DayOfYear) &&
(postDate.Year == userLocalTime.Year))
{
if (authorID > 0)
formatString += postToday;
else
formatString += postTodayAnonymous;
formatElements[0] = ((DateTime) formatElements[0]).ToString(CSContext.Current.SiteSettings.TimeFormat);
}
else if ((postDate.DayOfYear == (userLocalTime.DayOfYear - 1)) &&
(postDate.Year == userLocalTime.Year))
{
if (authorID > 0)
formatString += postYesterday;
else
formatString += postYesterdayAnonymous;
formatElements[0] = ((DateTime) formatElements[0]).ToString(CSContext.Current.SiteSettings.TimeFormat);
}
else
{
formatString += "{0}";
formatElements[0] = ((DateTime) formatElements[0]).ToString(user.Profile.DateFormat) + " " + ((DateTime) formatElements[0]).ToString(CSContext.Current.SiteSettings.TimeFormat);
}
// add a table
//
if (DisplaySubject)
temp = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\" class=\"txt5\">" + String.Format(formatString, formatElements) + "</td></tr></table>";
else
temp = "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\"><tr><td align=\"right\" class=\"txt5\">" + String.Format(formatString, formatElements) + "</td></tr></table>";
return temp;
/*
string postToday;
string postYesterday;
string postTodayAnonymous;
string postYesterdayAnonymous;
string dateFormat;
string formatString = "";
object[] formatElements = new object[6];
string subjectFormat = "<b><a title=\"{5}\" href=\"{3}\">{4}</a></b><br>";
string temp = "";
postToday = "<b>" + ResourceManager.GetString("TodayAt") + " {0}</b>";
postYesterday = "<b>" + ResourceManager.GetString("YesterdayAt") + " {0}</b>";
postTodayAnonymous = "<b>" + ResourceManager.GetString("TodayAt") + " {0}</b>";
postYesterdayAnonymous = "<b>" + ResourceManager.GetString("YesterdayAt") + " {0}</b>";
// Do we have an author
//
if (author == string.Empty)
author = ResourceManager.GetString("DefaultAnonymousUsername");
// Populate the object array for the string formatter
//
formatElements[0] = postDate;
formatElements[1] = Globals.GetSiteUrls().UserProfile(authorID);
formatElements[2] = Formatter.CheckStringLength(author, 16);
if (replies > SiteSettingsManager.GetSiteSettings().PostsPerPage)
{
int page = 1 + replies / SiteSettingsManager.GetSiteSettings().PostsPerPage;
formatElements[3] = Globals.GetSiteUrls().PostPaged(postID, page);
}
else
{
formatElements[3] = Globals.GetSiteUrls().PostInPage(postID, postID);
}
if (postDate < DateTime.Now.AddYears(-20) )
return ResourceManager.GetString("NumberWhenZero");
// Attempt to get the currently signed in user
//
User user = Users.GetUser();
// Do we have a signed in user? If so, adjust.
//
if (!user.IsAnonymous)
{
postDate = user.GetTimezone(postDate);
formatElements[0] = postDate;
dateFormat = user.Profile.DateFormat;
}
else
{
dateFormat = SiteSettingsManager.GetSiteSettings().DateFormat;
}
// prefix the formatString with the subject if asked
//
if (DisplaySubject)
{
// Used to grab the subject of the postID.
//
formatString = subjectFormat + ResourceManager.GetString("ForumGroupView_Legend_LastPostBy") + "<a href=\"{1}\">{2}</a><br>";
// For some reason, CheckStringLength doesn't work here.
//
if (Globals.HtmlDecode(subject).Length > 25)
{
//formatElements[4] = Globals.HtmlDecode(subject).Substring(0, 22) + "...";
formatElements[4] = Globals.HtmlEncode(Globals.HtmlDecode(subject).Substring(0, 22)) + "...";
formatElements[5] = subject;
}
else
{
formatElements[4] = subject;
formatElements[5] = subject;
}
}
else
{
formatString = ResourceManager.GetString("ForumGroupView_Legend_LastPostBy") + "<a href=\"{1}\">{2}</a> <a href=\"{3}\"><img border=\"0\" src=\"" + Globals.GetSkinPath() + "/images/icon_mini_topic.gif\"></a><br>";
formatElements[4] = "";
formatElements[5] = "";
}
// Format the post if it occurred today
//
DateTime userLocalTime = user.GetTimezone(DateTime.Now);
if ((postDate.DayOfYear == userLocalTime.DayOfYear) &&
(postDate.Year == userLocalTime.Year))
{
if (authorID > 0)
formatString += postToday;
else
formatString += postTodayAnonymous;
formatElements[0] = ((DateTime) formatElements[0]).ToString(SiteSettingsManager.GetSiteSettings().TimeFormat);
}
else if ((postDate.DayOfYear == (userLocalTime.DayOfYear - 1)) &&
(postDate.Year == userLocalTime.Year))
{
if (authorID > 0)
formatString += postYesterday;
else
formatString += postYesterdayAnonymous;
formatElements[0] = ((DateTime) formatElements[0]).ToString(SiteSettingsManager.GetSiteSettings().TimeFormat);
}
else
{
formatString += "{0}";
formatElements[0] = ((DateTime) formatElements[0]).ToString(user.Profile.DateFormat) + " " + ((DateTime) formatElements[0]).ToString(SiteSettingsManager.GetSiteSettings().TimeFormat);
}
// add a table
//
if (DisplaySubject)
temp = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\" class=\"txt5\">" + String.Format(formatString, formatElements) + "</td></tr></table>";
else
temp = "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\"><tr><td align=\"right\" class=\"txt5\">" + String.Format(formatString, formatElements) + "</td></tr></table>";
return temp;
*/
}
#endregion
#endregion
#region Format Users Viewing Forum
public static string FormatUsersViewingForum (Forum forum)
{
SiteUrls.ForumLocation location;
ArrayList users;
int viewing = 0;
users = Users.GetUsersOnline(CSContext.Current.SiteSettings.UserOnlineTimeWindow);
foreach (User user in users)
{
location = SiteUrls.GetForumLocation(user.LastAction);
if (location.ForumID == forum.SectionID)
viewing++;
}
if (viewing > 0)
return string.Format(ResourceManager.GetString("ForumGroupView_Viewing"), viewing);
return "";
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -