line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: IMG.pm 284 2006-12-01 07:51:49Z chronos $ |
2
|
|
|
|
|
|
|
package BBCode::Tag::IMG; |
3
|
3
|
|
|
3
|
|
19
|
use base qw(BBCode::Tag::Inline); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
804
|
|
4
|
3
|
|
|
3
|
|
18
|
use BBCode::Util qw(:parse :text encodeHTML); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
767
|
|
5
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
6
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2998
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub BodyPermitted($):method { |
10
|
8
|
|
|
8
|
1
|
14
|
my $this_or_class = shift; |
11
|
8
|
100
|
66
|
|
|
61
|
if(ref $this_or_class and defined $this_or_class->param('SRC')) { |
12
|
4
|
|
|
|
|
32
|
return 0; |
13
|
|
|
|
|
|
|
} |
14
|
4
|
|
|
|
|
15
|
return 1; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BodyTags($):method { |
18
|
8
|
|
|
8
|
1
|
31
|
return qw(:TEXT); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub NamedParams($):method { |
22
|
5
|
|
|
5
|
1
|
24
|
return qw(SRC ALT W H TITLE); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub RequiredParams($):method { |
26
|
0
|
|
|
0
|
1
|
0
|
return qw(SRC); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub DefaultParam($):method { |
30
|
5
|
|
|
5
|
1
|
15
|
return 'SRC'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validateParam($$$):method { |
34
|
10
|
|
|
10
|
1
|
21
|
my($this,$param,$val) = @_; |
35
|
10
|
100
|
|
|
|
32
|
if($param eq 'SRC') { |
36
|
4
|
|
|
|
|
31
|
my $url = parseURL($val); |
37
|
4
|
100
|
|
|
|
19
|
if(defined $url) { |
38
|
3
|
50
|
|
|
|
15
|
if($url->scheme =~ /^(?:http|https|ftp|data)$/) { |
39
|
3
|
|
|
|
|
54
|
return $url->as_string; |
40
|
|
|
|
|
|
|
} else { |
41
|
0
|
|
|
|
|
0
|
die qq(Scheme "$url->scheme" not permitted for [IMG]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} else { |
44
|
1
|
|
|
|
|
33
|
die qq(Invalid value "$val" for [IMG]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
6
|
100
|
100
|
|
|
49
|
if($param eq 'W' or $param eq 'H') { |
48
|
2
|
|
|
|
|
10
|
return parseNum $val; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
40
|
return $this->SUPER::validateParam($param,$val); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub replace($):method { |
54
|
6
|
|
|
6
|
0
|
9
|
my $this = shift; |
55
|
6
|
|
|
|
|
9
|
my($src,$alt) = map { $this->param($_) } qw(SRC ALT); |
|
12
|
|
|
|
|
30
|
|
56
|
6
|
50
|
|
|
|
18
|
if(defined $src) { |
57
|
|
|
|
|
|
|
# [IMG SRC] has no body... |
58
|
6
|
|
|
|
|
14
|
delete $this->{body}; |
59
|
6
|
|
|
|
|
15
|
delete $this->{permit}; |
60
|
6
|
|
|
|
|
10
|
delete $this->{forbid}; |
61
|
|
|
|
|
|
|
} |
62
|
6
|
50
|
33
|
|
|
39
|
return $this if defined $src and defined $alt; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my($text,$url); |
65
|
0
|
0
|
|
|
|
0
|
if(defined $src) { |
66
|
0
|
|
|
|
|
0
|
$url = parseURL $src; |
67
|
0
|
0
|
|
|
|
0
|
die "BUG: Cannot re-parse URL <$src>" unless defined $url; |
68
|
0
|
|
|
|
|
0
|
$text = textALT $url; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
0
|
$text = $this->bodyText; |
71
|
0
|
|
|
|
|
0
|
$url = parseURL $text; |
72
|
0
|
0
|
|
|
|
0
|
goto boom unless defined $url; |
73
|
0
|
|
|
|
|
0
|
$text = textALT $url; |
74
|
0
|
|
|
|
|
0
|
$this->param(SRC => $url); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
|
|
|
0
|
$this->param(ALT => $text) if not defined $alt; |
77
|
0
|
|
|
|
|
0
|
return $this; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
boom: |
80
|
|
|
|
|
|
|
return BBCode::Tag->new($this->parser, 'TEXT', [ undef, $text ]); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub toHTML($):method { |
84
|
1
|
|
|
1
|
1
|
2
|
my $this = shift; |
85
|
1
|
|
|
|
|
3
|
my($src,$alt,$w,$h,$t) = map { $this->param($_) } qw(SRC ALT W H TITLE); |
|
5
|
|
|
|
|
14
|
|
86
|
|
|
|
|
|
|
|
87
|
1
|
50
|
33
|
|
|
8
|
if(defined $src and defined $alt) { |
88
|
1
|
50
|
|
|
|
4
|
if(not defined $t) { |
89
|
0
|
|
|
|
|
0
|
$t = $this->bodyText; |
90
|
|
|
|
|
|
|
} |
91
|
1
|
|
|
|
|
2
|
my $ret = '
|
92
|
1
|
|
|
|
|
5
|
$ret .= ' src="'.encodeHTML($src).'"'; |
93
|
1
|
|
|
|
|
4
|
$ret .= ' alt="'.encodeHTML($alt).'"'; |
94
|
1
|
50
|
|
|
|
6
|
$ret .= ' width="'.encodeHTML($w).'"' if defined $w; |
95
|
1
|
50
|
|
|
|
6
|
$ret .= ' height="'.encodeHTML($h).'"' if defined $h; |
96
|
1
|
50
|
|
|
|
7
|
$ret .= ' title="'.encodeHTML($t).'"' if defined $t; |
97
|
1
|
|
|
|
|
3
|
$ret .= ' />'; |
98
|
1
|
|
|
|
|
6
|
return $ret; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
0
|
return ''; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub toLinkList($;$):method { |
104
|
2
|
|
|
2
|
1
|
3
|
my $this = shift; |
105
|
2
|
|
|
|
|
3
|
my $ret = shift; |
106
|
2
|
50
|
|
|
|
7
|
$ret = [] if not defined $ret; |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
3
|
my($src,$alt) = map { $this->param($_) } qw(SRC ALT); |
|
4
|
|
|
|
|
9
|
|
109
|
2
|
50
|
33
|
|
|
12
|
if(defined $src and defined $alt) { |
110
|
2
|
|
|
|
|
6
|
push @$ret, [ 1, $this->Tag, $src, $alt ]; |
111
|
|
|
|
|
|
|
} |
112
|
2
|
|
|
|
|
11
|
return $this->SUPER::toLinkList($ret); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |