+ #
+ # Копируем элемент с классом message
+ #
+ my $newmsg = $messagetpl->clone;
+ my $parent = $messagetpl->parent;
+ $parent->push_content($newmsg);
+ #
+ # Подставляем данные сообщения
+ #
+ $newmsg->attr("id"=>$id);
+ substinfo($newmsg,[class=>"subject"],_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) {
+ substinfo($editform,[_tag=>"input",name=>"id"],value=>$id) ||
+ show_error($forum,"В форме управления сообщением нет поля id");
+ substinfo($editform,[_tag=>"input",name=>"author"],value=>
+ $forum->{authenticated}{user}) ||
+ show_error($forum,"В форме управления сообщением нет поля author");
+ }
+ # Подставляем mdate
+ substinfo($newmsg,["class"=>"mdate"],
+ _content =>strftime("%d.%m.%Y %H:%M",localtime()));
+ # Подставляем mreply
+ substinfo($newmsg,[_tag=>"a","class"=>"mreply"],"href" =>
+ $cgi->url(-absolute=>1,-path_info=>1)."?reply=1&id=$id");
+ # Подставляем manchor
+ substinfo($newmsg,[_tag=>"a","class"=>"manchor"],
+ "name"=>"#$id","href"=>undef) or
+ show_error($forum,"В шаблоне сообщения отсутствует якорь для ссылок на него");
+ # подставляем mlink
+ substinfo($newmsg,[_tag=>"a","class"=>"mlink"],
+ href=>$cgi->path_info."#id");
+ # подставляем mparent
+ my $parent_id=$cgi->param("id");
+ if ($parent_id) {
+ substinfo($newmsg,[_tag => "a",class=>"mparent"],
+ "href"=>$cgi->path_info."#$parent_id");
+ } else {
+ substinfo($newmsg,[_tag => "a",class=>"mparent"],
+ "_content"=>"");
+ }
+
+ #
+ # Проверяем видимость списка сообщений
+ #
+ my $msglist = $tree->look_down("class"=>"messagelist");
+ if ($msglist) {
+ my $style = $msglist->attr("style");
+ $msglist->attr("style",$style) if $style && $style =~ s/display: none;//;
+ }
+ #
+ # Делаем Уфф и сохраняем то, что получилось
+ #
+ savetree($ENV{PATH_TRANSLATED},$tree,$lockfd);
+ forum_redirect($cgi,$forum);
+