line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::DWT::Simple;
|
2
|
|
|
|
|
|
|
#############################################################
|
3
|
|
|
|
|
|
|
# HTML::DWT::Simple
|
4
|
|
|
|
|
|
|
# Whyte.Wolf DreamWeaver HTML Template Module (Simple)
|
5
|
|
|
|
|
|
|
# Version 1.02
|
6
|
|
|
|
|
|
|
#
|
7
|
|
|
|
|
|
|
# Copyright (c) 2002 by S.D. Campbell
|
8
|
|
|
|
|
|
|
#
|
9
|
|
|
|
|
|
|
# Created 13 March 2002, Modified 05 April 2002
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
# A perl module designed to parse a simple HTML template file
|
12
|
|
|
|
|
|
|
# generated by Macromedia Dreamweaver and replace fields in the
|
13
|
|
|
|
|
|
|
# template with values from a CGI script.
|
14
|
|
|
|
|
|
|
#
|
15
|
|
|
|
|
|
|
#############################################################
|
16
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
17
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
18
|
|
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
19
|
|
|
|
|
|
|
# of the License, or (at your option) any later version.
|
20
|
|
|
|
|
|
|
#
|
21
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
22
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24
|
|
|
|
|
|
|
# GNU General Public License for more details.
|
25
|
|
|
|
|
|
|
#
|
26
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
27
|
|
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
28
|
|
|
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
29
|
|
|
|
|
|
|
#############################################################
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
1169
|
use Exporter;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
34
|
|
|
|
|
|
|
@EXPORT_OK = qw(output param);
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
37
|
1
|
|
|
|
|
1142
|
use vars qw($errmsg $VERSION @ISA @EXPORT_OK
|
38
|
1
|
|
|
1
|
|
4
|
$NOTICE %DWT_FIELDS %DWT_VALUES);
|
|
1
|
|
|
|
|
4
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$VERSION = '1.02';
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$NOTICE = "\n\t\t\n";
|
43
|
|
|
|
|
|
|
$NOTICE .= "\t\n";
|
44
|
|
|
|
|
|
|
$NOTICE .= "\t\n";
|
45
|
|
|
|
|
|
|
$NOTICE .= "\t\n";
|
46
|
|
|
|
|
|
|
$NOTICE .= "\n";
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
%DWT_FIELDS = ();
|
49
|
|
|
|
|
|
|
%DWT_VALUES = ();
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$errmsg = "";
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#############################################################
|
54
|
|
|
|
|
|
|
# new
|
55
|
|
|
|
|
|
|
#
|
56
|
|
|
|
|
|
|
# The constructor for the class. Requires a HTML Template
|
57
|
|
|
|
|
|
|
# filename. Returns a reference to the new object or undef
|
58
|
|
|
|
|
|
|
# on error. Errors can be retrieved from
|
59
|
|
|
|
|
|
|
# $HTML::DWT::Simple::errmsg.
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new {
|
62
|
2
|
|
|
2
|
1
|
4522
|
my $class = shift;
|
63
|
2
|
|
|
|
|
6
|
my %params = @_;
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
4
|
my $self = {};
|
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
7
|
if (!$params{filename}){
|
69
|
0
|
|
|
|
|
0
|
$params{filename} = $_[0];
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
2
|
100
|
|
|
|
7
|
if (exists($params{associate})){
|
73
|
1
|
50
|
|
|
|
3
|
if (ref($params{associate}) ne 'ARRAY') {
|
74
|
1
|
|
|
|
|
3
|
$$self{associate} = [ $params{associate} ];
|
75
|
|
|
|
|
|
|
}
|
76
|
1
|
|
|
|
|
3
|
$$self{associate} = $params{associate};
|
77
|
|
|
|
|
|
|
} else {
|
78
|
1
|
|
|
|
|
2
|
$$self{associate} = undef;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
3
|
$$self{filename} = $params{filename};
|
83
|
2
|
|
|
|
|
4
|
$$self{template} = '';
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
2
|
50
|
|
|
|
83
|
unless(open(TEMPLATE_FILE, $$self{filename})){
|
87
|
0
|
|
|
|
|
0
|
$errmsg = "HTML::DWT::Simple--Template File $$self{filename} not opened: $!\n";
|
88
|
0
|
|
|
|
|
0
|
return undef;
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
33
|
while(){
|
92
|
58
|
|
|
|
|
122
|
$$self{template} .= $_;
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
7
|
$$self{html} = $$self{template};
|
96
|
2
|
|
|
|
|
11
|
$$self{html} =~ s//_beginTemplate($$self{filename})/ie;
|
|
2
|
|
|
|
|
6
|
|
97
|
2
|
|
|
|
|
25
|
$$self{html} =~ s/<\/html>/_endTemplate()/ie;
|
|
2
|
|
|
|
|
7
|
|
98
|
2
|
|
|
|
|
19
|
$$self{html} =~ s/?/_quoteReplace($1)/ieg;
|
|
8
|
|
|
|
|
17
|
|
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
6
|
bless $self, $class;
|
101
|
|
|
|
|
|
|
|
102
|
2
|
50
|
|
|
|
8
|
if (exists($$self{associate})){
|
103
|
2
|
|
|
|
|
5
|
$self->_load();
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
8
|
return $self;
|
107
|
|
|
|
|
|
|
}
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#############################################################
|
111
|
|
|
|
|
|
|
# output
|
112
|
|
|
|
|
|
|
#
|
113
|
|
|
|
|
|
|
# Returns the substituted HTML as generated by fill() or
|
114
|
|
|
|
|
|
|
# param(). For compatibility with HTML::Template.
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub output {
|
117
|
1
|
|
|
1
|
1
|
12
|
my $self = shift;
|
118
|
1
|
|
|
|
|
2
|
my %params = @_;
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
16
|
foreach my $key (keys %DWT_VALUES) {
|
122
|
4
|
|
|
|
|
125
|
$$self{html}=~s/?(.*?)!--\s*#EndEditable\s*-->/_keyReplace($DWT_VALUES{$key},$1)/iegs;
|
|
4
|
|
|
|
|
9
|
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
4
|
if ($params{'print_to'}){
|
127
|
0
|
|
|
|
|
0
|
my $print_to = $params{'print_to'};
|
128
|
0
|
|
|
|
|
0
|
print $print_to $$self{html};
|
129
|
0
|
|
|
|
|
0
|
return undef;
|
130
|
|
|
|
|
|
|
} else {
|
131
|
1
|
|
|
|
|
3
|
return $$self{html};
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#############################################################
|
136
|
|
|
|
|
|
|
# param
|
137
|
|
|
|
|
|
|
#
|
138
|
|
|
|
|
|
|
# Take a hash of one or more key/value pairs and substitutes
|
139
|
|
|
|
|
|
|
# the HTML value in the key's spot in the template. For
|
140
|
|
|
|
|
|
|
# compatibility with HTML::Template.
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub param {
|
143
|
|
|
|
|
|
|
|
144
|
22
|
|
|
22
|
1
|
293
|
my $self = shift;
|
145
|
|
|
|
|
|
|
|
146
|
22
|
100
|
|
|
|
48
|
if (scalar(@_) == 0) {
|
|
|
100
|
|
|
|
|
|
147
|
1
|
|
|
|
|
5
|
return keys %DWT_FIELDS;
|
148
|
|
|
|
|
|
|
} elsif (scalar(@_) == 1){
|
149
|
12
|
|
|
|
|
15
|
my $field = shift;
|
150
|
12
|
|
|
|
|
37
|
return $DWT_VALUES{$field};
|
151
|
|
|
|
|
|
|
} else {
|
152
|
9
|
|
|
|
|
17
|
my %params = @_;
|
153
|
9
|
|
|
|
|
20
|
foreach my $key (keys %params) {
|
154
|
12
|
100
|
66
|
|
|
35
|
if ($key eq 'doctitle' && !($params{$key}=~/(.*?)<\/title>/i)){
|
155
|
3
|
|
|
|
|
12
|
$DWT_VALUES{'doctitle'} = "" . $params{$key} . "";
|
156
|
|
|
|
|
|
|
} else {
|
157
|
9
|
|
|
|
|
25
|
$DWT_VALUES{$key} = $params{$key};
|
158
|
|
|
|
|
|
|
}
|
159
|
|
|
|
|
|
|
}
|
160
|
|
|
|
|
|
|
}
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#############################################################
|
166
|
|
|
|
|
|
|
# _keyReplace
|
167
|
|
|
|
|
|
|
#
|
168
|
|
|
|
|
|
|
# An internal subroutine that does the actual key/value
|
169
|
|
|
|
|
|
|
# replacement. Takes the contents scalar and returns a
|
170
|
|
|
|
|
|
|
# HTML string.
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _keyReplace {
|
173
|
4
|
|
|
4
|
|
6
|
my $cont = shift;
|
174
|
4
|
|
|
|
|
8
|
my $key = shift;
|
175
|
|
|
|
|
|
|
|
176
|
4
|
|
|
|
|
34
|
return "\n" . $cont . "\n\n";
|
177
|
|
|
|
|
|
|
}
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
#############################################################
|
180
|
|
|
|
|
|
|
# _beginTemplate
|
181
|
|
|
|
|
|
|
#
|
182
|
|
|
|
|
|
|
# Returns the begin template string and file name back into
|
183
|
|
|
|
|
|
|
# the parsed HTML.
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _beginTemplate {
|
186
|
2
|
|
|
2
|
|
4
|
my $filename = shift;
|
187
|
2
|
|
|
|
|
12
|
return "\n\n" . $NOTICE;
|
188
|
|
|
|
|
|
|
}
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
#############################################################
|
191
|
|
|
|
|
|
|
# _endTemplate
|
192
|
|
|
|
|
|
|
#
|
193
|
|
|
|
|
|
|
# Returns the end template string back into the parsed HTML.
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _endTemplate {
|
196
|
2
|
|
|
2
|
|
5
|
return "\n";
|
197
|
|
|
|
|
|
|
}
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#############################################################
|
200
|
|
|
|
|
|
|
# _quoteReplace
|
201
|
|
|
|
|
|
|
#
|
202
|
|
|
|
|
|
|
# An internal subroutine that removes quotes from around
|
203
|
|
|
|
|
|
|
# the editable region name (fixes recursive loop bug).
|
204
|
|
|
|
|
|
|
# As of version 2.06 also builds %DWT_FIELDS and %DWT_VALUES
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub _quoteReplace {
|
207
|
8
|
|
|
8
|
|
11
|
my $key = shift;
|
208
|
8
|
|
|
|
|
13
|
$DWT_FIELDS{$key} = 'VAR';
|
209
|
8
|
|
|
|
|
10
|
$DWT_VALUES{$key} = undef;
|
210
|
|
|
|
|
|
|
|
211
|
8
|
|
|
|
|
43
|
return "";
|
212
|
|
|
|
|
|
|
}
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
#############################################################
|
215
|
|
|
|
|
|
|
# _load
|
216
|
|
|
|
|
|
|
#
|
217
|
|
|
|
|
|
|
# Loads the parameters from external sources
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub _load {
|
220
|
|
|
|
|
|
|
|
221
|
2
|
|
|
2
|
|
3
|
my $self = shift;
|
222
|
|
|
|
|
|
|
|
223
|
2
|
100
|
|
|
|
7
|
if ($$self{associate}){
|
224
|
1
|
|
|
|
|
2
|
foreach my $query ($$self{associate}){
|
225
|
1
|
|
|
|
|
3
|
foreach my $param ($query->param) {
|
226
|
4
|
|
|
|
|
25
|
$self->param($param => $query->param($param));
|
227
|
|
|
|
|
|
|
}
|
228
|
|
|
|
|
|
|
}
|
229
|
|
|
|
|
|
|
}
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
}
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1;
|
234
|
|
|
|
|
|
|
__END__
|