summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/formatter.ex6
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex2
-rw-r--r--lib/pleroma/web/common_api/common_api.ex14
-rw-r--r--lib/pleroma/web/common_api/utils.ex34
-rw-r--r--lib/pleroma/web/nodeinfo/nodeinfo_controller.ex31
-rw-r--r--lib/pleroma/web/twitter_api/controllers/util_controller.ex1
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex2
7 files changed, 81 insertions, 9 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index d5565a2ca..5b63fb795 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -192,7 +192,11 @@ defmodule Pleroma.Formatter do
]
# TODO: make it use something other than @link_regex
- def html_escape(text) do
+ def html_escape(text, "text/html") do
+ HTML.filter_tags(text)
+ end
+
+ def html_escape(text, "text/plain") do
Regex.split(@link_regex, text, include_captures: true)
|> Enum.map_every(2, fn chunk ->
{:safe, part} = Phoenix.HTML.html_escape(chunk)
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index e03e7c471..fc191addf 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -756,7 +756,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
{:ok, Object.normalize(activity.data["object"])}
else
- {:reject, nil} ->
+ {:error, {:reject, nil}} ->
{:reject, nil}
object = %Object{} ->
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 125c57d05..d4a973e36 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -73,6 +73,11 @@ defmodule Pleroma.Web.CommonAPI do
def get_visibility(_), do: "public"
@instance Application.get_env(:pleroma, :instance)
+ @allowed_post_formats Keyword.get(@instance, :allowed_post_formats)
+
+ defp get_content_type(content_type) when content_type in @allowed_post_formats, do: content_type
+ defp get_content_type(_), do: "text/plain"
+
@limit Keyword.get(@instance, :limit)
def post(user, %{"status" => status} = data) do
visibility = get_visibility(data)
@@ -85,7 +90,14 @@ defmodule Pleroma.Web.CommonAPI do
{to, cc} <- to_for_user_and_mentions(user, mentions, inReplyTo, visibility),
tags <- Formatter.parse_tags(status, data),
content_html <-
- make_content_html(status, mentions, attachments, tags, data["no_attachment_links"]),
+ make_content_html(
+ status,
+ mentions,
+ attachments,
+ tags,
+ get_content_type(data["content_type"]),
+ data["no_attachment_links"]
+ ),
context <- make_context(inReplyTo),
cw <- data["spoiler_text"],
object <-
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 358ca22ac..667027c02 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -63,9 +63,16 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end
end
- def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
+ def make_content_html(
+ status,
+ mentions,
+ attachments,
+ tags,
+ content_type,
+ no_attachment_links \\ false
+ ) do
status
- |> format_input(mentions, tags)
+ |> format_input(mentions, tags, content_type)
|> maybe_add_attachments(attachments, no_attachment_links)
end
@@ -92,9 +99,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do
Enum.join([text | attachment_text], "<br>")
end
- def format_input(text, mentions, tags) do
+ def format_input(text, mentions, tags, "text/plain") do
text
- |> Formatter.html_escape()
+ |> Formatter.html_escape("text/plain")
|> String.replace(~r/\r?\n/, "<br>")
|> (&{[], &1}).()
|> Formatter.add_links()
@@ -103,6 +110,25 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|> Formatter.finalize()
end
+ def format_input(text, mentions, tags, "text/html") do
+ text
+ |> Formatter.html_escape("text/html")
+ |> String.replace(~r/\r?\n/, "<br>")
+ |> (&{[], &1}).()
+ |> Formatter.add_user_links(mentions)
+ |> Formatter.finalize()
+ end
+
+ def format_input(text, mentions, tags, "text/markdown") do
+ text
+ |> Earmark.as_html!()
+ |> Formatter.html_escape("text/html")
+ |> String.replace(~r/\r?\n/, "")
+ |> (&{[], &1}).()
+ |> Formatter.add_user_links(mentions)
+ |> Formatter.finalize()
+ end
+
def add_tag_links(text, tags) do
tags =
tags
diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index 9c4827426..a14000c61 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -27,6 +27,29 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
gopher = Application.get_env(:pleroma, :gopher)
stats = Stats.get_stats()
+ mrf_simple =
+ Application.get_env(:pleroma, :mrf_simple)
+ |> Enum.into(%{})
+
+ mrf_policies = Keyword.get(instance, :rewrite_policy)
+
+ mrf_policies =
+ if(is_list(mrf_policies)) do
+ mrf_policies
+ |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
+ else
+ [to_string(mrf_policies) |> String.split(".") |> List.last()]
+ end
+
+ quarantined = Keyword.get(instance, :quarantined_instances)
+
+ quarantined =
+ if is_list(quarantined) do
+ quarantined
+ else
+ []
+ end
+
staff_accounts =
User.moderator_user_query()
|> Repo.all()
@@ -64,7 +87,13 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
},
staffAccounts: staff_accounts,
chat: Keyword.get(chat, :enabled),
- gopher: Keyword.get(gopher, :enabled)
+ gopher: Keyword.get(gopher, :enabled),
+ federation: %{
+ mrf_policies: mrf_policies,
+ mrf_simple: mrf_simple,
+ quarantined_instances: quarantined
+ },
+ postFormats: Keyword.get(instance, :allowed_post_formats)
}
}
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index 886b70f5f..4aaf28869 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -176,6 +176,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
chatDisabled: !Keyword.get(@instance_chat, :enabled),
showInstanceSpecificPanel: Keyword.get(@instance_fe, :show_instance_panel),
scopeOptionsEnabled: Keyword.get(@instance_fe, :scope_options_enabled),
+ formattingOptionsEnabled: Keyword.get(@instance_fe, :formatting_options_enabled),
collapseMessageWithSubject: Keyword.get(@instance_fe, :collapse_message_with_subject)
}
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index cd2bb5b57..c6637e38d 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -423,7 +423,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{String.trim(name, ":"), url}
end)
- bio_html = CommonUtils.format_input(bio, mentions, tags)
+ bio_html = CommonUtils.format_input(bio, mentions, tags, "text/plain")
Map.put(params, "bio", bio_html |> Formatter.emojify(emoji))
else
params