Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/web/www/routino/customvisualiser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 939 - (show annotations) (download)
Fri Dec 9 15:55:50 2011 UTC (13 years, 4 months ago) by amb
File size: 2564 byte(s)
The custom router uses the translated router.html or visualiser.html depending
on the browser's Accept-Language header.

1 #!/usr/bin/perl
2 #
3 # Routino data visualiser custom link CGI
4 #
5 # Part of the Routino routing software.
6 #
7 # This file Copyright 2008-2011 Andrew M. Bishop
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU Affero General Public License for more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 # Use the perl CGI module
24 use CGI ':cgi';
25
26 # Create the query and get the parameters
27
28 $query=new CGI;
29
30 @rawparams=$query->param;
31
32 # Legal CGI parameters with regexp validity check
33
34 %legalparams=(
35 "lon" => "[-0-9.]+",
36 "lat" => "[-0-9.]+",
37 "zoom" => "[0-9]+"
38 );
39
40 # Validate the CGI parameters, ignore invalid ones
41
42 foreach $key (@rawparams)
43 {
44 foreach $test (keys (%legalparams))
45 {
46 if($key =~ m%^$test$%)
47 {
48 $value=$query->param($key);
49
50 if($value =~ m%^$legalparams{$test}$%)
51 {
52 $cgiparams{$key}=$value;
53 last;
54 }
55 }
56 }
57 }
58
59 # Open template file and output it
60
61 $bestpref=0;
62 $bestlang="";
63
64 if(defined $ENV{HTTP_ACCEPT_LANGUAGE})
65 {
66 $LANGUAGES=$ENV{HTTP_ACCEPT_LANGUAGE};
67
68 @LANGUAGES=split(",",$LANGUAGES);
69
70 foreach $LANG (@LANGUAGES)
71 {
72 if($LANG =~ m%^([^; ]+) *; *q *= *([0-9.]+)%)
73 {
74 $LANG=$1;
75 $preference=$2;
76 }
77 else
78 {
79 $preference=1.0;
80 }
81
82 if($preference>$bestpref && -f "visualiser.html.$LANG")
83 {
84 $bestpref=$preference;
85 $bestlang=$LANG;
86 }
87 }
88 }
89
90 if($bestpref>0)
91 {
92 open(TEMPLATE,"<visualiser.html.$bestlang");
93 }
94 else
95 {
96 open(TEMPLATE,"<visualiser.html");
97 }
98
99 # Parse the template and fill in the parameters
100
101 print header('text/html');
102
103 while(<TEMPLATE>)
104 {
105 if(m%^<BODY.+>%)
106 {
107 s/'lat'/$cgiparams{'lat'}/ if(defined $cgiparams{'lat'});
108 s/'lon'/$cgiparams{'lon'}/ if(defined $cgiparams{'lon'});
109 s/'zoom'/$cgiparams{'zoom'}/ if(defined $cgiparams{'zoom'});
110 print;
111 }
112 else
113 {
114 print;
115 }
116 }
117
118 close(TEMPLATE);

Properties

Name Value
svn:executable *