/** * 站长回复留言板之留言 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ protected ActionForward doReply( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { GuestBookForm msgform = (GuestBookForm) form; super.validateClientId(request, msgform); if (StringUtils.isNotEmpty(msgform.getReply())) { UserBean loginUser = super.getLoginUser(request, response); if (loginUser != null) { // 判断是否为站长 SiteBean site = SiteDAO.getSiteByID(msgform.getSid()); if (site != null && site.isOwner(loginUser)) { // 回复留言 GuestBookBean gbean = GuestBookDAO.getMsg(msgform.getSid(), msgform.getId()); if (gbean != null) { String reply = super.autoFiltrate(site, msgform.getReply()); if (reply.length() > MAX_GB_REPLY_LENGTH) reply = reply.substring(0, MAX_GB_REPLY_LENGTH); gbean.setReply(super.filterScriptAndStyle(reply)); gbean.setReplyTime(new Date()); GuestBookDAO.flush(); } } } } String ext = null; if (msgform.getPage() > 1) { ext = "page=" + msgform.getPage(); } return makeForward(mapping.findForward("list"), msgform.getSid(), ext); }
/** * 留言板之发表留言 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ protected ActionForward doCreate( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { GuestBookForm msgform = (GuestBookForm) form; super.validateClientId(request, msgform); ActionMessages msgs = new ActionMessages(); while (true) { if (StringUtils.isEmpty(msgform.getContent())) { msgs.add("content", new ActionMessage("error.empty_content")); break; } UserBean loginUser = super.getLoginUser(request, response); if (loginUser == null) { msgs.add("message", new ActionMessage("error.user_not_login")); break; } else if (loginUser.getStatus() != UserBean.STATUS_NORMAL) { msgs.add("message", new ActionMessage("error.user_not_available")); break; } SiteBean site = super.getSiteByID(msgform.getSid()); if (site == null) { msgs.add("message", new ActionMessage("error.site_not_available")); break; } // 检查黑名单 if (isUserInBlackList(site, loginUser)) { msgs.add("message", new ActionMessage("error.user_in_blacklist")); break; } GuestBookBean msgbean = new GuestBookBean(); String content = super.autoFiltrate(site, msgform.getContent()); if (content.length() > MAX_GB_COUNT_LENGTH) content = content.substring(0, MAX_GB_COUNT_LENGTH); msgbean.setContent(super.filterScriptAndStyle(content)); msgbean.setClient(new ClientInfo(request, 0)); msgbean.setUser(loginUser); msgbean.setSiteId(site.getId()); try { GuestBookDAO.createMsg(msgbean); } catch (HibernateException e) { context().log("undelete diary failed.", e); msgs.add("message", new ActionMessage("error.database", e.getMessage())); } break; } if (!msgs.isEmpty()) { saveMessages(request, msgs); return mapping.findForward("pub"); } return makeForward(mapping.findForward("list"), msgform.getSid()); }
/** * 获取网站的精华帖子数 * * @param site * @param fbean * @return */ public static int getEliteCount(SiteBean site, ForumBean fbean) { StringBuffer hql = new StringBuffer("SELECT COUNT(*) FROM TopicBean AS t WHERE t.status=:status"); if (site != null) hql.append(" AND t.site.id=:site"); if (fbean != null) hql.append(" AND t.forum.id=:forum"); hql.append(" AND (t.type=:elite OR t.type=:top_elite)"); Session ssn = getSession(); Query q = ssn.createQuery(hql.toString()); q.setInteger("status", TopicBean.STATUS_NORMAL); q.setInteger("elite", TopicBean.INFO_TYPE_ELITE); q.setInteger("top_elite", TopicBean.INFO_TYPE_TOP_ELITE); if (site != null) q.setInteger("site", site.getId()); if (fbean != null) q.setInteger("forum", fbean.getId()); return ((Number) q.uniqueResult()).intValue(); }
/** * 列出精华帖 * * @param site * @param fbean * @param fromIdx * @param count * @return */ public static List listEliteTopics(SiteBean site, ForumBean fbean, int fromIdx, int count) { StringBuffer hql = new StringBuffer("FROM TopicOutlineBean AS t WHERE t.status=:status"); if (site != null) hql.append(" AND t.site.id=:site"); if (fbean != null) hql.append(" AND t.forum.id=:forum"); hql.append( " AND (t.type=:elite OR t.type=:top_elite) ORDER BY ROUND(t.type / 16, 0) DESC, t.id DESC"); Session ssn = getSession(); Query q = ssn.createQuery(hql.toString()); q.setInteger("status", TopicBean.STATUS_NORMAL); q.setInteger("elite", TopicBean.INFO_TYPE_ELITE); q.setInteger("top_elite", TopicBean.INFO_TYPE_TOP_ELITE); if (site != null) q.setInteger("site", site.getId()); if (fbean != null) q.setInteger("forum", fbean.getId()); if (fromIdx > 0) q.setFirstResult(fromIdx); if (count > 0) q.setMaxResults(count); return q.list(); }
/** * 分页浏览某个论坛的热门帖子 帖子按照回帖数 * * @param forum_id * @param fromIdx * @param count * @return */ public static List listHotTopics( SiteBean site, ForumBean forum, int fromIdx, int count, int days) { StringBuffer hql = new StringBuffer( "FROM TopicOutlineBean AS t WHERE t.site.id=? AND t.status=? AND t.createTime >= ? AND t.replyCount > 0"); if (forum != null) hql.append(" AND t.forum.id=?"); hql.append(" ORDER BY ROUND(t.type / 16, 0) DESC, t.replyCount DESC, t.id DESC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setInteger(0, site.getId()); q.setInteger(1, TopicOutlineBean.STATUS_NORMAL); Calendar cur_time = Calendar.getInstance(); cur_time.add(Calendar.DATE, -days); q.setTimestamp(2, new Timestamp(cur_time.getTime().getTime())); if (forum != null) q.setInteger(3, forum.getId()); if (fromIdx > 0) q.setFirstResult(fromIdx); q.setMaxResults(count); return q.list(); } finally { hql = null; } }
/** * 查询某个HTTP会话上传的且尚未被领取的所有文件信息 要把文件大小计算进site中 * * @param userid * @param sessionId * @return * @throws CapacityExceedException */ public static int pickupOrphanFiles( int userid, String sessionId, SiteBean site, int refId, int refType) throws CapacityExceedException { int er = 0; try { // 要把文件大小计算进site中 Number totalSize = executeNamedStat("SUM_UPLOAD_FILE_SIZE", new Object[] {new Integer(userid), sessionId}); if (totalSize != null) { beginTransaction(); int iTotalSize = totalSize.intValue(); int file_size = DLOG4JUtils.sizeInKbytes(iTotalSize); if (site.getCapacity().getDiaryTotal() > 0 && site.getCapacity().getDiaryUsed() + file_size > site.getCapacity().getDiaryTotal()) { // 已然超过可用的空间 throw new CapacityExceedException(site.getCapacity().getDiaryTotal()); } executeNamedUpdate("INC_SITE_UPLOAD_SPACE", Math.max(1, file_size), site.getId()); // 更新尚未领取文件的归属信息 executeNamedUpdate( "PICKUP_UPLOAD_FILES", new Object[] { new Integer(site.getId()), new Integer(refId), new Integer(refType), new Integer(userid), sessionId }); commit(); } return er; } catch (HibernateException e) { rollback(); throw e; } }