X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FElements%2FMakeClicky;h=7c2de834ddaf2ecc7becda673d5593f5173fdd95;hp=dabe3bb33b7701ba3f94b823523998bda248ec79;hb=7322f2afedcc2f427e997d1535a503613a83f088;hpb=7588a4ac90a9b07c08a3107cd1107d773be1c991 diff --git a/rt/share/html/Elements/MakeClicky b/rt/share/html/Elements/MakeClicky index dabe3bb33..7c2de834d 100644 --- a/rt/share/html/Elements/MakeClicky +++ b/rt/share/html/Elements/MakeClicky @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -50,7 +50,7 @@ use Regexp::Common qw(URI); my $escaper = sub { my $content = shift; - RT::Interface::Web::EscapeUTF8( \$content ); + RT::Interface::Web::EscapeHTML( \$content ); return $content; }; @@ -61,27 +61,31 @@ my %actions = ( }, url => sub { my %args = @_; + my $post = ""; + $post = ")" if $args{value} !~ /\(/ and $args{value} =~ s/\)$//; $args{value} = $escaper->($args{value}); - my $result = qq{[}. loc('Open URL') .qq{]}; - return $args{value} . qq{ $result}; + my $result = qq{[}. loc('Open URL') .qq{]}; + return $args{value} . qq{ $result$post}; }, url_overwrite => sub { my %args = @_; + my $post = ""; + $post = ")" if $args{value} !~ /\(/ and $args{value} =~ s/\)$//; $args{value} = $escaper->($args{value}); - my $result = qq{$args{value}}; - return qq{$result}; + my $result = qq{$args{value}}; + return qq{$result$post}; }, ); my @types = ( { name => "httpurl", - regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}(?:#\S+)?/, + regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}(?:#[^\s<]+)?(? "url", }, { name => "httpurl_overwrite", - regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}(?:#\S+)?/, + regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}(?:#[^\s<]+)?(? "url_overwrite", }, ); @@ -96,6 +100,8 @@ my $handle = sub { } }; +my $cache; # only defined via callback + # Hook to add more Clicky types # XXX Have to have Page argument, as Mason gets caller wrong in Callback? # This happens as we are in <%ONCE> block @@ -104,6 +110,7 @@ $m->callback( types => \@types, actions => \%actions, handle => \$handle, + cache => \$cache, ); @@ -131,15 +138,24 @@ $html => undef <%INIT> return unless defined $$content; +if ( defined $cache ) { + my $cached_content = $cache->(fetch => $content); + if ( $cached_content ) { + RT->Logger->debug("Found MakeClicky cache"); + $$content = $cached_content; + return; + } +} + unless ( $regexp ) { - RT::Interface::Web::EscapeUTF8( $content ) unless $html; + RT::Interface::Web::EscapeHTML( $content ) unless $html; return; } my $pos = 0; while ( $$content =~ /($regexp)/gsio ) { my $match = $1; - next if $` =~ /href=(?:"|")$/; + next if $` =~ /\w+=(?:"|")$/; my $skipped_len = pos($$content) - $pos - length($match); if ( $skipped_len > 0 ) { my $plain; @@ -165,40 +181,6 @@ substr( $$content, $pos ) = $escaper->( substr( $$content, $pos ) ) unless ($pos == length $$content) || $html; pos($$content) = 0; +$cache->(store => $content) if defined $cache; -<%doc> - -MakeClicky detects various formats of data in headers and email -messages, and extends them with supporting links. By default, RT -provides two formats: - - * 'httpurl': detects http:// and https:// URLs and adds '[Open URL]' - link after the URL. - - * 'httpurl_overwrite': also detects URLs as 'httpurl' format, but - replace URL with link. - -To extend this with your own types of data, use the callback. -It will be provided with: - - * 'types': An array reference of hash references. Modify this array - reference to add your own types; the first matching type will be - used. Each hashref should contain: - - 'name': The name of the data format; this is used in the - configuration file to enable the format. - - 'regex': A regular expression to match against - - 'action': The name of the action to run (see "actions", below) - - * 'actions': A hash reference of 'actions'. Modify this hash - reference to change or add action types. Values are subroutine - references which will get called when needed. They should return - the modified string. Note that subroutine must escape HTML. - - * 'handler': A reference to a subroutine reference; modify it if you - have to. This can be used to add pre- or post-processing around - all actions. - -Read more about writing new actions in docs/extending/clickable_links.pod - -