Skip to content

Commit

Permalink
better caching and html validation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxious committed Oct 1, 2012
1 parent 2df6e54 commit e410157
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 23 deletions.
1 change: 1 addition & 0 deletions about.php
Expand Up @@ -15,6 +15,7 @@
limitations under the License.
*/
include ('include/common.inc.php');
cache_modtime();
include_header("About", "about")
?>
<p>
Expand Down
1 change: 1 addition & 0 deletions feedback.php
@@ -1,6 +1,7 @@
<?php
include ("include/common.inc.php");
$GTFSREnabled = false;
cache_modtime();
include_header("Feedback", "feedback");
function sendEmail($topic, $message)
{
Expand Down
1 change: 1 addition & 0 deletions include/common-session.inc.php
Expand Up @@ -16,6 +16,7 @@
limitations under the License.
*/
// you have to open the session to be able to modify or remove it
session_cache_limiter ('private_no_expire, must-revalidate');
session_start();
if (isset($_REQUEST['geolocate']) && $_REQUEST['geolocate'] != 'Enter co-ordinates or address here') {
$geocoded = false;
Expand Down
41 changes: 24 additions & 17 deletions include/common-template.inc.php
Expand Up @@ -19,7 +19,13 @@
// Copyright 2009 Google Inc. All Rights Reserved.
$GA_ACCOUNT = "MO-22173039-1";
$GA_PIXEL = "/lib/ga.php";

function cache_modtime() {
header('Cache-Control: max-age=31556926');
$mtime = filemtime(__FILE__);
$etag = md5($mtime);
header('ETag: "' . $etag . '"');
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
}
function googleAnalyticsGetImageUrl() {
global $GA_ACCOUNT, $GA_PIXEL;
//if (stristr($_SERVER['HTTP_USER_AGENT'], 'Googlebot') return "";
Expand Down Expand Up @@ -47,7 +53,7 @@ function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = fal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>' . $pageTitle . ' - Canberra Bus Timetable</title>
<meta name="google-site-verification" content="-53T5Qn4TB_de1NyfR_ZZkEVdUNcNFSaYKSFkWKx-sY" />
Expand All @@ -67,18 +73,18 @@ function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = fal
$jqmjs = "//code.jquery.com/mobile/$jqmVersion/jquery.mobile-$jqmVersion.min.js";
}
echo '<link rel="stylesheet" href="' . $jqmcss . '" />
<script src="' . $jqjs . '"></script>
<script>$(document).bind("mobileinit", function(){
<script type="text/javascript" src="' . $jqjs . '"></script>
<script type="text/javascript">$(document).bind("mobileinit", function(){
$.mobile.ajaxEnabled = false;
});
</script>
<script src="' . $jqmjs . '"></script>
<script type="text/javascript" src="' . $jqmjs . '"></script>
<script src="' . $basePath . 'js/jquery.ui.core.min.js"></script>
<script src="' . $basePath . 'js/jquery.ui.position.min.js"></script>
<script src="' . $basePath . 'js/jquery.ui.widget.min.js"></script>
<script src="' . $basePath . 'js/jquery.ui.autocomplete.min.js"></script>
<script>
<script type="text/javascript" src="' . $basePath . 'js/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="' . $basePath . 'js/jquery.ui.position.min.js"></script>
<script type="text/javascript" src="' . $basePath . 'js/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="' . $basePath . 'js/jquery.ui.autocomplete.min.js"></script>
<script type="text/javascript">
$(function() {
$( "#geolocate" ).autocomplete({
source: "lib/autocomplete.php",
Expand Down Expand Up @@ -113,7 +119,7 @@ function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = fal
<link rel="apple-touch-icon" href="apple-touch-icon.png" />';
}
if ($geolocate) {
echo "<script>
echo "<script type=\"text/javascript\">
function success(position) {
$('#error').val('Location now detected. Please wait for data to load.');
Expand Down Expand Up @@ -147,7 +153,7 @@ function geolocate() {
echo "geolocate();";
echo "</script> ";
}
if (isAnalyticsOn())
if (isAnalyticsOn()) {
echo '
<script type="text/javascript">' . "
Expand All @@ -156,6 +162,7 @@ function geolocate() {
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
</script>";
}
echo '</head>
<body>
<div id="skip">
Expand Down Expand Up @@ -217,10 +224,10 @@ function geolocate() {
function include_footer() {
global $basePath;
echo '<div id="footer"><a href="' . $basePath . 'about.php">About/Contact Us</a>&nbsp;<a href="' . $basePath . 'feedback.php">Feedback/Bug Report</a>&nbsp;<a href="' . $basePath . 'privacy.php">Privacy Policy</a>';
echo '<br><small>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/au/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/au/80x15.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/au/">Creative Commons Attribution 3.0 Australia License</a>.</small></div>';
echo '<br/><small>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/au/"><img alt="Creative Commons License" src="http://i.creativecommons.org/l/by/3.0/au/80x15.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/au/">Creative Commons Attribution 3.0 Australia License</a>.</small></div>';
if (isAnalyticsOn()) {
echo "<script> (function() {
echo "<script type=\"text/javascript\"> (function() {
var ga = document.createElement('script'); ga.type =
'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ?
Expand All @@ -229,7 +236,7 @@ function include_footer() {
s.parentNode.insertBefore(ga, s);
})();</script>";
$googleAnalyticsImageUrl = googleAnalyticsGetImageUrl();
echo '<noscript><img src="' . $googleAnalyticsImageUrl . '" alt=""/></noscript>';
echo '<noscript><div><img src="' . $googleAnalyticsImageUrl . '" alt=""/></div></noscript>';
}
echo "\n</div></div></body></html>";
}
Expand Down Expand Up @@ -301,7 +308,7 @@ function placeSettings() {

function trackEvent($category, $action, $label = "", $value = - 1) {
if (isAnalyticsOn()) {
echo "\n<script> _gaq.push(['_trackEvent', '$category', '$action'" . ($label != "" ? ", '$label'" : "") . ($value != - 1 ? ", $value" : "") . "]);</script>";
echo "\n<script type=\"text/javascript\"> _gaq.push(['_trackEvent', '$category', '$action'" . ($label != "" ? ", '$label'" : "") . ($value != - 1 ? ", $value" : "") . "]);</script>";
}
}

Expand Down
3 changes: 2 additions & 1 deletion index.php
Expand Up @@ -15,12 +15,13 @@
limitations under the License.
*/
include ('include/common.inc.php');
cache_modtime();
include_header("bus.lambdacomplex.org", "index", false)
?>
<div data-role="page">
<div data-role="content">
<div id="jqm-homeheader">
<h1>busness time</h1><br><small>Canberra Bus Timetables and Trip Planner</small>
<h1>busness time</h1><br/><small>Canberra Bus Timetables and Trip Planner</small>
</div>
<a name="maincontent" id="maincontent"></a>
<a href="tripPlanner.php" data-role="button" data-icon="navigation">Launch Trip Planner...</a>
Expand Down
5 changes: 3 additions & 2 deletions labs/gtfs-trips-wheelchair_accessibility.php
Expand Up @@ -48,11 +48,12 @@ function buildRouteURL($routeNum)

$verbose = false;
$numberSerieses = Array(
//2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50,
2, 3, 4,
//5, 6, 7, 8, 9, 10, 20, 30, 40, 50,
//60, 70, 80, 110, 160, 200, 220, 265,
//300,
//310,
700, 710, 720, 730, 740, 750, 760, 770, 780, 900, 910, 920, 930, 930, 940, 950, 960, 980
//700, 710, 720, 730, 740, 750, 760, 770, 780, 900, 910, 920, 930, 930, 940, 950, 960, 980
);
foreach ($numberSerieses as $numberSeries) {
echo "<h1>$numberSeries</h1>";
Expand Down
2 changes: 1 addition & 1 deletion labs/index.php
@@ -1,6 +1,6 @@
<?php
include ('../include/common.inc.php');

cache_modtime();
include_header("Busness R&amp;D", "index");
?>
<ul data-role="listview" data-theme="e" data-groupingtheme="e">
Expand Down
2 changes: 1 addition & 1 deletion myway/index.php
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
*/
include ('../include/common.inc.php');

cache_modtime();
include_header("MyWay Balance and Timeliness Survey Results", "index");
if ($_SESSION['authed'] == true) {
echo '<ul data-role="listview" data-theme="e" data-groupingtheme="e">
Expand Down
3 changes: 3 additions & 0 deletions myway/mywaybalance.php
Expand Up @@ -16,6 +16,9 @@
limitations under the License.
*/
include ('../include/common.inc.php');
if (!isset($_REQUEST['card_number'])) {
cache_modtime();
}
include_header("MyWay Balance", "mywayBalance", false, false, true);
echo '<div data-role="page">
<div data-role="header" data-position="inline">
Expand Down
1 change: 1 addition & 0 deletions privacy.php
Expand Up @@ -15,6 +15,7 @@
limitations under the License.
*/
include ('include/common.inc.php');
cache_modtime();
include_header("Privacy Policy", "privacy")
?>
<h2>Information collected</a></h2>
Expand Down
1 change: 1 addition & 0 deletions routeList.php
Expand Up @@ -81,6 +81,7 @@ function displayNearbyRoutes($routes) {
}

if (isset($bysuburbs)) {

include_header("Routes by Suburb", "routeList");
navbar();
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >';
Expand Down
5 changes: 4 additions & 1 deletion tripPlanner.php
Expand Up @@ -16,6 +16,9 @@
limitations under the License.
*/
include ('include/common.inc.php');
if (!isset($_REQUEST['time'])) {
cache_modtime();
}
include_header("Trip Planner", "tripPlanner", true, false, true);
$from = (isset($_REQUEST['from']) ? filter_var($_REQUEST['from'], FILTER_SANITIZE_STRING) : "");
$to = (isset($_REQUEST['to']) ? filter_var($_REQUEST['to'], FILTER_SANITIZE_STRING) : "");
Expand Down Expand Up @@ -161,7 +164,7 @@ function processLeg($legNumber, $leg)
}
}

if ($_REQUEST['time']) {
if (isset($_REQUEST['time'])) {
if (startsWith($to, "-")) {
$toPlace = $to;
} else if (strpos($to, "(") !== false) {
Expand Down
1 change: 1 addition & 0 deletions updatedb.php
Expand Up @@ -30,6 +30,7 @@
delete from trips;
delete from fare_attributes;
delete from feed_info;
delete from x_end_times;
*/

// Unzip cbrfeed.zip, import all csv files to database
Expand Down

0 comments on commit e410157

Please sign in to comment.