]> www.wagner.pp.ru Git - oss/stilllife.git/blobdiff - forum/forum
*** empty log message ***
[oss/stilllife.git] / forum / forum
index 5ece800ea5750a442beddde87169e3247657a177..3faec6039281b856667341360cf03c030470cc14 100755 (executable)
@@ -65,7 +65,6 @@ my $cgi = new CGI;
 print STDERR "--------------------\n";
 my $forum=get_forum_config();
 
-
 authorize_user($cgi,$forum);
 if ($cgi->request_method ne "POST") {
 # Запрос к скрипту методом GET. Надо показать форму, если только это не
@@ -83,6 +82,7 @@ if ($cgi->request_method ne "POST") {
 # нехороших символов нет, но чтобы perl в taint mode не
 # ругался... 
                                if (allow_operation($param,$cgi,$forum)) {
+                                       print STDERR "Allow_operation completed\n";
                                        show_template($1,$cgi,$forum) if $param=~/^(\w+)$/;     
                                        exit;
                                } else {
@@ -384,7 +384,8 @@ sub fix_forum_links {
                }
                my $link = $element->attr($attr);
                # Абсолютная ссылка - оставляем как есть. 
-               next ELEMENT if (! defined $link || $link=~/^\w+:/); 
+               next ELEMENT if (! defined $link || $link=~/^\w+:/ || $link
+               eq"."||$link eq ".."); 
                # Ссылка от корня сайта. 
                if (substr($link,0,1) eq "/") {
                        # Если она не ведет на наш скрипт, не обрабатываем
@@ -934,10 +935,10 @@ sub new_topic {
        # Скрыть список сообщений.
        hide_list($tree,"messagelist");
        savetree($filename,$tree,undef);
+       $tree->destroy;
        #
        # Добавляем элемент в список тем текущего форума
        #
-       $tree->destroy;
 
        my $lockfd;
        ($tree,$lockfd)=gettree($path_translated."/".$forum->{"indexfile"});
@@ -959,6 +960,126 @@ sub new_topic {
        record_statistics($forum,"topic");
        forum_redirect($cgi,$forum,$cgi->path_info."/$urlname.html");
 }
+
+sub new_forum {
+       my ($form,$cgi,$forum) = @_;
+       #
+       # Проверяем корректность urlname и прочих полей
+       #
+       my $urlname;
+        if (!$cgi->param("urlname")) {
+               form_error($form,$cgi,$forum,"Форуму необходимо задать непустое urlname");
+        }     
+        if ($cgi->param("urlname") eq ".") {
+               $urlname = "."
+        } else {       
+               $urlname=$1 if $cgi->param("urlname") =~ /^([-\w]+)$/ ;
+               form_error($form,$cgi,$forum,"Некорректные символы в urlname.
+                       Допустимы только латинские буквы, цифры и минус") unless $urlname; 
+       }
+       if (!-d $path_translated) {
+               show_error($forum,"Операция $form может быть вызвана только со
+               страницы форума");
+       }       
+       my $newname = "$path_translated/$urlname";
+       $newname=$path_translated if ($urlname eq ".");  
+       my $filename = "$newname/$forum->{indexfile}";
+       if (-f $filename) {
+               form_error($form,$cgi,$forum,"Форум $urlname уже существует");
+       }       
+       if (!$cgi->param("title")) {
+               form_error($form,$cgi,$forum,"Форум должен иметь непустое название");
+       }
+       mkdir $newname unless -d $newname;
+       #
+       # Сохраняем логотип
+       #
+       my ($logo_name,$logo_width,$logo_height);
+       if ($cgi->param("logo")) {
+               my $userpath = $cgi->param("logo");
+               $logo_name="logo.".lc($1) if $userpath=~/\.([^.]+)$/;
+               my $in = $cgi->upload("logo");
+               if (!$in) {
+                       show_error($forum,"Ошибка при загрузке картинки $userpath");
+                       exit;
+               }       
+               my $out;
+               open $out,">$newname/$logo_name";
+               binmode $out,":bytes";
+               local $/=undef;
+               my $data = <$in>;
+               print $out $data;
+               close $in;
+               close $out;
+               ($logo_width,$logo_height) = imgsize("$newname/$logo_name");
+       } else {
+               $logo_name = $forum->{"templatesurl"}."/1x1.gif";
+               $logo_width = 1;
+               $logo_height=1;
+       }       
+
+
+       #
+       # Создаем собственно оглавление форума
+       #
+       
+
+       my $tree = gettemplate($forum,"forum",$cgi->path_info."/$urlname");
+    # Заполнить название и аннотацию 
+       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")
+               or show_error($forum,"В шаблоне форума отсутствует класс annotation");
+       my $creation_time=strftime("%d.%m.%Y %H:%M",localtime());
+               substinfo($subtree,["class"=>"title"],
+               _content=>$cgi->param("title"));
+               substinfo($subtree,["class"=>"date"],
+                       _content=>$creation_time);
+               # Вставляем в страницу КОПИЮ аннотации, поскольку аннотация
+               # нам еще понадобится в списке тем.
+               substinfo($subtree,["class"=>"abstract"],_content=>$abstract->clone);   
+               substitute_user_info($subtree,$forum);  
+       substinfo($subtree,[_tag=>"img","class"=>"logo"],
+               src=> $logo_name, width=>$logo_width, height=>$logo_height);
+       # Скрыть списки подфорумов и тем .
+       hide_list($tree,"forumlist");
+       hide_list($tree,"topiclist");
+       if ($urlname eq ".") {
+               for my $link_up ($tree->look_down(_tag=>"a",href=>"..")) {
+                       $link_up->delete;
+               }
+       }       
+       savetree($filename,$tree,undef);
+       $tree->destroy;
+       #
+       # Добавляем элемент в список тем текущего форума
+       #
+       if ($urlname ne ".") {
+       my $lockfd;
+       ($tree,$lockfd)=gettree($path_translated."/".$forum->{"indexfile"});
+       my $newforum = newlistelement($tree,"forum","forumlist");
+       substinfo($newforum,[_tag=>"a","class"=>"title"],
+       _content=>$cgi->param("title"), href=>"$urlname/");
+       substinfo($newforum,["class"=>"date"], _content=>$creation_time);
+       substinfo($newforum,["class"=>"abstract"],_content=>$abstract); 
+       substinfo($newforum,[_tag=>"img","class"=>"logo"],src=>"$urlname/$logo_name",
+               width=>$logo_width,height=>$logo_height);
+       substitute_user_info($newforum,$forum); 
+       $newforum->attr("id",$urlname);
+       my $controlform = $newforum->look_down(_tag=>"form",class=>"foruminfo");
+       if ($controlform) {
+               $controlform->attr("action"=>$cgi->url(-absolute=>1,-path_info=>1).
+               "/$urlname");
+               substinfo($controlform,[_tag=>"input",name=>"author"],value=>
+                       $forum->{authenticated}{user});
+       }               
+       savetree($path_translated."/".$forum->{"indexfile"},$tree,$lockfd);
+       record_statistics($forum,"forum");
+       }
+       forum_redirect($cgi,$forum,$cgi->path_info."/$urlname");
+}
+       
 #---------------------------------------------------------- 
 # База пользователей и права доступа
 #----------------------------------------------------------
@@ -988,12 +1109,14 @@ sub getrights {
                return undef;
        }       
        my $user = $forum->{authenticated}{user};
-       my $dir = $ENV{'PATH_TRANSLATED'};
+       my $dir = $path_translated;
+       $dir =~s/\/$//;
        $dir =~s/\/[^\/]+$// if (!-d $dir);
        my $f;
        my $user_status = "normal";
        LEVEL:
        while (length($dir)) {  
+               print STDERR "Searcghing for perms in $dir\n";
                if (-f "$dir/perms.txt") {
                        open $f,"<","$dir/perms.txt";
                        my $status = undef;
@@ -1015,9 +1138,9 @@ sub getrights {
                        }
                        close $f;
                        last LEVEL if  -f "$dir/.forum";
-                       # Strip last path component.
-                       $dir =~s/\/[^\/]+$// 
                }       
+               # Strip last path component.
+               $dir =~s/\/[^\/]+$// 
        }               
        return $user_status;