X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND.pm;h=dd017f3a4201c73c8a579373ace4d9446e0d1eb1;hb=9ce5a8529e75cb109ed9ba3fc788c94ef47b1080;hp=46a9de3877b166927b4ae30c657d088ce6462012;hpb=30ff54d1d68e41a17bd8a7ff57e4104021e52ff5;p=ndwebbie.git diff --git a/ND.pm b/ND.pm index 46a9de3..dd017f3 100755 --- a/ND.pm +++ b/ND.pm @@ -24,13 +24,16 @@ use HTML::Template; use DBI; use DBD::Pg qw(:pg_types); use Apache2::Request; -use ND::Include; +use ND::Web::Include; use ND::DB; use Tie::File; use Fcntl 'O_RDONLY'; use strict; use warnings FATAL => 'all'; +chdir '/var/www/ndawn/code'; +our %PAGES; +our $NOACCESS = HTML::Template->new(filename => 'templates/NoAccess.tmpl', global_vars => 1, cache => 1); sub handler { local $ND::r = shift; @@ -49,16 +52,20 @@ sub handler { if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){ $ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl'; } - $ND::PAGE = '' unless defined $ND::PAGE; - page(); + $ND::PAGE = 'main' unless exists $PAGES{$ND::PAGE}; + + $PAGES{$ND::PAGE}->{parse}->($ENV{REQUEST_URI}); + + page($ND::PAGE); return Apache2::Const::OK; } sub page { + my ($PAGE) = @_; our $DBH = ND::DB::DB(); $DBH->do(q{SET timezone = 'GMT'}); - our $ERROR = ''; + our $ERROR; chdir '/var/www/ndawn/code'; @@ -81,17 +88,11 @@ sub page { $ATTACKER = 1 if $attack; } - - our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)'); - - tie my @pages, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY, memory => 0 or die $!; - $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @pages; - our $XML = 0; - $XML = 1 if param('xml') and $ND::PAGE =~ /^(raids)$/; - our $AJAX = 1; + $PAGES{$PAGE}->{process}->(); + my $type = 'text/html'; if ($XML){ $type = 'text/xml'; @@ -99,14 +100,10 @@ sub page { $ND::BODY = HTML::Template->new(filename => "templates/$ND::PAGE.xml.tmpl", cache => 1); }else{ $ND::BODY = HTML::Template->new(filename => "templates/$ND::PAGE.tmpl", global_vars => 1, cache => 1); - $ND::BODY->param(PAGE => $ND::PAGE); + $ND::BODY->param(PAGE => '/'.$ND::PAGE); } - unless (my $return = do "$ND::PAGE.pl"){ - $ERROR .= "
couldn't parse $ND::PAGE: $@
" if $@; - $ERROR .= "couldn't do $ND::PAGE: $!
" unless defined $return && defined $!; - $ERROR .= "couldn't run $ND::PAGE
" unless $return; - } + $ND::BODY = $PAGES{$PAGE}->{render}->($DBH,$ND::BODY); unless ($XML){ my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID); @@ -115,11 +112,11 @@ sub page { my ($unread) = $DBH->selectrow_array(q{ SELECT count(*) AS unread -FROM forum_boards fb NATURAL JOIN forum_access fa NATURAL JOIN forum_threads ft +FROM forum_boards fb NATURAL JOIN forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid -WHERE ftv.time IS NULL OR fp.time > ftv.time AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers - WHERE uid = $1)) +WHERE (ftv.time IS NULL OR fp.time > ftv.time) AND fbid > 0 AND + fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1))) },undef,$UID) or $ERROR .= p($DBH->errstr); $TEMPLATE->param(UnreadPosts => $unread);