📄 createeditblogpost.ascx.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Blogs.Controls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using TWC = Telligent.Web.UI;
using Calendar = ComponentArt.Web.UI.Calendar;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
namespace CommunityServer.ControlPanel.Blogs
{
/// <summary>
/// Summary description for Skin_CreateEditBlogPost.
/// </summary>
public class CreateEditBlogPost : BaseBlogControl
{
#region Controls
protected TWC.TabbedPanes EditorTabs;
protected Controls.ResourceControl Message;
protected ResourceLinkButton PostButton;
protected ResourceLinkButton SaveButton;
protected ResourceLinkButton SaveEditButton;
protected Literal PreviewTitle;
protected Literal PreviewBody;
protected HtmlGenericControl ErrorPanel;
protected HtmlGenericControl Post;
protected HtmlGenericControl Preview;
protected TextBox PostSubject;
protected Editor PostBody;
protected TextBox postName;
protected TextBox postExcerpt;
protected RegularExpressionValidator vRegexPostName;
protected RequiredFieldValidator postSubjectValidator;
protected RequiredFieldValidator postBodyValidator;
protected ValidationSummary valSummary;
protected CommentModerationDropDownList ModerationDDL;
protected TextBox postDate;
protected Label DateError;
protected Calendar DatePicker;
protected DropDownRange HourPicker;
protected DropDownRange MinutePicker;
protected DropDownList AMPM;
protected HtmlInputHidden ServeruploadtempID;
protected HtmlInputHidden Serverfriendlyfilename;
protected Label serverfilename;
protected System.Web.UI.Control RemoveAttachment;
protected FeedbackNotificationDropDownList NotificationType;
protected System.Web.UI.HtmlControls.HtmlTableRow CrossPostingRow;
protected TextBox VideoUrl;
protected TextBox VideoImageUrl;
protected TextBox VideoDuration;
protected TextBox VideoWidth;
protected TextBox VideoHeight;
protected TagEditor Tags;
protected HtmlContainerControl DefaultTagsContainer;
protected Literal DefaultTags;
#endregion
#region Field / Properties
protected Modal Modal1;
protected Script Script1;
protected CSContext context = CSContext.Current;
protected InkWebControl inkWeb = null;
protected CommunityServer.Controls.Script Script2;
protected System.Web.UI.HtmlControls.HtmlGenericControl ButtonSet;
protected CheckBox EnableInk = null;
protected bool EnableAttachments
{
get
{
return Permissions.ValidatePermissions(this.CurrentWeblog,Permission.LocalAttachment, context.User) || Permissions.ValidatePermissions(this.CurrentWeblog,Permission.RemoteAttachment, context.User);
}
}
protected bool EnableInkSupport
{
get
{
return context.SiteSettings.EnableInk && context.User.EnableInk && Permissions.ValidatePermissions(this.CurrentWeblog,Permission.Ink, context.User);
}
}
protected bool EnableVideos
{
get
{
return Permissions.ValidatePermissions(this.CurrentWeblog,Permission.Video, context.User);
}
}
#endregion
override protected void OnInit(EventArgs e)
{
this.PostButton.Click += new System.EventHandler(this.PostButton_Click);
this.SaveButton.Click +=new EventHandler(SaveButton_Click);
this.SaveEditButton.Click +=new EventHandler(SaveEditButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
base.OnInit(e);
}
private void Page_Load(object sender, EventArgs e)
{
AjaxManager.Register(this,"CreateEditBlogPost");
this.PanelPage.IsInEdit = true;
UI.PanelPage.RegisterControlForByPass(PostButton);
UI.PanelPage.RegisterControlForByPass(SaveButton);
UI.PanelPage.RegisterControlForByPass(SaveEditButton);
if(EnableInk != null)
EnableInk.Text = ResourceManager.GetString("CP_Blogs_CreateEditBlogPost_EnableInk");
if (!Page.IsPostBack)
{
Bind();
}
}
const int attachTabIndex = 1;
const int inkTabIndex = 3;
const int videoTabIndex = 2;
void Bind()
{
EditorTabs.Panes[attachTabIndex].Visible = this.EnableAttachments;
// EditorTabs.Tabs[5].Visible = false;
// EditorTabs.Tabs[4].Visible = false;
// SaveEditButton.Visible = false;
if(this.EnableInkSupport)
{
inkWeb.Enabled = true;
inkWeb.RegisterLinkButton(this.PostButton);
}
else
{
inkWeb.Enabled = false;
}
EditorTabs.Panes[inkTabIndex].Visible = inkWeb.Enabled;
CrossPostingRow.Visible = WeblogConfiguration.Instance().EnableCrossPosting;
vRegexPostName.ValidationExpression = WeblogPosts.PostNamePattern;
vRegexPostName.ErrorMessage = ResourceManager.GetString("Weblog_CreateEditBlogPost_PostNameRegexValidator");
postSubjectValidator.ErrorMessage = ResourceManager.GetString("Weblog_CreateEditBlogPost_TitleValidator");
postBodyValidator.ErrorMessage = ResourceManager.GetString("Weblog_CreateEditBlogPost_BodyValidator");
valSummary.HeaderText = ResourceManager.GetString("Weblog_CreateEditBlogPost_ValidatorSummary");
EditorTabs.Panes[videoTabIndex].Visible = this.EnableVideos;
if (context.PostID > 0)
{
WeblogPost post = WeblogPosts.GetPost(context.PostID, true, false, false);
if (post != null)
{
if(post.HasInk)
{
if(inkWeb.Enabled)
{
InkData ink = Ink.Get(post.InkID);
if(ink != null)
{
inkWeb.InkData = ink.InkString;
}
}
}
PopulateCategories(post.BlogPostType);
PostSubject.Text = Server.HtmlDecode(post.Subject);
PostBody.Text = post.Body;
postExcerpt.Text = post.Excerpt;
ModerationDDL.Items.FindByValue(post.ModerationType.ToString()).Selected = true;
postName.Text = post.Name;
SetDate(post.UserTime);
NotificationType.SelectedValue = post.FeedbackNotificationType;
VideoUrl.Text = post.VideoUrl;
VideoImageUrl.Text = post.VideoImageUrl;
VideoDuration.Text = post.VideoDuration;
VideoHeight.Text = post.VideoHeight >= 0 ? post.VideoHeight.ToString() : string.Empty;
VideoWidth.Text = post.VideoWidth >= 0 ? post.VideoWidth.ToString() : string.Empty;
if (post.HasCategories)
Tags.SelectedTags = post.Categories;
if(!Globals.IsNullorEmpty(post.AttachmentFilename))
{
PostAttachmentMetaData attachment = post.Attachment;
if(attachment != null)
{
this.Serverfriendlyfilename.Value = attachment.FileName;
this.ServeruploadtempID.Value = "Existing";
this.serverfilename.Text = attachment.FileName;
}
}
bool hasMultipleOwners = post.Weblog.OwnerArray.Length > 1;
SetYesNo(post.PostConfig, post.IsApproved, !post.IsLocked, post.EnableAllOwnerNotification, post.EnableRatings, post.EnableTrackBacks, hasMultipleOwners, post.EnableCrossPosting);
}
}
else
{
PopulateCategories(this.BlogPostType);
SetDate(UserTime.CurrentUserTime);
ModerationDDL.Items.FindByValue(CurrentWeblog.ModerationTypeDefault.ToString()).Selected = true;
NotificationType.SelectedValue = CurrentWeblog.FeedbackNotificationType;
SetYesNo(CurrentWeblog.DefaultPostConfig, true, true, false, this.CurrentWeblog.EnableRatingsDefault, CurrentWeblog.EnableTrackbacksDefault, false, CurrentWeblog.EnableCrossPostingDefault);
}
// Display Default Tags notice if that feature is being used on this site
WeblogConfiguration config = WeblogConfiguration.Instance();
if (config.DefaultAggregateTags != null && config.DefaultAggregateTags.Length > 0)
{
DefaultTagsContainer.Visible = true;
foreach (string tag in config.DefaultAggregateTags)
{
if (DefaultTags.Text.Length > 0)
DefaultTags.Text += "; ";
DefaultTags.Text += tag;
}
}
else
{
DefaultTagsContainer.Visible = false;
}
}
#region Get Post From Form
private WeblogPost GetPostFromForm()
{
WeblogPost post = null;
if (context.PostID > 0)
{
post = WeblogPosts.GetPost(context.PostID, false, false, false);
if(Globals.IsNullorEmpty(this.ServeruploadtempID.Value))
PostAttachments.Delete(context.PostID);
}
else
{
post = new WeblogPost();
post.Username = context.User.Username;
post.SectionID = CurrentWeblog.SectionID;
post.ParentID = 0;
post.BlogPostType = this.BlogPostType;
post.PostID = -1;
post.IsApproved = false;
}
if(EnableInkSupport)
{
if(EnableInk.Checked)
{
if(!post.HasInk)
{
if(!Globals.IsNullorEmpty(inkWeb.InkData))
{
post.InkID = CreateInk();
}
}
else
{
if(Globals.IsNullorEmpty(inkWeb.InkData))
{
DeleteInk(post);
post.InkID = -1;
}
else
{
InkData existingInk = Ink.Get(post.InkID);
existingInk.InkString = inkWeb.InkData;
Ink.Update(existingInk);
}
}
}
else
{
if(post.HasInk)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -