对天乙社区bbscs8实现的详细分析二十六

来源:互联网 发布:linux closehandle 编辑:程序博客网 时间:2024/05/16 00:45

我们进入topic这个tag的java实现代码处:
protected String mainIdName = "%{id}";
protected String forumCurrentPageName = "%{fcpage}";
protected String inPagesName = "%{inpages}";
protected String topicTotalNumName = "%{totalnum}";
protected String type = "";
protected String boardObjName = "%{board}";
protected String forumCurrentActionName = "%{fcaction}";
protected String tagIdProperty = "%{tagId}";
if (type.equalsIgnoreCase("returnforum")) {//返回版区
   sb.append("<a href="");
   if (Constant.USE_URL_REWRITE) {
    sb.append("forum-" + fcaction + "-" + board.getId() + "-" + tagId + "-" + fcpage + "-0.html");
   } else {
    sb.append(BBSCSUtil.getActionMappingURL("/forum?action=" + fcaction + "&bid=" + board.getId()
      + "&page=" + fcpage, request));
   }
   sb.append("">");

   sb.append(messageSource.getMessage("bbscs.back", null, request.getLocale()));
   sb.append("</a>");
   this.write(writer, sb.toString());
   return result;
}
if (type.equalsIgnoreCase("subs")) {//订阅帖子
   sb.append("<a href="javascript:;" onclick="subsTopic('");
   sb.append(board.getId());
   sb.append("','");
   sb.append(mainId);
   sb.append("');">");
   sb.append(messageSource.getMessage("post.subs.title", null, request.getLocale()));
   sb.append("</a>");
   this.write(writer, sb.toString());
   return result;
}
if (type.equalsIgnoreCase("mailsendtopic")) {//发信!
   sb.append("<a href="javascript:;" onclick="mailSendTopicAll('");
   sb.append(board.getId());
   sb.append("','");
   sb.append(mainId);
   sb.append("');">");
   sb.append(messageSource.getMessage("post.mailsendtopic.title", null, request.getLocale()));
   sb.append("</a>");
   this.write(writer, sb.toString());
   return result;
}

if (type.equalsIgnoreCase("own") || type.equalsIgnoreCase("topic")) {
   sb.append("<a href="");
   sb.append(BBSCSUtil.getActionMappingURL("/read?action=" + type + "&bid=" + board.getId() + "&id=" + mainId
     + "&fcpage=" + fcpage + "&fcaction=" + fcaction + "&tagId=" + tagId, request));
   sb.append("">");
   if (type.equalsIgnoreCase("own")) {//显示的字不一样
    sb.append(messageSource.getMessage("post.read.own", null, request.getLocale()));
   }
   if (type.equalsIgnoreCase("topic")) {
    sb.append(messageSource.getMessage("post.read.all", null, request.getLocale()));
   }
   sb.append("</a>");
   this.write(writer, sb.toString());
   return result;
}

OK,我们继续分析read.jsp:
<div id="head2">
    <div id="head2content">
    <s:text name="read.thisposturl"/>:<span id="posturl" class="font6"><bbscs:topic type="posturl"/></span>//main的URL!
    </div>
</div>
--->
if (type.equalsIgnoreCase("posturl")) {
   try {
    if (Constant.USE_URL_REWRITE) {
     sb.append(BBSCSUtil.absoluteActionURLHtml(request, "/main-read-" + board.getId() + "-" + mainId
       + ".html"));
    } else {
     sb.append(BBSCSUtil.absoluteActionURL(request, "/main?action=read&bid=" + board.getId()
       + "&postID=" + mainId));
    }
   } catch (MalformedURLException ex1) {
    sb.append("");
   }
   this.write(writer, sb.toString());
   return result;
}
Go ON!   <span class="font2">[<bbscs:forum forumValue="f" type="floor"/>]</span>
                  <bbscs:forum forumValue="f" type="face"/>
<span class="font1">
                    <strong><s:text name="forum.art.title"/>:<s:property value="#f.title"/></strong>//显示标题!
                    <span id="cndt<s:property value="#f.id"/>">
       <s:if test="#f.canNotDel==1">M</s:if>
                    </span>
                  </span>
这里用到两个tag,我们看floor:
if (type.equalsIgnoreCase("floor")) {//第几楼的显示!
   int index = 0;
   Object statusObj = this.getStack().findValue(indexValue);
   if (statusObj != null) {
    index = ((IteratorStatus) statusObj).getIndex();
   }
   int inpages = 1;
   Object inpagesObj = this.getStack().findValue(inPagesValue);
   if (inpagesObj != null) {
    inpages = ((Integer) inpagesObj).intValue();
   }
   UserCookie uc = new UserCookie(request, response, sysConfig);
   int perNum = this.getUserPostPerNum(uc.getPostPerNum(), sysConfig.getPostPerPage());
   int floor = (inpages - 1) * perNum + index;
   if (floor == 0) {
    sb.append(messageSource.getMessage("forum.floor0", null, request.getLocale()));//楼主
   } else {
    sb.append(messageSource.getMessage("forum.floor1", new String[] { String.valueOf(floor) }, request
      .getLocale()));//[9楼]
   }
   this.write(writer, sb.toString());
   return result;
}
                 <div align="right">
     <s:if test="%{action!='own'}">//不是只看楼主的话
     <s:if test="%{fcaction=='index'}">
                    [<bbscs:forum forumValue="f" type="sendnote"/>]//留言
                    [<bbscs:forum forumValue="f" type="del" currentPageValue="%{fcpage}"/>]//删除
                    [<bbscs:forum forumValue="f" type="delattachpage"/>]//删除附件
     <s:if test="#f.isNew==1">//是主帖的话
                      [<bbscs:forum forumValue="f" type="movepage"/>]//移动!
     </s:if>
                    [<bbscs:forum forumValue="f" type="edit" currentPageValue="%{fcpage}"/>]//修改
                    [<bbscs:forum forumValue="f" type="re" currentPageValue="%{fcpage}" />]//回复
                    [<bbscs:forum forumValue="f" type="requote" currentPageValue="%{fcpage}" />]//引用回复
                    [<bbscs:forum forumValue="f" type="upfilepage"/>]//上传附件
                    </s:if>
                    </s:if>//下面是公有的
                    [<a href="javascript:;" onclick="mailSendTopic('<s:property value="%{bid}"/>','<s:property value="#f.id"/>');"><s:text name="post.mailsend.title" /></a>]//打包
                    [<a href="javascript:;" onclick="reportTopic('<s:property value="%{bid}"/>','<s:property value="#f.id"/>');"><s:text name="post.report.title" /></a>]//举报
                  </div>
我们再到ForumComponent.java中看相关的tag:
if (type.equalsIgnoreCase("sendnote")) {
   sb.append("<a href="javascript:;" onclick="loadNoteSend('");//把下面的notesend这个div显示出来
   sb.append(f.getId());
   sb.append("');">");
   sb.append(messageSource.getMessage("pot.sendnote", null, request.getLocale()));
   sb.append("</a>");
   this.write(writer, sb.toString());
   return result;
}
   if (type.equalsIgnoreCase("edit")) {
   Object forumCurrentPageObj = this.getStack().findValue(this.currentPageValue);
   int fcpage = 1;
   if (forumCurrentPageObj != null) {
    fcpage = ((Integer) forumCurrentPageObj).intValue();
   }

   int inpages = 1;
   Object inpagesObj = this.getStack().findValue(inPagesValue);
   if (inpagesObj != null) {
    inpages = ((Integer) inpagesObj).intValue();
   }

   String tagId = "0";
   Object tagIdObj = this.getStack().findValue(this.tagIdValue);
   if (tagIdObj != null) {
    tagId = (String) tagIdObj;
   }

   StringBuffer linksb = new StringBuffer();
   if (f.getIsVote() == 0) {
    linksb.append("/post?action=edit&");
   } else {
    linksb.append("/votePost?action=edit&");
   }
   linksb.append("id=");
   linksb.append(f.getId());
   linksb.append("&bid=");
   linksb.append(f.getBoardID());
   linksb.append("&fcpage=");
   linksb.append(fcpage);
   linksb.append("&inpages=");
   linksb.append(inpages);
   linksb.append("&mainID=");
   linksb.append(f.getMainID());
   linksb.append("&tagId=");
   linksb.append(tagId);
   sb.append("<a href="");
   sb.append(BBSCSUtil.getActionMappingURL(linksb.toString(), request));
   sb.append("">");
   sb.append(messageSource.getMessage("bbscs.change", null, request.getLocale()));
   sb.append("</a>");
   this.write(writer, sb.toString());//产生一个url!
   return result;
}
if (type.equalsIgnoreCase("del")) {
   Object forumCurrentPageObj = this.getStack().findValue(this.currentPageValue);
   int fcpage = 1;
   if (forumCurrentPageObj != null) {
    fcpage = ((Integer) forumCurrentPageObj).intValue();
   }
   sb.append("<a href="javascript:;" onclick="delapost('");
   sb.append(f.getBoardID());
   sb.append("','");
   sb.append(f.getId());
   sb.append("','");
   sb.append(f.getIsNew());
   sb.append("','");
   sb.append(fcpage);
   sb.append("');">");
   sb.append(messageSource.getMessage("bbscs.del", null, request.getLocale()));
   sb.append("</a>");
   this.write(writer, sb.toString());
   return result;
}
其它省略之!我们继续看sidebar:
<div class="siderbarcontent" id="commenddiv">
<bbscs:topic type="commend"/>
</div>
-->
if (type.equalsIgnoreCase("commend")) {
   File commendFile = new File(BBSCSUtil.getIncludePath() + "Commend_" + board.getTopBid() + ".html");
   String commendText = "";
   try {
    commendText = FileUtils.readFileToString(commendFile, Constant.CHARSET);//读取文件!
    if (commendText == null) {
     commendText = "";
    }
   } catch (IOException ex) {
    commendText = "";
   }
   sb.append(commendText);
   this.write(writer, sb.toString());
   return result;
}
接下来,我们分析下回复,有快速回复和普通回复两种,快速回复只需标题和内容两项就可以ctrl+enter进行回复了!
function ctrlEnter(e){
    var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
    if(ie){
        if(event.ctrlKey && window.event.keyCode==13){doSomething();}
    }else{
        if(isKeyTrigger(e,13,true)){doSomething();}
    }
}
当我们回复时,form的action=post而action为addqre!
<input type="hidden" name="action" value="addqre" />
        <input type="hidden" name="bid" value="<s:property value="%{bid}"/>" />
        <input type="hidden" name="parentID" value="<s:property value="%{id}"/>" />
        <input type="hidden" name="editType" value="0" />
        <input type="hidden" name="mainID" value="<s:property value="%{id}"/>" />
        <input type="hidden" name="totalnum" value="<s:property value="%{pageList.pages.totalNum}"/>" />
        <input type="hidden" name="sign" value="-1" />
        <input type="hidden" name="fcpage" value="<s:property value="%{fcpage}"/>" />
        <input type="hidden" name="tagId" value="<s:property value="%{tagId}"/>" />
我们进入Post.java的addqre()方法,它仍要checkBeforePost,title的bestrowScreen还有detail的长度和bestrowScreen:
Forum mainForum = this.getForumService().findForumByID(this.getMainID(), this.getBid());
if (mainForum == null) {
   this.addActionError(this.getText("error.post.getpost"));
   return ERROR;
}
if (mainForum.getIsLock() == 1) {
   this.addActionError(this.getText("error.post.islock"));
   return ERROR;
}
其它的类似与addsave!最后,我们在read.jsp中看一下[打包]是怎么实现的:
<a href="javascript:;" onclick="mailSendTopic('<s:property value="%{bid}"/>','<s:property value="#f.id"/>');"><s:text name="post.mailsend.title" /></a>
在read.js中:
var SendMailTopicAjax = Class.create();

SendMailTopicAjax.prototype = {
initialize: function(bid,id) {
    this.bid = bid;
    this.id = id;
},

sendMail: function() {
    showExeMsg();
    var url = getActionMappingURL("/postOpt");
    var pars = "ajax=xml&action=mailsend&id=" + this.id + "&bid=" + this.bid;
    var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: this.sendMailCompleted.bind(this)});
},

sendMailCompleted: function(res) {
    var jsonMsgObj = new JsonMsgObj(res.responseText);
   var codeid = jsonMsgObj.getCodeid();
    hiddenExeMsg();
    Element.hide("postOpt" + this.id);
    alert(jsonMsgObj.getMessage());//提示成功!
}
};

function mailSendTopic(bid,id) {
var mset = confirm(sendtopicconfirm);
if (mset) {
    Element.show("postOpt" + id);// <div id="postOpt<s:property value="#f.id"/>" class="summary1" style="display:none"></div>
    $('postOpt' + id).innerHTML = sendMailMsg;
    var oSendMailTopicAjax = new SendMailTopicAjax(bid,id);
    oSendMailTopicAjax.sendMail();
}
else {
    return false;
}
}
我们看postOpt这个action:
<action name="postOpt" class="postOptAction">
   <interceptor-ref name="boardInterceptorStack"></interceptor-ref>
   <interceptor-ref name="remoteAddrInterceptor"></interceptor-ref>
   <interceptor-ref name="requestBasePathInterceptor"></interceptor-ref>
</action>
public String mailsend() {
Forum f = this.getForumService().findForumByID(this.getId(), this.getBid());
if (f == null) {
   this.getAjaxMessagesJson().setMessage("E_POST_NOT_EXIST", this.getText("error.post.getpost"));
   return RESULT_AJAXJSON;
}

if (StringUtils.isNotBlank(this.getUserSession().getEmail()) && this.getSysConfig().getUseEmail() == 1) {
   try {

    String detail = "";
    if (f.getIsHidden() != 0) {
     detail = this.getText("post.hidden.notmailsend");
    } else {
     detail = this.getForumService().getForumDetail(f, false);//找到内容!
     if (f.getEditType() == 0) {
      detail = BBSCSUtil.filterText(detail, (this.getBoard().getAllowHTML() == 1), (this.getBoard()
        .getAllowUBB() == 1), true);
     } // else {detail = f.getDetail();}
    }

    String url = this.getBasePath()
      + BBSCSUtil.getActionMappingURLWithoutPrefix("main?action=read&bid=" + this.getBoard().getId()
        + "&postID=" + f.getMainID());

    Map root = new HashMap();
    root.put("website", this.getSysConfig().getForumName());
    root.put("title", f.getTitle());
    root.put("detail", detail);
    root.put("url", url);

    this.getTemplateMail().sendMailFromTemplate(this.getUserSession().getEmail(), f.getTitle(),
      "mailSend.ftl", root, this.getLocale());//mainSend!

    this.getAjaxMessagesJson().setMessage("0", this.getText("post.mailsend.ok"));
   } catch (Exception ex7) {
    ex7.printStackTrace();
    this.getAjaxMessagesJson().setMessage("E_POST_MAILSEND_ERROR", this.getText("post.mailsend.error"));
   }
   return RESULT_AJAXJSON;
} else {
   this.getAjaxMessagesJson().setMessage("E_POST_MAILSEND_ERROR", this.getText("post.mailsend.error"));
   return RESULT_AJAXJSON;
}
}
而下面的方法是实现同主题打包的功能的:
public String mailsendtopic() {
OrderObj[] oo = { new OrderObj("postTime", Constant.ORDER_ASC) };
List l = this.getForumService().findForumsTopicAll(this.getBid(), this.getMainid(), 0, 0, oo);
if (l == null || l.isEmpty()) {
   this.getAjaxMessagesJson().setMessage("E_POST_NOT_EXIST", this.getText("error.post.getpost"));
   return RESULT_AJAXJSON;
}
if (StringUtils.isNotBlank(this.getUserSession().getEmail()) && this.getSysConfig().getUseEmail() == 1) {
   try {
    String detail = "";
    Forum mainForum = (Forum) l.get(0);
    List<Forum> nl = new ArrayList<Forum>();
    for (int i = 0; i < l.size(); i++) {
     Forum f = (Forum) l.get(i);
     if (f.getIsHidden() != 0) {
      detail = this.getText("post.hidden.notmailsend");
     } else {
      detail = this.getForumService().getForumDetail(f, false);
      if (f.getEditType() == 0) {
       f.setDetail(BBSCSUtil.filterText(detail, (this.getBoard().getAllowHTML() == 1), (this
         .getBoard().getAllowUBB() == 1), true));
      } else {
       f.setDetail(detail);
      }
     }
     nl.add(f);
    }

    String url = this.getBasePath()
      + BBSCSUtil.getActionMappingURLWithoutPrefix("main?action=read&bid=" + this.getBoard().getId()
        + "&postID=" + this.getMainid());

    Map root = new HashMap();
    root.put("website", this.getSysConfig().getForumName());
    root.put("nl", nl);
    root.put("url", url);

    this.getTemplateMail().sendMailFromTemplate(this.getUserSession().getEmail(), mainForum.getTitle(),
      "mailSendTopic.ftl", root, this.getLocale());//mailSendTopic!

    this.getAjaxMessagesJson().setMessage("0", this.getText("post.mailsend.ok"));
   } catch (Exception ex8) {
    ex8.printStackTrace();
    this.getAjaxMessagesJson().setMessage("E_POST_MAILSEND_ERROR", this.getText("post.mailsend.error"));
   }
   return RESULT_AJAXJSON;
} else {
   this.getAjaxMessagesJson().setMessage("E_POST_MAILSEND_ERROR", this.getText("post.mailsend.error"));
   return RESULT_AJAXJSON;
}
}
对于举报功能,其实它也是发E-mail给webmaster的,下面是其实现的部分代码:
    Map root = new HashMap();
    root.put("userName", this.getUserSession().getUserName());
    root.put("title", f.getTitle());
    root.put("detail", detail);
    root.put("url", url);

    this.getTemplateMail().sendMailFromTemplate(this.getSysConfig().getWebmasterEmail(), title,
      "report.ftl", root, this.getLocale());

    this.getAjaxMessagesJson().setMessage("0", this.getText("post.report.ok"));
好的,关于其它的部分我们不再进行分析了.最后,我们看一下read的其它方法action="own":关键的是this.setPageList(this.getForumService().findForumsOwner(this.getBid(), f.getUserID(), this.getId(), pages));而action="elite":
public String elite() {
this.setEliteDirs(new ArrayList<Elite>());
Elite elite = this.getEliteService().findEliteByID(this.getEliteId());
if (elite != null) {
   List pes = elite.getParentIDs();
   for (int i = 0; i < pes.size(); i++) {
    Elite pe = this.getEliteService().findEliteByID(((Long) pes.get(i)).longValue());
    this.eliteDirs.add(pe);
   }
   this.eliteDirs.add(elite);
}
Forum f = this.getForumService().findForumByID(this.getId(), this.getBid());
if (f == null) {
   this.addActionError(this.getText("error.post.getpost"));
   return ERROR;
}
this.setForum(f);
return "readElite";
}
OK!我们的分析已经大部分给分析完成了。除了对管理部分的action和jsp外,在read.jsp等界面元素上还有些功能仍需要进行详细地分析,这将在以后的时间里进行阐述!