sub get_forum_config {
$path_translated = $1 if $ENV{PATH_TRANSLATED}=~/^(\S+)$/;
+ $path_translated=~s/\/+$//;
my @path=split("/",$path_translated);
while (@path>1) {
if (-r (my $config=join("/",@path,".forum")) ) {
#
sub fix_forum_links {
my ($forum,$tree,$path_info) = @_;
- $path_info=$ENV{'PATH_INFO'} if (!defined $path_info);
+ if (!defined $path_info) {
+ $path_info = $ENV{PATH_INFO};
+ $path_info =~ s/\/+/\//g;
+ }
my $script_with_path = $ENV{SCRIPT_NAME}.$path_info;
ELEMENT:
for my $element ($tree->find_by_tag_name("form","img","link","script","a")) {
substinfo($tree,["_tag"=>"a","class"=>"author"],
href=>$userpage,_content=>$userinfo{"user"});
delete $userinfo{"user"};
- substinfo($tree,["_tag"=>"img","class"=>"avatar"],
- src=>$userinfo{"avatar"}||$forum->{templatesurl}."/1x1.gif");
+ if (ref $userinfo{"avatar"} eq "HASH") {
+ substinfo($tree,["_tag"=>"img","class"=>"avatar"],
+ %{$userinfo{'avatar'}});
+ } elsif ($userinfo{'avatar'}) {
+ substinfo($tree,["_tag"=>"img","class"=>"avatar"],
+ src=>$userinfo{"avatar"});
+ } else {
+ substinfo($tree,["_tag"=>"img","class"=>"avatar"],
+ src=>$forum->{templatesurl}."/1x1.gif",
+ width=>1,height=>1);
+ }
delete $userinfo{"avatar"};
for my $element ( $tree->look_down("class",qr/^ap-/)) {
form_error($form,$cgi,$forum,"Тема с urlname $urlname уже
существует");
}
+ my $url = $cgi->url(-absolute=>1,-path_info=>1)."/$urlname.html";
+ $url =~ s/\/+/\//g;
if (!$cgi->param("title")) {
form_error($form,$cgi,$forum,"Тема должна иметь непустое название");
}
#
# Создаем собственно тему
#
- my $tree = gettemplate($forum,"topic",$cgi->path_info."/$urlname.html");
+ my $tree = gettemplate($forum,"topic",$url);
# Заполнить название и аннотацию
my $abstract = input2tree($cgi,$forum,"abstract");
substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text);
$newtopic->attr("id",$urlname);
my $controlform = $newtopic->look_down(_tag=>"form",class=>"topicinfo");
if ($controlform) {
- $controlform->attr("action"=>$cgi->url(-absolute=>1,-path_info=>1).
- "/$urlname.html");
+ $controlform->attr("action"=>$url);
substinfo($controlform,[_tag=>"input",name=>"author"],value=>
$forum->{authenticated}{user});
}
savetree($path_translated."/".$forum->{"indexfile"},$tree,$lockfd);
record_statistics($forum,"topic");
- forum_redirect($cgi,$forum,$cgi->path_info."/$urlname.html");
+ forum_redirect($cgi,$forum,$cgi->url(-base=>1).$url);
}
sub new_forum {
# Создаем собственно оглавление форума
#
-
- my $tree = gettemplate($forum,"forum",$cgi->path_info."/$urlname");
+ my $url = $cgi->path_info."/$urlname";
+ $url =~ s/\/+/\//g;
+ my $tree = gettemplate($forum,"forum",$url);
# Заполнить название и аннотацию
my $abstract = input2tree($cgi,$forum,"abstract");
substinfo($tree,[_tag=>"meta","name"=>"description"],content=>$abstract->as_trimmed_text);
$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");
+ $controlform->attr("action"=>$cgi->url(-absolute=>1,-path_info=>0).
+ $url);
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");
+ forum_redirect($cgi,$forum,$cgi->url(-base=>1).$url);
}
#----------------------------------------------------------
sub gettemplate {
my ($forum, $template,$url) = @_;
+ $url =~ s/\/+/\//g;
my $filename=$forum->{"templates"}."/$template.html";
if (! -r $filename) {
show_error($forum,"Нет шаблона $template");
sub create_openid_consumer {
my ($cgi,$forum) = @_;
return Net::OpenID::Consumer ->new(
- ua => LWP::UserAgent->new(),
+ ua => LWP::UserAgent->new( agent => "Stilllife/1.0"),
args => $cgi,
consumer_secret=>"X9RWPo0rBE7yLja6VB3d",
required_root => $cgi->url(-base=>1));
my $username = $user;
$username =~ s/^http:\/\///;
if (!$userbase{$username}) {
- $userbase{$username} = freeze($forum->{authenticated}={"openiduser"=>1});
+ # Тащим foaf, если получится
+ my %info=get_foaf($csr->ua,$vident->declared_foaf);
+ if (ref($info{'avatar'}) eq "HASH" ) {
+ delete $info{'avatar'}{'type'};
+ }
+ $info{"openiduser"}=1;
+ $forum->{authenticated}=\%info;
+ $userbase{$username} = freeze(\%info);
} else {
$forum->{authenticated} = thaw ($userbase{$username});
}
exit;
}
}
+
+sub get_foaf {
+ my ($ua,$foaf_url) = @_;
+ my $response = $ua->get($foaf_url);
+ unless ($response->is_success) {
+ print STDERR "Error geting foaf from $foaf_url\n";
+ return ();
+ }
+ my $foaf = $response->content;
+ my %info = foaf_parse($foaf);
+ if ($info{avatar}) {
+ $response = $ua->get($info{avatar});
+ if ($response->is_success) {
+ my $image = $response->content;
+ my ($w,$h,$type) = imgsize(\$image);
+ $info{avatar}={width=>$w,height=>$h,type=>$type,src=>$info{avatar}};
+ } else {
+ print STDERR "Error getting $info{avatar}: ".$response->status_line,"\n";
+ }
+ }
+ return %info;
+}
+sub foaf_parse {
+ my $foaf = shift;
+ my ($starttag) = $foaf =~ /<(\w+(:\w+)?[^>]+)>/sg;
+ my %ns = reverse ($starttag =~ /xmlns:(\w+)="([^"]+)"/sg);
+ my $foaf_prefix = $ns{"http://xmlns.com/foaf/0.1/"};
+ my $rdf_prefix = $ns{"http://www.w3.org/1999/02/22-rdf-syntax-ns#"};
+ my ($userpic) = $foaf=~/<$foaf_prefix:img[^>]* $rdf_prefix:resource="([^"]+)"/s;
+ my @info;
+ push @info, avatar =>$userpic if $userpic;
+ my ($icq) = $foaf =~/<$foaf_prefix:icqChatID>([^<]*)<\/$foaf_prefix:icqChatID>/s;
+ push @info, icq => $icq if ($icq);
+ my ($jabber) = $foaf =~/<$foaf_prefix:jabberID>([^<]*)<\/$foaf_prefix:jabberID>/s;
+ push @info, jabber => $jabber if ($jabber);
+ return @info;
+}
#-----------------------------------------------------------------
# Обработка форматированных текстовых полей
#-----------------------------------------------------------------