]> www.wagner.pp.ru Git - oss/stilllife.git/blobdiff - forum/forum
Решена проблема с PATH_TRANSLATED в Fedora: если путь в адресной строке
[oss/stilllife.git] / forum / forum
index 3a58ea626d0b87dc66b265f7eb974081caac6ab9..a1d613710cc5b4141d0b44fa857628f833ef84bc 100755 (executable)
@@ -13,6 +13,7 @@
 # 
 use strict;
 use warnings;
+use Carp;
 use Fcntl qw(:DEFAULT :flock);
 use CGI;
 use HTML::TreeBuilder;
@@ -1027,7 +1028,7 @@ sub reply {
        # Находим в тексте URL на приаттаченные картинки и меняем на те
        # имена, под которыми мы их сохранили.
        #
-       fix_image_links($txtree,\%attached,$dir);
+       fix_image_links($cgi,$txtree,\%attached,$dir);
        #
        # Подставляем данные сообщения 
        #
@@ -1088,17 +1089,17 @@ sub reply {
        #
        $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);
@@ -1151,18 +1152,15 @@ sub update_topic_list {
        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);
@@ -1176,6 +1174,11 @@ sub record_as_recent {
                                }       
                                $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);
@@ -1246,10 +1249,8 @@ sub show_rights {
                        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");
@@ -1304,7 +1305,9 @@ sub new_topic {
                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 может быть вызвана только со
                страницы форума");
        }       
@@ -1324,7 +1327,7 @@ sub new_topic {
        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());
@@ -1335,7 +1338,7 @@ sub new_topic {
                        _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"],
@@ -1387,7 +1390,9 @@ sub new_forum {
                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 может быть вызвана только со
                страницы форума");
        }       
@@ -1431,7 +1436,7 @@ sub new_forum {
        }
     # Заполнить название и аннотацию 
        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");
@@ -1442,7 +1447,7 @@ sub new_forum {
                        _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);
@@ -1518,7 +1523,6 @@ sub dispatch_objtype {
                                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'});
 
@@ -1816,7 +1820,7 @@ sub messageedit {
         
        #  Преобразуем текст в 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);
@@ -1829,7 +1833,7 @@ sub messageedit {
        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");
 }
@@ -1851,7 +1855,7 @@ sub topicedit {
                _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"));
@@ -1902,14 +1906,14 @@ sub forumedit {
        }
        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);
@@ -2031,7 +2035,6 @@ sub replacefile {
 }      
 sub savetree {
        my ($filename,$tree,$lockfd) = @_;
-       print STDERR "Savetree(@_)\n";
        replacefile($filename,output_html($tree));
        close $lockfd if defined($lockfd);
 }      
@@ -2048,7 +2051,8 @@ sub discardtree {
 #
 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("<>&");
 }