X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND.pm;h=e95198a8898fbc709b1a595fe9b87f6b85834531;hb=5c44ea5af4277f139fffa052304349bc5b6d644c;hp=404c8795648e042764cc2c28443b56a476e85981;hpb=f9bfa2ffe57377a483158ac96a6f81156b5b9220;p=ndwebbie.git diff --git a/ND.pm b/ND.pm index 404c879..e95198a 100755 --- a/ND.pm +++ b/ND.pm @@ -24,7 +24,7 @@ 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'; @@ -43,11 +43,15 @@ sub handler { local $ND::BODY; local $ND::TICK; local %ND::GROUPS; + local $ND::ERROR; local $ND::PAGE = $ND::req->param('page'); if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){ $ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl'; } + if ($ENV{REQUEST_URI} =~ m{^.*/(\w+)$}){ + param($1,1); + } $ND::PAGE = '' unless defined $ND::PAGE; page(); return Apache2::Const::OK; @@ -55,7 +59,9 @@ sub handler { sub page { our $DBH = ND::DB::DB(); - my $error = ''; + $DBH->do(q{SET timezone = 'GMT'}); + + our $ERROR; chdir '/var/www/ndawn/code'; @@ -78,9 +84,6 @@ 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; @@ -96,13 +99,13 @@ 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; + $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; } unless ($XML){ @@ -110,6 +113,16 @@ sub page { $fleetupdate = 0 unless defined $fleetupdate; + my ($unread) = $DBH->selectrow_array(q{ + SELECT count(*) AS unread +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 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); $TEMPLATE->param(Tick => $TICK); $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember()); $TEMPLATE->param(isHC => isHC()); @@ -123,7 +136,7 @@ sub page { $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1'); } - $TEMPLATE->param(Error => $error); + $TEMPLATE->param(Error => $ERROR); $ND::TEMPLATE->param(BODY => $ND::BODY->output); my $output = $TEMPLATE->output; print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output);