Commit 3ed92a11 authored by Liang Ding's avatar Liang Ding

🎨 #12690

parent 555bcc11
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.event;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.util.Strings;
import org.b3log.solo.mail.MailService;
import org.b3log.solo.mail.MailServiceFactory;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Option;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
/**
* This listener is responsible for processing article comment reply.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://www.wanglay.com">Lei Wang</a>
* @version 1.2.2.12, Oct 23, 2018
* @since 0.3.1
*/
@Singleton
public class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(ArticleCommentReplyNotifier.class);
/**
* Mail service.
*/
private MailService mailService = MailServiceFactory.getMailService();
@Override
public void action(final Event<JSONObject> event) {
final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject article = eventData.optJSONObject(Article.ARTICLE);
LOGGER.log(Level.DEBUG, "Processing an event [type={0}, data={1}] in listener [className={2}]",
event.getType(), eventData, ArticleCommentReplyNotifier.class.getName());
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (StringUtils.isBlank(originalCommentId)) {
LOGGER.log(Level.DEBUG, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
return;
}
if (Latkes.getServePath().contains("localhost") || Strings.isIPv4(Latkes.getServePath())) {
LOGGER.log(Level.INFO, "Solo runs on local server, so should not send mail");
return;
}
if (!Solos.isMailConfigured()) {
return;
}
final BeanManager beanManager = BeanManager.getInstance();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final CommentRepository commentRepository = beanManager.getReference(CommentRepository.class);
try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = commentRepository.get(originalCommentId);
final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return;
}
if (!Strings.isEmail(originalCommentEmail)) {
return;
}
final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
throw new Exception("Not found preference");
}
final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE);
final String adminEmail = preference.getString(Option.ID_C_ADMIN_EMAIL);
final String commentContent = comment.getString(Comment.COMMENT_CONTENT);
final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
final MailService.Message message = new MailService.Message();
message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final String articleTitle = article.getString(Article.ARTICLE_TITLE);
final String articleLink = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter;
if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
} else {
commenter = commentName;
}
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${postLink}", articleLink).
replace("${postTitle}", articleTitle).
replace("${replier}", commenter).
replace("${blogTitle}", blogTitle).
replace("${replyURL}", Latkes.getServePath() + commentSharpURL).
replace("${replyContent}", commentContent).
replace("${servePath}", Latkes.getServePath());
message.setSubject(mailSubject);
final String mailBody = replyNotificationTemplate.
getString("body").
replace("${postLink}", articleLink).
replace("${postTitle}", articleTitle).
replace("${replier}", commenter).
replace("${blogTitle}", blogTitle).
replace("${replyURL}", Latkes.getServePath() + commentSharpURL).
replace("${replyContent}", commentContent).
replace("${servePath}", Latkes.getServePath());
message.setHtmlBody(mailBody);
LOGGER.log(Level.DEBUG, "Sending a mail [mailSubject={0}, mailBody=[{1}] to [{2}]",
mailSubject, mailBody, originalCommentEmail);
mailService.send(message);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
}
}
/**
* Gets the event type {@linkplain EventTypes#ADD_COMMENT_TO_ARTICLE}.
*
* @return event type
*/
@Override
public String getEventType() {
return EventTypes.ADD_COMMENT_TO_ARTICLE;
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.event;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.util.Strings;
import org.b3log.solo.mail.MailService;
import org.b3log.solo.mail.MailServiceFactory;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Page;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
/**
* This listener is responsible for processing page comment reply.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.2.6, Sep 25, 2018
* @since 0.3.1
*/
@Singleton
public class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(PageCommentReplyNotifier.class);
/**
* Mail service.
*/
private MailService mailService = MailServiceFactory.getMailService();
@Override
public void action(final Event<JSONObject> event) {
final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject page = eventData.optJSONObject(Page.PAGE);
LOGGER.log(Level.DEBUG, "Processing an event [type={0}, data={1}] in listener [className={2}]",
event.getType(), eventData, PageCommentReplyNotifier.class.getName());
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (StringUtils.isBlank(originalCommentId)) {
LOGGER.log(Level.DEBUG, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
return;
}
if (!Solos.isMailConfigured()) {
return;
}
final BeanManager beanManager = BeanManager.getInstance();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final CommentRepository commentRepository = beanManager.getReference(CommentRepository.class);
try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = commentRepository.get(originalCommentId);
final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return;
}
if (!Strings.isEmail(originalCommentEmail)) {
return;
}
final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
LOGGER.log(Level.ERROR, "Not found preference");
return;
}
final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE);
final String adminEmail = preference.getString(Option.ID_C_ADMIN_EMAIL);
final String commentContent = comment.getString(Comment.COMMENT_CONTENT);
final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
final MailService.Message message = new MailService.Message();
message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject);
final String pageTitle = page.getString(Page.PAGE_TITLE);
final String pageLink = Latkes.getServePath() + page.getString(Page.PAGE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter;
if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
} else {
commenter = commentName;
}
final String mailBody = replyNotificationTemplate.getString("body").replace("${postLink}", pageLink).replace("${postTitle}", pageTitle).replace("${replier}", commenter).replace("${replyURL}", Latkes.getServePath() + commentSharpURL).replace(
"${replyContent}", commentContent);
message.setHtmlBody(mailBody);
LOGGER.log(Level.DEBUG, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
mailSubject, mailBody, originalCommentEmail);
mailService.send(message);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
}
}
/**
* Gets the event type {@linkplain EventTypes#ADD_COMMENT_TO_PAGE}.
*
* @return event type
*/
@Override
public String getEventType() {
return EventTypes.ADD_COMMENT_TO_PAGE;
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.mail;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Mail service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Aug 8, 2011
*/
public interface MailService {
/**
* Sends the specified message as a mail asynchronously.
*
* @param message the specified message
* @throws IOException if internal errors
*/
void send(final Message message) throws IOException;
/**
* Mail message.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Aug 8, 2011
*/
class Message {
/**
* From.
*/
private String from;
/**
* Recipients.
*/
private Set<String> recipients = new HashSet<>();
/**
* HTML body.
*/
private String htmlBody;
/**
* Subject.
*/
private String subject;
/**
* Gets the recipients.
*
* @return recipients
*/
public Set<String> getRecipients() {
return Collections.unmodifiableSet(recipients);
}
/**
* Adds the specified recipient.
*
* @param recipient the specified recipient
*/
public void addRecipient(final String recipient) {
recipients.add(recipient);
}
/**
* Gets the HTML body.
*
* @return HTML body
*/
public String getHtmlBody() {
return htmlBody;
}
/**
* Sets the HTML body with the specified HTML body.
*
* @param htmlBody the specified HTML body
*/
public void setHtmlBody(final String htmlBody) {
this.htmlBody = htmlBody;
}
/**
* Gets the from.
*
* @return from
*/
public String getFrom() {
return from;
}
/**
* Sets the from with the specified from.
*
* @param from the specified from
*/
public void setFrom(final String from) {
this.from = from;
}
/**
* Gets the subject.
*
* @return subject
*/
public String getSubject() {
return subject;
}
/**
* Sets the subject with the specified subject.
*
* @param subject the specified subject
*/
public void setSubject(final String subject) {
this.subject = subject;
}
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.mail;
/**
* Mail service factory.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.1.3, Dec 3, 2018
*/
public final class MailServiceFactory {
/**
* Mail service.
*/
private static final MailService MAIL_SERVICE;
static {
try {
final Class<MailService> mailServiceClass = (Class<MailService>) Class.forName("org.b3log.solo.mail.local.LocalMailService");
MAIL_SERVICE = mailServiceClass.newInstance();
} catch (final Exception e) {
throw new RuntimeException("Can not initialize mail service!", e);
}
}
/**
* Private constructor.
*/
private MailServiceFactory() {
}
/**
* Gets mail service.
*
* @return mail service
*/
public static MailService getMailService() {
return MAIL_SERVICE;
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.mail.local;
import org.b3log.solo.mail.MailService;
/**
* JavaMail implementation of the {@link MailService} interface.
*
* @author <a href="https://hacpai.com/member/jiangzezhou">zezhou jiang</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Jan 18, 2019
*/
public final class LocalMailService implements MailService {
@Override
public void send(final Message message) {
new Thread(() -> new MailSender().sendMail(message)).start();
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.mail.local;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.solo.mail.MailService.Message;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
import javax.mail.internet.MimeUtility;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
/**
* Email sender.
*
* @author <a href="https://hacpai.com/member/jiangzezhou">zezhou jiang</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.2.5, Jan 18, 2019
*/
final class MailSender {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(MailSender.class);
/**
* Mail configurations.
*
* <ul>
* <li>mail.user</li>
* <li>mail.password</li>
* <li>mail.smtp.host</li>
* <li>mail.smtp.auth</li>
* <li>mail.smtp.port</li>
* <li>mail.smtp.starttls.enable</li>
* <li>mail.debug</li>
* <li>mail.smtp.socketFactory.class</li>
* <li>mail.smtp.socketFactory.fallback</li>
* <li>mail.smtp.socketFactory.port</li>
* </ul>
*/
private static final ResourceBundle mailProperties = ResourceBundle.getBundle("mail");
/**
* Create session based on the mail properties.
*
* @return session session from mail properties
*/
private Session getSession() {
final Properties props = new Properties();
props.setProperty("mail.smtp.host", mailProperties.getString("mail.smtp.host"));
String auth = "true";
if (mailProperties.containsKey("mail.smtp.auth")) {
auth = mailProperties.getString("mail.smtp.auth");
}
props.setProperty("mail.smtp.auth", auth);
props.setProperty("mail.smtp.port", mailProperties.getString("mail.smtp.port"));
String starttls = "true";
if (mailProperties.containsKey("mail.smtp.starttls.enable")) {
starttls = mailProperties.getString("mail.smtp.starttls.enable");
}
props.put("mail.smtp.starttls.enable", starttls);
props.put("mail.debug", mailProperties.getString("mail.debug"));
props.put("mail.smtp.socketFactory.class", mailProperties.getString("mail.smtp.socketFactory.class"));
props.put("mail.smtp.socketFactory.fallback", mailProperties.getString("mail.smtp.socketFactory.fallback"));
props.put("mail.smtp.socketFactory.port", mailProperties.getString("mail.smtp.socketFactory.port"));
return Session.getInstance(props, new SMTPAuthenticator());
}
/**
* Converts the specified message into a {@link javax.mail.Message javax.mail.Message}.
*
* @param message the specified message
* @return a {@link javax.mail.internet.MimeMessage}
* @throws Exception if converts error
*/
public javax.mail.Message convert2JavaMailMsg(final Message message) throws Exception {
if (null == message) {
return null;
}
if (StringUtils.isBlank(message.getFrom())) {
throw new MessagingException("Null from");
}
if (null == message.getRecipients() || message.getRecipients().isEmpty()) {
throw new MessagingException("Null recipients");
}
final MimeMessage ret = new MimeMessage(getSession());
ret.setFrom(new InternetAddress(message.getFrom()));
final String subject = message.getSubject();
ret.setSubject(MimeUtility.encodeText(subject != null ? subject : "", "UTF-8", "B"));
final String htmlBody = message.getHtmlBody();
ret.setContent(htmlBody != null ? htmlBody : "", "text/html;charset=UTF-8");
ret.addRecipients(RecipientType.TO, transformRecipients(message.getRecipients()));
return ret;
}
/**
* Transport recipients to InternetAddress array.
*
* @param recipients the set of all recipients
* @return InternetAddress array of all recipients internetAddress
* @throws MessagingException messagingException from javax.mail
*/
private InternetAddress[] transformRecipients(final Set<String> recipients) throws MessagingException {
if (recipients.isEmpty()) {
throw new MessagingException("recipients of mail should not be empty");
}
final InternetAddress[] ret = new InternetAddress[recipients.size()];
int i = 0;
for (String recipient : recipients) {
ret[i] = new InternetAddress(recipient);
i++;
}
return ret;
}
/**
* Sends email.
*
* @param message the specified message
* @throws Exception message exception
*/
void sendMail(final Message message) {
try {
final javax.mail.Message msg = convert2JavaMailMsg(message);
Transport.send(msg);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Sends mail failed", e);
}
}
/**
* Inner class for Authenticator.
*/
private class SMTPAuthenticator extends Authenticator {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailProperties.getString("mail.user"), mailProperties.getString("mail.password"));
}
}
}
/**
* Provides mail service (via <a href="http://www.oracle.com/technetwork/java/javamail/index.html">
* JavaMail</a>) on local (standard Servlet container).
*/
package org.b3log.solo.mail.local;
/**
* Main service.
*/
package org.b3log.solo.mail;
......@@ -26,7 +26,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://github.com/hzchendou">hzchendou</a>
* @version 1.5.0.3, Feb 8, 2019
* @version 1.5.0.4, Mar 3, 2019
* @since 0.6.0
*/
public final class Option {
......@@ -117,11 +117,6 @@ public final class Option {
*/
public static final String ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE = "articleListPaginationWindowSize";
/**
* Key of administrator's email.
*/
public static final String ID_C_ADMIN_EMAIL = "adminEmail";
/**
* Key of locale string.
*/
......
......@@ -741,12 +741,7 @@ public class ArticleProcessor {
article.put(Common.AUTHOR_ID, authorId);
article.put(Common.AUTHOR_ROLE, author.getString(User.USER_ROLE));
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (StringUtils.isNotBlank(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Solos.getGravatarURL(author.optString(User.USER_EMAIL), "128");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
dataModelService.fillCategory(article);
......@@ -836,12 +831,7 @@ public class ArticleProcessor {
dataModel.put(Common.AUTHOR_NAME, author.optString(User.USER_NAME));
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (StringUtils.isNotBlank(userAvatar)) {
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Solos.getGravatarURL(author.optString(User.USER_EMAIL), "128");
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, currentPageNum);
}
......
......@@ -295,7 +295,6 @@ public class CommentProcessor {
}
requestJSONObject.put(Comment.COMMENT_NAME, currentUser.optString(User.USER_NAME));
requestJSONObject.put(Comment.COMMENT_EMAIL, currentUser.optString(User.USER_EMAIL));
requestJSONObject.put(Comment.COMMENT_URL, currentUser.optString(User.USER_URL));
}
}
......@@ -135,14 +135,8 @@ public class AdminConsole {
dataModel.put(User.USER_NAME, userName);
final String roleName = currentUser.optString(User.USER_ROLE);
dataModel.put(User.USER_ROLE, roleName);
final String email = currentUser.optString(User.USER_EMAIL);
final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
if (StringUtils.isNotBlank(userAvatar)) {
dataModel.put(Common.GRAVATAR, userAvatar);
} else {
final String gravatar = Solos.getGravatarURL(email, "128");
dataModel.put(Common.GRAVATAR, gravatar);
}
dataModel.put(Common.GRAVATAR, userAvatar);
try {
final JSONObject preference = preferenceQueryService.getPreference();
......
......@@ -183,7 +183,6 @@ public class UserConsole {
* "users": [{
* "oId": "",
* "userName": "",
* "userEmail": "",
* "roleName": "",
* ....
* }, ....]
......
......@@ -528,15 +528,8 @@ public class DataModelService {
comment.put(Comment.COMMENT_NAME, comment.getString(Comment.COMMENT_NAME));
comment.put(Comment.COMMENT_URL, comment.getString(Comment.COMMENT_URL));
comment.put(Common.IS_REPLY, false);
comment.remove(Comment.COMMENT_EMAIL); // Erases email for security reason
comment.put(Comment.COMMENT_T_DATE, new Date(comment.optLong(Comment.COMMENT_CREATED)));
comment.put("commentDate2", new Date(comment.optLong(Comment.COMMENT_CREATED)));
final String email = comment.optString(Comment.COMMENT_EMAIL);
final String thumbnailURL = comment.optString(Comment.COMMENT_THUMBNAIL_URL);
if (StringUtils.isBlank(thumbnailURL)) {
comment.put(Comment.COMMENT_THUMBNAIL_URL, Solos.getGravatarURL(email, "128"));
}
}
dataModel.put(Common.RECENT_COMMENTS, recentComments);
......@@ -615,14 +608,7 @@ public class DataModelService {
final JSONObject currentUser = Solos.getCurrentUser(context.getRequest(), context.getResponse());
if (null != currentUser) {
final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
if (StringUtils.isNotBlank(userAvatar)) {
dataModel.put(Common.GRAVATAR, userAvatar);
} else {
final String email = currentUser.optString(User.USER_EMAIL);
final String gravatar = Solos.getGravatarURL(email, "128");
dataModel.put(Common.GRAVATAR, gravatar);
}
dataModel.put(Common.GRAVATAR, userAvatar);
dataModel.put(User.USER_NAME, currentUser.optString(User.USER_NAME));
}
......@@ -909,12 +895,7 @@ public class DataModelService {
article.put(Article.ARTICLE_T_UPDATE_DATE, new Date(article.optLong(Article.ARTICLE_UPDATED)));
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (StringUtils.isNotBlank(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Solos.getGravatarURL(author.optString(User.USER_EMAIL), "128");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
if (preference.getBoolean(Option.ID_C_ENABLE_ARTICLE_UPDATE_HINT)) {
article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article));
......
......@@ -17,7 +17,6 @@
*/
package org.b3log.solo.service;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.b3log.latke.Keys;
......@@ -213,7 +212,6 @@ public class InitService {
* @param requestJSONObject the specified request json object, for example,
* {
* "userName": "",
* "userEmail": "",
* "userAvatar": "", // optional
* "userB3Key": "", // optional
* "userGitHubId": "" // optional
......@@ -286,7 +284,6 @@ public class InitService {
final JSONObject comment = new JSONObject();
comment.put(Keys.OBJECT_ID, articleId);
comment.put(Comment.COMMENT_NAME, "88250");
comment.put(Comment.COMMENT_EMAIL, "d@b3log.org");
comment.put(Comment.COMMENT_URL, "https://hacpai.com/member/88250");
comment.put(Comment.COMMENT_CONTENT, langPropsService.get("helloWorld.comment.content"));
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_ID, "");
......@@ -412,7 +409,6 @@ public class InitService {
* @param requestJSONObject the specified request json object, for example,
* {
* "userName": "",
* "userEmail": "",
* "userAvatar": "", // optional
* "userB3Key": "", // optional
* "userGitHubId": "" // optional
......@@ -427,11 +423,7 @@ public class InitService {
admin.put(User.USER_EMAIL, requestJSONObject.getString(User.USER_EMAIL));
admin.put(User.USER_URL, Latkes.getServePath());
admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
String avatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (StringUtils.isBlank(avatar)) {
avatar = Solos.getGravatarURL(requestJSONObject.getString(User.USER_EMAIL), "128");
}
admin.put(UserExt.USER_AVATAR, avatar);
admin.put(UserExt.USER_AVATAR, requestJSONObject.optString(UserExt.USER_AVATAR));
admin.put(UserExt.USER_B3_KEY, requestJSONObject.optString(UserExt.USER_B3_KEY));
admin.put(UserExt.USER_GITHUB_ID, requestJSONObject.optString(UserExt.USER_GITHUB_ID));
userRepository.add(admin);
......@@ -612,12 +604,6 @@ public class InitService {
blogSubtitleOpt.put(Option.OPTION_VALUE, DefaultPreference.DEFAULT_BLOG_SUBTITLE);
optionRepository.add(blogSubtitleOpt);
final JSONObject adminEmailOpt = new JSONObject();
adminEmailOpt.put(Keys.OBJECT_ID, Option.ID_C_ADMIN_EMAIL);
adminEmailOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
adminEmailOpt.put(Option.OPTION_VALUE, requestJSONObject.getString(User.USER_EMAIL));
optionRepository.add(adminEmailOpt);
final JSONObject localeStringOpt = new JSONObject();
localeStringOpt.put(Keys.OBJECT_ID, Option.ID_C_LOCALE_STRING);
localeStringOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
......
......@@ -209,20 +209,13 @@ public class PreferenceMgmtService {
preference.put(Option.ID_C_SIGNS, preference.get(Option.ID_C_SIGNS).toString());
final JSONObject oldPreference = preferenceQueryService.getPreference();
final String adminEmail = oldPreference.getString(Option.ID_C_ADMIN_EMAIL);
preference.put(Option.ID_C_ADMIN_EMAIL, adminEmail);
final String version = oldPreference.optString(Option.ID_C_VERSION);
preference.put(Option.ID_C_VERSION, version);
final String localeString = preference.getString(Option.ID_C_LOCALE_STRING);
LOGGER.log(Level.DEBUG, "Current locale[string={0}]", localeString);
Latkes.setLocale(new Locale(Locales.getLanguage(localeString), Locales.getCountry(localeString)));
final JSONObject adminEmailOpt = optionRepository.get(Option.ID_C_ADMIN_EMAIL);
adminEmailOpt.put(Option.OPTION_VALUE, adminEmail);
optionRepository.update(Option.ID_C_ADMIN_EMAIL, adminEmailOpt);
final JSONObject allowVisitDraftViaPermalinkOpt = optionRepository.get(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK);
allowVisitDraftViaPermalinkOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK));
optionRepository.update(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK, allowVisitDraftViaPermalinkOpt);
......
......@@ -81,13 +81,10 @@ public class PreferenceQueryService {
*/
public JSONObject getPreference() {
try {
final JSONObject checkInit = optionRepository.get(Option.ID_C_ADMIN_EMAIL);
if (null == checkInit) {
return null;
}
return optionQueryService.getOptions(Option.CATEGORY_C_PREFERENCE);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets preference failed", e);
return null;
}
}
......
......@@ -72,11 +72,14 @@ public final class V310_320 {
connection.commit();
connection.close();
optionRepository.remove("adminEmail");
final Transaction transaction = optionRepository.beginTransaction();
final JSONObject versionOpt = optionRepository.get(Option.ID_C_VERSION);
versionOpt.put(Option.OPTION_VALUE, toVer);
optionRepository.update(Option.ID_C_VERSION, versionOpt);
transaction.commit();
LOGGER.log(Level.INFO, "Upgraded from version [" + fromVer + "] to version [" + toVer + "] successfully");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment