summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-30 13:43:31 +0100
committerYorhel <git@yorhel.nl>2008-11-30 13:43:31 +0100
commit85a55d309c201906669595e1ec0f60bcb2016072 (patch)
tree9a521728832898b0170e1d04afe3408e32f28b87
parent165a55d275b816b36217daf2cc899848d0cde64e (diff)
Added small VN browser + search
-rw-r--r--lib/ChangeLog3
-rw-r--r--lib/VNDB/DB/VN.pm6
-rw-r--r--lib/VNDB/Func.pm13
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm89
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm2
-rw-r--r--static/f/style.css5
6 files changed, 114 insertions, 4 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 0816732d..5b4a017a 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -17,8 +17,9 @@ TODO:
- Database changes:
- Added caching of edit and vote counts in users.c_votes and .c_changes
- Split users.flags into users.show_nsfw and .show_list (boolean type)
+ - Global statistics are cached in stats_cache
- URL changes:
- - /p doesn't work anymore, use /p/all
+ - /p and /v don't work anymore, use /[pv]/all
- /u/list/* -> /u/* and /u/list -> /u/list/all
- Revert URL changed from /x99/edit?rev=1 to /x99.1/edit
- /v+/stats and /v+/scr moved into /v+
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 73abee82..358a470c 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -8,7 +8,7 @@ use Exporter 'import';
our @EXPORT = qw|dbVNGet dbVNAdd dbVNEdit dbVNImageId dbScreenshotAdd dbScreenshotGet|;
-# Options: id, rev, search, results, page, order, what
+# Options: id, rev, char, search, results, page, order, what
# What: extended categories anime relations screenshots relgraph changes
sub dbVNGet {
my($self, %o) = @_;
@@ -22,6 +22,10 @@ sub dbVNGet {
'v.id = ?' => $o{id} ) : (),
$o{rev} ? (
'c.rev = ?' => $o{rev} ) : (),
+ $o{char} ? (
+ '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 ) : (),
# don't fetch hidden items unless we ask for an ID
!$o{id} && !$o{rev} ? (
'v.hidden = FALSE' => 0 ) : (),
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index d2f86cf1..ac555d1d 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
use POSIX 'strftime';
-our @EXPORT = qw| shorten date datestr userstr bb2html |;
+our @EXPORT = qw| shorten date datestr monthstr userstr bb2html |;
# I would've done this as a #define if this was C...
@@ -46,6 +46,17 @@ sub datestr {
return qq|<b class="future">$str</b>|;
}
+# same as datestr(), but different output format:
+# e.g.: 'Jan 2009', '2009', 'unknown', 'TBA'
+sub monthstr {
+ my $date = sprintf '%08d', shift||0;
+ my($y, $m) = ($1, $2) if $date =~ /^([0-9]{4})([0-9]{2})/;
+ return 'TBA' if $y == 9999;
+ return 'unknown' if $y == 0;
+ return $y if $m == 99;
+ return strftime '%b %Y', 0, 0, 0, 0, $m-1, $y-1900, 0, 0, 0;
+}
+
# Arguments: (uid, username), or a hashref containing that info
sub userstr {
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
new file mode 100644
index 00000000..20471c6e
--- /dev/null
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -0,0 +1,89 @@
+
+package VNDB::Handler::VNBrowse;
+
+use strict;
+use warnings;
+use YAWF ':html';
+use VNDB::Func;
+
+
+YAWF::register(
+ qr{v/([a-z0]|all)} => \&list,
+);
+
+
+sub list {
+ my($self, $char) = @_;
+
+ my $f = $self->formValidate(
+ { name => 's', required => 0, default => 'title', enum => [ qw|title rel| ] },
+ { name => 'o', required => 0, default => 'a', enum => [ 'a','d' ] },
+ { name => 'p', required => 0, default => 1, template => 'int' },
+ { name => 'q', required => 0, default => '' },
+ );
+ return 404 if $f->{_err};
+
+ my($list, $np) = $self->dbVNGet(
+ $char ne 'all' ? ( char => $char ) : (),
+ $f->{q} ? ( search => $f->{q} ) : (),
+ results => 50,
+ page => $f->{p},
+ order => ($f->{s} eq 'rel' ? 'c_released' : 'title').($f->{o} eq 'a' ? ' ASC' : ' DESC'),
+ );
+
+ $self->htmlHeader(title => 'Browse visual novels');
+
+ div class => 'mainbox';
+ h1 'Browse visual novels';
+ form class => 'search', action => '/v/all', 'accept-charset' => 'UTF-8', method => 'get';
+ fieldset;
+ input type => 'text', name => 'q', id => 'q', class => 'text', value => $f->{q};
+ input type => 'submit', class => 'submit', value => 'Search!';
+ end;
+ end;
+ p class => 'browseopts';
+ for ('all', 'a'..'z', 0) {
+ a href => "/v/$_", $_ eq $char ? (class => 'optselected') : (), $_ ? uc $_ : '#';
+ }
+ end;
+ end;
+
+ $self->htmlBrowse(
+ class => 'vnbrowse',
+ items => $list,
+ options => $f,
+ nextpage => $np,
+ pageurl => "/v/$char?o=$f->{o};s=$f->{s};q=$f->{q}",
+ sorturl => "/v/$char?q=$f->{q}",
+ header => [
+ [ 'Title', 'title' ],
+ [ '', 0 ],
+ [ '', 0 ],
+ [ 'Released', 'rel' ],
+ ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ Tr $n % 2 ? (class => 'odd') : ();
+ td class => 'tc1';
+ a href => '/v'.$l->{id}, title => $l->{original}||$l->{title}, shorten $l->{title}, 100;
+ end;
+ td class => 'tc2';
+ $_ ne 'oth' && acronym class => "icons $_", title => $self->{platforms}{$_}, ' '
+ for (sort split /\//, $l->{c_platforms});
+ end;
+ td class => 'tc3';
+ acronym class => "icons lang $_", title => $self->{languages}{$_}, ' '
+ for (reverse sort split /\//, $l->{c_languages});
+ end;
+ td class => 'tc4';
+ lit monthstr $l->{c_released};
+ end;
+ end;
+ },
+ );
+ $self->htmlFooter;
+}
+
+
+1;
+
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 4307731d..758ce444 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -48,7 +48,7 @@ sub _menu {
h2 'Menu';
div;
a href => '/', 'Home'; br;
- a href => '#', 'Visual novels'; br;
+ a href => '/v/all', 'Visual novels'; br;
a href => '/p/all', 'Producers'; br;
a href => '/u/all', 'Users'; br;
a href => '/hist', 'Recent changes'; br;
diff --git a/static/f/style.css b/static/f/style.css
index e04dee4a..93232f7d 100644
--- a/static/f/style.css
+++ b/static/f/style.css
@@ -621,6 +621,11 @@ form #jt_box_categories li li b { width: 13px; font-weight: bold; }
#scr_table select { width: 400px; }
+/* VN browse */
+
+.vnbrowse .tc2 { text-align: right }
+
+
/***** Producer page/list *******/