111 |
my @LINES = <CACHE>; |
my @LINES = <CACHE>; |
112 |
close( CACHE ); |
close( CACHE ); |
113 |
|
|
114 |
|
my $searchingsomething = 0; |
|
# Search terms - if any. |
|
|
my $terms = $ARGUMENTS{ "q" }; |
|
|
|
|
115 |
|
|
116 |
# |
# |
117 |
# Remove XSS attacks |
# Remove XSS attacks |
118 |
# |
# |
119 |
if ( defined( $terms ) && length( $terms ) ) |
|
120 |
{ |
foreach my $st (qw(q artist album song year genre)) |
121 |
$terms =~ s/</</g; |
{ |
122 |
$terms =~ s/>/>/g; |
if ( defined( $ARGUMENTS{$st} ) && length( $ARGUMENTS{$st} ) ) |
123 |
|
{ |
124 |
|
$ARGUMENTS{$st} =~ s/</</g; |
125 |
|
$ARGUMENTS{$st} =~ s/>/>/g; |
126 |
|
} |
127 |
|
$searchingsomething ++; |
128 |
} |
} |
129 |
|
|
130 |
|
if ( ! $searchingsomething ) |
131 |
|
{ |
132 |
|
# |
133 |
|
# we don't seem to be searching anything |
134 |
|
# |
135 |
|
delete( $ARGUMENTS{ "q" } ); |
136 |
|
my $header = &getHTTPHeader( 200, "text/html" ); |
137 |
|
&sendData($data, $header ); |
138 |
|
my $err = &getErrorPage( $ARGUMENTS{"theme"}, |
139 |
|
"<p> You must search for <em>something</em>.</p>" . |
140 |
|
"<p> <a href='/search'>Search again</a>.</p>" ); |
141 |
|
&sendData( $data, $err ); |
142 |
|
close( $data ); |
143 |
|
exit; |
144 |
|
} |
145 |
|
|
146 |
|
# |
147 |
|
# search term across all fields |
148 |
|
# |
149 |
|
my $terms = $ARGUMENTS{ "q" }; |
150 |
|
|
151 |
# |
# |
152 |
# The mode will be either 'any' or 'all' |
# The mode will be either 'any' or 'all' |
164 |
# |
# |
165 |
# Now do the searching for real. |
# Now do the searching for real. |
166 |
# |
# |
167 |
|
SEARCHALINE: |
168 |
foreach my $line ( @LINES ) |
foreach my $line ( @LINES ) |
169 |
{ |
{ |
170 |
chomp( $line ); |
chomp( $line ); |
171 |
|
|
172 |
my $match = 0; |
my $match = 0; |
173 |
|
|
174 |
|
# |
175 |
|
# searches limited by one of the specific fields; |
176 |
|
# these operate as AND searches in all cases |
177 |
|
# |
178 |
|
foreach my $f ( qw(artist album song year) ) { |
179 |
|
if ( defined($ARGUMENTS{$f} ) && length($ARGUMENTS{$f}) ) |
180 |
|
{ |
181 |
|
my $F = uc($f); |
182 |
|
# either match now or jump out |
183 |
|
if ( $line !~ /$F=[^\t]*(?i)\Q$ARGUMENTS{$f}\E/ ) |
184 |
|
{ |
185 |
|
# warn("didn't match term $f == '$ARGUMENTS{$f}'\n"); |
186 |
|
next SEARCHALINE; |
187 |
|
} |
188 |
|
} |
189 |
|
} |
190 |
|
|
191 |
|
# genre searches must match exactly |
192 |
|
if ( defined($ARGUMENTS{'genre'} ) && length($ARGUMENTS{'genre'} ) ) |
193 |
|
{ |
194 |
|
if ( $line !~ /GENRE=\Q$ARGUMENTS{'genre'}\E/ ) |
195 |
|
{ |
196 |
|
next SEARCHALINE; |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
# |
# |
201 |
# Search for entered term(s). |
# Search for entered term(s). |
202 |
# |
# |
203 |
if ( $mode eq "all" ) |
if ( $mode eq "all" ) |
204 |
{ |
{ |
205 |
# Searching for any term. |
# Searching for any term. |
206 |
# Assume the match succeeded unless a term isnt found. |
# Assume the match succeeded unless a term isn't found. |
207 |
$match = 1; |
$match = 1; |
208 |
foreach my $term ( split( ' ', $terms ) ) |
foreach my $term ( split( ' ', $terms ) ) |
209 |
{ |
{ |