diff options
author | Yorhel <git@yorhel.nl> | 2011-01-01 14:31:27 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2011-01-01 14:31:27 +0100 |
commit | 7fd5b49039f5e9b3367a0a9025f695eeabbcd318 (patch) | |
tree | d79f0c59ad425b68244c909e88f36b987c92d997 /lib/VNDB/Handler/VNBrowse.pm | |
parent | a919a25370b31a4b969bcb663de6acce26bf235d (diff) |
Implemented filFetchDB() and converted the VN/Release browser to use it
This will correctly handle fetching stuff from the database when
permanent filters are enabled.
This update also removes compatibility with some old VN browse URLs. The
old 'ti' and 'te' (tag include/exclude) query parameters are now
ignored, and searching for a language in the query string (e.g.
"q=English") won't enable the language filter.
Diffstat (limited to 'lib/VNDB/Handler/VNBrowse.pm')
-rw-r--r-- | lib/VNDB/Handler/VNBrowse.pm | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm index 25166717..15407076 100644 --- a/lib/VNDB/Handler/VNBrowse.pm +++ b/lib/VNDB/Handler/VNBrowse.pm @@ -25,32 +25,22 @@ sub list { ); return 404 if $f->{_err}; $f->{q} ||= $f->{sq}; - my $fil = fil_parse $f->{fil}, qw|length hasani tag_inc tag_exc taginc tagexc tagspoil lang olang plat|; - _fil_compat($self, $fil); + my %compat = _fil_compat($self); - if($f->{q}) { - return $self->resRedirect('/'.$1.$2.(!$3 ? '' : $1 eq 'd' ? '#'.$3 : '.'.$3), 'temp') - if $f->{q} =~ /^([gvrptud])([0-9]+)(?:\.([0-9]+))?$/; + return $self->resRedirect('/'.$1.$2.(!$3 ? '' : $1 eq 'd' ? '#'.$3 : '.'.$3), 'temp') + if $f->{q} && $f->{q} =~ /^([gvrptud])([0-9]+)(?:\.([0-9]+))?$/; - # for URL compatibilty with older versions (ugly hack to get English strings) - my @lang; - $f->{q} =~ s/\s*$VNDB::L10N::en::Lexicon{"_lang_$_"}\s*//&&push @lang, $_ for (@{$self->{languages}}); - $fil->{lang} = $fil->{lang} ? [ ref($fil->{lang}) ? @{$fil->{lang}} : $fil->{lang}, @lang ] : \@lang if @lang; - } - $f->{fil} = fil_serialize $fil; - - $f->{s} = 'title' if !$fil->{tag_inc} && $f->{s} eq 'tagscore'; + $f->{s} = 'title' if $f->{fil} !~ /tag_inc-/ && $f->{s} eq 'tagscore'; $f->{o} = $f->{s} eq 'tagscore' ? 'd' : 'a' if !$f->{o}; - my($list, $np) = $self->dbVNGet( + my($list, $np) = $self->filFetchDB(vn => $f->{fil}, \%compat, { what => 'rating', $char ne 'all' ? ( char => $char ) : (), $f->{q} ? ( search => $f->{q} ) : (), results => 50, page => $f->{p}, sort => $f->{s}, reverse => $f->{o} eq 'd', - %$fil - ); + }); $self->resRedirect('/v'.$list->[0]{id}, 'temp') if $f->{q} && @$list == 1 && $f->{p} == 1; @@ -74,35 +64,24 @@ sub list { end; end; # /form - $self->htmlBrowseVN($list, $f, $np, "/v/$char?q=$f->{q};fil=$f->{fil}", $fil->{tag_inc}); + $self->htmlBrowseVN($list, $f, $np, "/v/$char?q=$f->{q};fil=$f->{fil}", $f->{fil} =~ /tag_inc-/); $self->htmlFooter; } sub _fil_compat { - my($self, $fil) = @_; + my $self = shift; + my %c; my $f = $self->formValidate( { name => 'ln', required => 0, multi => 1, enum => $self->{languages}, default => '' }, { name => 'pl', required => 0, multi => 1, enum => $self->{platforms}, default => '' }, - { name => 'ti', required => 0, default => '', maxlength => 200 }, - { name => 'te', required => 0, default => '', maxlength => 200 }, { name => 'sp', required => 0, default => $self->reqCookie($self->{cookie_prefix}.'tagspoil') =~ /^([0-2])$/ ? $1 : 0, enum => [0..2] }, ); - $fil->{lang} //= $f->{ln} if $f->{ln}[0]; - $fil->{plat} //= $f->{pl} if $f->{pl}[0]; - $fil->{taginc} //= $f->{ti} if $f->{ti}; - $fil->{tagexc} //= $f->{te} if $f->{te}; - $fil->{tagspoil} //= $f->{sp}; - - # older tag specification (by name rather than ID) - my $tagfind = sub { - return map { - my $i = $self->dbTagGet(name => $_)->[0]; - $i && !$i->{meta} ? $i->{id} : (); - } grep $_, ref $_[0] ? @{$_[0]} : ($_[0]||'') - }; - $fil->{tag_inc} //= [ $tagfind->(delete $fil->{taginc}) ] if $fil->{taginc}; - $fil->{tag_exc} //= [ $tagfind->(delete $fil->{tagexc}) ] if $fil->{tagexc}; + return () if $f->{_err}; + $c{lang} //= $f->{ln} if $f->{ln}[0]; + $c{plat} //= $f->{pl} if $f->{pl}[0]; + $c{tagspoil} //= $f->{sp}; + return %c; } |