+ * Created by Luis on 2018/4/30.
+ */
+@Component
+public final class AdminCommons {
+
+ /**
+ * 判断category和cat的交集
+ *
+ * @param cats
+ * @return
+ */
+ public static boolean exist_cat(MetaDomain category, String cats) {
+ String[] arr = StringUtils.split(cats, ",");
+ if (null != arr && arr.length > 0) {
+ for (String c : arr) {
+ if (c.trim().equals(category.getName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static final String[] COLORS = {"default", "primary", "success", "info", "warning", "danger", "inverse", "purple", "pink"};
+
+ public static String rand_color() {
+ int r = Tools.rand(0, COLORS.length - 1);
+ return COLORS[r];
+ }
+
+}
diff --git a/src/main/java/cn/luischen/utils/Commons.java b/src/main/java/cn/luischen/utils/Commons.java
new file mode 100644
index 00000000..1d3e02b1
--- /dev/null
+++ b/src/main/java/cn/luischen/utils/Commons.java
@@ -0,0 +1,480 @@
+package cn.luischen.utils;
+
+import cn.luischen.constant.WebConst;
+import cn.luischen.model.ContentDomain;
+import cn.luischen.model.OptionsDomain;
+import cn.luischen.service.option.OptionService;
+import com.github.pagehelper.PageInfo;
+import com.vdurmont.emoji.EmojiParser;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 公共函数
+ * Created by Donghua.Chen on 2018/4/30.
+ */
+@Component
+public class Commons {
+
+
+ /**
+ * 网站链接
+ *
+ * @return
+ */
+ public static String site_url() {
+ return site_url("");
+ }
+
+ /**
+ * 返回网站链接下的全址
+ *
+ * @param sub 后面追加的地址
+ * @return
+ */
+ public static String site_url(String sub) {
+ return site_option("site_url") + sub;
+ }
+
+
+ /**
+ * 文件上传,为文件重新命名
+ **/
+ public static String getFileRename(String name) {
+ Date date = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+ String sdfDate = sdf.format(date);
+ int pos = name.lastIndexOf(".");
+ String suffix = name.substring(pos);
+ String rename = sdfDate+suffix;
+ return rename;
+ }
+
+ /**
+ * 获取网站的描述
+ * @return
+ */
+ public static String site_desc(){
+ return site_option("site_description");
+ }
+
+ public static String site_keywords(){
+ return site_option("site_keywords");
+ }
+
+ /**
+ * 获取网站的备案信息
+ * @return
+ */
+ public static String site_record() {
+ return site_option("site_record");
+ }
+
+ /**
+ * 获取网站标题
+ * @return
+ */
+ public static String site_title() {
+ return site_option("site_title");
+ }
+
+ /**
+ * 网站配置项
+ *
+ * @param key
+ * @return
+ */
+ public static String site_option(String key) {
+ return site_option(key, "");
+ }
+
+ /**
+ * 获取GitHub地址
+ * @return
+ */
+ public static String social_github(){
+ return site_option("social_github");
+ }
+
+ /**
+ * 获取google网站验证码
+ * @return
+ */
+ public static String google_site_verification(){
+ return site_option("google_site_verification");
+ }
+
+ /**
+ * 获取百度网站验证码
+ * @return
+ */
+ public static String baidu_site_verification(){
+ return site_option("baidu_site_verification");
+ }
+ /**
+ * 网站配置项
+ *
+ * @param key
+ * @param defalutValue 默认值
+ * @return
+ */
+ public static String site_option(String key, String defalutValue) {
+ if (StringUtils.isBlank(key)) {
+ return "";
+ }
+ String str = WebConst.initConfig.get(key);
+ if (StringUtils.isNotBlank(str)) {
+ return str;
+ } else {
+ return defalutValue;
+ }
+ }
+
+ /**
+ * 格式化unix时间戳为日期
+ *
+ * @param unixTime
+ * @return
+ */
+ public static String fmtdate(Integer unixTime) {
+ return fmtdate(unixTime, "yyyy-MM-dd");
+ }
+
+ /**
+ * 格式化unix时间戳为日期
+ *
+ * @param unixTime
+ * @param patten
+ * @return
+ */
+ public static String fmtdate(Integer unixTime, String patten) {
+ if (null != unixTime && StringUtils.isNotBlank(patten)) {
+ return DateKit.formatDateByUnixTime(unixTime, patten);
+ }
+ return "";
+ }
+
+ /**
+ * 英文格式的日期
+ * @param unixTime
+ * @return
+ */
+ public static String fmtdate_en(Integer unixTime){
+ return fmtdate(unixTime,"MMM d, yyyy");
+ }
+
+
+ /**
+ * 英文格式的日期-月,日
+ * @param unixTime
+ * @return
+ */
+ public static String fmtdate_en_m(Integer unixTime){
+ return fmtdate(unixTime,"MMM d");
+ }
+
+ /**
+ * 日期-年
+ * @param unixTime
+ * @return
+ */
+ public static String fmtdate_en_y(Integer unixTime){
+ return fmtdate(unixTime,"yyyy");
+ }
+
+ /**
+ * 将中文的yyyy年MM月 - > yyyy
+ * @param date
+ * @return
+ */
+ public static String parsedate_zh_y_m(String date){
+ if (StringUtils.isNotBlank(date)){
+ Date d = DateKit.dateFormat(date, "yyyy年MM月");
+ return DateKit.dateFormat(d, "yyyy");
+ }
+ return null;
+ }
+
+ /**
+ * 字符串转Date
+ * @param date
+ * @return
+ */
+ public static Date fmtdate_date(String date){
+ if (StringUtils.isNotBlank(date)){
+ return DateKit.dateFormat(date, "yyyy年MM月");
+ }
+ return null;
+ }
+
+ /**
+ * 根据nuix时间戳获取Date
+ * @param nuixTime
+ * @return
+ */
+ public static Date fmtdate_unxtime(Integer nuixTime){
+ if (null != nuixTime){
+ return DateKit.getDateByUnixTime(nuixTime);
+ }
+ return null;
+ }
+ /**
+ * 获取社交的链接地址
+ *
+ * @return
+ */
+ public static Map
+ * 这种格式的字符转换为emoji表情
+ *
+ * @param value
+ * @return
+ */
+ public static String emoji(String value) {
+ return EmojiParser.parseToUnicode(value);
+ }
+
+ /**
+ * 获取随机数
+ *
+ * @param max
+ * @param str
+ * @return
+ */
+ public static String random(int max, String str) {
+ return UUID.random(1, max) + str;
+ }
+
+ /**
+ * 返回github头像地址
+ *
+ * @param email
+ * @return
+ */
+ public static String gravatar(String email) {
+ String avatarUrl = "https://github.com/identicons/";
+ if (StringUtils.isBlank(email)) {
+ email = "user@hanshuai.xin";
+ }
+ String hash = TaleUtils.MD5encode(email.trim().toLowerCase());
+ return avatarUrl + hash + ".png";
+ }
+
+ /**
+ * 显示文章内容,转换markdown为html
+ *
+ * @param value
+ * @return
+ */
+ public static String article(String value) {
+ if (StringUtils.isNotBlank(value)) {
+ value = value.replace("", "\r\n");
+ value = value.replace("", "\r\n");
+ return TaleUtils.mdToHtml(value);
+ }
+ return "";
+ }
+
+ /**
+ * 返回文章链接地址
+ *
+ * @param contents
+ * @return
+ */
+ public static String permalink(ContentDomain contents) {
+ return permalink(contents.getCid(), contents.getSlug());
+ }
+
+
+
+ /**
+ * 返回文章链接地址
+ *
+ * @param cid
+ * @param slug
+ * @return
+ */
+ public static String permalink(Integer cid, String slug) {
+ return site_url("/article/" + (StringUtils.isNotBlank(slug) ? slug : cid.toString()));
+ }
+
+ /**
+ * 判断分页中是否有数据
+ *
+ * @param paginator
+ * @return
+ */
+ public static boolean is_empty(PageInfo paginator) {
+ return paginator == null || (paginator.getList() == null) || (paginator.getList().size() == 0);
+ }
+
+ /**
+ * 截取字符串
+ *
+ * @param str
+ * @param len
+ * @return
+ */
+ public static String substr(String str, int len) {
+ if (str.length() > len) {
+ return str.substring(0, len);
+ }
+ return str;
+ }
+
+ /**
+ * 返回作品文章地址
+ * @param cid
+ * @return
+ */
+ public static String photoPermalink(Integer cid) {
+ return site_url("/photo/article/" + cid.toString());
+ }
+
+ /**
+ * 返回blog文章地址
+ * @param cid
+ * @return
+ */
+ public static String blogPermalink(Integer cid) {
+ return site_url("/blog/article/" + cid.toString());
+ }
+
+ /**
+ * 获取blog归档地址
+ * @param date
+ * @return
+ */
+ public static String archivePermalink(String date){
+ return site_url("/blog/archives/" + date);
+ }
+
+
+ public static String archiveYearPermalink(String date){
+ return site_url("/blog/archives/year/" + date);
+ }
+ /**
+ * 返回blog分类的地址
+ * @param categorie
+ * @return
+ */
+ public static String categoriePermalink(String categorie){
+ return site_url("/blog/categories/" + categorie);
+ }
+
+ /**
+ * 返回blog标签页的地址
+ * @param tag
+ * @return
+ */
+ public static String tagPermalink(String tag){
+ return site_url("/blog/tag/" + tag);
+ }
+ /**
+ * 获取文章第一张图片
+ *
+ * @return
+ */
+ public static String show_thumb(String content) {
+ content = TaleUtils.mdToHtml(content);
+ if (content.contains("|\\s+)").matcher(img);
+ if (m.find()) {
+ return m.group(1);
+ }
+ }
+ }
+ return "";
+ }
+
+ /**
+ * 显示分类
+ *
+ * @param categories
+ * @return
+ */
+ public static String show_categories(String categories) throws UnsupportedEncodingException {
+ if (StringUtils.isNotBlank(categories)) {
+ String[] arr = categories.split(",");
+ StringBuffer sbuf = new StringBuffer();
+ for (String c : arr) {
+ sbuf.append("" + c + "");
+ }
+ return sbuf.toString();
+ }
+ return show_categories("默认分类");
+ }
+
+ /**
+ * 显示标签
+ *
+ * @param tags
+ * @return
+ */
+ public static String show_tags(String tags) throws UnsupportedEncodingException {
+ if (StringUtils.isNotBlank(tags)) {
+ String[] arr = tags.split(",");
+ StringBuffer sbuf = new StringBuffer();
+ for (String c : arr) {
+ sbuf.append("