Finally merged the branch 'apache20'(+'apache2') back to the main trunk.
[www.jankratochvil.net.git] / project / List.pm
1 # $Id$
2 # List of projects Perl template.
3 # Copyright (C) 2003-2005 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; exactly version 2 of June 1991 is required
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19 package project::List;
20 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
21 our $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
22 our $CVS_ID=q$Id$;
23 use strict;
24 use warnings;
25
26 use My::Web;
27 Wrequire 'project::Lib';
28
29
30 sub handler
31 {
32 My::Web->init(
33                 "title"=>'Project List',
34                 "args_check"=>{
35                                 "platform"=>'^(?:platform)?$',
36                                 },
37 #               "rel_up"=>"/",  # TODO:homepage
38 #               "rel_start"=>"/",       # TODO:homepage
39                 "footer_ids"=>0,
40                 );
41 My::Web->heading();
42
43
44 print(project::Lib->views(($W->{"args"}{"platform"} ? "BriefPlatform" : "BriefUnified")));
45 print(project::Lib->platforms(undef(),"novskip"=>1)) if $W->{"args"}{"platform"};
46
47 my %item=project::Lib->name_to_hashref();
48
49 # $col{"name"}{"show"}=1
50 # $col{"name"}{"format"}=sub { "<".$_[0].">"; }
51 # $col{"name"}{""}="Project name";
52 # @col_order
53
54 my @row_order=qw(-priority);
55 my @col_order=qw(name summary license maintenance language);
56 my %col;
57
58 sub format_url ($) { return (!$_[0] ? "" : '<a href="'.$_[0].'">X</a>'); }
59
60 $col{"name"}{"format"}=sub {
61                 local $_=$_[0];
62                 s#<a\s[^>]*>([^<]*)</a>#$1#g;
63                 return "<a href=\"".$_[1]."/\">"
64                                 .(!$My::Web::W->{"args"}{"W"} ? "" : $item{$_[1]}{"priority"}.":")
65                                 .$_."</a>";
66                 };
67
68 $col{"license"}{"format"}=sub {
69                 my %known=(
70                                 "PD"=>"<a href=\"http://www.gnu.org/philosophy/categories.html#PublicDomainSoftware\">PD</a>",
71                                 "GPL"=>"<a href=\"http://www.gnu.org/licenses/gpl.html\">GPL</a>",
72                                 "LGPL"=>"<a href=\"http://www.gnu.org/licenses/lgpl.html\">LGPL</a>",
73                                 );
74                 return $known{$_[0]} if $known{$_[0]};
75                 return $_[0];
76                 };
77
78 $col{"maintenance"}{"format"}=sub {
79                 return ($_[0]=~/^([^-]*)/)[0];
80                 };
81
82 $col{"online-demo"}{"format"}=\&format_url;
83 $col{"download"}{"format"}=\&format_url;
84 $col{"name"}{""}="Project Name";
85 $col{"summary"}{""}="Abstract";
86 $col{"license"}{""}="Copying";
87 $col{"maintenance"}{""}="State";
88 $col{"language"}{""}="Language";
89
90 # Fill in cols not contained in @col_order
91 if (0) {
92         my %col_order=map(($_=>1),@col_order);
93         push @col_order,map({ ($col_order{$_} ? () : $_); } keys(%{{ map(($_=>1),map((keys(%{$item{$_}})),keys(%item)))}}));
94         }
95
96 my $print_one_platform=sub ($)
97 {
98 my($platform)=@_;
99
100         print '<table border="1">'."\n";
101                 print '<tr>';
102                         for my $col (@col_order) {
103                                 next if defined $col{$col}{"show"} && !$col{$col}{"show"};
104                                 print '<th>'.($col{$col}{""} || "[$col]").'</th>';
105                                 }
106                 print '</tr>'."\n";
107                 my @rows_ordered=sort {
108                                 for my $order_by (@row_order,"name") {
109                                         my $order_by=$order_by;
110                                         my $minus=($order_by=~s/^(-)//)[0];
111                                         # FIXME: 'cmp' or '<=>'?
112                                         # Currently it complains on "name" not <=>able if two projects have the same 'priority'.
113                                         my $r=($item{$a}{$order_by} <=> $item{$b}{$order_by});
114                                         $r=-$r if $minus;
115                                         return $r if $r;
116                                         }
117                                 return 0;
118                                 } map(($platform && $item{$_}{"platform"} ne $platform ? () : ($_)),keys(%item));
119                 for my $row (@rows_ordered) {
120                         print '<tr>';
121                         for my $col (@col_order) {
122                                 next if defined $col{$col}{"show"} && !$col{$col}{"show"};
123                                 print '<td>';
124                                 if (!$col{$col}{"format"}) {
125                                         print(($item{$row}{$col} || ""));
126                                         }
127                                 else {
128                                         print(&{$col{$col}{"format"}}($item{$row}{$col},$row));
129                                         }
130                                 print '</td>';
131                                 }
132                         print '</tr>'."\n";
133                         if ($W->{"args"}{"description_opt"}) {
134                                 print '<tr><td style="border: none;"></td>';
135                                 print '<td colspan="'.(scalar(@col_order)-1).'"><blockquote>'.$item{$row}{"description"}.'</blockquote></td>';
136                                 print '</tr>'."\n";
137                                 print '<tr><td style="border: none;" colspan="'.scalar(@col_order).'">&nbsp;</td></tr>'."\n";
138                                 }
139                         }
140         print '</table>'."\n";
141 };
142
143
144 if (!$W->{"args"}{"platform"}) {
145         &{$print_one_platform}(undef());
146         }
147 else {
148         my @platforms=@project::Lib::platforms;
149         while (@platforms) {
150                 my $platform_sym =shift @platforms;
151                 my $platform_name=shift @platforms;
152                 print '<h2 id="'.$platform_sym.'">'.$platform_name.'</h2>'."\n";
153                 &{$print_one_platform}($platform_sym);
154                 }
155         }
156
157
158 exit;
159 }
160 1;