温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:BlogEngine v1.3 多皮肤多语言版源码
当前文件路径:BlogEngine/admin/Pages/Settings.aspx.cs

1Using 14
15
public partial class admin_Pages_configuration : System.Web.UI.Page { 16
protected void Page_Load(object sender, EventArgs e) { 17
if (!IsPostBack) { 18
BindThemes(); 19
BindCultures(); 20
BindSettings(); 21
} 22
23
Page.MaintainScrollPositionOnPostBack = true; 24
Page.Title = Resources.labels.settings; 25
26
btnSave.Click += new EventHandler(btnSave_Click); 27
btnSaveTop.Click += new EventHandler(btnSave_Click); 28
btnTestSmtp.Click += new EventHandler(btnTestSmtp_Click); 29
30
btnSaveTop.Text = Resources.labels.saveSettings; 31
btnSave.Text = btnSaveTop.Text; 32
} 33
34
private void btnTestSmtp_Click(object sender, EventArgs e) { 35
try { 36
MailMessage mail = new MailMessage(); 37
mail.From = new MailAddress(txtEmail.Text, txtName.Text); 38
mail.To.Add(mail.From); 39
mail.Subject = "Test mail from " + txtName.Text; 40
mail.Body = "Success"; 41
SmtpClient smtp = new SmtpClient(txtSmtpServer.Text); 42
smtp.Credentials = new System.Net.NetworkCredential(txtSmtpUsername.Text, txtSmtpPassword.Text); 43
smtp.EnableSsl = cbEnableSsl.Checked; 44
smtp.Port = int.Parse(txtSmtpServerPort.Text, CultureInfo.InvariantCulture); 45
smtp.Send(mail); 46
lbSmtpStatus.Text = "Test successfull"; 47
lbSmtpStatus.Style.Add(HtmlTextWriterStyle.Color, "green"); 48
} catch { 49
lbSmtpStatus.Text = "Could not connect"; 50
lbSmtpStatus.Style.Add(HtmlTextWriterStyle.Color, "red"); 51
} 52
} 53
54
private void btnSave_Click(object sender, EventArgs e) { 55
//----------------------------------------------------------------------- 56
// Set Basic settings 57
//----------------------------------------------------------------------- 58
BlogSettings.Instance.Name = txtName.Text; 59
BlogSettings.Instance.Description = txtDescription.Text; 60
BlogSettings.Instance.PostsPerPage = int.Parse(txtPostsPerPage.Text); 61
BlogSettings.Instance.Theme = ddlTheme.SelectedValue; 62
BlogSettings.Instance.MobileTheme = ddlMobileTheme.SelectedValue; 63
BlogSettings.Instance.EnableRelatedPosts = cbShowRelatedPosts.Checked; 64
BlogSettings.Instance.EnableRating = cbEnableRating.Checked; 65
BlogSettings.Instance.ShowDescriptionInPostList = cbShowDescriptionInPostList.Checked; 66
BlogSettings.Instance.TimeStampPostLinks = cbTimeStampPostLinks.Checked; 67
BlogSettings.Instance.ShowPostNavigation = cbShowPostNavigation.Checked; 68
BlogSettings.Instance.Culture = ddlCulture.SelectedValue; 69
BlogSettings.Instance.Timezone = double.Parse(txtTimeZone.Text, CultureInfo.InvariantCulture); 70
71
//----------------------------------------------------------------------- 72
// Set Email settings 73
//----------------------------------------------------------------------- 74
BlogSettings.Instance.Email = txtEmail.Text; 75
BlogSettings.Instance.SmtpServer = txtSmtpServer.Text; 76
BlogSettings.Instance.SmtpServerPort = int.Parse(txtSmtpServerPort.Text); 77
BlogSettings.Instance.SmtpUserName = txtSmtpUsername.Text; 78
BlogSettings.Instance.SmtpPassword = txtSmtpPassword.Text; 79
BlogSettings.Instance.SendMailOnComment = cbComments.Checked; 80
BlogSettings.Instance.EnableSsl = cbEnableSsl.Checked; 81
BlogSettings.Instance.EmailSubjectPrefix = txtEmailSubjectPrefix.Text; 82
83
//----------------------------------------------------------------------- 84
// Set Comments settings 85
//----------------------------------------------------------------------- 86
BlogSettings.Instance.IsCommentsEnabled = cbEnableComments.Checked; 87
BlogSettings.Instance.EnableCountryInComments = cbEnableCountryInComments.Checked; 88
BlogSettings.Instance.IsCoCommentEnabled = cbEnableCoComment.Checked; 89
BlogSettings.Instance.ShowLivePreview = cbShowLivePreview.Checked; 90
BlogSettings.Instance.DaysCommentsAreEnabled = int.Parse(ddlCloseComments.SelectedValue); 91
BlogSettings.Instance.EnableCommentsModeration = cbEnableCommentsModeration.Checked; 92
BlogSettings.Instance.Avatar = rblAvatar.SelectedValue; 93
94
//----------------------------------------------------------------------- 95
// Set Advanced settings 96
//----------------------------------------------------------------------- 97
BlogSettings.Instance.EnableHttpCompression = cbEnableCompression.Checked; 98
BlogSettings.Instance.RemoveWhitespaceInStyleSheets = cbRemoveWhitespaceInStyleSheets.Checked; 99
BlogSettings.Instance.EnableOpenSearch = cbEnableOpenSearch.Checked; 100
BlogSettings.Instance.HandleWwwSubdomain = rblWwwSubdomain.SelectedItem.Value; 101
BlogSettings.Instance.EnableTrackBackSend = cbEnableTrackBackSend.Checked; 102
BlogSettings.Instance.EnableTrackBackReceive = cbEnableTrackBackReceive.Checked; 103
BlogSettings.Instance.EnablePingBackSend = cbEnablePingBackSend.Checked; 104
BlogSettings.Instance.EnablePingBackReceive = cbEnablePingBackReceive.Checked; 105
106
//----------------------------------------------------------------------- 107
// Set Syndication settings 108
//----------------------------------------------------------------------- 109
BlogSettings.Instance.SyndicationFormat = ddlSyndicationFormat.SelectedValue; 110
BlogSettings.Instance.PostsPerFeed = int.Parse(txtPostsPerFeed.Text, CultureInfo.InvariantCulture); 111
BlogSettings.Instance.AuthorName = txtDublinCoreCreator.Text; 112
BlogSettings.Instance.Language = txtDublinCoreLanguage.Text; 113
114
float latitude; 115
if (Single.TryParse(txtGeocodingLatitude.Text, out latitude)) { 116
BlogSettings.Instance.GeocodingLatitude = latitude; 117
} else { 118
BlogSettings.Instance.GeocodingLatitude = Single.MinValue; 119
} 120
float longitude; 121
if (Single.TryParse(txtGeocodingLongitude.Text, out longitude)) { 122
BlogSettings.Instance.GeocodingLongitude = longitude; 123
} else { 124
BlogSettings.Instance.GeocodingLongitude = Single.MinValue; 125
} 126
127
BlogSettings.Instance.Endorsement = txtBlogChannelBLink.Text; 128
129
if (txtAlternateFeedUrl.Text.Trim().Length > 0 && !txtAlternateFeedUrl.Text.Contains("://")) 130
txtAlternateFeedUrl.Text = "http://" + txtAlternateFeedUrl.Text; 131
132
BlogSettings.Instance.AlternateFeedUrl = txtAlternateFeedUrl.Text; 133
134
//----------------------------------------------------------------------- 135
// HTML header section 136
//----------------------------------------------------------------------- 137
BlogSettings.Instance.HtmlHeader = txtHtmlHeader.Text; 138
139
//----------------------------------------------------------------------- 140
// Visitor tracking settings 141
//----------------------------------------------------------------------- 142
BlogSettings.Instance.TrackingScript = txtTrackingScript.Text; 143
144
//----------------------------------------------------------------------- 145
// Persist settings 146
//----------------------------------------------------------------------- 147
BlogSettings.Instance.Save(); 148
Response.Redirect(Request.RawUrl, true); 149
} 150
151
private void BindSettings() { 152
//----------------------------------------------------------------------- 153
// Bind Basic settings 154
//----------------------------------------------------------------------- 155
txtName.Text = BlogSettings.Instance.Name; 156
txtDescription.Text = BlogSettings.Instance.Description; 157
txtPostsPerPage.Text = BlogSettings.Instance.PostsPerPage.ToString(); 158
cbShowRelatedPosts.Checked = BlogSettings.Instance.EnableRelatedPosts; 159
ddlTheme.SelectedValue = BlogSettings.Instance.Theme; 160
ddlMobileTheme.SelectedValue = BlogSettings.Instance.MobileTheme; 161
cbEnableRating.Checked = BlogSettings.Instance.EnableRating; 162
cbShowDescriptionInPostList.Checked = BlogSettings.Instance.ShowDescriptionInPostList; 163
cbTimeStampPostLinks.Checked = BlogSettings.Instance.TimeStampPostLinks; 164
ddlCulture.SelectedValue = BlogSettings.Instance.Culture; 165
txtTimeZone.Text = BlogSettings.Instance.Timezone.ToString(); 166
167
//----------------------------------------------------------------------- 168
// Bind Comments settings 169
//----------------------------------------------------------------------- 170
cbEnableComments.Checked = BlogSettings.Instance.IsCommentsEnabled; 171
cbEnableCountryInComments.Checked = BlogSettings.Instance.EnableCountryInComments; 172
cbEnableCoComment.Checked = BlogSettings.Instance.IsCoCommentEnabled; 173
cbShowLivePreview.Checked = BlogSettings.Instance.ShowLivePreview; 174
cbShowPostNavigation.Checked = BlogSettings.Instance.ShowPostNavigation; 175
ddlCloseComments.SelectedValue = BlogSettings.Instance.DaysCommentsAreEnabled.ToString(); 176
cbEnableCommentsModeration.Checked = BlogSettings.Instance.EnableCommentsModeration; 177
rblAvatar.SelectedValue = BlogSettings.Instance.Avatar; 178
179
//----------------------------------------------------------------------- 180
// Bind Email settings 181
//----------------------------------------------------------------------- 182
txtEmail.Text = BlogSettings.Instance.Email; 183
txtSmtpServer.Text = BlogSettings.Instance.SmtpServer; 184
txtSmtpServerPort.Text = BlogSettings.Instance.SmtpServerPort.ToString(); 185
txtSmtpUsername.Text = BlogSettings.Instance.SmtpUserName; 186
txtSmtpPassword.Text = BlogSettings.Instance.SmtpPassword; 187
cbComments.Checked = BlogSettings.Instance.SendMailOnComment; 188
cbEnableSsl.Checked = BlogSettings.Instance.EnableSsl; 189
txtEmailSubjectPrefix.Text = BlogSettings.Instance.EmailSubjectPrefix; 190
191
//----------------------------------------------------------------------- 192
// Bind Advanced settings 193
//----------------------------------------------------------------------- 194
cbEnableCompression.Checked = BlogSettings.Instance.EnableHttpCompression; 195
cbRemoveWhitespaceInStyleSheets.Checked = BlogSettings.Instance.RemoveWhitespaceInStyleSheets; 196
cbEnableOpenSearch.Checked = BlogSettings.Instance.EnableOpenSearch; 197
rblWwwSubdomain.SelectedValue = BlogSettings.Instance.HandleWwwSubdomain; 198
cbEnablePingBackSend.Checked = BlogSettings.Instance.EnablePingBackSend; 199
cbEnablePingBackReceive.Checked = BlogSettings.Instance.EnablePingBackReceive; 200
cbEnableTrackBackSend.Checked = BlogSettings.Instance.EnableTrackBackSend; 201
cbEnableTrackBackReceive.Checked = BlogSettings.Instance.EnableTrackBackReceive; 202
203
//----------------------------------------------------------------------- 204
// Bind Syndication settings 205
//----------------------------------------------------------------------- 206
ddlSyndicationFormat.SelectedValue = BlogSettings.Instance.SyndicationFormat; 207
txtPostsPerFeed.Text = BlogSettings.Instance.PostsPerFeed.ToString(); 208
txtDublinCoreCreator.Text = BlogSettings.Instance.AuthorName; 209
txtDublinCoreLanguage.Text = BlogSettings.Instance.Language; 210
211
txtGeocodingLatitude.Text = BlogSettings.Instance.GeocodingLatitude != Single.MinValue ? BlogSettings.Instance.GeocodingLatitude.ToString() : String.Empty; 212
txtGeocodingLongitude.Text = BlogSettings.Instance.GeocodingLongitude != Single.MinValue ? BlogSettings.Instance.GeocodingLongitude.ToString() : String.Empty; 213
214
txtBlogChannelBLink.Text = BlogSettings.Instance.Endorsement; 215
txtAlternateFeedUrl.Text = BlogSettings.Instance.AlternateFeedUrl; 216
217
//----------------------------------------------------------------------- 218
// HTML header section 219
//----------------------------------------------------------------------- 220
txtHtmlHeader.Text = BlogSettings.Instance.HtmlHeader; 221
222
//----------------------------------------------------------------------- 223
// Visitor tracking settings 224
//----------------------------------------------------------------------- 225
txtTrackingScript.Text = BlogSettings.Instance.TrackingScript; 226
} 227
228
private void BindThemes() { 229
string path = Server.MapPath(Utils.RelativeWebRoot + "themes/"); 230
foreach (string dic in Directory.GetDirectories(path)) { 231
int index = dic.LastIndexOf(Path.DirectorySeparatorChar) + 1; 232
ddlTheme.Items.Add(dic.Substring(index)); 233
ddlMobileTheme.Items.Add(dic.Substring(index)); 234
} 235
} 236
237
private void BindCultures() { 238
if (File.Exists(Path.Combine(HttpRuntime.AppDomainAppPath, "PrecompiledApp.config"))) { 239
240
string precompiledDir = HttpRuntime.BinDirectory; 241
string[] translations = Directory.GetFiles(precompiledDir, "App_GlobalResources.resources.dll", SearchOption.AllDirectories); 242
foreach (string translation in translations) { 243
string resourceDir = Path.GetDirectoryName(translation).Remove(0, precompiledDir.Length); 244
if (!String.IsNullOrEmpty(resourceDir)) { 245
246
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag(resourceDir); 247
ddlCulture.Items.Add(new ListItem(info.NativeName, resourceDir)); 248
} 249
} 250
} else { 251
252
string path = Server.MapPath(Utils.RelativeWebRoot + "App_GlobalResources/"); 253
foreach (string file in Directory.GetFiles(path, "labels.*.resx")) { 254
255
int index = file.LastIndexOf(Path.DirectorySeparatorChar) + 1; 256
string filename = file.Substring(index); 257
filename = filename.Replace("labels.", string.Empty).Replace(".resx", string.Empty); 258
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag(filename); 259
ddlCulture.Items.Add(new ListItem(info.NativeName, filename)); 260
261
} 262
} 263
} 264
265
}





}