--- db/prgsrc/db.cgi 2004/11/21 13:37:29 1.138 +++ db/prgsrc/db.cgi 2008/11/29 08:51:29 1.151 @@ -3,8 +3,11 @@ use DBI; use CGI ':all'; #use strict; +use Encode; my @softfields=("От Олега Степанова"); use Time::Local; +use Data::Dumper "Dumper"; +use URI::Escape; my $proxyredirect=1; use POSIX qw(locale_h); use locale; @@ -14,6 +17,7 @@ use Getopt::Std; eval {require "dbdefs.pl";} ; my $url=url||''; my @used_stop=(); +my $showNearQuestions=0; $dbuser||="piataev"; $dbname||="chgk"; $dbpass||=""; @@ -44,7 +48,7 @@ if ($^O =~ /win/i) { $realHTMLDIR="/html/znatoki/baza/"; } else { - $realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; + $realHTMLDIR="/home/znatoki/chgk-db/public_html/dimrub/db/files/"; } @@ -67,7 +71,7 @@ $outputkvo=100 if $outputkvo>100; if (param('debug')) {$debug=1; $printqueries=1} *STDERR=*STDOUT if $debug; -if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/) { +if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/ && $url !~ /question\.chgk\.info/ ) { my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs"; Redirect ($u); exit; @@ -130,8 +134,8 @@ my $all=param('all'); $all=0 if lc $all eq 'no'; my ($PWD) = `pwd` if $^O!~/win/i; chomp $PWD if $PWD; -my ($SRCPATH) = "/home/piataev/public_html/dimrub/src"; -my ($ZIP) = "/usr/local/bin/zip"; +my ($SRCPATH) = "/home/db-chgk/public_html/dimrub/src"; +my ($ZIP) = "/usr/bin/zip"; my $DUMPFILE = "/tmp/chgkdump"; my ($SENDMAIL) = "/usr/sbin/sendmail"; my ($TMPDIR) = "/var/tmp"; @@ -279,15 +283,17 @@ sub tourhref { my $res; if ($usehtml) { $res=$t; + $res=~s/\-q$//; + $res=~s/\-a$//; $res.=$a?"-a":"-q" unless $gr; $res.=".html"; $res=~s/(\#\d+)(.*)$/$2$1/; my $t=$res; $t=~s/\#.*$//; - $res=~s/\.1// unless -e "$realHTMLDIR$t"; +# $res=~s/\.1// unless $gr ||$res=~/\.\d+$/;#-e "$realHTMLDIR$t"; $t=$res; $t=~s/\#.*$//; - $res=~s/\.html/-q\.html/ unless -e "$realHTMLDIR$t"; +# $res=~s/\.html/-q\.html/ unless -e "$realHTMLDIR$t"; $res="$HTMLDIR$res" unless $opt_z; return $res; } else { @@ -433,9 +439,9 @@ action="/znatoki/cgi-bin/db.cgi"> -
Если при попытке поиска выдаётся сообщение об ошибке,
+
EOT
@@ -711,7 +717,10 @@ sub Search {
my (@sar, $i, $sth,$where,$query);
if ($metod eq 'rus')
{
- my @tasks=russearch($dbh,$sstr,$all,$allnf);
+ my @tasks;
+ @tasks = russearch($dbh,$sstr,$all,$allnf);
+
+
return @tasks
}
elsif ($metod eq 'proxy')
@@ -904,12 +913,14 @@ sub PrintList {
for (my $i = $first; $i <= $last; $i++) {
my $q=$q{$$Questions[$i-1]};
my $output;
- $output = &PrintQuestion($dbh, $q, 1, 0, 1,0,1 );
+ $output = &PrintQuestion($dbh, $q, 1, 0, 1,$text,1 );
# if (param('metod') && (param('metod') eq 'rus' || param('metod') eq 'proxy'))
{
$output=~s/\b($shablon)\b/\$1\<\/strong\>/gi;
$output=~s/($shablon)/\$1\<\/strong\>/gi;
+ $output=~s/(href="[^"]*?)(?:<.*?>)+([^"]*?)(?:<\/.*?>)+([^"]*?")/!1 $1$2$3 2!/g;#!!!!
}
+
$Output.= $output;
}
$sth->finish;
@@ -951,7 +962,7 @@ sub PrintSearch {
}
while (--$ss && (!$dbh->do ("insert into lastqueries (id,sstr,questions,allnf)
values ($was, $qsstr,$tmp,$nf)")));
- $Output.= "Something is wrong...".br unless $ss;
+ $Output.= "Something is wrong...".br."\n" unless $ss;
}
}
@@ -1191,7 +1202,6 @@ sub PrintTournament {
p("Дополнительная информация об этом турнире - по адресу " .
a({-'href'=>$URL}, $URL));
}
-
if ($Copyright) {
$output .= p("Копирайт: " . $Copyright);
}
@@ -1201,6 +1211,10 @@ sub PrintTournament {
if ($Info) {
$output .= p($Info);
}
+
+ $output.=p("XML");
+
+
return $output;
}
@@ -1270,7 +1284,7 @@ sub PrintTour {
$output .= h2({align=>"center"}, $Tournament{"Title"},
$Tournament{'PlayedAt'}||'',
- " /g unless $text;
+ $output=~s/⌡/\ï/g;
+ $output=~s/⌠/\Ï/g;
+
$paramtour||=param("tour");
$fname=$fname.".$Question{'TourNumber'}" if $fname && $Question{'TourNumber'};
$fname||=param('tour');
my $qid=$fname ? ($fname.".$Question{'Number'}" ): '';
- $output.=br.a({href=> $url."?metod=proxy&
+ $output.=br."\n".a({href=> "/search/"."?metod=proxy&
qid=$qid"}, 'Близкие вопросы').p
- if $answer>0 && !$text && $qid;
+ if $answer>0 && !$text && $qid && $showNearQuestions;
return $output;
}
@@ -1979,7 +2019,7 @@ MAIN:
my $texttour=$tour;
my ($sth,$dbh);
my($dsn) = "DBI:mysql:database=$dbname;host=$dbhost";
- $dbh = DBI->connect($dsn, $dbuser, $dbpass)
+ $dbh = DBI->connect($dsn, $dbuser, $dbpass)
# $dbh = DBI->connect("DBI:mysql:$dbname", $username, $dbpass)
or do {
print header.h1("Временные проблемы") . "База вопросов временно не
@@ -1988,17 +2028,17 @@ MAIN:
print end_html;
die "Can't connect to DB chgk\n";
};
-
+ $dbh->do("set names koi8r");
if (param('qid') && (param('qid')=~/^\d+$/) || $tour && $tour=~/^\d+$/) {
- my $destination='http://chgk.zaba.ru/search.html';
+# my $destination='http://chgk.zaba.ru/search.html';
# print header (-'Content-Type' => 'text/html',
# -'Location:'=> 'http:\\db.chgk.info');
Redirect($destination);
exit
}
- if ($tour && !param('qnumber') && (!param('answers')||(param('answers')<=1)))
+ if (0 && $tour && !param('qnumber') && (!param('answers')||(param('answers')<=1)))
{
my $n=param('tour');
$n=~s/.txt$//;
@@ -2229,7 +2269,7 @@ EOT
$QuestionNumber=($sth->fetchrow)[0]||0;
}
if ($QuestionNumber) {
- $globaloutput.= &PrintQuestion($dbh, $QuestionNumber, $withanswers||0, $qnum, 1,0,0);
+ $globaloutput.= &PrintQuestion($dbh, $QuestionNumber, $withanswers||0, $qnum, 1,$text,0);
# $dbh, $Id, $answer, $qnum, $title, $text
} else {
$globaloutput.=&PrintTournament($dbh, $tour, $withanswers);
", $Tour{"Title"} .
+ "
\n", $Tour{"Title"} .
" ($qnum вопрос$suffix)\n") . p;
$output .=&PrintEditor(\%Tour);
@@ -1278,25 +1292,35 @@ sub PrintTour {
my $sth=SelectQuestions($dbh,\@Questions,0);
for ($q = 0; $q <= $#Questions; $q++) {
fetchquestion($sth,\%q,0);
- $output .= &PrintQuestion($dbh, \%q, $answer, 0,0,0,1);
+ $output .= &PrintQuestion($dbh, \%q, $answer, 0,0,$text,1);
}
$sth->finish;
$output .= hr({-'align'=>'center', -'width'=>'80%'});
if ($Tournament{'URL'}) {
- $output .=
- p("Дополнительная информация об этом турнире - по адресу " .
- a({-'href'=>$Tournament{'URL'}}, $Tournament{'URL'}));
+ $URL = $Tournament{'URL'};
+ $URL=~s/http:\/znatoki\/boris\/reports\//$newsurl/ if $url=~/kulichki/ || $url=~/db.chgk.info/;
+ $URL=~s/\/znatoki\/boris\/reports\//$newsurl/ if url=~/kulichki/ || $url=~/db.chgk.info/;
+
+ $output .=
+ p("Дополнительная информация об этом турнире - по адресу " .
+ a({-'href'=>$URL}, $URL));
}
if ($Tournament{'Copyright'}) {
$output .= p("Копирайт: " . $Tournament{'Copyright'});
}
- if ($Tournament{'Info'}) {
+ if ($Tournament{'Info'} ) {
$output .= p($Tournament{'Info'});
}
+ if ($Tour{'Info'} && ($Tournament{'Info'} ne $Tour{'Info'})) {
+ $output .= "!!".p($Tour{'Info'});
+ }
+
+ $output.=p("XML");
+
my $n=$Tour{'Number'};
if ($answer == 0) {
my $nn=".$n";
@@ -1304,7 +1328,7 @@ sub PrintTour {
$bottom .=
"[" . a({href=>tourhref("$fname$nn",1)},
- "ответы") . "] " . br;
+ "ответы") . "] " . br."\n";
}
if ($n>1) {
$bottom .=
@@ -1312,7 +1336,7 @@ sub PrintTour {
"предыдущий тур") . "] ";
$bottom .=
"[" . a({href=>tourhref("$fname.".($n-1),1)},
- "предыдущий тур с ответами") . "] " . br;
+ "предыдущий тур с ответами") . "] " . br."\n";
}
if (&IsTour($dbh, $Tour{'ParentId'}, $n + 1)) {
$bottom .=
@@ -1329,6 +1353,14 @@ sub PrintTour {
return $output;
}
+
+sub escapeUrl {
+ my $uri = shift;
+ $uri=~s/<.*?>//g;
+ $uri =~ s/([Ю-Ъю-ъ]+)/URI::Escape::uri_escape_utf8(decode("koi8-r",$1))/eg;
+ return $uri;
+}
+
sub PrintField {
my ($header, $value, $text) = @_;
if ($text) {
@@ -1336,15 +1368,20 @@ sub PrintField {
} else {
if ($header=~/Комментар/)
{
- $value=~s/^\s*$_[\.:]/p."\n".strong("$_").":"/me foreach @softfields;
+ $value=~s/^\s*$_[\.:]/p."\n".strong("$_").":\n"/me foreach @softfields;
}
- $value =~ s/^\s+/
/mg;
+ $value =~ s/^\s+/
\n /mg;
$value =~ s/(\s+)-+(\s+)/$1$2/mg;
$value =~ s/\s+\/ \/mg
if $value !~ /^\|/;
$value =~ s/^\|([^\n]*)/$1<\/pre>/mg;
- $value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/$1<\/a>/g if $header !~ /^Авто/;
+
+ $value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/a({href=>escapeUrl($1)},$1)/egm if $header !~ /^Авто/;#!!!
+
+
+# $value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/make/eg if $header !~ /^Авто/;#!!!
+# $value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/$1<\/a>/g if $header !~ /^Авто/;
# $value =~ s/(http:\/\/(?:\w+.)+[\w\\\~]+(\?[^\s.]+)?)/$1<\/a>/g if $header !~ /^Авто/;
# $value =~ s/(\s)"/$1/mg;
# $value =~ s/^"//mg;
@@ -1356,7 +1393,7 @@ sub PrintField {
$value . p . "\n";
}
return $text ? "$header:\n$value\n\n" :
- strong("$header: ") . $value . p . "\n";
+ strong("$header: ") . "\n".$value . p . "\n";
}
# Gets a DB handler (ofcourse) and a question Id. Prints
@@ -1499,14 +1536,17 @@ $output.=""
}
$output=~s/\(pic: ([^\)]*)\)/