📄 blogsettingsadmin.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;
namespace CommunityServer.Blogs.Controls
{
public class BlogSettingsAdmin : WeblogAdminTemplatedWebControl
{
#region ChildControls
private TextBox Name;
private TextBox Description;
private TextBox News;
private TextBox AppKey;
private YesNoRadioButtonList IsActive;
private YesNoRadioButtonList IsSearchable;
private YesNoRadioButtonList EnableAutoDelete;
private YesNoRadioButtonList EnableTrackbacks;
private YesNoRadioButtonList EnableRatings;
private YesNoRadioButtonList EnableContact;
private YesNoRadioButtonList EnableAggBugs;
private TextBox AutoDeleteThreshold;
private TextBox Owners;
private YesNoRadioButtonList EnableAnonymousPosting;
private DropDownList ExpiredDays;
private YesNoRadioButtonList EnableComments;
private DropDownList Themes;
private DropDownList Language;
private TextBox CustomCSS;
private TextBox AdminEmail;
private CommentModerationDropDownList ModerationDDL;
private Button Save;
private Button Delete;
#endregion
protected override void OnLoad(EventArgs e)
{
if ( !Page.IsPostBack )
{
this.DataBind();
}
base.OnLoad (e);
}
private bool _isSystem;
/// <summary>
/// Property IsSystem (bool)
/// </summary>
public bool IsSystem
{
get { return this._isSystem; }
set { this._isSystem = value; }
}
protected override void AttachChildControls()
{
Name = (TextBox)FindControl("Name");
Description = (TextBox)FindControl("Description");
News = (TextBox)FindControl("News");
AppKey = (TextBox)FindControl("AppKey");
Owners = (TextBox)FindControl("Owners");
AdminEmail = (TextBox)FindControl("AdminEmail");
ExpiredDays = (DropDownList)FindControl("ExpiredDays");
IsActive = (YesNoRadioButtonList)FindControl("IsActive");
IsSearchable = (YesNoRadioButtonList)FindControl("IsSearchable");
EnableAutoDelete = (YesNoRadioButtonList)FindControl("EnableAutoDelete");
EnableAutoDelete = (YesNoRadioButtonList)FindControl("EnableAutoDelete");
AutoDeleteThreshold = (TextBox)FindControl("AutoDeleteThreshold");
EnableAnonymousPosting = (YesNoRadioButtonList)FindControl("EnableAnonymousPosting");
EnableComments = (YesNoRadioButtonList)FindControl("EnableComments");
EnableTrackbacks = (YesNoRadioButtonList)FindControl("EnableTrackbacks");
EnableRatings = (YesNoRadioButtonList)FindControl("EnableRatings");
EnableContact = (YesNoRadioButtonList)FindControl("EnableContact");
EnableAggBugs = (YesNoRadioButtonList)FindControl("EnableAggBugs");
ModerationDDL = (CommentModerationDropDownList)FindControl("ModerationDDL");
CustomCSS = FindControl("CustomCSS") as TextBox;
Themes = FindControl("Themes") as DropDownList;
Language = FindControl("Language") as DropDownList;
bool enableThemes = WeblogConfiguration.Instance().EnableThemes;
FindControl("Theme_Section").Visible = enableThemes;
FindControl("CustomCSS_Section").Visible = enableThemes;
if(!CurrentUser.IsBlogAdministrator)
{
HideControl("row_AppKey");
HideControl("row_Active");
HideControl("row_Searchable");
HideControl("row_AggBug");
//HideControl("row_AutoDelete");
//HideControl("row_AutoDeleteThreshold");
HideControl("row_AdmimMessage");
HideControl("Delete");
HideControl("row_Owners");
}
Save = (Button)FindControl("Save");
Delete = (Button)FindControl("Delete");
Save.Click +=new EventHandler( Save_Click );
Delete.Click +=new EventHandler( Delete_Click );
}
private void HideControl(string id)
{
FindControl( id ).Visible = false;
}
public override void DataBind()
{
base.DataBind();
Save.Text = CommunityServer.Components.ResourceManager.GetString("Save");
Delete.Text = CommunityServer.Components.ResourceManager.GetString("Delete");
Delete.Attributes["onclick"] = "if ( !confirm('" + ResourceManager.GetString("BlogSettings_DeleteBlogVerify").Replace("'", @"\'") + "') ) {return false; } ";
PopulateThems();
this.LoadWeblog( this.CurrentWeblog );
}
protected virtual void LoadWeblog( Weblog w )
{
if ( w != null )
{
IsActive.SelectedValue = w.IsActive;
Name.Text = w.Name;
News.Text = w.News;
AppKey.Text = w.ApplicationKey;
Description.Text = w.Description;
Owners.Text = w.Owners;
AdminEmail.Text = w.Email;
EnableAutoDelete.SelectedValue = w.EnableAutoDelete;
EnableAutoDelete.SelectedValue = w.EnableAutoDelete;
EnableAnonymousPosting.SelectedValue = w.EnableAnonymousPosting;
AutoDeleteThreshold.Text = w.AutoDeleteThreshold.ToString();
IsSearchable.SelectedValue = w.IsSearchable;
EnableComments.SelectedValue = w.EnableComments;
EnableTrackbacks.SelectedValue = w.EnableTrackbacks;
EnableRatings.SelectedValue = w.EnableRatings;
EnableContact.SelectedValue = w.EnableContact;
EnableAggBugs.SelectedValue = w.EnableAggBugs;
ModerationDDL.Items.FindByValue(w.ModerationType.ToString()).Selected = true;
FindControl( "EnableAnonymousPostingRow" ).Visible = CSContext.Current.SiteSettings.EnableAnonymousUserPosting;
ListItem li = ExpiredDays.Items.FindByValue(w.CommentExpirationDays.ToString());
if(li != null)
li.Selected = true;
string theme = string.Format("{0}@{1}", w.Theme,w.SecondaryCSS).ToLower().Trim();
ListItem liTheme = Themes.Items.FindByValue(theme);
if(liTheme != null)
liTheme.Selected = true;
ListItem liLanguage = Language.Items.FindByValue(w.Langugage);
if(liLanguage != null)
liLanguage.Selected = true;
CustomCSS.Text = w.CSSOverride;
}
}
/// <summary>
/// Populates the Themes dropdown list with all know blog themes and color choices
/// </summary>
private void PopulateThems()
{
Themes.Items.Clear();
string dirPath = Context.Server.MapPath("~/Themes/Blogs");
DirectoryInfo dirAllBlogs = new DirectoryInfo(dirPath);
foreach(DirectoryInfo dirBlog in dirAllBlogs.GetDirectories())
{
DirectoryInfo dirStyle = new DirectoryInfo(Path.Combine(dirBlog.FullName, "Style"));
if(dirStyle.Exists)
{
Themes.Items.Add(new ListItem(dirBlog.Name, dirBlog.Name.ToLower() + "@"));
foreach(FileInfo fi in dirStyle.GetFiles("*.css"))
{
string name = Path.GetFileNameWithoutExtension(fi.FullName).ToLower();
if( name != "style")
{
string themeText = string.Format("{0} - {1}", dirBlog.Name, name);
string themeValue = string.Format("{0}@{1}.css", dirBlog.Name, name);
Themes.Items.Add(new ListItem(themeText,themeValue.ToLower()));
}
}
}
}
}
protected virtual void UpdateWeblog( Weblog w )
{
if(w.ApplicationKey != AppKey.Text.ToLower())
{
string formattedKey = null;
Globals.ValidateApplicationKey(AppKey.Text, out formattedKey);
string oldPath = Globals.GetSiteUrls().Locations["weblogs"] + w.ApplicationKey;
string newPath = Globals.GetSiteUrls().Locations["weblogs"] + formattedKey;
if(WeblogConfiguration.Instance().CreateBlogDirectories)
WebDirectory.Move(oldPath,newPath);
w.ApplicationKey = formattedKey;
}
w.IsActive = IsActive.SelectedValue;
w.Name = Name.Text;
w.Description = Description.Text;
w.News = News.Text;
w.Owners = Owners.Text;
w.Email = AdminEmail.Text;
w.CommentExpirationDays = Int32.Parse(ExpiredDays.SelectedValue);
w.EnableAutoDelete = EnableAutoDelete.SelectedValue;
w.EnableAnonymousPosting = EnableAnonymousPosting.SelectedValue;
w.AutoDeleteThreshold = Int32.Parse( AutoDeleteThreshold.Text );
w.IsSearchable = IsSearchable.SelectedValue;
w.EnableComments = EnableComments.SelectedValue;
w.EnableTrackbacks = EnableTrackbacks.SelectedValue;
w.EnableRatings = EnableRatings.SelectedValue;
w.EnableContact = EnableContact.SelectedValue;
w.EnableAggBugs = EnableAggBugs.SelectedValue;
w.ModerationType = (CommentModerationType)Enum.Parse(typeof(CommentModerationType),ModerationDDL.SelectedValue,false);
string[] theme = Themes.SelectedValue.Split('@');
w.Theme = theme[0];
if(theme.Length > 1)
w.SecondaryCSS = theme[1];
else
w.SecondaryCSS = null;
w.CSSOverride = CustomCSS.Text;
w.Langugage = Language.SelectedValue;
Weblogs.Update(w);
}
protected virtual void DeleteWeblog( Weblog w )
{
Weblogs.Delete(w);
}
private void Delete_Click( Object sender, EventArgs e )
{
if( CSContext.Current.User.IsBlogAdministrator )
{
DeleteWeblog(this.CurrentWeblog);
CSContext.Current.Context.Response.Redirect( BlogUrls.Instance().Manage, true );
}
else
{
throw new CSException( CSExceptionType.AdministrationAccessDenied );
}
}
private void Save_Click( Object sender, EventArgs e )
{
UpdateWeblog( CurrentWeblog );
if(!Globals.RedirectSiteUrl())
CSContext.Current.Context.Response.Redirect( BlogUrls.Instance().Manage, true );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -