#!/usr/bin/perl -w use strict; $ENV{PATH} = ''; my $Home = "/usr/local/etc/httpd/pereplet/htdocs/lenta"; my $DataFile = "$Home/news.dat"; my $HeaderFile = "$Home/_head.html"; my $FooterFile = "$Home/_foot.html"; my $Brief = "$Home/_brief.news"; my $Full = "$Home/_full.news"; my $Count = 20; use CGI qw(:all :utf8); my $q = new CGI; my @brief; open(FB, "< $Brief") || NoBriefFileExcpt();; while(){ push(@brief, $_) unless $_=~/^#/; } close(FB); my @full; open(FF, "< $Full") || NoFullFileExcpt(); while(){ push(@full, $_) unless $_=~/^#/; } close(FF); #print $q->header("text/html;charset=UTF-8"); print "Content-Type: text/html; charset=utf-8\n\n"; open(FH, "< $HeaderFile") || NoHeaderFileExcpt(); print ; close(FH); my $id = $q->param('id'); $id||=-1; my $page = $q->param('page'); $page||=1; my $count=$q->param('count'); $count||=$Count; my @n2show=(); $#n2show=$count; my ($index, $state, $maxdecpage, $decpage, $found, $i, $novelty, $maxpagenum, $pagenum, $numb); $found=$i=$decpage=$maxdecpage=0; $pagenum=$maxpagenum=$state=1; $index=0; $/="\x00"; open(FL, "< $DataFile") || die NoDataFileExcpt(); my($max, $min); while($novelty=){ if($state){ ($numb)=$novelty=~/(\d+)/; $max=$numb if $i==0; $found=1 if $numb == $id; $n2show[$i]=$novelty; $index=$i++; if($i>=$count){ $min=$numb; if(($id<1 && $pagenum == $page)||($id>$max)||($id<=$max && $id>=$min)){ $state=0; }else{ $i=0; $pagenum++; $decpage++ unless $pagenum % 10; $maxpagenum = $pagenum; $maxdecpage = $decpage; } } }else{ $i++; if($i>=$count){ $i=0; $maxpagenum++; $maxdecpage++ unless $maxpagenum % 10 ; } } } close(FL); $/="\n"; $#n2show=$index; my ($date, $time, $title, $text, $src, $auth); if(!$found && $id>0) { ($numb, $date, $time, $title, $text)=($id, "", "", "Произошла ошибка!", "Извините, новость с данным номером отсутствует в базе данных!!!"); for my $str (@full){ print Subst($str); } }else{ for $i (0..$#n2show){ ($numb, $date, $time, $title, $text, $src, $auth) = split(/\x01/, $n2show[$i]); $src||=''; $auth||=''; my ($day, $month, $year)=split('\.', $date); $year+=1900; $date="$day.$month.$year"; if($numb != $id){ for my $str (@brief){ print Subst($str); } }else{ $found=1; for my $str (@full){ print Subst($str); } } } } my $pageline = $decpage?qq[<< ]:''; for $i ($decpage*10+1..($decpage==$maxdecpage?$maxpagenum:($decpage+1)*10)){ $pageline.=$i==$pagenum?$i:qq[$i]; $pageline.='|' if $i%10 && $i!=$maxpagenum; } $pageline.=$decpage<$maxdecpage?qq[ >>]:''; open(FT, "< $FooterFile") || NoFooterFileExcpt(); while(){ s//$pageline/o; print; } close(FT); ################################################################################ sub Subst { my($st)=$_[0]; my $tl=$title; $st=~s/\%NUMB\%/$numb/go; $st=~s/\%DATE\%/$date/go; $st=~s/\%TIME\%/$time/go; $st=~s/\%TITLE\%/$title/go; $st=~s/\%TEXT\%/$text/go; $st=~s/\%SRC\%/$src/go; $st=~s/\%AUTH\%/$auth/go; $tl=~s/[\000-\032]/ /go; $tl=~s/\&/\&/go; $tl=~s/>/\>/go; $tl=~s/header("text/html;charset=UTF-8"); print "Error: No data file!"; print "

ERROR: Data File is not available!

"; print "If you see this message, please inform us on "; print 'this e-mail address.'; } sub NoBriefFileExcpt { @brief=("\n\n

", "\%DATE\%
\%TIME\%

\n", "

\%TITLE\%

\n"); } sub NoFullFileExcpt { @full=("\n\n

", "\%DATE\%
\%TIME\%

", "\n

\%TITLE\%

    \%TEXT\%
    \%SRC\%
    \%AUTH\%

\n"); } sub NoHeaderFileExcpt { print "\n". "\n\nРусский переплет - литературный интернет-журнал\n\n". "\n". "

\n

\n
\n
\n

\n\"Русский

\n". "
\n
\n\n
\n\n". ""; } sub NoFooterFileExcpt { print "
\n\nЛента новостей\n". "
\n\n

 

\n\n\n\n\n
Архив новостейДобавить новость
\n". "
\n
\n"; }