+# $Id$
+# Common functions for HTML/XHTML output generation
+# Copyright (C) 2003 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; exactly version 2 of June 1991 is required
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+package My::Project;
+require 5.6.0; # at least 'use warnings;' but we need some 5.6.0+ modules anyway
+our $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
+our $CVS_ID=q$Id$;
+use strict;
+use warnings;
+
+use My::Web;
+
+use Exporter;
+our @EXPORT=qw();
+our @ISA=qw(My::Web Exporter);
+
+
+sub print_project ($)
+{
+my($class,$ListItem)=@_;
+
+ print "<h1>".$ListItem->{"name"}."</h1>\n";
+ print $ListItem->{"description"};
+ print "<hr />\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=a_href($_[0],CGI::escapeHTML($_[0]));
+ }
+ else {
+ $r=a_href($_[0],CGI::escapeHTML(File::Basename::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 a_href($_[0],CGI::escapeHTML($_[0]));
+ }},
+ {"key"=>"summary","text"=>"Summary"},
+ {"key"=>"ownership","text"=>"Ownership"},
+ {"key"=>"license","text"=>"License","format"=>sub ($) {
+ my %known=(
+ "PD"=>"Public Domain",
+ "GPL"=>a_href("http://www.gnu.org/licenses/gpl.html","GNU General Public License"),
+ "LGPL"=>a_href("http://www.gnu.org/licenses/lgpl.html","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 a_href("http://java.sun.com/",CGI::escapeHTML($_[0]))
+ if $_[0]=~/^Java\b/;
+ return a_href("http://www.php.net/",CGI::escapeHTML($_[0]))
+ if $_[0]=~/^PHP\b/;
+ return undef();
+ }},
+ );
+ print '<table border="0">'."\n";
+
+sub tableit_func
+{
+my($tableit,$val,$key,$ListItem)=@_;
+
+ print "<tr><td>";
+ if (!ref $tableit->{"text"}) {
+ print $tableit->{"text"};
+ }
+ else {
+ my $textfunc=$tableit->{"text"};
+ my $key=$key;
+ print &$textfunc($key);
+ }
+ print ":</td>";
+ if ($tableit->{"format"}) {
+ my $format=$tableit->{"format"};
+ my $valn=&$format($val);
+ $val=$valn if defined $valn;
+ }
+ print "<td>$val</td></tr>\n";
+ delete $ListItem->{$key};
+}
+
+ for my $tableit (@table) {
+ if (!ref $tableit->{"key"}) {
+ tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem) if $ListItem->{$tableit->{"key"}};
+ }
+ else {
+ for my $key (@{$ListItem->{"keys_array"}}) {
+ my $keyregex=$tableit->{"key"};
+ next if $key!~/$keyregex/;
+ tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
+ }
+ }
+ }
+ print "</table>\n";
+ print vskip;
+}
+
+sub project_arr_to_hash (@)
+{
+my(@arr)=@_;
+
+ return (
+ @arr,
+ "keys_array"=>[ My::Web::arr_keys(@arr) ],
+ );
+}
+
+# $args{"ListItem"}=\%...;
+sub init_project ($%)
+{
+my($class,%args)=@_;
+
+ my $ListItem={ project_arr_to_hash(@{$args{"ListItem"}}) };
+ my $name=$ListItem->{"name"};
+ $name=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
+ my $W=$class->init(
+ "title"=>$name,
+ %args);
+ $class->heading();
+ $class->print_project({ %$ListItem });
+ return $W;
+}
+
+1;