community server 学习与分析 之一

 Community Server 是一个功能很强大同时也很复杂的一个社区系统,目前我想修改其中的论坛,以解除免费版本的某些限制,而这样,就需要对它进行分析了。
刚刚接触CS,甚至接触.NET也不到两个月,所以写的东西显得有些杂乱吧。不过主要的目的还是让自己看的,免得以后忘了。也希望看到这个的朋友能和我交流交流,共同进步。

通过浏览CS的论坛知道,显示帖子是Forums/ShowThread.aspx页面负责的,打开这个页面,其代码如下:
<%@ Page SmartNavigation="False" Language="C#"  enableViewState = "false" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>
<%@ Import Namespace="CommunityServer.Galleries.Components" %>
<%@ Import Namespace="CommunityServer.Blogs.Components" %>
<%@ Import Namespace="CommunityServer.Components" %>

<CS:MPContainer runat="server" id="MPContainer" ThemeMasterFile = "ForumMaster.ascx" >
    <CS:MPContent id="bcr" runat="server">
   <CSD:PostSelectedView runat="server" id="PostSelectedView" EnableViewState="False" />
    </CS:MPContent>
</CS:MPContainer>


很明显,<CSD:PostSelectedView runat="server" id="PostSelectedView" EnableViewState="False" />加载的详细的数据。继续转向PostSelectedView 。
根据ShowThread.aspx的TagPrefix的描述,可以在对应的命名空间中找到PostSelectedView类的定义。

这个类的定义如下:

//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

using System;
using System.Web;
using System.Web.UI;
using CommunityServer.Components;

namespace CommunityServer.Discussions.Controls
{
 /// <summary>
 /// Summary description for PostThreadedView.
 /// </summary>
 public class PostSelectedView : Control
 {
     CSContext csContext;


  #region Control Event Handlers

  protected override void OnInit(EventArgs e)
  {
   base.OnInit(e);

   this.csContext = CSContext.Current;
   
   EnsureChildControls();
  }

  protected override void CreateChildControls()
  {
   base.CreateChildControls();
  
   PostViewType view;
   if (!Globals.IsNullorEmpty(Page.Request.QueryString["View"]))
   {
    try
    {
     view = (PostViewType) Enum.Parse(typeof(PostViewType), Page.Request.QueryString["View"], false);
     UpdateCookie(view);
    }
    catch
    {
     view = GetUserPostViewType();
    }
   }
   else
    view = GetUserPostViewType();

   switch (view)
   {
    case PostViewType.Flat:
     PostFlatView flatView = new PostFlatView();
     flatView.EnableViewState = false;
     this.Controls.Add(flatView);

     break;

    case PostViewType.Threaded:
     PostThreadedView threadView = new PostThreadedView();
     threadView.EnableViewState = false;
     this.Controls.Add(threadView);

     break;
   }
  }

  ---------------
--------------------
---------------------省略若干代码
----------------------------
  #endregion
 }
}

在这个类中,主要看的是CreateChildControls方法。
if (!Globals.IsNullorEmpty(Page.Request.QueryString["View"]))  这一行代码的作用是根据页面的设置,来确定是怎么显示这个页面(具体就是树型和平面型)。这个很重要,继续往下看。后面紧跟着的一段try...catch...的作用是取得页面显示的设置,就不详细看了。继续往下,此时,根据取得的显示设置,来具体的使用某一个控件来显示帖子的内容,具体的代码就是
   switch (view)
   {
    case PostViewType.Flat:
     PostFlatView flatView = new PostFlatView();
     flatView.EnableViewState = false;
     this.Controls.Add(flatView);

     break;

    case PostViewType.Threaded:
     PostThreadedView threadView = new PostThreadedView();
     threadView.EnableViewState = false;
     this.Controls.Add(threadView);

     break;
   }
默认的是平面型(flatview),于是就实例化了一个PostFlatView 类的实例,PostFlatView 类和PostSelectedView是在同一个命名空间中,找到了PostFlatView 类后,可以看到它是一个继承了TemplatedWebControl的类,凭着经验,觉得这是一个带有皮肤的类,由于代码太多,不便于贴出来,就不贴了,把主要的代码放几行吧:
 protected override void OnInit(EventArgs e) {

   if (SkinName == null)               
    ExternalSkinFileName = "View-PostFlatView.ascx";
   else
    ExternalSkinFileName = SkinName;
    .......................
    这段有些大概是用于权限控制的,留待以后继续分析
    ........................
    }

这里就指定了它的皮肤的文件名, 为了弄清楚是如何加载帖子的详细内容,我们继续前往View-PostFlatView.ascx。为了知道这个文件具体的位置,可以在PostFlatView类的父类TemplatedWebControl里查找,也不再详细说明了。打开View-PostFlatView.ascx后,帖子的内容是由哪些控件加载的就一目了然了,需要修改什么,就看对应的用户控件,应该可以慢慢的实现自己想要的功能了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值