diff options
Diffstat (limited to 'perllib/Page.pm')
-rw-r--r-- | perllib/Page.pm | 126 |
1 files changed, 61 insertions, 65 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm index fc7127a78..279c5a79a 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -15,6 +15,7 @@ use strict; use Carp; use mySociety::CGIFast qw(-no_xhtml); use Data::Dumper; +use Encode; use Error qw(:try); use File::Slurp; use HTTP::Date; # time2str @@ -49,7 +50,9 @@ use FixMyStreet::Map; my $lastmodified; sub do_fastcgi { - my ($func, $lm) = @_; + my ($func, $lm, $binary) = @_; + + binmode(STDOUT, ":utf8") unless $binary; try { my $W = new mySociety::WatchUpdate(); @@ -83,7 +86,7 @@ sub report_error { my $msg_br = join '<br><br>', split m{\n}, $msg; - print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n", + print "Status: 500\nContent-Type: text/html; charset=utf-8\n\n", qq(<html><head><title>$somethingwrong</title></head></html>), q(<body>), qq(<h1>$somethingwrong</h1>), @@ -111,7 +114,7 @@ sub microsite { my $lang; $lang = 'cy' if $host =~ /cy/; $lang = 'en-gb' if $host =~ /^en\./; - Cobrand::set_lang_and_domain(get_cobrand($q), $lang); + Cobrand::set_lang_and_domain(get_cobrand($q), $lang, 1); Problems::set_site_restriction($q); Memcached::set_namespace(mySociety::Config::get('BCI_DB_NAME') . ":"); @@ -185,9 +188,8 @@ sub template_vars ($%) { my $lang_url = base_url_with_lang($q, 1); $lang_url .= $ENV{REQUEST_URI} if $ENV{REQUEST_URI}; - my $site_title = $q->{site} eq 'fixmystreet' - ? _('FixMyStreet') - : Cobrand::site_title(get_cobrand($q)); + my $site_title = Cobrand::site_title(get_cobrand($q)); + $site_title = _('FixMyStreet') unless $site_title; %vars = ( 'report' => _('Report a problem'), @@ -202,7 +204,7 @@ sub template_vars ($%) { 'lang_url' => $lang_url, 'title' => $params{title}, 'rss' => '', - map_js => FixMyStreet::Map::header_js(), + map_js => $params{js} || '', ); if ($params{rss}) { @@ -213,12 +215,10 @@ sub template_vars ($%) { $vars{robots} = '<meta name="robots" content="' . $params{robots} . '">'; } - if ($q->{site} eq 'fixmystreet') { - my $home = !$params{title} && $ENV{SCRIPT_NAME} eq '/index.cgi' && !$ENV{QUERY_STRING}; - $vars{heading_element_start} = $home ? '<h1 id="header">' : '<div id="header"><a href="/">'; - $vars{heading} = _('Fix<span id="my">My</span>Street'); - $vars{heading_element_end} = $home ? '</h1>' : '</a></div>'; - } + my $home = !$params{title} && $ENV{SCRIPT_NAME} eq '/index.cgi' && !$ENV{QUERY_STRING}; + $vars{heading_element_start} = $home ? '<h1 id="header">' : '<div id="header"><a href="/">'; + $vars{heading} = _('Fix<span id="my">My</span>Street'); + $vars{heading_element_end} = $home ? '</h1>' : '</a></div>'; return \%vars; } @@ -260,22 +260,6 @@ sub template_include { return $template->fill_in(HASH => \%params); } -=item template_header TEMPLATE Q ROOT PARAMS - -Return HTML for the templated top of a page, given a -template name, request, template root, and parameters. - -=cut - -sub template_header($$$%) { - my ($template, $q, $template_root, %params) = @_; - $template = $q->{site} eq 'fixmystreet' - ? 'header' - : $template . '-header'; - my $vars = template_vars($q, %params); - return template_include($template, $q, $template_root, %$vars); -} - =item header Q [PARAM VALUE ...] Return HTML for the top of the page, given PARAMs (TITLE is required). @@ -287,7 +271,7 @@ sub header ($%) { my $default_params = Cobrand::header_params(get_cobrand($q), $q, %params); my %default_params = %{$default_params}; %params = (%default_params, %params); - my %permitted_params = map { $_ => 1 } qw(title rss expires lastmodified template cachecontrol context status_code robots); + my %permitted_params = map { $_ => 1 } qw(title rss expires lastmodified template cachecontrol context status_code robots js); foreach (keys %params) { croak "bad parameter '$_'" if (!exists($permitted_params{$_})); } @@ -305,8 +289,8 @@ sub header ($%) { $params{title} = ent($params{title}); $params{lang} = $mySociety::Locale::lang; - my $template = template($q, %params); - my $html = template_header($template, $q, template_root($q), %params); + my $vars = template_vars($q, %params); + my $html = template_include('header', $q, template_root($q), %$vars); my $cache_val = $default_params{cachecontrol}; if (mySociety::Config::get('STAGING_SITE')) { $html .= '<p class="error">' . _("This is a developer site; things might break at any time, and the database will be periodically deleted.") . '</p>'; @@ -320,10 +304,28 @@ sub header ($%) { sub footer { my ($q, %params) = @_; - if ($q->{site} ne 'fixmystreet') { - my $template = template($q, %params) . '-footer'; - my $template_root = template_root($q); - my $html = template_include($template, $q, $template_root, %params); + my $pc = $q->param('pc') || ''; + $pc = '?pc=' . URI::Escape::uri_escape($pc) if $pc; + + my $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a>, using some <a href="http://github.com/mysociety/fixmystreet">clever</a> <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.'); + if (mySociety::Config::get('COUNTRY') eq 'NO') { + $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a> and maintained by <a href="http://www.nuug.no/">NUUG</a>, using some <a href="http://github.com/mysociety/fixmystreet">clever</a> <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.'); + } + + %params = (%params, + navigation => _('Navigation'), + report => _("Report a problem"), + reports => _("All reports"), + alerts => _("Local alerts"), + help => _("Help"), + contact => _("Contact"), + pc => $pc, + orglogo => _('<a href="http://www.mysociety.org/"><img id="logo" width="133" height="26" src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>'), + creditline => $creditline, + ); + + my $html = template_include('footer', $q, template_root($q), %params); + if ($html) { my $lang = $mySociety::Locale::lang; if ($q->{site} eq 'emptyhomes' && $lang eq 'cy') { $html =~ s/25 Walter Road<br>Swansea/25 Heol Walter<br>Abertawe/; @@ -331,9 +333,6 @@ sub footer { return $html; } - my $pc = $q->param('pc') || ''; - $pc = "?pc=" . ent($pc) if $pc; - my $piwik = ""; if (mySociety::Config::get('BASE_URL') eq "http://www.fixmystreet.com") { $piwik = <<EOF; @@ -352,29 +351,20 @@ piwikTracker.enableLinkTracking(); EOF } - my $navigation = _('Navigation'); - my $report = _("Report a problem"); - my $reports = _("All reports"); - my $alerts = _("Local alerts"); - my $help = _("Help"); - my $contact = _("Contact"); - my $orglogo = _('<a href="http://www.mysociety.org/"><img id="logo" width="133" height="26" src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>'); - my $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a>, using some <a href="http://github.com/mysociety/fixmystreet">clever</a> <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.'); - return <<EOF; </div></div> -<h2 class="v">$navigation</h2> +<h2 class="v">$params{navigation}</h2> <ul id="navigation"> -<li><a href="/">$report</a></li> -<li><a href="/reports">$reports</a></li> -<li><a href="/alert$pc">$alerts</a></li> -<li><a href="/faq">$help</a></li> -<li><a href="/contact">$contact</a></li> +<li><a href="/">$params{report}</a></li> +<li><a href="/reports">$params{reports}</a></li> +<li><a href="/alert$params{pc}">$params{alerts}</a></li> +<li><a href="/faq">$params{help}</a></li> +<li><a href="/contact">$params{contact}</a></li> </ul> -$orglogo +$params{orglogo} -<p id="footer">$creditline</p> +<p id="footer">$params{creditline}</p> $piwik @@ -518,17 +508,17 @@ sub prettify_duration { return _('less than a minute') if $s == 0; } my @out = (); - _part(\$s, 60*60*24*7, _('week'), \@out); - _part(\$s, 60*60*24, _('day'), \@out); - _part(\$s, 60*60, _('hour'), \@out); - _part(\$s, 60, _('minute'), \@out); + _part(\$s, 60*60*24*7, _('%d week'), _('%d weeks'), \@out); + _part(\$s, 60*60*24, _('%d day'), _('%d days'), \@out); + _part(\$s, 60*60, _('%d hour'), _('%d hours'), \@out); + _part(\$s, 60, _('%d minute'), _('%d minutes'), \@out); return join(', ', @out); } sub _part { - my ($s, $m, $w, $o) = @_; + my ($s, $m, $w1, $w2, $o) = @_; if ($$s >= $m) { my $i = int($$s / $m); - push @$o, "$i $w" . ($i != 1 ? 's' : ''); + push @$o, sprintf(mySociety::Locale::nget($w1, $w2, $i), $i); $$s -= $i * $m; } } @@ -688,10 +678,16 @@ sub mapit_check_error { } sub short_name { - my $name = shift; + my ($area, $info) = @_; # Special case Durham as it's the only place with two councils of the same name - return 'Durham+County' if ($name eq 'Durham County Council'); - return 'Durham+City' if ($name eq 'Durham City Council'); + # And some places in Norway + return 'Durham+County' if $area->{name} eq 'Durham County Council'; + return 'Durham+City' if $area->{name} eq 'Durham City Council'; + if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) { + my $parent = $info->{$area->{parent_area}}->{name}; + return URI::Escape::uri_escape_utf8("$area->{name}, $parent"); + } + my $name = $area->{name}; $name =~ s/ (Borough|City|District|County) Council$//; $name =~ s/ Council$//; $name =~ s/ & / and /; |