X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND.pm;h=8b2fdb3d9b2e872213e899edf86c686a1fa490c2;hb=8551be2ae42a4a4e7a425e2a71ead79c10bf9df4;hp=c54bb77a085b828793d0d6391594d932e10ba951;hpb=6d6177b5221cc6d74b58c73c91f33bc8132649db;p=ndwebbie.git diff --git a/ND.pm b/ND.pm index c54bb77..8b2fdb3 100755 --- a/ND.pm +++ b/ND.pm @@ -24,13 +24,17 @@ 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 ND::Include; 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 +53,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 (defined $ND::PAGE and 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 +89,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,20 +101,19 @@ 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); $fleetupdate = 0 unless defined $fleetupdate; + my ($unread,$lastv) = $DBH->selectrow_array(unread_query,undef,$UID) or $ERROR .= p($DBH->errstr); + + $TEMPLATE->param(UnreadPosts => $unread); $TEMPLATE->param(Tick => $TICK); $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember()); $TEMPLATE->param(isHC => isHC()); @@ -124,6 +125,8 @@ sub page { $ND::TEMPLATE->param(Targets => listTargets()); } $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1'); + my ($css) = $DBH->selectrow_array(q{SELECT css FROM users WHERE uid = $1},undef,$ND::UID); + $TEMPLATE->param(CSS => $css); } $TEMPLATE->param(Error => $ERROR);