aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/CrossSell.pm5
-rw-r--r--perllib/Page.pm19
-rw-r--r--perllib/Problems.pm40
3 files changed, 34 insertions, 30 deletions
diff --git a/perllib/CrossSell.pm b/perllib/CrossSell.pm
index a533ecfc7..e40f2166f 100644
--- a/perllib/CrossSell.pm
+++ b/perllib/CrossSell.pm
@@ -218,9 +218,8 @@ sub display_advert ($$;$%) {
# }
#}
- # ALWAYS return democracy club advert for the mo
- $q->{scratch} = 'advert=demclub0';
- return display_democracyclub();
+ #$q->{scratch} = 'advert=demclub0';
+ #return display_democracyclub();
#unless (defined $data{done_tms} && $data{done_tms}==1) {
$q->{scratch} = 'advert=news';
diff --git a/perllib/Page.pm b/perllib/Page.pm
index fcf11f7f7..cafd9ba91 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -339,17 +339,14 @@ sub footer {
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.mysociety.org/" : "http://piwik.mysociety.org/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
-</script>
-<script type="text/javascript">
-<!--
-piwik_action_name = '';
-piwik_idsite = 8;
-piwik_url = pkBaseURL + "piwik.php";
-piwik_log(piwik_action_name, piwik_idsite, piwik_url);
-//-->
-</script>
-<noscript><img width=1 height=1 src="http://piwik.mysociety.org/piwik.php?idsite=8" style="border:0" alt=""></noscript>
-<!-- /Piwik -->
+</script><script type="text/javascript">
+try {
+var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 8);
+piwikTracker.trackPageView();
+piwikTracker.enableLinkTracking();
+} catch( err ) {}
+</script><noscript><p><img src="http://piwik.mysociety.org/piwik.php?idsite=8" style="border:0" alt=""/></p></noscript>
+<!-- End Piwik Tag -->
EOF
}
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index 69293e162..7ce082129 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -34,6 +34,11 @@ sub set_site_restriction {
}
}
+sub current_timestamp {
+ my $current_timestamp = dbh()->selectrow_array('select ms_current_timestamp()');
+ return "'$current_timestamp'::timestamp";
+}
+
# Front page statistics
sub recent_fixed {
@@ -41,7 +46,7 @@ sub recent_fixed {
my $result = Memcached::get($key);
unless ($result) {
$result = dbh()->selectrow_array("select count(*) from problem
- where state='fixed' and lastupdate>ms_current_timestamp()-'1 month'::interval
+ where state='fixed' and lastupdate>" . current_timestamp() . "-'1 month'::interval
$site_restriction");
Memcached::set($key, $result, 3600);
}
@@ -72,7 +77,7 @@ sub recent_new {
my $result = Memcached::get($key);
unless ($result) {
$result = dbh()->selectrow_array("select count(*) from problem
- where state in ('confirmed','fixed') and confirmed>ms_current_timestamp()-'$interval'::interval
+ where state in ('confirmed','fixed') and confirmed>" . current_timestamp() . "-'$interval'::interval
$site_restriction");
Memcached::set($key, $result, 3600);
}
@@ -209,7 +214,7 @@ sub fixed_nearby {
sub fetch_problem {
my $id = shift;
- dbh()->selectrow_hashref(
+ my $p = dbh()->selectrow_hashref(
"select id, easting, northing, council, category, title, detail, photo,
used_map, name, anonymous, extract(epoch from confirmed) as time,
state, extract(epoch from whensent-confirmed) as whensent,
@@ -218,7 +223,10 @@ sub fetch_problem {
from problem where id=? and state in ('confirmed','fixed', 'hidden')
$site_restriction", {}, $id
);
+ $p->{service} =~ s/_/ /g;
+ return $p;
}
+
# API functions
sub problems_matching_criteria {
@@ -301,10 +309,11 @@ sub council_problems {
push @params, $one_council;
$where_extra = "and areas like '%,'||?||',%'";
}
+ my $current_timestamp = current_timestamp();
my $problems = select_all(
"select id, title, detail, council, state, areas,
- extract(epoch from ms_current_timestamp()-lastupdate) as duration,
- extract(epoch from ms_current_timestamp()-confirmed) as age
+ extract(epoch from $current_timestamp-lastupdate) as duration,
+ extract(epoch from $current_timestamp-confirmed) as age
from problem
where state in ('confirmed', 'fixed')
$where_extra
@@ -471,14 +480,14 @@ Return a reference to an array of problems suitable for display in the admin tim
Uses any site_restriction defined by a cobrand.
=cut
sub timeline_problems {
-
+ my $current_timestamp = current_timestamp();
my $problems = select_all("select state,id,name,email,title,council,category,service,cobrand,cobrand_data,
extract(epoch from created) as created,
extract(epoch from confirmed) as confirmed,
extract(epoch from whensent) as whensent
- from problem where (created>=ms_current_timestamp()-'7 days'::interval
- or confirmed>=ms_current_timestamp()-'7 days'::interval
- or whensent>=ms_current_timestamp()-'7 days'::interval)
+ from problem where (created>=$current_timestamp-'7 days'::interval
+ or confirmed>=$current_timestamp-'7 days'::interval
+ or whensent>=$current_timestamp-'7 days'::interval)
$site_restriction");
return $problems;
@@ -498,7 +507,7 @@ sub timeline_updates {
from comment, problem
where comment.problem_id = problem.id
and comment.state='confirmed'
- and comment.created>=ms_current_timestamp()-'7 days'::interval
+ and comment.created>=" . current_timestamp() . "-'7 days'::interval
$site_restriction");
return $updates;
}
@@ -515,10 +524,9 @@ sub timeline_alerts {
if ($cobrand) {
$cobrand_clause = " and cobrand = '$cobrand'";
}
- my $current_time = dbh()->selectrow_array('select ms_current_timestamp()');
my $alerts = select_all("select *,
extract(epoch from whensubscribed) as whensubscribed
- from alert where whensubscribed>='$current_time'-'7 days'::interval
+ from alert where whensubscribed>=" . current_timestamp() . "-'7 days'::interval
and confirmed=1
$cobrand_clause");
return $alerts;
@@ -538,11 +546,10 @@ sub timeline_deleted_alerts {
$cobrand_clause = " and cobrand = '$cobrand'";
}
- my $current_time = dbh()->selectrow_array('select ms_current_timestamp()');
my $alerts = select_all("select *,
extract(epoch from whensubscribed) as whensubscribed,
extract(epoch from whendisabled) as whendisabled
- from alert where whendisabled>='$current_time'-'7 days'::interval
+ from alert where whendisabled>=" . current_timestamp() . "-'7 days'::interval
$cobrand_clause");
return $alerts;
@@ -561,13 +568,14 @@ sub timeline_questionnaires {
if ($cobrand) {
$cobrand_clause = " and cobrand = '$cobrand'";
}
+ my $current_timestamp = current_timestamp();
my $questionnaire = select_all("select questionnaire.*,
extract(epoch from questionnaire.whensent) as whensent,
extract(epoch from questionnaire.whenanswered) as whenanswered
from questionnaire, problem
where questionnaire.problem_id = problem.id
- and (questionnaire.whensent>=ms_current_timestamp()-'7 days'::interval
- or questionnaire.whenanswered>=ms_current_timestamp()-'7 days'::interval)
+ and (questionnaire.whensent>=$current_timestamp-'7 days'::interval
+ or questionnaire.whenanswered>=$current_timestamp-'7 days'::interval)
$cobrand_clause");
}