X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=Web.pm;h=13e397c17a74509b25da4b339129063abd519194;hb=4b4554f24cc005a4c1f97e8b4f73693702284731;hp=37539682192da812b2ad4d182d95c11e95a10209;hpb=f57880ccc987cde161a416a013be13bd28f9ee2d;p=MyWeb.git diff --git a/Web.pm b/Web.pm index 3753968..13e397c 100644 --- a/Web.pm +++ b/Web.pm @@ -23,13 +23,45 @@ our $CVS_ID=q$Id$; use strict; use warnings; -use lib qw(/home/short/lib/perl5/site_perl/5.6.0/i386-linux /home/short/lib/perl5/site_perl/5.6.0 /home/short/lib/perl5/site_perl/i386-linux /home/short/lib/perl5/site_perl /home/short/lib/perl5/5.6.0/i386-linux /home/short/lib/perl5/5.6.0 /home/short/lib/perl5/i386-linux /home/short/lib/perl5); - use Exporter; -our @EXPORT=qw(&require &a_href &a_href_cz &vskip &img $W); +sub Wrequire ($); +sub Wuse ($@); +our $W; +our @EXPORT=qw(&Wrequire &Wuse &a_href &a_href_cz &vskip &img $W &top_dir); our @ISA=qw(Exporter); -use WebConfig; # for %WebConfig +BEGIN +{ + sub Wrequire ($) + { + my($file)=@_; + +# print STDERR "Wrequire $file\n"; + $file=~s#/#::#g; + $file=~s/[.]pm$//; + my $class=$file; + $file=~s#::#/#g; + $file.=".pm"; + my $aref=($W->{"packages_used"}{$Apache::Registry::curstash}||=[]); + push @$aref,$class + if !{ map(($_=>1),@$aref) }->{$class}; # Prevent duplicated entries. + CORE::require $file; + 1; # Otherwise 'require' would already file above. + } + + sub Wuse ($@) + { + my($file,@list)=@_; + +# print STDERR "Wuse $file\n"; + Wrequire $file; + local $Exporter::ExportLevel=$Exporter::ExportLevel+1; + $file->import(@list); + 1; + } +} + +BEGIN { Wuse 'WebConfig'; } # for %WebConfig require CGI; # for &escapeHTML require Image::Size; # for &imgsize use File::Basename; # &basename @@ -46,7 +78,7 @@ delete $ENV{"PERLLIB"}; delete $ENV{"LD_LIBRARY_PATH"}; -our $W; +#our $W; # $W->{"title"} # $W->{"head"} # $W->{"head_css"} @@ -63,7 +95,9 @@ sub init ($%) { my($class,%args)=@_; + my $packages_used_save=$W->{"packages_used"}; $W={ %WebConfig,%args }; # override %WebConfig settings + $W->{"packages_used"}=$packages_used_save; $W->{"__PACKAGE__"}||="Apache::ROOT".$Apache::Registry::curstash; @@ -72,6 +106,7 @@ my($class,%args)=@_; do { $W->{$_}=0 if !defined $W->{$_}; } for ("detect_ent"); do { $W->{$_}=0 if !defined $W->{$_}; } for ("detect_js"); do { $W->{$_}=1 if !defined $W->{$_}; } for ("have_css"); # AFAIK it does not hurt anyone. + do { $W->{$_}=1 if !defined $W->{$_}; } for ("heading"); do { $W->{$_}=1 if !defined $W->{$_}; } for ("footer"); do { $W->{$_}=1 if !defined $W->{$_}; } for ("footer_delimit"); do { $W->{$_}=1 if !defined $W->{$_}; } for ("footer_mailme"); @@ -121,7 +156,7 @@ my($class,%args)=@_; $W->{"have_js"}=($W->{"args"}{"have_js"} ? 1 : 0); if ($W->{"detect_js"} && !$W->{"have_js"}) { - $W->{"head"}.=''."\n"; + $W->{"head"}.=''."\n"; } do { args_check(%$_) if $_; } for ($W->{"args_check"}); @@ -129,20 +164,10 @@ my($class,%args)=@_; return $W; } -sub require ($) +sub top_dir () { -my($file)=@_; - - $file=~s#/#::#g; - $file=~s/[.]pm$//; - my $class=$file; - $file=~s#::#/#g; - $file.=".pm"; - my $aref=($W->{"packages_used"}{$Apache::Registry::curstash}||=[]); - push @$aref,$class - if !{ map(($_=>1),@$aref) }->{$class}; # Prevent duplicated entries. - CORE::require $file; - 1; # Otherwise 'require' would already file above. + do { return $_ if $_; } for ($W->{"top_dir"}); + return $INC[0]; # fallback } sub fatal (;$); @@ -191,7 +216,7 @@ sub footer (;$) print "
\n" if $W->{"footer"}; if ($W->{"footer_mailme"}) { - print '
{"top_dir"}."/$file$ext"; + last if -r top_dir()."/$file$ext"; cluck "Class file $file not found" if !$ext; } $file.=$ext; @@ -238,11 +263,26 @@ sub footer (;$) } ( $W->{"__PACKAGE__"}, __PACKAGE__, - "WebConfig", @{$W->{"packages_used"}{$Apache::Registry::curstash}}, ))); print "

\n"; } + + for my $package ( + $W->{"__PACKAGE__"}, + __PACKAGE__, + @{$W->{"packages_used"}{$Apache::Registry::curstash}}, + ) { + my $cvs_id=(eval('$'.$package."::CVS_ID") +# || $package # debug + ); + print ''."\n" if $cvs_id; + } + + if ($W->{"heading"}) { + do { &{$_}() if $_; } for ($W->{"footing"}); + } + print "\n"; exit(0); } @@ -288,6 +328,8 @@ my($url,$contents,%args)=@_; do { $$_=1 if !defined $$_; } for (\$args{"size"}); $contents=CGI::escapeHTML($url) if !defined $contents; + $contents=~s#]*>##gi; + $contents=~s###gi; my $r='{"r"}->hostname()."/Redirect.pl?location=".uri_escape($url)); } - $r.='">'.$contents.''; - if ($args{"size"} && url_is_local($url) && $url=~/[.](?:gz|rpm|zip|deb)/) { # Downloadable? + { $r.=CGI::escapeHTML(top_dir()."/Redirect.pl?location=".uri_escape($url)); } + $r.='"'; + do { $r.=" $_" if $_; } for ($args{"attr"}); + $r.='>'.$contents.''; + if ($args{"size"} && url_is_local($url) && $url=~/[.](?:gz|Z|rpm|zip|deb|lha)/) { # Downloadable? if (!-r $url) { cluck "File not readable: $url"; } else { @@ -326,7 +370,6 @@ sub remote_ip () sub is_cz () { -print STDERR "IP=".remote_ip()."\n"; return "CZ" eq Geo::IP->new()->country_code_by_addr(remote_ip()); } @@ -373,8 +416,8 @@ my($file_base)=@_; my $file=$file_base.".".$var->{"id"}; # TODO: Somehow quickly check dependencies? system 'make >&2 -s --no-print-directory' - .' -C '."'".File::Basename::dirname($file)."' '".File::Basename::basename($file)."'"; -# if !-f $file; + .' -C '."'".File::Basename::dirname($file)."' '".File::Basename::basename($file)."'" + if !-f $file; push @nego_variants,negotiate_variant( %$var, "size"=>(stat $file)[7], @@ -393,6 +436,7 @@ my($file_base,$alt,$attrs)=@_; my $file=img_src $file_base; my($width,$height)=Image::Size::imgsize($file); + $alt=~s/<[^>]*>//g; $alt=CGI::escapeHTML($alt); return "\"$alt\""; @@ -444,9 +488,10 @@ my($class)=@_; } print ''."\n"; print ''."\n"; - print ''.CGI::escapeHTML($W->{"title_prefix"}) - .join("",map({ ': '.CGI::escapeHTML($_); } ($W->{"title"} || ()))) - .''."\n"; + my $title=$W->{"title_prefix"}.join("",map({ ': '.$_; } ($W->{"title"} || ()))); + $title=~s#<[^>]*>##g; + print ""; + print "$title\n"; if ($W->{"have_css"}) { print <<'HERE'; @@ -479,6 +524,10 @@ HERE print ' bgcolor="black" text="white" link="aqua" vlink="teal"' if $W->{"browser"}->netscape() && $W->{"browser"}->major<=4; print ">\n"; + + if ($W->{"heading"}) { + do { &{$_}() if $_; } for ($W->{"heading"}); + } } 1;