line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenGuides::Template; |
2
|
|
|
|
|
|
|
|
3
|
92
|
|
|
92
|
|
27618
|
use strict; |
|
92
|
|
|
|
|
167
|
|
|
92
|
|
|
|
|
2668
|
|
4
|
92
|
|
|
92
|
|
463
|
use vars qw( $VERSION ); |
|
92
|
|
|
|
|
190
|
|
|
92
|
|
|
|
|
4480
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.20'; |
6
|
|
|
|
|
|
|
|
7
|
92
|
|
|
92
|
|
484
|
use Carp qw( croak ); |
|
92
|
|
|
|
|
161
|
|
|
92
|
|
|
|
|
4450
|
|
8
|
92
|
|
|
92
|
|
1744
|
use CGI; # want to get rid of this and put the burden on the templates |
|
92
|
|
|
|
|
32690
|
|
|
92
|
|
|
|
|
778
|
|
9
|
92
|
|
|
92
|
|
19085
|
use OpenGuides; # for $VERSION for template variable |
|
92
|
|
|
|
|
201
|
|
|
92
|
|
|
|
|
2758
|
|
10
|
92
|
|
|
92
|
|
568
|
use OpenGuides::CGI; |
|
92
|
|
|
|
|
169
|
|
|
92
|
|
|
|
|
2179
|
|
11
|
92
|
|
|
92
|
|
77773
|
use Template; |
|
92
|
|
|
|
|
2014680
|
|
|
92
|
|
|
|
|
2921
|
|
12
|
92
|
|
|
92
|
|
692
|
use URI::Escape; |
|
92
|
|
|
|
|
175
|
|
|
92
|
|
|
|
|
5809
|
|
13
|
92
|
|
|
92
|
|
64221
|
use Data::Validate::URI qw( is_web_uri ); |
|
92
|
|
|
|
|
4402607
|
|
|
92
|
|
|
|
|
292899
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
OpenGuides::Template - Do Template Toolkit related stuff for OpenGuides applications. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Does all the Template Toolkit stuff for OpenGuides. Distributed and |
22
|
|
|
|
|
|
|
installed as part of the OpenGuides project, not intended for |
23
|
|
|
|
|
|
|
independent installation. This documentation is probably only useful |
24
|
|
|
|
|
|
|
to OpenGuides developers. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use OpenGuides::Config; |
29
|
|
|
|
|
|
|
use OpenGuides::Utils; |
30
|
|
|
|
|
|
|
use OpenGuides::Template; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $config = OpenGuides::Config->new( file => "wiki.conf" ); |
33
|
|
|
|
|
|
|
my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
print OpenGuides::Template->output( wiki => $wiki, |
36
|
|
|
|
|
|
|
config => $config, |
37
|
|
|
|
|
|
|
template => "node.tt", |
38
|
|
|
|
|
|
|
vars => { foo => "bar" } |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item B |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
print OpenGuides::Template->output( wiki => $wiki, |
48
|
|
|
|
|
|
|
config => $config, |
49
|
|
|
|
|
|
|
template => "node.tt", |
50
|
|
|
|
|
|
|
content_type => "text/html", |
51
|
|
|
|
|
|
|
cookies => $cookie, |
52
|
|
|
|
|
|
|
vars => {foo => "bar"}, |
53
|
|
|
|
|
|
|
noheaders => 1 |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Returns everything you need to send to STDOUT, including the |
57
|
|
|
|
|
|
|
Content-Type: header. Croaks unless C is supplied. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The config object and variables supplied in C are passed through |
60
|
|
|
|
|
|
|
to the template specified. Additional Template Toolkit variables are |
61
|
|
|
|
|
|
|
automatically set and passed through as well, as described below. |
62
|
|
|
|
|
|
|
B variables set in C will over-ride any variables of the |
63
|
|
|
|
|
|
|
same name in the config object or the user cookies. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=over |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * C |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item * C |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item * C |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item * C |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item * C (gets set to true or false - defaults to false) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * C |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * C |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * C |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item * C (unless C is set in user cookie) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * C |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * C |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * C |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * C |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * C |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * C |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * C (the preferences from the user cookie) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=back |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
If C is supplied: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * C |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * C (the node name escaped for use in URLs) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Content-Type: defaults to C and is omitted if the |
112
|
|
|
|
|
|
|
C arg is explicitly set to the blank string. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
However, what you more often need is the C option, |
115
|
|
|
|
|
|
|
which suppresses all HTTP headers, not just the Content-Type. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The HTTP response code may be explictly set with the C arg. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub output { |
122
|
256
|
|
|
256
|
1
|
22134
|
my ($class, %args) = @_; |
123
|
256
|
100
|
|
|
|
1361
|
croak "No template supplied" unless $args{template}; |
124
|
255
|
50
|
|
|
|
1133
|
my $config = $args{config} or croak "No config supplied"; |
125
|
255
|
|
|
|
|
1343
|
my $template_path = $config->template_path; |
126
|
255
|
|
100
|
|
|
3455
|
my $custom_template_path = $config->custom_template_path || ""; |
127
|
255
|
|
|
|
|
6049
|
my $tt = Template->new( |
128
|
|
|
|
|
|
|
{ INCLUDE_PATH => "$custom_template_path:$template_path" } ); |
129
|
|
|
|
|
|
|
|
130
|
255
|
|
|
|
|
831960
|
my $script_name = $config->script_name; |
131
|
255
|
|
|
|
|
3731
|
my $script_url = $config->script_url; |
132
|
255
|
|
|
|
|
1159
|
my $default_city = $config->default_city; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Check cookie to see if we need to set the formatting_rules_link. |
135
|
255
|
|
|
|
|
2398
|
my ($formatting_rules_link, $omit_help_links); |
136
|
255
|
|
|
|
|
1200
|
my $formatting_rules_node = $config->formatting_rules_node; |
137
|
255
|
|
|
|
|
2889
|
$formatting_rules_link = $config->formatting_rules_link; |
138
|
|
|
|
|
|
|
my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie( |
139
|
|
|
|
|
|
|
config => $config, |
140
|
|
|
|
|
|
|
cookies => $args{cookies}, |
141
|
255
|
|
|
|
|
4015
|
); |
142
|
255
|
100
|
|
|
|
1547
|
if ( $cookie_data{omit_help_links} ) { |
143
|
14
|
|
|
|
|
32
|
$omit_help_links = 1; |
144
|
|
|
|
|
|
|
} else { |
145
|
241
|
100
|
66
|
|
|
1834
|
if (( $formatting_rules_node ) and !( $formatting_rules_link )){ |
146
|
|
|
|
|
|
|
$formatting_rules_link = $script_url . $script_name . "?" |
147
|
8
|
|
|
|
|
50
|
. uri_escape($args{wiki}->formatter->node_name_to_node_param($formatting_rules_node)); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
255
|
|
|
|
|
832
|
my $enable_page_deletion = 0; |
152
|
255
|
100
|
100
|
|
|
1160
|
if ( $config->enable_page_deletion |
|
|
|
66
|
|
|
|
|
153
|
|
|
|
|
|
|
and ( lc($config->enable_page_deletion) eq "y" |
154
|
|
|
|
|
|
|
or $config->enable_page_deletion eq "1" ) |
155
|
|
|
|
|
|
|
) { |
156
|
8
|
|
|
|
|
273
|
$enable_page_deletion = 1; |
157
|
|
|
|
|
|
|
} |
158
|
255
|
|
|
|
|
3072
|
my $is_admin = 0; |
159
|
255
|
100
|
|
|
|
1000
|
if ( $cookie_data{is_admin} ) { |
160
|
17
|
|
|
|
|
31
|
$is_admin = 1; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
255
|
|
|
|
|
1049
|
my $tt_vars = { |
164
|
|
|
|
|
|
|
config => $config, |
165
|
|
|
|
|
|
|
prefs => \%cookie_data, |
166
|
|
|
|
|
|
|
site_name => $config->site_name, |
167
|
|
|
|
|
|
|
cgi_url => $script_name, |
168
|
|
|
|
|
|
|
script_url => $script_url, |
169
|
|
|
|
|
|
|
full_cgi_url => $script_url . $script_name, |
170
|
|
|
|
|
|
|
contact_email => $config->contact_email, |
171
|
|
|
|
|
|
|
stylesheet => $config->stylesheet_url, |
172
|
|
|
|
|
|
|
home_link => $script_url . $script_name, |
173
|
|
|
|
|
|
|
home_name => $config->home_name, |
174
|
|
|
|
|
|
|
navbar_on_home_page => $config->navbar_on_home_page, |
175
|
|
|
|
|
|
|
omit_help_links => $omit_help_links, |
176
|
|
|
|
|
|
|
is_admin => $is_admin, |
177
|
|
|
|
|
|
|
formatting_rules_link => $formatting_rules_link, |
178
|
|
|
|
|
|
|
formatting_rules_node => $formatting_rules_node, |
179
|
|
|
|
|
|
|
openguides_version => $OpenGuides::VERSION, |
180
|
|
|
|
|
|
|
enable_page_deletion => $enable_page_deletion, |
181
|
|
|
|
|
|
|
language => $config->default_language, |
182
|
|
|
|
|
|
|
http_charset => $config->http_charset, |
183
|
|
|
|
|
|
|
default_city => $default_city, |
184
|
|
|
|
|
|
|
gmaps_api_key => $config->gmaps_api_key, |
185
|
|
|
|
|
|
|
licence_name => $config->licence_name, |
186
|
|
|
|
|
|
|
licence_url => $config->licence_url, |
187
|
|
|
|
|
|
|
licence_info_url => $config->licence_info_url |
188
|
|
|
|
|
|
|
}; |
189
|
|
|
|
|
|
|
|
190
|
255
|
100
|
|
|
|
25091
|
if ($args{node}) { |
191
|
143
|
|
|
|
|
1063
|
$tt_vars->{node_name} = CGI->escapeHTML($args{node}); |
192
|
143
|
|
|
|
|
15529
|
$tt_vars->{node_param} = CGI->escape($args{wiki}->formatter->node_name_to_node_param($args{node})); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# Now set further TT variables if explicitly supplied - do this after the |
196
|
|
|
|
|
|
|
# above auto-setting as these override auto-set ones. |
197
|
255
|
100
|
|
|
|
8372
|
$tt_vars = { %$tt_vars, %{ $args{vars} || {} } }; |
|
255
|
|
|
|
|
6765
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Finally, dig out the username from the cookie if we haven't already |
200
|
|
|
|
|
|
|
# been sent it in vars. |
201
|
255
|
100
|
|
|
|
2741
|
if ( !$tt_vars->{username} ) { |
202
|
249
|
|
|
|
|
1131
|
my %prefs = OpenGuides::CGI->get_prefs_from_cookie(config => $config); |
203
|
|
|
|
|
|
|
# If there's nothing in there, it defaults to "Anonymous". |
204
|
249
|
100
|
|
|
|
1743
|
if ( $prefs{username} ne "Anonymous" ) { |
205
|
45
|
|
|
|
|
247
|
$tt_vars->{username} = $prefs{username}; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
255
|
|
|
|
|
543
|
my $header = ""; |
210
|
|
|
|
|
|
|
|
211
|
255
|
100
|
|
|
|
1065
|
unless ( $args{noheaders} ) { |
212
|
187
|
|
|
|
|
320
|
my %cgi_header_args; |
213
|
|
|
|
|
|
|
|
214
|
187
|
100
|
100
|
|
|
900
|
if ( defined $args{content_type} and $args{content_type} eq "" ) { |
215
|
1
|
|
|
|
|
3
|
$cgi_header_args{'-type'} = ''; |
216
|
|
|
|
|
|
|
} else { |
217
|
186
|
100
|
|
|
|
569
|
if ( $args{content_type} ) { |
218
|
4
|
|
|
|
|
12
|
$cgi_header_args{'-type'} = $args{content_type}; |
219
|
|
|
|
|
|
|
} else { |
220
|
182
|
|
|
|
|
570
|
$cgi_header_args{'-type'} = "text/html"; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
187
|
100
|
|
|
|
697
|
if ( $tt_vars->{http_charset} ) { |
225
|
2
|
|
|
|
|
8
|
$cgi_header_args{'-type'} .= "; charset=".$tt_vars->{http_charset}; |
226
|
|
|
|
|
|
|
} |
227
|
187
|
|
|
|
|
474
|
$cgi_header_args{'-cookie'} = $args{cookies}; |
228
|
|
|
|
|
|
|
|
229
|
187
|
100
|
|
|
|
553
|
if ( $args{http_status} ) { |
230
|
8
|
|
|
|
|
20
|
$cgi_header_args{'-status'} = $args{http_status}; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
187
|
|
|
|
|
1166
|
$header = CGI::header( %cgi_header_args ); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
# vile hack |
237
|
|
|
|
|
|
|
my %field_vars = OpenGuides::Template->extract_metadata_vars( |
238
|
|
|
|
|
|
|
wiki => $args{wiki}, |
239
|
255
|
|
|
|
|
60337
|
config => $config, |
240
|
|
|
|
|
|
|
set_coord_field_vars => 1, |
241
|
|
|
|
|
|
|
metadata => {}, |
242
|
|
|
|
|
|
|
); |
243
|
|
|
|
|
|
|
|
244
|
255
|
|
|
|
|
9142
|
$tt_vars = { %field_vars, %$tt_vars }; |
245
|
|
|
|
|
|
|
|
246
|
255
|
|
|
|
|
2818
|
my $output; |
247
|
255
|
|
|
|
|
1678
|
$tt->process( $args{template}, $tt_vars, \$output ); |
248
|
|
|
|
|
|
|
|
249
|
255
|
|
|
|
|
198518
|
my $contact_email = $config->contact_email; |
250
|
|
|
|
|
|
|
|
251
|
255
|
|
66
|
|
|
3312
|
$output ||= qq(ERROR |
252
|
|
|
|
|
|
|
Sorry! Something went wrong. Please contact the site administrator |
253
|
|
|
|
|
|
|
at $contact_email and quote the |
254
|
|
|
|
|
|
|
following error message:Failed to process template: ) |
255
|
|
|
|
|
|
|
. $tt->error |
256
|
|
|
|
|
|
|
. qq(); |
257
|
|
|
|
|
|
|
|
258
|
255
|
|
|
|
|
10406
|
return $header . $output; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item B |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
my %node_data = $wiki->retrieve_node( "Home Page" ); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
my %metadata_vars = OpenGuides::Template->extract_metadata_vars( |
266
|
|
|
|
|
|
|
wiki => $wiki, |
267
|
|
|
|
|
|
|
config => $config, |
268
|
|
|
|
|
|
|
metadata => $node_data{metadata} |
269
|
|
|
|
|
|
|
); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# -- or -- |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
my %metadata_vars = OpenGuides::Template->extract_metadata_vars( |
274
|
|
|
|
|
|
|
wiki => $wiki, |
275
|
|
|
|
|
|
|
config => $config, |
276
|
|
|
|
|
|
|
cgi_obj => $q |
277
|
|
|
|
|
|
|
); |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
# -- then -- |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
print OpenGuides::Template->output( |
282
|
|
|
|
|
|
|
wiki => $wiki, |
283
|
|
|
|
|
|
|
config => $config, |
284
|
|
|
|
|
|
|
template => "node.tt", |
285
|
|
|
|
|
|
|
vars => { foo => "bar", |
286
|
|
|
|
|
|
|
%metadata_vars } |
287
|
|
|
|
|
|
|
); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Picks out things like categories, locales, phone number etc from |
290
|
|
|
|
|
|
|
EITHER the metadata hash returned by L OR the query |
291
|
|
|
|
|
|
|
parameters in a L object, and packages them nicely for passing to |
292
|
|
|
|
|
|
|
templates or storing in L datastore. If you supply both |
293
|
|
|
|
|
|
|
C and C then C will take precedence, but |
294
|
|
|
|
|
|
|
don't do that. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
The variables C, C, C, |
297
|
|
|
|
|
|
|
C, C, C, and |
298
|
|
|
|
|
|
|
C, which are used to create various forms, will |
299
|
|
|
|
|
|
|
only be set if I C is supplied I |
300
|
|
|
|
|
|
|
C is true, to prevent these values from being |
301
|
|
|
|
|
|
|
stored in the database on a node commit. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=cut |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub extract_metadata_vars { |
306
|
730
|
|
|
730
|
1
|
10399
|
my ($class, %args) = @_; |
307
|
730
|
100
|
|
|
|
1342
|
my %metadata = %{$args{metadata} || {} }; |
|
730
|
|
|
|
|
5630
|
|
308
|
730
|
|
|
|
|
2022
|
my $q = $args{cgi_obj}; |
309
|
730
|
|
|
|
|
1512
|
my $wiki = $args{wiki}; |
310
|
730
|
|
|
|
|
2910
|
my $formatter = $wiki->formatter; |
311
|
730
|
|
|
|
|
3756
|
my $config = $args{config}; |
312
|
730
|
|
|
|
|
2871
|
my $script_name = $config->script_name; |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# Categories and locales are displayed as links in the page footer. |
315
|
|
|
|
|
|
|
# We return these twice, as eg 'category' being a simple array of |
316
|
|
|
|
|
|
|
# category names, but 'categories' being an array of hashrefs including |
317
|
|
|
|
|
|
|
# a URL too. This is ick. |
318
|
730
|
|
|
|
|
7481
|
my (@catlist, @loclist); |
319
|
730
|
100
|
|
|
|
2421
|
if ( $args{metadata} ) { |
320
|
371
|
100
|
|
|
|
680
|
@catlist = sort @{ $metadata{category} || [] }; |
|
371
|
|
|
|
|
2627
|
|
321
|
371
|
100
|
|
|
|
769
|
@loclist = sort @{ $metadata{locale} || [] }; |
|
371
|
|
|
|
|
7843
|
|
322
|
|
|
|
|
|
|
} else { |
323
|
359
|
|
|
|
|
1305
|
my $categories_text = $q->param('categories'); |
324
|
359
|
|
|
|
|
8311
|
my $locales_text = $q->param('locales'); |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# Basic sanity-checking. Probably lives elsewhere. |
327
|
359
|
|
|
|
|
7429
|
foreach ( $categories_text, $locales_text ) { |
328
|
718
|
|
|
|
|
1230
|
s/</g; |
329
|
718
|
|
|
|
|
1375
|
s/>/>/g; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
# Trim leading and trailing spaces, collapse internal whitespace. |
333
|
359
|
|
|
|
|
1644
|
@catlist = sort grep { s/^\s+//; s/\s+$//; s/\s+/ /g; $_; } |
|
114
|
|
|
|
|
355
|
|
|
114
|
|
|
|
|
296
|
|
|
114
|
|
|
|
|
346
|
|
|
114
|
|
|
|
|
545
|
|
334
|
|
|
|
|
|
|
split("\r\n", $categories_text); |
335
|
359
|
|
|
|
|
1434
|
@loclist = sort grep { s/^\s+//; s/\s+$//; s/\s+/ /g; $_; } |
|
56
|
|
|
|
|
187
|
|
|
56
|
|
|
|
|
147
|
|
|
56
|
|
|
|
|
151
|
|
|
56
|
|
|
|
|
221
|
|
336
|
|
|
|
|
|
|
split("\r\n", $locales_text); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# Some stuff here is copied from OpenGuides->_autoCreateCategoryLocale |
340
|
|
|
|
|
|
|
# - we should rationalise this. |
341
|
|
|
|
|
|
|
my @categories = map { |
342
|
730
|
|
|
|
|
1940
|
my $param = $formatter->node_name_to_node_param( $_ ); |
|
144
|
|
|
|
|
21454
|
|
343
|
144
|
|
|
|
|
3849
|
my $name = $_; |
344
|
144
|
|
|
|
|
1113
|
$name =~ s/(.*)/\u$1/; |
345
|
144
|
|
|
|
|
521
|
$name = $wiki->formatter->_do_freeupper( "Category $name" ); |
346
|
|
|
|
|
|
|
{ |
347
|
144
|
100
|
|
|
|
2055
|
name => $_, |
348
|
|
|
|
|
|
|
url => $wiki->node_exists( $name ) |
349
|
|
|
|
|
|
|
? "$script_name?Category_" . uri_escape( $param ) |
350
|
|
|
|
|
|
|
: "", |
351
|
|
|
|
|
|
|
}; |
352
|
|
|
|
|
|
|
} @catlist; |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
my @locales = map { |
355
|
730
|
|
|
|
|
101277
|
my $param = $formatter->node_name_to_node_param( $_ ); |
|
85
|
|
|
|
|
16150
|
|
356
|
85
|
|
|
|
|
2042
|
my $name = $_; |
357
|
85
|
|
|
|
|
666
|
$name =~ s/(.*)/\u$1/; |
358
|
85
|
|
|
|
|
329
|
$name = $wiki->formatter->_do_freeupper( "Locale $name" ); |
359
|
|
|
|
|
|
|
{ |
360
|
85
|
100
|
|
|
|
1296
|
name => $_, |
361
|
|
|
|
|
|
|
url => $wiki->node_exists( $name ) |
362
|
|
|
|
|
|
|
? "$script_name?Locale_" . uri_escape( $param ) |
363
|
|
|
|
|
|
|
: "", |
364
|
|
|
|
|
|
|
}; |
365
|
|
|
|
|
|
|
} @loclist; |
366
|
|
|
|
|
|
|
|
367
|
730
|
100
|
|
|
|
49966
|
my $website = $args{metadata} ? $metadata{website}[0] |
368
|
|
|
|
|
|
|
: $q->param("website"); |
369
|
|
|
|
|
|
|
# Do truncation for website name display. Max length of field is set in |
370
|
|
|
|
|
|
|
# conf file (website_link_max_chars). Leading http:// and www. if present |
371
|
|
|
|
|
|
|
# is stripped; trailing / is also stripped if it's the only / in the URL. |
372
|
730
|
|
|
|
|
8639
|
my $formatted_website_text = ""; |
373
|
730
|
50
|
66
|
|
|
3402
|
if ( $website && $website ne "http://" && is_web_uri( $website ) ) { |
|
|
|
66
|
|
|
|
|
374
|
13
|
|
|
|
|
13278
|
my $maxlen = $config->website_link_max_chars; |
375
|
13
|
|
|
|
|
140
|
my $trunc_website = $website; |
376
|
13
|
|
|
|
|
81
|
$trunc_website =~ s|http://(www.)?||; |
377
|
13
|
100
|
|
|
|
69
|
if ( $trunc_website =~ tr|/|| == 1 ) { |
378
|
6
|
|
|
|
|
19
|
$trunc_website =~ s|/$||; |
379
|
|
|
|
|
|
|
} |
380
|
13
|
100
|
|
|
|
45
|
if ( length( $trunc_website ) > $maxlen ) { |
381
|
2
|
|
|
|
|
8
|
$trunc_website = substr( $trunc_website, 0, $maxlen - 3 ) . "..."; |
382
|
|
|
|
|
|
|
} |
383
|
13
|
|
|
|
|
61
|
$formatted_website_text = '' |
384
|
|
|
|
|
|
|
. $trunc_website . ''; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
730
|
100
|
|
|
|
3360
|
my $hours_text = $args{metadata} ? $metadata{opening_hours_text}[0] |
388
|
|
|
|
|
|
|
: $q->param("hours_text"); |
389
|
|
|
|
|
|
|
|
390
|
730
|
100
|
|
|
|
9798
|
my $summary = $args{metadata} ? $metadata{summary}[0] |
391
|
|
|
|
|
|
|
: $q->param("summary"); |
392
|
|
|
|
|
|
|
|
393
|
730
|
|
|
|
|
12581
|
my %vars = ( |
394
|
|
|
|
|
|
|
categories => \@categories, |
395
|
|
|
|
|
|
|
locales => \@locales, |
396
|
|
|
|
|
|
|
category => \@catlist, |
397
|
|
|
|
|
|
|
locale => \@loclist, |
398
|
|
|
|
|
|
|
formatted_website_text => $formatted_website_text, |
399
|
|
|
|
|
|
|
hours_text => $hours_text, |
400
|
|
|
|
|
|
|
summary => $summary, |
401
|
|
|
|
|
|
|
); |
402
|
|
|
|
|
|
|
|
403
|
730
|
100
|
|
|
|
5146
|
if ($config->enable_node_image ) { |
404
|
728
|
|
|
|
|
8735
|
foreach my $key ( qw( node_image node_image_licence node_image_url |
405
|
|
|
|
|
|
|
node_image_copyright ) ) { |
406
|
2912
|
100
|
|
|
|
10015
|
my $value = $args{metadata} ? $metadata{$key}[0] |
407
|
|
|
|
|
|
|
: $q->param( $key ); |
408
|
2912
|
100
|
|
|
|
32698
|
if ( $value ) { |
409
|
37
|
|
|
|
|
104
|
$value =~ s/^\s+//g; |
410
|
37
|
|
|
|
|
104
|
$value =~ s/\s+$//g; |
411
|
|
|
|
|
|
|
} |
412
|
2912
|
100
|
|
|
|
9489
|
$vars{$key} = $value if $value; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
730
|
100
|
|
|
|
2385
|
if (exists $metadata{source}) { |
417
|
1
|
|
|
|
|
13
|
($vars{source_site}) = $metadata{source}[0] =~ /^(.*?)(?:\?|$)/; |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
|
420
|
730
|
100
|
|
|
|
2043
|
if ( $args{metadata} ) { |
421
|
371
|
|
|
|
|
969
|
foreach my $var ( qw( phone fax address postcode os_x os_y osie_x |
422
|
|
|
|
|
|
|
osie_y latitude longitude map_link website |
423
|
|
|
|
|
|
|
summary) ) { |
424
|
4823
|
|
|
|
|
10967
|
$vars{$var} = $metadata{$var}[0]; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
# Data for the distance search forms on the node display. |
427
|
371
|
|
|
|
|
1473
|
my $geo_handler = $config->geo_handler; |
428
|
371
|
100
|
|
|
|
3880
|
if ( $geo_handler == 1 ) { |
|
|
100
|
|
|
|
|
|
429
|
|
|
|
|
|
|
%vars = ( |
430
|
|
|
|
|
|
|
%vars, |
431
|
|
|
|
|
|
|
coord_field_1 => "os_x", |
432
|
|
|
|
|
|
|
coord_field_2 => "os_y", |
433
|
|
|
|
|
|
|
dist_field => "os_dist", |
434
|
|
|
|
|
|
|
coord_field_1_name => "OS X coordinate", |
435
|
|
|
|
|
|
|
coord_field_2_name => "OS Y coordinate", |
436
|
|
|
|
|
|
|
coord_field_1_value => $metadata{os_x}[0], |
437
|
341
|
|
|
|
|
7406
|
coord_field_2_value => $metadata{os_y}[0], |
438
|
|
|
|
|
|
|
); |
439
|
|
|
|
|
|
|
} elsif ( $geo_handler == 2 ) { |
440
|
|
|
|
|
|
|
%vars = ( |
441
|
|
|
|
|
|
|
%vars, |
442
|
|
|
|
|
|
|
coord_field_1 => "osie_x", |
443
|
|
|
|
|
|
|
coord_field_2 => "osie_y", |
444
|
|
|
|
|
|
|
dist_field => "osie_dist", |
445
|
|
|
|
|
|
|
coord_field_1_name |
446
|
|
|
|
|
|
|
=> "Irish National Grid X coordinate", |
447
|
|
|
|
|
|
|
coord_field_2_name |
448
|
|
|
|
|
|
|
=>"Irish National Grid Y coordinate", |
449
|
|
|
|
|
|
|
coord_field_1_value => $metadata{osie_x}[0], |
450
|
11
|
|
|
|
|
258
|
coord_field_2_value => $metadata{osie_y}[0], |
451
|
|
|
|
|
|
|
); |
452
|
|
|
|
|
|
|
} else { |
453
|
19
|
|
|
|
|
81
|
my $lat_text = "Latitude (" . $config->ellipsoid . " decimal)"; |
454
|
19
|
|
|
|
|
227
|
my $long_text = "Longitude (" . $config->ellipsoid . " decimal)"; |
455
|
|
|
|
|
|
|
%vars = ( |
456
|
|
|
|
|
|
|
%vars, |
457
|
|
|
|
|
|
|
coord_field_1 => "latitude", |
458
|
|
|
|
|
|
|
coord_field_2 => "longitude", |
459
|
|
|
|
|
|
|
dist_field => "latlong_dist", |
460
|
|
|
|
|
|
|
coord_field_1_name => $lat_text, |
461
|
|
|
|
|
|
|
coord_field_2_name => $long_text, |
462
|
|
|
|
|
|
|
coord_field_1_value => $metadata{latitude}[0], |
463
|
19
|
|
|
|
|
579
|
coord_field_2_value => $metadata{longitude}[0], |
464
|
|
|
|
|
|
|
); |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
} else { |
467
|
359
|
|
|
|
|
1046
|
foreach my $var ( qw( phone fax address postcode map_link website |
468
|
|
|
|
|
|
|
summary) ) { |
469
|
2513
|
|
|
|
|
46695
|
$vars{$var} = $q->param($var); |
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
# Trim leading and trailing whitespace from the fax field - some |
473
|
|
|
|
|
|
|
# guides use this to store the Twitter username, so whitespace will |
474
|
|
|
|
|
|
|
# mess things up when this is turned into a URL. |
475
|
359
|
|
|
|
|
7436
|
$vars{fax} =~ s/^\s+//g; |
476
|
359
|
|
|
|
|
868
|
$vars{fax} =~ s/\s+$//g; |
477
|
|
|
|
|
|
|
|
478
|
359
|
|
|
|
|
1566
|
my $geo_handler = $config->geo_handler; |
479
|
359
|
100
|
|
|
|
4174
|
if ( $geo_handler == 1 ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
480
|
233
|
|
|
|
|
72416
|
require Geo::Coordinates::OSGB; |
481
|
|
|
|
|
|
|
|
482
|
233
|
|
|
|
|
4119185
|
my $os_x = $q->param("os_x"); |
483
|
233
|
|
|
|
|
6501
|
my $os_y = $q->param("os_y"); |
484
|
233
|
|
|
|
|
5141
|
my $lat = $q->param("latitude"); |
485
|
233
|
|
|
|
|
4825
|
my $long = $q->param("longitude"); |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
# Trim whitespace - trailing whitespace buggers up the |
488
|
|
|
|
|
|
|
# integerification by postgres and it's an easy mistake to |
489
|
|
|
|
|
|
|
# make when typing into a form. |
490
|
233
|
|
|
|
|
4683
|
$os_x =~ s/\s+//g; |
491
|
233
|
|
|
|
|
604
|
$os_y =~ s/\s+//g; |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
# If we were sent x and y, work out lat/long; and vice versa. |
494
|
233
|
100
|
66
|
|
|
4736
|
if ( defined $os_x && length $os_x |
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
495
|
|
|
|
|
|
|
&& defined $os_y && length $os_y ) { |
496
|
63
|
|
|
|
|
331
|
( $lat, $long ) = Geo::Coordinates::OSGB::grid_to_ll( |
497
|
|
|
|
|
|
|
$os_x, $os_y ); |
498
|
63
|
|
|
|
|
8348
|
$lat = sprintf( "%.6f", $lat ); |
499
|
63
|
|
|
|
|
398
|
$long = sprintf( "%.6f", $long ); |
500
|
|
|
|
|
|
|
} elsif ( defined $lat && length $lat |
501
|
|
|
|
|
|
|
&& defined $long && length $long ) { |
502
|
17
|
|
|
|
|
97
|
( $os_x, $os_y ) = Geo::Coordinates::OSGB::ll_to_grid( |
503
|
|
|
|
|
|
|
$lat, $long ); |
504
|
17
|
|
|
|
|
2028
|
$os_x = sprintf( "%d", $os_x ); |
505
|
17
|
|
|
|
|
67
|
$os_y = sprintf( "%d", $os_y ); |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
233
|
100
|
66
|
|
|
2193
|
if ( defined $os_x && length $os_x |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
509
|
|
|
|
|
|
|
&& defined $os_y && length $os_y ) { |
510
|
80
|
|
|
|
|
1426
|
%vars = ( |
511
|
|
|
|
|
|
|
%vars, |
512
|
|
|
|
|
|
|
latitude => $lat, |
513
|
|
|
|
|
|
|
longitude => $long, |
514
|
|
|
|
|
|
|
os_x => $os_x, |
515
|
|
|
|
|
|
|
os_y => $os_y, |
516
|
|
|
|
|
|
|
); |
517
|
|
|
|
|
|
|
} |
518
|
233
|
100
|
|
|
|
1392
|
if ( $args{set_coord_field_vars} ) { |
519
|
1
|
|
|
|
|
31
|
%vars = ( |
520
|
|
|
|
|
|
|
%vars, |
521
|
|
|
|
|
|
|
coord_field_1 => "os_x", |
522
|
|
|
|
|
|
|
coord_field_2 => "os_y", |
523
|
|
|
|
|
|
|
dist_field => "os_dist", |
524
|
|
|
|
|
|
|
coord_field_1_name => "OS X coordinate", |
525
|
|
|
|
|
|
|
coord_field_2_name => "OS Y coordinate", |
526
|
|
|
|
|
|
|
coord_field_1_value => $os_x, |
527
|
|
|
|
|
|
|
coord_field_2_value => $os_y, |
528
|
|
|
|
|
|
|
); |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
} elsif ( $geo_handler == 2 ) { |
531
|
57
|
|
|
|
|
6338
|
require Geo::Coordinates::ITM; |
532
|
|
|
|
|
|
|
|
533
|
57
|
|
|
|
|
104170
|
my $osie_x = $q->param("osie_x"); |
534
|
57
|
|
|
|
|
1340
|
my $osie_y = $q->param("osie_y"); |
535
|
57
|
|
|
|
|
1282
|
my $lat = $q->param("latitude"); |
536
|
57
|
|
|
|
|
1206
|
my $long = $q->param("longitude"); |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
# Trim whitespace. |
539
|
57
|
|
|
|
|
1218
|
$osie_x =~ s/\s+//g; |
540
|
57
|
|
|
|
|
195
|
$osie_y =~ s/\s+//g; |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
# If we were sent x and y, work out lat/long; and vice versa. |
543
|
57
|
100
|
66
|
|
|
892
|
if ( defined $osie_x && length $osie_x |
|
|
100
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
544
|
|
|
|
|
|
|
&& defined $osie_y && length $osie_y ) { |
545
|
55
|
|
|
|
|
325
|
( $lat, $long ) = Geo::Coordinates::ITM::grid_to_ll( |
546
|
|
|
|
|
|
|
$osie_x, $osie_y ); |
547
|
55
|
|
|
|
|
20494
|
$lat = sprintf( "%.6f", $lat ); |
548
|
55
|
|
|
|
|
456
|
$long = sprintf( "%.6f", $long ); |
549
|
|
|
|
|
|
|
} elsif ( defined $lat && length $lat && defined $long |
550
|
|
|
|
|
|
|
&& length $long ) { |
551
|
1
|
|
|
|
|
6
|
( $osie_x, $osie_y ) = Geo::Coordinates::ITM::ll_to_grid( |
552
|
|
|
|
|
|
|
$lat, $long ); |
553
|
1
|
|
|
|
|
241
|
$osie_x = sprintf( "%d", $osie_x ); |
554
|
1
|
|
|
|
|
4
|
$osie_y = sprintf( "%d", $osie_y ); |
555
|
|
|
|
|
|
|
} |
556
|
57
|
50
|
66
|
|
|
792
|
if ( defined $osie_x && length $osie_x |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
557
|
|
|
|
|
|
|
&& defined $osie_y && length $osie_y ) { |
558
|
56
|
|
|
|
|
1043
|
%vars = ( |
559
|
|
|
|
|
|
|
%vars, |
560
|
|
|
|
|
|
|
latitude => $lat, |
561
|
|
|
|
|
|
|
longitude => $long, |
562
|
|
|
|
|
|
|
osie_x => $osie_x, |
563
|
|
|
|
|
|
|
osie_y => $osie_y, |
564
|
|
|
|
|
|
|
); |
565
|
|
|
|
|
|
|
} |
566
|
57
|
50
|
|
|
|
434
|
if ( $args{set_coord_field_vars} ) { |
567
|
0
|
|
|
|
|
0
|
%vars = ( |
568
|
|
|
|
|
|
|
%vars, |
569
|
|
|
|
|
|
|
coord_field_1 => "osie_x", |
570
|
|
|
|
|
|
|
coord_field_2 => "osie_y", |
571
|
|
|
|
|
|
|
dist_field => "osie_dist", |
572
|
|
|
|
|
|
|
coord_field_1_name |
573
|
|
|
|
|
|
|
=> "Irish National Grid X coordinate", |
574
|
|
|
|
|
|
|
coord_field_2_name |
575
|
|
|
|
|
|
|
=> "Irish National Grid Y coordinate", |
576
|
|
|
|
|
|
|
coord_field_1_value => $osie_x, |
577
|
|
|
|
|
|
|
coord_field_2_value => $osie_y, |
578
|
|
|
|
|
|
|
); |
579
|
|
|
|
|
|
|
} |
580
|
|
|
|
|
|
|
} elsif ( $geo_handler == 3 ) { |
581
|
69
|
|
|
|
|
10789
|
require Geo::Coordinates::UTM; |
582
|
69
|
|
|
|
|
125540
|
my $lat = $q->param("latitude"); |
583
|
69
|
|
|
|
|
1670
|
my $long = $q->param("longitude"); |
584
|
|
|
|
|
|
|
|
585
|
69
|
50
|
66
|
|
|
3301
|
if ( defined $lat && length $lat |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
586
|
|
|
|
|
|
|
&& defined $long && length $long ) { |
587
|
|
|
|
|
|
|
# Trim whitespace. |
588
|
66
|
|
|
|
|
492
|
$lat =~ s/\s+//g; |
589
|
66
|
|
|
|
|
244
|
$long =~ s/\s+//g; |
590
|
66
|
|
|
|
|
295
|
my ($zone, $easting, $northing) = |
591
|
|
|
|
|
|
|
Geo::Coordinates::UTM::latlon_to_utm( $config->ellipsoid, |
592
|
|
|
|
|
|
|
$lat, $long ); |
593
|
66
|
|
|
|
|
10464
|
$easting =~ s/\..*//; # chop off decimal places |
594
|
66
|
|
|
|
|
647
|
$northing =~ s/\..*//; # - metre accuracy enough |
595
|
66
|
|
|
|
|
1134
|
%vars = ( |
596
|
|
|
|
|
|
|
%vars, |
597
|
|
|
|
|
|
|
latitude => $lat, |
598
|
|
|
|
|
|
|
longitude => $long, |
599
|
|
|
|
|
|
|
easting => $easting, |
600
|
|
|
|
|
|
|
northing => $northing, |
601
|
|
|
|
|
|
|
); |
602
|
|
|
|
|
|
|
} |
603
|
69
|
50
|
|
|
|
587
|
if ( $args{set_coord_field_vars} ) { |
604
|
0
|
|
|
|
|
0
|
%vars = ( |
605
|
|
|
|
|
|
|
%vars, |
606
|
|
|
|
|
|
|
coord_field_1 => "latitude", |
607
|
|
|
|
|
|
|
coord_field_2 => "longitude", |
608
|
|
|
|
|
|
|
dist_field => "latlong_dist", |
609
|
|
|
|
|
|
|
coord_field_1_name => "Latitude (decimal)", |
610
|
|
|
|
|
|
|
coord_field_2_name => "Longitude (decimal)", |
611
|
|
|
|
|
|
|
coord_field_1_value => $lat, |
612
|
|
|
|
|
|
|
coord_field_2_value => $long, |
613
|
|
|
|
|
|
|
); |
614
|
|
|
|
|
|
|
} |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
# Check whether we need to munge lat and long. |
619
|
|
|
|
|
|
|
# Store them unmunged as well so commit_node can get hold of them. |
620
|
730
|
|
|
|
|
7914
|
my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); |
621
|
730
|
100
|
|
|
|
4104
|
if ( $prefs{latlong_traditional} ) { |
622
|
6
|
|
|
|
|
12
|
foreach my $var ( qw( latitude longitude ) ) { |
623
|
12
|
100
|
66
|
|
|
66
|
next unless defined $vars{$var} && length $vars{$var}; |
624
|
4
|
|
|
|
|
13
|
$vars{$var."_unmunged"} = $vars{$var}; |
625
|
4
|
|
|
|
|
12
|
$vars{$var} = _deg2string($vars{$var}); |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
|
629
|
730
|
|
|
|
|
14723
|
return %vars; |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
# Slightly modified from the no-longer-available Geography::NationalGrid |
633
|
|
|
|
|
|
|
# module, which was written by P Kent and distributed under the Artistic |
634
|
|
|
|
|
|
|
# Licence. |
635
|
|
|
|
|
|
|
sub _deg2string { |
636
|
4
|
|
|
4
|
|
7
|
my $degrees = shift; |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
# make positive |
639
|
4
|
|
|
|
|
6
|
my $isneg = 0; |
640
|
4
|
100
|
|
|
|
25
|
if ($degrees < 0) { |
|
|
50
|
|
|
|
|
|
641
|
2
|
|
|
|
|
3
|
$isneg = 1; |
642
|
2
|
|
|
|
|
5
|
$degrees = abs( $degrees ); |
643
|
|
|
|
|
|
|
} elsif ($degrees == 0) { |
644
|
0
|
|
|
|
|
0
|
return '0d 0m 0s'; |
645
|
|
|
|
|
|
|
} |
646
|
|
|
|
|
|
|
|
647
|
4
|
|
|
|
|
8
|
my $d = int( $degrees ); |
648
|
4
|
|
|
|
|
7
|
$degrees -= $d; |
649
|
4
|
|
|
|
|
6
|
$degrees *= 60; |
650
|
4
|
|
|
|
|
6
|
my $m = int( $degrees ); |
651
|
4
|
|
|
|
|
6
|
$degrees -= $m; |
652
|
4
|
|
|
|
|
7
|
my $s = $degrees * 60; |
653
|
|
|
|
|
|
|
|
654
|
4
|
100
|
|
|
|
40
|
return sprintf("%s%dd %um %.2fs", ($isneg?'-':''), $d, $m, $s); |
655
|
|
|
|
|
|
|
} |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=back |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
=head1 AUTHOR |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
The OpenGuides Project (openguides-dev@lists.openguides.org) |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
=head1 COPYRIGHT |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Copyright (C) 2003-2013 The OpenGuides Project. All Rights Reserved. |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
668
|
|
|
|
|
|
|
under the same terms as Perl itself. |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
=cut |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
1; |