--- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -1,4 +1,20 @@ <?php + +/* + * Copyright 2010,2011 Alexander Sadleir + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ // Copyright 2009 Google Inc. All Rights Reserved. $GA_ACCOUNT = "MO-22173039-1"; @@ -11,7 +27,7 @@ $url.= $GA_PIXEL . "?"; $url.= "utmac=" . $GA_ACCOUNT; $url.= "&utmn=" . rand(0, 0x7fffffff); - $referer = $_SERVER["HTTP_REFERER"]; + $referer = (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : ""); $query = $_SERVER["QUERY_STRING"]; $path = $_SERVER["REQUEST_URI"]; if (empty($referer)) { @@ -26,7 +42,7 @@ } function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = false, $datepicker = false) { - global $basePath, $serviceAlertsEnabled; + global $basePath, $GTFSREnabled, $stopid, $routeid; echo ' <!DOCTYPE html> <html lang="en"> @@ -36,31 +52,24 @@ <title>' . $pageTitle . ' - Canberra Bus Timetable</title> <meta name="google-site-verification" content="-53T5Qn4TB_de1NyfR_ZZkEVdUNcNFSaYKSFkWKx-sY" /> <link rel="dns-prefetch" href="//code.jquery.com"> -<link rel="dns-prefetch" href="//ajax.googleapis.com"> - <link rel="stylesheet" href="' . $basePath . 'css/jquery-ui-1.8.12.custom.css" />'; - if (isDebugServer()) { - $jqmcss = $basePath . 'css/jquery.mobile-1.0b2.css'; - $jqjs = $basePath . 'js/jquery-1.6.2.min.js'; - $jqmjs = $basePath . 'js/jquery.mobile-1.0b2.js'; - } else { - $jqmcss = "//code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css"; - $jqjs = "//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"; - $jqmjs = "//code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"; - } - echo '<link rel="stylesheet" href="' . $jqmcss . '" /> - <script src="' . $jqjs . '"></script> - <script>$(document).bind("mobileinit", function(){ +<link rel="dns-prefetch" href="//ajax.googleapis.com">'; + $jqmVersion = "1.0.1"; + echo ' + <script src="'.$basePath.'js/yepnope/yepnope.1.5.3-min.js"></script> + <script> + yepnope([{ + load: "//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js", + complete: function () { + + $(document).bind("mobileinit", function(){ $.mobile.ajaxEnabled = false; -}); -</script> - <script 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> - $(function() { +}); } + +}, { + load: ["//code.jquery.com/mobile/' . $jqmVersion . '/jquery.mobile-' . $jqmVersion . '.min.css","//code.jquery.com/mobile/' . $jqmVersion . '/jquery.mobile-' . $jqmVersion . '.min.js"] + }, { + load: ["' . $basePath . 'css/jquery-ui-1.8.12.custom.css","' . $basePath . 'js/jquery.ui.core.min.js","' . $basePath . 'js/jquery.ui.position.min.js","' . $basePath . 'js/jquery.ui.widget.min.js","' . $basePath . 'js/jquery.ui.autocomplete.min.js"], + complete: function() { $( "#geolocate" ).autocomplete({ source: "lib/autocomplete.php", minLength: 2 @@ -73,8 +82,13 @@ source: "lib/autocomplete.php", minLength: 2 }); - }); - </script>'; + } + + +}]); + +</script> + '; echo '<style type="text/css">'; if (strstr($_SERVER['HTTP_USER_AGENT'], 'Android')) echo '.ui-shadow,.ui-btn-up-a,.ui-btn-hover-a,.ui-btn-down-a,.ui-body-b,.ui-btn-up-b,.ui-btn-hover-b, @@ -87,7 +101,7 @@ }'; echo '</style>'; echo '<link rel="stylesheet" href="' . $basePath . 'css/local.css.php" />'; - if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { + if (isIOSDevice()) { echo '<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <link rel="apple-touch-startup-image" href="startup.png" /> @@ -152,20 +166,44 @@ </div><!-- /header --> <a name="maincontent" id="maincontent"></a> <div data-role="content"> '; - $overrides = getServiceOverride(); - if ($overrides['service_id']) { - if ($overrides['service_id'] == "noservice") { - echo '<div id="servicewarning">Buses are <strong>not running today</strong> due to industrial action/public holiday. See <a + if ($GTFSREnabled) { + $overrides = getServiceOverride(); + if (isset($overrides['service_id'])) { + if ($overrides['service_id'] == "noservice") { + echo '<div class="servicewarning">Buses are <strong>not running today</strong> due to industrial action/public holiday. See <a href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>'; - } else { - echo '<div id="servicewarning">Buses are running on an altered timetable today due to industrial action/public holiday. See <a href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>'; - } - } - if ($GTFSREnabled) { - $serviceAlerts = getServiceAlertsAsArray("agency", "0"); - foreach ($serviceAlerts['entity'] as $entity) { - echo "<div id='servicewarning'>" . date("F j, g:i a", strtotime($entity['alert']['active_period'][0]['start'])) . " to " . date("F j, g:i a", strtotime($entity['alert']['active_period'][0]['end'])) . "{$entity['alert']['header_text']['translation'][0]['text']}<br>Warning: {$entity['alert']['description_text']['translation'][0]['text']} - <br><a href='{$entity['alert']['url']['translation'][0]['text']}'>Source</a> </div>"; + } else { + echo '<div class="servicewarning">Buses are running on an altered timetable today due to industrial action/public holiday. See <a href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>'; + } + } + $serviceAlerts = Array(); + $globalAlerts = getServiceAlertsAsArray("agency", "0"); + if ($globalAlerts != null) { + // echo "getting alerts due to network wide"; + $serviceAlerts = array_merge($serviceAlerts, $globalAlerts); + } + if (isset($stopid)) { + $stopAlerts = getServiceAlertsAsArray("stop", $stopid); + if ($stopAlerts != null) { + // echo "getting alerts due to stop $stopid"; + $serviceAlerts = array_merge($serviceAlerts, $stopAlerts); + } + } + if (isset($routeid)) { + $routeAlerts = getServiceAlertsAsArray("route", $routeid); + if ($routeAlerts != null) { + // echo "getting alerts due to route $routeid"; + $serviceAlerts = array_merge($serviceAlerts, $routeAlerts); + } + } + if (isset($serviceAlerts['entity']) && sizeof($serviceAlerts['entity']) > 0) { + foreach ($serviceAlerts['entity'] as $entity) { + echo "<div class='servicewarning'><b>{$entity['alert']['header_text']['translation'][0]['text']}</b> <small>" + . date("F jS Y, g:i a", $entity['alert']['active_period'][0]['start']) . " to " + . date("F jS Y, g:i a", $entity['alert']['active_period'][0]['end']) . "</small> + <br>Warning: {$entity['alert']['description_text']['translation'][0]['text']} + <br><a href='{$entity['alert']['url']['translation'][0]['text']}'>Source</a> </div>"; + } } } } @@ -185,13 +223,43 @@ s.parentNode.insertBefore(ga, s); })();</script>"; $googleAnalyticsImageUrl = googleAnalyticsGetImageUrl(); - echo '<noscript><img src="' . $googleAnalyticsImageUrl . '" /></noscript>'; + echo '<noscript><img src="' . $googleAnalyticsImageUrl . '" alt=""/></noscript>'; } echo "\n</div></div></body></html>"; } +function timeSettings() { + global $service_periods; + echo '<div id="settings" data-role="collapsible" data-collapsed="true"> +<h3>Change Time (' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...</h3> + <form action="' . basename($_SERVER['PHP_SELF']) . '" method="GET"> + <input type="hidden" name="suburb" id="suburb" value="' . (isset($_REQUEST['suburb']) ? $_REQUEST['suburb'] : "") . '"/> + + <input type="hidden" name="stopid" id="stopid" value="' . (isset($_REQUEST['stopid']) ? $_REQUEST['stopid'] : "") . '"/> + <input type="hidden" name="stopcode" id="stopcode" value="' . (isset($_REQUEST['stopcode']) ? $_REQUEST['stopcode'] : "") . '"/> + <div class="ui-body"> + <div data-role="fieldcontain"> + <label for="time"> Time: </label> + <input type="time" name="time" id="time" value="' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : date("H:i")) . '"/> + <a href="#" name="currentTime" id="currentTime" onClick="var d = new Date();' . "$('#time').val(d.getHours() +':'+ (d.getMinutes().toString().length == 1 ? '0'+ d.getMinutes(): d.getMinutes()));" . '">Current Time?</a> + </div> + <div data-role="fieldcontain"> + <label for="service_period"> Service Period: </label> + <select name="service_period" id="service_period">'; + foreach ($service_periods as $service_period) { + echo "<option value=\"$service_period\"" . (service_period() === $service_period ? " SELECTED" : "") . '>' . ucwords($service_period) . '</option>'; + } + echo '</select> + <a href="#" style="display:none" name="currentPeriod" id="currentPeriod">Current Period?</a> + </div> + + <input type="submit" value="Update"/> + </div></form> + </div>'; +} + function placeSettings() { - global $service_periods; + $geoerror = false; $geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; @@ -222,5 +290,36 @@ } } -?> - +//stop list collapsing +function stopCompare($stopName) { + return substr(trim(preg_replace("/\(Platform.*/", "", $stopName)), 0, 9); +} + +function stopGroupTitle($stopName, $stopdesc) { + if (preg_match("/Dr |Cct |Cir |Av |St |Cr |Parade |Way |Bank /", $stopName)) { + $descParts = explode("<br>", $stopdesc); + return trim(str_replace("Street: ", "", $descParts[0])); + } else { + return trim(preg_replace("/\(Platform.*/", "", $stopName)); + } +} + +function viaPointNames($tripid, $stop_sequence = "") { + $viaPointNames = Array(); + foreach (viaPoints($tripid, $stop_sequence) as $point) { + if (strstr($point['stop_name'], "Station") + || strstr($point['stop_name'], "Shops") + || strstr($point['stop_name'], "CIT") + || strstr($point['stop_name'], "School") + || strstr($point['stop_name'], "University") + ) { + $viaPointNames[] = $point['stop_name']; + } + } + if (sizeof($viaPointNames) > 0) { + return r_implode(", ", $viaPointNames); + } else { + return ""; + } +} +