Search in sources :

Example 56 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class TaskTemplateAdminController method delete.

/**
 * @param path
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(String path, HttpServletRequest request, HttpSession session, ModelMap model) {
    if (CommonUtils.notEmpty(path)) {
        SysSite site = getSite(request);
        String filePath = siteComponent.getTaskTemplateFilePath(site, path);
        if (ControllerUtils.verifyCustom("notExist.template", !fileComponent.deleteFile(filePath), model)) {
            return TEMPLATE_ERROR;
        }
        templateComponent.clearTaskTemplateCache();
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.task.template", RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class UeditorAdminController method catchimage.

/**
 * @param request
 * @param session
 * @return view name
 */
@RequestMapping(params = "action=" + ACTION_CATCHIMAGE)
@ResponseBody
public Map<String, Object> catchimage(HttpServletRequest request, HttpSession session) {
    SysSite site = getSite(request);
    try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
        String[] files = request.getParameterValues(FIELD_NAME + "[]");
        if (CommonUtils.notEmpty(files)) {
            List<Map<String, Object>> list = new ArrayList<>();
            for (String image : files) {
                HttpGet httpget = new HttpGet(image);
                CloseableHttpResponse response = httpclient.execute(httpget);
                HttpEntity entity = response.getEntity();
                if (null != entity) {
                    String suffix = null;
                    if (CommonUtils.notEmpty(entity.getContentType().getElements())) {
                        suffix = CONTENT_TYPE_MAP.get(entity.getContentType().getElements()[0].getName());
                    }
                    if (CommonUtils.empty(suffix)) {
                        suffix = ".jpg";
                    }
                    String fileName = fileComponent.getUploadFileName(suffix);
                    File dest = new File(siteComponent.getWebFilePath(site, fileName));
                    FileUtils.copyInputStreamToFile(entity.getContent(), dest);
                    logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, true, dest.length(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
                    Map<String, Object> map = getResultMap(true);
                    map.put("size", entity.getContentLength());
                    map.put("title", dest.getName());
                    map.put("url", fileName);
                    map.put("source", image);
                    list.add(map);
                }
                EntityUtils.consume(entity);
            }
            Map<String, Object> map = getResultMap(true);
            map.put("list", list);
            return map;
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return getResultMap(false);
    }
    return getResultMap(false);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) LogUpload(com.publiccms.entities.log.LogUpload) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 58 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class UeditorAdminController method upload.

/**
 * @param file
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(params = "action=" + ACTION_UPLOAD)
public String upload(MultipartFile file, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != file && !file.isEmpty()) {
        String originalName = file.getOriginalFilename();
        String suffix = fileComponent.getSuffix(originalName);
        String fileName = fileComponent.getUploadFileName(suffix);
        try {
            fileComponent.upload(file, siteComponent.getWebFilePath(site, fileName));
            logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, false, file.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
            Map<String, Object> map = getResultMap(true);
            map.put("size", file.getSize());
            map.put("title", originalName);
            map.put("url", fileName);
            map.put("type", suffix);
            map.put("original", originalName);
            model.addAttribute("result", map);
        } catch (IllegalStateException | IOException e) {
            model.addAttribute("result", getResultMap(false));
        }
    } else {
        model.addAttribute("result", getResultMap(false));
    }
    return "common/mapResult";
}
Also used : LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 59 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class ContentController method save.

/**
 * 保存内容
 *
 * @param entity
 * @param attribute
 * @param contentParamters
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    SysUser user = getUserFromSession(session);
    CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
    if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model) || ControllerUtils.verifyCustom("contribute", null == user, model)) {
        return REDIRECT + returnUrl;
    }
    CmsCategory category = categoryService.getEntity(entity.getCategoryId());
    if (null != category && (site.getId() != category.getSiteId() || !category.isAllowContribute())) {
        category = null;
    }
    CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
    if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
        return REDIRECT + returnUrl;
    }
    entity.setHasFiles(cmsModel.isHasFiles());
    entity.setHasImages(cmsModel.isHasImages());
    entity.setOnlyUrl(cmsModel.isOnlyUrl());
    entity.setStatus(CmsContentService.STATUS_PEND);
    if (null != entity.getId()) {
        CmsContent oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return REDIRECT + returnUrl;
        }
        entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
        if (null != entity.getId()) {
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        entity.setSiteId(site.getId());
        entity.setUserId(user.getId());
        service.save(entity);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            service.updateChilds(entity.getParentId(), 1);
        }
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "save.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    if (entity.isHasImages() || entity.isHasFiles()) {
        contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
        entity.isHasImages() ? contentParamters.getImages() : null);
    }
    if (null != attribute.getText()) {
        attribute.setWordCount(HtmlUtils.removeHtmlTag(attribute.getText()).length());
    }
    List<ExtendField> modelExtendList = cmsModel.getExtendList();
    Map<String, String> map = ExtendUtils.getExtentDataMap(contentParamters.getModelExtendDataList(), modelExtendList);
    if (null != category && null != extendService.getEntity(category.getExtendId())) {
        List<SysExtendField> categoryExtendList = extendFieldService.getList(category.getExtendId());
        Map<String, String> categoryMap = ExtendUtils.getSysExtentDataMap(contentParamters.getCategoryExtendDataList(), categoryExtendList);
        if (CommonUtils.notEmpty(map)) {
            map.putAll(categoryMap);
        } else {
            map = categoryMap;
        }
    }
    if (CommonUtils.notEmpty(map)) {
        attribute.setData(ExtendUtils.getExtendString(map));
    } else {
        attribute.setData(null);
    }
    // 更新保存扩展字段,文本字段
    attributeService.updateAttribute(entity.getId(), attribute);
    return REDIRECT + returnUrl;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) CmsModel(com.publiccms.views.pojo.entities.CmsModel) SysExtendField(com.publiccms.entities.sys.SysExtendField) ExtendField(com.publiccms.views.pojo.entities.ExtendField) CmsCategoryModelId(com.publiccms.entities.cms.CmsCategoryModelId) CmsCategoryModel(com.publiccms.entities.cms.CmsCategoryModel) SysSite(com.publiccms.entities.sys.SysSite) SysExtendField(com.publiccms.entities.sys.SysExtendField) CmsCategory(com.publiccms.entities.cms.CmsCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 60 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class ContentController method contentRedirect.

/**
 * 内容链接重定向并计数
 *
 * @param id
 * @param request
 * @param response
 * @return view name
 */
@RequestMapping("redirect")
public String contentRedirect(Long id, HttpServletRequest request, HttpServletResponse response) {
    CmsContentStatistics contentStatistics = statisticsComponent.clicks(id);
    SysSite site = getSite(request);
    if (null != contentStatistics && null != contentStatistics.getEntity() && site.getId() == contentStatistics.getEntity().getSiteId()) {
        return REDIRECT + contentStatistics.getEntity().getUrl();
    } else {
        return REDIRECT + site.getDynamicPath();
    }
}
Also used : CmsContentStatistics(com.publiccms.views.pojo.entities.CmsContentStatistics) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysSite (com.publiccms.entities.sys.SysSite)175 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)135 LogOperate (com.publiccms.entities.log.LogOperate)117 IOException (java.io.IOException)33 SysUser (com.publiccms.entities.sys.SysUser)21 LinkedHashMap (java.util.LinkedHashMap)19 TemplateException (freemarker.template.TemplateException)15 File (java.io.File)14 CmsContent (com.publiccms.entities.cms.CmsContent)12 CmsCategory (com.publiccms.entities.cms.CmsCategory)11 MultipartFile (org.springframework.web.multipart.MultipartFile)10 SysTask (com.publiccms.entities.sys.SysTask)9 HashMap (java.util.HashMap)8 LogUpload (com.publiccms.entities.log.LogUpload)7 SysDept (com.publiccms.entities.sys.SysDept)7 SysUserToken (com.publiccms.entities.sys.SysUserToken)7 CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)7 CmsPageMetadata (com.publiccms.views.pojo.entities.CmsPageMetadata)6 CmsPlace (com.publiccms.entities.cms.CmsPlace)5 SysDomain (com.publiccms.entities.sys.SysDomain)5