コード例 #1
0
ファイル: TestForumService.java プロジェクト: hanhvq/exo-ks
  public void testUserProfile() throws Exception {
    String userName = "******";
    UserProfile userProfile = createdUserProfile(userName);

    // save UserProfile
    forumService_.saveUserProfile(userProfile, true, true);

    // getUserInfo
    userProfile = forumService_.getUserInfo(userName);
    assertNotNull("Get info UserProfile is null", userProfile);

    // get Default
    userProfile = forumService_.getDefaultUserProfile(userName, "");
    assertNotNull("Get default UserProfile is null", userProfile);

    // getUserInformations
    userProfile = forumService_.getUserInformations(userProfile);
    assertNotNull("Get informations UserProfile is null", userProfile);

    // getUserSettingProfile
    userProfile = forumService_.getUserSettingProfile(userName);
    assertNotNull("Get Setting UserProfile is not null", userProfile);

    // saveUserSettingProfile
    assertEquals("Default AutoWatchMyTopics is false", userProfile.getIsAutoWatchMyTopics(), false);
    userProfile.setIsAutoWatchMyTopics(true);
    forumService_.saveUserSettingProfile(userProfile);
    userProfile = forumService_.getUserSettingProfile(userName);
    assertEquals(
        "Edit AutoWatchMyTopics and can't save this property. AutoWatchMyTopics is false",
        userProfile.getIsAutoWatchMyTopics(),
        true);
    //
  }
コード例 #2
0
 protected boolean getIsBanned(UserProfile userProfile) throws Exception {
   if (userProfile.getBanUntil() > 0) {
     Calendar calendar = CommonUtils.getGreenwichMeanTime();
     if (calendar.getTimeInMillis() >= userProfile.getBanUntil()) {
       userProfile.setIsBanned(false);
       return false;
     }
   }
   return true;
 }
コード例 #3
0
ファイル: TestForumService.java プロジェクト: hanhvq/exo-ks
 private UserProfile createdUserProfile(String userName) {
   UserProfile userProfile = new UserProfile();
   userProfile.setUserId(userName);
   userProfile.setUserRole((long) 0);
   userProfile.setUserTitle(Utils.ADMIN);
   userProfile.setEmail("*****@*****.**");
   userProfile.setJoinedDate(new Date());
   userProfile.setTimeZone(7.0);
   userProfile.setSignature("signature");
   return userProfile;
 }
コード例 #4
0
 private UserProfile getUserProfile(String userId) throws Exception {
   for (UserProfile userProfile : this.userProfiles) {
     if (userProfile.getUserId().equals(userId)) {
       if (userProfile.getUserRole() != 0 && isAdmin(userProfile.getUserId())) {
         userProfile.setUserRole((long) 0);
         userProfile.setUserTitle(Utils.ADMIN);
       }
       return userProfile;
     }
   }
   UserProfile userProfile = new UserProfile();
   userProfile.setUserId(userId);
   return userProfile;
 }
コード例 #5
0
ファイル: FAQUtils.java プロジェクト: phuonglm/forum
 private static String getFormatDate(int dateFormat, Date myDate) {
   if (myDate == null) return "";
   String format = (dateFormat == DateFormat.LONG) ? "EEE,MMM dd,yyyy" : "MM/dd/yyyy";
   try {
     String userName = getCurrentUser();
     if (!isFieldEmpty(userName)) {
       org.exoplatform.forum.service.ForumService forumService =
           (org.exoplatform.forum.service.ForumService)
               ExoContainerContext.getCurrentContainer()
                   .getComponentInstanceOfType(org.exoplatform.forum.service.ForumService.class);
       org.exoplatform.forum.service.UserProfile profile =
           forumService.getUserSettingProfile(userName);
       format =
           (dateFormat == DateFormat.LONG)
               ? profile.getLongDateFormat()
               : profile.getShortDateFormat();
     }
   } catch (Exception e) {
     log.debug("No forum settings found for date format. Will use format " + format);
   }
   format = format.replaceAll("D", "E");
   return TimeConvertUtils.getFormatDate(myDate, format);
 }
コード例 #6
0
ファイル: UserProfileData.java プロジェクト: javen-hao/forum
 public UserProfileData(UserProfile profile) {
   this.userId = profile.getUserId();
   this.userTitle = profile.getUserTitle();
   this.screenName = profile.getScreenName();
   this.userRole = profile.getUserRole();
   this.signature = profile.getSignature();
   this.lastLoginDate = profile.getLastLoginDate();
   this.joinedDate = profile.getJoinedDate();
   this.lastPostDate = profile.getLastPostDate();
   this.totalPost = profile.getTotalPost();
   this.isDisplaySignature = profile.getIsDisplaySignature();
   this.isDisplayAvatar = profile.getIsDisplayAvatar();
   this.timeZone = profile.getTimeZone();
   this.shortDateformat = profile.getShortDateFormat();
   this.longDateformat = profile.getLongDateFormat();
   this.moderateForums = profile.getModerateForums();
   this.moderateCategory = profile.getModerateCategory();
   this.maxTopic = profile.getMaxTopicInPage();
   this.maxPost = profile.getMaxPostInPage();
   this.isBanned = profile.getIsBanned();
   this.banUntil = profile.getBanUntil();
   this.banReason = profile.getBanReason();
   this.banCounter = profile.getBanCounter();
   this.banReasonSummary = profile.getBanReasonSummary();
   this.createdDateBan = profile.getCreatedDateBan();
   this.isDisabled = profile.isDisabled();
 }
コード例 #7
0
ファイル: UserProfileData.java プロジェクト: javen-hao/forum
 @Override
 public UserProfile build() {
   UserProfile userProfile = new UserProfile();
   userProfile.setUserId(this.userId);
   userProfile.setUserTitle(this.userTitle);
   userProfile.setScreenName(this.screenName);
   userProfile.setUserRole(this.userRole);
   userProfile.setSignature(this.signature);
   userProfile.setLastLoginDate(this.lastLoginDate);
   userProfile.setJoinedDate(this.joinedDate);
   userProfile.setLastPostDate(this.lastPostDate);
   userProfile.setTotalPost(this.totalPost);
   userProfile.setIsDisplaySignature(this.isDisplaySignature);
   userProfile.setIsDisplayAvatar(this.isDisplayAvatar);
   userProfile.setTimeZone(this.timeZone);
   userProfile.setShortDateFormat(this.shortDateformat);
   userProfile.setLongDateFormat(this.longDateformat);
   userProfile.setModerateForums(this.moderateForums);
   userProfile.setModerateCategory(this.moderateCategory);
   userProfile.setMaxPostInPage(this.maxPost);
   userProfile.setMaxTopicInPage(this.maxTopic);
   userProfile.setIsBanned(this.isBanned);
   userProfile.setBanUntil(this.banUntil);
   userProfile.setBanReason(this.banReason);
   userProfile.setBanCounter(this.banCounter);
   userProfile.setBanReasonSummary(this.banReasonSummary);
   userProfile.setCreatedDateBan(this.createdDateBan);
   userProfile.setDisabled(this.isDisabled);
   return userProfile;
 }
コード例 #8
0
    public void onEvent(
        Event<UIModeratorManagementForm> event, UIModeratorManagementForm uiForm, String userId)
        throws Exception {
      UserProfile userProfile = uiForm.editUserProfile;
      UIFormInputWithActions inputSetProfile = uiForm.getChildById(FIELD_USERPROFILE_FORM);
      String userTitle = inputSetProfile.getUIStringInput(FIELD_USERTITLE_INPUT).getValue();
      String screenName = inputSetProfile.getUIStringInput(FIELD_SCREENNAME_INPUT).getValue();
      screenName = CommonUtils.encodeSpecialCharInTitle(screenName);
      long userRole = 2;
      boolean isAdmin = inputSetProfile.getUICheckBoxInput(FIELD_USERROLE_CHECKBOX).isChecked();
      if (isAdmin || uiForm.isAdmin(userProfile.getUserId())) {
        isAdmin = true;
        userRole = 0;
      }
      //
      if (ForumUtils.isEmpty(userTitle)) {
        if (isAdmin) {
          userTitle = Utils.ADMIN;
        } else {
          userTitle = userProfile.getUserTitle();
        }
      } else {
        userTitle = CommonUtils.encodeSpecialCharInTitle(userTitle);
      }
      // -----------------
      List<String> oldModerateForum =
          uiForm.getModerateList(Arrays.asList(userProfile.getModerateForums()));
      List<String> newModeratorsForum = new ArrayList<String>();
      List<String> removeModerateForum = new ArrayList<String>();
      List<String> forumIdsMod = new ArrayList<String>();
      //
      newModeratorsForum = uiForm.getModerateList(uiForm.listModerate);
      forumIdsMod.addAll(newModeratorsForum);
      if (newModeratorsForum.isEmpty()) {
        removeModerateForum = oldModerateForum;
      } else {
        for (String string : oldModerateForum) {
          if (newModeratorsForum.contains(string)) {
            newModeratorsForum.remove(string);
          } else {
            removeModerateForum.add(string);
          }
        }
        if (!newModeratorsForum.isEmpty())
          uiForm
              .getForumService()
              .saveModerateOfForums(newModeratorsForum, userProfile.getUserId(), false);
      }
      if (!removeModerateForum.isEmpty()) {
        uiForm
            .getForumService()
            .saveModerateOfForums(removeModerateForum, userProfile.getUserId(), true);
      }

      uiForm
          .getForumService()
          .saveUserModerator(userProfile.getUserId(), uiForm.listModerate, false);

      List<String> moderateCates = new ArrayList<String>();
      moderateCates.addAll(uiForm.listModCate);
      List<String> newModeratorsCate = new ArrayList<String>();
      List<String> categoryIdsMod = new ArrayList<String>();
      List<String> oldModerateCate =
          uiForm.getModerateList(Arrays.asList(userProfile.getModerateCategory()));
      List<String> removeModerateCate = new ArrayList<String>();
      // set moderator category
      newModeratorsCate = uiForm.getModerateList(moderateCates);
      categoryIdsMod.addAll(newModeratorsCate);
      if (newModeratorsCate.isEmpty()) {
        removeModerateCate = oldModerateCate;
      } else {
        for (String string : oldModerateCate) {
          if (newModeratorsCate.contains(string)) {
            newModeratorsCate.remove(string);
          } else {
            removeModerateCate.add(string);
          }
        }
        if (!newModeratorsCate.isEmpty()) {
          uiForm
              .getForumService()
              .saveModOfCategory(newModeratorsCate, userProfile.getUserId(), true);
          if (userRole > 1) userRole = 1;
        }
      }
      if (removeModerateCate.size() > 0) {
        uiForm
            .getForumService()
            .saveModOfCategory(removeModerateCate, userProfile.getUserId(), false);
      }

      if (userRole > 1) {
        uiForm.listModerate =
            uiForm.getForumService().getUserModerator(userProfile.getUserId(), false);
        if (uiForm.listModerate.size() >= 1 && !uiForm.listModerate.get(0).equals(" "))
          userRole = 1;
      }

      if (userTitle == null || userTitle.trim().length() < 1) {
        userTitle = userProfile.getUserTitle();
      } else if (!isAdmin) {
        int newPos = Arrays.asList(uiForm.permissionUser).indexOf(userTitle.toLowerCase());
        if (newPos >= 0 && newPos < userRole) {
          if (Arrays.asList(uiForm.permissionUser).indexOf(userProfile.getUserTitle().toLowerCase())
              < 0) userTitle = userProfile.getUserTitle();
          else userTitle = uiForm.titleUser[(int) userRole];
        }
      } else {
        if (userTitle.equalsIgnoreCase(uiForm.titleUser[1])
            || userTitle.equalsIgnoreCase(uiForm.titleUser[2])) userTitle = uiForm.titleUser[0];
      }
      if (userRole == 1 && userTitle.equalsIgnoreCase(uiForm.titleUser[2])) {
        userTitle = uiForm.titleUser[1];
      }

      String signature =
          inputSetProfile.getUIFormTextAreaInput(FIELD_SIGNATURE_TEXTAREA).getValue();
      signature = CommonUtils.encodeSpecialCharInTitle(signature);
      boolean isDisplaySignature =
          inputSetProfile.getUICheckBoxInput(FIELD_ISDISPLAYSIGNATURE_CHECKBOX).isChecked();
      Boolean isDisplayAvatar =
          inputSetProfile.getUICheckBoxInput(FIELD_ISDISPLAYAVATAR_CHECKBOX).isChecked();

      UIFormInputWithActions inputSetOption = uiForm.getChildById(FIELD_USEROPTION_FORM);
      double timeZone =
          Double.parseDouble(
              inputSetOption.getUIFormSelectBox(FIELD_TIMEZONE_SELECTBOX).getValue());
      String shortDateFormat =
          inputSetOption.getUIFormSelectBox(FIELD_SHORTDATEFORMAT_SELECTBOX).getValue();
      String longDateFormat =
          inputSetOption.getUIFormSelectBox(FIELD_LONGDATEFORMAT_SELECTBOX).getValue();
      String timeFormat = inputSetOption.getUIFormSelectBox(FIELD_TIMEFORMAT_SELECTBOX).getValue();
      long maxTopic =
          Long.parseLong(
              inputSetOption.getUIFormSelectBox(FIELD_MAXTOPICS_SELECTBOX).getValue().substring(2));
      long maxPost =
          Long.parseLong(
              inputSetOption.getUIFormSelectBox(FIELD_MAXPOSTS_SELECTBOX).getValue().substring(2));

      UIFormInputWithActions inputSetBan = uiForm.getChildById(FIELD_USERBAN_FORM);
      boolean wasBanned = userProfile.getIsBanned();
      boolean isBanned = inputSetBan.getUICheckBoxInput(FIELD_ISBANNED_CHECKBOX).isChecked();
      String until = inputSetBan.getUIFormSelectBox(FIELD_BANUNTIL_SELECTBOX).getValue();
      long banUntil = 0;
      if (!ForumUtils.isEmpty(until)) {
        banUntil = Long.parseLong(until.substring(6));
      }
      String banReason = inputSetBan.getUIFormTextAreaInput(FIELD_BANREASON_TEXTAREA).getValue();
      String[] banReasonSummaries = userProfile.getBanReasonSummary();
      Date date = CommonUtils.getGreenwichMeanTime().getTime();
      int banCounter = userProfile.getBanCounter();
      date.setTime(banUntil);
      StringBuffer stringBuffer = new StringBuffer();
      if (!ForumUtils.isEmpty(banReason)) {
        stringBuffer.append("Ban Reason: ").append(banReason).append(" ");
      }
      stringBuffer
          .append("From Date: ")
          .append(
              TimeConvertUtils.getFormatDate(
                  "MM-dd-yyyy hh:mm a", CommonUtils.getGreenwichMeanTime().getTime()))
          .append(" GMT+0 To Date: ")
          .append(TimeConvertUtils.getFormatDate("MM-dd-yyyy hh:mm a", date))
          .append(" GMT+0");
      if (isBanned) {
        if (banReasonSummaries != null && banReasonSummaries.length > 0) {
          if (wasBanned) {
            banReasonSummaries[0] = stringBuffer.toString();
          } else {
            String[] temp = new String[banReasonSummaries.length + 1];
            int i = 1;
            for (String string : banReasonSummaries) {
              temp[i++] = string;
            }
            temp[0] = stringBuffer.toString();
            banReasonSummaries = temp;
            banCounter = banCounter + 1;
          }
        } else {
          banReasonSummaries = new String[] {stringBuffer.toString()};
          banCounter = 1;
        }
      }
      userProfile.setUserTitle(userTitle);
      userProfile.setScreenName(screenName);
      userProfile.setUserRole(userRole);
      userProfile.setSignature(signature);
      userProfile.setIsDisplaySignature(isDisplaySignature);
      userProfile.setModerateCategory(moderateCates.toArray(new String[] {}));
      userProfile.setIsDisplayAvatar(isDisplayAvatar);

      userProfile.setTimeZone(-timeZone);
      userProfile.setShortDateFormat(shortDateFormat);
      userProfile.setLongDateFormat(longDateFormat.replace('=', ' '));
      userProfile.setTimeFormat(timeFormat.replace('=', ' '));
      userProfile.setMaxPostInPage(maxPost);
      userProfile.setMaxTopicInPage(maxTopic);
      userProfile.setIsBanned(isBanned);
      userProfile.setBanUntil(banUntil);
      userProfile.setBanReason(banReason);
      userProfile.setBanCounter(banCounter);
      userProfile.setBanReasonSummary(banReasonSummaries);
      try {
        uiForm.getForumService().saveUserProfile(userProfile, true, true);
      } catch (Exception e) {
        uiForm.log.trace("\nSave user profile fail: " + e.getMessage() + "\n" + e.getCause());
      }
      uiForm.isEdit = false;
      if (ForumUtils.isEmpty(uiForm.valueSearch)) {
        uiForm.isViewSearchUser = false;
      } else {
        uiForm.searchUserProfileByKey(uiForm.valueSearch);
      }
      UIPopupWindow popupWindow = uiForm.getAncestorOfType(UIPopupWindow.class);
      popupWindow.setWindowSize(760, 350);
      event.getRequestContext().addUIComponentToUpdateByAjax(popupWindow.getParent());
    }
コード例 #9
0
  private void initUserProfileForm() throws Exception {
    List<SelectItemOption<String>> list;
    UIFormStringInput userId = new UIFormStringInput(FIELD_USERID_INPUT, FIELD_USERID_INPUT, null);
    userId.setValue(this.editUserProfile.getUserId());
    userId.setReadOnly(true);
    userId.setDisabled(true);
    UIFormStringInput screenName =
        new UIFormStringInput(FIELD_SCREENNAME_INPUT, FIELD_SCREENNAME_INPUT, null);
    String screenN = editUserProfile.getScreenName();
    if (ForumUtils.isEmpty(screenN)) screenN = editUserProfile.getUserId();
    screenName.setValue(CommonUtils.decodeSpecialCharToHTMLnumber(screenN));
    UIFormStringInput userTitle =
        new UIFormStringInput(FIELD_USERTITLE_INPUT, FIELD_USERTITLE_INPUT, null);
    String title = this.editUserProfile.getUserTitle();
    boolean isAdmin = false;
    UICheckBoxInput userRole =
        new UICheckBoxInput(FIELD_USERROLE_CHECKBOX, FIELD_USERROLE_CHECKBOX, false);
    if (this.editUserProfile.getUserRole() == 0) isAdmin = true;
    if (isAdmin(this.editUserProfile.getUserId())) {
      userRole.setDisabled(true);
      isAdmin = true;
      if (this.editUserProfile.getUserRole() != 0) title = Utils.ADMIN;
    }
    userRole.setValue(isAdmin);
    userTitle.setValue(CommonUtils.decodeSpecialCharToHTMLnumber(title));

    UIFormTextAreaInput signature =
        new UIFormTextAreaInput(FIELD_SIGNATURE_TEXTAREA, FIELD_SIGNATURE_TEXTAREA, null);
    signature.setValue(CommonUtils.decodeSpecialCharToHTMLnumber(editUserProfile.getSignature()));
    UICheckBoxInput isDisplaySignature =
        new UICheckBoxInput(
            FIELD_ISDISPLAYSIGNATURE_CHECKBOX, FIELD_ISDISPLAYSIGNATURE_CHECKBOX, false);
    isDisplaySignature.setChecked(this.editUserProfile.getIsDisplaySignature());

    UIFormTextAreaInput moderateForums =
        new UIFormTextAreaInput(
            FIELD_MODERATEFORUMS_MULTIVALUE, FIELD_MODERATEFORUMS_MULTIVALUE, null);
    List<String> values = Arrays.asList(editUserProfile.getModerateForums());
    this.listModerate = new ArrayList<String>(values);
    moderateForums.setValue(stringForumProcess(values));
    moderateForums.setReadOnly(true);

    UIFormTextAreaInput moderateCategorys =
        new UIFormTextAreaInput(
            FIELD_MODERATECATEGORYS_MULTIVALUE, FIELD_MODERATECATEGORYS_MULTIVALUE, null);
    List<String> valuesCate = Arrays.asList(editUserProfile.getModerateCategory());
    this.listModCate = new ArrayList<String>(valuesCate);
    moderateCategorys.setValue(stringCategoryProcess(valuesCate));
    moderateCategorys.setReadOnly(true);

    UIAvatarContainer avatarContainer = createUIComponent(UIAvatarContainer.class, null, "Avatar");
    avatarContainer.setUserProfile(this.editUserProfile);
    avatarContainer.setForumService(getForumService());
    UICheckBoxInput isDisplayAvatar =
        new UICheckBoxInput(FIELD_ISDISPLAYAVATAR_CHECKBOX, FIELD_ISDISPLAYAVATAR_CHECKBOX, false);
    isDisplayAvatar.setChecked(this.editUserProfile.getIsDisplayAvatar());
    // Option
    String[] timeZone1 = getLabel(FIELD_TIMEZONE).split(ForumUtils.SLASH);
    list = new ArrayList<SelectItemOption<String>>();
    for (String string : timeZone1) {
      list.add(new SelectItemOption<String>(string, ForumUtils.getTimeZoneNumberInString(string)));
    }
    UIFormSelectBox timeZone =
        new UIFormSelectBox(FIELD_TIMEZONE_SELECTBOX, FIELD_TIMEZONE_SELECTBOX, list);
    double timeZoneOld = -editUserProfile.getTimeZone();
    Date date = getNewDate(timeZoneOld);
    String mark = "-";
    if (timeZoneOld < 0) {
      timeZoneOld = -timeZoneOld;
    } else if (timeZoneOld > 0) {
      mark = "+";
    } else {
      timeZoneOld = 0.0;
      mark = ForumUtils.EMPTY_STR;
    }
    timeZone.setValue(mark + timeZoneOld + "0");

    list = new ArrayList<SelectItemOption<String>>();
    String[] format =
        new String[] {
          "M-d-yyyy",
          "M-d-yy",
          "MM-dd-yy",
          "MM-dd-yyyy",
          "yyyy-MM-dd",
          "yy-MM-dd",
          "dd-MM-yyyy",
          "dd-MM-yy",
          "M/d/yyyy",
          "M/d/yy",
          "MM/dd/yy",
          "MM/dd/yyyy",
          "yyyy/MM/dd",
          "yy/MM/dd",
          "dd/MM/yyyy",
          "dd/MM/yy"
        };
    for (String frm : format) {
      list.add(
          new SelectItemOption<String>(
              (frm.toLowerCase() + " (" + TimeConvertUtils.getFormatDate(frm, date) + ")"), frm));
    }
    UIFormSelectBox shortdateFormat =
        new UIFormSelectBox(FIELD_SHORTDATEFORMAT_SELECTBOX, FIELD_SHORTDATEFORMAT_SELECTBOX, list);
    shortdateFormat.setValue(editUserProfile.getShortDateFormat());
    list = new ArrayList<SelectItemOption<String>>();
    format =
        new String[] {
          "EEE, MMMM dd, yyyy",
          "EEEE, MMMM dd, yyyy",
          "EEEE, dd MMMM, yyyy",
          "EEE, MMM dd, yyyy",
          "EEEE, MMM dd, yyyy",
          "EEEE, dd MMM, yyyy",
          "MMMM dd, yyyy",
          "dd MMMM, yyyy",
          "MMM dd, yyyy",
          "dd MMM, yyyy"
        };
    for (String idFrm : format) {
      list.add(
          new SelectItemOption<String>(
              (idFrm.toLowerCase() + " (" + TimeConvertUtils.getFormatDate(idFrm, date) + ")"),
              idFrm.replaceFirst(" ", "=")));
    }
    UIFormSelectBox longDateFormat =
        new UIFormSelectBox(FIELD_LONGDATEFORMAT_SELECTBOX, FIELD_LONGDATEFORMAT_SELECTBOX, list);
    longDateFormat.setValue(editUserProfile.getLongDateFormat().replaceFirst(" ", "="));
    list = new ArrayList<SelectItemOption<String>>();
    list.add(new SelectItemOption<String>("12-hour", "hh:mm=a"));
    list.add(new SelectItemOption<String>("24-hour", "HH:mm"));
    UIFormSelectBox timeFormat =
        new UIFormSelectBox(FIELD_TIMEFORMAT_SELECTBOX, FIELD_TIMEFORMAT_SELECTBOX, list);
    timeFormat.setValue(editUserProfile.getTimeFormat().replace(' ', '='));
    list = new ArrayList<SelectItemOption<String>>();
    for (int i = 5; i <= 45; i = i + 5) {
      list.add(new SelectItemOption<String>(String.valueOf(i), ("id" + i)));
    }
    UIFormSelectBox maximumThreads =
        new UIFormSelectBox(FIELD_MAXTOPICS_SELECTBOX, FIELD_MAXTOPICS_SELECTBOX, list);
    maximumThreads.setValue("id" + editUserProfile.getMaxTopicInPage());
    list = new ArrayList<SelectItemOption<String>>();
    for (int i = 5; i <= 35; i = i + 5) {
      list.add(new SelectItemOption<String>(String.valueOf(i), ("id" + i)));
    }
    UIFormSelectBox maximumPosts =
        new UIFormSelectBox(FIELD_MAXPOSTS_SELECTBOX, FIELD_MAXPOSTS_SELECTBOX, list);
    maximumPosts.setValue("id" + editUserProfile.getMaxPostInPage());
    // Ban
    UICheckBoxInput isBanned =
        new UICheckBoxInput(FIELD_ISBANNED_CHECKBOX, FIELD_ISBANNED_CHECKBOX, false);
    boolean isBan = editUserProfile.getIsBanned();
    isBanned.setChecked(isBan);
    list = new ArrayList<SelectItemOption<String>>();
    String dv = "Day";
    int i = 1;
    long oneDate = 86400000, until = 0;
    Calendar cal = CommonUtils.getGreenwichMeanTime();
    if (isBan) {
      until = editUserProfile.getBanUntil();
      cal.setTimeInMillis(until);
      list.add(
          new SelectItemOption<String>(
              getLabel("Banned until: ")
                  + TimeConvertUtils.getFormatDate(
                      editUserProfile.getShortDateFormat() + " hh:mm a", cal.getTime())
                  + " GMT+0",
              ("Until_" + until)));
    }
    while (true) {
      if (i == 2 && dv.equals("Day")) {
        dv = "Days";
      }
      if (i == 8 && dv.equals("Days")) i = 10;
      if (i == 11) {
        i = 2;
        dv = "Weeks";
      }
      if (i == 4 && dv.equals("Weeks")) {
        i = 1;
        dv = "Month";
      }
      if (i == 2 && dv.equals("Month")) {
        dv = "Months";
      }
      if (i == 7 && dv.equals("Months")) {
        i = 1;
        dv = "Year";
      }
      if (i == 2 && dv.equals("Year")) {
        dv = "Years";
      }
      if (i == 4 && dv.equals("Years")) {
        break;
      }
      if (dv.equals("Days") || dv.equals("Day")) {
        cal = CommonUtils.getGreenwichMeanTime();
        until = cal.getTimeInMillis() + i * oneDate;
        cal.setTimeInMillis(until);
      }
      if (dv.equals("Weeks")) {
        cal = CommonUtils.getGreenwichMeanTime();
        until = cal.getTimeInMillis() + i * oneDate * 7;
        cal.setTimeInMillis(until);
      }
      if (dv.equals("Month") || dv.equals("Months")) {
        cal = CommonUtils.getGreenwichMeanTime();
        cal.setLenient(true);
        int t = cal.get(Calendar.MONTH) + i;
        if (t >= 12) {
          cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);
          t -= 12;
        }
        cal.set(Calendar.MONTH, t);
        until = cal.getTimeInMillis();
      }
      if (dv.equals("Years") || dv.equals("Year")) {
        cal = CommonUtils.getGreenwichMeanTime();
        cal.setLenient(true);
        cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + i);
        until = cal.getTimeInMillis();
      }
      list.add(
          new SelectItemOption<String>(
              i
                  + " "
                  + getLabel(dv)
                  + " ("
                  + TimeConvertUtils.getFormatDate(
                      editUserProfile.getShortDateFormat() + " hh:mm a", cal.getTime())
                  + " GMT+0)",
              ("Until_" + until)));
      ++i;
    }
    UIFormSelectBox banUntil =
        new UIFormSelectBox(FIELD_BANUNTIL_SELECTBOX, FIELD_BANUNTIL_SELECTBOX, list);
    if (isBan) {
      banUntil.setValue("Until_" + editUserProfile.getBanUntil());
    }
    UIFormTextAreaInput banReason =
        new UIFormTextAreaInput(FIELD_BANREASON_TEXTAREA, FIELD_BANREASON_TEXTAREA, null);
    UIFormStringInput banCounter =
        new UIFormStringInput(FIELD_BANCOUNTER_INPUT, FIELD_BANCOUNTER_INPUT, null);
    banCounter.setValue(editUserProfile.getBanCounter() + ForumUtils.EMPTY_STR);
    UIFormTextAreaInput banReasonSummary =
        new UIFormTextAreaInput(
            FIELD_BANREASONSUMMARY_MULTIVALUE, FIELD_BANREASONSUMMARY_MULTIVALUE, null);
    banReasonSummary.setValue(ForumUtils.unSplitForForum(editUserProfile.getBanReasonSummary()));
    banReasonSummary.setReadOnly(true);
    UIFormStringInput createdDateBan =
        new UIFormStringInput(FIELD_CREATEDDATEBAN_INPUT, FIELD_CREATEDDATEBAN_INPUT, null);
    if (isBan) {
      banReason.setValue(editUserProfile.getBanReason());
      createdDateBan.setValue(
          TimeConvertUtils.getFormatDate(
              "MM/dd/yyyy, hh:mm a", editUserProfile.getCreatedDateBan()));
    } else {
      banReason.setDisabled(false);
    }
    UIFormInputWithActions inputSetProfile = new UIFormInputWithActions(FIELD_USERPROFILE_FORM);
    inputSetProfile.addUIFormInput(userId);
    inputSetProfile.addUIFormInput(screenName);
    inputSetProfile.addUIFormInput(userTitle);
    inputSetProfile.addUIFormInput(userRole);
    inputSetProfile.addUIFormInput(moderateCategorys);
    inputSetProfile.addUIFormInput(moderateForums);
    inputSetProfile.addUIFormInput(signature);
    inputSetProfile.addUIFormInput(isDisplaySignature);

    inputSetProfile.addUIFormInput(avatarContainer);
    inputSetProfile.addUIFormInput(isDisplayAvatar);

    String[] fields =
        new String[] {FIELD_MODERATEFORUMS_MULTIVALUE, FIELD_MODERATECATEGORYS_MULTIVALUE};
    String[] actionNames = new String[] {"AddValuesModForum", "AddValuesModCategory"};
    List<ActionData> actions;
    ActionData actionData;
    for (int j = 0; j < fields.length; j++) {
      String string = fields[j];
      actionData = new ActionData();
      actionData.setActionListener(actionNames[j]);
      actionData.setActionParameter(string);
      actionData.setCssIconClass("uiIconAddIcon uiIconLightGray");
      actionData.setActionName(string);
      actions = new ArrayList<ActionData>();
      actions.add(actionData);
      inputSetProfile.setActionField(string, actions);
    }
    //
    addUIFormInput(inputSetProfile);

    UIFormInputWithActions inputSetOption = new UIFormInputWithActions(FIELD_USEROPTION_FORM);
    inputSetOption.addUIFormInput(timeZone);
    inputSetOption.addUIFormInput(shortdateFormat);
    inputSetOption.addUIFormInput(longDateFormat);
    inputSetOption.addUIFormInput(timeFormat);
    inputSetOption.addUIFormInput(maximumThreads);
    inputSetOption.addUIFormInput(maximumPosts);
    addUIFormInput(inputSetOption);

    UIFormInputWithActions inputSetBan = new UIFormInputWithActions(FIELD_USERBAN_FORM);
    inputSetBan.addUIFormInput(isBanned);
    inputSetBan.addUIFormInput(banUntil);
    inputSetBan.addUIFormInput(banReason);
    inputSetBan.addUIFormInput(banCounter);
    inputSetBan.addUIFormInput(banReasonSummary);
    inputSetBan.addUIFormInput(createdDateBan);
    //
    addUIFormInput(inputSetBan);

    UIPageListTopicByUser pageListTopicByUser = addChild(UIPageListTopicByUser.class, null, null);
    pageListTopicByUser.setUserName(this.editUserProfile.getUserId());
    UIPageListPostByUser listPostByUser = addChild(UIPageListPostByUser.class, null, null);
    listPostByUser.setUserName(this.editUserProfile.getUserId());
  }
コード例 #10
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();
      }
    }