From 60eca0837da884487ccb28e0f88ee5159b1ce693 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Tue, 6 May 2008 14:59:40 +0000 Subject: [PATCH] Bug fixes --- forum/forum | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/forum/forum b/forum/forum index 8c966e9..a8fd425 100755 --- a/forum/forum +++ b/forum/forum @@ -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 ''. $tree->as_HTML("<>&"); } -- 2.39.5