#
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);
last if $d eq $forum->{forumroot};
}
- print STDERR "Found permission files in @dirs\n";
# Подставляем их куда надо
for $d (@dirs) {
- print STDERR "substituting dir $d\n";
my %users = getperms($d);
my $title=gettitle($d."/".$forum->{indexfile});
my $item = newlistelement($tree,"dir","dirlist");
form_error($form,$cgi,$forum,"Некорректные символы в urlname.
Допустимы только латинские буквы, цифры и минус") unless $urlname;
}
- if (!-d $path_translated) {
+ if (!-d $path_translated &&
+ $path_translated=~s/^(.+)\/+[^\/]+$/$1/ &&
+ !-d $path_translated) {
show_error($forum,"Операция $form может быть вызвана только со
страницы форума");
}
my $tree = gettemplate($forum,"topic",$url);
# Заполнить название и аннотацию
my $abstract = input2tree($cgi,$forum,"abstract");
- substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text);
+ substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text) if $abstract;
substinfo($tree,[_tag=>"title"],_content=>$cgi->param("title"));
my $subtree = $tree->look_down("class"=>"topic");
my $creation_time=strftime("%d.%m.%Y %H:%M",localtime());
_content=>$creation_time);
# Вставляем в страницу КОПИЮ аннотации, поскольку аннотация
# нам еще понадобится в списке тем.
- substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone);
+ substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone) if $abstract;
substitute_user_info($subtree,$forum);
} else {
substinfo($tree,["class"=>"title"],
form_error($form,$cgi,$forum,"Некорректные символы в urlname.
Допустимы только латинские буквы, цифры и минус") unless $urlname;
}
- if (!-d $path_translated) {
+ if (!-d $path_translated &&
+ $path_translated=~s/^(.+)\/+[^\/]+$/$1/ &&
+ !-d $path_translated) {
show_error($forum,"Операция $form может быть вызвана только со
страницы форума");
}
}
# Заполнить название и аннотацию
my $abstract = input2tree($cgi,$forum,"abstract");
- substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text);
+ substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text) if $abstract;
substinfo($tree,[_tag=>"title"],_content=>$cgi->param("title"));
my $subtree = $tree->look_down("class"=>"annotation")
or show_error($forum,"В шаблоне форума отсутствует класс annotation");
_content=>$creation_time);
# Вставляем в страницу КОПИЮ аннотации, поскольку аннотация
# нам еще понадобится в списке тем.
- substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone);
+ substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone) if $abstract;
substitute_user_info($subtree,$forum);
substinfo($subtree,[_tag=>"img","class"=>"logo"],
src=> $logo_name, width=>$logo_width, height=>$logo_height);
if exists($actions{'topic'});
}
} elsif (-d $path_translated && -f $path_translated ."/". $forum->{indexfile}) {
- print STDERR "Dispatching forum\n";
$actions{'forum'}->($cgi,$forum,$path_translated)
if exists($actions{'forum'});
# Преобразуем текст в 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");
}
_content=>$cgi->param("title"));
# Вставляем в страницу КОПИЮ аннотации, поскольку аннотация
# нам еще понадобится в списке тем.
- substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone);
+ substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone) if $abstract;
} else {
substinfo($tree,["class"=>"title"],
_content=>$cgi->param("title"));
}
my ($tree,$lockfd) = gettree($path_translated . "/".$forum->{indexfile});
my $abstract = input2tree($cgi,$forum,"abstract");
- substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text);
+ substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text) if $abstract;
substinfo($tree,[_tag=>"title"],_content=>$cgi->param("title"));
my $subtree = $tree->look_down("class"=>"annotation");
substinfo($subtree,["class"=>"title"],
_content=>$cgi->param("title"));
# Вставляем в страницу КОПИЮ аннотации, поскольку аннотация
# нам еще понадобится в списке тем.
- substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone);
+ substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone) if $abstract;
substinfo($subtree,[_tag=>"img","class"=>"logo"],
src=> $logo_name, width=>$logo_width, height=>$logo_height)
if defined($logo_name);
}
sub savetree {
my ($filename,$tree,$lockfd) = @_;
- print STDERR "Savetree(@_)\n";
replacefile($filename,output_html($tree));
close $lockfd if defined($lockfd);
}
#
sub output_html {
my $tree=shift;
- print STDERR "output_html(@_)\n";
+ 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("<>&");
}