|
@@ -2,9 +2,11 @@ package space.apps.moudules.website.services;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Base64;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
@@ -71,6 +73,7 @@ public class ArticleService extends BaseTransaction {
|
|
|
private static final String PREVIEW_DESC_KEY = "desc";
|
|
private static final String PREVIEW_DESC_KEY = "desc";
|
|
|
private static final String PREVIEW_NAVIGATION_ID_KEY = "navigationid";
|
|
private static final String PREVIEW_NAVIGATION_ID_KEY = "navigationid";
|
|
|
private static final String PREVIEW_WEBSITE_ID_KEY = "websiteid";
|
|
private static final String PREVIEW_WEBSITE_ID_KEY = "websiteid";
|
|
|
|
|
+ private static final String PREVIEW_RELEASE_TIME_KEY = "releaseTime";
|
|
|
private static final Pattern LOCAL_UPLOAD_ABSOLUTE_URL_PATTERN = Pattern.compile(
|
|
private static final Pattern LOCAL_UPLOAD_ABSOLUTE_URL_PATTERN = Pattern.compile(
|
|
|
"(?i)(?:https?:)?//(?:ht\\.gzhxtc\\.edu\\.cn|localhost|127\\.0\\.0\\.1|ffkj-[a-z0-9-]+\\.localhost)(?::\\d+)?(/web/upload/[^\"'<>\\s]*)");
|
|
"(?i)(?:https?:)?//(?:ht\\.gzhxtc\\.edu\\.cn|localhost|127\\.0\\.0\\.1|ffkj-[a-z0-9-]+\\.localhost)(?::\\d+)?(/web/upload/[^\"'<>\\s]*)");
|
|
|
private static final Long NAVIGATION_STYLE_GRAPHIC_LIST = 10010L;
|
|
private static final Long NAVIGATION_STYLE_GRAPHIC_LIST = 10010L;
|
|
@@ -97,6 +100,7 @@ public class ArticleService extends BaseTransaction {
|
|
|
replaceHtmlLink(doc, domain);
|
|
replaceHtmlLink(doc, domain);
|
|
|
|
|
|
|
|
imgSrcConverLazyloadSrc(doc);
|
|
imgSrcConverLazyloadSrc(doc);
|
|
|
|
|
+ normalizePreviewArticleImages(doc);
|
|
|
|
|
|
|
|
String html = doc.select("body").eq(0).html();
|
|
String html = doc.select("body").eq(0).html();
|
|
|
String articleTemplate = FileUtil.readFile(
|
|
String articleTemplate = FileUtil.readFile(
|
|
@@ -991,12 +995,20 @@ public class ArticleService extends BaseTransaction {
|
|
|
setRequestAttribute("navAllName", navAllName);
|
|
setRequestAttribute("navAllName", navAllName);
|
|
|
|
|
|
|
|
setRequestAttribute("copyNav", GsonUtil.toJson(articleCopyList));
|
|
setRequestAttribute("copyNav", GsonUtil.toJson(articleCopyList));
|
|
|
|
|
+ WebsiteNavigation navigation = getWebsiteNavigationById(gdba, article.getNavigationid());
|
|
|
|
|
+ String articleContentForPreview;
|
|
|
try {
|
|
try {
|
|
|
- setRequestAttribute("body", FileUtil.readFile(getWebRootPath() + article.getContent()));
|
|
|
|
|
|
|
+ articleContentForPreview = FileUtil.readFile(getWebRootPath() + article.getContent());
|
|
|
|
|
+ setRequestAttribute("body", articleContentForPreview);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- setRequestAttribute("body", "内容文件不存在或已被删除");
|
|
|
|
|
|
|
+ articleContentForPreview = "内容文件不存在或已被删除";
|
|
|
|
|
+ setRequestAttribute("body", articleContentForPreview);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ setRequestAttribute("infoPreviewHtmlB64", Base64.getEncoder().encodeToString(
|
|
|
|
|
+ buildArticleInfoPreviewHtml(article, website, navigation, articleContentForPreview)
|
|
|
|
|
+ .getBytes(StandardCharsets.UTF_8)));
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
setRequestAttribute("editBody", FileUtil.readFile(getWebRootPath() + article.getEditContent()));
|
|
setRequestAttribute("editBody", FileUtil.readFile(getWebRootPath() + article.getEditContent()));
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -1369,6 +1381,66 @@ public class ArticleService extends BaseTransaction {
|
|
|
write(buildArticlePreviewHtml(null, null, FileUtil.readFile(previewFile.getPath())));
|
|
write(buildArticlePreviewHtml(null, null, FileUtil.readFile(previewFile.getPath())));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 文章信息弹窗内容区 PC 预览(与三端预览 PC 端同源)。
|
|
|
|
|
+ */
|
|
|
|
|
+ public void infoPreviewView() throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+ getResponse().setContentType("text/html;charset=UTF-8");
|
|
|
|
|
+
|
|
|
|
|
+ Long articleid = getParameterToLong("articleid");
|
|
|
|
|
+ if (articleid == null || articleid <= 0) {
|
|
|
|
|
+ writePreviewUnavailable();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ GeneralDBAccess gdba = getGdbaInstance();
|
|
|
|
|
+ Article article = new Article();
|
|
|
|
|
+ article.setArticleid(articleid);
|
|
|
|
|
+ gdba.selectById(article);
|
|
|
|
|
+
|
|
|
|
|
+ Website website = new Website();
|
|
|
|
|
+ website.setWebsiteid(article.getWebsiteid());
|
|
|
|
|
+ gdba.selectById(website);
|
|
|
|
|
+
|
|
|
|
|
+ WebsiteNavigation navigation = getWebsiteNavigationById(gdba, article.getNavigationid());
|
|
|
|
|
+
|
|
|
|
|
+ String articleContent;
|
|
|
|
|
+ try {
|
|
|
|
|
+ articleContent = FileUtil.readFile(getWebRootPath() + article.getContent());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ writePreviewUnavailable();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ write(buildArticleInfoPreviewHtml(article, website, navigation, articleContent));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String buildArticleInfoPreviewHtml(Article article, Website website, WebsiteNavigation navigation,
|
|
|
|
|
+ String articleContent) {
|
|
|
|
|
+ Map<String, Object> previewInfo = new HashMap<String, Object>();
|
|
|
|
|
+ previewInfo.put(PREVIEW_TITLE_KEY, article.getTitle());
|
|
|
|
|
+ previewInfo.put(PREVIEW_SOURCE_KEY, firstNotBlank(article.getSource(), website.getName()));
|
|
|
|
|
+ previewInfo.put(PREVIEW_RELEASE_TIME_KEY, formatArticleReleaseTime(article.getReleaseTime()));
|
|
|
|
|
+ previewInfo.put(PREVIEW_NAVIGATION_ID_KEY,
|
|
|
|
|
+ article.getNavigationid() == null ? "" : article.getNavigationid().toString());
|
|
|
|
|
+ previewInfo.put(PREVIEW_WEBSITE_ID_KEY,
|
|
|
|
|
+ article.getWebsiteid() == null ? "" : article.getWebsiteid().toString());
|
|
|
|
|
+ return buildArticlePreviewHtml(previewInfo, navigation, website, articleContent);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String formatArticleReleaseTime(Timestamp releaseTime) {
|
|
|
|
|
+ if (releaseTime == null) {
|
|
|
|
|
+ return DateTimeUtil.getNowDate("yyyy-MM-dd HH:mm");
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ String formatted = DateTimeUtil.formatDateYMdHms(releaseTime);
|
|
|
|
|
+ return StringUtil.isNull(formatted) ? DateTimeUtil.getNowDate("yyyy-MM-dd HH:mm") : formatted;
|
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
|
+ return DateTimeUtil.getNowDate("yyyy-MM-dd HH:mm");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private Map<String, Object> buildPreviewInfo(String runPath, WebsiteNavigation navigation, String title,
|
|
private Map<String, Object> buildPreviewInfo(String runPath, WebsiteNavigation navigation, String title,
|
|
|
String source, String desc) {
|
|
String source, String desc) {
|
|
|
Map<String, Object> previewInfo = new HashMap<String, Object>();
|
|
Map<String, Object> previewInfo = new HashMap<String, Object>();
|
|
@@ -1413,23 +1485,31 @@ public class ArticleService extends BaseTransaction {
|
|
|
String title = firstNotBlank(previewInfo == null ? null : previewInfo.get(PREVIEW_TITLE_KEY), "正文预览");
|
|
String title = firstNotBlank(previewInfo == null ? null : previewInfo.get(PREVIEW_TITLE_KEY), "正文预览");
|
|
|
String source = firstNotBlank(previewInfo == null ? null : previewInfo.get(PREVIEW_SOURCE_KEY),
|
|
String source = firstNotBlank(previewInfo == null ? null : previewInfo.get(PREVIEW_SOURCE_KEY),
|
|
|
website == null ? "" : website.getName());
|
|
website == null ? "" : website.getName());
|
|
|
- String releaseTime = DateTimeUtil.getNowDate("yyyy-MM-dd HH:mm");
|
|
|
|
|
|
|
+ String releaseTime = firstNotBlank(previewInfo == null ? null : previewInfo.get(PREVIEW_RELEASE_TIME_KEY),
|
|
|
|
|
+ DateTimeUtil.getNowDate("yyyy-MM-dd HH:mm"));
|
|
|
String content = restorePreviewLazyImages(firstNotBlank(articleContent, ""));
|
|
String content = restorePreviewLazyImages(firstNotBlank(articleContent, ""));
|
|
|
|
|
|
|
|
StringBuilder html = new StringBuilder();
|
|
StringBuilder html = new StringBuilder();
|
|
|
html.append("<!DOCTYPE html><html><head><meta charset=\"UTF-8\">")
|
|
html.append("<!DOCTYPE html><html><head><meta charset=\"UTF-8\">")
|
|
|
.append("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">")
|
|
.append("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">")
|
|
|
- .append("<link rel=\"stylesheet\" href=\"/main/ffkj-portal/portal-source.css\">")
|
|
|
|
|
- .append("<link rel=\"stylesheet\" href=\"/apps/space/css/space.editor.css\">")
|
|
|
|
|
|
|
+ .append("<link rel=\"stylesheet\" href=\"/main/ffkj-portal/portal-source.css?v=20260703-article-image-fit-v2\">")
|
|
|
|
|
+ .append("<link rel=\"stylesheet\" href=\"/apps/space/css/space.editor.css?v=20260703-article-image-fit-v2\">")
|
|
|
.append("<style>")
|
|
.append("<style>")
|
|
|
- .append("body{margin:0;background:#f5f7fa;color:#1f2937;font-family:Arial,'Microsoft YaHei',sans-serif;}")
|
|
|
|
|
- .append(".preview-article{box-sizing:border-box;max-width:900px;margin:0 auto;padding:36px 32px;background:#fff;min-height:100vh;}")
|
|
|
|
|
|
|
+ .append("html{height:100%;overflow:hidden;}")
|
|
|
|
|
+ .append("body{margin:0;height:100%;overflow-x:hidden;overflow-y:auto;background:#f5f7fa;color:#1f2937;font-family:Arial,'Microsoft YaHei',sans-serif;}")
|
|
|
|
|
+ .append(".preview-article{box-sizing:border-box;max-width:900px;margin:0 auto;padding:36px 32px;background:#fff;min-height:100%;}")
|
|
|
|
|
+ .append(".preview-article.article-panel{padding:36px 32px!important;}")
|
|
|
.append(".preview-article-header{margin:0 0 22px;padding:0 0 18px;border-bottom:3px solid #a40011;}")
|
|
.append(".preview-article-header{margin:0 0 22px;padding:0 0 18px;border-bottom:3px solid #a40011;}")
|
|
|
.append(".preview-article-title{margin:0;color:#a40011;font-size:30px;line-height:1.35;font-weight:700;letter-spacing:0;}")
|
|
.append(".preview-article-title{margin:0;color:#a40011;font-size:30px;line-height:1.35;font-weight:700;letter-spacing:0;}")
|
|
|
.append(".preview-article-meta{display:flex;flex-wrap:wrap;gap:8px 16px;margin-top:14px;color:#666;font-size:14px;line-height:1.5;}")
|
|
.append(".preview-article-meta{display:flex;flex-wrap:wrap;gap:8px 16px;margin-top:14px;color:#666;font-size:14px;line-height:1.5;}")
|
|
|
.append(".preview-article-body{font-size:16px;line-height:1.9;color:#333;}")
|
|
.append(".preview-article-body{font-size:16px;line-height:1.9;color:#333;}")
|
|
|
- .append(".preview-article-body img{max-width:100%;height:auto;display:block;margin:0 auto;}")
|
|
|
|
|
- .append(".preview-article-body video,.preview-article-body iframe,.preview-article-body object,.preview-article-body embed{max-width:100%;}")
|
|
|
|
|
|
|
+ .append(".preview-article-body .ck-content,#jquery-lazyload-container.ck-content{width:100%!important;margin:0!important;padding:0!important;}")
|
|
|
|
|
+ .append(".preview-article-body img,.article-body img,.preview-article-body .ck-content img,.article-body .ck-content img,.preview-article-body figure.image img,.article-body figure.image img,.preview-article-body .ck-content .image img,.article-body .ck-content .image img{display:block;width:100%!important;max-width:100%!important;height:auto!important;margin:18px 0!important;box-sizing:border-box;}")
|
|
|
|
|
+ .append(".preview-article-body figure.image,.article-body figure.image,.preview-article-body figure:has(img),.article-body figure:has(img),.preview-article-body .ck-content .image,.article-body .ck-content .image,.preview-article-body .ck-content figure,.article-body .ck-content figure{display:block!important;width:100%!important;max-width:100%!important;margin:18px 0!important;padding:0!important;text-align:left!important;}")
|
|
|
|
|
+ .append(".preview-article-body p:has(img),.preview-article-body div:has(img),.preview-article-body figure:has(img),")
|
|
|
|
|
+ .append(".article-body p:has(img),.article-body div:has(img),.article-body figure:has(img),")
|
|
|
|
|
+ .append(".preview-article-body .ck-content p:has(img),.preview-article-body .ck-content div:has(img),.article-body .ck-content p:has(img),.article-body .ck-content div:has(img){text-align:left!important;text-indent:0!important;}")
|
|
|
|
|
+ .append(".preview-article-body video,.preview-article-body iframe,.preview-article-body object,.preview-article-body embed,.article-body video,.article-body iframe,.article-body object,.article-body embed{display:block;width:100%!important;max-width:100%!important;margin:18px 0!important;}")
|
|
|
.append(".preview-article-body figure.space-editor-pdf-viewer{max-width:100%;}")
|
|
.append(".preview-article-body figure.space-editor-pdf-viewer{max-width:100%;}")
|
|
|
.append(".preview-article-body iframe.space-editor-pdf-frame{width:100%;height:min(78vh,720px);min-height:480px;}")
|
|
.append(".preview-article-body iframe.space-editor-pdf-frame{width:100%;height:min(78vh,720px);min-height:480px;}")
|
|
|
.append("@media (max-width: 700px){.preview-article{padding:24px 18px;}.preview-article-title{font-size:24px;}.preview-article-body iframe.space-editor-pdf-frame{min-height:420px;}}")
|
|
.append("@media (max-width: 700px){.preview-article{padding:24px 18px;}.preview-article-title{font-size:24px;}.preview-article-body iframe.space-editor-pdf-frame{min-height:420px;}}")
|
|
@@ -1446,6 +1526,7 @@ public class ArticleService extends BaseTransaction {
|
|
|
.append("<div class=\"preview-article-body article-body\" data-article-preview=\"true\">")
|
|
.append("<div class=\"preview-article-body article-body\" data-article-preview=\"true\">")
|
|
|
.append(content)
|
|
.append(content)
|
|
|
.append("</div></article>")
|
|
.append("</div></article>")
|
|
|
|
|
+ .append("<script>(function(){var root=document.querySelector('.article-body,[data-article-preview]');if(!root){return;}function normalizeNode(node){if(!node){return;}node.style.setProperty('display','block','important');node.style.setProperty('width','100%','important');node.style.setProperty('max-width','100%','important');node.style.setProperty('margin','18px 0','important');node.style.setProperty('padding','0','important');node.style.setProperty('text-align','left','important');}root.querySelectorAll('.ck-content .image,figure.image,figure').forEach(function(fig){if(!fig.querySelector('img')){return;}normalizeNode(fig);});root.querySelectorAll('img').forEach(function(img){img.style.setProperty('display','block','important');img.style.setProperty('width','100%','important');img.style.setProperty('max-width','100%','important');img.style.setProperty('height','auto','important');img.style.setProperty('margin','18px 0','important');var parent=img.closest('p,div,figure,.image');if(parent){parent.style.setProperty('text-align','left','important');parent.style.setProperty('text-indent','0','important');}});})();</script>")
|
|
|
.append("</body></html>");
|
|
.append("</body></html>");
|
|
|
return html.toString();
|
|
return html.toString();
|
|
|
}
|
|
}
|
|
@@ -1465,10 +1546,65 @@ public class ArticleService extends BaseTransaction {
|
|
|
image.attr("src", image.attr("data-original"));
|
|
image.attr("src", image.attr("data-original"));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ normalizePreviewArticleImages(doc);
|
|
|
doc.select("script").remove();
|
|
doc.select("script").remove();
|
|
|
|
|
+ unwrapArticleContentContainer(doc);
|
|
|
return doc.body().html();
|
|
return doc.body().html();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void unwrapArticleContentContainer(Document doc) {
|
|
|
|
|
+ Elements wrappers = doc.select("#jquery-lazyload-container, div.ck-content");
|
|
|
|
|
+ for (Element wrapper : wrappers) {
|
|
|
|
|
+ wrapper.unwrap();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void normalizePreviewArticleImages(Document doc) {
|
|
|
|
|
+ Elements figures = doc.select("figure.image, figure.image_resized, figure:has(img), .ck-content .image");
|
|
|
|
|
+ for (Element figure : figures) {
|
|
|
|
|
+ figure.removeAttr("width");
|
|
|
|
|
+ figure.removeAttr("height");
|
|
|
|
|
+ figure.attr("style", "display:block;width:100%;max-width:100%;margin:18px 0;text-align:left;");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Elements images = doc.select("img");
|
|
|
|
|
+ for (Element image : images) {
|
|
|
|
|
+ image.removeAttr("width");
|
|
|
|
|
+ image.removeAttr("height");
|
|
|
|
|
+ image.removeAttr("hspace");
|
|
|
|
|
+ image.removeAttr("vspace");
|
|
|
|
|
+ image.removeAttr("border");
|
|
|
|
|
+ image.attr("style", "display:block;width:100%;max-width:100%;height:auto;margin:18px 0;box-sizing:border-box;");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Elements mediaBlocks = doc.select("p:has(img), div:has(img), figure:has(img)");
|
|
|
|
|
+ for (Element block : mediaBlocks) {
|
|
|
|
|
+ String style = block.attr("style");
|
|
|
|
|
+ style = stripArticleImageStyleProperty(style, "width");
|
|
|
|
|
+ style = stripArticleImageStyleProperty(style, "max-width");
|
|
|
|
|
+ style = stripArticleImageStyleProperty(style, "margin");
|
|
|
|
|
+ style = stripArticleImageStyleProperty(style, "text-align");
|
|
|
|
|
+ style = stripArticleImageStyleProperty(style, "text-indent");
|
|
|
|
|
+ block.attr("style", joinArticleImageStyle(style,
|
|
|
|
|
+ "text-align:left;text-indent:0;"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String stripArticleImageStyleProperty(String style, String property) {
|
|
|
|
|
+ if (StringUtil.isNull(style) || StringUtil.isNull(property)) {
|
|
|
|
|
+ return style == null ? "" : style;
|
|
|
|
|
+ }
|
|
|
|
|
+ return style.replaceAll("(?i)" + Pattern.quote(property) + "\\s*:[^;\"']*(;|$)", "$1").trim();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String joinArticleImageStyle(String baseStyle, String appendStyle) {
|
|
|
|
|
+ String normalizedBase = baseStyle == null ? "" : baseStyle.trim();
|
|
|
|
|
+ if (normalizedBase.length() > 0 && !normalizedBase.endsWith(";")) {
|
|
|
|
|
+ normalizedBase += ";";
|
|
|
|
|
+ }
|
|
|
|
|
+ return normalizedBase + appendStyle;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private String normalizeLocalUploadResourceUrl(String content) {
|
|
private String normalizeLocalUploadResourceUrl(String content) {
|
|
|
if (StringUtil.isNull(content) || content.indexOf("/web/upload/") < 0) {
|
|
if (StringUtil.isNull(content) || content.indexOf("/web/upload/") < 0) {
|
|
|
return content;
|
|
return content;
|
|
@@ -1605,6 +1741,7 @@ public class ArticleService extends BaseTransaction {
|
|
|
replaceAllHtmlLink(hrefEles, "href", domain);
|
|
replaceAllHtmlLink(hrefEles, "href", domain);
|
|
|
|
|
|
|
|
imgSrcConverLazyloadSrc(doc);
|
|
imgSrcConverLazyloadSrc(doc);
|
|
|
|
|
+ normalizePreviewArticleImages(doc);
|
|
|
|
|
|
|
|
String html = doc.select("body").eq(0).html();
|
|
String html = doc.select("body").eq(0).html();
|
|
|
String articleTemplate = html;
|
|
String articleTemplate = html;
|