| 1293 |
dpurdie |
1 |
package Codestriker::Template::Plugin::AutomagicLinks;
|
|
|
2 |
|
|
|
3 |
# Simple template toolkit plugin module for automagically changing all
|
|
|
4 |
# URLs to be hyperlinked, and all text in the form "Bug \d+" to be changed
|
|
|
5 |
# to link with the associated bug record if a bugtracking system is
|
|
|
6 |
# registered with the system.
|
|
|
7 |
|
|
|
8 |
use Template::Plugin::Filter;
|
|
|
9 |
use Codestriker;
|
|
|
10 |
|
|
|
11 |
use base qw( Template::Plugin::Filter );
|
|
|
12 |
|
|
|
13 |
sub filter {
|
|
|
14 |
my ($self, $text) = @_;
|
|
|
15 |
|
|
|
16 |
# First handle any URL linking.
|
|
|
17 |
my @words = split /(\s)/, $text;
|
|
|
18 |
my $result = "";
|
|
|
19 |
for (my $i = 0; $i <= $#words; $i++) {
|
|
|
20 |
if ($words[$i] =~ /^([A-Za-z]+:\/\/.*[A-Za-z0-9_])(.*)$/o) {
|
|
|
21 |
# A URL, create a link to it.
|
|
|
22 |
$result .= "<A HREF=\"$1\">$1</A>$2";
|
|
|
23 |
} else {
|
|
|
24 |
$result .= $words[$i];
|
|
|
25 |
}
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
# If there is a link to a bug tracking system, automagically modify all
|
|
|
29 |
# text of the form "[Bb]ug \d+" to a hyperlink for that bug record.
|
|
|
30 |
if (defined $Codestriker::bugtracker && $Codestriker::bugtracker ne "") {
|
|
|
31 |
$result =~ s/(\b)([Bb][Uu][Gg]\s*(\d+))(\b)/$1<A HREF="${Codestriker::bugtracker}$3">$1$2$4<\/A>/mg;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
return $result;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
1;
|