line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Urlize; |
2
|
3
|
|
|
3
|
|
1093
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
67
|
|
3
|
3
|
|
|
3
|
|
13
|
use utf8; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
13
|
|
4
|
3
|
|
|
3
|
|
56
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
78
|
|
5
|
3
|
|
|
3
|
|
14
|
use parent 'DTL::Fast::Filter'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
14
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{urlize} = __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
161
|
use DTL::Fast::Utils qw(unescape); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1226
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $DOMAINS_RE = qr/com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|ru|рф|[a-z]{2,3}/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $URL_RE = qr |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
(?:(?:http|ftp|https)\://)? # protocol |
16
|
|
|
|
|
|
|
(?:\w+\:\w+\@)? # username and password |
17
|
|
|
|
|
|
|
(?:(?:www|ftp)\.)? # domain prefixes |
18
|
|
|
|
|
|
|
(?:[-\w]+\.)+ # domain name |
19
|
|
|
|
|
|
|
(?:$DOMAINS_RE) # top level domain |
20
|
|
|
|
|
|
|
(?:\:\d{1,5})? # port number |
21
|
|
|
|
|
|
|
(?:/[-\w~._]*)*? # directories and files |
22
|
|
|
|
|
|
|
(?:\?[^\s#]+?)? # query string no spaces or sharp |
23
|
|
|
|
|
|
|
(?:\#[^\s]+?)? # anchor |
24
|
|
|
|
|
|
|
}x; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $EMAIL_RE = qr |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
(?:[-\w_~\.]+\@) # user name |
29
|
|
|
|
|
|
|
(?:[-\w]+\.)+ # domain name |
30
|
|
|
|
|
|
|
(?:$DOMAINS_RE) # top level domain |
31
|
|
|
|
|
|
|
}x; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#@Override |
34
|
|
|
|
|
|
|
sub filter |
35
|
|
|
|
|
|
|
{ |
36
|
18
|
|
|
18
|
0
|
29
|
my $self = shift; # self |
37
|
18
|
|
|
|
|
24
|
my $filter_manager = shift; # filter_manager |
38
|
18
|
|
|
|
|
27
|
my $value = shift; # value |
39
|
18
|
|
|
|
|
25
|
shift; #context |
40
|
|
|
|
|
|
|
|
41
|
18
|
|
|
|
|
911
|
$value =~ s |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
(?:($EMAIL_RE)|($URL_RE)) |
44
|
|
|
|
|
|
|
($|\s|\.|,|!) # after link |
45
|
|
|
|
|
|
|
}{ |
46
|
20
|
|
|
|
|
60
|
$self->wrap_email($1, $3).$self->wrap_url($2, $3) |
47
|
|
|
|
|
|
|
}gxesi; |
48
|
|
|
|
|
|
|
|
49
|
18
|
|
|
|
|
46
|
$filter_manager->{safe} = 1; |
50
|
|
|
|
|
|
|
|
51
|
18
|
|
|
|
|
66
|
return $value; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub wrap_url |
55
|
|
|
|
|
|
|
{ |
56
|
20
|
|
|
20
|
0
|
31
|
my $self = shift; |
57
|
20
|
|
|
|
|
42
|
my $text = shift; |
58
|
20
|
100
|
|
|
|
51
|
return '' if (not $text); |
59
|
18
|
|
50
|
|
|
54
|
my $appendix = shift // ''; |
60
|
|
|
|
|
|
|
|
61
|
18
|
|
|
|
|
29
|
my $uri = $text; |
62
|
18
|
100
|
|
|
|
68
|
$uri = 'http://'.$uri if |
63
|
|
|
|
|
|
|
($uri !~ m{^(http|ftp|https)://}i); |
64
|
|
|
|
|
|
|
|
65
|
18
|
|
50
|
|
|
66
|
return sprintf '%s%s' |
66
|
|
|
|
|
|
|
, $uri // 'undef' |
67
|
|
|
|
|
|
|
, DTL::Fast::html_protect(unescape($self->normalize_text($text))) |
68
|
|
|
|
|
|
|
, $appendix |
69
|
|
|
|
|
|
|
; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub wrap_email |
73
|
|
|
|
|
|
|
{ |
74
|
20
|
|
|
20
|
0
|
35
|
my $self = shift; |
75
|
20
|
|
|
|
|
41
|
my $text = shift; |
76
|
20
|
100
|
|
|
|
68
|
return '' if (not $text); |
77
|
2
|
|
50
|
|
|
8
|
my $appendix = shift // ''; |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
6
|
my $uri = $text; |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
6
|
return sprintf '%s%s' |
82
|
|
|
|
|
|
|
, $uri |
83
|
|
|
|
|
|
|
, DTL::Fast::html_protect(unescape($self->normalize_text($text))) |
84
|
|
|
|
|
|
|
, $appendix |
85
|
|
|
|
|
|
|
; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub normalize_text |
89
|
|
|
|
|
|
|
{ |
90
|
10
|
|
|
10
|
0
|
17
|
shift; |
91
|
10
|
|
|
|
|
128
|
return shift; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |