コード例 #1
0
  protected void deleteImages(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] deleteFileEntryIds = null;

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    if (fileEntryId > 0) {
      deleteFileEntryIds = new long[] {fileEntryId};
    } else {
      deleteFileEntryIds =
          StringUtil.split(ParamUtil.getString(actionRequest, "deleteFileEntryIds"), 0L);
    }

    Folder folder =
        _blogsEntryLocalService.addAttachmentsFolder(
            themeDisplay.getUserId(), themeDisplay.getScopeGroupId());

    for (long deleteFileEntryId : deleteFileEntryIds) {
      FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(deleteFileEntryId);

      if (fileEntry.getFolderId() != folder.getFolderId()) {
        continue;
      }

      if ((fileEntry.getUserId() == themeDisplay.getUserId())
          || BlogsPermission.contains(
              themeDisplay.getPermissionChecker(),
              themeDisplay.getScopeGroupId(),
              ActionKeys.UPDATE)) {

        PortletFileRepositoryUtil.deletePortletFileEntry(deleteFileEntryId);
      }
    }
  }
コード例 #2
0
  protected Tuple getNewScope(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    long scopeGroupId = 0;
    String scopeName = null;

    if (Validator.isNull(scopeType)) {
      scopeGroupId = layout.getGroupId();
    } else if (scopeType.equals("company")) {
      scopeGroupId = themeDisplay.getCompanyGroupId();
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid = scopes[1];

      Layout scopeLayout =
          _layoutLocalService.getLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (!scopeLayout.hasScopeGroup()) {
        Map<Locale, String> nameMap = new HashMap<>();

        String name = String.valueOf(scopeLayout.getPlid());

        nameMap.put(LocaleUtil.getDefault(), name);

        _groupLocalService.addGroup(
            themeDisplay.getUserId(),
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            Layout.class.getName(),
            scopeLayout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            nameMap,
            null,
            0,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            null,
            false,
            true,
            null);
      }

      scopeGroupId = scopeLayout.getGroupId();
      scopeName = scopeLayout.getName(themeDisplay.getLocale());
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return new Tuple(scopeGroupId, scopeName);
  }
コード例 #3
0
  public Long getUserId() {
    if (_userId != null) {
      return _userId;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _userId = themeDisplay.getUserId();

    return _userId;
  }
コード例 #4
0
  public void markNotSpamMBMessages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] mbMessageIds = ParamUtil.getLongValues(actionRequest, "notSpamMBMessageIds");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    for (long mbMessageId : mbMessageIds) {
      MBMessage mbMessage =
          MBMessageLocalServiceUtil.updateStatus(
              themeDisplay.getUserId(),
              mbMessageId,
              WorkflowConstants.STATUS_APPROVED,
              serviceContext);

      if (AkismetUtil.isMessageBoardsEnabled(mbMessage.getCompanyId())) {
        AkismetUtil.submitHam(mbMessage);
      }
    }
  }
コード例 #5
0
  public AssetEntry incrementViewCounter(AssetEntry assetEntry) throws PortalException {

    // Dynamically created asset entries are never persisted so incrementing
    // the view counter breaks

    if ((assetEntry == null)
        || assetEntry.isNew()
        || !assetEntry.isVisible()
        || !isEnableViewCountIncrement()) {

      return assetEntry;
    }

    if (isEnablePermissions()) {
      return AssetEntryServiceUtil.incrementViewCounter(
          assetEntry.getClassName(), assetEntry.getClassPK());
    } else {
      ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

      return AssetEntryLocalServiceUtil.incrementViewCounter(
          themeDisplay.getUserId(), assetEntry.getClassName(), assetEntry.getClassPK());
    }
  }
  /**
   * Returns an export layout settings map if the type is {@link
   * ExportImportConfigurationConstants#TYPE_EXPORT_LAYOUT}; otherwise, returns either a local or
   * remote publish layout settings map, depending on the staging type.
   *
   * @param portletRequest the portlet request
   * @param groupId the primary key of the group
   * @param type the export/import option type
   * @return an export layout settings map if the type is an export layout; otherwise, returns
   *     either a local or remote publish layout settings map, depending on the staging type
   */
  public static Map<String, Serializable> buildSettingsMap(
      PortletRequest portletRequest, long groupId, int type) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean privateLayout = ParamUtil.getBoolean(portletRequest, "privateLayout");

    Map<Long, Boolean> layoutIdMap = ExportImportHelperUtil.getLayoutIdMap(portletRequest);

    if (type == ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT) {
      long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layoutIdMap);

      return buildExportLayoutSettingsMap(
          themeDisplay.getUserId(),
          groupId,
          privateLayout,
          layoutIds,
          portletRequest.getParameterMap(),
          themeDisplay.getLocale(),
          themeDisplay.getTimeZone());
    }

    Group stagingGroup = GroupLocalServiceUtil.getGroup(groupId);

    Group liveGroup = stagingGroup.getLiveGroup();

    Map<String, String[]> parameterMap =
        ExportImportConfigurationParameterMapFactory.buildParameterMap(portletRequest);

    if (liveGroup != null) {
      long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layoutIdMap, liveGroup.getGroupId());

      return buildPublishLayoutLocalSettingsMap(
          themeDisplay.getUserId(),
          stagingGroup.getGroupId(),
          liveGroup.getGroupId(),
          privateLayout,
          layoutIds,
          parameterMap,
          themeDisplay.getLocale(),
          themeDisplay.getTimeZone());
    }

    UnicodeProperties groupTypeSettingsProperties = stagingGroup.getTypeSettingsProperties();

    String remoteAddress =
        ParamUtil.getString(
            portletRequest,
            "remoteAddress",
            groupTypeSettingsProperties.getProperty("remoteAddress"));

    remoteAddress = StagingUtil.stripProtocolFromRemoteAddress(remoteAddress);

    int remotePort =
        ParamUtil.getInteger(
            portletRequest,
            "remotePort",
            GetterUtil.getInteger(groupTypeSettingsProperties.getProperty("remotePort")));
    String remotePathContext =
        ParamUtil.getString(
            portletRequest,
            "remotePathContext",
            groupTypeSettingsProperties.getProperty("remotePathContext"));
    boolean secureConnection =
        ParamUtil.getBoolean(
            portletRequest,
            "secureConnection",
            GetterUtil.getBoolean(groupTypeSettingsProperties.getProperty("secureConnection")));
    long remoteGroupId =
        ParamUtil.getLong(
            portletRequest,
            "remoteGroupId",
            GetterUtil.getLong(groupTypeSettingsProperties.getProperty("remoteGroupId")));
    boolean remotePrivateLayout = ParamUtil.getBoolean(portletRequest, "remotePrivateLayout");

    StagingUtil.validateRemote(
        groupId, remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId);

    return buildPublishLayoutRemoteSettingsMap(
        themeDisplay.getUserId(),
        groupId,
        privateLayout,
        layoutIdMap,
        parameterMap,
        remoteAddress,
        remotePort,
        remotePathContext,
        secureConnection,
        remoteGroupId,
        remotePrivateLayout,
        themeDisplay.getLocale(),
        themeDisplay.getTimeZone());
  }
コード例 #7
0
  public ArticleSearch getSearchContainer() throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    ArticleSearch articleSearchContainer =
        new ArticleSearch(_liferayPortletRequest, getPortletURL());

    OrderByComparator<JournalArticle> orderByComparator =
        JournalPortletUtil.getArticleOrderByComparator(getOrderByCol(), getOrderByType());

    articleSearchContainer.setOrderByCol(getOrderByCol());
    articleSearchContainer.setOrderByComparator(orderByComparator);
    articleSearchContainer.setOrderByType(getOrderByType());

    EntriesChecker entriesChecker =
        new EntriesChecker(_liferayPortletRequest, _liferayPortletResponse);

    entriesChecker.setCssClass("entry-selector");

    articleSearchContainer.setRowChecker(entriesChecker);

    EntriesMover entriesMover = new EntriesMover(themeDisplay.getScopeGroupId());

    articleSearchContainer.setRowMover(entriesMover);

    if (isNavigationMine() || isNavigationRecent()) {
      boolean includeOwner = true;

      if (isNavigationMine()) {
        includeOwner = false;
      }

      if (isNavigationRecent()) {
        articleSearchContainer.setOrderByCol("create-date");
        articleSearchContainer.setOrderByType(getOrderByType());
      }

      int total =
          JournalArticleServiceUtil.getGroupArticlesCount(
              themeDisplay.getScopeGroupId(),
              themeDisplay.getUserId(),
              getFolderId(),
              getStatus(),
              includeOwner);

      articleSearchContainer.setTotal(total);

      List results =
          JournalArticleServiceUtil.getGroupArticles(
              themeDisplay.getScopeGroupId(),
              themeDisplay.getUserId(),
              getFolderId(),
              getStatus(),
              includeOwner,
              articleSearchContainer.getStart(),
              articleSearchContainer.getEnd(),
              articleSearchContainer.getOrderByComparator());

      articleSearchContainer.setResults(results);
    } else if (Validator.isNotNull(getDDMStructureKey())) {
      int total =
          JournalArticleServiceUtil.getArticlesCountByStructureId(
              themeDisplay.getScopeGroupId(), getDDMStructureKey(), getStatus());

      articleSearchContainer.setTotal(total);

      List results =
          JournalArticleServiceUtil.getArticlesByStructureId(
              themeDisplay.getScopeGroupId(),
              getDDMStructureKey(),
              getStatus(),
              articleSearchContainer.getStart(),
              articleSearchContainer.getEnd(),
              articleSearchContainer.getOrderByComparator());

      articleSearchContainer.setResults(results);
    } else if (Validator.isNotNull(getDDMTemplateKey())) {
      List<Long> folderIds = new ArrayList<>(1);

      if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        folderIds.add(getFolderId());
      }

      int total =
          JournalArticleServiceUtil.searchCount(
              themeDisplay.getCompanyId(),
              themeDisplay.getScopeGroupId(),
              folderIds,
              JournalArticleConstants.CLASSNAME_ID_DEFAULT,
              getKeywords(),
              -1.0,
              getDDMStructureKey(),
              getDDMTemplateKey(),
              null,
              null,
              getStatus(),
              null);

      articleSearchContainer.setTotal(total);

      List results =
          JournalArticleServiceUtil.search(
              themeDisplay.getCompanyId(),
              themeDisplay.getScopeGroupId(),
              folderIds,
              JournalArticleConstants.CLASSNAME_ID_DEFAULT,
              getKeywords(),
              -1.0,
              getDDMStructureKey(),
              getDDMTemplateKey(),
              null,
              null,
              getStatus(),
              null,
              articleSearchContainer.getStart(),
              articleSearchContainer.getEnd(),
              articleSearchContainer.getOrderByComparator());

      articleSearchContainer.setResults(results);
    } else if (isSearch()) {
      List<Long> folderIds = new ArrayList<>(1);

      if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        folderIds.add(getFolderId());
      }

      JournalWebConfiguration journalWebConfiguration =
          (JournalWebConfiguration) _request.getAttribute(JournalWebConfiguration.class.getName());

      if (journalWebConfiguration.journalArticlesSearchWithIndex()) {
        boolean orderByAsc = false;

        if (Validator.equals(getOrderByType(), "asc")) {
          orderByAsc = true;
        }

        Sort sort = null;

        if (Validator.equals(getOrderByCol(), "display-date")) {
          sort = new Sort("displayDate", Sort.LONG_TYPE, orderByAsc);
        } else if (Validator.equals(getOrderByCol(), "modified-date")) {
          sort = new Sort(Field.MODIFIED_DATE, Sort.LONG_TYPE, orderByAsc);
        }

        LinkedHashMap<String, Object> params = new LinkedHashMap<>();

        params.put("expandoAttributes", getKeywords());

        BaseModelSearchResult<JournalArticle> baseModelSearchResult =
            JournalArticleLocalServiceUtil.searchJournalArticles(
                themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(),
                folderIds,
                JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getDDMStructureKey(),
                getDDMTemplateKey(),
                getKeywords(),
                params,
                articleSearchContainer.getStart(),
                articleSearchContainer.getEnd(),
                sort);

        int total = baseModelSearchResult.getLength();

        articleSearchContainer.setTotal(total);

        List results = baseModelSearchResult.getBaseModels();

        articleSearchContainer.setResults(results);
      } else {
        int total =
            JournalArticleServiceUtil.searchCount(
                themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(),
                folderIds,
                JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getKeywords(),
                -1.0,
                getDDMStructureKey(),
                getDDMTemplateKey(),
                null,
                null,
                getStatus(),
                null);

        articleSearchContainer.setTotal(total);

        List results =
            JournalArticleServiceUtil.search(
                themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(),
                folderIds,
                JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getKeywords(),
                -1.0,
                getDDMStructureKey(),
                getDDMTemplateKey(),
                null,
                null,
                getStatus(),
                null,
                articleSearchContainer.getStart(),
                articleSearchContainer.getEnd(),
                articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
      }
    } else {
      int total =
          JournalFolderServiceUtil.getFoldersAndArticlesCount(
              themeDisplay.getScopeGroupId(), 0, getFolderId(), getStatus());

      articleSearchContainer.setTotal(total);

      OrderByComparator<Object> folderOrderByComparator = null;

      boolean orderByAsc = false;

      if (Validator.equals(getOrderByType(), "asc")) {
        orderByAsc = true;
      }

      if (Validator.equals(getOrderByCol(), "display-date")) {
        folderOrderByComparator = new FolderArticleDisplayDateComparator(orderByAsc);
      } else if (Validator.equals(getOrderByCol(), "modified-date")) {
        folderOrderByComparator = new FolderArticleModifiedDateComparator(orderByAsc);
      }

      List results =
          JournalFolderServiceUtil.getFoldersAndArticles(
              themeDisplay.getScopeGroupId(),
              0,
              getFolderId(),
              getStatus(),
              articleSearchContainer.getStart(),
              articleSearchContainer.getEnd(),
              folderOrderByComparator);

      articleSearchContainer.setResults(results);
    }

    return articleSearchContainer;
  }
コード例 #8
0
  @Override
  public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {

    try {

      // Do not randomize look and feel unless the user is logged in

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      if (!themeDisplay.isSignedIn()) {
        return;
      }

      // Do not randomize look and feel unless the user is accessing the
      // portal

      String requestURI = GetterUtil.getString(request.getRequestURI());

      if (!requestURI.endsWith("/portal/layout")) {
        return;
      }

      // Do not randomize look and feel unless the user is accessing a
      // personal layout

      Layout layout = themeDisplay.getLayout();

      if (layout == null) {
        return;
      }

      boolean wapTheme = BrowserSnifferUtil.isWap(request);

      List<Theme> themes =
          ThemeLocalServiceUtil.getPageThemes(
              themeDisplay.getCompanyId(),
              themeDisplay.getScopeGroupId(),
              themeDisplay.getUserId(),
              wapTheme);

      if (!themes.isEmpty()) {
        Theme theme = themes.get(RandomUtil.nextInt(themes.size()));

        List<ColorScheme> colorSchemes = theme.getColorSchemes();

        ColorScheme colorScheme = colorSchemes.get(RandomUtil.nextInt(colorSchemes.size()));

        LayoutServiceUtil.updateLookAndFeel(
            layout.getGroupId(),
            layout.isPrivateLayout(),
            layout.getPlid(),
            theme.getThemeId(),
            colorScheme.getColorSchemeId(),
            layout.getCss(),
            wapTheme);

        themeDisplay.setLookAndFeel(theme, colorScheme);

        request.setAttribute(WebKeys.THEME, theme);
        request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
      }
    } catch (Exception e) {
      _log.error(e, e);

      throw new ActionException(e);
    }
  }
コード例 #9
0
  public void editLayout(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");
    boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");

    byte[] iconBytes = null;

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    if (fileEntryId > 0) {
      FileEntry fileEntry = dlAppLocalService.getFileEntry(fileEntryId);

      iconBytes = FileUtil.getBytes(fileEntry.getContentStream());
    }

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = layoutLocalService.getLayout(groupId, privateLayout, layoutId);

    layout =
        layoutService.updateLayout(
            groupId,
            privateLayout,
            layoutId,
            layout.getParentLayoutId(),
            nameMap,
            titleMap,
            descriptionMap,
            keywordsMap,
            robotsMap,
            type,
            hidden,
            friendlyURLMap,
            !deleteLogo,
            iconBytes,
            serviceContext);

    UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties();

    UnicodeProperties formTypeSettingsProperties =
        PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--");

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    if (type.equals(LayoutConstants.TYPE_PORTLET)) {
      String layoutTemplateId =
          ParamUtil.getString(
              uploadPortletRequest, "layoutTemplateId", PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

      layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

      layoutTypeSettingsProperties.putAll(formTypeSettingsProperties);

      layoutService.updateLayout(
          groupId, privateLayout, layoutId, layoutTypeSettingsProperties.toString());
    } else {
      layout.setTypeSettingsProperties(formTypeSettingsProperties);

      layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties());

      layoutService.updateLayout(groupId, privateLayout, layoutId, layout.getTypeSettings());
    }

    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

    EventsProcessorUtil.process(
        PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
        layoutTypePortlet.getConfigurationActionUpdate(),
        uploadPortletRequest,
        response);

    updateLookAndFeel(
        actionRequest,
        themeDisplay.getCompanyId(),
        liveGroupId,
        stagingGroupId,
        privateLayout,
        layout.getLayoutId(),
        layoutTypeSettingsProperties);
  }
コード例 #10
0
  public void addLayout(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long parentLayoutId = ParamUtil.getLong(uploadPortletRequest, "parentLayoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");

    long layoutPrototypeId = ParamUtil.getLong(uploadPortletRequest, "layoutPrototypeId");

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = null;

    boolean inheritFromParentLayoutId =
        ParamUtil.getBoolean(uploadPortletRequest, "inheritFromParentLayoutId");

    UnicodeProperties typeSettingsProperties =
        PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--");

    if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
      Layout parentLayout = layoutLocalService.getLayout(groupId, privateLayout, parentLayoutId);

      layout =
          layoutService.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              nameMap,
              titleMap,
              parentLayout.getDescriptionMap(),
              parentLayout.getKeywordsMap(),
              parentLayout.getRobotsMap(),
              parentLayout.getType(),
              parentLayout.getTypeSettings(),
              hidden,
              friendlyURLMap,
              serviceContext);

      inheritMobileRuleGroups(layout, serviceContext);

      if (parentLayout.isTypePortlet()) {
        ActionUtil.copyPreferences(actionRequest, layout, parentLayout);

        SitesUtil.copyLookAndFeel(layout, parentLayout);
      }
    } else if (layoutPrototypeId > 0) {
      LayoutPrototype layoutPrototype =
          layoutPrototypeService.getLayoutPrototype(layoutPrototypeId);

      boolean layoutPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              uploadPortletRequest, "layoutPrototypeLinkEnabled" + layoutPrototype.getUuid());

      serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

      serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototype.getUuid());

      layout =
          layoutService.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              nameMap,
              titleMap,
              descriptionMap,
              keywordsMap,
              robotsMap,
              LayoutConstants.TYPE_PORTLET,
              typeSettingsProperties.toString(),
              hidden,
              friendlyURLMap,
              serviceContext);

      // Force propagation from page template to page.
      // See LPS-48430.

      SitesUtil.mergeLayoutPrototypeLayout(layout.getGroup(), layout);
    } else {
      long copyLayoutId = ParamUtil.getLong(uploadPortletRequest, "copyLayoutId");

      Layout copyLayout = null;

      String layoutTemplateId =
          ParamUtil.getString(
              uploadPortletRequest, "layoutTemplateId", PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

      if (copyLayoutId > 0) {
        copyLayout = layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

        if ((copyLayout != null) && copyLayout.isTypePortlet()) {
          LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout.getLayoutType();

          layoutTemplateId = copyLayoutTypePortlet.getLayoutTemplateId();

          typeSettingsProperties = copyLayout.getTypeSettingsProperties();
        }
      }

      layout =
          layoutService.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              nameMap,
              titleMap,
              descriptionMap,
              keywordsMap,
              robotsMap,
              type,
              typeSettingsProperties.toString(),
              hidden,
              friendlyURLMap,
              serviceContext);

      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

      layoutService.updateLayout(
          groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings());

      if ((copyLayout != null) && copyLayout.isTypePortlet()) {
        ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

        SitesUtil.copyLookAndFeel(layout, copyLayout);
      }
    }

    updateLookAndFeel(
        actionRequest,
        themeDisplay.getCompanyId(),
        liveGroupId,
        stagingGroupId,
        privateLayout,
        layout.getLayoutId(),
        layout.getTypeSettingsProperties());
  }
コード例 #11
0
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds");

    List<String> wikiPageLinks = new ArrayList<>();

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      WikiPage latestVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), false);

      String latestContent = null;

      if (latestVersionWikiPage != null) {
        latestContent = latestVersionWikiPage.getContent();
      }

      WikiPage previousVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), true);

      String previousContent = null;

      if (previousVersionWikiPage != null) {
        previousContent = previousVersionWikiPage.getContent();
      }

      // Selected version

      wikiPage.setStatus(WorkflowConstants.STATUS_APPROVED);
      wikiPage.setSummary(StringPool.BLANK);

      wikiPage = WikiPageLocalServiceUtil.updateWikiPage(wikiPage);

      // Latest version

      if ((latestContent != null)
          && ((previousContent == null) || latestContent.equals(previousContent))) {

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        WikiPageLocalServiceUtil.revertPage(
            themeDisplay.getUserId(),
            wikiPage.getNodeId(),
            wikiPage.getTitle(),
            wikiPage.getVersion(),
            serviceContext);
      } else {
        StringBundler sb = new StringBundler(5);

        sb.append("<a href=\"");

        long plid = PortalUtil.getPlidFromPortletId(wikiPage.getGroupId(), WikiPortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, WikiPortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE);

        WikiNode wikiNode = wikiPage.getNode();

        liferayPortletURL.setParameter("struts_action", "/wiki/view");
        liferayPortletURL.setParameter("nodeName", wikiNode.getName());
        liferayPortletURL.setParameter("title", wikiPage.getTitle());
        liferayPortletURL.setParameter("version", String.valueOf(wikiPage.getVersion()));

        sb.append(liferayPortletURL.toString());
        sb.append("\" target=\"_blank\">");
        sb.append(HtmlUtil.escape(wikiPage.getTitle()));
        sb.append("</a>");

        wikiPageLinks.add(sb.toString());
      }

      // Akismet

      if (AkismetUtil.isWikiEnabled(wikiPage.getCompanyId())) {
        AkismetUtil.submitHam(wikiPage);
      }
    }

    if (!wikiPageLinks.isEmpty()) {
      SessionMessages.add(
          actionRequest,
          "anotherUserHasMadeChangesToThesePages",
          StringUtil.merge(wikiPageLinks, "<br />"));

      addSuccessMessage(actionRequest, actionResponse);

      super.sendRedirect(actionRequest, actionResponse);
    }
  }