Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
ac486fc5
Commit
ac486fc5
authored
Sep 09, 2018
by
kaniini
Browse files
everywhere: use Pleroma.HTML module instead of HtmlSanitizeEx directly
parent
255f46d7
Changes
7
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/formatter.ex
View file @
ac486fc5
defmodule
Pleroma
.
Formatter
do
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
MediaProxy
alias
Pleroma
.
HTML
@tag_regex
~r/\#\w+/u
def
parse_tags
(
text
,
data
\\
%{})
do
...
...
@@ -144,8 +145,8 @@ def emojify(text, nil), do: text
def
emojify
(
text
,
emoji
)
do
Enum
.
reduce
(
emoji
,
text
,
fn
{
emoji
,
file
},
text
->
emoji
=
H
tmlSanitizeEx
.
strip_tags
(
emoji
)
file
=
H
tmlSanitizeEx
.
strip_tags
(
file
)
emoji
=
H
TML
.
strip_tags
(
emoji
)
file
=
H
TML
.
strip_tags
(
file
)
String
.
replace
(
text
,
...
...
@@ -154,7 +155,7 @@ def emojify(text, emoji) do
MediaProxy
.
url
(
file
)
}
' />"
)
|>
H
tmlSanitizeEx
.
basic_html
()
|>
H
TML
.
filter_tags
()
end
)
end
...
...
lib/pleroma/gopher/server.ex
View file @
ac486fc5
...
...
@@ -35,6 +35,7 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
alias
Pleroma
.
User
alias
Pleroma
.
Activity
alias
Pleroma
.
Repo
alias
Pleroma
.
HTML
@instance
Application
.
get_env
(
:pleroma
,
:instance
)
@gopher
Application
.
get_env
(
:pleroma
,
:gopher
)
...
...
@@ -79,7 +80,7 @@ def render_activities(activities) do
info
(
"
#{
like_count
}
likes,
#{
announcement_count
}
repeats"
)
<>
"i
\t
fake
\t
(NULL)
\t
0
\r\n
"
<>
info
(
H
tmlSanitizeEx
.
strip_tags
(
H
TML
.
strip_tags
(
String
.
replace
(
activity
.
data
[
"object"
][
"content"
],
"<br>"
,
"
\r
"
)
)
)
...
...
lib/pleroma/web/mastodon_api/views/account_view.ex
View file @
ac486fc5
...
...
@@ -4,6 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
alias
Pleroma
.
Web
.
MastodonAPI
.
AccountView
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
alias
Pleroma
.
Web
.
MediaProxy
alias
Pleroma
.
HTML
def
render
(
"accounts.json"
,
%{
users:
users
}
=
opts
)
do
render_many
(
users
,
AccountView
,
"account.json"
,
opts
)
...
...
@@ -42,7 +43,7 @@ def render("account.json", %{user: user}) do
followers_count:
user_info
.
follower_count
,
following_count:
user_info
.
following_count
,
statuses_count:
user_info
.
note_count
,
note:
H
tmlSanitizeEx
.
basic_html
(
user
.
bio
)
||
""
,
note:
H
TML
.
filter_tags
(
user
.
bio
)
||
""
,
url:
user
.
ap_id
,
avatar:
image
,
avatar_static:
image
,
...
...
lib/pleroma/web/mastodon_api/views/status_view.ex
View file @
ac486fc5
...
...
@@ -5,6 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
alias
Pleroma
.
Web
.
MediaProxy
alias
Pleroma
.
Repo
alias
Pleroma
.
HTML
# TODO: Add cached version.
defp
get_replied_to_activities
(
activities
)
do
...
...
@@ -111,10 +112,10 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
emojis
=
(
activity
.
data
[
"object"
][
"emoji"
]
||
[])
|>
Enum
.
map
(
fn
{
name
,
url
}
->
name
=
H
tmlSanitizeEx
.
strip_tags
(
name
)
name
=
H
TML
.
strip_tags
(
name
)
url
=
H
tmlSanitizeEx
.
strip_tags
(
url
)
H
TML
.
strip_tags
(
url
)
|>
MediaProxy
.
url
()
%{
shortcode:
name
,
url:
url
,
static_url:
url
}
...
...
@@ -221,7 +222,7 @@ def render_content(%{"type" => "Video"} = object) do
object
[
"content"
]
end
H
tmlSanitizeEx
.
basic_html
(
content
)
H
TML
.
filter_tags
(
content
)
end
def
render_content
(%{
"type"
=>
"Article"
}
=
object
)
do
...
...
@@ -234,10 +235,10 @@ def render_content(%{"type" => "Article"} = object) do
object
[
"content"
]
end
H
tmlSanitizeEx
.
basic_html
(
content
)
H
TML
.
filter_tags
(
content
)
end
def
render_content
(
object
)
do
H
tmlSanitizeEx
.
basic_html
(
object
[
"content"
])
H
TML
.
filter_tags
(
object
[
"content"
])
end
end
lib/pleroma/web/twitter_api/representers/activity_representer.ex
View file @
ac486fc5
...
...
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
alias
Pleroma
.
Web
.
TwitterAPI
.
{
TwitterAPI
,
UserView
,
ActivityView
}
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
alias
Pleroma
.
Formatter
alias
Pleroma
.
HTML
defp
user_by_ap_id
(
user_list
,
ap_id
)
do
Enum
.
find
(
user_list
,
fn
%{
ap_id:
user_id
}
->
ap_id
==
user_id
end
)
...
...
@@ -167,7 +168,7 @@ def to_map(
{
summary
,
content
}
=
ActivityView
.
render_content
(
object
)
html
=
H
tmlSanitizeEx
.
basic_html
(
content
)
H
TML
.
filter_tags
(
content
)
|>
Formatter
.
emojify
(
object
[
"emoji"
])
video
=
...
...
@@ -184,7 +185,7 @@ def to_map(
"uri"
=>
activity
.
data
[
"object"
][
"id"
],
"user"
=>
UserView
.
render
(
"show.json"
,
%{
user:
user
,
for:
opts
[
:for
]}),
"statusnet_html"
=>
html
,
"text"
=>
H
tmlSanitizeEx
.
strip_tags
(
content
),
"text"
=>
H
TML
.
strip_tags
(
content
),
"is_local"
=>
activity
.
local
,
"is_post_verb"
=>
true
,
"created_at"
=>
created_at
,
...
...
lib/pleroma/web/twitter_api/views/activity_view.ex
View file @
ac486fc5
...
...
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
alias
Pleroma
.
User
alias
Pleroma
.
Repo
alias
Pleroma
.
Formatter
alias
Pleroma
.
HTML
import
Ecto
.
Query
...
...
@@ -232,7 +233,7 @@ def render(
{
summary
,
content
}
=
render_content
(
object
)
html
=
H
tmlSanitizeEx
.
basic_html
(
content
)
H
TML
.
filter_tags
(
content
)
|>
Formatter
.
emojify
(
object
[
"emoji"
])
%{
...
...
@@ -240,7 +241,7 @@ def render(
"uri"
=>
activity
.
data
[
"object"
][
"id"
],
"user"
=>
UserView
.
render
(
"show.json"
,
%{
user:
user
,
for:
opts
[
:for
]}),
"statusnet_html"
=>
html
,
"text"
=>
H
tmlSanitizeEx
.
strip_tags
(
content
),
"text"
=>
H
TML
.
strip_tags
(
content
),
"is_local"
=>
activity
.
local
,
"is_post_verb"
=>
true
,
"created_at"
=>
created_at
,
...
...
lib/pleroma/web/twitter_api/views/user_view.ex
View file @
ac486fc5
...
...
@@ -4,6 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
alias
Pleroma
.
Formatter
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
alias
Pleroma
.
Web
.
MediaProxy
alias
Pleroma
.
HTML
def
render
(
"show.json"
,
%{
user:
user
=
%
User
{}}
=
assigns
)
do
render_one
(
user
,
Pleroma
.
Web
.
TwitterAPI
.
UserView
,
"user.json"
,
assigns
)
...
...
@@ -39,8 +40,8 @@ def render("user.json", %{user: user = %User{}} = assigns) do
data
=
%{
"created_at"
=>
user
.
inserted_at
|>
Utils
.
format_naive_asctime
(),
"description"
=>
H
tmlSanitizeEx
.
strip_tags
((
user
.
bio
||
""
)
|>
String
.
replace
(
"<br>"
,
"
\n
"
)),
"description_html"
=>
H
tmlSanitizeEx
.
basic_html
(
user
.
bio
),
H
TML
.
strip_tags
((
user
.
bio
||
""
)
|>
String
.
replace
(
"<br>"
,
"
\n
"
)),
"description_html"
=>
H
TML
.
filter_tags
(
user
.
bio
),
"favourites_count"
=>
0
,
"followers_count"
=>
user_info
[
:follower_count
],
"following"
=>
following
,
...
...
@@ -49,7 +50,7 @@ def render("user.json", %{user: user = %User{}} = assigns) do
"friends_count"
=>
user_info
[
:following_count
],
"id"
=>
user
.
id
,
"name"
=>
user
.
name
,
"name_html"
=>
H
tmlSanitizeEx
.
strip_tags
(
user
.
name
)
|>
Formatter
.
emojify
(
emoji
),
"name_html"
=>
H
TML
.
strip_tags
(
user
.
name
)
|>
Formatter
.
emojify
(
emoji
),
"profile_image_url"
=>
image
,
"profile_image_url_https"
=>
image
,
"profile_image_url_profile_size"
=>
image
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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