diff options
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/DB/Tags.pm | 15 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 44 | ||||
-rw-r--r-- | lib/VNDB/Util/Misc.pm | 2 |
3 files changed, 38 insertions, 23 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm index fb4717d8..389e172a 100644 --- a/lib/VNDB/DB/Tags.pm +++ b/lib/VNDB/DB/Tags.pm @@ -8,7 +8,7 @@ use Exporter 'import'; our @EXPORT = qw|dbTagGet dbTTTree dbTagEdit dbTagAdd dbTagMerge dbTagLinks dbTagLinkEdit dbTagStats|; -# %options->{ id noid name search state meta page results what sort reverse } +# %options->{ id noid name search state searchable applicable page results what sort reverse } # what: parents childs(n) aliases addedby # sort: id name added items search sub dbTagGet { @@ -35,11 +35,11 @@ sub dbTagGet { 't.state <> 1' => 1 ) : (), $o{search} ? ( 't.id IN (SELECT id FROM tags LEFT JOIN tags_aliases ON id = tag WHERE name ILIKE ? OR alias ILIKE ?)' => [ "%$o{search}%", "%$o{search}%" ] ) : (), - defined $o{meta} ? ( - 't.meta = ?' => $o{meta}?1:0 ) : (), + defined $o{searchable} ? ('t.searchable = ?' => $o{searchable}?1:0 ) : (), + defined $o{applicable} ? ('t.applicable = ?' => $o{applicable}?1:0 ) : (), ); my @select = ( - qw|t.id t.meta t.name t.description t.state t.cat t.c_items t.defaultspoil|, + qw|t.id t.searchable t.applicable t.name t.description t.state t.cat t.c_items t.defaultspoil|, q|extract('epoch' from t.added) as added|, $o{what} =~ /addedby/ ? ('t.addedby', 'u.username') : (), ); @@ -129,7 +129,7 @@ sub dbTagEdit { $self->dbExec('UPDATE tags !H WHERE id = ?', { $o{upddate} ? ('added = NOW()' => 1) : (), - map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name meta description state cat defaultspoil| + map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name searchable applicable description state cat defaultspoil| }, $id); if($o{aliases}) { $self->dbExec('DELETE FROM tags_aliases WHERE tag = ?', $id); @@ -139,7 +139,6 @@ sub dbTagEdit { $self->dbExec('DELETE FROM tags_parents WHERE tag = ?', $id); $self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}}); } - $self->dbExec('DELETE FROM tags_vn WHERE tag = ?', $id) if $o{meta} || ($o{state} && $o{state} == 1); } @@ -147,8 +146,8 @@ sub dbTagEdit { # returns the id of the new tag sub dbTagAdd { my($self, %o) = @_; - my $id = $self->dbRow('INSERT INTO tags (name, meta, description, state, cat, defaultspoil, addedby) VALUES (!l, ?) RETURNING id', - [ map $o{$_}, qw|name meta description state cat defaultspoil| ], $o{addedby}||$self->authInfo->{id} + my $id = $self->dbRow('INSERT INTO tags (name, searchable, applicable, description, state, cat, defaultspoil, addedby) VALUES (!l, ?) RETURNING id', + [ map $o{$_}, qw|name searchable applicable description state cat defaultspoil| ], $o{addedby}||$self->authInfo->{id} )->{id}; $self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}}); $self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_) for (@{$o{aliases}}); diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm index 165aadd0..33da3dd6 100644 --- a/lib/VNDB/Handler/Tags.pm +++ b/lib/VNDB/Handler/Tags.pm @@ -39,7 +39,7 @@ sub tagpage { return $self->resNotFound if $f->{_err}; $f->{fil} //= $self->authPref('filter_vn'); - my($list, $np) = $t->{meta} || $t->{state} != 2 ? ([],0) : $self->filFetchDB(vn => $f->{fil}, undef, { + my($list, $np) = !$t->{searchable} || $t->{state} != 2 ? ([],0) : $self->filFetchDB(vn => $f->{fil}, undef, { what => 'rating', results => 50, page => $f->{p}, @@ -49,7 +49,7 @@ sub tagpage { tag_exc => undef, }); - my $title = ($t->{meta} ? 'Meta tag: ' : 'Tag: ').$t->{name}; + my $title = "Tag: $t->{name}"; $self->htmlHeader(title => $title, noindex => $t->{state} != 2); $self->htmlMainTabs('g', $t); @@ -87,6 +87,15 @@ sub tagpage { lit bb2html $t->{description}; end; } + if(!$t->{applicable} || !$t->{searchable}) { + p class => 'center'; + b 'Properties'; + br; + txt 'Not searchable.' if !$t->{searchable}; + br; + txt 'Can not be directly applied to visual novels.' if !$t->{applicable}; + end; + } p class => 'center'; b 'Category'; br; @@ -103,7 +112,7 @@ sub tagpage { childtags($self, 'Child tags', 'g', $t) if @{$t->{childs}}; - if(!$t->{meta} && $t->{state} == 2) { + if($t->{searchable} && $t->{state} == 2) { form action => "/g$t->{id}", 'accept-charset' => 'UTF-8', method => 'get'; div class => 'mainbox'; a class => 'addnew', href => "/g/links?t=$tag", 'Recently tagged'; @@ -160,7 +169,8 @@ sub tagedit { { post => 'state', required => 0, default => 0, enum => [ 0..2 ] }, { post => 'cat', required => 1, enum => [ keys %{$self->{tag_categories}} ] }, { post => 'catrec', required => 0 }, - { post => 'meta', required => 0, default => 0 }, + { post => 'searchable', required => 0, default => 0 }, + { post => 'applicable', required => 0, default => 0 }, { post => 'alias', required => 0, maxlength => 1024, default => '', regex => [ qr/^[^,]+$/s, 'No comma allowed in aliases' ] }, { post => 'description', required => 0, maxlength => 10240, default => '' }, { post => 'defaultspoil',required => 0, default => 0, enum => [ 0..2 ] }, @@ -182,13 +192,17 @@ sub tagedit { } if(!$frm->{_err}) { - $frm->{state} = $frm->{meta} = 0 if !$self->authCan('tagmod'); + if(!$self->authCan('tagmod')) { + $frm->{state} = 0; + $frm->{searchable} = $frm->{applicable} = 1; + } my %opts = ( name => $frm->{name}, state => $frm->{state}, cat => $frm->{cat}, description => $frm->{description}, - meta => $frm->{meta}?1:0, + searchable => $frm->{searchable}?1:0, + applicable => $frm->{applicable}?1:0, defaultspoil => $frm->{defaultspoil}, aliases => \@aliases, parents => \@parents, @@ -206,7 +220,7 @@ sub tagedit { } if($tag) { - $frm->{$_} ||= $t->{$_} for (qw|name meta description state cat defaultspoil|); + $frm->{$_} ||= $t->{$_} for (qw|name searchable applicable description state cat defaultspoil|); $frm->{alias} ||= join "\n", @{$t->{aliases}}; $frm->{parents} ||= join ', ', map $_->{name}, @{$t->{parents}}; } @@ -239,9 +253,8 @@ sub tagedit { [ static => label => 'Added by', content => fmtuser($t->{addedby}, $t->{username}) ] : (), [ select => short => 'state', name => 'State', options => [ [0, 'Awaiting moderation'], [1, 'Deleted/hidden'], [2, 'Approved'] ] ], - [ checkbox => short => 'meta', name => 'This is a meta-tag (only to be used as parent for other tags, not for linking to VN entries)' ], - $tag ? - [ static => content => 'WARNING: Checking this option or selecting "Deleted" as state will permanently delete all existing VN relations!' ] : (), + [ checkbox => short => 'searchable', name => 'Searchable (people can use this tag to filter VNs)' ], + [ checkbox => short => 'applicable', name => 'Applicable (people can apply this tag to VNs)' ], ) : (), [ select => short => 'cat', name => 'Category', options => [ map [$_, $self->{tag_categories}{$_}], keys %{$self->{tag_categories}} ] ], @@ -504,6 +517,11 @@ sub vntagmod { my %insert; # tag => [ vote, spoiler, ignore ] my %overrule; # tag => 0/1 + # remove tags in the deleted state + delete $new{$_->{id}} for(keys %new ? @{$self->dbTagGet(id => [ keys %new ], state => 1)} : ()); + # and not-applicable tags + delete $new{$_->{id}} for(keys %new ? @{$self->dbTagGet(id => [ keys %new ], applicable => 0)} : ()); + for my $t (keys %old, keys %new) { my $prev_over = $old{$t} && !$old{$t}{ignore} && $tags{$t}{overruled}; @@ -525,8 +543,6 @@ sub vntagmod { $update{$t} = [ $new{$t}[0], $new{$t}[1] ]; } } - # remove tags in the deleted state. - delete $insert{$_->{id}} for(keys %insert ? @{$self->dbTagGet(id => [ keys %insert ], state => 1)} : ()); $self->dbTagLinkEdit($self->authInfo->{id}, $vid, \%insert, \%update, \%delete, \%overrule); @@ -668,7 +684,7 @@ sub tagindex { # Popular td; a class => 'addnew', href => "/g/links", 'Recently tagged'; - $r = $self->dbTagGet(sort => 'items', reverse => 1, meta => 0, results => 10); + $r = $self->dbTagGet(sort => 'items', reverse => 1, searchable => 1, applicable => 1, results => 10); h1 'Popular tags'; ul; for (@$r) { @@ -758,7 +774,7 @@ sub tagxml { xml; tag 'tags', more => $np ? 'yes' : 'no', $f->{q} ? (query => $f->{q}) : (); for(@$list) { - tag 'item', id => $_->{id}, meta => $_->{meta} ? 'yes' : 'no', state => $_->{state}, $_->{name}; + tag 'item', id => $_->{id}, searchable => $_->{searchable} ? 'yes' : 'no', applicable => $_->{applicable} ? 'yes' : 'no', state => $_->{state}, $_->{name}; } end; } diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm index 1146c687..0f6a7448 100644 --- a/lib/VNDB/Util/Misc.pm +++ b/lib/VNDB/Util/Misc.pm @@ -90,7 +90,7 @@ sub filCompat { my $tagfind = sub { return map { my $i = $self->dbTagGet(name => $_)->[0]; - $i && !$i->{meta} ? $i->{id} : (); + $i && $i->{searchable} ? $i->{id} : (); } grep $_, ref $_[0] ? @{$_[0]} : ($_[0]||'') }; $fil->{tag_inc} //= [ $tagfind->(delete $fil->{taginc}) ] if $fil->{taginc}; |