📄 textpost.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
namespace CommunityServer.Discussions.Controls.PostDisplay
{
public class TextPost : SkinnedWebControl
{
string skinFilename = "PostType-TextPost.ascx";
public TextPost()
{
// Assign a default template name
if (SkinFilename == null)
SkinFilename = skinFilename;
}
// *********************************************************************
// Initializeskin
//
/// <summary>
/// Initializes the user control loaded in CreateChildControls. Initialization
/// consists of finding well known control names and wiring up any necessary events.
/// </summary>
///
// ********************************************************************/
protected override void InitializeSkin(Control skin)
{
// very minimal code should be, to keep the speed of post display
// quick and efficient. item left to optimize are EditNotes.
//
Literal body;
Literal signature;
Literal editNotes;
// Find the controls we need
//
body = (Literal) skin.FindControl("Body");
signature = (Literal) skin.FindControl("Signature");
editNotes = (Literal) skin.FindControl("EditNotes");
body.Text = Post.FormattedBody;
ForumPost post = this.Post;
// Inform the following controls that the user should be seen as anonymous
//
bool swowUserAsAnonymous = (post.IsAnonymousPost && CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous && post.Forum.EnableAnonymousPostingForUsers);
// TODO eventually we'll add support for multiple attachments, this would need to be improved to handle more than 1 image attachment
string fileName = Post.AttachmentFilename;
if (fileName != "" && fileName != null)
{
string fileExtension = fileName.Substring(fileName.LastIndexOf(".") + 1);
if( fileExtension != null && fileExtension != string.Empty )
{
fileExtension = fileExtension.ToLower();
if( CSContext.Current.SiteSettings.EnableInlinedImages )
{
string supportedTypes = CSContext.Current.SiteSettings.SupportedInlinedImageTypes;
if( supportedTypes != null && supportedTypes != string.Empty )
{
string[] supportedImageTypes = supportedTypes.Split(';');
int height = CSContext.Current.SiteSettings.InlinedImageHeight;
int width = CSContext.Current.SiteSettings.InlinedImageWidth;
foreach( string imageType in supportedImageTypes )
{
if( fileExtension == imageType )
{
// format the image element to constrain the height and width of the image, if the admin configures it
body.Text += String.Format("<br /><a href='{0}' target='_blank'><img src='{1}' border='0' onload=\"{2}{3}\"></a>"
, Globals.GetSiteUrls().PostAttachment(post.PostID), Globals.GetSiteUrls().PostAttachment(post.PostID)
, width != -1 ? String.Format("if(this.width>{0})this.width={0};", width ) : String.Empty
, height != -1 ? String.Format("if(this.height>{0})this.height={0};", height ) : String.Empty );
// break out of the for loop
break;
}
}
}
}
}
}
// set the user's formatted signature
//
if (Post.Section.ForumType == ForumType.Normal &&
CSContext.Current.SiteSettings.EnableUserSignatures &&
!swowUserAsAnonymous)
{
signature.Text = Globals.FormatSignature(Post.User.Profile.SignatureFormatted);
}
// construct the user object
//
User user = CSContext.Current.User;
if (CSContext.Current.SiteSettings.DisplayEditNotesInPost)
{
// TDD 3/18/2004
// This is another huge performance hit. Again we should only be processing the edit notes
// once when they are initially created not for each view of the post.
if (!user.IsAnonymous)
{
if (user.IsForumAdministrator || user.IsModerator)
{
if (Post.EditNotes != null)
{
string formattedNotes = Globals.HtmlNewLine + Globals.HtmlNewLine + Globals.HtmlNewLine + "<div width=\"100%\" class=\"txt3\">" + Post.EditNotes + "</div>";
editNotes.Text = formattedNotes.Replace("\n", Globals.HtmlNewLine);
}
}
}
}
}
public ForumPost Post
{
get
{
if ( _post == null )
{
Object state = ViewState["Post"];
if ( state != null )
{
Int32 postID = (Int32)state;
_post = Posts.GetPost( postID, CSContext.Current.User.UserID, false );
}
}
return _post;
}
set
{
_post = value;
if ( _post != null )
{
ViewState[ "Post" ] = _post.PostID;
}
else
{
ViewState.Remove( "Post" );
}
}
}
ForumPost _post;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -