diff options
Diffstat (limited to 'lib/VNDB/Util/Misc.pm')
-rw-r--r-- | lib/VNDB/Util/Misc.pm | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm deleted file mode 100644 index 0423e35b..00000000 --- a/lib/VNDB/Util/Misc.pm +++ /dev/null @@ -1,100 +0,0 @@ - -package VNDB::Util::Misc; - -use strict; -use warnings; -use Exporter 'import'; -use TUWF ':html'; -use VNDB::Func; -use VNDB::Types; -use VNDB::BBCode; - -our @EXPORT = qw|filFetchDB filCompat bbSubstLinks|; - - -our %filfields = ( - vn => [qw|date_before date_after released length hasani hasshot tag_inc tag_exc taginc tagexc tagspoil lang olang plat staff_inc staff_exc ul_notblack ul_onwish ul_voted ul_onlist|], - release => [qw|type patch freeware doujin uncensored date_before date_after released minage lang olang resolution plat prod_inc prod_exc med voiced ani_story ani_ero engine|], - char => [qw|gender bloodt bust_min bust_max waist_min waist_max hip_min hip_max height_min height_max va_inc va_exc weight_min weight_max cup_min cup_max trait_inc trait_exc tagspoil role|], - staff => [qw|gender role truename lang|], -); - - -# Arguments: -# type ('vn', 'release' or 'char'), -# filter overwrite (string or undef), -# when defined, these filters will be used instead of the preferences, -# must point to a variable, will be modified in-place with the actually used filters -# options to pass to db*Get() before the filters (hashref or undef) -# these options can be overwritten by the filters or the next option -# options to pass to db*Get() after the filters (hashref or undef) -# these options overwrite all other options (pre-options and filters) - -sub filFetchDB { - my($self, $type, $overwrite, $pre, $post) = @_; - $pre = {} if !$pre; - $post = {} if !$post; - my $dbfunc = $self->can($type eq 'vn' ? 'dbVNGet' : $type eq 'release' ? 'dbReleaseGet' : $type eq 'char' ? 'dbCharGet' : 'dbStaffGet'); - my $prefname = 'filter_'.$type; - my $pref = $self->authPref($prefname); - - my $filters = fil_parse $overwrite // $pref, @{$filfields{$type}}; - - VNWeb::Filters::debug_validate($type, $filters); - - # compatibility - my $compat = $self->filCompat($type, $filters); - $self->authPref($prefname => fil_serialize $filters) if $compat && !defined $overwrite; - - # write the definite filter string in $overwrite - $_[2] = fil_serialize({map +( - exists($post->{$_}) ? ($_ => $post->{$_}) : - exists($filters->{$_}) ? ($_ => $filters->{$_}) : - exists($pre->{$_}) ? ($_ => $pre->{$_}) : (), - ), @{$filfields{$type}}}) if defined $overwrite; - - return $dbfunc->($self, %$pre, %$filters, %$post) if defined $overwrite or !keys %$filters;; - - # since incorrect filters can throw a database error, we have to special-case - # filters that originate from a preference setting, so that in case these are - # the cause of an error, they are removed. Not doing this will result in VNDB - # throwing 500's even for non-browse pages. We have to do some low-level - # PostgreSQL stuff with savepoints to ensure that an error won't affect our - # existing transaction. - my $dbh = $self->dbh; - $dbh->pg_savepoint('filter'); - my($r, $np); - my $OK = eval { - ($r, $np) = $dbfunc->($self, %$pre, %$filters, %$post); - 1; - }; - $dbh->pg_rollback_to('filter') if !$OK; - $dbh->pg_release('filter'); - - # error occured, let's try again without filters. if that succeeds we know - # it's the fault of the filter preference, and we should remove it. - if(!$OK) { - ($r, $np) = $dbfunc->($self, %$pre, %$post); - # if we're here, it means the previous function didn't die() (duh!) - $self->authPref($prefname => ''); - warn sprintf "Reset filter preference for userid %d. Old: %s\n", $self->authInfo->{id}||0, $pref; - } - return wantarray ? ($r, $np) : $r; -} - - -# Compatibility with old filters. Modifies the filter in-place and returns the number of changes made. -sub filCompat { - my($self, $type, $fil) = @_; - $type eq 'vn' ? VNWeb::Filters::filter_vn_compat($fil) : 0 -} - - - -sub bbSubstLinks { - shift; bb_subst_links @_; -} - - -1; - |