[Rt-commit] r5031 - in rt/branches/3.7-EXPERIMENTAL: . etc
html/Ticket/Elements
ruz at bestpractical.com
ruz at bestpractical.com
Thu Apr 13 21:08:30 EDT 2006
Author: ruz
Date: Thu Apr 13 21:08:29 2006
New Revision: 5031
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in
rt/branches/3.7-EXPERIMENTAL/html/Elements/MakeClicky
rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders
rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageStanza
Log:
r2380 at cubic-pc: cubic | 2006-04-14 05:15:42 +0400
* run MakeClicky after all callbacks
* run callbacks on unescaped content
* move escaping into MakeClicky component
* add httpurl_overwrite clicky action
* docs
Modified: rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in (original)
+++ rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in Thu Apr 13 21:08:29 2006
@@ -517,16 +517,21 @@
'<small>__LastUpdatedRelative__</small>',
'<small>__TimeLeft__</small>'});
-# RT provides a tool called MakeClicky that can detect various formats
-# of data in headers and email messages, and extend them with various
-# supporting links. By default, RT only provides one format,
-# 'httpurl', which detects http:// and https:// URLs. It is disabled
-# by default; to enable it, add 'httpurl' to the line below. Other
-# products, such as RTIR, may add additional kinds of MakeClicky
-# types. See html/Elements/MakeClicky for documentation on how to add
-# your own.
-Set(@Active_MakeClicky, qw());
+# 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 and *adds spaces* into text if it's longer
+# then 30 chars. This allow browser to wrap long URLs and avoid
+# horizontal scrolling.
+#
+# See html/Elements/MakeClicky for documentation on how to add your own.
+Set(@Active_MakeClicky, qw());
# }}}
Modified: rt/branches/3.7-EXPERIMENTAL/html/Elements/MakeClicky
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Elements/MakeClicky (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Elements/MakeClicky Thu Apr 13 21:08:29 2006
@@ -11,6 +11,14 @@
my $result = qq{[<a target="new" href="$args{value}">}. loc('open URL') .qq{</a>]};
return $args{value} . qq{ <span class="clickylink">$result</span>};
},
+ url_overwrite => sub {
+ my %args = @_;
+ my $result = qq{<a target="new" href="$args{'value'}">};
+ #XXX: use spaces here. ­ <wbr> are not well supported :(
+ $args{'value'} =~ s/(\S{30})/$1 /g;
+ $result .= qq{$args{'value'}</a>};
+ return qq{<span class="clickylink">$result</span>};
+ },
);
my @types = (
@@ -19,6 +27,11 @@
regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
action => "url",
},
+ {
+ name => "httpurl_overwrite",
+ regex => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
+ action => "url_overwrite",
+ },
);
my $handle = sub {
@@ -39,7 +52,7 @@
# Filter
my %active;
$active{$_}++ for RT->Config->Get('Active_MakeClicky');
- at types = grep {$active{$_->{name}}} @types;
+ at types = grep $active{$_->{name}}, @types;
# Build up the whole match
my $regexp = join "|",
@@ -60,18 +73,49 @@
$content => undef
</%ARGS>
<%INIT>
-return unless $regexp;
return unless defined $$content;
+unless ( $regexp ) {
+ RT::Interface::Web::EscapeUTF8( $content );
+ return;
+}
-$$content =~ s/($regexp)/$handle->( %ARGS, value => ($1 || '') )/gsieo;
+my $pos = 0;
+while ( $$content =~ /($regexp)/gsio ) {
+ my $match_start = pos($$content) - length($1);
+ if ( $match_start != $pos ) {
+ my $plain = substr( $$content, $pos, $match_start );
+ RT::Interface::Web::EscapeUTF8( \$plain );
+ substr( $$content, $pos, $match_start ) = $plain;
+ $match_start = $pos + length($plain);
+ }
+ {
+ my $plain = $handle->( %ARGS, value => ($1 || '') );
+ substr( $$content, $match_start, length($1) ) = $plain;
+ pos($$content) = $pos = $match_start + length($plain);
+ }
+}
+{
+ my $plain = substr( $$content, $pos );
+ RT::Interface::Web::EscapeUTF8( \$plain );
+ substr( $$content, $pos ) = $plain;
+}
</%INIT>
<%doc>
MakeClicky detects various formats of data in headers and email
-messages, and extends them with supporting links. By default, RT only
-provides one format, 'httpurl', which detects http:// and https://
-URLs. To extend this with your own types od data, use the callback.
+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 and *adds spaces* into text if it's longer
+ then 30 chars. This allow browser to wrap long URLs and avoid
+ horizontal scrolling.
+
+To extend this with your own types od data, use the callback.
It will be provided with:
* 'types': An array reference of hash references. Modify this array
@@ -85,10 +129,10 @@
* '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.
+ 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
+ have to. This can be used to add pre- or post-processing around
all actions.
</%doc>
Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders Thu Apr 13 21:08:29 2006
@@ -59,20 +59,8 @@
push @headers, { Tag => $tag, Value => $value };
}
-# apply html escaping on the original content
-# we'll display the value without escaping later (for MakeClicky et al.)
-foreach ( @headers ) {
- $_->{'Value'} = $m->interp->apply_escapes( $_->{Value}, 'h' );
-}
-
my %display_headers = map { lc($_) => 1 } @DisplayHeaders;
-my $ticket = $Message->TransactionObj->TicketObj;
-foreach my $f (@headers) {
- next unless $display_headers{'_all'} || $display_headers{ lc $f->{'Tag'} };
- $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, ticket => $ticket, %ARGS);
-}
-
$m->comp( '/Elements/Callback',
message => $Message,
headers => \@headers,
@@ -80,9 +68,14 @@
);
unless ( $display_headers{'_all'} ) {
- @headers = grep $display_headers{ lc $_->{'Tag'} },
- @headers;
+ @headers = grep $display_headers{ lc $_->{'Tag'} }, @headers;
}
+
+my $ticket = $Message->TransactionObj->TicketObj;
+foreach my $f (@headers) {
+ $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, ticket => $ticket, %ARGS);
+}
+
if ( $Localize ) {
$_->{'Tag'} = loc($_->{'Tag'}) foreach @headers;
}
Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageStanza
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageStanza (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageStanza Thu Apr 13 21:08:29 2006
@@ -55,27 +55,24 @@
}
elsif ( ref $stanza eq "HASH" ) {
my $content = $stanza->{raw};
- RT::Interface::Web::EscapeUTF8(\$content);
- $m->comp('/Elements/MakeClicky', content => \$content, ticket => $ticket, %ARGS);
- $m->comp('/Elements/Callback', content => \$content, %ARGS);
- $content =~ s{$}{<br />}mg
- if defined $content;
-
+ $print_content->( \$content );
+ }
+}
</%perl>
-<%$content |n%>
-% }
-% } # end foreach
</div>
% } else {
-% my $content = $Message;
-% RT::Interface::Web::EscapeUTF8(\$content);
-% $m->comp('/Elements/MakeClicky', content => \$content, ticket => $ticket, %ARGS);
-% $m->comp('/Elements/Callback', content => \$content, %ARGS);
-% $content =~ s{$}{<br />}mg;
-<%$content |n%>
+% $print_content->( \$Message );
% }
<%INIT>
my $ticket = $Transaction ? $Transaction->TicketObj : undef;
+
+my $print_content = sub {
+ my $ref = shift;
+ $m->comp('/Elements/Callback', content => $ref, %ARGS);
+ $m->comp('/Elements/MakeClicky', content => $ref, ticket => $ticket, %ARGS);
+ $$ref =~ s{$}{<br />}mg if defined $$ref;
+ $m->out( $$ref );
+};
</%INIT>
<%ARGS>
$Message => undef
More information about the Rt-commit
mailing list