1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
49 use Regexp::Common qw(URI);
53 RT::Interface::Web::EscapeUTF8( \$content );
60 return $escaper->($args{value});
64 $args{value} = $escaper->($args{value});
65 my $result = qq{[<a target="new" href="$args{value}">}. loc('Open URL') .qq{</a>]};
66 return $args{value} . qq{ <span class="clickylink">$result</span>};
68 url_overwrite => sub {
70 my $result = qq{<a target="new" href="} . $escaper->($args{'value'}) . q{">};
71 #XXX: use spaces here. ­ <wbr> are not well supported :(
72 $args{'value'} =~ s/(\S{30})/$1 /g;
73 $result .= $escaper->($args{value}).qq{</a>};
74 return qq{<span class="clickylink">$result</span>};
81 regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
85 name => "httpurl_overwrite",
86 regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
87 action => "url_overwrite",
93 for my $rec( @types ) {
94 return $rec->{action}->(
96 all_matches => [ $args{value}, $1, $2, $3, $4, $5, $6, $7, $8, $9 ],
97 ) if $args{value} =~ $rec->{regex};
101 # Hook to add more Clicky types
102 # XXX Have to have Page argument, as Mason gets caller wrong in Callback?
103 # This happens as we are in <%ONCE> block
105 CallbackPage => "/Elements/MakeClicky",
107 actions => \%actions,
114 $active{$_}++ for RT->Config->Get('Active_MakeClicky');
115 @types = grep $active{$_->{name}}, @types;
117 # Build up the whole match
118 my $regexp = join "|", map $_->{regex}, @types;
120 # Make sure we have a default
121 $actions{default} ||= sub {};
123 # Anchor the regexes and look up the actions
124 foreach my $type ( @types ) {
125 $type->{regex} = qr/^$type->{regex}$/;
126 $type->{action} = $actions{$type->{action}} || $actions{default};
135 return unless defined $$content;
137 RT::Interface::Web::EscapeUTF8( $content ) unless $html;
142 while ( $$content =~ /($regexp)/gsio ) {
144 next if $` =~ /href=(?:"|")$/;
145 my $skipped_len = pos($$content) - $pos - length($match);
146 if ( $skipped_len > 0 ) {
149 $plain = substr( $$content, $pos, $skipped_len );
152 $plain = $escaper->( substr( $$content, $pos, $skipped_len ) )
154 substr( $$content, $pos, $skipped_len ) = $plain;
155 $pos += length($plain);
157 my $plain = $handle->(
160 all_matches => [ $1, $2, $3, $4, $5, $6, $7, $8, $9 ],
162 substr( $$content, $pos, length($match) ) = $plain;
163 pos($$content) = ( $pos += length($plain) );
166 substr( $$content, $pos ) = $escaper->( substr( $$content, $pos ) ) unless
167 ($pos == length $$content) || $html;
174 MakeClicky detects various formats of data in headers and email
175 messages, and extends them with supporting links. By default, RT
176 provides two formats:
178 * 'httpurl': detects http:// and https:// URLs and adds '[Open URL]'
181 * 'httpurl_overwrite': also detects URLs as 'httpurl' format, but
182 replace URL with link and *adds spaces* into text if it's longer
183 then 30 chars. This allow browser to wrap long URLs and avoid
184 horizontal scrolling.
186 To extend this with your own types of data, use the callback.
187 It will be provided with:
189 * 'types': An array reference of hash references. Modify this array
190 reference to add your own types; the first matching type will be
191 used. Each hashref should contain:
192 - 'name': The name of the data format; this is used in the
193 configuration file to enable the format.
194 - 'regex': A regular expression to match against
195 - 'action': The name of the action to run (see "actions", below)
197 * 'actions': A hash reference of 'actions'. Modify this hash
198 reference to change or add action types. Values are subroutine
199 references which will get called when needed. They should return
200 the modified string. Note that subroutine must escape HTML.
202 * 'handler': A reference to a subroutine reference; modify it if you
203 have to. This can be used to add pre- or post-processing around
206 Read more about writing new actions in docs/extending_clickable_links.pod