From 28fc8232c0a3222eccc8507fe4fe4affb7ec08ee Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Tue, 25 Mar 2008 21:59:54 +0000 Subject: [PATCH] *** empty log message *** --- forum/TODO | 25 +++---- forum/forum | 135 ++++++++++++++++++++++++++++++++-- templates/basicset/forum.html | 17 +++-- templates/basicset/topic.html | 10 +-- 4 files changed, 156 insertions(+), 31 deletions(-) diff --git a/forum/TODO b/forum/TODO index c924f77..d499084 100644 --- a/forum/TODO +++ b/forum/TODO @@ -1,15 +1,12 @@ Roadmap по server-side части -1. newtopic -2. newforum -3. процедура раскрутки -4. страничка юзера -5. список юзеров -6. редактирование user profile и фиксы в регистрации -7. Механизм регистрации с подтверждением -8. delete (message, topic, forum) -9. edit (message,topic,forum) -10. move (message,topic,forum) -11. setrights -12. applytemplates -13. Раскрутка форума -14. Почтовые оповещения о новых репликах, RSS или recent comments page +1. процедура раскрутки +2. страничка юзера +3. список юзеров +4. редактирование user profile и фиксы в регистрации +5. Механизм регистрации с подтверждением +6. delete (message, topic, forum) +7. edit (message,topic,forum) +8. move (message,topic,forum) +9. setrights +10. applytemplates +11. Почтовые оповещения о новых репликах, RSS или recent comments page diff --git a/forum/forum b/forum/forum index 5ece800..3faec60 100755 --- a/forum/forum +++ b/forum/forum @@ -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; diff --git a/templates/basicset/forum.html b/templates/basicset/forum.html index 5219f07..011033a 100644 --- a/templates/basicset/forum.html +++ b/templates/basicset/forum.html @@ -14,18 +14,24 @@ class="login" href="forum?login=1">Войти Создать форум Редактировать Права доступа +Уровень выше

Тестовый форум Still Life

Корень форума

-
Создан
-
+

Подфорумы

-Название форума Создан:
+ + +
+Название форума Создан:
аннотация форума
@@ -33,13 +39,13 @@ class="logo">
Создан
+

Темы

-

Название темы Создана:
# @@ -53,8 +59,7 @@ class="logo">Создан
-

- +
diff --git a/templates/basicset/topic.html b/templates/basicset/topic.html index 883367a..aa451d9 100644 --- a/templates/basicset/topic.html +++ b/templates/basicset/topic.html @@ -36,9 +36,9 @@ name="openid_site" onChange="selectSite(this)"> Пароль: Только с этого IP-адреса - + +value="Вoйти"> @@ -52,12 +52,12 @@ class="mparent">(в ответ на) Автор

-Статус:
-Email: +Статус:
+Email:
Текст сообщения
- +
-- 2.39.2