コード例 #1
0
ファイル: UIPostForm.java プロジェクト: nampq309/forum
 public void execute(Event<UIPostForm> event) throws Exception {
   UIPostForm uiForm = event.getSource();
   UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class);
   UIAttachFileForm attachFileForm =
       uiForm.openPopup(popupContainer, UIAttachFileForm.class, 500, 0);
   attachFileForm.updateIsTopicForm(false);
   attachFileForm.setMaxField(5, false);
 }
コード例 #2
0
ファイル: UIPostForm.java プロジェクト: nampq309/forum
 public void onEvent(Event<UIPostForm> event, UIPostForm uiPostForm, String attFileId)
     throws Exception {
   for (ForumAttachment att : uiPostForm.attachments_) {
     if (att.getId().equals(attFileId)) {
       uiPostForm.removeFromUploadFileList(att);
       break;
     }
   }
   UIForumInputWithActions threadContent = uiPostForm.getChildById(FIELD_THREADCONTEN_TAB);
   threadContent.setActionField(FIELD_ATTACHMENTS, uiPostForm.getUploadFileList());
   event.getRequestContext().addUIComponentToUpdateByAjax(uiPostForm);
 }
コード例 #3
0
ファイル: UIPostForm.java プロジェクト: nampq309/forum
 public void onEvent(Event<UIPostForm> event, UIPostForm uiForm, String id) throws Exception {
   UIForumInputWithActions threadContent = uiForm.getChildById(FIELD_THREADCONTEN_TAB);
   int t = 0, k = 1;
   String postTitle = threadContent.getUIStringInput(FIELD_POSTTITLE_INPUT).getValue();
   String userName = UserHelper.getCurrentUser();
   String message = threadContent.getChild(UIFormWYSIWYGInput.class).getValue();
   String checksms =
       TransformHTML.cleanHtmlCode(
           message, new ArrayList<String>((new ExtendedBBCodeProvider()).getSupportedBBCodes()));
   checksms = checksms.replaceAll("&nbsp;", " ");
   t = checksms.trim().length();
   if (ForumUtils.isEmpty(postTitle)) {
     k = 0;
   }
   if (t > 0 && k != 0 && !checksms.equals("null")) {
     postTitle = CommonUtils.encodeSpecialCharInTitle(postTitle);
     Post post = uiForm.post_;
     post.setName(postTitle);
     post.setMessage(message);
     post.setOwner(userName);
     if (ForumUtils.isEmpty(uiForm.postId)) {
       post.setCreatedDate(CommonUtils.getGreenwichMeanTime().getTime());
       post.setModifiedDate(CommonUtils.getGreenwichMeanTime().getTime());
     }
     post.setModifiedBy(userName);
     post.setRemoteAddr(ForumUtils.EMPTY_STR);
     post.setIcon("uiIconForumTopic uiIconForumLightGray");
     post.setIsApproved(false);
     post.setAttachments(uiForm.getAttachFileList());
     UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class);
     UIViewPost viewPost = uiForm.openPopup(popupContainer, UIViewPost.class, 670, 0);
     viewPost.setId("viewPost");
     viewPost.setPostView(post);
     viewPost.setActionForm(new String[] {"Close"});
   } 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.warning("NameValidator.msg.ShortText", args);
     } else if (t <= 0) {
       args = new String[] {uiForm.getLabel(FIELD_MESSAGECONTENT)};
       uiForm.warning("NameValidator.msg.ShortMessage", args);
     }
   }
 }
コード例 #4
0
ファイル: UIPostForm.java プロジェクト: nampq309/forum
 public void execute(Event<UIPostForm> event) throws Exception {
   UIPostForm uiForm = event.getSource();
   UIForumPortlet forumPortlet = uiForm.getAncestorOfType(UIForumPortlet.class);
   forumPortlet.cancelAction();
 }
コード例 #5
0
ファイル: UIPostForm.java プロジェクト: nampq309/forum
 public void onEvent(Event<UIPostForm> event, UIPostForm postForm, String id) throws Exception {
   postForm.tabId = Integer.parseInt(id);
   Util.getPortalRequestContext().setResponseComplete(true);
 }
コード例 #6
0
ファイル: UIPostForm.java プロジェクト: nampq309/forum
    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("&nbsp;", " ");
          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();
      }
    }