+ #
+ # Копируем элемент с классом message
+ #
+ my $newmsg = $messagetpl->clone;
+ my $parent = $messagetpl->parent;
+ $parent->push_content($newmsg);
+ #
+ # Подставляем данные сообщения
+ #
+ $newmsg->attr("id"=>$id);
+ if (my $subj=$newmsg->look_down("class"=>"subject") &&
+ $cgi->param("subject")) {
+ $subj->delete_content;
+ $subj->push_content($cgi->param("subject"));
+ }
+ my $textnode=$newmsg->look_down("class"=>"mtext");
+ if (!$textnode) {
+ show_error($forum,"В шаблоне реплики нет места для текста");
+ }
+ $textnode->delete_content();
+ $textnode->push_content($txtree);
+ if ($forum->{authenticated}{signature}) {
+ $textnode->push_content(new HTML::Element("br"),"--",
+ new HTML::Element("br"),str2tree($forum->{authenticated}{signature}));
+ }
+ substitute_user_info($newmsg,$forum);
+ #
+ # Подставляем данные в форму msginfo
+ #
+ my $editform=$newmsg->look_down(_tag=>"form","class"=>"msginfo");
+ if ($editform) {
+ my $idfield = $editform->look_down(_tag=>"input","name"=>"id");
+ if (!$idfield) {
+ show_error($forum,"В форме управления сообщением нет поля
+ id");
+ }
+ $idfield->attr("value" => $id);
+ my $authorfield = $editform->look_down(_tag=>"input","name"=>"author");
+ if (!$authorfield) {
+ show_error($forum,"В форме управления сообщением нет поля
+ id");
+ }
+ $authorfield->attr("value"=>$forum->{authenticated}{user});
+ }
+ # Подставляем mdate
+ my $date = $newmsg->look_down("class"=>"mdate");
+ if ($date) {
+ $date->delete_content;
+ $date->push_content(strftime("%d.%m.%Y %H:%M",localtime()));
+
+ }
+ # Подставляем mreply
+ my $reply_link = $newmsg->look_down(_tag=>"a","class"=>"mreply");
+ $reply_link->attr("href"=> $cgi->url(-absolute=>1,-path_info=>1).
+ "?reply=1&id=$id") if ($reply_link);
+ # Подставляем manchor
+ my $anchor = $newmsg->look_down(_tag=>"a","class"=>"manchor");
+ if (! $anchor) {
+ show_error($forum,"В шаблоне сообщения отсутствует якорь для
+ ссылок на него");
+ exit;
+ }
+ $anchor->attr(href=>undef);
+ $anchor->attr(name=>"#$id");
+ # подставляем mlink
+ my $link = $newmsg->look_down(_tag=>"a","class"=>"mlink");
+ $link->attr(href=>$cgi->path_info."#id");
+ # подставляем mparent
+ my $parent_id=$cgi->param("id");
+ my $parent_link=$newmsg->lookdown(_tag => "a",class=>"mparent");
+ if ($parent_link) {
+ if ($parent_id) {
+ $parent_link->attr("href"=>$cgi->path_info."#$parent_id");
+ } else {
+ # Если parent_id отсутствует, т.е. это начало нового треда
+ # просто делаем ссылку невидимой.
+ $parent_link->delete_content();
+ }
+ }
+
+ #
+ # Проверяем видимость списка сообщений
+ #
+ my $msglist = $tree->look_down("class"=>"messagelist");
+ if ($msglist) {
+ my $style = $msglist->attr("style");
+ $msglist->attr("style",$style) if $style =~ s/display: none;//;
+ }
+ #
+ # Делаем Уфф и сохраняем то, что получилось
+ #
+ savetree($ENV{PATH_TRANSLATED},$tree,$lockfd);
+ forum_redirect($cgi,$forum);
+