summaryrefslogtreecommitdiff
path: root/util/vndb.pl
diff options
context:
space:
mode:
Diffstat (limited to 'util/vndb.pl')
-rwxr-xr-xutil/vndb.pl99
1 files changed, 22 insertions, 77 deletions
diff --git a/util/vndb.pl b/util/vndb.pl
index c0af72e1..efdc5e25 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -1,97 +1,42 @@
#!/usr/bin/perl
-
-package VNDB;
-
use strict;
use warnings;
-
+use TUWF;
use Cwd 'abs_path';
-our $ROOT;
+my $ROOT;
BEGIN { ($ROOT = abs_path $0) =~ s{/util/vndb\.pl$}{}; }
-
-$|=1; # Disable buffering on STDOUT, otherwise vndb-dev-server.pl won't pick up our readyness notification.
-
use lib $ROOT.'/lib';
+$|=1; # Disable buffering on STDOUT, otherwise vndb-dev-server.pl won't pick up our readyness notification.
-use TUWF ':html';
-use SkinFile;
-
-
-our(%O, %S);
-
-
-# load the skins
-# NOTE: $S{skins} can be modified in data/config.pl, allowing deletion of skins or forcing only one skin
-my $skin = SkinFile->new("$ROOT/static/s");
-$S{skins} = { map +($_ => [ $skin->get($_, 'name'), $skin->get($_, 'userid') ]), $skin->list };
-
-
-# load settings from global.pl
-require $ROOT.'/data/global.pl';
-
-
-# automatically regenerate the skins and script.js and whatever else should be done
-system "make -sC $ROOT" if $S{regen_static};
-
-
-$TUWF::OBJ->{$_} = $S{$_} for (keys %S);
-TUWF::set(
- %O,
- pre_request_handler => \&reqinit,
- error_404_handler => \&handle404,
- log_format => \&logformat,
-);
-TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler');
-TUWF::run();
+my $conf = require $ROOT.'/data/config3.pl';
-sub reqinit {
- my $self = shift;
+# Make the configuration available as tuwf->conf
+sub TUWF::Object::conf { $conf }
- # If we're running standalone, serve www/ and static/ too.
- if($TUWF::OBJ->{_TUWF}{http}) {
- if($self->resFile("$ROOT/www", $self->reqPath) || $self->resFile("$ROOT/static", $self->reqPath)) {
- $self->resHeader('Cache-Control' => 'max-age=31536000');
- return 0;
- }
- }
- # check authentication cookies
- $self->authInit;
+# Make our root path available as tuwf->root
+# Optionally accepts other path components to assemble a file path:
+# tuwf->root('static/sf/01/1.jpg')
+sub TUWF::Object::root { shift; join '/', $ROOT, @_ }
- # load some stats (used for about all pageviews, anyway)
- $self->{stats} = $self->dbStats;
- return 1;
-}
+TUWF::set %{ $conf->{tuwf} || {} };
-sub handle404 {
- my $self = shift;
- $self->resStatus(404);
- $self->htmlHeader(title => 'Page Not Found');
- div class => 'mainbox';
- h1 'Page not found';
- div class => 'warning';
- h2 'Oops!';
- p;
- txt 'It seems the page you were looking for does not exist,';
- br;
- txt 'you may want to try using the menu on your left to find what you are looking for.';
- end;
- end;
- end;
- $self->htmlFooter;
-}
+# If we're running standalone, serve www/ and static/ too.
+TUWF::hook before => sub {
+ my $static = tuwf->{_TUWF}{http} &&
+ ( tuwf->resFile(tuwf->root('www'), tuwf->reqPath)
+ || tuwf->resFile(tuwf->root('static'), tuwf->reqPath)
+ );
+ tuwf->resHeader('Cache-Control' => 'max-age=31536000') if $static;
+ !$static;
+};
-# log user IDs (necessary for determining performance issues, user preferences
-# have a lot of influence in this)
-sub logformat {
- my($self, $uri, $msg) = @_;
- sprintf "[%s] %s %s: %s\n", scalar localtime(), $uri,
- $self->authInfo->{id} ? 'u'.$self->authInfo->{id} : '-', $msg;
-}
+TUWF::load_recursive 'VNDB';
+TUWF::run;