diff options
Diffstat (limited to 'perllib/FixMyStreet/App/View/Web.pm')
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 42878be37..e4aafe951 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -18,8 +18,8 @@ __PACKAGE__->config( ENCODING => 'utf8', render_die => 1, expose_methods => [ - 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_epoch', - 'add_links', 'version', + 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_dt', + 'add_links', 'version', 'decode', ], FILTERS => { escape_js => \&escape_js, @@ -92,20 +92,20 @@ sub display_crosssell_advert { return CrossSell::display_advert( $c, $email, $name, %data ); } -=head2 Utils::prettify_epoch +=head2 Utils::prettify_dt - [% pretty = prettify_epoch( $epoch, $short_bool ) %] + [% pretty = prettify_dt( $dt, $short_bool ) %] -Return a pretty version of the epoch. +Return a pretty version of the DateTime object. $short_bool = 1; # 16:02, 29 Mar 2011 $short_bool = 0; # 16:02, Tuesday 29 March 2011 =cut -sub prettify_epoch { +sub prettify_dt { my ( $self, $c, $epoch, $short_bool ) = @_; - return Utils::prettify_epoch( $epoch, $short_bool ); + return Utils::prettify_dt( $epoch, $short_bool ); } =head2 add_links @@ -121,10 +121,16 @@ sub add_links { $text =~ s/\r//g; $text = ent($text); - $text =~ s{(https?://[^\s]+)}{<a href="$1">$1</a>}g; + $text =~ s{(https?://)([^\s]+)}{"<a href='$1$2'>$1" . _space_slash($2) . '</a>'}ge; return $text; } +sub _space_slash { + my $t = shift; + $t =~ s{/(?!$)}{/ }g; + return $t; +} + =head2 escape_js Used to escape strings that are going to be put inside JavaScript. @@ -175,5 +181,11 @@ sub version { return "$file?$version_hash{$file}"; } +sub decode { + my ( $self, $c, $text ) = @_; + utf8::decode($text) unless utf8::is_utf8($text); + return $text; +} + 1; |