`
lonestone
  • 浏览: 90816 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

给你的CS2.0(CommunityServer2.0)添加帖子底部带登录的快速回复控件!

阅读更多

自从公司网站http://bbs.cnfdc.com.cn 用上了cs2.0,就有同事给我提出,能不能添加一个帖子底部的快速回复,这样可以很方便的回复帖子,当时刚接触cs,没有弄,现在,觉得对于cs比较熟悉了,于是就下手做了一个,没想到,成功了,现在就和大家分享一下吧。

我采用的是cs的标准方法,即用户控件的方式,建立一个皮肤文件,然后给这个皮肤文件对应写一个类。皮肤文件可以说是skin-Login.ascx和CreateQuickReplay.ascx的混合体,类文件也一样,不过由于要求游客可以通过一并输入用户名和密码的方式来发帖,所以先登录用户,这里就去掉了一些验证,放在用户登录后进行。

先把初步的皮肤文件的代码放上来,文件名Skin-ThreadQuickReply.ascx,放在default主题目录下

<%...@ControlLanguage="C#"%>
<%...@RegisterTagPrefix="CSD"Namespace="CommunityServer.Discussions.Controls"Assembly="CommunityServer.Discussions"%>
<%...@RegisterTagPrefix="CS"Namespace="CommunityServer.Controls"Assembly="CommunityServer.Controls"%>
<%...@ImportNamespace="CommunityServer.Discussions.Controls"%>
<%...@ImportNamespace="CommunityServer.Discussions.Components"%>
<%...@ImportNamespace="CommunityServer.Components"%>
<%...@ImportNamespace="CommunityServer.Controls"%>
<%...@ImportNamespace="CommunityServer"%>
<divclass="CommonContentArea">
<divclass="CommonContent">
<divclass="CommonFormArea">
<ulclass="ForumPostList">
<li>
<divclass="ForumPostArea">
<h4class="ForumPostHeader">
<tablecellpadding="0"cellspacing="0"border="0"width="100%">
<trvalign="middle">
<tdalign="left">快速回复主题</td>
<tdalign="right"class="ForumPostHeaderControlArea">
</td>
</tr>
</table>
</h4>
<tablecellspacing="0"cellpadding="0"border="0"width="100%"style="table-layout:auto;">
<trvalign=top>
<tdrowspan="2"class="ForumPostUserArea">
<divclass="ForumPostUserContent"style="text-align:left">
<CSD:UserPermissionsrunat="server"id="Userpermissions1"/>
</div>
</td>
<tdclass="ForumPostContentArea">
<tablewidth="100%"cellpadding="0"cellspacing="0"border="0">
<tr>
<tdclass="CommonFormField"colspan="2">
<asp:PanelID="UserLoginForm"runat="server">
<spanclass="CommonFormFieldName"><CS:ResourceLabelID="ResourceLabel1"runat="server"ResourceName="Login_UserName"/></span>
<CS:DefaultButtonTextBoxButton="loginButton"id="username"runat="server"size="30"maxlength="64"/>
<spanclass="CommonFormFieldName"><CS:ResourceLabelID="ResourceLabel2"runat="server"ResourceName="Login_Password"/></span>
<CS:DefaultButtonTextBoxButton="loginButton"TextMode="Password"id="password"runat="server"size="11"maxlength="64"/>
<spanclass="txt4">(<CSD:ForumAnchorAnchorType="UserForgotPassword"runat="server"/>)</span>
<asp:CheckBoxtype="checkbox"Checked="true"runat="server"id="autoLogin"/>
<asp:LinkButtonid="loginButton"runat="server"CssClass="CommonTextButton"/><ahref="/user/CreateUser.aspx">立即注册</a>
</asp:Panel>

</td>
</tr>
<tr>
<tdclass="CommonFormFieldName"><CS:ResourceLabelrunat="server"ResourceName="SendEmail_Subject"id="rc_send_subject"/></td>
<tdclass="CommonFormField"><asp:textboxautocomplete="off"id="PostSubject"runat="server"columns="80"/><asp:requiredfieldvalidatorid="SubjectValidator"runat="server"Cssclass="CommonValidationWarning"ControlToValidate="PostSubject">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<tdcolspan=2class="CommonFormField">
<asp:requiredfieldvalidatorid="Requiredfieldvalidator1"runat="server"Cssclass="CommonValidationWarning"ControlToValidate="PostBody">*</asp:requiredfieldvalidator>
<CS:Editorrunat="Server"EnableHtmlModeEditing="false"id="PostBody"Width="660"Height="200"/>
</td>
</tr>
<tr>
<tdcolspan=2class="CommonFormField">
<asp:buttonid="SavePost"Runat="server"Text="发表"/>
</td>
</tr>
</table>
</td>
</tr>
<trvalign="bottom">
<tdclass="ForumPostFooterArea">
<ulclass="ForumPostStatisticsCommonPrintHidden"style="clear:both;">
<li></li>
</ul>
</td>
</tr>
</table>
</div>
</li>
</ul>

</div>
</div>
</div>

然后就是ThreadQuickReply.cs,放在CommunityServerForums20项目的根目录下即可:

//------------------------------------------------------------------------------
//<copyrightcompany="TelligentSystems">
//Copyright(c)TelligentSystemsCorporation.Allrightsreserved.
//</copyright>
//------------------------------------------------------------------------------

usingSystem;
usingSystem.Web;
usingSystem.Web.UI.WebControls;
usingCommunityServer.Components;
usingCommunityServer.Controls;
usingCommunityServer.Discussions.Components;
usingSystem.Web.Security;

namespaceCommunityServer.Discussions.Controls
...{
/**////<summary>
///用来在主题下直接快速回复
///作者:王勇
///日期:2006-8-14
///email:wangyong.yichang@gmail.com
///qq:12586093
///</summary>

publicclassThreadQuickReply:CommunityServer.Controls.TemplatedWebControl
...{
publicThreadQuickReply()
...{
Initialize();
}


privatevoidInitialize()
...{


//CSEvents.AuthorizePost();

if(context.PostID>0)
...{
postReplyingTo
=Posts.GetPost(context.PostID,context.User.UserID);
forum
=postReplyingTo.SectionasForum;
}



if(postReplyingTo==null)
...{
thrownewCSException(CSExceptionType.PostNotFound);
}


//Securitychecktoseeiftheforumallowsanonymousposts
//
//if(context.User.IsAnonymous&&(!forum.EnableAnonymousPosting||!context.SiteSettings.EnableAnonymousUserPosting))
//{
//if(!Context.Request.IsAuthenticated)
//{
//Context.Response.Redirect(Globals.GetSiteUrls().Login);
//Context.Response.End();
//}
//}

if(postReplyingTo.IsLocked)
...{
Context.Response.Redirect(Globals.GetSiteUrls().Post(context.PostID));
Context.Response.End();
}

}


privateEditorpostBody;
privateTextBoxpostSubject;
privateIButtonbutton;
CSContextcontext
=CSContext.Current;
ForumPostpostReplyingTo
=null;
Forumforum
=null;

//提前登录控件
TextBoxusername;
TextBoxpassword;
IButtonloginButton;
CheckBoxautoLogin;

//*********************************************************************
//CreateChildControls
//
/**////<summary>
///Thiseventhandleraddsthechildrencontrols.
///</summary>

//***********************************************************************/
protectedoverridevoidCreateChildControls()
...{
//Iftheuserisalreadyauthenticatedwehavenoworktodo
if(Page.Request.IsAuthenticated)
border-right: #808080 1px solid; border-top: #808080 1px s
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics