Unify/simplify redirects handings by: &My::Web::http_moved
[www.jankratochvil.net.git] / project / Rel.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::Rel;
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 use Apache2::Const qw(HTTP_MOVED_PERMANENTLY);
28 Wrequire 'project::Lib';
29
30
31 our $HTML_TEST=0;
32
33 sub handler
34 {
35 my $W=My::Web->init(
36                 "args_check"=>{
37                                 "rel"=>'^(?:prev|next)$',
38                                 "project"=>'^\w+$',
39                                 },
40                 );
41
42
43 my %item=project::Lib->name_to_hashref();
44 my @platforms=@project::Lib::platforms;
45 my @projects=();
46 # Do not sort by platforms:
47 # while (@platforms)
48 {
49         my $platform_sym =shift @platforms;
50         my $platform_name=shift @platforms;
51         push @projects,sort {
52                         ($item{$b}{"priority"} <=> $item{$a}{"priority"})
53                         or
54                         (lc($item{$a}{"name"}) cmp lc($item{$b}{"name"}));
55                         }
56                                         ( # Do not sort by platform: map({ $item{$_}{"platform"} ne $platform_sym ? () : ($_); }        # )
57                                         keys(%item)
58                                         );
59         }
60 my $target=undef();
61 for (0..$#projects) {
62         next if $projects[$_] ne $W->{"args"}{"project"};
63         $target=$projects[$_-1] if $_>0          && $W->{"args"}{"rel"} eq "prev";
64         $target=$projects[$_+1] if $_<$#projects && $W->{"args"}{"rel"} eq "next";
65         last if $target;
66         }
67
68 My::Web->http_moved("./".(!$target ? "" : "$target/"),HTTP_MOVED_PERMANENTLY);
69 die "NOTREACHED";
70 }
71 1;