MakeClicky

From Request Tracker Wiki
Jump to navigation Jump to search

3.8.x

This is now built-in functionality. From RT_Config.pm:

=item C<@Active_MakeClicky> MakeClicky detects various formats of data in headers and email messages, and extends them with supporting links. By default, RT provides two formats: <ul> <li>'httpurl': detects http:// and https:// URLs and adds '[Open URL]' link after the URL.</li> <li>'httpurl_overwrite': also detects URLs as 'httpurl' format, but replace URL with link and <em>adds spaces</em> into text if it's longer then 30 chars. This allow browser to wrap long URLs and avoid horizontal scrolling. See F<share/html/Elements/MakeClicky> for documentation on how to add your own. =cut Set(@Active_MakeClicky, qw());

If you're new to this, the option you choose is contained in qw(), frex:

Set(@Active_MakeClicky, qw(httpurl));

Note that httpurl will result in things like

http://www.someplace.tld/path/morepath/etc/target.htm [Open URL]

where the [Open URL] is your clickable link. httpurl_overwrite will make the existing link clickable (oddly enough). Try both and see how it works on your links; don't forget to reload your webserver when you change it.

If you want to add your own actions be aware that the documentation in docs/extending_clickable_links.pod is not correct where it says to create the file ' local/html/MyCallbacks/Elements/MakeClicky/Default' it needs to be ' local/html/Callbacks/MyCallbacks/Elements/MakeClicky/Default' otherwise it will not be picked up by rt. Doc fixed in 3.8.5. NOTE that such things should be reported via bug tracker.

Known Problems

html #anchors

cp $RTHOME/share/html/Elements/MakeClicky $RTHOME/local/html/Elements/MakeClicky

 $EDITOR $RTHOME/local/html/Elements/MakeClicky

Now change regex to also match # qr@(?<!src=["'])https?:([\w\/\@-~%#?=;,.:+[]()]|\&|[])+[\w\/]@,

my @types = (

   {
       name   => "httpurl",
       regex  => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
       action => "url",
   },
   {
       name   => "httpurl_overwrite",
       #regex  => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
       regex  => qr@(?<!src=["'])https?:([\w\/\@-~%#?=;,.:+[]()]|\&|[])+[\w\/]@,
       action => "url_overwrite",
   },
 );

Earlier Versions

This is a patch to make links clickable when displaying a ticket. Works for 3.0, success has been reported for 3.4 too.

Regexp based on work by Abigail. As always, mind the tab damage.

$ diff -u /usr{,/local}/share/request-tracker3/html/Ticket/Elements/ShowMessageStanza

--- /usr/share/request-tracker3/html/Ticket/Elements/ShowMessageStanza  2004-02-13 19:21:02.000000000 +0100
+++ /usr/local/share/request-tracker3/html/Ticket/Elements/ShowMessageStanza   2005-05-08 01:04:15.000000000 +0200
@@ -37,6 +37,9 @@
         $m->comp('/Elements/Callback', content => \$content, %ARGS);
                 $content =~ s/\n/<br>/gi;
  • # Make URLs in plaintext clickable. This is dangerous!
  • $content =~ s@(https?://(?:(?:(?:(?:(?:a-zA-Z\d?).)(?:a-zA-Z?))|(?:(?:\d+)(?:.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[;:\@&=#]))(?:/(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[;:\@&=#]))))(?:\?(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[;:\@&=#])))?)?)|(?:ftp://(?:(?:(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[;?&=]))(?::(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])))?\@)?(?:(?:(?:(?:(?:a-zA-Z\d?).)(?:a-zA-Z?))|(?:(?:\d+)(?:.(?:\d+)){3}))(?::(?:\d+))?))(?:/(?:(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[?:\@&=]))(?:/(?:(?:(?:[a-zA-Z\d$-_.+!'(),]|(?:%[a-fA-F\d]{2}))|[?:\@&=]))))(?:;type=[AIDaid])?)?)|(?:mailto:(?:(?:[a-zA-Z\d$-_.+!*'(),;/?:\@&=]|(?:%[a-fA-F\d]{2}))+))@<a href=\"$1\" target=\"_blank\">$1</a>@g;
  • </%perl> <%$content |n%><br> % }

Alternatively you could implement this callback by Dirk Pape which goes in

[=$your-rt-path/local/html/Callbacks/MI/Ticket/Elements/ShowMessageStanza/Default]

<%init>

my $val = $$content;
use bytes;
$val =~ s/https?:([\w\/\@-~%#?=;,.:+]|\&)+[\w\/]/<a href="$&" target="_blank">$&<\/a>/gi;
$val =~ s/(s?ftp|ftps):[\w\/.:+-]+/<a href="$&">$&<\/a>/gi;
$val =~ s/(mailto:)?([a-zA-Z0-9_+-.]+\@([a-zA-Z0-9][\w.+-]+.[a-zA-Z]{2,})(\?([\w\/\@-~%#?=;,.:+]|\&)+[\w\/])?)/<a href="mailto:$2">$&<\/a>/gi;
$val =~ s/\<((url:\s*)?\w+:[^&<>]+)\>/<<a href="$1" target="_blank">$1<\/a>>/gi;
$$content = $val;
</%init>
<%args>
$content => undef
</%args>

For what it's worth, the above file content worked for me accept for the 6th line, which contains the "mailto:" parsing. My system complained about the syntax of this line. I deleted it from my Default file, and all works well on my resulting RT 3.4.2 system.

-Matt England


There was a typo in line 6. It read "$val =~ s/(mailto ... <\/a>/ gi;" but the space before "gi" is too much. I removed it, and removed the cached file [=/var/cache/request-tracker3.4/mason_data/obj/local/Callbacks/MI/Ticket/Elements/ShowMessageStanza/Default] (on our server). It then worked as expected.

-Andreas


A small enhancement to Disk's Callback method, where long http(s) URL's are truncated when displayed:

<%init>

my $val = $$content;
use bytes;
my @parts = ();
my @markup = ();

my $max_length = 67;

my $http_regex = 'https?:[\w\/\@-~%#?=;,.:+&]+[\w\/]';
my $ftp_regex = '(s?ftp|ftps):[\w\/.:+-]+';
my $mail_regex = '(mailto:)?([a-zA-Z0-9_+-.]+\@([a-zA-Z0-9][\w.+-]+.[a-zA-Z]{2,})(\?([\w\/\@-~%#?=;,.:+]|\&)+[\w\/])?)';
my $url_regex = '\<((url:\s*)?\w+:[^&<>]+)\>';

$val =~ s/$ftp_regex/<a href="$&">$&<\/a>/gi;

$val =~ s/$mail_regex/<a href="mailto:$2">$&<\/a>/gi;
$val =~ s/$url_regex/<a href="$1" target="_blank">$1<\/a>/gi;

@parts = split(/($http_regex)/, $val);

foreach my $bit (@parts) {
        if ($bit =~ m/$http_regex/) {
                if (length($bit) < $max_length) {
                        $bit = '<a href="'.$bit.'" target="_blank">'.$bit.'</a>';
                } else {
                        $bit = '<a href="'.$bit.'" target="_blank">'.substr($bit, 0, $max_length).'...</a>';
                }
        }
        push(@markup, $bit);
}

$$content = join("", @markup);

</%init>

<%args>

$content => undef
</%args>

-Shane PS Copy it in "Edit" mode Template:3.8.x Template:Configuration