Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
02edff31
Unverified
Commit
02edff31
authored
Jun 01, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
#12787
parent
7251371f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
21 deletions
+148
-21
src/main/java/org/b3log/solo/upgrade/V361_362.java
src/main/java/org/b3log/solo/upgrade/V361_362.java
+122
-0
src/main/java/org/b3log/solo/util/Emotions.java
src/main/java/org/b3log/solo/util/Emotions.java
+26
-21
No files found.
src/main/java/org/b3log/solo/upgrade/V361_362.java
0 → 100644
View file @
02edff31
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* 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
.
upgrade
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.ioc.BeanManager
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.repository.Query
;
import
org.b3log.latke.repository.Transaction
;
import
org.b3log.solo.model.Article
;
import
org.b3log.solo.model.Comment
;
import
org.b3log.solo.model.Option
;
import
org.b3log.solo.repository.ArticleRepository
;
import
org.b3log.solo.repository.CommentRepository
;
import
org.b3log.solo.repository.OptionRepository
;
import
org.b3log.solo.util.Emotions
;
import
org.json.JSONObject
;
import
java.util.List
;
/**
* Upgrade script from v3.6.1 to v3.6.2.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jun 1, 2019
* @since 3.6.2
*/
public
final
class
V361_362
{
/**
* Logger.
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
V361_362
.
class
);
/**
* Performs upgrade from v3.6.1 to v3.6.2.
*
* @throws Exception upgrade fails
*/
public
static
void
perform
()
throws
Exception
{
final
String
fromVer
=
"3.6.1"
;
final
String
toVer
=
"3.6.2"
;
LOGGER
.
log
(
Level
.
INFO
,
"Upgrading from version ["
+
fromVer
+
"] to version ["
+
toVer
+
"]...."
);
final
BeanManager
beanManager
=
BeanManager
.
getInstance
();
final
OptionRepository
optionRepository
=
beanManager
.
getReference
(
OptionRepository
.
class
);
final
ArticleRepository
articleRepository
=
beanManager
.
getReference
(
ArticleRepository
.
class
);
final
CommentRepository
commentRepository
=
beanManager
.
getReference
(
CommentRepository
.
class
);
try
{
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
);
// 迁移历史表情图片 https://github.com/b3log/solo/issues/12787
final
List
<
JSONObject
>
articles
=
articleRepository
.
getList
(
new
Query
());
for
(
final
JSONObject
article
:
articles
)
{
String
articleContent
=
article
.
optString
(
Article
.
ARTICLE_CONTENT
);
articleContent
=
Emotions
.
convert
(
articleContent
);
articleContent
=
convertEm00
(
articleContent
);
article
.
put
(
Article
.
ARTICLE_CONTENT
,
articleContent
);
articleRepository
.
update
(
article
.
optString
(
Keys
.
OBJECT_ID
),
article
);
}
final
List
<
JSONObject
>
comments
=
commentRepository
.
getList
(
new
Query
());
for
(
final
JSONObject
comment
:
comments
)
{
String
commentContent
=
comment
.
optString
(
Comment
.
COMMENT_CONTENT
);
commentContent
=
Emotions
.
convert
(
commentContent
);
commentContent
=
convertEm00
(
commentContent
);
comment
.
put
(
Comment
.
COMMENT_CONTENT
,
commentContent
);
commentRepository
.
update
(
comment
.
optString
(
Keys
.
OBJECT_ID
),
comment
);
}
transaction
.
commit
();
LOGGER
.
log
(
Level
.
INFO
,
"Upgraded from version ["
+
fromVer
+
"] to version ["
+
toVer
+
"] successfully"
);
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Upgrade failed!"
,
e
);
throw
new
Exception
(
"Upgrade failed from version ["
+
fromVer
+
"] to version ["
+
toVer
+
"]"
);
}
}
private
static
String
convertEm00
(
final
String
content
)
{
String
ret
=
StringUtils
.
replace
(
content
,
"[em00]"
,
"\uD83D\uDE04"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em01]"
,
"\uD83D\uDE02"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em02]"
,
"\uD83D\uDE1C"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em03]"
,
"\uD83D\uDE2B"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em04]"
,
"\uD83D\uDE2D"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em05]"
,
"\uD83D\uDE30"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em06]"
,
"\uD83D\uDE21"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em07]"
,
"\uD83D\uDE24"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em08]"
,
"\uD83D\uDC40"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em09]"
,
"\uD83D\uDE31"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em10]"
,
"\uD83D\uDE0E"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em11]"
,
"\uD83D\uDE0B"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em12]"
,
"❤️"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em13]"
,
"\uD83D\uDC94"
);
ret
=
StringUtils
.
replace
(
ret
,
"[em14]"
,
"\uD83D\uDC7F"
);
return
ret
;
}
}
src/main/java/org/b3log/solo/util/Emotions.java
View file @
02edff31
...
...
@@ -17,6 +17,8 @@
*/
package
org
.
b3log
.
solo
.
util
;
import
com.vdurmont.emoji.EmojiParser
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Latkes
;
import
java.util.regex.Pattern
;
...
...
@@ -25,47 +27,50 @@ import java.util.regex.Pattern;
* Emotions utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.
0, Mar 15
, 2019
* @version 1.1.0.
1, Jun 1
, 2019
* @since 1.4.0
*/
public
final
class
Emotions
{
/**
* Emoji pattern.
*/
public
static
final
Pattern
EMOJI_PATTERN
=
Pattern
.
compile
(
":.+:"
);
/**
* Converts the specified content with emotions.
* <p>
* <ol>
* <li>Emoji: http://www.emoji-cheat-sheet.com</li>
* </ol>
*
* @param content the specified content
* @return converted content
*/
public
static
String
convert
(
final
String
content
)
{
final
String
staticServePath
=
Latkes
.
getStaticServePath
();
String
ret
=
content
;
if
(!
EMOJI_PATTERN
.
matcher
(
ret
).
find
())
{
return
ret
;
}
for
(
final
String
emojiCode
:
EMOJIS
)
{
final
String
emoji
=
":"
+
emojiCode
+
":"
;
String
repl
=
"<img align=\"absmiddle\" alt=\""
+
emoji
+
"\" class=\"emoji\" src=\""
+
staticServePath
+
"/js/lib/emojify.js-1.1.0/images/basic/"
+
emojiCode
;
final
String
suffix
=
"huaji"
.
equals
(
emojiCode
)
?
".gif"
:
".png"
;
repl
+=
suffix
+
"\" title=\""
+
emoji
+
"\" width=\"20px\" height=\"20px\"></img>"
;
ret
=
ret
.
replace
(
emoji
,
repl
);
}
ret
=
toUnicode
(
ret
);
String
repl
=
"<img align=\"absmiddle\" alt=\":huaji:\" class=\"emoji\" src=\""
+
Latkes
.
getStaticServePath
()
+
"/js/lib/emojify.js-1.1.0/images/basic/huaji.gif"
+
"\" title=\":huaji:\" width=\"20px\" height=\"20px\"></img>"
;
ret
=
StringUtils
.
replace
(
ret
,
":huaji:"
,
repl
);
return
ret
;
}
/**
* Replaces the emoji's alias by its unicode. Example: ":smile:" gives "😄".
*
* @param content the specified string to parse
* @return the string with the mojis replaces by their unicode
*/
private
static
String
toUnicode
(
final
String
content
)
{
String
ret
=
EmojiParser
.
parseToUnicode
(
content
);
ret
=
ret
.
replace
(
"❤"
,
"❤️"
);
ret
=
ret
.
replace
(
"♥"
,
"❤️"
);
return
ret
;
}
/**
* Emoji pattern.
*/
private
static
final
Pattern
EMOJI_PATTERN
=
Pattern
.
compile
(
":.+:"
);
/**
* Emoji list.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment