📄 userattribute.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections;
using CommunityServer.Components;
namespace CommunityServer.Controls {
public class UserAttribute : PlaceHolder {
CSContext csContext = CSContext.Current;
bool isCloakedUser = false;
protected override void Render(HtmlTextWriter writer) {
Literal l = new Literal();
if (this.User.IsAnonymous || IsCloakedUser)
return;
// Note, we could have used reflection, but that
// would have been slower
//
switch (this.Attribute) {
case UserAttributes.Joined:
l.Text = String.Format(this.FormatString, ResourceManager.GetString("PostFlatView_Joined") + User.GetTimezone(this.User.DateCreated).ToString(csContext.User.Profile.DateFormat));
break;
case UserAttributes.Location:
if (this.User.Profile.Location == string.Empty)
return;
l.Text = String.Format(this.FormatString, ResourceManager.GetString("PostFlatView_Location") + this.User.Profile.Location);
break;
case UserAttributes.Posts:
UserActivityDisplayMode displayMode = CSContext.Current.SiteSettings.PostingActivityDisplay;
bool displayRankAsPicture = CSContext.Current.SiteSettings.DisplayUserRankAsPicture;
ArrayList ranks = Ranks.GetRanks();
if (displayMode == UserActivityDisplayMode.PostCount ||
ranks == null ||
(ranks != null && ranks.Count == 0)) {
l.Text = String.Format( this.FormatString, ResourceManager.GetString("PostFlatView_Posts") + this.User.TotalPosts.ToString(ResourceManager.GetString("NumberFormat")) );
}
else {
l.Text = String.Format( this.FormatString, Formatter.FormatUserRank( this.User.DummyTotalPosts, displayRankAsPicture, ranks ) );
}
break;
}
l.RenderControl(writer);
}
public User User {
get {
if ( _user == null ) {
Object state = ViewState[ "UserID" ];
if ( state != null ) {
Int32 userID = (Int32)state;
_user = Users.GetUser( userID, false );
}
}
return _user;
}
set {
_user = value;
if ( _user != null ) {
ViewState[ "UserID" ] = _user.UserID;
} else {
ViewState.Remove( "UserID" );
}
}
}
User _user;
/// <summary>
/// Added to specify if this user should be displayed as anonymous
/// </summary>
public bool IsCloakedUser {
get { return isCloakedUser; }
set { isCloakedUser = value; }
}
[
System.ComponentModel.DefaultValue( "" ),
]
public virtual String FormatString {
get {
Object state = ViewState["FormatString"];
if ( state != null ) {
return (String)state;
}
return "";
}
set {
ViewState["FormatString"] = value;
}
}
[
System.ComponentModel.DefaultValue( UserAttributes.Joined ),
]
public virtual UserAttributes Attribute {
get {
Object state = ViewState["Attribute"];
if ( state != null ) {
return (UserAttributes)state;
}
return UserAttributes.Joined;
}
set {
ViewState["Attribute"] = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -