X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;ds=sidebyside;f=forum%2Fforum;h=e7cbc9218f6e23ae34691ed508adc207a72147c9;hb=89667c75001818612ff7456840d369954560e76a;hp=989c5bc173ed374e8d975effa24c11eb61d4d49a;hpb=e520a1139a35b2e8f30407dcee80ad363f0e3b76;p=oss%2Fstilllife.git diff --git a/forum/forum b/forum/forum index 989c5bc..e7cbc92 100755 --- a/forum/forum +++ b/forum/forum @@ -19,6 +19,9 @@ use HTML::TreeBuilder; use Storable qw(freeze thaw); use Date::Parse; use Email::Valid; +use Image::Size; +use HTML::BBReverse; +use POSIX; use LWP::UserAgent; use Net::OpenID::Consumer; # @@ -345,7 +348,7 @@ sub show_template { } } - $f->attr("type","POST"); + $f->attr("method","POST"); for my $required ($form,"returnto") { if (!$substituted{$required}) { my $element = new HTML::Element('input', @@ -421,39 +424,27 @@ my %userinfo = %{$forum->{"authenticated"}}; # # СпеÑиалÑно обÑабаÑÑваем Ð¿Ð¾Ð»Ñ user (должна бÑÑÑ ÑÑÑлка) и avatar # (должен бÑÑÑ img). -my @userlink = $tree->look_down("_tag"=>"a","class"=>"author"); -if (@userlink) { my $userpage; - if ($userinfo{"user"}=~/^http:/) { - $userpage = $userinfo{"user"}; + if ($userinfo{"openiduser"}) { + $userpage = "http://".$userinfo{"user"}; } else { $userpage = $cgi->url(-absolute=>1).$forum->{"userurl"}."/".$cgi->escape($userinfo{"user"}); } - for my $element (@userlink) { - $element->attr(href=>$userpage); + 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"); + delete $userinfo{"avatar"}; + + for my $element ( $tree->look_down("class",qr/^ap-/)) { + my $field=$1 if $element->attr("class")=~/^ap-(.*)$/; $element->delete_content(); - $element->push_content($userinfo{"user"}); + $element->push_content(str2tree($userinfo{$field})) + if $userinfo{$field}; } -} -delete $userinfo{"userpage"}; -delete $userinfo{"user"}; -my $avatar = $tree->look_down("_tag"=>"img","class"=>"avatar"); -if ($avatar) { - $avatar->attr(src=>$userinfo{"avatar"}); -} -delete $userinfo{"avatar"}; -while (my ($field,$value)=each %userinfo) { - my $element = $tree->look_down("class","a".$field); - if ($element) { - $element->delete_content(); - # - # FixME - allow HTML in author attributes - $element->push_content($value); - } - -} } # @@ -490,8 +481,7 @@ sub authorize_user { } print STDERR "user $user restored session $session\n"; $forum->{"authenticated"}=$userinfo; - print STDERR "authorize_user: - ",$forum->{authenticated}{user}, + print STDERR "authorize_user: ",$forum->{authenticated}{user}, $forum->{authenticated},"\n"; } dbmclose %userbase; @@ -787,24 +777,27 @@ sub reply { # # Ð¡Ð¾Ñ ÑанÑем пÑиаÑÑаÑеннÑе каÑÑинки, еÑли еÑÑÑ. # - my $dir = $ENV{PATH_TRANSLATED}; + my $dir = $1 if $ENV{PATH_TRANSLATED}=~/^(.*)$/; $dir=~ s/[^\/]+$// if (-f $dir); my %attached; - for (my $i=1;defined $cgi->param("image$i"); $i++) { + for (my $i=1;$cgi->param("image$i"); $i++) { my $userpath=$cgi->param("image$i"); my $filename=lc($1) if $userpath =~ /([^\/\\]+)$/; - attached{$filename} = $id."_".$filename; + $attached{$filename} = $id."_".$filename; my $in = $cgi->upload("image$i"); + if (!$in) { + show_error($forum,"ÐÑибка пÑи загÑÑзке каÑÑинки $filename"); + exit; + } my $out; open $out,">$dir/$attached{$filename}"; binmode $out,":bytes"; - local $_=undef; + local $/=undef; my $data = <$in>; print $out $data; close $in; close $out; } - # # ÐÑеобÑазÑем ÑекÑÑ Ð·Ð°Ð¿Ð¸Ñи в html и ÑиÑÑим его # @@ -814,8 +807,8 @@ sub reply { # имена, под коÑоÑÑми Ð¼Ñ Ð¸Ñ ÑÐ¾Ñ Ñанили. # for my $image ($txtree->find_by_tag_name("img")) { - my $file; - if ( exists $attached{$file=lc($image->attr("src"))}) { + my $file=lc($image->attr("src")); + if ( exists $attached{$file}) { $image->attr("src" => $attached{$file}); my ($width,$height) = imgsize($dir ."/".$attached{$file}); $image->attr("width" =>$width); @@ -832,11 +825,7 @@ sub reply { # ÐодÑÑавлÑем даннÑе ÑообÑÐµÐ½Ð¸Ñ # $newmsg->attr("id"=>$id); - if (my $subj=$newmsg->look_down("class"=>"subject") && - $cgi->param("subject")) { - $subj->delete_content; - $subj->push_content($cgi->param("subject")); - } + substinfo($newmsg,[class=>"subject"],_content=>$cgi->param("subject")); my $textnode=$newmsg->look_down("class"=>"mtext"); if (!$textnode) { show_error($forum,"Ð Ñаблоне Ñеплики Ð½ÐµÑ Ð¼ÐµÑÑа Ð´Ð»Ñ ÑекÑÑа"); @@ -853,53 +842,33 @@ sub reply { # my $editform=$newmsg->look_down(_tag=>"form","class"=>"msginfo"); if ($editform) { - my $idfield = $editform->look_down(_tag=>"input","name"=>"id"); - if (!$idfield) { - show_error($forum,"Ð ÑоÑме ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ÑообÑением Ð½ÐµÑ Ð¿Ð¾Ð»Ñ - id"); - } - $idfield->attr("value" => $id); - my $authorfield = $editform->look_down(_tag=>"input","name"=>"author"); - if (!$authorfield) { - show_error($forum,"Ð ÑоÑме ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ÑообÑением Ð½ÐµÑ Ð¿Ð¾Ð»Ñ - id"); - } - $authorfield->attr("value"=>$forum->{authenticated}{user}); + substinfo($editform,[_tag=>"input",name=>"id"],value=>$id) || + show_error($forum,"Ð ÑоÑме ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ÑообÑением Ð½ÐµÑ Ð¿Ð¾Ð»Ñ id"); + substinfo($editform,[_tag=>"input",name=>"author"],value=> + $forum->{authenticated}{user}) || + show_error($forum,"Ð ÑоÑме ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ÑообÑением Ð½ÐµÑ Ð¿Ð¾Ð»Ñ author"); } # ÐодÑÑавлÑем mdate - my $date = $newmsg->look_down("class"=>"mdate"); - if ($date) { - $date->delete_content; - $date->push_content(strftime("%d.%m.%Y %H:%M",localtime())); - - } + substinfo($newmsg,["class"=>"mdate"], + _content =>strftime("%d.%m.%Y %H:%M",localtime())); # ÐодÑÑавлÑем mreply - my $reply_link = $newmsg->look_down(_tag=>"a","class"=>"mreply"); - $reply_link->attr("href"=> $cgi->url(-absolute=>1,-path_info=>1). - "?reply=1&id=$id") if ($reply_link); + substinfo($newmsg,[_tag=>"a","class"=>"mreply"],"href" => + $cgi->url(-absolute=>1,-path_info=>1)."?reply=1&id=$id"); # ÐодÑÑавлÑем manchor - my $anchor = $newmsg->look_down(_tag=>"a","class"=>"manchor"); - if (! $anchor) { - show_error($forum,"Ð Ñаблоне ÑообÑÐµÐ½Ð¸Ñ Ð¾ÑÑÑÑÑÑвÑÐµÑ ÑкоÑÑ Ð´Ð»Ñ - ÑÑÑлок на него"); - exit; - } - $anchor->attr(href=>undef); - $anchor->attr(name=>"#$id"); + substinfo($newmsg,[_tag=>"a","class"=>"manchor"], + "name"=>"#$id","href"=>undef) or + show_error($forum,"Ð Ñаблоне ÑообÑÐµÐ½Ð¸Ñ Ð¾ÑÑÑÑÑÑвÑÐµÑ ÑкоÑÑ Ð´Ð»Ñ ÑÑÑлок на него"); # подÑÑавлÑем mlink - my $link = $newmsg->look_down(_tag=>"a","class"=>"mlink"); - $link->attr(href=>$cgi->path_info."#id"); + substinfo($newmsg,[_tag=>"a","class"=>"mlink"], + href=>$cgi->path_info."#id"); # подÑÑавлÑем mparent my $parent_id=$cgi->param("id"); - my $parent_link=$newmsg->lookdown(_tag => "a",class=>"mparent"); - if ($parent_link) { - if ($parent_id) { - $parent_link->attr("href"=>$cgi->path_info."#$parent_id"); - } else { - # ÐÑли parent_id оÑÑÑÑÑÑвÑеÑ, Ñ.е. ÑÑо наÑало нового ÑÑеда - # пÑоÑÑо делаем ÑÑÑÐ»ÐºÑ Ð½ÐµÐ²Ð¸Ð´Ð¸Ð¼Ð¾Ð¹. - $parent_link->delete_content(); - } + if ($parent_id) { + substinfo($newmsg,[_tag => "a",class=>"mparent"], + "href"=>$cgi->path_info."#$parent_id"); + } else { + substinfo($newmsg,[_tag => "a",class=>"mparent"], + "_content"=>""); } # @@ -908,7 +877,7 @@ sub reply { my $msglist = $tree->look_down("class"=>"messagelist"); if ($msglist) { my $style = $msglist->attr("style"); - $msglist->attr("style",$style) if $style =~ s/display: none;//; + $msglist->attr("style",$style) if $style && $style =~ s/display: none;//; } # # Ðелаем УÑÑ Ð¸ ÑÐ¾Ñ ÑанÑем Ñо, ÑÑо полÑÑилоÑÑ @@ -982,8 +951,9 @@ sub gettree { # sub savetree { - my ($filename,$tree,$lockfd) = shift; + my ($filename,$tree,$lockfd) = @_; my $f; + $filename = $1 if $filename =~ /^(.*)$/; open $f,">",$filename . ".new" or return undef; print $f $tree->as_HTML("<>&"); close $f; @@ -1001,14 +971,15 @@ sub savetree { sub get_uid { my $forum = shift; my $f; - open $f,"<+",datafile($forum,"sequence"); + open $f,"+<",datafile($forum,"sequence") or flock $f,LOCK_EX; my $id=<$f> || "0"; $id++; seek $f,0,0; printf $f "%8s\n",$id; close $f; - return sprintf ("%08s",$id); + $id=~/(\d+)/; + return sprintf ("%08s",$1); } # -------------------------------------------------------------------- # OpenID registration @@ -1104,18 +1075,14 @@ sub input2tree { my ($cgi,$forum,$field_name) = @_; my $format = $cgi->param($field_name."_format"); my $text = $cgi->param($field_name); - if ($format eq "bbcode") { my $parser = HTML::BBReverse->new(); $text="
/;
$text=~s/\r?\n/
/;
- $text = "
".$text."
"; - } else { - $text="".$text."