]> www.wagner.pp.ru Git - oss/stilllife.git/commitdiff
posting into existing topic more or less works
authorVictor Wagner <vitus@wagner.pp.ru>
Mon, 24 Mar 2008 19:44:47 +0000 (19:44 +0000)
committerVictor Wagner <vitus@wagner.pp.ru>
Mon, 24 Mar 2008 19:44:47 +0000 (19:44 +0000)
forum/forum

index 989c5bc173ed374e8d975effa24c11eb61d4d49a..6b0c9c1eee82f278ad16075697d80ee259dee3fe 100755 (executable)
@@ -19,6 +19,9 @@ use HTML::TreeBuilder;
 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;
 #
@@ -345,7 +348,7 @@ sub show_template {
                }
 
        }
-       $f->attr("type","POST");
+       $f->attr("method","POST");
        for my $required ($form,"returnto") {
                if (!$substituted{$required}) {
                        my $element = new HTML::Element('input',
@@ -490,8 +493,7 @@ sub authorize_user  {
                                                }
                                                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; 
@@ -787,24 +789,27 @@ sub reply {
        #
        # Сохраняем приаттаченные картинки, если есть.
        #
-       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 и чистим его
        #
@@ -814,8 +819,8 @@ sub reply {
        # имена, под которыми мы их сохранили.
        #
        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);
@@ -832,7 +837,7 @@ sub reply {
        # Подставляем данные сообщения 
        #
        $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"));
@@ -861,8 +866,7 @@ sub reply {
                $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});
        }
@@ -888,10 +892,10 @@ sub reply {
        $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");
@@ -908,7 +912,7 @@ sub reply {
        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;//;
        }       
        #
        # Делаем Уфф и сохраняем то, что получилось 
@@ -982,8 +986,9 @@ sub gettree {
 #
 
 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;
@@ -1001,14 +1006,15 @@ sub savetree {
 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
@@ -1104,18 +1110,14 @@ sub input2tree {
        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",
@@ -1134,10 +1136,14 @@ sub str2tree {
        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 {