use Storable qw(freeze thaw);
use Date::Parse;
use Email::Valid;
+use Image::Size;
+use HTML::BBReverse;
+use POSIX;
use LWP::UserAgent;
use Net::OpenID::Consumer;
#
}
}
- $f->attr("type","POST");
+ $f->attr("method","POST");
for my $required ($form,"returnto") {
if (!$substituted{$required}) {
my $element = new HTML::Element('input',
}
print STDERR "user $user restored session $session\n";
$forum->{"authenticated"}=$userinfo;
- print STDERR "authorize_user:
- ",$forum->{authenticated}{user},
+ print STDERR "authorize_user: ",$forum->{authenticated}{user},
$forum->{authenticated},"\n";
}
dbmclose %userbase;
#
# Сохраняем приаттаченные картинки, если есть.
#
- my $dir = $ENV{PATH_TRANSLATED};
+ my $dir = $1 if $ENV{PATH_TRANSLATED}=~/^(.*)$/;
$dir=~ s/[^\/]+$// if (-f $dir);
my %attached;
- for (my $i=1;defined $cgi->param("image$i"); $i++) {
+ for (my $i=1;$cgi->param("image$i"); $i++) {
my $userpath=$cgi->param("image$i");
my $filename=lc($1) if $userpath =~ /([^\/\\]+)$/;
- attached{$filename} = $id."_".$filename;
+ $attached{$filename} = $id."_".$filename;
my $in = $cgi->upload("image$i");
+ if (!$in) {
+ show_error($forum,"Ошибка при загрузке картинки $filename");
+ exit;
+ }
my $out;
open $out,">$dir/$attached{$filename}";
binmode $out,":bytes";
- local $_=undef;
+ local $/=undef;
my $data = <$in>;
print $out $data;
close $in;
close $out;
}
-
#
# Преобразуем текст записи в html и чистим его
#
# имена, под которыми мы их сохранили.
#
for my $image ($txtree->find_by_tag_name("img")) {
- my $file;
- if ( exists $attached{$file=lc($image->attr("src"))}) {
+ my $file=lc($image->attr("src"));
+ if ( exists $attached{$file}) {
$image->attr("src" => $attached{$file});
my ($width,$height) = imgsize($dir ."/".$attached{$file});
$image->attr("width" =>$width);
# Подставляем данные сообщения
#
$newmsg->attr("id"=>$id);
- if (my $subj=$newmsg->look_down("class"=>"subject") &&
+ if ((my $subj=$newmsg->look_down("class"=>"subject")) &&
$cgi->param("subject")) {
$subj->delete_content;
$subj->push_content($cgi->param("subject"));
$idfield->attr("value" => $id);
my $authorfield = $editform->look_down(_tag=>"input","name"=>"author");
if (!$authorfield) {
- show_error($forum,"В форме управления сообщением нет поля
- id");
+ show_error($forum,"В форме управления сообщением нет поля author");
}
$authorfield->attr("value"=>$forum->{authenticated}{user});
}
$anchor->attr(name=>"#$id");
# подставляем mlink
my $link = $newmsg->look_down(_tag=>"a","class"=>"mlink");
- $link->attr(href=>$cgi->path_info."#id");
+ $link->attr(href=>$cgi->path_info."#id") if $link;
# подставляем mparent
my $parent_id=$cgi->param("id");
- my $parent_link=$newmsg->lookdown(_tag => "a",class=>"mparent");
+ my $parent_link=$newmsg->look_down(_tag => "a",class=>"mparent");
if ($parent_link) {
if ($parent_id) {
$parent_link->attr("href"=>$cgi->path_info."#$parent_id");
my $msglist = $tree->look_down("class"=>"messagelist");
if ($msglist) {
my $style = $msglist->attr("style");
- $msglist->attr("style",$style) if $style =~ s/display: none;//;
+ $msglist->attr("style",$style) if $style && $style =~ s/display: none;//;
}
#
# Делаем Уфф и сохраняем то, что получилось
#
sub savetree {
- my ($filename,$tree,$lockfd) = shift;
+ my ($filename,$tree,$lockfd) = @_;
my $f;
+ $filename = $1 if $filename =~ /^(.*)$/;
open $f,">",$filename . ".new" or return undef;
print $f $tree->as_HTML("<>&");
close $f;
sub get_uid {
my $forum = shift;
my $f;
- open $f,"<+",datafile($forum,"sequence");
+ open $f,"+<",datafile($forum,"sequence") or
flock $f,LOCK_EX;
my $id=<$f> || "0";
$id++;
seek $f,0,0;
printf $f "%8s\n",$id;
close $f;
- return sprintf ("%08s",$id);
+ $id=~/(\d+)/;
+ return sprintf ("%08s",$1);
}
# --------------------------------------------------------------------
# OpenID registration
my ($cgi,$forum,$field_name) = @_;
my $format = $cgi->param($field_name."_format");
my $text = $cgi->param($field_name);
-
if ($format eq "bbcode") {
my $parser = HTML::BBReverse->new();
$text="<div class=\"bbcode\">".$parser->parse($text)."</div>";
-
} elsif ($format eq "text") {
$text=~s/\r?\n\r?\n/<\/p><p class=\"text\">/;
$text=~s/\r?\n/<br>/;
- $text = "<p class=\"text\">".$text."</p>";
- } else {
- $text="<div>".$text."</div>";
- }
+ $text = "<div><p class=\"text\">".$text."</p></div>";
+ }
my $txtree = str2tree($text);
for my $badtag
("script","style","head","html","object","embed","iframe","frameset","frame",
my ($data)=@_;
my $tree = HTML::TreeBuilder->new();
# Set parser options here
- $tree->parse($data);
+ $tree->parse("<html><body><div>$data</div></body></html>");
$tree->eof;
- return $tree;
-
+ my $element=$tree->find("body");
+ while (($element =($element->content_list)[0])->tag ne "div") {
+ }
+ $element->detach;
+ $tree->destroy;
+ return $element;
}
sub tree2str {