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

好的,我们看jsp文件:post.jsp,对于这个文件,我们要注意的是有些值加入了判断是不是 <s:if test="%{action=='editdo'}">或者是<s:if test="%{action=='addsave'}">可见用户在修改自己的帖子时也用的是这个文件.当用户编辑的时候,用户签名之后的选项都被disabled="true"了或者去掉了(如隐藏帖选项),当我们提交后,<s:form action="post">在js之后进行触发:
<script type="text/javascript">
function postSubmit() {
document.getElementById("postButton").disabled = true;
document.post.submit();
}
</script>
另外,这个文件中的:
<s:actionerror theme="bbscs0"/> //错误提示信息
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
    <td class="bgColor3">
    <bbscs:post type="postat"/>
/**在bbscs.tld中<tag>
<name>post</name>
<tag-class>com.laoer.bbscs.web.taglib.PostTag</tag-class>
<body-content>empty</body-content>
<attribute>
   <name>type</name>
   <required>true</required>
   <rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
   <name>boardValue</name>
   <required>false</required>
   <rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
   <name>tagIdValue</name>
   <required>false</required>
   <rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
-->postTag.java中:
protected String type = "";
protected String boardValue = "%{board}";
protected String tagIdValue = "%{tagId}";
实际上是if (type.equalsIgnoreCase("postat")) {
     this.write(writer, messageSource.getMessage("post.youatboards", new String[] { sb.toString() },
       request.getLocale()));
    }/您目前在 社区技术 区发表信息
*/
    </td>
</tr>
</table>
OK!我们看addsave方法,注意它充当了验证的功能:
try {              //上传文件的部分!
    uploadFile = new UploadFile();
    uploadFile.setFileName(this.getUploadFileName().toLowerCase());
    uploadFile.setInputStream(new FileInputStream(this.getUpload()));
   } catch (FileNotFoundException e) {
    logger.error(e);
    uploadFile = null;
   }
}
..
Forum f = new ForumMain();
f.setPreviewAttach(this.boolean2int(this.getPreviewAttach()));        //写入用户部分!
try {
   UserInfo ui = this.getUserService().findUserInfoById(this.getUserSession().getId());
   if (ui == null) {
    this.addActionError(this.getText("error.post.guest"));
    this.setNeedsAttribute(false);
    return INPUT;
   }

   f = this.getForumService().createForum(f, this.getBoard(), ui, uploadFile);
   this.getUserCookie().addLastPostTime();
   if (this.getBoard().getAuditPost() == 0) {
    if (Constant.USE_URL_REWRITE) {
     this.setForwardUrl(this.getBasePath() + "forum-index-" + this.getBid() + "-" + this.getTagId()
       + "-1-0.html");
    } else {
     this.setForwardUrl(BBSCSUtil.getActionMappingURLWithoutPrefix("forum?action=index&bid="
       + this.getBid() + "&tagId=" + this.getTagId()));//forwardUrl用于发帖后成功的Href!
    }
   } else {
    this.setForwardUrl(BBSCSUtil.getActionMappingURLWithoutPrefix("postWaitAudit?bid=" + this.getBid()));
   }
   return SUCCESS;
}
好的,我们先转看新投票功能http://bbs.laoer.com/votePost.bbscs?action=add&bid=15&tagId=0
<action name="votePost" class="votePostAction">
   <interceptor-ref name="boardInterceptorStack"></interceptor-ref>
   <interceptor-ref name="remoteAddrInterceptor"></interceptor-ref>
   <interceptor-ref name="requestBasePathInterceptor"></interceptor-ref>
   <result name="input">/WEB-INF/jsp/votePost.jsp</result>
   <result name="success" type="redirect">${forwardUrl}</result>
</action>
我们直接看VotePost:
public String add() {
this.setAction("addsave");
this.setDeadLineYear(String.valueOf(Util.getYear()));
/**
public static int getYear() {
Calendar cld = Calendar.getInstance();
cld.setTime(new java.util.Date());
return cld.get(Calendar.YEAR);
}
public static int getMonth() {
Calendar cld = Calendar.getInstance();
cld.setTime(new java.util.Date());
return cld.get(Calendar.MONTH) + 1;
}

*/
this.setDeadLineMon(Util.getMonth());
this.setTagsAttribute();
return INPUT;
}
另外,关于tagValues:
        <td width="85%" class="bgColor2">
    <s:if test="%{action=='addsave'}">
    <s:select list="tagValues" id="tagId" name="tagId" cssClass="select1" listKey="key" listValue="value"></s:select>
    </s:if>
    <s:textfield id="title" name="title" cssClass="input2" size="60" maxlength="60"></s:textfield>
        </td>
当点击提交按钮运行postSubmit()这个函数:
function postSubmit() {
document.getElementById("postButton").disabled = true;
document.votePost.submit();
}
在addSave()方法中:
f.setIsNew(1);
f.setIsTop(0);
f.setIsVote(1);
f.setLastPostNickName("---");
f.setLastPostTitle("");
f.setLastPostUserName("---");
f.setLastTime(nowtime);
f.setMainID("");
f.setNickName(this.getUserSession().getNickName());
f.setParentID("");
f.setPostTime(nowtime);
f.setPostType(0);
f.setQuoteText("");
f.setReNum(0);
f.setSign("");
f.setTitle(stitle);
f.setTitleColor(0);
f.setUserID(this.getUserSession().getId());
f.setUserName(this.getUserSession().getUserName());
f.setEmailInform(0);
f.setMsgInform(0);
...
Vote vote = new Vote();
vote.setDeadLine(Util.Date2Long(Integer.parseInt(this.getDeadLineYear()), this.getDeadLineMon(), this
    .getDeadLineDay()));
vote.setIsM(this.getIsM());
vote.setTitle(this.getTitle());
...
this.getForumService().createVoteForum(f, this.getBoard(), vote, ui, svoteItem);
this.getVoteService().saveVote(vote);
   this.setForwardUrl(this.getBasePath()
     + BBSCSUtil.getActionMappingURLWithoutPrefix("forum?action=index&bid=" + this.getBid()));//forwardUrl!!!
   return SUCCESS;
这里用到了tagValues:
private void setTagsAttribute() {
this.tagValues.add(new OptionsString("0", this.getBoard().getBoardName()));
Iterator it = this.getBoard().getBoardTag().iterator();//这个Board的所有tag!
BoardTag bt = null;
while (it.hasNext()) {
   bt = (BoardTag) it.next();
   this.tagValues.add(new OptionsString(bt.getId(), bt.getTagName()));
}
}
OK!我们进入读取帖子这个关键的业务,我们选择一个喜欢的帖子进行分析(http://bbs.laoer.com/read-topic-15-ff80808113baa8140113d201333e5274-0-1-index-1.html),我们先在struts.xml中察看read这个action:
<action name="read" class="readAction">
   <interceptor-ref name="boardInterceptorStack"></interceptor-ref>
   <interceptor-ref name="remoteAddrInterceptor"></interceptor-ref>
   <interceptor-ref name="requestBasePathInterceptor"></interceptor-ref>
   <result name="read">/WEB-INF/jsp/read.jsp</result>
   <result name="readHistory">/WEB-INF/jsp/readHistory.jsp</result>
   <result name="postSummary">/WEB-INF/jsp/postSummary.jsp</result>
   <result name="postShowIpInfo">/WEB-INF/jsp/postShowIpInfo.jsp</result>
   <result name="showUpFileInPost">/WEB-INF/jsp/showUpFileInPost.jsp</result>
   <result name="showAttach">/WEB-INF/jsp/showAttach.jsp</result>
   <result name="showVoteInPost">/WEB-INF/jsp/showVoteInPost.jsp</result>
   <result name="readWaste">/WEB-INF/jsp/readWaste.jsp</result>
   <result name="readAuditing">/WEB-INF/jsp/readAuditing.jsp</result>
   <result name="readElite">/WEB-INF/jsp/readElite.jsp</result>
</action>
我们根据topic直接进入Read.java:
public String execute() { //可见其内容之丰富!
if (this.getAction().equalsIgnoreCase("topic")) {
   return this.topic();
} else if (this.getAction().equalsIgnoreCase("history")) {
   return this.history();
} else if (this.getAction().equalsIgnoreCase("own")) {
   return this.own();
} else if (this.getAction().equalsIgnoreCase("summary")) {
   return this.summary();
} else if (this.getAction().equalsIgnoreCase("showip")) {
   return this.showip();
} else if (this.getAction().equalsIgnoreCase("summaryhistory")) {
   return this.summaryhistory();
} else if (this.getAction().equalsIgnoreCase("showiphistory")) {
   return this.showiphistory();
} else if (this.getAction().equalsIgnoreCase("showupfile")) {
   return this.showupfile();
} else if (this.getAction().equalsIgnoreCase("attach")) {
   return this.attach();
} else if (this.getAction().equalsIgnoreCase("showvote")) {
   return this.showvote();
} else if (this.getAction().equalsIgnoreCase("waste")) {
   return this.waste();
} else if (this.getAction().equalsIgnoreCase("auditing")) {
   return this.auditing();
} else if (this.getAction().equalsIgnoreCase("auditingAttach")) {
   return this.auditingAttach();
} else if (this.getAction().equalsIgnoreCase("elite")) {
   return this.elite();
} else {
   return ERROR;
}
}
--->
public String topic() {
setUrlRewriteValue();//UrlRewrite!
Pages pages = new Pages();
pages.setPage(this.getInpages());
pages.setPerPageNum(this.getUserPostPerNum(this.getUserCookie().getPostPerNum(), this.getSysConfig().getPostPerPage()));//设置PrePageNum!
if (Constant.USE_URL_REWRITE) {
   pages.setUseUrlRewrite(Constant.USE_URL_REWRITE);
   pages.setFileName("read-" + this.getAction() + "-" + this.getBid() + "-" + this.getId() + "-"
     + this.getTagId() + "-" + this.getFcpage() + "-" + this.getFcaction() + "-{page}.html");
} else {
   pages.setFileName(this.getBasePath()
     + BBSCSUtil.getActionMappingURLWithoutPrefix("read?action=" + this.getAction() + "&bid="
       + this.getBid() + "&id=" + this.getId() + "&fcpage=" + this.getFcpage() + "&fcaction="
       + this.getFcaction() + "&tagId=" + this.getTagId()));
}
this.setPageList(this.getForumService().findForumsTopic(this.getBid(), this.getId(), pages));

if (this.getPageList().getObjectList().isEmpty()) {//没有~~
   return this.history();
}

this.pageTitle = "";

Forum f = (Forum) this.getPageList().getObjectList().get(0);//主贴相关!
if (f.getIsNew() == 1) {
   f.setClick(f.getClick() + 1);
   try {
    f = this.getForumService().updateForum(f);
    if (f.getClick() == this.getSysConfig().getForumHotViews() && f.getIsHidden() == 0) {
     UserInfo ui = this.getUserService().findUserInfoById(f.getUserID());
     if (ui != null) {
      ui.setLiterary(ui.getLiterary() + 1); // 增加用户文采值
      this.getUserService().saveUserInfo(ui);
     }
    }
   } catch (BbscsException ex) {
    this.addActionError(this.getText("error.post.getpost"));
    return ERROR;

   }
} else {
   if (this.getInpages() == 1) {//private int inpages = 1;

    this.addActionError(this.getText("error.post.getpost"));
    return ERROR;
   }
}
this.pageTitle = f.getTitle();
this.setTotalnum(this.getPageList().getPages().getTotalNum());
this.setParentBoards();
this.setForumSiteInit();
return "read";
}
我们注意最后的几个set!
private int getUserPostPerNum(int userNum, int sysNum) {
if (userNum == 0) {
   return sysNum;
} else {
   return userNum;
}
}
private void setParentBoards() {
this.setParentBoards(this.getBoardService().findBoardsInIDs(this.getBoard().getParentIDs()));
}
private void setForumSiteInit() {
String url = this.getSysConfig().getForumUrl();
if (url == null) {
   url = "bbs.laoer.com";
} else if (url.startsWith("http://")) {
   url = url.substring("http://".length(), url.length());
}
this.setForumSite(url);
}
我们进入read.jsp:
<div id="head1right">   //头部的right部分:[分页: 1] [查看全部] [同主题打包] [订阅] [返回]
      <div id="head1rcontent">

      [<s:text name="bbscs.pagebreak"/>: <bbscs:pages value="%{pageList.pages}" argPage="inpages" argTotal="topicTotal"/>]
<s:if test="%{action=='topic'}">
[<bbscs:topic type="own"/>]
</s:if>
<s:if test="%{action=='own'}">
[<bbscs:topic type="topic"/>]
</s:if>
        [<bbscs:topic type="mailsendtopic"/>]
        [<bbscs:topic type="subs" />]
        [<bbscs:topic type="returnforum"/>]

      </div>
    </div>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
计算八字神煞需要用到农历和天干地支的知识,可以使用 PHP 的日期和时间函数来实现。 步骤如下: 1. 获取用户输入的阳历生日,使用 PHP 的 date 函数将其转换为农历生日。 2. 根据农历生日,计算出生年、生月、生日的天干地支。 3. 根据天干地支,查找对应的八字神煞。 以下是一个简单的 PHP 代码示例: ```php // 获取用户输入的生日 $birthday = '1990-01-01'; // 将阳历生日转换为农历生日 $chineseBirthday = getChineseBirthday($birthday); // 计算出生年、月、日的天干地支 list($yearTianGan, $yearDiZhi) = getTianGanDiZhi($chineseBirthday['year']); list($monthTianGan, $monthDiZhi) = getTianGanDiZhi($chineseBirthday['month']); list($dayTianGan, $dayDiZhi) = getTianGanDiZhi($chineseBirthday['day']); // 查找八字神煞 $shenSha = getShenSha($yearTianGan, $yearDiZhi, $monthTianGan, $monthDiZhi, $dayTianGan, $dayDiZhi); // 输出结果 echo '您的八字神煞为:' . implode(',', $shenSha); // 获取农历生日 function getChineseBirthday($birthday) { // 使用 PHP 的 DateTime 类将阳历生日转换为农历生日 $dateTime = new DateTime($birthday); $chineseCalendar = new ChineseCalendar($dateTime); $chineseBirthday = [ 'year' => $chineseCalendar->getChineseYear(), 'month' => $chineseCalendar->getChineseMonth(), 'day' => $chineseCalendar->getChineseDay(), ]; return $chineseBirthday; } // 计算天干地支 function getTianGanDiZhi($chineseValue) { // 天干 $tianGan = ['甲', '', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸']; // 地支 $diZhi = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥']; // 计算天干地支 $index = ($chineseValue - 4) % 60; $tianGanIndex = $index % 10; $diZhiIndex = $index % 12; $tianGanValue = $tianGan[$tianGanIndex]; $diZhiValue = $diZhi[$diZhiIndex]; return [$tianGanValue, $diZhiValue]; } // 查找八字神煞 function getShenSha($yearTianGan, $yearDiZhi, $monthTianGan, $monthDiZhi, $dayTianGan, $dayDiZhi) { // 八字神煞表 $shenShaTable = [ '甲子' => ['天', '文昌'], '甲戌' => ['天厨', '文曲'], '丑' => ['吊客', '天哭'], '酉' => ['陀罗', '天虚'], '丙寅' => ['将星', '天月'], '丙申' => ['天巫', '天德'], '丁卯' => ['天才', '天福'], '丁酉' => ['天寿', '天恩'], '戊辰' => ['天贵', '天使'], '戊戌' => ['天荫', '天罡'], '己巳' => ['天福', '天官'], '己亥' => ['天伤', '天蓬'], '庚午' => ['天空', '天任'], '庚子' => ['天后', '天伯'], '辛未' => ['天印', '天威'], '辛酉' => ['天权', '天禄'], '壬申' => ['天德', '天'], '壬子' => ['天才', '天英'], '癸未' => ['天寿', '天巫'], '癸酉' => ['天恩', '天贵'], ]; // 查找八字神煞 $shenSha = []; $key = $yearTianGan . $yearDiZhi; if (isset($shenShaTable[$key])) { $shenSha = array_merge($shenSha, $shenShaTable[$key]); } $key = $monthTianGan . $monthDiZhi; if (isset($shenShaTable[$key])) { $shenSha = array_merge($shenSha, $shenShaTable[$key]); } $key = $dayTianGan . $dayDiZhi; if (isset($shenShaTable[$key])) { $shenSha = array_merge($shenSha, $shenShaTable[$key]); } return $shenSha; } ``` 需要注意的是,以上代码示例中使用了第三方库 `ChineseCalendar` 来实现阳历和农历的转换,使用前需要先安装该库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值