diff options
-rw-r--r-- | conf/packages | 1 | ||||
-rw-r--r-- | perllib/Page.pm | 27 | ||||
-rw-r--r-- | templates/website/emptyhomes-header | 16 | ||||
-rw-r--r-- | templates/website/header | 8 | ||||
-rwxr-xr-x | templates/website/map | 22 | ||||
-rw-r--r-- | templates/website/report-form | 52 | ||||
-rw-r--r-- | templates/website/scambs-header | 2 | ||||
-rwxr-xr-x | web/index.cgi | 10 |
8 files changed, 63 insertions, 75 deletions
diff --git a/conf/packages b/conf/packages index 890cf3a48..8c13b9ccd 100644 --- a/conf/packages +++ b/conf/packages @@ -25,3 +25,4 @@ perlmagick libjson-perl libimage-size-perl libmath-bigint-gmp-perl +libtext-template-perl diff --git a/perllib/Page.pm b/perllib/Page.pm index a98b128da..b42c27291 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Page.pm,v 1.197 2009-11-03 22:53:50 matthew Exp $ +# $Id: Page.pm,v 1.198 2009-11-04 13:11:06 matthew Exp $ # package Page; @@ -23,6 +23,7 @@ use LWP::Simple; use Digest::MD5 qw(md5_hex); use POSIX qw(strftime); use URI::Escape; +use Text::Template; use Memcached; use Problems; @@ -231,20 +232,6 @@ sub template($%){ return $template; } -=item template_substitute TEMPLATE VARS - -Substitutes the VARS into TEMPLATE. - -=cut - -sub template_substitute($%) { - my ($template, %vars) = @_; - no warnings; - $template =~ s#{{ ([a-z_0-9]+) }}#$vars{$1}#g; - use warnings; - return $template; -} - =item template_include Return HTML for a template, given a template name, request, @@ -257,10 +244,12 @@ sub template_include { (my $file = __FILE__) =~ s{/[^/]*?$}{}; my $template_file = $file . $template_root . $template; $template_file = $file . template_root($q, 1) . $template unless -e $template_file; - open FP, $template_file; - my $html = join('', <FP>); - close FP; - return template_substitute($html, %params); + + $template = Text::Template->new( + SOURCE => $template_file, + DELIMITERS => ['{{', '}}'], + ); + return $template->fill_in(HASH => \%params); } =item template_header TEMPLATE Q ROOT PARAMS diff --git a/templates/website/emptyhomes-header b/templates/website/emptyhomes-header index 95c0833ea..313fc55c5 100644 --- a/templates/website/emptyhomes-header +++ b/templates/website/emptyhomes-header @@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html lang="{{ lang_code }}"> +<html lang="{{ $lang_code }}"> <head> -<title>{{ title }}{{ site_title }}</title> +<title>{{ $title }}{{ $site_title }}</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="/yui/utilities.js"></script> <script type="text/javascript" src="/js.js"></script> @@ -23,12 +23,12 @@ <div id="navigation"> <ul> - <li><a href="/">{{ report }}</a> - <li><a href="/reports">{{ reports }}</a></li> - <li><a href="/alert">{{ alert }}</a></li> - <li><a href="/faq">{{ faq }}</a></li> - <li><a href="/about">{{ about }}</a></li> - <li><a href="{{ lang_url }}">{{ lang }}</a></li> + <li><a href="/">{{ $report }}</a> + <li><a href="/reports">{{ $reports }}</a></li> + <li><a href="/alert">{{ $alert }}</a></li> + <li><a href="/faq">{{ $faq }}</a></li> + <li><a href="/about">{{ $about }}</a></li> + <li><a href="{{ $lang_url }}">{{ $lang }}</a></li> </ul> </div> diff --git a/templates/website/header b/templates/website/header index 9246ea927..44f51ca55 100644 --- a/templates/website/header +++ b/templates/website/header @@ -1,16 +1,16 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html lang="{{ lang_code }}"> +<html lang="{{ $lang_code }}"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="/yui/utilities.js"></script> <script type="text/javascript" src="/js.js"></script> - <title>{{ title }}{{ site_title }}</title> + <title>{{ $title }}{{ $site_title }}</title> <style type="text/css">@import url("/css/core.css"); @import url("/css/main.css");</style> <!--[if LT IE 7]> <style type="text/css">@import url("/css/ie6.css");</style> <![endif]--> - {{ rss }} + {{ $rss }} </head> <body> - {{ heading_element_start }}{{ heading }}{{ heading_element_end }} + {{ $heading_element_start }}{{ $heading }}{{ $heading_element_end }} <div id="wrapper"><div id="content"> diff --git a/templates/website/map b/templates/website/map index 8faf76c06..f54c68aba 100755 --- a/templates/website/map +++ b/templates/website/map @@ -1,28 +1,28 @@ -{{ map }} +{{ $map }} -<h1>{{ heading_problems }}</h1> +<h1>{{ $heading_problems }}</h1> <p id="alert_links_area"> -<a id="email_alert" rel="nofollow" href="{{ url_email }}">{{ email_me }}</a> -| <a href="{{ url_rss }}" id="rss_alert"><span>{{ rss_alt }}</span> <img src="/i/feed.png" width="16" height="16" title="{{ rss_title }}" alt="{{ rss_alt }}" border="0" style="vertical-align: top"></a> +<a id="email_alert" rel="nofollow" href="{{ $url_email }}">{{ $email_me }}</a> +| <a href="{{ $url_rss }}" id="rss_alert"><span>{{ $rss_alt }}</span> <img src="/i/feed.png" width="16" height="16" title="{{ $rss_title }}" alt="{{ $rss_alt }}" border="0" style="vertical-align: top"></a> </p> -{{ errors }} +{{ $errors }} -<p id="text_map">{{ text_to_report }} {{ text_skip }}</p> +<p id="text_map">{{ $text_to_report }} {{ $text_skip }}</p> <div id="nearby_lists"> -<h2>{{ heading_on_around }}</h2> +<h2>{{ $heading_on_around }}</h2> <ul id="current"> -{{ reports_on_around }} +{{ $reports_on_around }} </ul> -<h2 id="closest_problems">{{ heading_closest }}</h2> +<h2 id="closest_problems">{{ $heading_closest }}</h2> <ul id="current_near"> -{{ reports_nearby }} +{{ $reports_nearby }} </ul> </div> -{{ map_end }} +{{ $map_end }} diff --git a/templates/website/report-form b/templates/website/report-form index f1b7bf594..94d96b800 100644 --- a/templates/website/report-form +++ b/templates/website/report-form @@ -1,42 +1,42 @@ -{{ form_start }} -{{ page_heading }} +{{ $form_start }} +{{ $page_heading }} -{{ text_located }} +{{ $text_located }} -{{ text_help }} +{{ $text_help }} -{{ errors }} +{{ $errors }} <div id="problem_form"> -{{ form_heading }} +{{ $form_heading }} <div id="fieldset"> -{{ category }} +{{ $category }} -<div><label for="form_title">{{ subject_label }}</label> -<input type="text" value="{{ input_h_title }}" name="title" id="form_title" size="30"></div> -<div><label for="form_detail">{{ detail_label }}</label> -<textarea name="detail" id="form_detail" rows="7" cols="26">{{ input_h_detail }}</textarea></div> +<div><label for="form_title">{{ $subject_label }}</label> +<input type="text" value="{{ $input_h{title} }}" name="title" id="form_title" size="30"></div> +<div><label for="form_detail">{{ $detail_label }}</label> +<textarea name="detail" id="form_detail" rows="7" cols="26">{{ $input_h{detail} }}</textarea></div> -{{ partial_field }} +{{ $partial_field }} -{{ photo_field }} +{{ $photo_field }} -<div><label for="form_name">{{ name_label }}</label> -<input type="text" value="{{ input_h_name }}" name="name" id="form_name" size="30"></div> -<div class="checkbox"><input type="checkbox" name="anonymous" id="form_anonymous" value="1"{{ anon }}> -<label for="form_anonymous">{{ anonymous }}</label> -<small>{{ anonymous2 }}</small></div> -<div><label for="form_email">{{ email_label }}</label> -<input type="text" value="{{ input_h_email }}" name="email" id="form_email" size="30"></div> -<div><label for="form_phone">{{ phone_label }}</label> -<input type="text" value="{{ input_h_phone }}" name="phone" id="form_phone" size="15"> -<small>{{ optional }}</small></div> +<div><label for="form_name">{{ $name_label }}</label> +<input type="text" value="{{ $input_h{name} }}" name="name" id="form_name" size="30"></div> +<div class="checkbox"><input type="checkbox" name="anonymous" id="form_anonymous" value="1"{{ $anon }}> +<label for="form_anonymous">{{ $anonymous }}</label> +<small>{{ $anonymous2 }}</small></div> +<div><label for="form_email">{{ $email_label }}</label> +<input type="text" value="{{ $input_h{email} }}" name="email" id="form_email" size="30"></div> +<div><label for="form_phone">{{ $phone_label }}</label> +<input type="text" value="{{ $input_h{phone} }}" name="phone" id="form_phone" size="15"> +<small>{{ $optional }}</small></div> -{{ text_notes }} +{{ $text_notes }} -<p id="problem_submit"><input type="submit" name="submit_problem" value="{{ submit_button }}"></p> +<p id="problem_submit"><input type="submit" name="submit_problem" value="{{ $submit_button }}"></p> </div> </div> -{{ map_end }} +{{ $map_end }} diff --git a/templates/website/scambs-header b/templates/website/scambs-header index 91a4f299e..326602de1 100644 --- a/templates/website/scambs-header +++ b/templates/website/scambs-header @@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en-gb"> <head> -<title>{{ title }}Envirocrime - South Cambridgeshire District Council</title> +<title>{{ $title }}Envirocrime - South Cambridgeshire District Council</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="/yui/utilities.js"></script> <script type="text/javascript" src="/js.js"></script> diff --git a/web/index.cgi b/web/index.cgi index 91afa2fb4..239b73b9f 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: index.cgi,v 1.307 2009-11-03 22:53:50 matthew Exp $ +# $Id: index.cgi,v 1.308 2009-11-04 13:11:06 matthew Exp $ use strict; use Standard; @@ -586,9 +586,7 @@ please specify the closest point on land.')) unless @$all_councils; } my %vars; - foreach (keys %input_h) { - $vars{'input_h_'.$_} = $input_h{$_}; - } + $vars{input_h} = \%input_h; if ($input{skipped}) { my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'mapSkippedForm', $q); @@ -600,8 +598,8 @@ please specify the closest point on land.')) unless @$all_councils; <input type="hidden" name="y" value="$input_h{y}"> <input type="hidden" name="skipped" value="1"> $cobrand_form_elements +<div> EOF - $vars{page_heading} = $q->h1(_('Reporting a problem')) . '<div>'; } else { my $pins = Page::display_pin($q, $px, $py, 'purple'); my $type; @@ -621,10 +619,10 @@ EOF and add further information below, then submit.'); } } - $vars{page_heading} = $q->h1(_('Reporting a problem')) . ' '; $vars{text_located} = $q->p(_('You have located the problem at the point marked with a purple pin on the map. If this is not the correct location, simply click on the map again. ')); } + $vars{page_heading} = $q->h1(_('Reporting a problem')); if ($details eq 'all') { my $council_list = join('</strong> or <strong>', map { $areas_info->{$_}->{name} } @$all_councils); |