aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/View
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/View')
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm30
1 files changed, 12 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 1e1b50094..8d3d53d0d 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -25,7 +25,7 @@ __PACKAGE__->config(
FILTERS => {
add_links => \&add_links,
escape_js => \&escape_js,
- markup => [ \&markup_factory, 1 ],
+ staff_html_markup => [ \&staff_html_markup_factory, 1 ],
},
COMPILE_EXT => '.ttc',
STAT_TTL => FixMyStreet->config('STAGING_SITE') ? 1 : 86400,
@@ -98,32 +98,26 @@ Add some links to some text (and thus HTML-escapes the other text).
sub add_links {
my $text = shift;
- $text = FixMyStreet::Template::conditional_escape($text);
- $text =~ s/\r//g;
- $text =~ s{(https?://)([^\s]+)}{"<a href=\"$1$2\">$1" . _space_slash($2) . '</a>'}ge;
- return FixMyStreet::Template::SafeString->new($text);
+ return FixMyStreet::Template::add_links($text);
}
-sub _space_slash {
- my $t = shift;
- $t =~ s{/(?!$)}{/ }g;
- return $t;
-}
+=head2 staff_html_markup_factory
-=head2 markup_factory
+This returns a function that processes the text body of an update, applying
+HTML sanitization and markdown-style italics if it was made by a staff user.
-This returns a function that will allow updates to have markdown-style italics.
-Pass in the user that wrote the text, so we know whether it can be privileged.
+Pass in the update extra, so we can determine if it was made by a staff user.
=cut
-sub markup_factory {
- my ($c, $user) = @_;
+sub staff_html_markup_factory {
+ my ($c, $extra) = @_;
+
+ my $staff = $extra->{is_superuser} || $extra->{is_body_user};
+
return sub {
my $text = shift;
- return $text unless $user && ($user->from_body || $user->is_superuser);
- $text =~ s{\*(\S.*?\S)\*}{<i>$1</i>};
- FixMyStreet::Template::SafeString->new($text);
+ return FixMyStreet::Template::_staff_html_markup($text, $staff);
}
}