X-Git-Url: http://git.jankratochvil.net/?p=MyWeb.git;a=blobdiff_plain;f=Web.pm;h=524cf143e94cc8cfa6a8ee8df4b85b4d6e50a5ee;hp=957507fa52aa2700fee2095d8cb0b39339a1139e;hb=a76d950284c79e8e569d5c9101ad04c4f8c736ae;hpb=b04e153c27986d315a3eacae5440b2bdc554c40d
diff --git a/Web.pm b/Web.pm
index 957507f..524cf14 100644
--- a/Web.pm
+++ b/Web.pm
@@ -1,5 +1,3 @@
-#! /usr/bin/perl
-#
# $Id$
# Common functions for HTML/XHTML output generation
# Copyright (C) 2003 Jan Kratochvil You can report this problem's details to"
- ." admin of this website.".$ListItem->{"name"}."
\n";
- print $ListItem->{"description"};
- print "
\n";
- my @table=(
- {"key"=>qr(^download\b.*),"text"=>sub ($) {
- $_[0]=~s/^download//;
- $_[0]=~s/^-/ /;
- return "Download".$_[0];
- },
- "format"=>sub ($) {
- my $r;
- if ($_[0]=~m#^[a-z]+://#) {
- $r="".CGI::escapeHTML($_[0])."";
- }
- else {
- $r="".CGI::escapeHTML(basename($_[0]))."";
- my $size=(stat $_[0])[7];
- die "Cannot stat \"".$_[0]."\": $!" if !defined $size;
- if ($size>=1024*1024) { $size=int($size/(1024*1024))." MB"; }
- elsif ($size>=1024 ) { $size=int($size/(1024 ))." KB"; }
- else { $size=int($size )." B"; }
- $r.=" ($size)";
- }
- return $r;
- }},
- {"key"=>qr(^link\b.*),"text"=>sub ($) {
- $_[0]=~s/^link-//;
- return $_[0];
- },
- "format"=>sub ($) {
- return "".CGI::escapeHTML($_[0])."";
- }},
- {"key"=>"summary","text"=>"Summary"},
- {"key"=>"ownership","text"=>"Ownership"},
- {"key"=>"license","text"=>"License","format"=>sub ($) {
- my %known=(
- "PD"=>"Public Domain",
- "GPL"=>"GNU General Public License",
- "LGPL"=>"GNU Lesser General Public License",
- );
- return $known{$_[0]};
- }},
- {"key"=>"maintenance","text"=>"Currently maintained?","format"=>sub ($) {
- my %known=(
- "finished"=>"Project is finished. Possible bug reports welcome although project not actively developed.",
- "dead"=>"Project became dead code, some updates would be required. It is no longer used, project is not supported.",
- "obsolete"=>"Obsolete as some other existing package superseded this one.",
- "merge"=>"Functions of this package should be merged to some other one.",
- "update"=>"Package needs updating to be fully usable, patches welcome.",
- "accepted"=>"This patch was accepted by the original package author. It has no longer any separate meaning.",
- );
- return $known{$_[0]};
- }},
- {"key"=>"reason","text"=>"Reason"},
- {"key"=>"sponsorship","text"=>"Sponsoring Company"},
- {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
- return "".CGI::escapeHTML($_[0]).""
- if $_[0]=~/^Java\b/;
- return "".CGI::escapeHTML($_[0]).""
- if $_[0]=~/^PHP\b/;
- return undef();
- }},
- );
- print ''."\n";
+ $W->{"__PACKAGE__"}||="Apache::ROOT".$Apache::Registry::curstash;
-sub tableit_func
-{
-my($tableit,$val,$key,$ListItem)=@_;
+ $W->{"top_dir"}||=eval '$'.$W->{"__PACKAGE__"}.'::top_dir';
- print "
\n";
- print " \n";
- delete $ListItem->{$key};
+
+ do { $W->{$_}=$ENV{"HTTP_ACCEPT"} if !defined $W->{$_}; } for ("accept");
+ do { $W->{$_}=$ENV{"HTTP_USER_AGENT"} if !defined $W->{$_}; } for ("user_agent");
+
+ $W->{"browser"}=HTTP::BrowserDetect->new($W->{"user_agent"});
+
+ if (!defined $W->{"have_style"}) {
+ $W->{"have_style"}=(!$W->{"browser"}->netscape() || ($W->{"browser"}->major() && $W->{"browser"}->major()>4) ? 1 : 0);
+ }
+
+ $W->{"have_js"}=($W->{"args"}{"have_js"} ? 1 : 0);
+ if ($W->{"detect_js"} && !$W->{"have_js"}) {
+ $W->{"head"}.=''."\n";
+ }
+
+ do { args_check(%$_) if $_; } for ($W->{"args_check"});
+
+ return $W;
}
- for my $tableit (@table) {
- if (!ref $tableit->{"key"}) {
- tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem) if $ListItem->{$tableit->{"key"}};
+sub top_dir_disk ()
+{
+ do { return $_ if $_; } for ($W->{"top_dir"});
+ return $INC[0]; # fallback
+}
+
+sub top_dir (;$)
+{
+my($in)=@_;
+
+ if (my $uri=$ENV{"REQUEST_URI"}) {
+ if ($W->{"args"}{"Wabs"}) {
+ # FIXME: $in may not be defined here!
+ # to prevent: Use of uninitialized value in ...
+ if ($in=~m#^/#) {
+ $in=~s#^/*##;
+ }
+ else {
+ $in=$ENV{"REQUEST_URI"}."/".$in;
+ $in=~tr#/#/#s;
+ 1 while $in=~s#/(?:[^/]+)/\Q..\E/#/#g
+ }
+ return "http://".&{$W->{"web_hostname_sub"}}()."/".(defined $in ? $in : "");
}
- else {
- for my $key (keys(%$ListItem)) {
- my $keyregex=$tableit->{"key"};
- next if $key!~/$keyregex/;
- tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
+ $uri.="Index" if $uri=~m#/$#;
+ if (defined $in) {
+ my($inpath,$inquery)=split /[?]/,$in,2;
+ $inpath=~tr///cs;
+ $uri=~tr///cs;
+ for (;;) {
+ my($in1 ,$in2 )=($in =~m#^(/[^/]+)(/.*)$#);
+ my($uri1,$uri2)=($uri=~m#^(/[^/]+)(/.*)$#);
+ last if !defined $in1 || !defined $uri1 || $in1 ne $uri1;
+ $in=$in2;
+ $uri=$uri2;
}
}
+ $uri=~s#^/*##;
+ $uri=~s#[^/]+#..#g;
+ $uri=File::Basename::dirname($uri);
+ my $r=$uri.(defined $in ? $in : "");
+# 1 while $r=~s#^[.]/##;
+# $r="./$r" if $r=~m#^(?:?.*)$#; # empty pathname?
+ return $r;
}
- print "";
- if (!ref $tableit->{"text"}) {
- print $tableit->{"text"};
+ 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");
+ do { $W->{$_}=1 if !defined $W->{$_}; } for ("footer_ids");
+ do { $W->{$_}=1 if !defined $W->{$_}; } for ("indexme");
+ do { $W->{$_}="" if !defined $W->{$_}; } for ("head");
+ do { $W->{$_}="" if !defined $W->{$_}; } for ("head_css");
+
+ my $footer_any=0;
+ for (qw(footer_mailme footer_ids)) {
+ $W->{$_}=0 if !$W->{"footer"};
+ $footer_any=1 if $W->{$_};
}
- else {
- my $textfunc=$tableit->{"text"};
- my $key=$key;
- print &$textfunc($key);
+ $W->{"footer"}=0 if !$footer_any;
+ $W->{"footer_delimit"}=0 if !$W->{"footer"};
+
+ $W->{"r"}=Apache->request();
+
+ $W->{"QUERY_STRING"}=$W->{"r"}->args() || "";
+ if ($W->{"QUERY_STRING"}=~/[&]amp;have_ent/)
+ { $W->{"have_ent"}=0; }
+ elsif ($W->{"QUERY_STRING"}=~ /[&]have_ent/)
+ { $W->{"have_ent"}=1; }
+ else
+ { delete $W->{"have_ent"}; }
+ if ($W->{"detect_ent"} && !defined $W->{"have_ent"} && $W->{"r"}->method() eq "GET") {
+ $W->{"head"}.='{"web_hostname_sub"}}()."/".($W->{"r"}->uri()=~m#^/*(.*)$#)[0]
+ ."?".($W->{"QUERY_STRING"} || "detect_ent_glue=1").'&have_ent=detect')
+ .'" />'."\n";
}
- print ": ";
- if ($tableit->{"format"}) {
- my $format=$tableit->{"format"};
- my $valn=&$format($val);
- $val=$valn if defined $valn;
+ $W->{"QUERY_STRING"}=~s/([&])amp;/$1/g;
+ $W->{"r"}->args($W->{"QUERY_STRING"});
+ $ENV{"QUERY_STRING"}=$W->{"QUERY_STRING"};
+ # Do not: $W->{"r"}->args()
+ # as it parses only QUERY_STRING (not POST data).
+ $W->{"args"}={ CGI->new()->Vars() };
+ for (keys(%{$W->{"args"}})) {
+ my @vals=split /\x00/,$W->{"args"}{$_};
+ next if @vals<=1;
+ $W->{"args"}{$_}=[@vals];
}
- print "$val
FATAL ERROR: $msg!
\n"
+ $W->{"indexme"}=0; # For the case no heading was sent yet.
+ My::Web->heading();
+ print "\n".vskip("3ex")."FATAL ERROR: $msg!
\n"
."
';
+ print join("
\n",map({ my $package=$_;
+ my $cvs_id=(eval('$'.$package."::CVS_ID")
+# || $package # debug
+ );
+ if (!$cvs_id) {
+ ();
+ }
+ else {
+ $cvs_id='$'.$cvs_id.'$'; # Eaten by 'q' operator.
+ my @cvs_id_split=split / +/,$cvs_id;
+ if (@cvs_id_split==8) {
+ my $file=$package;
+ $file=~s#::#/#g;
+ my $ext;
+ for (qw(.html.pl .pl .pm),"") {
+ $ext=$_;
+ last if -r top_dir_disk()."/$file$ext";
+ cluck "Class file $file not found" if !$ext;
+ }
+ $file.=$ext;
+ $cvs_id_split[2]=""
+ .a_href((map({ my $s=$_; $s=~s#/viewcvs/#$&~checkout~/#; $s; } $W->{"viewcvs"}))[0]."$file?rev=".$cvs_id_split[2],
+ $cvs_id_split[2]);
+ # FIXME: Use 'CVS/Repository' here.
+ my $viewcvs=$W->{"viewcvs"};
+ $viewcvs=~s#(/viewcvs)/.*$#$1/MyWeb/# if $file=~s#^My/##;
+ $cvs_id_split[1]=a_href($viewcvs.$file,
+ ($package!~/^Apache::/ ? $package : $cvs_id_split[1]));
+ $cvs_id_split[5]=&{$W->{"cvs_id_author"}}($cvs_id_split[5]);
+ }
+ join " ",@cvs_id_split;
+ }
+ } (
+ $W->{"__PACKAGE__"},
+ __PACKAGE__,
+ @{$W->{"packages_used"}{$Apache::Registry::curstash}},
+ )));
+ print "
\n" if $delimit; - print "
$cvs_id_html
\n"; + if ($W->{"heading"}) { + do { &{$_}() if $_; } for ($W->{"footing"}); } + print "