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;
}
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);
}
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";
}
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;
}
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();
}
}
Aggregations