using System; using System.Data; using System.Web; using System.Web.UI; using CMS.CMSHelper; using CMS.Forums; using CMS.GlobalHelper; using CMS.PortalControls; public partial class CMSWebParts_Forums_ForumForum : CMSAbstractWebPart { #region "Public properties" /// /// Gets or sets the site name which should be used for forum group selection. /// public string SiteName { get { return ValidationHelper.GetString(GetValue("SiteName"), String.Empty); } set { SetValue("SiteName", value); viewerForum.SiteName = value; } } /// /// Gets or sets the roles split by semicilon, which roles can report abuse, requires security access state authorize roles. /// public string AbuseReportRoles { get { return ValidationHelper.GetString(GetValue("AbuseReportRoles"), ""); } set { SetValue("AbuseReportRoles", value); viewerForum.AbuseReportRoles = value; } } /// /// Gets or sets the security access enum to abuse report (Authenticated users by default). /// public SecurityAccessEnum AbuseReportAccess { get { return (SecurityAccessEnum)Enum.ToObject(typeof(SecurityAccessEnum), ValidationHelper.GetInteger(GetValue("AbuseReportAccess"), (int)viewerForum.AbuseReportAccess)); } set { SetValue("AbuseReportAccess", value); viewerForum.AbuseReportAccess = value; } } /// /// Gets or sets the value that indicates whether on site management is enabled. /// public bool OnSiteManagement { get { return ValidationHelper.GetBoolean(GetValue("OnSiteManagement"), viewerForum.EnableOnSiteManagement); } set { SetValue("OnSiteManagement", value); viewerForum.EnableOnSiteManagement = value; } } /// /// Gets or sets the value that indicates whether subscription should be enabled. /// public bool EnableSubscription { get { return ValidationHelper.GetBoolean(GetValue("EnableSubscription"), viewerForum.EnableSubscription); } set { SetValue("EnableSubscription", value); viewerForum.EnableSubscription = value; } } /// /// Gets or sets the value that indicates whether private messaging is enabled. /// public bool EnableMessaging { get { return ValidationHelper.GetBoolean(GetValue("EnableMessaging"), viewerForum.EnableMessaging); } set { SetValue("EnableMessaging", value); viewerForum.EnableMessaging = value; } } /// /// Gets or sets the value that indicates whether friendship request is enabled. /// public bool EnableFriendship { get { return ValidationHelper.GetBoolean(GetValue("EnableFriendship"), viewerForum.EnableFriendship); } set { SetValue("EnableFriendship", value); viewerForum.EnableFriendship = value; } } /// /// Gets or sets the value that indicates whether usernam should be link to the user profile page. /// public bool RedirectToUserProfile { get { return ValidationHelper.GetBoolean(GetValue("RedirectToUserProfile"), viewerForum.RedirectToUserProfile); } set { SetValue("RedirectToUserProfile", value); viewerForum.RedirectToUserProfile = value; } } /// /// Gets or sets the value that indicates whether badge info should be displayed. /// public bool DisplayBadgeInfo { get { return ValidationHelper.GetBoolean(GetValue("DisplayBadgeInfo"), viewerForum.DisplayBadgeInfo); } set { SetValue("DisplayBadgeInfo", value); viewerForum.DisplayBadgeInfo = value; } } /// /// Gets or sets the maximal relative level. /// public int MaxRelativeLevel { get { return ValidationHelper.GetInteger(GetValue("MaxRelativeLevel"), viewerForum.MaxRelativeLevel); } set { SetValue("MaxRelativeLevel", value); viewerForum.MaxRelativeLevel = value; } } /// /// Gets or sets the value which determines whether the user can add his signature to the post. /// public bool EnableSignature { get { return ValidationHelper.GetBoolean(GetValue("EnableSignature"), viewerForum.EnableSignature); } set { SetValue("EnableSignature", value); viewerForum.EnableSignature = value; } } /// /// Gets or sets the value which determines whether the user can add the posts to his favorites. /// public bool EnableFavorites { get { return ValidationHelper.GetBoolean(GetValue("EnableFavorites"), viewerForum.EnableFavorites); } set { SetValue("EnableFavorites", value); viewerForum.EnableFavorites = value; } } /// /// Gets or sets maximal size of the image in the post. /// public int AttachmentImageMaxSideSize { get { return ValidationHelper.GetInteger(GetValue("AttachmentImageMaxSideSize"), 100); } set { SetValue("AttachmentImageMaxSideSize", value); viewerForum.AttachmentImageMaxSideSize = AttachmentImageMaxSideSize; } } /// /// Gets or sets the value which determines whether to display image prviews in attachment list. /// public bool DisplayAttachmentImage { get { return ValidationHelper.GetBoolean(GetValue("DisplayAttachmentImage"), viewerForum.DisplayAttachmentImage); } set { SetValue("DisplayAttachmentImage", value); viewerForum.DisplayAttachmentImage = value; } } /// /// Gets or sets the value that indicates whether forum generates friendly URLs. /// public bool UseFriendlyURL { get { return ValidationHelper.GetBoolean(GetValue("UseFriendlyURL"), false); } set { SetValue("UseFriendlyURL", value); viewerForum.UseFriendlyURL = value; } } /// /// Gets or sets the forum base URL without extension. /// public string FriendlyBaseURL { get { return ValidationHelper.GetString(GetValue("FriendlyBaseURL"), ""); } set { SetValue("FriendlyBaseURL", value); viewerForum.FriendlyBaseURL = value; } } /// /// Gets or sets the friendly URL extension. For extension less URLs sets it to empty string. /// public string FriendlyURLExtension { get { return ValidationHelper.GetString(GetValue("FriendlyURLExtension"), viewerForum.FriendlyURLExtension); } set { SetValue("FriendlyURLExtension", value); viewerForum.FriendlyURLExtension = value; } } /// /// Gets or sets value that indicates whether avatars should be displayed. /// public bool EnableAvatars { get { return ValidationHelper.GetBoolean(GetValue("EnableAvatars"), viewerForum.EnableAvatars); } set { SetValue("EnableAvatars", value); viewerForum.EnableAvatars = value; } } /// /// Gets or sets max side sizfe of avatar image. /// public int AvatarMaxSideSize { get { return ValidationHelper.GetInteger(GetValue("AvatarMaxSideSize"), viewerForum.AvatarMaxSideSize); } set { SetValue("AvatarMaxSideSize", value); viewerForum.AvatarMaxSideSize = value; } } /// /// Gets or sets the thread view mode. /// public FlatModeEnum ThreadViewMode { get { switch (ValidationHelper.GetString(GetValue("ThreadViewMode"), "")) { case "newtoold": return FlatModeEnum.NewestToOldest; case "oldtonew": return FlatModeEnum.OldestToNewest; default: return FlatModeEnum.Threaded; } } set { switch (value) { case FlatModeEnum.NewestToOldest: SetValue("ThreadViewMode", "newtoold"); break; case FlatModeEnum.OldestToNewest: SetValue("ThreadViewMode", "oldtonew"); break; default: SetValue("ThreadViewMode", "threaded"); break; } viewerForum.ViewMode = value; } } /// /// Gets or sets the value that indicates whether public user should be redirected /// to the logon page if hasn't permissions to required action /// public bool RedirectUnauthorized { get { return ValidationHelper.GetBoolean(GetValue("UseRedirectForUnauthorized"), viewerForum.RedirectUnauthorized); } set { SetValue("UseRedirectForUnauthorized", value); viewerForum.RedirectUnauthorized = value; } } /// /// Gets or sets the logon page URL. /// public string LogonPageURL { get { return ValidationHelper.GetString(GetValue("LogonPageURL"), viewerForum.LogonPageURL); } set { SetValue("LogonPageURL", value); viewerForum.LogonPageURL = value; } } /// /// Gets or sets the access denied page URL (URL where the user is redirected when /// trying to access forum for which the user is unauthorized). /// public string AccessDeniedPageURL { get { return ValidationHelper.GetString(GetValue("AccessDeniedPageURL"), viewerForum.AccessDeniedPageURL); } set { SetValue("AccessDeniedPageURL", value); viewerForum.AccessDeniedPageURL = value; } } /// /// Gets or sets the value that indicates whether paging is enabled for thread, this option is depend on select forum layout. /// public bool EnableThreadPaging { get { return ValidationHelper.GetBoolean(GetValue("EnableThreadPaging"), viewerForum.EnableThreadPaging); } set { SetValue("EnableThreadPaging", value); viewerForum.EnableThreadPaging = value; } } /// /// Gets or sets the thread page size. /// public int ThreadPageSize { get { return ValidationHelper.GetInteger(GetValue("ThreadPageSize"), viewerForum.ThreadPageSize); } set { SetValue("ThreadPageSize", value); viewerForum.ThreadPageSize = value; } } /// /// Gets or sets the value that indicates whether paging is enabled for thread, this option is depend on select forum layout. /// public bool EnablePostsPaging { get { return ValidationHelper.GetBoolean(GetValue("EnablePostsPaging"), viewerForum.EnablePostsPaging); } set { SetValue("EnablePostsPaging", value); viewerForum.EnablePostsPaging = value; } } /// /// Gets or sets the thread page size. /// public int PostsPageSize { get { return ValidationHelper.GetInteger(GetValue("PostsPageSize"), viewerForum.PostsPageSize); } set { SetValue("PostsPageSize", value); viewerForum.PostsPageSize = value; } } /// /// Gets or sets the show mode (available only for tree forum). /// public ShowModeEnum ShowMode { get { return ForumModes.GetShowMode(ValidationHelper.GetString(GetValue("ShowMode"), viewerForum.ShowMode.ToString())); } set { SetValue("ShowMode", value); viewerForum.ShowMode = value; } } /// /// Gets or sets the value that indicates whether tree is expanded (available only for tree view mode). /// public bool ExpandTree { get { return ValidationHelper.GetBoolean(GetValue("ExpandTree"), viewerForum.ExpandTree); } set { SetValue("ExpandTree", value); viewerForum.ExpandTree = value; } } /// /// Gets forum layout based on current forum code name due to backward compatibility. /// private string LayoutCodeName { get { if ((PartInstance != null) && (PartInstance.WebPartType == "ForumTree")) { return "Tree"; } else { return "Flat"; } } } /// /// Gets or sets the group code name. /// public string ForumLayout { get { return ValidationHelper.GetString(GetValue("ForumViewMode"), LayoutCodeName); } set { SetValue("ForumViewMode", value); viewerForum.ForumLayout = value; } } /// /// Gets or sets the forum code name. /// public string ForumName { get { return ValidationHelper.GetString(GetValue("ForumName"), ""); } set { SetValue("ForumName", value); viewerForum.ForumName = value; } } /// /// Gets or sets value that indicates whether logging activity is performed. /// public bool LogActivity { get { return ValidationHelper.GetBoolean(GetValue("LogActivity"), false); } set { SetValue("LogActivity", value); viewerForum.LogActivity = value; } } #endregion /// /// OnContent load override. /// public override void OnContentLoaded() { SetupControl(); base.OnContentLoaded(); } /// /// Reloads the control data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } /// /// Initialize control. /// protected void SetupControl() { if (StopProcessing) { viewerForum.StopProcessing = true; } else { // Forum settings viewerForum.SiteName = SiteName; viewerForum.ForumName = ForumName; viewerForum.ForumLayout = ForumLayout; // Friendly URLs viewerForum.UseFriendlyURL = UseFriendlyURL; viewerForum.FriendlyURLExtension = FriendlyURLExtension; viewerForum.FriendlyBaseURL = FriendlyBaseURL; // Post options viewerForum.DisplayAttachmentImage = DisplayAttachmentImage; viewerForum.AttachmentImageMaxSideSize = AttachmentImageMaxSideSize; viewerForum.EnableAvatars = EnableAvatars; viewerForum.AvatarMaxSideSize = AvatarMaxSideSize; viewerForum.ViewMode = ThreadViewMode; viewerForum.EnableFavorites = EnableFavorites; viewerForum.EnableSignature = EnableSignature; viewerForum.MaxRelativeLevel = MaxRelativeLevel; viewerForum.DisplayBadgeInfo = DisplayBadgeInfo; viewerForum.RedirectToUserProfile = RedirectToUserProfile; viewerForum.EnableFriendship = EnableFriendship && UIHelper.IsFriendsModuleEnabled(CMSContext.CurrentSiteName); viewerForum.EnableMessaging = EnableMessaging; // Behaviour viewerForum.EnableSubscription = EnableSubscription; viewerForum.EnableOnSiteManagement = OnSiteManagement; viewerForum.RedirectUnauthorized = RedirectUnauthorized; viewerForum.LogonPageURL = LogonPageURL; viewerForum.AccessDeniedPageURL = AccessDeniedPageURL; // Abuse report viewerForum.AbuseReportAccess = AbuseReportAccess; viewerForum.AbuseReportRoles = AbuseReportRoles; //Paging viewerForum.EnableThreadPaging = EnableThreadPaging; viewerForum.ThreadPageSize = ThreadPageSize; viewerForum.EnablePostsPaging = EnablePostsPaging; viewerForum.PostsPageSize = PostsPageSize; // Log activity viewerForum.LogActivity = LogActivity; // Tree forum properties viewerForum.ShowMode = ShowMode; viewerForum.ExpandTree = ExpandTree; if (UseUpdatePanel) { viewerForum.UseRedirectAfterAction = false; } } } /// /// OnPreRender - hide webpart if content is not displayed. /// protected override void OnPreRender(EventArgs e) { Visible = viewerForum.Visible && !StopProcessing; base.OnPreRender(e); } }