line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormRemove; |
2
|
|
|
|
|
|
|
# -*- Perl -*- Tue May 21 13:01:01 CDT 2002 |
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Written by Tim Skirvin |
5
|
|
|
|
|
|
|
# Copyright 2000-2002, Tim Skirvin and UIUC Board of Trustees. Redistribution |
6
|
|
|
|
|
|
|
# terms are below. |
7
|
|
|
|
|
|
|
############################################################################### |
8
|
1
|
|
|
1
|
|
663
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
9
|
|
|
|
|
|
|
$VERSION = "0.3a"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
HTML::FormRemove - remove form tags from HTML |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $html = |
18
|
|
|
|
|
|
|
""; |
19
|
|
|
|
|
|
|
use HTML::FormRemove |
20
|
|
|
|
|
|
|
print RemoveFormValues($html); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
HTML::FormRemove is a module that removes form tags from HTML, while |
25
|
|
|
|
|
|
|
otherwise leaving the HTML intact. This allows for forms to be converted |
26
|
|
|
|
|
|
|
into something printable and usable. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
32
|
1
|
|
|
1
|
|
1683
|
use HTML::Form; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use Exporter; |
35
|
|
|
|
|
|
|
use vars qw( @EXPORT @EXPORT_OK @ISA ); |
36
|
|
|
|
|
|
|
@ISA = "Exporter"; |
37
|
|
|
|
|
|
|
@EXPORT = qw( RemoveFormValues ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Untaint $0; this may not be the best idea in the world, but it's |
40
|
|
|
|
|
|
|
# necessary if we're in taint mode |
41
|
|
|
|
|
|
|
if ($0 =~ /^(.*)$/) { $0 = $1 } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item RemoveFormValues ( HTML [, HTML [, HTML [...]]] ) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Removes the form values. Exported by default. Returns an array of lines |
48
|
|
|
|
|
|
|
containing the updated HTML, or one single like containing them separated |
49
|
|
|
|
|
|
|
by newlines. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=back |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# We want to modularize this a lot, and fix it up. |
56
|
|
|
|
|
|
|
sub RemoveFormValues { |
57
|
|
|
|
|
|
|
my $line = join("\n", @_); |
58
|
|
|
|
|
|
|
return undef unless $line; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $form = HTML::Form->parse($line, $0); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Take out the tags |
63
|
|
|
|
|
|
|
$line =~ s%?form[^>]*>%%isg; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Take out , replacing them with [...] |
66
|
|
|
|
|
|
|
# (this may not be the best idea; perhaps we should just leave them in?) |
67
|
|
|
|
|
|
|
$line =~ s%<(\s*/?\s*)textarea([^>]*)*>%<$1pre$2>%g; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my (%radio); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Take out bits, leaving the 'value' part, unless it's |
72
|
|
|
|
|
|
|
# a 'submit' box, in which case we'll drop it entirely |
73
|
|
|
|
|
|
|
my $i; |
74
|
|
|
|
|
|
|
$line =~ s%(]*>)% |
75
|
|
|
|
|
|
|
my $form = HTML::Form->parse("", $0); |
76
|
|
|
|
|
|
|
foreach ($form->inputs) { |
77
|
|
|
|
|
|
|
next unless ref $_; |
78
|
|
|
|
|
|
|
$i = ""; |
79
|
|
|
|
|
|
|
if ($_->type eq 'submit' || $_->type eq 'reset') { } |
80
|
|
|
|
|
|
|
elsif ($_->type eq 'image' || $_->type eq 'button' ) { } |
81
|
|
|
|
|
|
|
elsif ($_->type eq 'radio') { |
82
|
|
|
|
|
|
|
my $input = $form->find_input($_->name); |
83
|
|
|
|
|
|
|
if ($input->value) { $i = " [X] " unless $radio{$_->name}++ } |
84
|
|
|
|
|
|
|
else { $i = " [ ] " } |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ($_->type eq 'checkbox') { |
87
|
|
|
|
|
|
|
my $input = $form->find_input($_->name); |
88
|
|
|
|
|
|
|
$input->value ? $i = " [X] " : $i = " [ ] "; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ($_->type eq 'hidden') { } |
91
|
|
|
|
|
|
|
elsif ($_->type eq 'file') { } |
92
|
|
|
|
|
|
|
elsif ($_->type eq 'password') { $i = $_->value; $i =~ s/./x/g; } |
93
|
|
|
|
|
|
|
elsif ($_->type eq 'text') { $i = $_->value } |
94
|
|
|
|
|
|
|
else { $i = ""} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
$i %eisgx; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Now comes the work with 'select'. Just leave these in a form tag. |
100
|
|
|
|
|
|
|
$line =~ s%(]*>)% |
101
|
|
|
|
|
|
|
"" %eisgx; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
wantarray ? split("\n", $line) : $line; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NOTES |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This module is a work in progress; I've only got basic functionality |
111
|
|
|
|
|
|
|
working at the moment. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 REQUIREMENTS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Perl 5 or better, and the C module (with everything that |
116
|
|
|
|
|
|
|
requires). |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
B |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
http://www.ks.uiuc.edu/Development/MDTools/dbiframe for the latest version. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 TODO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Modularize the code. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Make some more specific functions, and allow for more customizability |
129
|
|
|
|
|
|
|
within it. IE, it'd be nice to only take out |
130
|
|
|
|
|
|
|
everything else alone. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Written by Tim Skirvin . |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 LICENSE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
University of Illinois Open Source License |
139
|
|
|
|
|
|
|
Copyright (c) 2002 University of Illinois Board of Trustees |
140
|
|
|
|
|
|
|
All rights reserved |
141
|
|
|
|
|
|
|
Developed by: Theoretical Biophysics Group |
142
|
|
|
|
|
|
|
University of Illinois, Beckman Institute |
143
|
|
|
|
|
|
|
http://www.ks.uiuc.edu/ |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a |
146
|
|
|
|
|
|
|
copy of this software, DBI::Frame, and associated documentation files |
147
|
|
|
|
|
|
|
(the "Software"), to deal with the Software without restriction, |
148
|
|
|
|
|
|
|
including without limitation the rights to use, copy, modify, merge, |
149
|
|
|
|
|
|
|
publish, distribute, sublicense, and/or sell copies of the Software, and |
150
|
|
|
|
|
|
|
to permit persons to whom the Software is furnished to do so, subject to |
151
|
|
|
|
|
|
|
the following conditions: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright |
154
|
|
|
|
|
|
|
notice, this list of conditions and the following disclaimers. |
155
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright |
156
|
|
|
|
|
|
|
notice, this list of conditions and the following disclaimers in |
157
|
|
|
|
|
|
|
the documentation and/or other materials provided with the |
158
|
|
|
|
|
|
|
distribution. |
159
|
|
|
|
|
|
|
* Neither the names of the Theoretical Biophysics Group, the |
160
|
|
|
|
|
|
|
University of Illinois, nor the names of its contributors may |
161
|
|
|
|
|
|
|
be used to endorse or promote products derived from this Software |
162
|
|
|
|
|
|
|
without specific prior written permission. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
165
|
|
|
|
|
|
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
166
|
|
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
167
|
|
|
|
|
|
|
THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
168
|
|
|
|
|
|
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
169
|
|
|
|
|
|
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
170
|
|
|
|
|
|
|
OTHER DEALINGS WITH THE SOFTWARE. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2001-2002 by the University of Illinois Board of Trustees and |
175
|
|
|
|
|
|
|
Tim Skirvin . |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
##### Version History |
180
|
|
|
|
|
|
|
# v0.1a Fri Jun 15 15:05:10 CDT 2001 |
181
|
|
|
|
|
|
|
### Initial version. Works, but not all that well. |
182
|
|
|
|
|
|
|
# v0.2a Thu Feb 21 11:24:02 CST 2002 |
183
|
|
|
|
|
|
|
### Changed to UIUC/NCSA Open Source License. |
184
|
|
|
|
|
|
|
# v0.3a Tue May 21 11:22:37 CDT 2002 |
185
|
|
|
|
|
|
|
### Made the |
186
|
|
|
|
|
|
|
### interaction with URI and taint mode by untainting $0. |