Commit 4aa52aee authored by Liang Ding's avatar Liang Ding

#12724

parent b8b78db1
......@@ -217,11 +217,6 @@ public final class Option {
*/
public static final String ID_C_FEED_OUTPUT_CNT = "feedOutputCnt";
/**
* Key of skins.
*/
public static final String ID_C_SKINS = "skins";
/**
* Key of skin dir name.
*/
......
/*
* 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.model;
/**
* This class defines all skin model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Mar 29, 2019
*/
public final class Skin {
/**
* Skin.
*/
public static final String SKIN = "skin";
/**
* Skins.
*/
public static final String SKINS = "skins";
/**
* Key of skin directory name.
*/
public static final String SKIN_DIR_NAME = "skinDirName";
/**
* Private constructor.
*/
private Skin() {
}
}
......@@ -36,7 +36,6 @@ import org.b3log.latke.util.Paginator;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Skin;
import org.b3log.solo.service.DataModelService;
import org.b3log.solo.service.InitService;
import org.b3log.solo.service.OptionQueryService;
......@@ -124,7 +123,7 @@ public class IndexProcessor {
}
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, specifiedSkin);
final Cookie cookie = new Cookie(Skin.SKIN, specifiedSkin);
final Cookie cookie = new Cookie(Option.CATEGORY_C_SKIN, specifiedSkin);
cookie.setMaxAge(60 * 60); // 1 hour
cookie.setPath("/");
response.addCookie(cookie);
......
......@@ -42,7 +42,6 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Skin;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.DataModelService;
import org.b3log.solo.service.ExportService;
......@@ -144,7 +143,8 @@ public class AdminConsole {
dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
dataModel.put(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT, preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT));
dataModel.put(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE, preference.getInt(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE));
dataModel.put(Skin.SKIN_DIR_NAME, preference.getString(Skin.SKIN_DIR_NAME));
final JSONObject skin = optionQueryService.getSkin();
dataModel.put(Option.CATEGORY_C_SKIN, skin.optString(Option.OPTION_VALUE));
Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel);
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614
......
......@@ -29,16 +29,12 @@ import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JsonRenderer;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Sign;
import org.b3log.solo.model.Skin;
import org.b3log.solo.service.OptionMgmtService;
import org.b3log.solo.service.OptionQueryService;
import org.b3log.solo.service.PreferenceMgmtService;
import org.json.JSONArray;
import org.json.JSONObject;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
* Preference console request processing.
*
......@@ -225,7 +221,6 @@ public class PreferenceConsole {
* "randomArticlesDisplayCount": int,
* "blogTitle": "",
* "blogSubtitle": "",
* "skinDirName": "",
* "localeString": "",
* "timeZoneId": "",
* "noticeBoard": "",
......@@ -268,12 +263,6 @@ public class PreferenceConsole {
preferenceMgmtService.updatePreference(preference);
final HttpServletResponse response = context.getResponse();
final Cookie cookie = new Cookie(Skin.SKIN, preference.getString(Skin.SKIN_DIR_NAME));
cookie.setMaxAge(60 * 60); // 1 hour
cookie.setPath("/");
response.addCookie(cookie);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
} catch (final ServiceException e) {
......
......@@ -28,7 +28,6 @@ import org.b3log.latke.servlet.annotation.Before;
import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JsonRenderer;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Skin;
import org.b3log.solo.service.OptionQueryService;
import org.b3log.solo.service.SkinMgmtService;
import org.json.JSONObject;
......@@ -146,7 +145,7 @@ public class SkinConsole {
skinMgmtService.updateSkin(skin);
final HttpServletResponse response = context.getResponse();
final Cookie cookie = new Cookie(Skin.SKIN, skin.getString(Skin.SKIN_DIR_NAME));
final Cookie cookie = new Cookie(Option.CATEGORY_C_SKIN, skin.getString(Option.ID_C_SKIN_DIR_NAME));
cookie.setMaxAge(60 * 60); // 1 hour
cookie.setPath("/");
response.addCookie(cookie);
......
......@@ -707,7 +707,7 @@ public class DataModelService {
final JSONObject admin = userRepository.getAdmin();
dataModel.put(Common.ADMIN_USER, admin);
final String skinDirName = (String) context.attr(Keys.TEMAPLTE_DIR_NAME);
dataModel.put(Skin.SKIN_DIR_NAME, skinDirName);
dataModel.put(Option.ID_C_SKIN_DIR_NAME, skinDirName);
Keys.fillRuntime(dataModel);
fillMinified(dataModel);
fillPageNavigations(dataModel);
......
......@@ -672,19 +672,6 @@ public class InitService {
mobileSkinDirNameOpt.put(Option.OPTION_VALUE, DefaultPreference.DEFAULT_MOBILE_SKIN_DIR_NAME);
optionRepository.add(mobileSkinDirNameOpt);
final Set<String> skinDirNames = Skins.getSkinDirNames();
final JSONArray skinArray = new JSONArray();
for (final String dirName : skinDirNames) {
final JSONObject skin = new JSONObject();
skinArray.put(skin);
skin.put(Skin.SKIN_DIR_NAME, dirName);
}
final JSONObject skinsOpt = new JSONObject();
skinsOpt.put(Keys.OBJECT_ID, Option.ID_C_SKINS);
skinsOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_SKIN);
skinsOpt.put(Option.OPTION_VALUE, skinArray.toString());
optionRepository.add(skinsOpt);
LOGGER.info("Initialized preference");
}
}
......@@ -28,15 +28,11 @@ import org.b3log.latke.service.ServiceException;
import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.util.Locales;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Skin;
import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.util.Skins;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
/**
* Preference management service.
......@@ -89,15 +85,6 @@ public class PreferenceMgmtService {
final Transaction transaction = optionRepository.beginTransaction();
try {
final Set<String> skinDirNames = Skins.getSkinDirNames();
final JSONArray skinArray = new JSONArray();
for (final String dirName : skinDirNames) {
final JSONObject skin = new JSONObject();
skinArray.put(skin);
skin.put(Skin.SKIN_DIR_NAME, dirName);
}
preference.put(Skin.SKINS, skinArray.toString());
preference.put(Option.ID_C_SIGNS, preference.get(Option.ID_C_SIGNS).toString());
final JSONObject oldPreference = optionQueryService.getPreference();
......@@ -208,10 +195,6 @@ public class PreferenceMgmtService {
signsOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SIGNS));
optionRepository.update(Option.ID_C_SIGNS, signsOpt);
final JSONObject skinsOpt = optionRepository.get(Option.ID_C_SKINS);
skinsOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SKINS));
optionRepository.update(Option.ID_C_SKINS, skinsOpt);
final JSONObject timeZoneIdOpt = optionRepository.get(Option.ID_C_TIME_ZONE_ID);
timeZoneIdOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_TIME_ZONE_ID));
optionRepository.update(Option.ID_C_TIME_ZONE_ID, timeZoneIdOpt);
......
......@@ -29,15 +29,12 @@ import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.solo.model.Option;
import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.util.Skins;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.Set;
import static org.b3log.solo.model.Skin.SKINS;
import static org.b3log.solo.model.Skin.SKIN_DIR_NAME;
import static org.b3log.solo.util.Skins.getSkinDirNames;
/**
* Skin management service.
*
......@@ -78,10 +75,7 @@ public class SkinMgmtService {
* @throws Exception exception
*/
public void loadSkins(final JSONObject skin) throws Exception {
Stopwatchs.start("Load Skins");
LOGGER.debug("Loading skins....");
final Set<String> skinDirNames = getSkinDirNames();
final Set<String> skinDirNames = Skins.getSkinDirNames();
LOGGER.log(Level.DEBUG, "Loaded skins [dirNames={0}]", skinDirNames);
final JSONArray skinArray = new JSONArray();
for (final String dirName : skinDirNames) {
......@@ -93,11 +87,11 @@ public class SkinMgmtService {
continue;
}
s.put(SKIN_DIR_NAME, dirName);
s.put(Option.ID_C_SKIN_DIR_NAME, dirName);
skinArray.put(s);
}
final String currentSkinDirName = skin.optString(SKIN_DIR_NAME);
final String currentSkinDirName = skin.optString(Option.ID_C_SKIN_DIR_NAME);
if (!skinDirNames.contains(currentSkinDirName)) {
LOGGER.log(Level.WARN, "Configured skin [dirName={0}] can not find, try to use " + "default skin [dirName="
+ Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME + "] instead.", currentSkinDirName);
......@@ -107,20 +101,9 @@ public class SkinMgmtService {
System.exit(-1);
}
skin.put(SKIN_DIR_NAME, Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME);
skin.put(Option.ID_C_SKIN_DIR_NAME, Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME);
updateSkin(skin);
}
final String skinsString = skinArray.toString();
if (!skinsString.equals(skin.getString(SKINS))) {
LOGGER.debug("The skins directory has been changed, persists it into database");
skin.put(SKINS, skinsString);
updateSkin(skin);
}
LOGGER.debug("Loaded skins....");
Stopwatchs.end();
}
/**
......
......@@ -58,6 +58,7 @@ public final class V340_350 {
final Transaction transaction = optionRepository.beginTransaction();
optionRepository.remove("skinName");
optionRepository.remove("skins");
final JSONObject skinOpt = optionRepository.get(Option.ID_C_SKIN_DIR_NAME);
skinOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_SKIN);
optionRepository.update(Option.ID_C_SKIN_DIR_NAME, skinOpt);
......
......@@ -33,7 +33,6 @@ import org.b3log.latke.util.Locales;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Skin;
import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
......@@ -219,7 +218,7 @@ public final class Skins {
*/
public static String getSkinDirName(final RequestContext context) {
// 1. Get skin from query
final String specifiedSkin = context.param(Skin.SKIN);
final String specifiedSkin = context.param(Option.CATEGORY_C_SKIN);
if (StringUtils.isNotBlank(specifiedSkin)) {
final Set<String> skinDirNames = Skins.getSkinDirNames();
if (skinDirNames.contains(specifiedSkin)) {
......@@ -243,7 +242,7 @@ public final class Skins {
final Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (final Cookie cookie : cookies) {
if (Skin.SKIN.equals(cookie.getName())) {
if (Option.CATEGORY_C_SKIN.equals(cookie.getName())) {
final String skin = cookie.getValue();
final Set<String> skinDirNames = Skins.getSkinDirNames();
......
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