+
+sub messageedit {
+ my ($cgi,$forum,$topic,$id) = @_;
+ my ($tree,$lockfd) = gettree($path_translated);
+ my ($msg) = $tree->look_down(id=>$id);
+ show_error($forum,"В данной теме нет реплики с id=$id") if (!$msg);
+ show_error($forum,"У вас нет прав на редактированиее этого сообщения")
+ unless moderator_or_author($cgi,$forum,$msg);
+ # Обработка картинок
+ my ($dirname,$topic_id)=($1,$2) if $path_translated=~/(.+)\/([^\/]+).html/;
+ # 1. Удаляем помеченные как таковые
+ for my $file ($cgi->param("delpictire")) {
+ unlink $dirname."/".$file;
+ }
+ # 2. Сохраняем свежеприаттаченные
+ my %attached=save_attached_images($cgi,$forum,$dirname,"${id}_%f",grep(/^image\d+/,$cgi->param));
+
+ # Преобразуем текст в html
+ my $txtree = input2tree($cgi,$forum,"text");
+ fix_image_links($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);
+ makeuserlink($forum,$msg,"editor",$forum->{authenticated});
+ unhide_list($msg,"edited");
+ my $textnode = $msg->look_down(class=>"mtext");
+ my ($old_text)=$textnode->splice_content(0,1,$txtree);
+ $old_text->delete;
+ $msg = $msg->clone;
+ my @msgs = $tree->look_down(class=>"message");
+ my $msgcount=@msgs;
+ savetree($path_translated,$tree,$lockfd);
+ record_as_recent($forum,$msg);
+ update_topic_list($forum,$path_translated,$msgcount,$edited);
+ forum_redirect($cgi,$forum,$cgi->url(-base=>1).$cgi->path_info()."#$id");
+}
+
+
+sub topicedit {
+ my ($cgi,$forum,$topic) = @_;
+ show_error($forum,"Нет такой темы ".$cgi->path_info)
+ if (!-f $path_translated);
+ show_error($forum,"У вас нет прав на редактированиее этой темы")
+ unless moderator_or_author($cgi,$forum,$topic);
+ form_error("edit_topic",$cgi,$forum,"Тема должна иметь непустое название")
+ if (!$cgi->param("title"));
+ my $abstract = input2tree($cgi,$forum,"abstract");
+ my ($tree,$lockfd) = gettree($path_translated);
+ my $subtree = $tree->look_down("class"=>"topic");
+ if ($subtree) {
+ substinfo($subtree,["class"=>"title"],
+ _content=>$cgi->param("title"));
+ # Вставляем в страницу КОПИЮ аннотации, поскольку аннотация
+ # нам еще понадобится в списке тем.
+ substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone);
+ } else {
+ substinfo($tree,["class"=>"title"],
+ _content=>$cgi->param("title"));
+ }
+ savetree($path_translated,$tree,$lockfd);
+ $tree->destroy;
+ my ($dir,$id) = ($1,$2) if $path_translated=~/^(.*)\/([^\/]+).html$/;
+ ($tree,$lockfd) = gettree($dir."/".$forum->{indexfile});
+ my $item = $tree->look_down(id=>$id);
+ substinfo($item,[_tag=>"a","class"=>"title"],
+ _content=>$cgi->param("title"));
+ substinfo($item,["class"=>"abstract"],_content=>$abstract);
+ savetree($dir."/".$forum->{"indexfile"},$tree,$lockfd);
+ forum_redirect($cgi,$forum);
+}
+
+sub forumedit {
+ my ($cgi,$forum,$dir) = @_;
+ show_error($forum,"У вас нет прав на редактированиее этого форума")
+ unless (getrights($cgi,$forum) eq 'moderator' || getrights($cgi,$forum) eq
+ 'admin');
+
+ if (!-d $path_translated) {
+ show_error($forum,"Операция редактирования форумаможет быть вызвана только со
+ страницы форума");
+ }
+ if (!$cgi->param("title")) {
+ form_error("edit_forum",$cgi,$forum,"Форум должен иметь непустое название");
+ }
+ my ($logo_name,$logo_width,$logo_height);
+ if ($cgi->param("delpicture")) {
+ # Удаляем старый логотип
+ unlink $path_translated ."/".$cgi->param("delpicture");
+ $logo_name = $forum->{"templatesurl"}."/1x1.gif";
+ $logo_width = 1;
+ $logo_height=1;
+ }
+ if ($cgi->param("logo")) {
+ # Удаляем все, что похоже на логотип
+ opendir D, $path_translated;
+ for my $f (readdir(D)) {
+ next unless -f $path_translated."/".$f && $f=~/^logo\.\w+$/;
+ unlink $path_translated."/".$f;
+ }
+ closedir D;
+ $logo_name=(save_attached_images($cgi,$forum,$path_translated,"logo.%e","logo"))[1];
+ ($logo_width,$logo_height) = imgsize("$path_translated/$logo_name");
+ }
+ 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=>"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,[_tag=>"img","class"=>"logo"],
+ src=> $logo_name, width=>$logo_width, height=>$logo_height)
+ if defined($logo_name);
+ savetree($path_translated ."/".$forum->{indexfile},$tree,$lockfd);
+ $tree->destroy;
+ if ($path_translated ne $forum->{forumroot}) {
+ my ($updir,$id) = ($1,$2) if $path_translated=~/^(.*)\/([^\/]+)$/;
+ ($tree,$lockfd) = gettree($updir . "/".$forum->{indexfile});
+ my $item = $tree->look_down(id=>$id);
+ substinfo($item,[_tag=>"a","class"=>"title"],
+ _content=>$cgi->param("title"));
+ substinfo($item,["class"=>"abstract"],_content=>$abstract);
+ substinfo($item,[_tag=>"img","class"=>"logo"],src=>"$id/$logo_name",
+ width=>$logo_width,height=>$logo_height) if $logo_name;
+ savetree($updir."/".$forum->{"indexfile"},$tree,$lockfd);
+ }
+ forum_redirect($cgi,$forum);
+}
+