📄 postflatview.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
namespace CommunityServer.Discussions.Controls
{
// *********************************************************************
// PostFlatView
//
/// <summary>
/// This server control is used to display top level threads. Note, a thread
/// is a post with more information. The Thread class inherits from the Post
/// class.
/// </summary>
///
// ********************************************************************/
public class PostFlatView : TemplatedWebControl
{
CSContext csContext;
ForumPost post;
Forum forum;
ForumPermission permission;
Forum reportForum;
User currentUser;
Thread postThread;
bool siteEnableUserPostingAsAnonymous = false;
bool forumEnableUserPostingAsAnonymous = false;
protected override void OnInit(EventArgs e) {
if (SkinName == null)
ExternalSkinFileName = "View-PostFlatView.ascx";
else
ExternalSkinFileName = SkinName;
this.csContext = CSContext.Current;
this.currentUser = csContext.User;
this.post = Posts.GetPost( csContext.PostID, currentUser.UserID, true, true );
// Are we looking up the forum by forum id or post id
//
if (csContext.SectionID > 0)
{
forum = Forums.GetForum(csContext.SectionID, true, true);
}
else if (csContext.PostID > 0)
{
forum = Forums.GetForumByPostID(csContext.PostID, csContext.User.UserID, true );
}
if (forum == null)
{
PermissionBase.RedirectOrExcpetion(CSExceptionType.SectionNotFound, csContext.SectionID.ToString());
}
if (forum.SectionID == 0)
{
UserMessages.InvalidateMessageCount(currentUser.UserID);
}
else
{
SearchFilters.SetFilters(forum,ForumGroups.GetForumGroup(forum.GroupID),Context);
}
//Get the report forum
reportForum = Forums.GetReportedForum();
// Get site and forum settings if users may post as anonymous.
//
siteEnableUserPostingAsAnonymous = ForumConfiguration.Instance().EnableUserPostingAsAnonymous;
forumEnableUserPostingAsAnonymous = forum.EnableAnonymousPostingForUsers;
permission = forum.ResolvePermission( currentUser ) as ForumPermission;
if( !permission.Read )
PermissionBase.RedirectOrExcpetion(CSExceptionType.AccessDenied);
base.OnInit(e);
}
protected string BuildQuickReplyScript()
{
string url = ForumUrls.Instance().QuickReply;
StringBuilder sb = new StringBuilder();
sb.AppendFormat(@"<script type=""text/javascript"">{0}", Environment.NewLine);
sb.AppendFormat(@"function showQuickReply(postID) {{{0}", Environment.NewLine);
sb.AppendFormat(@" Telligent_Modal.Open('{0}'+postID,{1},{2},reLoadPage); {3}", url,600,400, Environment.NewLine);
sb.AppendFormat(@"}}{0}", Environment.NewLine);
// sb.Append("function reloadCallback(res){ if(shouldRefresh){refresh();}}");
// sb.Append(Environment.NewLine);
sb.Append("function reLoadPage(shouldRefresh){ if(shouldRefresh){refresh();}}");
sb.Append(Environment.NewLine);
sb.AppendFormat(@"</script>{0}", Environment.NewLine);
return sb.ToString();
}
protected override void OnLoad(EventArgs e)
{
AjaxManager.Register(this, "PostFlatViewAJAX", true, AjaxDebug.None);
if ( !Page.IsPostBack || !EnableViewState )
{
DataBind();
}
JavaScript.RegisterRefresh(this.Page);
JavaScript.RegisterToolTips(this.Page);
Page.RegisterClientScriptBlock("QuickReply", BuildQuickReplyScript());
base.OnLoad(e);
}
[AjaxMethod(IncludeControlValuesWithCallBack=false)]
public void TogglePostStatus(int postID)
{
ForumPost post = Posts.GetPost(postID, csContext.User.UserID, false, false, false);
post.PostStatus ^= PostStatus.IsAnswer;
Posts.UpdatePost(post, csContext.User.UserID);
}
#region Child Controls
Repeater postRepeater;
ForumPager pager, pager2;
RatePost rateThread;
CurrentPage currentPage, currentPage2;
RequiredFieldValidator postBodyValidator;
ForumImageButton prevThread;
ForumImageButton nextThread;
Label forumName;
Label postSubject;
ForumImageButton newPostButtonUp;
ForumImageButton newPostButtonDown;
Label threadStats;
PlaceHolder pagingArea, pagingArea2;
DropDownList sortOrder;
ITrackedThread trackingButton;
ModerationContextMenu modContextMenu;
//StatusDropDownList threadStatus;
#endregion
#region Skin
protected override void AttachChildControls()
{
postRepeater = (Repeater)FindControl( "PostRepeater" );
pager = (ForumPager)FindControl( "Pager" );
pager2 = (ForumPager) FindControl("Pager2");
rateThread = (RatePost)FindControl( "RateThread" );
currentPage = (CurrentPage)FindControl( "CurrentPage" );
currentPage2 = (CurrentPage)FindControl("CurrentPage2");
postBodyValidator = (RequiredFieldValidator)FindControl( "PostBodyValidator" );
prevThread = (ForumImageButton)FindControl( "PrevThread" );
nextThread = (ForumImageButton)FindControl( "NextThread" );
forumName = (Label)FindControl( "ForumName" );
postSubject = (Label)FindControl( "PostSubject" );
newPostButtonUp = (ForumImageButton)FindControl("NewPostButtonUp");
newPostButtonDown = (ForumImageButton)FindControl("NewPostButtonDown");
threadStats = (Label)FindControl("ThreadStats");
pagingArea = (PlaceHolder)FindControl( "PagingArea" );
pagingArea2 = (PlaceHolder) FindControl("PagingArea2");
sortOrder = (DropDownList)FindControl( "SortOrder" );
trackingButton = FindControl( "TrackingButton" ) as ITrackedThread;
modContextMenu = (ModerationContextMenu) FindControl ("ModerationContextMenu");
InitializeChildControls();
}
private void InitializeChildControls()
{
sortOrder.SelectedIndexChanged += new EventHandler(sortOrder_SelectedIndexChanged);
// Read if they have a cookie for a custom sort order set
if(Context.Request.Cookies["PostSortOrder" + csContext.PostID] != null)
sortOrder.Items.FindByValue( Context.Request.Cookies["PostSortOrder" + csContext.PostID].Value ).Selected = true;
else
sortOrder.Items.FindByValue( ((int)this.currentUser.PostSortOrder).ToString() ).Selected = true;
postRepeater.ItemDataBound += new RepeaterItemEventHandler(postRepeater_ItemDataBound);
}
#endregion
#region Event Handlers
private void ModerationMenu_PostModerateRefresh (object sender, EventArgs e)
{
Posts.ClearPosts(csContext.PostID, pager.PageIndex, pager.PageSize, 0, 0);
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
}
public void ThreadStatus_Changed (object sender, ThreadStatusEventArgs e) {
if (e.ThreadID <= 0)
return;
Threads.UpdateThreadStatus( e.ThreadID, e.Status );
}
private void sortOrder_SelectedIndexChanged(object sender, EventArgs e)
{
// Set a cookie to store their sort preference for this post until they close the browser
HttpCookie cookie = new HttpCookie("PostSortOrder" + csContext.PostID, sortOrder.SelectedValue.ToString());
cookie.Expires = DateTime.MinValue;
Context.Response.Cookies.Set(cookie);
Context.Response.Redirect(Context.Request.RawUrl);
}
#endregion
#region DataBinding
public override void DataBind()
{
base.DataBind();
#region prev/next thread navigation
if (this.prevThread != null)
prevThread.Post = post;
if ( this.nextThread != null)
nextThread.Post = post;
#endregion
// Get the post's thread
postThread = Threads.GetThread( post.ThreadID );
if (!postThread.IsApproved)
throw new CSException(CSExceptionType.PostNotFound, "The post starter is not approved");
if(postThread != null)
{
Head.AddSiteNameTitle(postThread.Subject,Context);
if(this.forum.IsPrivate)
{
UsersOnline.PrivateLocation();
}
else
{
UsersOnline.SetLocation(postThread.Subject);
}
}
if (rateThread != null)
{
rateThread.Post = this.post;
rateThread.Thread = postThread;
if (csContext.SiteSettings.SectionRatingType == SectionRatingType.ThreadRating)
rateThread.Visible = true;
}
if (modContextMenu != null)
{
modContextMenu.Forum = forum;
modContextMenu.PostModerateRefresh += new EventHandler(ModerationMenu_PostModerateRefresh);
}
if (forumName != null)
forumName.Text = postThread.Subject;
if (postSubject != null)
postSubject.Text = post.Subject;
if(trackingButton != null)
{
trackingButton.IsTracked = ThreadTracking.IsTracked(post.ThreadID,csContext.User.UserID);
trackingButton.ThreadID = post.ThreadID;
}
// Get a populated thread set
//
PostSet postSet = Posts.GetPosts(csContext.PostID, pager.PageIndex, pager.PageSize, 0, Int32.Parse(sortOrder.SelectedValue), true);
postRepeater.DataSource = postSet.Posts;
postRepeater.DataBind();
pager.TotalRecords = currentPage.TotalRecords = postSet.TotalRecords;
pager.UrlPattern = ForumUrls.Instance().PostPagedRaw(csContext.PostID);
if (pager2 != null)
{
pager2.PageIndex = pager.PageIndex;
pager2.TotalRecords = pager.TotalRecords;
pager2.UrlPattern = pager.UrlPattern;
}
currentPage.TotalPages = pager.CalculateTotalPages();
currentPage.PageIndex = pager.PageIndex;
if (currentPage2 != null)
{
currentPage2.TotalRecords = currentPage.TotalRecords;
currentPage2.TotalPages = currentPage.TotalPages;
currentPage2.PageIndex = pager.PageIndex;
}
if (pagingArea != null)
pagingArea.Visible = ( currentPage.TotalPages > 1 );
if (pagingArea2 != null)
pagingArea2.Visible = (currentPage.TotalPages > 1);
#region Post/Reply Permissions
if (newPostButtonUp != null)
{
newPostButtonUp.Visible = UserCanPost();
}
if (newPostButtonDown != null)
{
newPostButtonDown.Visible = UserCanPost();
}
#endregion
#region Post Stats
string[] info = new string[3];
if (threadStats != null)
{
// Quick access to the first post, and only access
// data we have (no trips to the DP).
//
if (postSet.TotalRecords > 0)
{
ForumPost topPost;
if (Int32.Parse(sortOrder.SelectedValue) == (int)SortOrder.Ascending)
topPost = (ForumPost) postSet.Posts[0];
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -