#
use strict;
use warnings;
+use Carp;
use Fcntl qw(:DEFAULT :flock);
use CGI;
use HTML::TreeBuilder;
# Находим в тексте URL на приаттаченные картинки и меняем на те
# имена, под которыми мы их сохранили.
#
- fix_image_links($txtree,\%attached,$dir);
+ fix_image_links($cgi,$txtree,\%attached,$dir);
#
# Подставляем данные сообщения
#
#
$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);
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);
}
$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);
# Преобразуем текст в 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);
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");
}
#
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("<>&");
}