line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: URL.pm 284 2006-12-01 07:51:49Z chronos $ |
2
|
|
|
|
|
|
|
package BBCode::Tag::URL; |
3
|
4
|
|
|
4
|
|
25
|
use base qw(BBCode::Tag); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
403
|
|
4
|
4
|
|
|
4
|
|
25
|
use BBCode::Util qw(:parse encodeHTML multilineText); |
|
4
|
|
|
|
|
198
|
|
|
4
|
|
|
|
|
1064
|
|
5
|
4
|
|
|
4
|
|
24
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
129
|
|
6
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
8065
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub Class($):method { |
10
|
25
|
|
|
25
|
1
|
87
|
return qw(LINK INLINE); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub BodyPermitted($):method { |
14
|
45
|
|
|
45
|
1
|
200
|
return 1; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BodyTags($):method { |
18
|
26
|
|
|
26
|
1
|
87
|
return qw(:INLINE !:LINK); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub NamedParams($):method { |
22
|
21
|
|
|
21
|
1
|
83
|
return qw(HREF FOLLOW NEWWINDOW TITLE); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub RequiredParams($):method { |
26
|
0
|
|
|
0
|
1
|
0
|
return qw(HREF); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub DefaultParam($):method { |
30
|
20
|
|
|
20
|
1
|
58
|
return 'HREF'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validateParam($$$):method { |
34
|
15
|
|
|
15
|
1
|
38
|
my($this,$param,$val) = @_; |
35
|
|
|
|
|
|
|
|
36
|
15
|
100
|
|
|
|
46
|
if($param eq 'HREF') { |
37
|
11
|
|
|
|
|
533
|
my $url = parseURL($val); |
38
|
11
|
100
|
|
|
|
41
|
if(defined $url) { |
39
|
10
|
|
|
|
|
38
|
return $url->as_string; |
40
|
|
|
|
|
|
|
} else { |
41
|
1
|
|
|
|
|
44
|
die qq(Invalid value "$val" for [URL]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
4
|
50
|
|
|
|
16
|
if($param eq 'FOLLOW') { |
45
|
4
|
|
|
|
|
19
|
return parseBool $val; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
0
|
|
|
|
0
|
if($param eq 'NEWWINDOW') { |
48
|
0
|
|
|
|
|
0
|
return parseBool $val; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
return $this->SUPER::validateParam($param,$val); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub replace($):method { |
54
|
20
|
|
|
20
|
0
|
33
|
my $this = shift; |
55
|
20
|
|
|
|
|
57
|
my $href = $this->param('HREF'); |
56
|
20
|
100
|
|
|
|
57
|
if(not defined $href) { |
57
|
1
|
|
|
|
|
7
|
my $text = $this->bodyText; |
58
|
1
|
|
|
|
|
6
|
my $url = parseURL $text; |
59
|
1
|
50
|
|
|
|
5
|
if(not defined $url) { |
60
|
0
|
|
|
|
|
0
|
return BBCode::Tag->new($this->parser, 'TEXT', [ undef, $text ]); |
61
|
|
|
|
|
|
|
} |
62
|
1
|
|
|
|
|
4
|
$this->param(HREF => $url); |
63
|
|
|
|
|
|
|
} |
64
|
20
|
|
|
|
|
48
|
return $this; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub toHTML($):method { |
68
|
8
|
|
|
8
|
1
|
21
|
my $this = shift; |
69
|
|
|
|
|
|
|
|
70
|
8
|
|
|
|
|
18
|
my $ret = ''; |
71
|
8
|
|
|
|
|
30
|
my $href = $this->param('HREF'); |
72
|
8
|
50
|
|
|
|
29
|
if(defined $href) { |
73
|
8
|
|
|
|
|
28
|
my $title = $this->param('TITLE'); |
74
|
8
|
|
|
|
|
35
|
$ret .= '
|
75
|
8
|
100
|
|
|
|
49
|
$ret .= ' rel="nofollow"' if not $this->isFollowed; |
76
|
8
|
50
|
|
|
|
79
|
$ret .= ' target="_blank"' if $this->openInNewWindow; |
77
|
8
|
50
|
|
|
|
27
|
$ret .= ' title="'.encodeHTML($title).'"' if defined $title; |
78
|
8
|
|
|
|
|
18
|
$ret .= '>'; |
79
|
|
|
|
|
|
|
} |
80
|
8
|
|
|
|
|
41
|
$ret .= $this->bodyHTML; |
81
|
8
|
50
|
|
|
|
38
|
if(defined $href) { |
82
|
8
|
|
|
|
|
13
|
$ret .= ''; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
8
|
|
|
|
|
28
|
return multilineText $ret; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub toText($):method { |
89
|
0
|
|
|
0
|
1
|
0
|
my $this = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $href = $this->param('HREF'); |
92
|
0
|
|
|
|
|
0
|
my $text = $this->bodyText; |
93
|
0
|
|
|
|
|
0
|
my $ret; |
94
|
0
|
0
|
|
|
|
0
|
if(defined $href) { |
95
|
0
|
|
|
|
|
0
|
$ret = "_${text}_"; |
96
|
0
|
0
|
|
|
|
0
|
if($href =~ /^mailto:([\w.+-]+\@[\w.-]+)$/) { |
97
|
0
|
|
|
|
|
0
|
$ret .= " <$1>"; |
98
|
|
|
|
|
|
|
} else { |
99
|
0
|
|
|
|
|
0
|
$ret .= " "; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
0
|
$ret = $text; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
0
|
return multilineText $ret; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub toLinkList($;$):method { |
108
|
4
|
|
|
4
|
1
|
5
|
my $this = shift; |
109
|
4
|
|
|
|
|
4
|
my $ret = shift; |
110
|
4
|
50
|
|
|
|
10
|
$ret = [] if not defined $ret; |
111
|
|
|
|
|
|
|
|
112
|
4
|
|
|
|
|
9
|
my $href = $this->param('HREF'); |
113
|
4
|
50
|
|
|
|
10
|
if(defined $href) { |
114
|
4
|
|
|
|
|
13
|
push @$ret, [ $this->isFollowed, $this->Tag, $href, $this->bodyText ]; |
115
|
|
|
|
|
|
|
} |
116
|
4
|
|
|
|
|
19
|
return $this->SUPER::toLinkList($ret); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |