summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-11-27 13:30:55 +0100
committerYorhel <git@yorhel.nl>2010-11-27 13:30:55 +0100
commit5f9aea8e9877b71b4372a8fde569367db6bb44e1 (patch)
tree98d12e246f36ad069a5478bcf0de7e559de563b7 /lib
parent156a362991ac6922f33e61a08f39f31048310183 (diff)
Replaced old VN advanced options with the new filter selection system
Had to fix some bugs here and there and add some new functionality to the abstractions at some places, but it appears to be working now. There are still a few TODOs left, I'll get to those in a bit.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/VN.pm10
-rw-r--r--lib/VNDB/Func.pm2
-rw-r--r--lib/VNDB/Handler/Releases.pm2
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm112
4 files changed, 43 insertions, 83 deletions
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 6d99ba8a..11b7c29a 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -10,7 +10,7 @@ use Encode 'decode_utf8';
our @EXPORT = qw|dbVNGet dbVNRevisionInsert dbVNImageId dbScreenshotAdd dbScreenshotGet dbScreenshotRandom|;
-# Options: id, rev, char, search, lang, platform, tags_include, tags_exclude, results, page, what, sort, reverse
+# Options: id, rev, char, search, lang, plat, tags_include, tags_exclude, results, page, what, sort, reverse
# What: extended anime relations screenshots relgraph rating ranking changes
# Sort: id rel pop rating title tagscore rand
sub dbVNGet {
@@ -29,10 +29,10 @@ sub dbVNGet {
'LOWER(SUBSTR(vr.title, 1, 1)) = ?' => $o{char} ) : (),
defined $o{char} && !$o{char} ? (
'(ASCII(vr.title) < 97 OR ASCII(vr.title) > 122) AND (ASCII(vr.title) < 65 OR ASCII(vr.title) > 90)' => 1 ) : (),
- $o{lang} && @{$o{lang}} ? (
- 'v.c_languages && ARRAY[!l]::language[]' => [ $o{lang} ]) : (),
- $o{platform} && @{$o{platform}} ? (
- '('.join(' OR ', map "v.c_platforms ILIKE '%%$_%%'", @{$o{platform}}).')' => 1 ) : (),
+ $o{lang} ? (
+ 'v.c_languages && ARRAY[!l]::language[]' => [ ref $o{lang} ? $o{lang} : [$o{lang}] ]) : (),
+ $o{plat} ? (
+ '('.join(' OR ', map "v.c_platforms ILIKE '%%$_%%'", ref $o{plat} ? @{$o{plat}} : $o{plat}).')' => 1 ) : (),
$o{tags_include} && @{$o{tags_include}} ? (
'v.id IN(SELECT vid FROM tags_vn_inherit WHERE tag IN(!l) AND spoiler <= ? GROUP BY vid HAVING COUNT(tag) = ?)',
[ $o{tags_include}[1], $o{tags_include}[0], $#{$o{tags_include}[1]}+1 ]
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 11d442f4..65b66f9e 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -13,7 +13,7 @@ our @EXPORT = (@VNDBUtil::EXPORT, qw| liststat clearfloat cssicon tagscore mt mi
# three ways to represent the same information
our $fil_escape = '_ !"#$%&\'()*+,-./:;<=>?@[\]^`{}~';
our @fil_escape = split //, $fil_escape;
-our %fil_escape = map +($fil_escape[$_], $_), 0..$#fil_escape;
+our %fil_escape = map +($fil_escape[$_], sprintf '%02d', $_), 0..$#fil_escape;
# Argument: hashref with rstat and vstat
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index 497c96de..cd3ea73c 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -511,7 +511,7 @@ sub browse {
div class => 'mainbox';
h1 mt '_rbrowse_title';
$self->htmlSearchBox('r', $f->{q});
- a id => 'filselect', href => '#';
+ a id => 'filselect', href => '#r';
lit '<i>&#9656;</i> '.mt('_rbrowse_filters').'<i></i>';
end;
input type => 'hidden', class => 'hidden', name => 'fil', id => 'fil', value => $f->{fil};
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
index f3193b57..3a8ae7d5 100644
--- a/lib/VNDB/Handler/VNBrowse.pm
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -21,14 +21,12 @@ sub list {
{ name => 'p', required => 0, default => 1, template => 'int' },
{ name => 'q', required => 0, default => '' },
{ name => 'sq', required => 0, default => '' },
- { 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] },
+ { name => 'fil',required => 0, default => '' },
);
return 404 if $f->{_err};
$f->{q} ||= $f->{sq};
+ my $fil = fil_parse $f->{fil}, qw|taginc tagexc tagspoil lang plat|;
+ _fil_compat($self, $fil);
if($f->{q}) {
return $self->resRedirect('/'.$1.$2.(!$3 ? '' : $1 eq 'd' ? '#'.$3 : '.'.$3), 'temp')
@@ -37,9 +35,11 @@ sub list {
# 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}});
- $f->{ln} = $f->{ln}[0] ? [ @{$f->{ln}}, @lang ] : \@lang;
+ $fil->{lang} = $fil->{lang} ? [ ref($fil->{lang}) ? @{$fil->{lang}} : $fil->{lang}, @lang ] : \@lang;
}
+ $f->{fil} = fil_serialize $fil;
+ # TODO: this should be moved to dbVNGet() in order for savable VN filters to be useful
my @ignored;
my $tagfind = sub {
return map {
@@ -47,10 +47,10 @@ sub list {
push @ignored, [$_, 0] if !$i;
push @ignored, [$_, 1] if $i && $i->{meta};
$i && !$i->{meta} ? $i->{id} : ();
- } grep $_, split /\s*,\s*/, $_[0];
+ } grep $_, ref $_[0] ? @{$_[0]} : ($_[0]||'')
};
- my @ti = $tagfind->($f->{ti});
- my @te = $tagfind->($f->{te});
+ my @ti = $tagfind->(delete $fil->{taginc});
+ my @te = $tagfind->(delete $fil->{tagexc});
$f->{s} = 'title' if !@ti && $f->{s} eq 'tagscore';
$f->{o} = $f->{s} eq 'tagscore' ? 'd' : 'a' if !$f->{o};
@@ -62,28 +62,15 @@ sub list {
results => 50,
page => $f->{p},
sort => $f->{s}, reverse => $f->{o} eq 'd',
- $f->{pl}[0] ? ( platform => $f->{pl} ) : (),
- $f->{ln}[0] ? ( lang => $f->{ln} ) : (),
- @ti ? (tags_include => [ $f->{sp}, \@ti ]) : (),
+ @ti ? (tags_include => [ delete $fil->{tagspoil}, \@ti ]) : (),
@te ? (tags_exclude => \@te) : (),
+ %$fil
);
$self->resRedirect('/v'.$list->[0]{id}, 'temp')
if $f->{q} && @$list == 1 && $f->{p} == 1;
$self->htmlHeader(title => mt('_vnbrowse_title'), search => $f->{q});
- _filters($self, $f, $char, \@ignored);
-
- my $url = "/v/$char?q=$f->{q};ti=$f->{ti};te=$f->{te}";
- $_ and $url .= ";pl=$_" for @{$f->{pl}};
- $_ and $url .= ";ln=$_" for @{$f->{ln}};
- $self->htmlBrowseVN($list, $f, $np, $url, scalar @ti);
- $self->htmlFooter;
-}
-
-
-sub _filters {
- my($self, $f, $char, $ign) = @_;
form action => '/v/all', 'accept-charset' => 'UTF-8', method => 'get';
div class => 'mainbox';
@@ -95,68 +82,41 @@ sub _filters {
}
end;
- if(@$ign) {
+ if(@ignored) {
div class => 'warning';
h2 mt '_vnbrowse_tagign_title';
ul;
- li $_->[0].' ('.mt('_vnbrowse_tagign_'.($_->[1]?'meta':'notfound')).')' for @$ign;
+ li $_->[0].' ('.mt('_vnbrowse_tagign_'.($_->[1]?'meta':'notfound')).')' for @ignored;
end;
end;
}
- a id => 'advselect', href => '#';
- lit '<i>&#9656;</i> '.mt('_vnbrowse_advsearch');
+ a id => 'filselect', href => '#v';
+ lit '<i>&#9656;</i> '.mt('_rbrowse_filters').'<i></i>'; # TODO: it's not *r*browse
end;
- div id => 'advoptions', class => 'hidden vnoptions';
-
- h2;
- txt mt '_vnbrowse_tags';
- b ' ('.mt('_vnbrowse_booland').')';
- end;
- table class => 'formtable', style => 'margin-left: 0';
- $self->htmlFormPart($f, [ input => short => 'ti', name => mt('_vnbrowse_taginc'), width => 350 ]);
- $self->htmlFormPart($f, [ radio => short => 'sp', name => '', options => [map [$_, mt '_vnbrowse_spoil'.$_], 0..2]]);
- $self->htmlFormPart($f, [ input => short => 'te', name => mt('_vnbrowse_tagexc'), width => 350 ]);
- end;
-
- h2;
- txt mt '_vnbrowse_lang';
- b ' ('.mt('_vnbrowse_boolor').')';
- end;
- for my $i (@{$self->{languages}}) {
- span;
- input type => 'checkbox', name => 'ln', value => $i, id => "lang_$i",
- (scalar grep $_ eq $i, @{$f->{ln}}) ? (checked => 'checked') : ();
- label for => "lang_$i";
- cssicon "lang $i", mt "_lang_$i";
- txt mt "_lang_$i";
- end;
- end;
- }
+ input type => 'hidden', class => 'hidden', name => 'fil', id => 'fil', value => $f->{fil};
+ end;
+ end; # /form
- h2;
- txt mt '_vnbrowse_plat';
- b ' ('.mt('_vnbrowse_boolor').')';
- end;
- for my $i (sort @{$self->{platforms}}) {
- next if $i eq 'oth';
- span;
- input type => 'checkbox', id => "plat_$i", name => 'pl', value => $i,
- (scalar grep $_ eq $i, @{$f->{pl}}) ? (checked => 'checked') : ();
- label for => "plat_$i";
- cssicon $i, mt "_plat_$i";
- txt mt "_plat_$i";
- end;
- end;
- }
+ $self->htmlBrowseVN($list, $f, $np, "/v/$char?q=$f->{q};fil=$f->{fil}", scalar @ti);
+ $self->htmlFooter;
+}
- div style => 'text-align: center; clear: left;';
- input type => 'submit', value => mt('_vnbrowse_apply'), class => 'submit';
- input type => 'reset', value => mt('_vnbrowse_clear'), class => 'submit', onclick => 'location.href="/v/all"';
- end;
- end;
- end;
- end;
+
+sub _fil_compat {
+ my($self, $fil) = @_;
+ 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};
}