温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.IO; 9
using System.Web.UI.WebControls; 10
11
using SpaceBuilder.Blogs.Components; 12
using SpaceBuilder.Components; 13
using SpaceBuilder.Controls; 14
using SpaceBuilder.Utils; 15
using SpaceBuilder.Security; 16
using SpaceBuilder.Controls.Utils; 17
using SpaceBuilder.Blogs.Configuration; 18
using SpaceBuilder.Posts.Permissions; 19
using TunyNet.Configuration; 20
using TunyNet.Utils; 21
using SpaceBuilder.Configuration; 22
23
namespace SpaceBuilder.Blogs.Controls 24
{ 25
/// <summary> 26
/// blog设置 27
/// </summary> 28
public class BlogSettingsAdmin : WeblogThemedControl 29
{ 30
/// <summary> 31
/// 验证当前用户身份 32
/// </summary> 33
protected override void Authorize(Weblog w) 34
{ 35
base.Authorize(w); 36
37
if (CurrentUser.IsAnonymous) 38
throw new SBException(SBExceptionType.AccessDenied, "Anonymous Blog Posting Access"); 39
40
if (!CurrentUser.IsBlogAdministrator) 41
Permissions.AccessCheck(w, Permission.Post, CurrentUser); 42
43
} 44
45
ChildControls 69
70
protected override void AttachChildControls() 71
{ 72
Name = (TextBox)FindControl("Name"); 73
//Description = (TextBox)FindControl("Description"); 74
//News = (TextBox)FindControl("News"); 75
AppKey = (TextBox)FindControl("AppKey"); 76
//Owners = (TextBox)FindControl("Owners"); 77
78
//ExpiredDays = (DropDownList)FindControl("ExpiredDays"); 79
80
IsActive = (YesNoRadioButtonList)FindControl("IsActive"); 81
IsSearchable = (YesNoRadioButtonList)FindControl("IsSearchable"); 82
EnableAnonymousPosting = (YesNoRadioButtonList)FindControl("EnableAnonymousPosting"); 83
EnableComments = (YesNoRadioButtonList)FindControl("EnableComments"); 84
EnableTrackbacks = (YesNoRadioButtonList)FindControl("EnableTrackbacks"); 85
EnableRatings = (YesNoRadioButtonList)FindControl("EnableRatings"); 86
EnableContact = (YesNoRadioButtonList)FindControl("EnableContact"); 87
EnableAggBugs = (YesNoRadioButtonList)FindControl("EnableAggBugs"); 88
enableCommentsNotification = (YesNoRadioButtonList)FindControl("EnableCommentsNotification"); 89
90
ModerationDDL = (CommentModerationDropDownList)FindControl("ModerationDDL"); 91
92
if (!CurrentUser.IsBlogAdministrator) 93
{ 94
HideControl("row_AppKey"); 95
HideControl("row_Active"); 96
HideControl("row_Searchable"); 97
HideControl("row_AggBug"); 98
99
HideControl("row_AdmimMessage"); 100
HideControl("Delete"); 101
//HideControl("row_Owners"); 102
} 103
104
Save = (Button)FindControl("Save"); 105
Delete = (Button)FindControl("Delete"); 106
107
Save.Click += new EventHandler(Save_Click); 108
Delete.Click += new EventHandler(Delete_Click); 109
} 110
111
protected override void OnLoad(EventArgs e) 112
{ 113
base.OnLoad(e); 114
EnsureChildControls(); 115
if (!Page.IsPostBack) 116
this.Bind(); 117
} 118
119
private void Bind() 120
{ 121
this.SetPageTitle("设置我的博客"); 122
123
Save.Text = SpaceBuilder.Components.ResourceManager.GetString("Save"); 124
Delete.Text = SpaceBuilder.Components.ResourceManager.GetString("Delete"); 125
Delete.Attributes["onclick"] = "if ( !confirm('删除该Blog将同时删除该Blog下的所有文章、评论和引用等。您确认继续删除?') ) {return false; } "; 126
127
this.LoadWeblog(this.CurrentWeblog); 128
} 129
130
protected virtual void LoadWeblog(Weblog w) 131
{ 132
if (w != null) 133
{ 134
if (IsActive != null) 135
IsActive.SelectedValue = w.IsActive; 136
137
AppKey.Text = w.ApplicationKey; 138
//Owners.Text = w.Owners; 139
Name.Text = w.SectionName; 140
EnableAnonymousPosting.SelectedValue = w.EnableAnonymousPosting; 141
enableCommentsNotification.SelectedValue = w.EnableCommentsNotification; 142
IsSearchable.SelectedValue = w.IsSearchable; 143
EnableComments.SelectedValue = w.EnableComments; 144
EnableTrackbacks.SelectedValue = w.EnableTrackbacks; 145
EnableRatings.SelectedValue = w.EnableRatings; 146
EnableContact.SelectedValue = w.EnableContact; 147
EnableAggBugs.SelectedValue = w.EnableAggBugs; 148
149
ModerationDDL.Items.FindByValue(w.ModerationType.ToString()).Selected = true; 150
151
FindControl("EnableAnonymousPostingRow").Visible = SiteSettingsManager.GetSiteSettings().EnableAnonymousUserPosting; 152
153
//ListItem li = ExpiredDays.Items.FindByValue(w.CommentExpirationDays.ToString()); 154
//if (li != null) 155
// li.Selected = true; 156
} 157
158
} 159
160
private void Delete_Click(Object sender, EventArgs e) 161
{ 162
if (SBContext.Current.User.IsBlogAdministrator) 163
{ 164
DeleteWeblog(this.CurrentWeblog); 165
SBContext.Current.Context.Response.Redirect(BlogUrls.Instance().Manage, true); 166
} 167
else 168
{ 169
throw new SBException(SBExceptionType.AdministrationAccessDenied); 170
} 171
} 172
173
174
private void Save_Click(Object sender, EventArgs e) 175
{ 176
Save.Enabled = false; 177
UpdateWeblog(CurrentWeblog); 178
StatusMessage statusMessage = FindControl("StatusMessage") as StatusMessage; 179
if (statusMessage != null) 180
{ 181
statusMessage.MessageType = StatusMessageType.Success; 182
statusMessage.Text = "您的博客设置成功"; 183
statusMessage.Visible = true; 184
statusMessage.EnableRedirect = true; 185
statusMessage.RedirectUrl = UserUrls.Instance().BlogHome(SBContext.Current.ApplicationKey); 186
} 187
188
/** 189
if(!Globals.RedirectSiteUrl()) 190
SBContext.Current.Context.Response.Redirect( BlogUrls.Instance().Manage, true ); 191
**/ 192
} 193
194
protected virtual void UpdateWeblog(Weblog w) 195
{ 196
if (w.ApplicationKey != AppKey.Text.ToLower()) 197
{ 198
string formattedKey = null; 199
Globals.ValidateApplicationKey(AppKey.Text, out formattedKey); 200
201
string oldPath = SiteUrls.Instance().Locations["weblogs"] + w.ApplicationKey; 202
string newPath = SiteUrls.Instance().Locations["weblogs"] + formattedKey; 203
204
//if (WeblogConfiguration.Instance().CreateBlogDirectories) 205
// WebDirectory.Move(oldPath, newPath); 206
207
w.ApplicationKey = formattedKey; 208
} 209
210
//w.IsActive = IsActive.SelectedValue; 211
212
//w.CommentExpirationDays = Int32.Parse(ExpiredDays.SelectedValue); 213
214
//w.EnableAutoDelete = EnableAutoDelete.SelectedValue; 215
w.EnableAnonymousPosting = EnableAnonymousPosting.SelectedValue; 216
//w.AutoDeleteThreshold = Int32.Parse(AutoDeleteThreshold.Text); 217
w.SectionName = Name.Text; 218
w.EnableCommentsNotification = enableCommentsNotification.SelectedValue; 219
w.IsSearchable = IsSearchable.SelectedValue; 220
w.EnableComments = EnableComments.SelectedValue; 221
w.EnableTrackbacks = EnableTrackbacks.SelectedValue; 222
w.EnableRatings = EnableRatings.SelectedValue; 223
w.EnableContact = EnableContact.SelectedValue; 224
w.EnableAggBugs = EnableAggBugs.SelectedValue; 225
226
w.ModerationType = (CommentModerationType)Enum.Parse(typeof(CommentModerationType), ModerationDDL.SelectedValue, false); 227
228
Weblogs.Update(w); 229
} 230
231
protected virtual void DeleteWeblog(Weblog w) 232
{ 233
Weblogs.Delete(w); 234
} 235
236
private bool _isSystem; 237
public bool IsSystem 238
{ 239
get { return this._isSystem; } 240
set { this._isSystem = value; } 241
} 242
243
private void HideControl(string id) 244
{ 245
if (FindControl(id) != null) 246
{ 247
FindControl(id).Visible = false; 248
} 249
} 250
251
} 252
} 253





}