📄 threadview.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
namespace CommunityServer.Discussions.Controls
{
// *********************************************************************
// ThreadView
//
/// <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 ThreadView : TemplatedWebControl
{
#region Child Controls
//Control threadDisplay;
Control noThreadsToDisplay;
internal Repeater announcements;
internal Repeater threads;
internal ForumRepeater subForums;
Control subForumContainer;
ForumPager pager, pager2;
CurrentPage currentPage, currentPage2;
ThreadSet threadSet;
DateFilter dateFilter;
InlineTextEdit forumName;
InlineTextEdit forumDescription;
Label forumFilterText;
EmailNotificationDropDownList ddlTracking;
ThreadSortDropDownList threadSortddl;
SortOrderDropDownList sortOrderddl;
ForumDropDownList forumFilterddl;
Button sortButton;
Button rememberSettingsButton;
HideReadPostsDropDownList hideReadPosts;
FilterUsersDropDownList filterUsers;
LinkButton moveThreads;
ForumImageButton newPostButton;
ForumImageButton poll;
ForumImageButton newPostButtonDown;
ForumImageButton forumSettings;
HtmlTableRow filterTopicRow;
HtmlTableRow emailNotificationRow;
//Control postbackSourceControl;
AggregateRssLink aggregateRssLink;
RssLink rssLink;
CSContext csContext = CSContext.Current;
internal Forum forum;
bool hideReadPost = false;
bool authUseLocalFilter = false; // Use local filter when user is authenticated, otherwise use previous remembered values.
string anonymousQuerystringFilter = "PageIndex={0}&sb={1}&d={2}&df={3}";
string authQuerystringFilter = "PageIndex={0}&sb={1}&d={2}&df={3}&uf={4}&hrp={5}&lf={6}";
ThreadViewMode mode = ThreadViewMode.Default;
SortThreadsBy sortBy = SortThreadsBy.LastPost;
SortOrder sortOrder = SortOrder.Descending;
ThreadDateFilterMode dateFilterMode = ThreadDateFilterMode.TwoMonths;
ThreadUsersFilter userFilter = ThreadUsersFilter.All;
PostMediaType postMedia = PostMediaType.Empty;
#endregion
public ThreadView()
{
try
{
int modeFromQS = Int32.Parse( csContext.Context.Request.QueryString["mode"] );
// What mode are we running in?
//
if (modeFromQS > 0)
mode = (ThreadViewMode) modeFromQS;
}
catch
{
mode = ThreadViewMode.Default;
}
dateFilterMode = csContext.SiteSettings.DefaultThreadDateFilter;
}
protected override void OnInit(EventArgs e)
{
if (SkinName == null)
ExternalSkinFileName = "View-Threads.ascx";
else
ExternalSkinFileName = SkinName;
// Private messages should not be seen like this
//
//if ((csContext.ForumID == 0) && (csContext.User.IsAnonymous))
if (csContext.SectionID == 0)
throw new CSException(CSExceptionType.SectionNotFound, csContext.SectionID.ToString());
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
DataBind();
base.OnLoad(e);
}
#region DataBind
public override void DataBind()
{
base.DataBind();
// Because the table of threads is databound, visibility on the the checkbox column
// for the multiple move thread functionality is done as part of the databinding process,
// in the skin. Because the move multiple threads link button is not databound, and to
// keep the skin as clean as possible its visibility is set here.
if (!csContext.User.IsForumAdministrator &&
!csContext.User.IsModerator)
{
if (moveThreads != null)
{
moveThreads.Visible = false;
}
}
#region Init by ThreadViewMode
// Init by ThreadViewMode
//
switch (mode)
{
case ThreadViewMode.Active:
if (forumName != null)
forumName.Text = ResourceManager.GetString("ViewActiveThreads_Title");
Head.AddSiteNameTitle(ResourceManager.GetString("ViewActiveThreads_Title"),Context);
UsersOnline.SetLocation(ResourceManager.GetString("ViewActiveThreads_Title"));
if (forumDescription != null)
forumDescription.Text = ResourceManager.GetString("ViewActiveThreads_Description");
break;
case ThreadViewMode.Unanswered:
if (forumName != null)
forumName.Text = ResourceManager.GetString("ViewUnansweredThreads_Title");
Head.AddSiteNameTitle(ResourceManager.GetString("ViewUnansweredThreads_Title"),Context);
UsersOnline.SetLocation(ResourceManager.GetString("ViewUnansweredThreads_Title"));
if (forumDescription != null)
forumDescription.Text = ResourceManager.GetString("ViewUnansweredThreads_Description");
break;
case ThreadViewMode.NotRead:
if (forumName != null)
forumName.Text = ResourceManager.GetString("ViewNotReadThreads_Title");
Head.AddSiteNameTitle(ResourceManager.GetString("ViewNotReadThreads_Title"),Context);
UsersOnline.SetLocation(ResourceManager.GetString("ViewNotReadThreads_Title"));
if (forumDescription != null)
forumDescription.Text = ResourceManager.GetString("ViewNotReadThreads_Description");
break;
case ThreadViewMode.PrivateMessages:
if (forumName != null)
forumName.Text = ResourceManager.GetString("PrivateMessages_Title");
Head.AddSiteNameTitle(ResourceManager.GetString("PrivateMessages_Title"),Context);
UsersOnline.SetLocation(ResourceManager.GetString("PrivateMessages_Title"));
if (forumDescription != null)
forumDescription.Text = ResourceManager.GetString("PrivateMessages_Description");
break;
case ThreadViewMode.Videos:
if (forumName != null)
forumName.Text = ResourceManager.GetString("ViewVideos_Title");
Head.AddSiteNameTitle(ResourceManager.GetString("ViewVideos_Title"),Context);
UsersOnline.SetLocation(ResourceManager.GetString("ViewVideos_Title"));
if (forumDescription != null)
forumDescription.Text = ResourceManager.GetString("ViewVideos_Description");
break;
case ThreadViewMode.MyForums:
// Don't need filter when viewing My Forums
if (forumFilterddl != null)
forumFilterddl.Visible = false;
if (forumFilterText != null)
forumFilterText.Visible = false;
if(forumName != null)
forumName.Text = ResourceManager.GetString("ViewMyForumsThreads_Title");
Head.AddSiteNameTitle(ResourceManager.GetString("ViewMyForumsThreads_Title"),Context);
UsersOnline.SetLocation(ResourceManager.GetString("ViewMyForumsThreads_Title"));
if(forumDescription != null)
forumDescription.Text = ResourceManager.GetString("ViewMyForumsThreads_Description");
break;
default:
//don't need filter when viewing a forum by default
if (forumFilterddl != null)
forumFilterddl.Visible = false;
if (forumFilterText != null)
forumFilterText.Visible = false;
break;
}
#endregion
if (sortButton != null)
sortButton.Text = ResourceManager.GetString("ViewThreads_SortThreads");
if (rememberSettingsButton != null)
rememberSettingsButton.Text = ResourceManager.GetString("ViewThreads_RememberSettings");
if (dateFilter == null)
dateFilter = new DateFilter();
// Apply filtering values on controls when not postback
//
if (!Page.IsPostBack)
SetFilteringControlValues();
// Populate threads list
//
DateTime dateFilterValue;
int forumID = csContext.SectionID;
#region Load forum details by ThreadViewMode
// Load forum details by ThreadViewMode
//
try
{
switch (mode)
{
case ThreadViewMode.Active:
if (forumFilterddl.SelectedForum > 0)
forum = Forums.GetForum( forumFilterddl.SelectedForum, true, true );
else
forum = new Forum(forumFilterddl.SelectedForum);
break;
case ThreadViewMode.Unanswered:
if (forumFilterddl.SelectedForum > 0)
forum = Forums.GetForum( forumFilterddl.SelectedForum, true, true );
else
forum = new Forum(forumFilterddl.SelectedForum);
break;
case ThreadViewMode.NotRead:
if (forumFilterddl.SelectedForum > 0)
forum = Forums.GetForum( forumFilterddl.SelectedForum, true, true );
else
forum = new Forum(forumFilterddl.SelectedForum);
break;
case ThreadViewMode.PrivateMessages:
//TODO: 0 can not be used to hard code Private Forum
forum = Forums.GetForum(0);
break;
case ThreadViewMode.MyForums:
// Don't need filter when viewing My Forums
break;
case ThreadViewMode.Videos:
if (forumFilterddl.SelectedForum > 0)
forum = Forums.GetForum(forumFilterddl.SelectedForum, true, true);
else
forum = new Forum(forumFilterddl.SelectedForum);
break;
default:
// Don't need filter when viewing a forum by default
if (forumID > 0)
{
forum = Forums.GetForum( forumID, true, true );
Permissions.AccessCheck( forum, Permission.View, csContext.User );
bool isAdmin = csContext.User.IsForumAdministrator;
if(isAdmin)
AjaxManager.Register(this,"QuickForumEdit");
if(forumName != null)
{
forumName.Text = forum.Name;
if(isAdmin)
{
forumName.AjaxClientID = this.ClientID;
forumName.AjaxFunction= string.Format("QuickForumEdit.UpdateForumName('{0}',this.innerHTML,null);",this.ClientID);
}
}
if(forumDescription != null) {
forumDescription.Text = forum.Description;
if(isAdmin)
{
forumDescription.AjaxClientID = this.ClientID;
forumDescription.AjaxFunction= string.Format("QuickForumEdit.UpdateForumDescription('{0}',this.innerHTML,null);",this.ClientID);
}
}
Head.AddMetaDescription(Globals.HtmlEncode(forum.Description),Context);
Head.AddSiteNameTitle(Globals.HtmlEncode(forum.Name),Context);
if(this.forum.IsPrivate)
{
UsersOnline.PrivateLocation();
}
else
{
UsersOnline.SetLocation(forum.Name);
}
}
break;
}
}
catch( Exception ex )
{
throw new CSException(CSExceptionType.SectionNotFound, csContext.SectionID.ToString(), ex );
}
#endregion
#region Check user's permissions
// Check user's permissions on forum.
// Also set new post button.
//
if (mode != ThreadViewMode.MyForums)
{
User user = csContext.User;
if( forum.SectionID > 0 )
{
// TODO: Rollback to initial approach after permissions on
// subforums are implemented.
//
// Note: This is a temporary solution untill permissions on subforums
// are handled properly.
ForumPermission p;
if (forum.ParentID > 0)
{
// Lookup for parent forum and verify credentials against it
//
Section parentSection = Forums.GetTopmostParentSection( forum.ParentID );
if (parentSection == null)
throw new CSException( CSExceptionType.AccessDenied );
p = parentSection.ResolvePermission( user ) as ForumPermission;
}
else
{
// No subforums
//
p = forum.ResolvePermission( user ) as ForumPermission;
}
/* Initial approach
ForumPermission p = forum.ResolvePermission( user ) as ForumPermission;
*/
if( !p.Read )
throw new CSException( CSExceptionType.AccessDenied );
if ((!p.Post) || ((mode != ThreadViewMode.Default) && (mode != ThreadViewMode.PrivateMessages)))
{
if (newPostButton != null)
newPostButton.Visible = false;
if (newPostButtonDown != null)
newPostButtonDown.Visible = false;
}
if ((!p.CreatePoll) || ((mode != ThreadViewMode.Default) && (mode != ThreadViewMode.PrivateMessages)))
{
if (poll != null)
poll.Visible = false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -