mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-27 08:16:16 +00:00
everywhere: use Pleroma.HTML module instead of HtmlSanitizeEx directly
This commit is contained in:
parent
255f46d7ab
commit
ac486fc59b
|
@ -1,6 +1,7 @@
|
||||||
defmodule Pleroma.Formatter do
|
defmodule Pleroma.Formatter do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
@tag_regex ~r/\#\w+/u
|
@tag_regex ~r/\#\w+/u
|
||||||
def parse_tags(text, data \\ %{}) do
|
def parse_tags(text, data \\ %{}) do
|
||||||
|
@ -144,8 +145,8 @@ defmodule Pleroma.Formatter do
|
||||||
|
|
||||||
def emojify(text, emoji) do
|
def emojify(text, emoji) do
|
||||||
Enum.reduce(emoji, text, fn {emoji, file}, text ->
|
Enum.reduce(emoji, text, fn {emoji, file}, text ->
|
||||||
emoji = HtmlSanitizeEx.strip_tags(emoji)
|
emoji = HTML.strip_tags(emoji)
|
||||||
file = HtmlSanitizeEx.strip_tags(file)
|
file = HTML.strip_tags(file)
|
||||||
|
|
||||||
String.replace(
|
String.replace(
|
||||||
text,
|
text,
|
||||||
|
@ -154,7 +155,7 @@ defmodule Pleroma.Formatter do
|
||||||
MediaProxy.url(file)
|
MediaProxy.url(file)
|
||||||
}' />"
|
}' />"
|
||||||
)
|
)
|
||||||
|> HtmlSanitizeEx.basic_html()
|
|> HTML.filter_tags()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
@instance Application.get_env(:pleroma, :instance)
|
@instance Application.get_env(:pleroma, :instance)
|
||||||
@gopher Application.get_env(:pleroma, :gopher)
|
@gopher Application.get_env(:pleroma, :gopher)
|
||||||
|
@ -79,7 +80,7 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
||||||
info("#{like_count} likes, #{announcement_count} repeats") <>
|
info("#{like_count} likes, #{announcement_count} repeats") <>
|
||||||
"i\tfake\t(NULL)\t0\r\n" <>
|
"i\tfake\t(NULL)\t0\r\n" <>
|
||||||
info(
|
info(
|
||||||
HtmlSanitizeEx.strip_tags(
|
HTML.strip_tags(
|
||||||
String.replace(activity.data["object"]["content"], "<br>", "\r")
|
String.replace(activity.data["object"]["content"], "<br>", "\r")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,6 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
def render("accounts.json", %{users: users} = opts) do
|
def render("accounts.json", %{users: users} = opts) do
|
||||||
render_many(users, AccountView, "account.json", opts)
|
render_many(users, AccountView, "account.json", opts)
|
||||||
|
@ -42,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
followers_count: user_info.follower_count,
|
followers_count: user_info.follower_count,
|
||||||
following_count: user_info.following_count,
|
following_count: user_info.following_count,
|
||||||
statuses_count: user_info.note_count,
|
statuses_count: user_info.note_count,
|
||||||
note: HtmlSanitizeEx.basic_html(user.bio) || "",
|
note: HTML.filter_tags(user.bio) || "",
|
||||||
url: user.ap_id,
|
url: user.ap_id,
|
||||||
avatar: image,
|
avatar: image,
|
||||||
avatar_static: image,
|
avatar_static: image,
|
||||||
|
|
|
@ -5,6 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
# TODO: Add cached version.
|
# TODO: Add cached version.
|
||||||
defp get_replied_to_activities(activities) do
|
defp get_replied_to_activities(activities) do
|
||||||
|
@ -111,10 +112,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
emojis =
|
emojis =
|
||||||
(activity.data["object"]["emoji"] || [])
|
(activity.data["object"]["emoji"] || [])
|
||||||
|> Enum.map(fn {name, url} ->
|
|> Enum.map(fn {name, url} ->
|
||||||
name = HtmlSanitizeEx.strip_tags(name)
|
name = HTML.strip_tags(name)
|
||||||
|
|
||||||
url =
|
url =
|
||||||
HtmlSanitizeEx.strip_tags(url)
|
HTML.strip_tags(url)
|
||||||
|> MediaProxy.url()
|
|> MediaProxy.url()
|
||||||
|
|
||||||
%{shortcode: name, url: url, static_url: url}
|
%{shortcode: name, url: url, static_url: url}
|
||||||
|
@ -221,7 +222,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
object["content"]
|
object["content"]
|
||||||
end
|
end
|
||||||
|
|
||||||
HtmlSanitizeEx.basic_html(content)
|
HTML.filter_tags(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_content(%{"type" => "Article"} = object) do
|
def render_content(%{"type" => "Article"} = object) do
|
||||||
|
@ -234,10 +235,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
object["content"]
|
object["content"]
|
||||||
end
|
end
|
||||||
|
|
||||||
HtmlSanitizeEx.basic_html(content)
|
HTML.filter_tags(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_content(object) do
|
def render_content(object) do
|
||||||
HtmlSanitizeEx.basic_html(object["content"])
|
HTML.filter_tags(object["content"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||||
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
|
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
defp user_by_ap_id(user_list, ap_id) do
|
defp user_by_ap_id(user_list, ap_id) do
|
||||||
Enum.find(user_list, fn %{ap_id: user_id} -> ap_id == user_id end)
|
Enum.find(user_list, fn %{ap_id: user_id} -> ap_id == user_id end)
|
||||||
|
@ -167,7 +168,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||||
{summary, content} = ActivityView.render_content(object)
|
{summary, content} = ActivityView.render_content(object)
|
||||||
|
|
||||||
html =
|
html =
|
||||||
HtmlSanitizeEx.basic_html(content)
|
HTML.filter_tags(content)
|
||||||
|> Formatter.emojify(object["emoji"])
|
|> Formatter.emojify(object["emoji"])
|
||||||
|
|
||||||
video =
|
video =
|
||||||
|
@ -184,7 +185,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||||
"uri" => activity.data["object"]["id"],
|
"uri" => activity.data["object"]["id"],
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
||||||
"statusnet_html" => html,
|
"statusnet_html" => html,
|
||||||
"text" => HtmlSanitizeEx.strip_tags(content),
|
"text" => HTML.strip_tags(content),
|
||||||
"is_local" => activity.local,
|
"is_local" => activity.local,
|
||||||
"is_post_verb" => true,
|
"is_post_verb" => true,
|
||||||
"created_at" => created_at,
|
"created_at" => created_at,
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@ -232,7 +233,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
|
||||||
{summary, content} = render_content(object)
|
{summary, content} = render_content(object)
|
||||||
|
|
||||||
html =
|
html =
|
||||||
HtmlSanitizeEx.basic_html(content)
|
HTML.filter_tags(content)
|
||||||
|> Formatter.emojify(object["emoji"])
|
|> Formatter.emojify(object["emoji"])
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
@ -240,7 +241,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
|
||||||
"uri" => activity.data["object"]["id"],
|
"uri" => activity.data["object"]["id"],
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
||||||
"statusnet_html" => html,
|
"statusnet_html" => html,
|
||||||
"text" => HtmlSanitizeEx.strip_tags(content),
|
"text" => HTML.strip_tags(content),
|
||||||
"is_local" => activity.local,
|
"is_local" => activity.local,
|
||||||
"is_post_verb" => true,
|
"is_post_verb" => true,
|
||||||
"created_at" => created_at,
|
"created_at" => created_at,
|
||||||
|
|
|
@ -4,6 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
alias Pleroma.HTML
|
||||||
|
|
||||||
def render("show.json", %{user: user = %User{}} = assigns) do
|
def render("show.json", %{user: user = %User{}} = assigns) do
|
||||||
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
|
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
|
||||||
|
@ -39,8 +40,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
||||||
data = %{
|
data = %{
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"description" =>
|
"description" =>
|
||||||
HtmlSanitizeEx.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
|
HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
|
||||||
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
"description_html" => HTML.filter_tags(user.bio),
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"followers_count" => user_info[:follower_count],
|
"followers_count" => user_info[:follower_count],
|
||||||
"following" => following,
|
"following" => following,
|
||||||
|
@ -49,7 +50,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
||||||
"friends_count" => user_info[:following_count],
|
"friends_count" => user_info[:following_count],
|
||||||
"id" => user.id,
|
"id" => user.id,
|
||||||
"name" => user.name,
|
"name" => user.name,
|
||||||
"name_html" => HtmlSanitizeEx.strip_tags(user.name) |> Formatter.emojify(emoji),
|
"name_html" => HTML.strip_tags(user.name) |> Formatter.emojify(emoji),
|
||||||
"profile_image_url" => image,
|
"profile_image_url" => image,
|
||||||
"profile_image_url_https" => image,
|
"profile_image_url_https" => image,
|
||||||
"profile_image_url_profile_size" => image,
|
"profile_image_url_profile_size" => image,
|
||||||
|
|
Loading…
Reference in a new issue