]> www.wagner.pp.ru Git - oss/stilllife.git/blobdiff - forum/forum
Bug fixes
[oss/stilllife.git] / forum / forum
index 8c966e93bec89259db459e407268233edc289762..a8fd425bdd215c564a2722bde18b66b23822154e 100755 (executable)
@@ -13,6 +13,7 @@
 # 
 use strict;
 use warnings;
+use Carp;
 use Fcntl qw(:DEFAULT :flock);
 use CGI;
 use HTML::TreeBuilder;
@@ -1027,7 +1028,7 @@ sub reply {
        # Находим в тексте URL на приаттаченные картинки и меняем на те
        # имена, под которыми мы их сохранили.
        #
-       fix_image_links($txtree,\%attached,$dir);
+       fix_image_links($cgi,$txtree,\%attached,$dir);
        #
        # Подставляем данные сообщения 
        #
@@ -1088,17 +1089,17 @@ sub reply {
        #
        $newmsg = $newmsg->clone;
        savetree($path_translated,$tree,$lockfd);
-       record_as_recent($forum,$newmsg);
+       record_as_recent($forum,$newmsg,1);
        record_statistics($forum,"message"),
        update_topic_list($forum,$path_translated,$msgcount,$posted);
        forum_redirect($cgi,$forum,$cgi->path_info."#$id");
 }      
 sub fix_image_links {
-       my ($txtree,$attached,$dir) =@_;
+       my ($cgi,$txtree,$attached,$dir) =@_;
        for my $image ($txtree->find_by_tag_name("img")) {
                my $file=lc($image->attr("src"));
                if ( exists $attached->{$file}) {
-                       $image->attr("src" => $attached->{$file});
+                       $image->attr("src" => dir2url($cgi,$dir)."/".$attached->{$file});
                        my ($width,$height) = imgsize($dir ."/".$attached->{$file});            
                        $image->attr("width" =>$width);
                        $image->attr("height" => $height);
@@ -1151,18 +1152,15 @@ sub update_topic_list {
        substinfo($block,[class=>"msgcount"],_content=>$count);
        substinfo($block,[class=>"last-updated"],_content=>$date);
        # и если мы парсили дерево, то мы его и сохраняем
-       savetree($index,$tree,$lockfd);
+       savetree($index,$tree,$lockfd) if defined $tree;
 }
 
 sub record_as_recent {
-       my ($forum,$msg) = @_;
+       my ($forum,$msg,$new) = @_;
        my ($tree,$lockfd) = gettree($forum->{forumroot}."/recent.html");
        my $msglist = $tree->look_down("class"=>"messagelist");
        if ($msglist) {
-               my $old_copy = $msglist->look_down(id=>$msg->attr("id"));
-               if ($old_copy) {
-                       $old_copy->replace_with($msg)->delete;
-               } else {
+               if ($new) {
                        my $style = $msglist->attr("style");
                        if ($style && $style =~ s/display: none;//) {
                                $msglist->attr("style",$style);
@@ -1176,6 +1174,11 @@ sub record_as_recent {
                                }       
                                $msgs[0]->preinsert($msg);      
                        }
+               } else {
+                       my $old_copy = $msglist->look_down(id=>$msg->attr("id"));
+                       if ($old_copy) {
+                               $old_copy->replace_with($msg)->delete;
+                       }       
                }
        }
        savetree($forum->{forumroot}."/recent.html",$tree,$lockfd);
@@ -1813,7 +1816,7 @@ sub messageedit {
         
        #  Преобразуем текст в html
        my $txtree = input2tree($cgi,$forum,"text");
-       fix_image_links($txtree,\%attached,$dirname);
+       fix_image_links($cgi,$txtree,\%attached,$dirname);
        my $edited = strftime("%d.%m.%Y %H:%M",localtime());
        substinfo($msg,[class=>"subject"],_content=>$cgi->param("subject"));
        substinfo($msg,[class=>"editdate"],_content=>$edited);
@@ -1826,7 +1829,7 @@ sub messageedit {
        my @msgs = $tree->look_down(class=>"message");
        my $msgcount=@msgs;
        savetree($path_translated,$tree,$lockfd);
-       record_as_recent($forum,$msg);
+       record_as_recent($forum,$msg,0);
        update_topic_list($forum,$path_translated,$msgcount,$edited);
        forum_redirect($cgi,$forum,$cgi->url(-base=>1).$cgi->path_info()."#$id");
 }
@@ -2044,6 +2047,8 @@ sub discardtree {
 #
 sub output_html {
        my $tree=shift;
+       confess "undefined tree" unless defined $tree;
+       confess "Tree is not HTML::TreeBuilder" unless ref($tree) eq "HTML::TreeBuilder";
        return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'.
        $tree->as_HTML("<>&");
 }