line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::Pro::Extension::HEAD_BODY; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = "0.11"; |
4
|
0
|
|
|
0
|
0
|
0
|
sub Version { $VERSION; } |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
899
|
use HTML::TokeParser; |
|
1
|
|
|
|
|
12813
|
|
|
1
|
|
|
|
|
813
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %fields_parent = |
12
|
|
|
|
|
|
|
( |
13
|
|
|
|
|
|
|
autoDeleteHeader => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub init { |
17
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
18
|
1
|
|
|
|
|
6
|
while (my ($key,$val) = each(%fields_parent)) { |
19
|
1
|
|
33
|
|
|
12
|
$self->{$key} = $self->{$key} || $val; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_filter { |
24
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
25
|
1
|
|
|
|
|
2
|
return _get_filter($self); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _get_filter { |
29
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
30
|
1
|
|
|
|
|
36
|
my @ret ; |
31
|
|
|
|
|
|
|
push @ret, sub { |
32
|
4
|
|
|
4
|
|
5
|
my $tmpl = shift; |
33
|
4
|
|
|
|
|
4
|
my $self = shift; |
34
|
4
|
100
|
|
|
|
12
|
if ($self->{autoDeleteHeader}) { |
35
|
2
|
|
|
|
|
3
|
my $header; |
36
|
2
|
50
|
|
|
|
15
|
if ($$tmpl =~s{(^.+?'"]*|".*?"|'.*?')+>)}{}msi) { |
37
|
2
|
|
|
|
|
6
|
$self->{header} = $1; |
38
|
2
|
|
|
|
|
4
|
&tokenizer_header($self); |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
# header doesn't exist |
41
|
0
|
|
|
|
|
0
|
undef $self->{header}; |
42
|
0
|
|
|
|
|
0
|
undef $self->{tokens}; |
43
|
|
|
|
|
|
|
} |
44
|
2
|
|
|
|
|
89
|
$$tmpl =~ s{.+}{}msi; |
45
|
|
|
|
|
|
|
} |
46
|
1
|
|
|
|
|
4
|
}; |
47
|
1
|
|
|
|
|
4
|
return @ret; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub autoDeleteHeader { |
51
|
5
|
|
|
5
|
0
|
6
|
my $s=shift; |
52
|
5
|
50
|
|
|
|
11
|
if (@_) { |
53
|
5
|
|
|
|
|
6
|
my $newvalue = shift; |
54
|
5
|
100
|
|
|
|
22
|
return if ($newvalue == $s->{autoDeleteHeader}); |
55
|
1
|
|
|
|
|
2
|
$s->{autoDeleteHeader}=$newvalue; |
56
|
|
|
|
|
|
|
}; |
57
|
1
|
|
|
|
|
3
|
return $s->{autoDeleteHeader}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub tokenizer_header { |
61
|
|
|
|
|
|
|
# prende l'header contenuto in $self->{header} e ne estrae i |
62
|
|
|
|
|
|
|
# token fondamentali inserendoli in $self->{tokens} |
63
|
2
|
|
|
2
|
0
|
2
|
my $self = shift; |
64
|
2
|
|
|
|
|
2
|
my $header = $self->{header}; |
65
|
2
|
|
|
|
|
7
|
$header =~m|(.*?)|smi; |
66
|
2
|
|
|
|
|
3
|
$header = $1; |
67
|
2
|
|
|
|
|
7
|
my $p = HTML::TokeParser->new(\$header); |
68
|
2
|
|
|
|
|
231
|
$self->{tokens} = {}; |
69
|
2
|
|
|
|
|
7
|
while (my $token = $p->get_tag()) { |
70
|
6
|
|
|
|
|
145
|
my $tag = $token->[0]; |
71
|
6
|
100
|
|
|
|
10
|
my $type = substr($tag,0,1) eq '/' ? 'E' : 'S'; |
72
|
6
|
|
|
|
|
7
|
my $tag_text; |
73
|
6
|
100
|
|
|
|
12
|
if ($type eq 'S') { |
|
|
50
|
|
|
|
|
|
74
|
4
|
|
|
|
|
5
|
$tag_text = $token->[3]; |
75
|
4
|
|
|
|
|
10
|
my $text = $p->get_text(); |
76
|
4
|
|
|
|
|
128
|
my $struct = [$tag_text,$text,undef]; |
77
|
4
|
|
|
|
|
5
|
push @{$self->{tokens}->{$tag}},$struct; |
|
4
|
|
|
|
|
20
|
|
78
|
|
|
|
|
|
|
} elsif ($type eq 'E') { |
79
|
2
|
|
|
|
|
3
|
$tag = substr($tag,1,length($tag)-1); |
80
|
2
|
|
|
|
|
3
|
$tag_text = $token->[1]; |
81
|
2
|
|
|
|
|
2
|
my $last_idx = scalar @{$self->{tokens}->{$tag}}-1; |
|
2
|
|
|
|
|
3
|
|
82
|
2
|
|
|
|
|
8
|
$self->{tokens}->{$tag}->[$last_idx]->[2] = $tag_text; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
1
|
0
|
2
|
sub header {my $s = shift;return exists($s->{header}) ? $s->{header} : ''}; |
|
1
|
|
|
|
|
5
|
|
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
0
|
0
|
sub js_header { return &header_js(shift); } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub header_js { |
93
|
|
|
|
|
|
|
# ritorna il codice javascript presente nell'header |
94
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
95
|
1
|
|
|
|
|
2
|
my $ret; |
96
|
1
|
|
|
|
|
2
|
my $js_token = $self->{tokens}->{script}; |
97
|
1
|
|
|
|
|
1
|
foreach (@{$js_token}) { |
|
1
|
|
|
|
|
2
|
|
98
|
1
|
|
|
|
|
5
|
$ret .= $_->[0] . $_->[1] . $_->[2]; |
99
|
|
|
|
|
|
|
} |
100
|
1
|
|
|
|
|
3
|
return $ret; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub header_css { |
104
|
|
|
|
|
|
|
# ritorna i css presenti nell'header |
105
|
|
|
|
|
|
|
# compresi i link a css esterni |
106
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
107
|
1
|
|
|
|
|
1
|
my $ret; |
108
|
1
|
|
|
|
|
5
|
my $style_token = $self->{tokens}->{style}; |
109
|
1
|
|
|
|
|
2
|
foreach (@{$style_token}) { |
|
1
|
|
|
|
|
1
|
|
110
|
1
|
|
|
|
|
4
|
$ret .= $_->[0] . $_->[1] . $_->[2]; |
111
|
|
|
|
|
|
|
} |
112
|
1
|
|
|
|
|
2
|
my $link_token = $self->{tokens}->{link}; |
113
|
1
|
|
|
|
|
1
|
foreach (@{$link_token}) { |
|
1
|
|
|
|
|
3
|
|
114
|
0
|
0
|
0
|
|
|
0
|
if ($_->[0] =~ /[Rr][Ee][Ll]\s*=\s*"?[Ss][Tt][Yy][Ll][Ee][Ss][Hh][Ee][Ee][Tt]"?/ && |
115
|
|
|
|
|
|
|
$_->[0] =~ /[Tt][Yy][Pp][Ee]\s*=\s*"?[Tt][Te][Xx][Tt]\/[Cc][Ss][Ss]"?/) { |
116
|
0
|
|
|
|
|
0
|
$ret .= $_->[0] . $_->[1] . $_->[2]; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
1
|
|
|
|
|
4
|
return $ret; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub body_attributes { |
123
|
|
|
|
|
|
|
# ritorna gli attributi interni al campo body |
124
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
125
|
0
|
|
|
|
|
0
|
my $h = $self->{header}; |
126
|
0
|
|
|
|
|
0
|
my $re_init = q|<\s*body(.*?)>|; |
127
|
0
|
|
|
|
|
0
|
$h=~/$re_init/msxi; |
128
|
0
|
|
|
|
|
0
|
return $1; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub header_tokens { |
132
|
|
|
|
|
|
|
# ritorna un riferimento ad un hash che contiene |
133
|
|
|
|
|
|
|
# come chiavi tutti i tag presenti nell'header ... |
134
|
|
|
|
|
|
|
# ogni elemento dell'hash e' un riferimento ad un array. |
135
|
|
|
|
|
|
|
# Ogni array e' a sua volta un riferimento ad array di tre elementi |
136
|
|
|
|
|
|
|
# tag_init - testo contenuto tra il tag e l'eventuale fine tag o successivo tag - eventuale fine tag o undef |
137
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
138
|
1
|
|
|
|
|
3
|
return $self->{tokens}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |