您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.1源代码>>BlogControls/Admin/BlogSettingsAdmin.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:文件类型 SpaceBuider11/BlogControls/Admin/BlogSettingsAdmin.cs打开代码结构图
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Inc. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.IO; 9using System.Web.UI.WebControls; 10 11using SpaceBuilder.Blogs.Components; 12using SpaceBuilder.Components; 13using SpaceBuilder.Controls; 14using SpaceBuilder.Utils; 15using SpaceBuilder.Security; 16using SpaceBuilder.Controls.Utils; 17using SpaceBuilder.Blogs.Configuration; 18using SpaceBuilder.Posts.Permissions; 19using TunyNet.Configuration; 20using TunyNet.Utils; 21using SpaceBuilder.Configuration; 22 23namespace 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 //检查用户针对博客w是否有发布主题权限 42 Permissions.AccessCheck(w, Permission.Post, CurrentUser); 43 44 } 45 46 ChildControls 107 /// <summary> 108 /// 从加载的皮肤文件中获取具体控件 109 /// </summary> 110 protected override void AttachChildControls() 111 { 112 Name = (TextBox)FindControl("Name"); 113 //Description = (TextBox)FindControl("Description"); 114 //News = (TextBox)FindControl("News"); 115 AppKey = (TextBox)FindControl("AppKey"); 116 //Owners = (TextBox)FindControl("Owners"); 117 118 //ExpiredDays = (DropDownList)FindControl("ExpiredDays"); 119 120 IsActive = (YesNoRadioButtonList)FindControl("IsActive"); 121 EnableAnonymousPosting = (YesNoRadioButtonList)FindControl("EnableAnonymousPosting"); 122 EnableComments = (YesNoRadioButtonList)FindControl("EnableComments"); 123 EnableTrackbacks = (YesNoRadioButtonList)FindControl("EnableTrackbacks"); 124 EnableRatings = (YesNoRadioButtonList)FindControl("EnableRatings"); 125 EnableAggBugs = (YesNoRadioButtonList)FindControl("EnableAggBugs"); 126 127 ModerationDDL = (CommentModerationDropDownList)FindControl("ModerationDDL"); 128 129 if (!CurrentUser.IsBlogAdministrator) 130 { 131 HideControl("row_AppKey"); 132 HideControl("row_Active"); 133 HideControl("row_AggBug"); 134 135 HideControl("row_AdmimMessage"); 136 HideControl("Delete"); 137 //HideControl("row_Owners"); 138 } 139 140 Save = (Button)FindControl("Save"); 141 Delete = (Button)FindControl("Delete"); 142 143 Save.Click += new EventHandler(Save_Click); 144 Delete.Click += new EventHandler(Delete_Click); 145 } 146 147 protected override void OnLoad(EventArgs e) 148 { 149 base.OnLoad(e); 150 EnsureChildControls(); 151 if (!Page.IsPostBack) 152 this.Bind(); 153 } 154 155 private void Bind() 156 { 157 this.SetPageTitle("设置我的博客"); 158 //从资源文件中获取Save对应的名称 159 Save.Text = SpaceBuilder.Components.ResourceManager.GetString("Save"); 160 //从资源文件中获取Delete对应的名称 161 Delete.Text = SpaceBuilder.Components.ResourceManager.GetString("Delete"); 162 //添加客户端单击属性,弹出删除提示框。按钮被单击时,会首先触发它 163 Delete.Attributes["onclick"] = "if ( !confirm('删除该Blog将同时删除该Blog下的所有文章、评论和引用等。您确认继续删除?') ) {return false; } "; 164 //加载当前博客 165 this.LoadWeblog(this.CurrentWeblog); 166 } 167 /// <summary> 168 /// 加载博客,派生类可以重写它 169 /// </summary> 170 /// <param name="w">博客实体</param> 171 protected virtual void LoadWeblog(Weblog w) 172 { 173 if (w != null) 174 { 175 if (IsActive != null) 176 IsActive.SelectedValue = w.IsActive; 177 178 AppKey.Text = w.ApplicationKey; 179 //Owners.Text = w.Owners; 180 Name.Text = w.SectionName; 181 EnableAnonymousPosting.SelectedValue = w.EnableAnonymousPosting; 182 EnableComments.SelectedValue = w.EnableComments; 183 EnableTrackbacks.SelectedValue = w.EnableTrackbacks; 184 EnableRatings.SelectedValue = w.EnableRatings; 185 EnableAggBugs.SelectedValue = w.EnableAggBugs; 186 187 ModerationDDL.Items.FindByValue(w.ModerationType.ToString()).Selected = true; 188 //设置匿名发帖的可见性。如果站点配置信息里允许匿名发帖,则可见。否则不可见 189 FindControl("EnableAnonymousPostingRow").Visible = SiteSettingsManager.GetSiteSettings().EnableAnonymousUserPosting; 190 191 //ListItem li = ExpiredDays.Items.FindByValue(w.CommentExpirationDays.ToString()); 192 //if (li != null) 193 // li.Selected = true; 194 } 195 196 } 197 198 private void Delete_Click(Object sender, EventArgs e) 199 { 200 if (SBContext.Current.User.IsBlogAdministrator) 201 { 202 //删除当前博客 203 DeleteWeblog(this.CurrentWeblog); 204 SBContext.Current.Context.Response.Redirect(BlogUrls.Instance().Manage, true); 205 } 206 else 207 { 208 throw new SBException(SBExceptionType.AdministrationAccessDenied); 209 } 210 } 211 212 213 private void Save_Click(Object sender, EventArgs e) 214 { 215 Save.Enabled = false; 216 UpdateWeblog(CurrentWeblog); 217 StatusMessage statusMessage = FindControl("StatusMessage") as StatusMessage; 218 if (statusMessage != null) 219 { 220 statusMessage.MessageType = StatusMessageType.Success; 221 statusMessage.Text = "您的博客设置成功"; 222 statusMessage.Visible = true; 223 statusMessage.EnableRedirect = true; 224 statusMessage.RedirectUrl = UserUrls.Instance().BlogHome(SBContext.Current.ApplicationKey); 225 } 226 227 /** 228 if(!Globals.RedirectSiteUrl()) 229 SBContext.Current.Context.Response.Redirect( BlogUrls.Instance().Manage, true ); 230 **/ 231 } 232 233 protected virtual void UpdateWeblog(Weblog w) 234 { 235 if (w.ApplicationKey != AppKey.Text.ToLower()) 236 { 237 string formattedKey = null; 238 Globals.ValidateApplicationKey(AppKey.Text, out formattedKey); 239 240 string oldPath = SiteUrls.Instance().Locations["weblogs"] + w.ApplicationKey; 241 string newPath = SiteUrls.Instance().Locations["weblogs"] + formattedKey; 242 243 //if (WeblogConfiguration.Instance().CreateBlogDirectories) 244 // WebDirectory.Move(oldPath, newPath); 245 246 w.ApplicationKey = formattedKey; 247 } 248 249 //w.IsActive = IsActive.SelectedValue; 250 251 //w.CommentExpirationDays = Int32.Parse(ExpiredDays.SelectedValue); 252 253 //w.EnableAutoDelete = EnableAutoDelete.SelectedValue; 254 w.EnableAnonymousPosting = EnableAnonymousPosting.SelectedValue; 255 //w.AutoDeleteThreshold = Int32.Parse(AutoDeleteThreshold.Text); 256 w.SectionName = Name.Text; 257 w.EnableComments = EnableComments.SelectedValue; 258 w.EnableTrackbacks = EnableTrackbacks.SelectedValue; 259 w.EnableRatings = EnableRatings.SelectedValue; 260 w.EnableAggBugs = EnableAggBugs.SelectedValue; 261 //设置文章评论审核类型 262 w.ModerationType = (CommentModerationType)Enum.Parse(typeof(CommentModerationType), ModerationDDL.SelectedValue, false); 263 //更新博客 264 Weblogs.Update(w); 265 } 266 /// <summary> 267 /// 删除博客 268 /// </summary> 269 /// <param name="w">博客实体</param> 270 protected virtual void DeleteWeblog(Weblog w) 271 { 272 Weblogs.Delete(w); 273 } 274 275 //private bool _isSystem; 276 //public bool IsSystem 277 //{ 278 // get { return this._isSystem; } 279 // set { this._isSystem = value; } 280 //} 281 /// <summary> 282 /// 隐藏控件 283 /// </summary> 284 /// <param name="id">控件ID</param> 285 private void HideControl(string id) 286 { 287 if (FindControl(id) != null) 288 { 289 FindControl(id).Visible = false; 290 } 291 } 292 293 } 294} 295
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.1源代码