diff options
author | Yorhel <git@yorhel.nl> | 2009-03-22 10:55:48 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-03-22 10:55:48 +0100 |
commit | 09f80833cef287a5a4f5cf1018b19f8c2db3341e (patch) | |
tree | 000e757f9b11a6ce069c13da9b648751d6b453b3 /lib/VNDB | |
parent | 5f744cdcc18e0d67df8162ffb76e752a6f7a4a9c (diff) | |
parent | 1b99dd8701ce572c8ac20b71b3eb9b471b69d788 (diff) |
Merge branch 'tagging' into beta
Conflicts:
lib/VNDB/DB/Discussions.pm
util/updates/update_2.3.sql
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/DB/Discussions.pm | 58 | ||||
-rw-r--r-- | lib/VNDB/DB/Tags.pm | 218 | ||||
-rw-r--r-- | lib/VNDB/DB/Users.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Func.pm | 34 | ||||
-rw-r--r-- | lib/VNDB/Handler/Discussions.pm | 68 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 673 | ||||
-rw-r--r-- | lib/VNDB/Handler/Users.pm | 14 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNEdit.pm | 30 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNPage.pm | 40 | ||||
-rw-r--r-- | lib/VNDB/Util/CommonHTML.pm | 34 | ||||
-rw-r--r-- | lib/VNDB/Util/FormHTML.pm | 14 | ||||
-rw-r--r-- | lib/VNDB/Util/LayoutHTML.pm | 4 |
12 files changed, 1072 insertions, 117 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm index 8e476f55..b28bfeab 100644 --- a/lib/VNDB/DB/Discussions.pm +++ b/lib/VNDB/DB/Discussions.pm @@ -9,7 +9,7 @@ our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPos # Options: id, type, iid, results, page, what -# What: tags, tagtitles, firstpost, lastpost +# What: boards, boardtitles, firstpost, lastpost sub dbThreadGet { my($self, %o) = @_; $o{results} ||= 50; @@ -23,9 +23,9 @@ sub dbThreadGet { !$o{id} ? ( 't.hidden = FALSE' => 0 ) : (), $o{type} && !$o{iid} ? ( - 't.id IN(SELECT tid FROM threads_tags WHERE type = ?)' => $o{type} ) : (), + 't.id IN(SELECT tid FROM threads_boards WHERE type = ?)' => $o{type} ) : (), $o{type} && $o{iid} ? ( - 'tt.type = ?' => $o{type}, 'tt.iid = ?' => $o{iid} ) : (), + 'tb.type = ?' => $o{type}, 'tb.iid = ?' => $o{iid} ) : (), ); my @select = ( @@ -44,7 +44,7 @@ sub dbThreadGet { 'JOIN users ul ON ul.id = tpl.uid' ) : (), $o{type} && $o{iid} ? - 'JOIN threads_tags tt ON tt.tid = t.id' : (), + 'JOIN threads_boards tb ON tb.tid = t.id' : (), ); my($r, $np) = $self->dbPage(\%o, q| @@ -56,30 +56,30 @@ sub dbThreadGet { join(', ', @select), join(' ', @join), \%where, $o{order} ); - if($o{what} =~ /(tags|tagtitles)/ && $#$r >= 0) { + if($o{what} =~ /(boards|boardtitles)/ && $#$r >= 0) { my %r = map { - $r->[$_]{tags} = []; + $r->[$_]{boards} = []; ($r->[$_]{id}, $_) } 0..$#$r; - if($o{what} =~ /tags/) { - ($_->{type}=~s/ +//||1) && push(@{$r->[$r{$_->{tid}}]{tags}}, [ $_->{type}, $_->{iid} ]) for (@{$self->dbAll(q| + if($o{what} =~ /boards/) { + ($_->{type}=~s/ +//||1) && push(@{$r->[$r{$_->{tid}}]{boards}}, [ $_->{type}, $_->{iid} ]) for (@{$self->dbAll(q| SELECT tid, type, iid - FROM threads_tags + FROM threads_boards WHERE tid IN(!l)|, [ keys %r ] )}); } - if($o{what} =~ /tagtitles/) { - ($_->{type}=~s/ +//||1) && push(@{$r->[$r{$_->{tid}}]{tags}}, $_) for (@{$self->dbAll(q| - SELECT tt.tid, tt.type, tt.iid, COALESCE(u.username, vr.title, pr.name) AS title, COALESCE(u.username, vr.original, pr.original) AS original - FROM threads_tags tt - LEFT JOIN vn v ON tt.type = 'v' AND v.id = tt.iid + if($o{what} =~ /boardtitles/) { + ($_->{type}=~s/ +//||1) && push(@{$r->[$r{$_->{tid}}]{boards}}, $_) for (@{$self->dbAll(q| + SELECT tb.tid, tb.type, tb.iid, COALESCE(u.username, vr.title, pr.name) AS title, COALESCE(u.username, vr.original, pr.original) AS original + FROM threads_boards tb + LEFT JOIN vn v ON tb.type = 'v' AND v.id = tb.iid LEFT JOIN vn_rev vr ON vr.id = v.latest - LEFT JOIN producers p ON tt.type = 'p' AND p.id = tt.iid + LEFT JOIN producers p ON tb.type = 'p' AND p.id = tb.iid LEFT JOIN producers_rev pr ON pr.id = p.latest - LEFT JOIN users u ON tt.type = 'u' AND u.id = tt.iid - WHERE tt.tid IN(!l)|, + LEFT JOIN users u ON tb.type = 'u' AND u.id = tb.iid + WHERE tb.tid IN(!l)|, [ keys %r ] )}); } @@ -89,7 +89,7 @@ sub dbThreadGet { } -# id, %options->( title locked hidden tags } +# id, %options->( title locked hidden boards } sub dbThreadEdit { my($self, $id, %o) = @_; @@ -105,18 +105,18 @@ sub dbThreadEdit { WHERE id = ?|, \%set, $id); - if($o{tags}) { - $self->dbExec('DELETE FROM threads_tags WHERE tid = ?', $id); + if($o{boards}) { + $self->dbExec('DELETE FROM threads_boards WHERE tid = ?', $id); $self->dbExec(q| - INSERT INTO threads_tags (tid, type, iid) + INSERT INTO threads_boards (tid, type, iid) VALUES (?, ?, ?)|, $id, $_->[0], $_->[1]||0 - ) for (@{$o{tags}}); + ) for (@{$o{boards}}); } } -# %options->{ title hidden locked tags } +# %options->{ title hidden locked boards } sub dbThreadAdd { my($self, %o) = @_; @@ -128,24 +128,24 @@ sub dbThreadAdd { )->{id}; $self->dbExec(q| - INSERT INTO threads_tags (tid, type, iid) + INSERT INTO threads_boards (tid, type, iid) VALUES (?, ?, ?)|, $id, $_->[0], $_->[1]||0 - ) for (@{$o{tags}}); + ) for (@{$o{boards}}); return $id; } -# Returns thread count of a specific item tag +# Returns thread count of a specific item board # Arguments: type, iid sub dbThreadCount { my($self, $type, $iid) = @_; return $self->dbRow(q| SELECT COUNT(*) AS cnt - FROM threads_tags tt - JOIN threads t ON t.id = tt.tid - WHERE tt.type = ? AND tt.iid = ? + FROM threads_boards tb + JOIN threads t ON t.id = tb.tid + WHERE tb.type = ? AND tb.iid = ? AND t.hidden = FALSE|, $type, $iid)->{cnt}; } diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm new file mode 100644 index 00000000..a24495cf --- /dev/null +++ b/lib/VNDB/DB/Tags.pm @@ -0,0 +1,218 @@ + +package VNDB::DB::Tags; + +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT = qw|dbTagGet dbTagTree dbTagEdit dbTagAdd dbTagMerge dbTagLinks dbTagLinkEdit dbTagStats dbTagVNs|; + + +# %options->{ id noid name search state meta page results order what } +# what: parents childs(n) aliases +sub dbTagGet { + my $self = shift; + my %o = ( + order => 't.id ASC', + page => 1, + results => 10, + what => '', + @_ + ); + + $o{search} =~ s/%//g if $o{search}; + + my %where = ( + $o{id} ? ( + 't.id = ?' => $o{id} ) : (), + $o{noid} ? ( + 't.id <> ?' => $o{noid} ) : (), + $o{name} ? ( + 't.id = (SELECT id FROM tags LEFT JOIN tags_aliases ON id = tag WHERE lower(name) = ? OR lower(alias) = ? LIMIT 1)' => [ lc $o{name}, lc $o{name} ]) : (), + defined $o{state} && $o{state} != -1 ? ( + 't.state = ?' => $o{state} ) : (), + !defined $o{state} && !$o{id} && !$o{name} ? ( + '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 ) : (), + ); + + my($r, $np) = $self->dbPage(\%o, q| + SELECT t.id, t.meta, t.name, t.description, t.added, t.state, t.c_vns + FROM tags t + !W + ORDER BY !s|, + \%where, $o{order} + ); + + if(@$r && $o{what} =~ /aliases/) { + my %r = map { + $_->{aliases} = []; + ($_->{id}, $_->{aliases}) + } @$r; + + push @{$r{$_->{tag}}}, $_->{alias} for (@{$self->dbAll(q| + SELECT tag, alias FROM tags_aliases WHERE tag IN(!l)|, [ keys %r ] + )}); + } + + if($o{what} =~ /parents\((\d+)\)/) { + $_->{parents} = $self->dbTagTree($_->{id}, $1, 0) for(@$r); + } + + if($o{what} =~ /childs\((\d+)\)/) { + $_->{childs} = $self->dbTagTree($_->{id}, $1, 1) for(@$r); + } + + return wantarray ? ($r, $np) : $r; +} + + +# plain interface to the tag_tree() stored procedure in pgsql +sub dbTagTree { + my($self, $id, $lvl, $dir) = @_; + return $self->dbAll('SELECT * FROM tag_tree(?, ?, ?)', $id, $lvl||0, $dir?1:0); +} + + +# args: tag id, %options->{ columns in the tags table + parents + aliases } +sub dbTagEdit { + my($self, $id, %o) = @_; + + $self->dbExec('UPDATE tags !H WHERE id = ?', { + $o{upddate} ? ('added = ?' => time) : (), + map { +"$_ = ?" => $o{$_} } qw|name meta description state| + }, $id); + $self->dbExec('DELETE FROM tags_aliases WHERE tag = ?', $id); + $self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_) for (@{$o{aliases}}); + $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} == 1; +} + + +# same args as dbTagEdit, without the first tag id +# returns the id of the new tag +sub dbTagAdd { + my($self, %o) = @_; + my $id = $self->dbRow('INSERT INTO tags (name, meta, description, state) VALUES (!l) RETURNING id', + [ map $o{$_}, qw|name meta description state| ] + )->{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}}); + return $id; +} + + +sub dbTagMerge { + my($self, $id, @merge) = @_; + $self->dbExec('UPDATE tags_vn SET tag = ? WHERE tag IN(!l)', $id, \@merge); + $self->dbExec('UPDATE tags_aliases SET tag = ? WHERE tag IN(!l)', $id, \@merge); + $self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_->{name}) + for (@{$self->dbAll('SELECT name FROM tags WHERE id IN(!l)', \@merge)}); + $self->dbExec('DELETE FROM tags_parents WHERE tag IN(!l)', \@merge); + $self->dbExec('DELETE FROM tags WHERE id IN(!l)', \@merge); +} + + +# Directly fetch rows from tags_vn +# Arguments: %options->{ vid uid tag } +sub dbTagLinks { + my($self, %o) = @_; + return $self->dbAll( + 'SELECT tag, vid, uid, vote, spoiler FROM tags_vn !W', + { map { +"$_ = ?" => $o{$_} } keys %o } + ); +} + + +# Change a user's tags for a VN entry +# Arguments: uid, vid, [ [ tag, vote, spoiler ], .. ] +sub dbTagLinkEdit { + my($self, $uid, $vid, $tags) = @_; + $self->dbExec('DELETE FROM tags_vn WHERE vid = ? AND uid = ?', $vid, $uid); + $self->dbExec('INSERT INTO tags_vn (tag, vid, uid, vote, spoiler) VALUES (?, ?, ?, ?, ?)', + $_->[0], $vid, $uid, $_->[1], $_->[2] == -1 ? undef : $_->[2] + ) for (@$tags); +} + + +# Fetch all tags related to a VN or User +# Argument: %options->{ uid vid minrating results what page order } +# what: vns +sub dbTagStats { + my($self, %o) = @_; + $o{results} ||= 10; + $o{page} ||= 1; + $o{order} ||= 't.name ASC'; + $o{what} ||= ''; + + my %where = ( + $o{uid} ? ( + 'tv.uid = ?' => $o{uid} ) : (), + $o{vid} ? ( + 'tv.vid = ?' => $o{vid} ) : (), + ); + my($r, $np) = $self->dbPage(\%o, q| + SELECT t.id, t.name, count(*) as cnt, avg(tv.vote) as rating, COALESCE(avg(tv.spoiler), 0) as spoiler + FROM tags t + JOIN tags_vn tv ON tv.tag = t.id + !W + GROUP BY t.id, t.name + !s + ORDER BY !s|, + \%where, defined $o{minrating} ? "HAVING avg(tv.vote) > $o{minrating}" : '', + $o{order} + ); + + if(@$r && $o{what} =~ /vns/ && $o{uid}) { + my %r = map { + $_->{vns} = []; + ($_->{id}, $_->{vns}) + } @$r; + + push @{$r{$_->{tag}}}, $_ for (@{$self->dbAll(q| + SELECT tv.tag, tv.vote, tv.spoiler, vr.vid, vr.title, vr.original + FROM tags_vn tv + JOIN vn v ON v.id = tv.vid + JOIN vn_rev vr ON vr.id = v.latest + WHERE tv.uid = ? + AND tv.tag IN(!l) + ORDER BY vr.title ASC|, + $o{uid}, [ keys %r ] + )}); + } + + return wantarray ? ($r, $np) : $r; +} + + +# Fetch all VNs from a tag, including VNs from child tags, and provide ratings for them. +# Argument: %options->{ tag order page results maxspoil } +sub dbTagVNs { + my($self, %o) = @_; + $o{order} ||= 'tb.rating DESC'; + $o{page} ||= 1; + $o{results} ||= 10; + + my %where = ( + 'tag = ?' => $o{tag}, + defined $o{maxspoil} ? ( + 'tb.spoiler <= ?' => $o{maxspoil} ) : (), + ); + + my($r, $np) = $self->dbPage(\%o, q| + SELECT tb.tag, tb.vid, tb.users, tb.rating, tb.spoiler, vr.title, vr.original, v.c_languages, v.c_released, v.c_platforms, v.c_popularity + FROM tags_vn_stored tb + JOIN vn v ON v.id = tb.vid + JOIN vn_rev vr ON vr.id = v.latest + !W + ORDER BY !s|, + \%where, $o{order}); + return wantarray ? ($r, $np) : $r; +} + +1; + diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm index 3a327197..3a93a9c5 100644 --- a/lib/VNDB/DB/Users.pm +++ b/lib/VNDB/DB/Users.pm @@ -48,6 +48,8 @@ sub dbUserGet { '(SELECT COUNT(DISTINCT rv.vid) FROM rlists rl JOIN releases r ON rl.rid = r.id JOIN releases_vn rv ON rv.rid = r.latest WHERE uid = u.id) AS vncount', '(SELECT COUNT(*) FROM threads_posts WHERE uid = u.id) AS postcount', '(SELECT COUNT(*) FROM threads_posts WHERE uid = u.id AND num = 1) AS threadcount', + '(SELECT COUNT(DISTINCT tag) FROM tags_vn WHERE uid = u.id) AS tagcount', + '(SELECT COUNT(DISTINCT vid) FROM tags_vn WHERE uid = u.id) AS tagvncount', ) : (), ); diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index 8a5c11d4..0a5a9038 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -5,8 +5,8 @@ use strict; use warnings; use YAWF ':html'; use Exporter 'import'; -use POSIX 'strftime'; -our @EXPORT = qw| shorten age date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon |; +use POSIX 'strftime', 'ceil', 'floor'; +our @EXPORT = qw| shorten age date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon tagscore|; # I would've done this as a #define if this was C... @@ -156,7 +156,7 @@ sub bb2html { next; } elsif(!grep(/url/, @open) && ( s{^(.*[^\w]|)([tdvpr][1-9][0-9]*)\.([1-9][0-9]*)([^\w].*|)$}{$e->($1).qq|<a href="/$2.$3">$2.$3</a>|.$e->($4)}e || - s{^(.*[^\w]|)([tduvpr][1-9][0-9]*)([^\w].*|)$}{$e->($1).qq|<a href="/$2">$2</a>|.$e->($3)}e)) { + s{^(.*[^\w]|)([tdvprug][1-9][0-9]*)([^\w].*|)$}{$e->($1).qq|<a href="/$2">$2</a>|.$e->($3)}e)) { $length += length $lit; last if $maxlength && $length > $maxlength; $result .= $_; @@ -238,5 +238,33 @@ sub cssicon { } +# Tag score in html tags, argument: score, users +sub tagscore { + my $s = shift; + div class => 'taglvl', style => sprintf('width: %.0fpx', ($s-floor($s))*10), ' ' if $s < 0 && $s-floor($s) > 0; + for(-3..3) { + div(class => "taglvl taglvl0", sprintf '%.1f', $s), next if !$_; + if($_ < 0) { + if($s > 0 || floor($s) > $_) { + div class => "taglvl taglvl$_", ' '; + } elsif(floor($s) != $_) { + div class => "taglvl taglvl$_ taglvlsel", ' '; + } else { + div class => "taglvl taglvl$_ taglvlsel", style => sprintf('width: %.0fpx', 10-($s-$_)*10), ' '; + } + } else { + if($s < 0 || ceil($s) < $_) { + div class => "taglvl taglvl$_", ' '; + } elsif(ceil($s) != $_) { + div class => "taglvl taglvl$_ taglvlsel", ' '; + } else { + div class => "taglvl taglvl$_ taglvlsel", style => sprintf('width: %.0fpx', 10-($_-$s)*10), ' '; + } + } + } + div class => 'taglvl', style => sprintf('width: %.0fpx', (ceil($s)-$s)*10), ' ' if $s > 0 && ceil($s)-$s > 0; +} + + 1; diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm index 5f247bd4..214753e8 100644 --- a/lib/VNDB/Handler/Discussions.pm +++ b/lib/VNDB/Handler/Discussions.pm @@ -11,7 +11,7 @@ use VNDB::Func; YAWF::register( qr{t([1-9]\d*)(?:/([1-9]\d*))?} => \&thread, qr{t([1-9]\d*)\.([1-9]\d*)} => \&redirect, - qr{t/(db|an|[vpu])([1-9]\d*)?} => \&tagbrowse, + qr{t/(db|an|[vpu])([1-9]\d*)?} => \&board, qr{t([1-9]\d*)/reply} => \&edit, qr{t([1-9]\d*)\.([1-9]\d*)/edit} => \&edit, qr{t/(db|an|[vpu])([1-9]\d*)?/new} => \&edit, @@ -23,7 +23,7 @@ sub thread { my($self, $tid, $page) = @_; $page ||= 1; - my $t = $self->dbThreadGet(id => $tid, what => 'tagtitles')->[0]; + my $t = $self->dbThreadGet(id => $tid, what => 'boardtitles')->[0]; return 404 if !$t->{id} || $t->{hidden} && !$self->authCan('boardmod'); my $p = $self->dbPostGet(tid => $tid, results => 25, page => $page); @@ -35,9 +35,9 @@ sub thread { h1 $t->{title}; h2 'Posted in'; ul; - for (sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } @{$t->{tags}}) { + for (sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } @{$t->{boards}}) { li; - a href => "/t/$_->{type}", $self->{discussion_tags}{$_->{type}}; + a href => "/t/$_->{type}", $self->{discussion_boards}{$_->{type}}; if($_->{iid}) { txt ' > '; a style => 'font-weight: bold', href => "/t/$_->{type}$_->{iid}", "$_->{type}$_->{iid}"; @@ -129,17 +129,17 @@ sub edit { my($self, $tid, $num) = @_; $num ||= 0; - # in case we start a new thread, parse tag - my $tag = ''; + # in case we start a new thread, parse boards + my $board = ''; if($tid !~ /^\d+$/) { return 404 if $tid =~ /(db|an)/ && $num || $tid =~ /[vpu]/ && !$num; - $tag = $tid.($num||''); + $board = $tid.($num||''); $tid = 0; $num = 0; } # get thread and post, if any - my $t = $tid && $self->dbThreadGet(id => $tid, what => 'tags')->[0]; + my $t = $tid && $self->dbThreadGet(id => $tid, what => 'boards')->[0]; return 404 if $tid && !$t->{id}; my $p = $num && $self->dbPostGet(tid => $tid, num => $num)->[0]; @@ -156,7 +156,7 @@ sub edit { $frm = $self->formValidate( !$tid || $num == 1 ? ( { name => 'title', maxlength => 50 }, - { name => 'tags', maxlength => 50 }, + { name => 'boards', maxlength => 50 }, ) : (), $self->authCan('boardmod') ? ( { name => 'locked', required => 0 }, @@ -166,14 +166,14 @@ sub edit { { name => 'msg', maxlenght => 5000 }, ); - # parse and validate the tags - my @tags; - if(!$frm->{_err} && $frm->{tags}) { - for (split /[ ,]/, $frm->{tags}) { + # parse and validate the boards + my @boards; + if(!$frm->{_err} && $frm->{boards}) { + for (split /[ ,]/, $frm->{boards}) { my($ty, $id) = ($1, $2) if /^([a-z]{1,2})([0-9]*)$/; - push @tags, [ $ty, $id ]; - push @{$frm->{_err}}, [ 'tags', 'wrongtag', $_ ] if - !$ty || !$self->{discussion_tags}{$ty} + push @boards, [ $ty, $id ]; + push @{$frm->{_err}}, [ 'boards', 'wrongboard', $_ ] if + !$ty || !$self->{discussion_boards}{$ty} || $ty eq 'an' && ($id || !$self->authCan('boardmod')) || $ty eq 'db' && $id || $ty eq 'v' && (!$id || !$self->dbVNGet(id => $id)->[0]{id}) @@ -189,7 +189,7 @@ sub edit { if(!$tid || $num == 1) { my %thread = ( title => $frm->{title}, - tags => \@tags, + boards => \@boards, hidden => $frm->{hidden}, locked => $frm->{locked}, ); @@ -217,27 +217,27 @@ sub edit { $frm->{msg} ||= $p->{msg}; $frm->{hidden} = $p->{hidden} if $num != 1 && !exists $frm->{hidden}; if($num == 1) { - $frm->{tags} ||= join ' ', sort map $_->[1]?$_->[0].$_->[1]:$_->[0], @{$t->{tags}}; + $frm->{boards} ||= join ' ', sort map $_->[1]?$_->[0].$_->[1]:$_->[0], @{$t->{boards}}; $frm->{title} ||= $t->{title}; $frm->{locked} = $t->{locked} if !exists $frm->{locked}; $frm->{hidden} = $t->{hidden} if !exists $frm->{hidden}; } } - $frm->{tags} ||= $tag; + $frm->{boards} ||= $board; $frm->{nolastmod} = 1 if $num && $self->authCan('boardmod') && !exists $frm->{nolastmod}; # generate html my $title = !$tid ? 'Start new thread' : !$num ? 'Reply to '.$t->{title} : 'Edit post'; - my $url = !$tid ? "/t/$tag/new" : !$num ? "/t$tid/reply" : "/t$tid.$num/edit"; + my $url = !$tid ? "/t/$board/new" : !$num ? "/t$tid/reply" : "/t$tid.$num/edit"; $self->htmlHeader(title => $title, noindex => 1); $self->htmlForm({ frm => $frm, action => $url }, $title => [ [ static => label => 'Username', content => userstr($self->authInfo->{id}, $self->authInfo->{username}) ], !$tid || $num == 1 ? ( [ input => short => 'title', name => 'Thread title' ], - [ input => short => 'tags', name => 'Tags' ], - [ static => content => 'Read <a href="/d9.2">d9.2</a> for information about how to use tags' ], + [ input => short => 'boards', name => 'Board(s)' ], + [ static => content => 'Read <a href="/d9.2">d9.2</a> for information about how to specify boards' ], $self->authCan('boardmod') ? ( [ check => name => 'Locked', short => 'locked' ], ) : (), @@ -257,7 +257,7 @@ sub edit { } -sub tagbrowse { +sub board { my($self, $type, $iid) = @_; $iid ||= ''; return 404 if $type =~ /(db|an)/ && $iid; @@ -273,14 +273,14 @@ sub tagbrowse { $self->dbVNGet(id => $iid)->[0]; return 404 if $iid && !$obj; my $ititle = $obj && ($obj->{title}||$obj->{name}||$obj->{username}); - my $title = !$obj ? $self->{discussion_tags}{$type} : 'Related discussions for '.$ititle; + my $title = !$obj ? $self->{discussion_boards}{$type} : 'Related discussions for '.$ititle; my($list, $np) = $self->dbThreadGet( type => $type, $iid ? (iid => $iid) : (), results => 50, page => $f->{p}, - what => 'firstpost lastpost tagtitles', + what => 'firstpost lastpost boardtitles', order => $type eq 'an' ? 't.id DESC' : 'tpl.date DESC', ); @@ -292,7 +292,7 @@ sub tagbrowse { p; a href => '/t', 'Discussion board'; txt ' > '; - a href => "/t/$type", $self->{discussion_tags}{$type}; + a href => "/t/$type", $self->{discussion_boards}{$type}; if($iid) { txt ' > '; a style => 'font-weight: bold', href => "/t/$type$iid", "$type$iid"; @@ -324,7 +324,7 @@ sub index { div class => 'mainbox'; h1 'Discussion board index'; p class => 'browseopts'; - a href => '/t/'.$_, $self->{discussion_tags}{$_} + a href => '/t/'.$_, $self->{discussion_boards}{$_} for (qw|an db v p u|); end; end; @@ -334,11 +334,11 @@ sub index { type => $_, results => 5, page => 1, - what => 'firstpost lastpost tagtitles', + what => 'firstpost lastpost boardtitles', order => 'tpl.date DESC', ); h1 class => 'boxtitle'; - a href => "/t/$_", $self->{discussion_tags}{$_}; + a href => "/t/$_", $self->{discussion_boards}{$_}; end; _threadlist($self, $list, {p=>1}, 0, "/t"); } @@ -377,17 +377,17 @@ sub _threadlist { end; end; Tr $n % 2 ? ( class => 'odd' ) : (); - td colspan => 4, class => 'tags'; + td colspan => 4, class => 'boards'; txt ' > '; my $i = 1; - for(sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } @{$o->{tags}}) { + for(sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } @{$o->{boards}}) { last if $i++ > 5; txt ', ' if $i > 2; a href => "/t/$_->{type}".($_->{iid}||''), - title => $_->{original}||$self->{discussion_tags}{$_->{type}}, - shorten $_->{title}||$self->{discussion_tags}{$_->{type}}, 30; + title => $_->{original}||$self->{discussion_boards}{$_->{type}}, + shorten $_->{title}||$self->{discussion_boards}{$_->{type}}, 30; } - txt ', ...' if @{$o->{tags}} > 5; + txt ', ...' if @{$o->{boards}} > 5; end; end; } diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm new file mode 100644 index 00000000..0be1ba10 --- /dev/null +++ b/lib/VNDB/Handler/Tags.pm @@ -0,0 +1,673 @@ + +package VNDB::Handler::Tags; + + +use strict; +use warnings; +use YAWF ':html', ':xml'; +use VNDB::Func; + + +YAWF::register( + qr{g([1-9]\d*)}, \&tagpage, + qr{g([1-9]\d*)/(edit)}, \&tagedit, + qr{g([1-9]\d*)/(add)}, \&tagedit, + qr{g/new}, \&tagedit, + qr{g/list}, \&taglist, + qr{v([1-9]\d*)/tagmod}, \&vntagmod, + qr{u([1-9]\d*)/tags}, \&usertags, + qr{g}, \&tagindex, + qr{xml/tags\.xml}, \&tagxml, +); + + +sub tagpage { + my($self, $tag) = @_; + + my $t = $self->dbTagGet(id => $tag, what => 'parents(0) childs(2) aliases')->[0]; + return 404 if !$t; + + my $f = $self->formValidate( + { name => 's', required => 0, default => 'score', enum => [ qw|score title rel pop| ] }, + { name => 'o', required => 0, default => 'd', enum => [ 'a','d' ] }, + { name => 'p', required => 0, default => 1, template => 'int' }, + { name => 'm', required => 0, default => -1, enum => [qw|0 1 2|] }, + ); + return 404 if $f->{_err}; + my $tagspoil = $self->reqCookie('tagspoil'); + $f->{m} = $tagspoil =~ /^[0-2]$/ ? $tagspoil : 1 if $f->{m} == -1; + + my($list, $np) = $t->{meta} || $t->{state} != 2 ? ([],0) : $self->dbTagVNs( + tag => $tag, + order => {score=>'tb.rating',title=>'vr.title',rel=>'v.c_released',pop=>'v.c_popularity'}->{$f->{s}}.($f->{o}eq'a'?' ASC':' DESC'), + page => $f->{p}, + results => 50, + maxspoil => $f->{m}, + ); + + my $title = ($t->{meta} ? 'Meta tag: ' : 'Tag: ').$t->{name}; + $self->htmlHeader(title => $title); + $self->htmlMainTabs('g', $t); + + if($t->{state} != 2) { + div class => 'mainbox'; + h1 "Tag: $t->{name}"; + if($t->{state} == 1) { + div class => 'warning'; + h2 'Tag deleted'; + p; + lit qq|This tag has been removed from the database, and cannot be used or re-added.|. + qq| File a request on the <a href="/t/db">discussion board</a> if you disagree with this.|; + end; + end; + } else { + div class => 'notice'; + h2 'Waiting for approval'; + p 'This tag is waiting for a moderator to approve it. You can still use it to tag VNs as you would with a normal tag.'; + end; + } + end; + return $self->htmlFooter if $t->{state} == 1 && !$self->authCan('tagmod'); + } + + div class => 'mainbox'; + a class => 'addnew', href => "/g$tag/add", ($self->authCan('tagmod')?'Create':'Request').' child tag' if $self->authCan('tag'); + h1 $title; + + p; + my @p = @{$t->{parents}}; + my @r; + for (0..$#p) { + if($_ && $p[$_-1]{lvl} < $p[$_]{lvl}) { + pop @r for (1..($p[$_]{lvl}-$p[$_-1]{lvl})); + } + if($_ < $#p && $p[$_+1]{lvl} < $p[$_]{lvl}) { + push @r, $p[$_]; + } elsif($#p == $_ || $p[$_+1]{lvl} >= $p[$_]{lvl}) { + a href => '/g', 'Tags'; + for ($p[$_], reverse @r) { + txt ' > '; + a href => "/g$_->{tag}", $_->{name}; + } + txt " > $t->{name}\n"; + } + } + if(!@p) { + a href => '/g', 'Tags'; + txt " > $t->{name}\n"; + } + end; + + if($t->{description}) { + p class => 'center'; + lit bb2html $t->{description}; + end; + } + if(@{$t->{aliases}}) { + p class => 'center'; + b "Aliases:\n"; + txt "$_\n" for (@{$t->{aliases}}); + end; + } + end; + + _childtags($self, $t) if @{$t->{childs}}; + _vnlist($self, $t, $f, $list, $np) if !$t->{meta} && $t->{state} == 2; + + $self->htmlFooter; +} + +# used for on both /g and /g+ +sub _childtags { + my($self, $t, $index) = @_; + + my @l = @{$t->{childs}}; + my @tags; + for (0..$#l) { + if($l[$_]{lvl} == $l[0]{lvl}) { + $l[$_]{childs} = []; + push @tags, $l[$_]; + } else { + push @{$tags[$#tags]{childs}}, $l[$_]; + } + } + + div class => 'mainbox'; + if(!$index) { + h1 'Child tags'; + } else { + h1 'Tag tree'; + } + ul class => 'tagtree'; + for my $p (sort { @{$b->{childs}} <=> @{$a->{childs}} } @tags) { + li; + a href => "/g$p->{tag}", $p->{name}; + b class => 'grayedout', " ($p->{c_vns})" if $p->{c_vns}; + end, next if !@{$p->{childs}}; + ul; + for (0..$#{$p->{childs}}) { + last if $_ >= 5 && @{$p->{childs}} > 6; + li; + txt '> '; + a href => "/g$p->{childs}[$_]{tag}", $p->{childs}[$_]{name}; + b class => 'grayedout', " ($p->{childs}[$_]{c_vns})" if $p->{childs}[$_]{c_vns}; + end; + } + if(@{$p->{childs}} > 6) { + li; + txt '> '; + a href => "/g$p->{tag}", style => 'font-style: italic', sprintf '%d more tags...', @{$p->{childs}}-5; + end; + } + end; + end; + } + end; + clearfloat; + br; + end; +} + +sub _vnlist { + my($self, $t, $f, $list, $np) = @_; + div class => 'mainbox'; + h1 'Visual novels'; + p class => 'browseopts'; + a href => "/g$t->{id}?m=0", $f->{m} == 0 ? (class => 'optselected') : (), onclick => "setCookie('tagspoil', 0);return true;", 'Hide spoilers'; + a href => "/g$t->{id}?m=1", $f->{m} == 1 ? (class => 'optselected') : (), onclick => "setCookie('tagspoil', 1);return true;", 'Show minor spoilers'; + a href => "/g$t->{id}?m=2", $f->{m} == 2 ? (class => 'optselected') : (), onclick => "setCookie('tagspoil', 2);return true;", 'Show major spoilers'; + end; + if(!@$list) { + p "\n\nThis tag has not been linked to any visual novels yet, or they were hidden because of the spoiler settings."; + } + end; + return if !@$list; + $self->htmlBrowse( + class => 'tagvnlist', + items => $list, + options => $f, + nextpage => $np, + pageurl => "/g$t->{id}?m=$f->{m};o=$f->{o};s=$f->{s}", + sorturl => "/g$t->{id}?m=$f->{m}", + header => [ + [ 'Score', 'score' ], + [ 'Title', 'title' ], + [ '', 0 ], + [ '', 0 ], + [ 'Released', 'rel' ], + [ 'Popularity', 'pop' ], + ], + row => sub { + my($s, $n, $l) = @_; + Tr $n % 2 ? (class => 'odd') : (); + td class => 'tc1'; + tagscore $l->{rating}; + i sprintf '(%d)', $l->{users}; + end; + td class => 'tc2'; + a href => '/v'.$l->{vid}, title => $l->{original}||$l->{title}, shorten $l->{title}, 100; + end; + td class => 'tc3'; + $_ ne 'oth' && cssicon $_, $self->{platforms}{$_} + for (sort split /\//, $l->{c_platforms}); + end; + td class => 'tc4'; + cssicon "lang $_", $self->{languages}{$_} + for (reverse sort split /\//, $l->{c_languages}); + end; + td class => 'tc5'; + lit monthstr $l->{c_released}; + end; + td class => 'tc6', sprintf '%.2f', $l->{c_popularity}*100; + end; + } + ); +} + + +sub tagedit { + my($self, $tag, $act) = @_; + + my($frm, $par); + if($act && $act eq 'add') { + $par = $self->dbTagGet(id => $tag)->[0]; + return 404 if !$par; + $frm->{parents} = $tag; + $tag = undef; + } + + return $self->htmlDenied if !$self->authCan('tag') || $tag && !$self->authCan('tagmod'); + + my $t = $tag && $self->dbTagGet(id => $tag, what => 'parents(1) aliases')->[0]; + return 404 if $tag && !$t; + + if($self->reqMethod eq 'POST') { + $frm = $self->formValidate( + { name => 'name', required => 1, maxlength => 250 }, + { name => 'state', required => 0, default => 0, enum => [ 0..2 ] }, + { name => 'meta', required => 0, default => 0 }, + { name => 'alias', required => 0, maxlength => 1024, default => '' }, + { name => 'description', required => 0, maxlength => 1024, default => '' }, + { name => 'parents', required => 0, default => '' }, + { name => 'merge', required => 0, default => '' }, + ); + my @aliases = split /[\t\s]*\n[\t\s]*/, $frm->{alias}; + my @parents = split /[\t\s]*,[\t\s]*/, $frm->{parents}; + my @merge = split /[\t\s]*,[\t\s]*/, $frm->{merge}; + if(!$frm->{_err}) { + my $c = $self->dbTagGet(name => $frm->{name}, noid => $tag); + push @{$frm->{_err}}, [ 'name', 'tagexists', $c->[0] ] if @$c; + for (@aliases) { + $c = $self->dbTagGet(name => $_, noid => $tag); + push @{$frm->{_err}}, [ 'alias', 'tagexists', $c->[0] ] if @$c; + } + for(@parents, @merge) { + my $c = $self->dbTagGet(name => $_, noid => $tag); + push @{$frm->{_err}}, [ 'parents', 'func', [ 0, "Tag '$_' not found." ]] if !@$c; + $_ = $c->[0]{id}; + } + } + if(!$frm->{_err}) { + $frm->{state} = $frm->{meta} = 0 if !$self->authCan('tagmod'); + my %opts = ( + name => $frm->{name}, + state => $frm->{state}, + description => $frm->{description}, + meta => $frm->{meta}?1:0, + aliases => \@aliases, + parents => \@parents, + ); + if(!$tag) { + $tag = $self->dbTagAdd(%opts); + $self->multiCmd("ircnotify g$tag"); + } else { + $self->dbTagEdit($tag, %opts, upddate => $frm->{state} == 2 && $t->{state} != 2); + } + $self->dbTagMerge($tag, @merge) if $self->authCan('tagmod') && @merge; + $self->resRedirect("/g$tag", 'post'); + return; + } + } + + if($tag) { + $frm->{$_} ||= $t->{$_} for (qw|name meta description state|); + $frm->{alias} ||= join "\n", @{$t->{aliases}}; + $frm->{parents} ||= join ', ', map $_->{name}, @{$t->{parents}}; + } + + my $title = $par ? "Add child tag to $par->{name}" : $tag ? "Edit tag: $t->{name}" : 'Add new tag'; + $self->htmlHeader(title => $title, noindex => 1); + $self->htmlMainTabs('g', $par || $t, 'edit') if $t || $par; + + if(!$self->authCan('tagmod')) { + div class => 'mainbox'; + h1 'Requesting new tag'; + div class => 'notice'; + h2 'Your tag must be approved'; + p 'Because all tags have to be approved by moderators, it can take a while before it '. + 'will show up in the tag list or on visual novel pages. You can still vote on tag even if '. + 'it has not been approved yet, though.'; + end; + end; + } + + $self->htmlForm({ frm => $frm, action => $par ? "/g$par->{id}/add" : $tag ? "/g$tag/edit" : '/g/new' }, $title => [ + [ input => short => 'name', name => 'Primary name' ], + $self->authCan('tagmod') ? ( + [ 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!' ] : (), + ) : (), + [ textarea => short => 'alias', name => "Aliases\n(separated by newlines)", cols => 30, rows => 4 ], + [ textarea => short => 'description', name => 'Description' ], + [ static => content => 'What should the tag be used for? Having a good description helps users choose which tags to link to a VN.' ], + [ input => short => 'parents', name => 'Parent tags' ], + [ static => content => "Comma separated list of tag names to be used as parent for this tag." ], + $self->authCan('tagmod') ? ( + [ part => title => 'Merge tags' ], + [ input => short => 'merge', name => 'Tags to merge' ], + [ static => content => 'Comma separated list of tag names to merge into this one.' + .' All votes and aliases/names will be moved over to this tag, and the old tags will be deleted.' + .' Just leave this field empty if you don\'t intend to do a merge.' + .'<br />WARNING: this action cannot be undone!' ], + ) : (), + ]); + $self->htmlFooter; +} + + +sub taglist { + my $self = shift; + + my $f = $self->formValidate( + { name => 's', required => 0, default => 'name', enum => ['added', 'name'] }, + { name => 'o', required => 0, default => 'a', enum => ['a', 'd'] }, + { name => 'p', required => 0, default => 1, template => 'int' }, + { name => 't', required => 0, default => -1, enum => [ -1..2 ] }, + { name => 'q', required => 0, default => '' }, + ); + $f->{t} = 0 if !$self->authCan('tagmod') && $f->{t} == 1; + return 404 if $f->{_err}; + + my($t, $np) = $self->dbTagGet( + order => $f->{s}.($f->{o}eq'd'?' DESC':' ASC'), + page => $f->{p}, + results => 50, + $f->{t} != -1 || $self->authCan('tagmod') ? ( + state => $f->{t} ) : (), + search => $f->{q}, + ); + + my $title = $f->{t} == -1 ? 'Browse tags' : $f->{t} == 0 ? 'Tags awaiting moderation' : $f->{t} == 1 ? 'Deleted tags' : 'All visible tags'; + $self->htmlHeader(title => $title); + div class => 'mainbox'; + h1 $title; + form class => 'search', action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get'; + fieldset; + input type => 'hidden', name => 't', value => $f->{t}; + input type => 'text', name => 'q', id => 'q', class => 'text', value => $f->{q}; + input type => 'submit', class => 'submit', value => 'Search!'; + end; + end; + p class => 'browseopts'; + a href => "/g/list?q=$f->{q};t=-1", $f->{t} == -1 ? (class => 'optselected') : (), 'All'; + a href => "/g/list?q=$f->{q};t=0", $f->{t} == 0 ? (class => 'optselected') : (), 'Awaiting moderation'; + a href => "/g/list?q=$f->{q};t=1", $f->{t} == 1 ? (class => 'optselected') : (), 'Deleted' if $self->authCan('tagmod'); + a href => "/g/list?q=$f->{q};t=2", $f->{t} == 2 ? (class => 'optselected') : (), 'Accepted'; + end; + if(!@$t) { + p 'No results found'; + } + end; + if(@$t) { + $self->htmlBrowse( + class => 'taglist', + options => $f, + nextpage => $np, + items => $t, + pageurl => "/g/list?t=$f->{t};q=$f->{q};s=$f->{s};o=$f->{o}", + sorturl => "/g/list?t=$f->{t};q=$f->{q}", + header => [ + [ 'Created', 'added' ], + [ 'Tag', 'name' ], + ], + row => sub { + my($s, $n, $l) = @_; + Tr $n % 2 ? (class => 'odd') : (); + td class => 'tc1', age $l->{added}; + td class => 'tc3'; + a href => "/g$l->{id}", $l->{name}; + if($f->{t} == -1) { + b class => 'grayedout', ' awaiting moderation' if $l->{state} == 0; + b class => 'grayedout', ' deleted' if $l->{state} == 1; + } + end; + end; + } + ); + } + $self->htmlFooter; +} + + +sub vntagmod { + my($self, $vid) = @_; + + my $v = $self->dbVNGet(id => $vid)->[0]; + return 404 if !$v; + + return $self->htmlDenied if !$self->authCan('tag'); + + if($self->reqMethod eq 'POST') { + my $frm = $self->formValidate( + { name => 'taglinks', required => 0, default => '', maxlength => 10240, regex => [ qr/^[1-9][0-9]*,-?[1-3],-?[0-2]( [1-9][0-9]*,-?[1-3],-?[0-2])*$/, 'meh' ] } + ); + return 404 if $frm->{_err}; + $self->dbTagLinkEdit($self->authInfo->{id}, $vid, [ map [ split /,/ ], split / /, $frm->{taglinks}]); + } + + my $my = $self->dbTagLinks(vid => $vid, uid => $self->authInfo->{id}); + my $tags = $self->dbTagStats(vid => $vid, result => 9999); + + my $frm; + + $self->htmlHeader(title => "Add/remove tags for $v->{title}", noindex => 1, js => 'forms'); + $self->htmlMainTabs('v', $v, 'tagmod'); + div class => 'mainbox'; + h1 "Add/remove tags for $v->{title}"; + div class => 'notice'; + h2 'Tagging'; + ul; + li "Don't forget to hit the submit button on the bottom of the page after changing anything here!"; + li 'Tag guidelines?'; + li 'Some tag information on the site is cached, it can take up to an hour for your changes to be visible everywhere.'; + end; + end; + end; + $self->htmlForm({ frm => $frm, action => "/v$vid/tagmod", hitsubmit => 1 }, 'Tags' => [ + [ hidden => short => 'taglinks', value => '' ], + [ static => nolabel => 1, content => sub { + table id => 'tagtable'; + thead; + Tr; + td ''; + td colspan => 2, class => 'tc2_1', 'Others'; + td colspan => 2, class => 'tc3_1', 'You'; + end; + Tr; + my $i=0; + td class => 'tc'.++$i, $_ for(qw|Tag Rating Spoiler Rating Spoiler|); + end; + end; + tfoot; Tr; + td colspan => 5; + input type => 'text', class => 'text', name => 'addtag', value => ''; + input type => 'button', class => 'submit', value => 'Add tag'; + br; + p; + lit 'Check the <a href="/g">tag list</a> to browse all available tags.'. + '<br />Can\'t find what you\'re looking for? <a href="/g/new">Request a new tag</a>.'; + end; + end; + end; end; + tbody; + for my $t (sort { $a->{name} cmp $b->{name} } @$tags) { + my $m = (grep $_->{tag} == $t->{id}, @$my)[0] || {}; + Tr; + td class => 'tc1'; + a href => "/g$t->{id}", $t->{name}; + end; + td class => 'tc2'; + tagscore !$m->{vote} ? $t->{rating} : $t->{cnt} == 1 ? 0 : ($t->{rating}*$t->{cnt} - $m->{vote}) / ($t->{cnt}-1); + i ' ('.($t->{cnt} - ($m->{vote} ? 1 : 0)).')'; + end; + td class => 'tc3', sprintf '%.2f', $t->{spoiler}; + td class => 'tc4', $m->{vote}||0; + td class => 'tc5', defined $m->{spoiler} ? $m->{spoiler} : -1; + end; + } + end; + end; + } ], + ]); + $self->htmlFooter; +} + + +sub usertags { + my($self, $uid) = @_; + + my $u = $self->dbUserGet(uid => $uid)->[0]; + return 404 if !$u; + + my $f = $self->formValidate( + { name => 's', required => 0, default => 'cnt', enum => [ qw|cnt name| ] }, + { name => 'o', required => 0, default => 'd', enum => [ 'a','d' ] }, + { name => 'p', required => 0, default => 1, template => 'int' }, + ); + return 404 if $f->{_err}; + + # TODO: might want to use AJAX to load the VN list on request + my($list, $np) = $self->dbTagStats( + uid => $uid, + page => $f->{p}, + order => ($f->{s}eq'cnt'?'COUNT(*)':'name').($f->{o}eq'a'?' ASC':' DESC'), + what => 'vns', + ); + + $self->htmlHeader(title => "Tags by $u->{username}", noindex => 1); + $self->htmlMainTabs('u', $u, 'tags'); + div class => 'mainbox'; + h1 "Tags by $u->{username}"; + if(@$list) { + p 'Warning: spoilery tags are not hidden in this list!'; + } else { + p "$u->{username} doesn't seem to have used the tagging system yet..."; + } + end; + + if(@$list) { + $self->htmlBrowse( + class => 'tagstats', + options => $f, + nextpage => $np, + items => $list, + pageurl => "/u$u->{id}/tags?s=$f->{s};o=$f->{o}", + sorturl => "/u$u->{id}/tags", + header => [ + sub { + td class => 'tc1'; + b id => 'relhidall'; + lit '<i>▸</i> #VNs '; + end; + lit $f->{s} eq 'cnt' && $f->{o} eq 'a' ? "\x{25B4}" : qq|<a href="/u$u->{id}/tags?o=a;s=cnt">\x{25B4}</a>|; + lit $f->{s} eq 'cnt' && $f->{o} eq 'd' ? "\x{25BE}" : qq|<a href="/u$u->{id}/tags?o=d;s=cnt">\x{25BE}</a>|; + end; + }, + [ 'Tag', 'name' ], + [ ' ', '' ], + ], + row => sub { + my($s, $n, $l) = @_; + Tr $n % 2 ? (class => 'odd') : (); + td class => 'tc1 relhid_but', id => "tag$l->{id}"; + lit "<i>▸</i> $l->{cnt}"; + end; + td class => 'tc2', colspan => 2; + a href => "/g$l->{id}", $l->{name}; + end; + end; + for(@{$l->{vns}}) { + Tr class => "relhid tag$l->{id}"; + td class => 'tc1_1'; + tagscore $_->{vote}; + end; + td class => 'tc1_2'; + a href => "/v$_->{vid}", title => $_->{original}||$_->{title}, shorten $_->{title}, 50; + end; + td class => 'tc1_3', !defined $_->{spoiler} ? ' ' : ['No spoiler', 'Minor spoiler', 'Major spoiler']->[$_->{spoiler}]; + end; + } + }, + ); + } + $self->htmlFooter; +} + + +sub tagindex { + my $self = shift; + + $self->htmlHeader(title => 'Browse tags'); + div class => 'mainbox'; + h1 'Search tags'; + form class => 'search', action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get'; + fieldset; + input type => 'text', name => 'q', id => 'q', class => 'text'; + input type => 'submit', class => 'submit', value => 'Search!'; + end; + end; + end; + + my $t = $self->dbTagTree(0, 2, 1); + _childtags($self, {childs => $t}, 1); + + # Recently added + div class => 'mainbox threelayout'; + a class => 'right', href => '/g/list', 'Browse all tags'; + my $r = $self->dbTagGet(order => 'added DESC', results => 10); + h1 'Recently added'; + ul; + for (@$r) { + li; + txt age $_->{added}; + txt ' '; + a href => "/g$_->{id}", $_->{name}; + end; + } + end; + end; + + # Popular + div class => 'mainbox threelayout'; + $r = $self->dbTagGet(order => 'c_vns DESC', meta => 0, results => 10); + h1 'Popular tags'; + ul; + for (@$r) { + li; + a href => "/g$_->{id}", $_->{name}; + txt " ($_->{c_vns})"; + end; + } + end; + end; + + # Moderation queue + div class => 'mainbox threelayout last'; + a class => 'right', href => '/g/list?t=0;o=d;s=added', 'Moderation queue'; + h1 'Awaiting moderation'; + $r = $self->dbTagGet(state => 0, order => 'added DESC', results => 10); + if(@$r) { + ul; + for (@$r) { + li; + txt age $_->{added}; + txt ' '; + a href => "/g$_->{id}", $_->{name}; + end; + } + end; + } else { + p 'Moderation queue empty! yay!'; + } + end; + clearfloat; + $self->htmlFooter; +} + + +sub tagxml { + my $self = shift; + + my $q = $self->formValidate({ name => 'q', maxlength => 500 }); + return 404 if $q->{_err}; + $q = $q->{q}; + + my($list, $np) = $self->dbTagGet( + $q =~ /^g([1-9]\d*)/ ? (id => $1) : $q =~ /^name:(.+)$/ ? (name => $1) : (search => $q), + results => 10, + page => 1, + ); + + $self->resHeader('Content-type' => 'text/xml; charset=UTF-8'); + xml; + tag 'tags', more => $np ? 'yes' : 'no', query => $q; + for(@$list) { + tag 'item', id => $_->{id}, meta => $_->{meta} ? 'yes' : 'no', state => $_->{state}, $_->{name}; + } + end; +} + +1; diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm index f34943ba..3bbcbf78 100644 --- a/lib/VNDB/Handler/Users.pm +++ b/lib/VNDB/Handler/Users.pm @@ -86,6 +86,12 @@ sub userpage { end; Tr ++$i % 2 ? (class => 'odd') : (); + td 'Tags'; + td !$u->{c_tags} ? '-' : sprintf '%d votes on %d distinct tags and %d visual novels', + $u->{c_tags}, $u->{tagcount}, $u->{tagvncount}; + end; + + Tr ++$i % 2 ? (class => 'odd') : (); td 'List stats'; td !$u->{show_list} ? 'hidden' : sprintf '%d release%s of %d visual novel%s', @@ -417,7 +423,7 @@ sub list { my($self, $char) = @_; my $f = $self->formValidate( - { name => 's', required => 0, default => 'username', enum => [ qw|username registered votes changes| ] }, + { name => 's', required => 0, default => 'username', enum => [ qw|username registered votes changes tags| ] }, { name => 'o', required => 0, default => 'a', enum => [ 'a','d' ] }, { name => 'p', required => 0, default => 1, template => 'int' }, ); @@ -435,7 +441,7 @@ sub list { end; my($list, $np) = $self->dbUserGet( - order => ($f->{s} eq 'changes' ? 'c_' : $f->{s} eq 'votes' ? 'NOT show_list, c_' : '').$f->{s}.($f->{o} eq 'a' ? ' ASC' : ' DESC'), + order => ($f->{s} eq 'changes' || $f->{s} eq 'tags' ? 'c_' : $f->{s} eq 'votes' ? 'NOT show_list, c_' : '').$f->{s}.($f->{o} eq 'a' ? ' ASC' : ' DESC'), $char ne 'all' ? ( firstchar => $char ) : (), results => 50, @@ -453,6 +459,7 @@ sub list { [ 'Registered', 'registered' ], [ 'Votes', 'votes' ], [ 'Edits', 'changes' ], + [ 'Tags', 'tags' ], ], row => sub { my($s, $n, $l) = @_; @@ -468,6 +475,9 @@ sub list { td class => 'tc4'; lit !$l->{c_changes} ? 0 : qq|<a href="/u$l->{id}/hist">$l->{c_changes}</a>|; end; + td class => 'tc5'; + lit !$l->{c_tags} ? 0 : qq|<a href="/u$l->{id}/tags">$l->{c_tags}</a>|; + end; end; }, ); diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index 6790ae6e..8363b500 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -27,7 +27,6 @@ sub edit { my %b4 = !$vid ? () : ( (map { $_ => $v->{$_} } qw|title original desc alias length l_wp l_encubed l_renai l_vnn img_nsfw|), anime => join(' ', sort { $a <=> $b } map $_->{id}, @{$v->{anime}}), - categories => join(',', map $_->[0].$_->[1], sort { $a->[0] cmp $b->[0] } @{$v->{categories}}), relations => join('|||', map $_->{relation}.','.$_->{id}.','.$_->{title}, sort { $a->{id} <=> $b->{id} } @{$v->{relations}}), screenshots => join(' ', map sprintf('%d,%d,%d', $_->{id}, $_->{nsfw}?1:0, $_->{rid}), @{$v->{screenshots}}), ); @@ -45,7 +44,6 @@ sub edit { { name => 'l_renai', required => 0, default => '', maxlength => 100 }, { name => 'l_vnn', required => 0, default => 0, template => 'int' }, { name => 'anime', required => 0, default => '' }, - { name => 'categories', required => 0, default => '', maxlength => 1000 }, { name => 'img_nsfw', required => 0, default => 0 }, { name => 'relations', required => 0, default => '', maxlength => 5000 }, { name => 'screenshots', required => 0, default => '', maxlength => 1000 }, @@ -58,7 +56,6 @@ sub edit { if(!$frm->{_err}) { # parse and re-sort fields that have multiple representations of the same information my $anime = [ grep /^[0-9]+$/, split /[ ,]+/, $frm->{anime} ]; - my $categories = [ map { [ substr($_,0,3), substr($_,3,1) ] } split /,/, $frm->{categories} ]; my $relations = [ map { /^([0-9]+),([0-9]+),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3 ] : () } split /\|\|\|/, $frm->{relations} ]; my $screenshots = [ map /^[0-9]+,[01],[0-9]+$/ ? [split /,/] : (), split / +/, $frm->{screenshots} ]; @@ -75,7 +72,7 @@ sub edit { my %args = ( (map { $_ => $frm->{$_} } qw|title original alias desc length l_wp l_encubed l_renai l_vnn editsum img_nsfw|), anime => $anime, - categories => $categories, + categories => $v->{categories}, relations => $relations, image => $image, screenshots => $screenshots, @@ -181,31 +178,6 @@ sub _form { |], ], - 'Categories' => [ - [ hidden => short => 'categories' ], - [ static => nolabel => 1, content => sub { - lit 'Please read the <a href="/d1">category descriptions</a> before modifying categories!<br /><br />'; - ul; - for my $c (qw| e g t p h l s |) { - $c !~ /[thl]/ ? li : br; - txt $self->{categories}{$c}[0]; - a href => "/d1#$self->{categories}{$c}[2]", class => 'help', '?'; - ul; - for (sort keys %{$self->{categories}{$c}[1]}) { - li; - a href => "#", id => "cat_$c$_"; - b id => "b_$c$_", '-'; - txt ' '.$self->{categories}{$c}[1]{$_}; - end; - end; - } - end; - end if $c !~ /[gph]/; - } - end; - }], - ], - 'Image' => [ [ static => nolabel => 1, content => sub { div class => 'img'; diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 6c336160..56fcc70d 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -125,16 +125,36 @@ sub page { _anime($self, \$i, $v) if @{$v->{anime}}; _useroptions($self, \$i, $v) if $self->authInfo->{id}; - end; - end; + Tr; + td class => 'vndesc', colspan => 2; + h2 'Description'; + p; + lit bb2html $v->{desc}; + end; + end; + end; - # description - div class => 'vndescription'; - h2 'Description'; - p; - lit bb2html $v->{desc}; end; end; + clearfloat; + + # tags + my $t = $self->dbTagStats(vid => $v->{id}, order => 'avg(tv.vote) DESC', minrating => 0); + if(@$t) { + div id => 'tagops'; + a href => '#', 'hide spoilers'; + a href => '#', class => 'tsel', 'show minor spoilers'; + a href => '#', 'all tags'; + end; + div id => 'vntags'; + for (@$t) { + span class => sprintf 'tagspl%.0f %s', $_->{spoiler}, $_->{spoiler} > 1 ? 'hidden' : ''; + a href => "/g$_->{id}", style => sprintf('font-size: %dpx', $_->{rating}*3.5+6), $_->{name}; + b class => 'grayedout', sprintf ' %.1f', $_->{rating}; + end; + } + end; + } end; _releases($self, $v, $r); @@ -252,7 +272,8 @@ sub _categories { Tr ++$$i % 2 ? (class => 'odd') : (); td 'Categories'; td; - dl; + dl id => 'vncats', style => 'display: none'; + dt 'Note:'; dd "The category system is outdated, please use tags instead.\n\n"; for (@cat) { dt shift(@$_).':'; dd; @@ -260,6 +281,7 @@ sub _categories { end; } end; + a href => '#', onclick => "document.getElementById('vncats').style.display='';this.style.display='none';return false", 'Show categories'; end; end; } @@ -407,7 +429,7 @@ sub _releases { end; td class => 'tc4'; a href => "/r$rel->{id}", title => $rel->{original}||$rel->{title}, $rel->{title}; - b class => 'patch', ' (patch)' if $rel->{patch}; + b class => 'grayedout', ' (patch)' if $rel->{patch}; end; td class => 'tc5'; if($self->authInfo->{id}) { diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm index 6b6725c6..6e50632d 100644 --- a/lib/VNDB/Util/CommonHTML.pm +++ b/lib/VNDB/Util/CommonHTML.pm @@ -17,18 +17,22 @@ our @EXPORT = qw| # generates the "main tabs". These are the commonly used tabs for # 'objects', i.e. VN/producer/release entries and users -# Arguments: u/v/r/p, object, currently selected item (empty=main) +# Arguments: u/v/r/p/g, object, currently selected item (empty=main) sub htmlMainTabs { my($self, $type, $obj, $sel) = @_; $sel ||= ''; my $id = $type.$obj->{id}; + return if $type eq 'g' && !$self->authCan('tagmod'); + ul class => 'maintabs'; - li $sel eq 'hist' ? (class => 'tabselected') : (); - a href => "/$id/hist", 'history'; - end; + if($type =~ /[uvrp]/) { + li $sel eq 'hist' ? (class => 'tabselected') : (); + a href => "/$id/hist", 'history'; + end; + } - if($type ne 'r') { + if($type =~ /[uvp]/) { my $cnt = $self->dbThreadCount($type, $obj->{id}); li $sel eq 'disc' ? (class => 'tabselected') : (); a href => "/t/$id", "discussions ($cnt)"; @@ -43,22 +47,34 @@ sub htmlMainTabs { li $sel eq 'list' ? (class => 'tabselected') : (); a href => "/$id/list", 'list'; end; + + li $sel eq 'tags' ? (class => 'tabselected') : (); + a href => "/$id/tags", 'tags'; + end; + } + + if($type eq 'v' && $self->authCan('tag')) { + li $sel eq 'tagmod' ? (class => 'tabselected') : (); + a href => "/$id/tagmod", 'modify tags'; + end; } - if($type eq 'u' && ($self->authInfo->{id} && $obj->{id} == $self->authInfo->{id} || $self->authCan('usermod')) - || $type ne 'u' && $self->authCan('edit') && (!$obj->{locked} || $self->authCan('lock')) && (!$obj->{hidden} || $self->authCan('del'))) { + if( $type eq 'u' && ($self->authInfo->{id} && $obj->{id} == $self->authInfo->{id} || $self->authCan('usermod')) + || $type =~ /[vrp]/ && $self->authCan('edit') && (!$obj->{locked} || $self->authCan('lock')) && (!$obj->{hidden} || $self->authCan('del')) + || $type eq 'g' && $self->authCan('tagmod') + ) { li $sel eq 'edit' ? (class => 'tabselected') : (); a href => "/$id/edit", 'edit'; end; } - if($type ne 'u' && $self->authCan('del')) { + if($type =~ /[vrp]/ && $self->authCan('del')) { li; a href => "/$id/hide", $obj->{hidden} ? 'unhide' : 'hide'; end; } - if($type ne 'u' && $self->authCan('lock')) { + if($type =~ /[vrp]/ && $self->authCan('lock')) { li; a href => "/$id/lock", $obj->{locked} ? 'unlock' : 'lock'; end; diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index fdd325ac..17de6663 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -14,6 +14,7 @@ my %formerr_names = ( alias => 'Aliases', anime => 'Anime', desc => 'Description', + description => 'Description', editsum => 'Edit summary', gtin => 'JAN/EAN/UPC', lang => 'Language', @@ -33,7 +34,7 @@ my %formerr_names = ( platforms => 'Platforms', producers => 'Producers', released => 'Release date', - tags => 'Tags', + boards => 'Boards', title => 'Title', type => 'Type', usrname => 'Username', @@ -79,7 +80,14 @@ sub htmlFormError { li sprintf '%s should have at least %d characters', $field, $rule if $type eq 'minlength'; li sprintf '%s: only %d characters allowed', $field, $rule if $type eq 'maxlength'; li sprintf '%s must be one of the following: %s', $field, join ', ', @$rule if $type eq 'enum'; - li sprintf 'Wrong tag: %s', $rule if $type eq 'wrongtag'; + li sprintf 'Wrong board: %s', $rule if $type eq 'wrongboard'; + if($type eq 'tagexists') { + li; + lit $rule->{state} != 1 ? qq|Tag <a href="/g$rule->{id}">$rule->{name}</a> already exists!| + : qq|A tag <a href="/g$rule->{id}">with the same name</a> has been deleted in the past,| + .qq| please use <a href="/t/db">the discussion board</a> if you want it to be re-added.|; + end; + } li $rule->[1] if $type eq 'func' || $type eq 'regex'; if($type eq 'template') { li sprintf @@ -253,7 +261,9 @@ sub htmlForm { end; br; } + b "Don't forget! -> " if $options->{hitsubmit}; input type => 'submit', value => 'Submit', class => 'submit'; + b ' <-' if $options->{hitsubmit}; end; end; diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm index cef1d8af..fed09ce2 100644 --- a/lib/VNDB/Util/LayoutHTML.pm +++ b/lib/VNDB/Util/LayoutHTML.pm @@ -57,6 +57,7 @@ sub _menu { div; a href => '/', 'Home'; br; a href => '/v/all', 'Visual novels'; br; + a href => '/g', 'Tags'; br; a href => '/p/all', 'Producers'; br; a href => '/u/all', 'Users'; br; a href => '/hist', 'Recent changes'; br; @@ -87,9 +88,12 @@ sub _menu { a href => "$uid/wish", 'My Wishlist'; br; a href => "/t$uid", 'My Messages'; br; a href => "$uid/hist", 'My Recent Changes'; br; + a href => "$uid/tags", 'My Tags'; br; br; a href => '/v/new', 'Add Visual Novel'; br; a href => '/p/new', 'Add Producer'; br; + if($self->authCan('tagmod')) { + a href => '/g/new', 'Add Tag'; br; } br; a href => '/u/logout', 'Logout'; end; |