public void updatePost(String postId, boolean isQuote, boolean isPP, Post post) throws Exception { if (post != null) this.post_ = post; this.postId = postId; this.isQuote = isQuote; this.isMP = isPP; UIForumInputWithActions threadContent = this.getChildById(FIELD_THREADCONTEN_TAB); UIFormStringInput editReason = threadContent.getUIStringInput(FIELD_EDITREASON_INPUT); editReason.setRendered(false); if (!ForumUtils.isEmpty(this.postId) && post != null) { String message = CommonUtils.decodeSpecialCharToHTMLnumberIgnore(post.getMessage()); if (isQuote) { // quote threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(getTitle(post.getName()))); String value = "[QUOTE=" + getForumService().getScreenName(post.getOwner()) + "]" + message + "[/QUOTE]"; threadContent.getChild(UIFormWYSIWYGInput.class).setValue(value); } else if (isPP) { threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(getTitle(topic.getTopicName()))); } else { // edit this.attachments_.clear(); editReason.setRendered(true); threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(post.getName())); if (post.getAttachments() != null && post.getAttachments().size() > 0) { this.attachments_.addAll(post.getAttachments()); this.refreshUploadFileList(); } threadContent.getChild(UIFormWYSIWYGInput.class).setValue(message); } } else { if (!isQuote) { // reply threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(getTitle(topic.getTopicName()))); } } }
public void onEvent(Event<UIPostForm> event, UIPostForm uiForm, String id) throws Exception { if (uiForm.isDoubleClickSubmit) return; uiForm.isDoubleClickSubmit = true; UIForumPortlet forumPortlet = uiForm.getAncestorOfType(UIForumPortlet.class); UserProfile userProfile = forumPortlet.getUserProfile(); try { if (forumPortlet.checkForumHasAddPost(uiForm.categoryId, uiForm.forumId, uiForm.topicId)) { UIForumInputWithActions threadContent = uiForm.getChildById(FIELD_THREADCONTEN_TAB); int t = 0, k = 1; String postTitle = threadContent.getUIStringInput(FIELD_POSTTITLE_INPUT).getValue(); boolean isAddRe = false; int maxText = ForumUtils.MAXTITLE; if (!ForumUtils.isEmpty(postTitle)) { while (postTitle.indexOf(uiForm.getTitle("").trim()) == 0) { postTitle = postTitle.replaceFirst(STR_RE.trim(), ForumUtils.EMPTY_STR).trim(); isAddRe = true; } if (postTitle.length() > maxText) { warning( "NameValidator.msg.warning-long-text", new String[] {uiForm.getLabel(FIELD_POSTTITLE_INPUT), String.valueOf(maxText)}); uiForm.isDoubleClickSubmit = false; return; } } String message = threadContent.getChild(UIFormWYSIWYGInput.class).getValue(); String checksms = TransformHTML.cleanHtmlCode( message, new ArrayList<String>((new ExtendedBBCodeProvider()).getSupportedBBCodes())); checksms = checksms.replaceAll(" ", " "); t = checksms.length(); if (ForumUtils.isEmpty(postTitle)) { k = 0; } if (t > 0 && k != 0 && !checksms.equals("null")) { String editReason = threadContent.getUIStringInput(FIELD_EDITREASON_INPUT).getValue(); if (!ForumUtils.isEmpty(editReason) && editReason.length() > maxText) { warning( "NameValidator.msg.warning-long-text", new String[] {uiForm.getLabel(FIELD_EDITREASON_INPUT), String.valueOf(maxText)}); uiForm.isDoubleClickSubmit = false; return; } String userName = userProfile.getUserId(); editReason = CommonUtils.encodeSpecialCharInTitle(editReason); message = TransformHTML.fixAddBBcodeAction(message); message = CommonUtils.encodeSpecialCharInSearchTerm(message); postTitle = CommonUtils.encodeSpecialCharInTitle(postTitle); Post post = uiForm.post_; boolean isPP = false; boolean isOffend = false; boolean hasTopicMod = false; if (!uiForm.isMod()) { String[] censoredKeyword = ForumUtils.getCensoredKeyword(uiForm.getForumService()); checksms = checksms.toLowerCase().trim(); for (String string : censoredKeyword) { if (checksms.indexOf(string.trim()) >= 0) { isOffend = true; break; } if (postTitle.toLowerCase().indexOf(string.trim()) >= 0) { isOffend = true; break; } } if (post.getUserPrivate() != null && post.getUserPrivate().length == 2) isPP = true; if ((!uiForm.isMP || !isPP) && uiForm.topic != null) hasTopicMod = uiForm.topic.getIsModeratePost(); } if (isOffend && (uiForm.isMP || isPP)) { uiForm.warning("UIPostForm.msg.PrivateCensor"); uiForm.isDoubleClickSubmit = false; return; } // set link String link = ForumUtils.createdForumLink(ForumUtils.TOPIC, uiForm.topicId, false); // if (uiForm.isQuote || uiForm.isMP) post = new Post(); post.setName((isAddRe) ? uiForm.getTitle(postTitle) : postTitle); post.setMessage(message); post.setOwner(userName); post.setCreatedDate(new Date()); post.setIcon("uiIconForumTopic uiIconForumLightGray"); post.setAttachments(uiForm.getAttachFileList()); post.setIsWaiting(isOffend); post.setLink(link); String[] userPrivate = new String[] {"exoUserPri"}; if (uiForm.isMP) { userPrivate = new String[] {userName, uiForm.post_.getOwner()}; hasTopicMod = false; } post.setUserPrivate(userPrivate); post.setIsApproved(!hasTopicMod); UITopicDetailContainer topicDetailContainer = forumPortlet.findFirstComponentOfType(UITopicDetailContainer.class); UITopicDetail topicDetail = topicDetailContainer.getChild(UITopicDetail.class); boolean isParentDelete = false; boolean isNew = false; try { if (!ForumUtils.isEmpty(uiForm.postId)) { if (uiForm.isQuote || uiForm.isMP) { post.setRemoteAddr(WebUIUtils.getRemoteIP()); try { uiForm .getForumService() .savePost( uiForm.categoryId, uiForm.forumId, uiForm.topicId, post, true, ForumUtils.getDefaultMail()); isNew = true; } catch (PathNotFoundException e) { isParentDelete = true; } topicDetail.setIdPostView("lastpost"); } else { // post.setId(uiForm.postId) ; post.setModifiedBy(userName); post.setModifiedDate(new Date()); post.setEditReason(editReason); MessageBuilder messageBuilder = ForumUtils.getDefaultMail(); messageBuilder.setLink(link + ForumUtils.SLASH + post.getId()); try { uiForm .getForumService() .savePost( uiForm.categoryId, uiForm.forumId, uiForm.topicId, post, false, messageBuilder); } catch (PathNotFoundException e) { isParentDelete = true; } topicDetail.setIdPostView(uiForm.postId); } } else { post.setRemoteAddr(WebUIUtils.getRemoteIP()); try { uiForm .getForumService() .savePost( uiForm.categoryId, uiForm.forumId, uiForm.topicId, post, true, ForumUtils.getDefaultMail()); isNew = true; } catch (PathNotFoundException e) { isParentDelete = true; } catch (Exception ex) { uiForm.log.warn(String.format("Failed to save post %s", post.getName()), ex); } topicDetail.setIdPostView("lastpost"); } if (isNew) { if (userProfile.getIsAutoWatchTopicIPost()) { List<String> values = new ArrayList<String>(); values.add(userProfile.getEmail()); String path = uiForm.categoryId + ForumUtils.SLASH + uiForm.forumId + ForumUtils.SLASH + uiForm.topicId; uiForm.getForumService().addWatch(1, path, values, userProfile.getUserId()); } } uiForm .getForumService() .updateTopicAccess(forumPortlet.getUserProfile().getUserId(), uiForm.topicId); forumPortlet .getUserProfile() .setLastTimeAccessTopic( uiForm.topicId, CommonUtils.getGreenwichMeanTime().getTimeInMillis()); } catch (Exception e) { uiForm.log.warn("Failed to save topic", e); } uiForm.isMP = uiForm.isQuote = false; if (isParentDelete) { forumPortlet.cancelAction(); uiForm.warning("UIPostForm.msg.isParentDelete"); return; } forumPortlet.cancelAction(); if (isOffend || hasTopicMod) { topicDetail.setIdPostView("normal"); if (isOffend) uiForm.warning("MessagePost.msg.isOffend", false); else { uiForm.warning("MessagePost.msg.isModerate", false); } } event.getRequestContext().addUIComponentToUpdateByAjax(topicDetailContainer); } else { String[] args = {ForumUtils.EMPTY_STR}; if (k == 0) { args = new String[] {uiForm.getLabel(FIELD_POSTTITLE_INPUT)}; if (t == 0) args = new String[] { uiForm.getLabel(FIELD_POSTTITLE_INPUT) + ", " + uiForm.getLabel(FIELD_MESSAGECONTENT) }; uiForm.isDoubleClickSubmit = false; uiForm.warning("NameValidator.msg.ShortMessage", args); } else if (t == 0) { args = new String[] {uiForm.getLabel(FIELD_MESSAGECONTENT)}; uiForm.isDoubleClickSubmit = false; uiForm.warning("NameValidator.msg.ShortMessage", args); } } } else { forumPortlet.cancelAction(); forumPortlet.removeCacheUserProfile(); UITopicDetail topicDetail = forumPortlet.findFirstComponentOfType(UITopicDetail.class); topicDetail.initInfoTopic(uiForm.categoryId, uiForm.forumId, uiForm.topic, 0); uiForm.warning("UIPostForm.msg.no-permission", false); event.getRequestContext().addUIComponentToUpdateByAjax(forumPortlet); } } catch (Exception e) { uiForm.log.error("Can not save post into this topic, exception: " + e.getMessage(), e); uiForm.warning("UIPostForm.msg.isParentDelete", false); forumPortlet.cancelAction(); } }