<?php | <?php |
date_default_timezone_set('Australia/ACT'); | date_default_timezone_set('Australia/ACT'); |
$APIurl = "http://localhost:8765"; | $APIurl = "http://localhost:8765"; |
$cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; | $cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; |
$googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; | $googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; |
$otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; |
$owaSiteID = 'fe5b819fa8c424a99ff0764d955d23f3'; | $owaSiteID = 'fe5b819fa8c424a99ff0764d955d23f3'; |
//$debugOkay = Array("session","json","phperror","other"); | //$debugOkay = Array("session","json","phperror","other"); |
$debugOkay = Array( | $debugOkay = Array( |
"session", | "session", |
"json", | "json", |
"phperror", | "phperror", |
"other" | "other" |
); | ); |
if (isDebug("phperror")) error_reporting(E_ALL ^ E_NOTICE); | if (isDebug("phperror")) error_reporting(E_ALL ^ E_NOTICE); |
include_once ("common-geo.inc.php"); | include_once ("common-geo.inc.php"); |
include_once ("common-net.inc.php"); | include_once ("common-net.inc.php"); |
include_once ("common-template.inc.php"); | include_once ("common-template.inc.php"); |
include_once ("common-transit.inc.php"); | include_once ("common-transit.inc.php"); |
// you have to open the session to be able to modify or remove it | // you have to open the session to be able to modify or remove it |
session_start(); | session_start(); |
if (isset($_REQUEST['service_period'])) { | if (isset($_REQUEST['service_period'])) { |
$_SESSION['service_period'] = filter_var($_REQUEST['service_period'], FILTER_SANITIZE_STRING); | $_SESSION['service_period'] = filter_var($_REQUEST['service_period'], FILTER_SANITIZE_STRING); |
} | } |
if (isset($_REQUEST['time'])) { | if (isset($_REQUEST['time'])) { |
$_SESSION['time'] = filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING); | $_SESSION['time'] = filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING); |
} | } |
if (isset($_REQUEST['geolocate'])) { | if (isset($_REQUEST['geolocate'])) { |
$geocoded = false; | $geocoded = false; |
if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { | if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { |
$_SESSION['lat'] = trim(filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); | $_SESSION['lat'] = trim(filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); |
$_SESSION['lon'] = trim(filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); | $_SESSION['lon'] = trim(filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); |
} | } |
else { | else { |
$geolocate = filter_var($_REQUEST['geolocate'], FILTER_SANITIZE_URL); | $geolocate = filter_var($_REQUEST['geolocate'], FILTER_SANITIZE_URL); |
echo $_REQUEST['geolocate']; | echo $_REQUEST['geolocate']; |
if (startsWith($geolocate, "-")) { | if (startsWith($geolocate, "-")) { |
$locateparts = explode(",",$geolocate); | $locateparts = explode(",",$geolocate); |
$_SESSION['lat'] = $locateparts[0]; | $_SESSION['lat'] = $locateparts[0]; |
$_SESSION['lon'] =$locateparts[1]; | $_SESSION['lon'] =$locateparts[1]; |
} else { | } else { |
$contents = geocode($geolocate, true); | $contents = geocode($geolocate, true); |
print_r($contents); | print_r($contents); |
if (isset($contents[0]->centroid)) { | if (isset($contents[0]->centroid)) { |
$geocoded = true; | $geocoded = true; |
$_SESSION['lat'] = $contents[0]->centroid->coordinates[0]; | $_SESSION['lat'] = $contents[0]->centroid->coordinates[0]; |
$_SESSION['lon'] = $contents[0]->centroid->coordinates[1]; | $_SESSION['lon'] = $contents[0]->centroid->coordinates[1]; |
} | } |
else { | else { |
$_SESSION['lat'] = ""; | $_SESSION['lat'] = ""; |
$_SESSION['lon'] = ""; | $_SESSION['lon'] = ""; |
} | } |
} | } |
} | } |
if ($_SESSION['lat'] != "" && isMetricsOn()) { | if ($_SESSION['lat'] != "" && isMetricsOn()) { |
// Create a new Instance of the tracker | // Create a new Instance of the tracker |
$owa = new owa_php($config); | $owa = new owa_php($config); |
// Set the ID of the site being tracked | // Set the ID of the site being tracked |
$owa->setSiteId($owaSiteID); | $owa->setSiteId($owaSiteID); |
// Create a new event object | // Create a new event object |
$event = $owa->makeEvent(); | $event = $owa->makeEvent(); |
// Set the Event Type, in this case a "video_play" | // Set the Event Type, in this case a "video_play" |
$event->setEventType('geolocate'); | $event->setEventType('geolocate'); |
// Set a property | // Set a property |
$event->set('lat', $_SESSION['lat']); | $event->set('lat', $_SESSION['lat']); |
$event->set('lon', $_SESSION['lon']); | $event->set('lon', $_SESSION['lon']); |
$event->set('geocoded', $geocoded); | $event->set('geocoded', $geocoded); |
// Track the event | // Track the event |
$owa->trackEvent($event); | $owa->trackEvent($event); |
} | } |
} | } |
debug(print_r($_SESSION, true) , "session"); | debug(print_r($_SESSION, true) , "session"); |
function isDebugServer() | function isDebugServer() |
{ | { |
return $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || !$_SERVER['SERVER_NAME']; | return $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || !$_SERVER['SERVER_NAME']; |
} | } |
function isDebug($debugReason = "other") | function isDebug($debugReason = "other") |
{ | { |
global $debugOkay; | global $debugOkay; |
return in_array($debugReason, $debugOkay, false) && isDebugServer(); | return in_array($debugReason, $debugOkay, false) && isDebugServer(); |
} | } |
function isMetricsOn() | function isMetricsOn() |
{ | { |
return !isDebugServer(); | return !isDebugServer(); |
} | } |
function debug($msg, $debugReason = "other") | function debug($msg, $debugReason = "other") |
{ | { |
if (isDebug($debugReason)) echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n"; | if (isDebug($debugReason)) echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n"; |
} | } |
function isFastDevice() | function isFastDevice() |
{ | { |
$ua = $_SERVER['HTTP_USER_AGENT']; | $ua = $_SERVER['HTTP_USER_AGENT']; |
$fastDevices = Array( | $fastDevices = Array( |
"Mozilla/5.0 (X11;", | "Mozilla/5.0 (X11;", |
"Mozilla/5.0 (Windows;", | "Mozilla/5.0 (Windows;", |
"Mozilla/5.0 (iP", | "Mozilla/5.0 (iP", |
"Mozilla/5.0 (Linux; U; Android", | "Mozilla/5.0 (Linux; U; Android", |
"Mozilla/4.0 (compatible; MSIE" | "Mozilla/4.0 (compatible; MSIE" |
); | ); |
$slowDevices = Array( | $slowDevices = Array( |
"J2ME", | "J2ME", |
"MIDP", | "MIDP", |
"Opera/", | "Opera/", |
"Mozilla/2.0 (compatible;", | "Mozilla/2.0 (compatible;", |
"Mozilla/3.0 (compatible;" | "Mozilla/3.0 (compatible;" |
); | ); |
return true; | return true; |
} | } |
function array_flatten($a, $f = array()) | function array_flatten($a, $f = array()) |
{ | { |
if (!$a || !is_array($a)) return ''; | if (!$a || !is_array($a)) return ''; |
foreach ($a as $k => $v) { | foreach ($a as $k => $v) { |
if (is_array($v)) $f = array_flatten($v, $f); | if (is_array($v)) $f = array_flatten($v, $f); |
else $f[$k] = $v; | else $f[$k] = $v; |
} | } |
return $f; | return $f; |
} | } |
function remove_spaces($string) | function remove_spaces($string) |
{ | { |
return str_replace(' ', '', $string); | return str_replace(' ', '', $string); |
} | } |
function object2array($object) | function object2array($object) |
{ | { |
if (is_object($object)) { | if (is_object($object)) { |
foreach ($object as $key => $value) { | foreach ($object as $key => $value) { |
$array[$key] = $value; | $array[$key] = $value; |
} | } |
} | } |
else { | else { |
$array = $object; | $array = $object; |
} | } |
return $array; | return $array; |
} | } |
function startsWith($haystack, $needle, $case = true) | function startsWith($haystack, $needle, $case = true) |
{ | { |
if ($case) { | if ($case) { |
return (strcmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); | return (strcmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); |
} | } |
return (strcasecmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); | return (strcasecmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); |
} | } |
function endsWith($haystack, $needle, $case = true) | function endsWith($haystack, $needle, $case = true) |
{ | { |
if ($case) { | if ($case) { |
return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); | return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); |
} | } |
return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); | return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); |
} | } |
function bracketsMeanNewLine($input) | function bracketsMeanNewLine($input) |
{ | { |
return str_replace(")", "</small>", str_replace("(", "<br><small>", $input)); | return str_replace(")", "</small>", str_replace("(", "<br><small>", $input)); |
} | } |
function sksort(&$array, $subkey="id", $sort_ascending=false) { | |
if (count($array)) | |
$temp_array[key($array)] = array_shift($array); | |
foreach($array as $key => $val){ | |
$offset = 0; | |
$found = false; | |
foreach($temp_array as $tmp_key => $tmp_val) | |
{ | |
if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) | |
{ | |
$temp_array = array_merge( (array)array_slice($temp_array,0,$offset), | |
array($key => $val), | |
array_slice($temp_array,$offset) | |
); | |
$found = true; | |
} | |
$offset++; | |
} | |
if(!$found) $temp_array = array_merge($temp_array, array($key => $val)); | |
} | |
if ($sort_ascending) $array = array_reverse($temp_array); | |
else $array = $temp_array; | |
} | |
?> | ?> |
<?php | <?php |
include ('common.inc.php'); | include ('common.inc.php'); |
include_header("Routes", "routeList"); | function navbar() |
echo ' | { |
echo ' | |
<div data-role="navbar"> | <div data-role="navbar"> |
<ul> | <ul> |
<li><a href="routeList.php">By Final Destination...</a></li> | <li><a href="routeList.php">By Final Destination...</a></li> |
<li><a href="routeList.php?bynumber=yes">By Number... </a></li> | <li><a href="routeList.php?bynumber=yes">By Number... </a></li> |
<li><a href="routeList.php?bysuburb=yes">By Suburb... </a></li> | <li><a href="routeList.php?bysuburb=yes">By Suburb... </a></li> |
<li><a href="routeList.php?nearby=yes">Nearby... </a></li> | <li><a href="routeList.php?nearby=yes">Nearby... </a></li> |
</ul> | </ul> |
</div> | </div> |
'; | '; |
echo ' <ul data-role="listview" data-inset="true">'; | } |
$url = $APIurl . "/json/routes"; | if ($_REQUEST['bysuburb']) { |
$contents = json_decode(getPage($url)); | include_header("Routes by Suburb", "routeList"); |
function printRoutes($routes) | navbar(); |
{ | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
foreach ($suburbs as $suburb) { | |
if (!isset($_REQUEST['firstLetter'])) { | |
foreach (range('A', 'Z') as $letter) { | |
echo "<li><a href=\"routeList.php?firstLetter=$letter&bysuburb=yes\">$letter...</a></li>\n"; | |
} | |
} | |
else if (startsWith($suburb, $_REQUEST['firstLetter'])) { | |
echo '<li><a href="routeList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | |
} | |
} | |
echo '</ul>'; | |
} | |
else if ($_REQUEST['nearby'] || $_REQUEST['suburb']) { | |
if ($_REQUEST['suburb']) { | |
$suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING); | |
$url = $APIurl . "/json/stopzonesearch?q=" . $suburb; | |
include_header("Routes by Suburb", "routeList"); | |
} | |
if ($_REQUEST['nearby']) { | |
$url = $APIurl . "/json/neareststops?lat={$_SESSION['lat']}&lon={$_SESSION['lon']}&limit=15"; | |
include_header("Routes Nearby", "routeList"); | |
} | |
$stops = json_decode(getPage($url)); | |
$routes = Array(); | |
foreach ($stops as $stop) { | |
$url = $APIurl . "/json/stoproutes?stop=" . $stop[0]; | |
$stoproutes = json_decode(getPage($url)); | |
foreach ($stoproutes as $route) { | |
if (!isset($routes[$route[0]])) $routes[$route[0]] = $route; | |
} | |
} | |
navbar(); | |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | |
sksort($routes, 1, true); | |
foreach ($routes as $row) { | foreach ($routes as $row) { |
echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; | echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[4]) . ")</a></li>\n"; |
} | } |
} | } |
if ($_REQUEST['bynumber']) { | else if ($_REQUEST['bynumber']) { |
include_header("Routes by Number", "routeList"); | |
navbar(); | |
echo ' <ul data-role="listview" data-inset="true">'; | |
$url = $APIurl . "/json/routes"; | |
$contents = json_decode(getPage($url)); | |
$routeSeries = Array(); | $routeSeries = Array(); |
$seriesRange = Array(); | $seriesRange = Array(); |
foreach ($contents as $key => $row) { | foreach ($contents as $key => $row) { |
foreach (explode(" ", $row[1]) as $routeNumber) { | foreach (explode(" ", $row[1]) as $routeNumber) { |
$seriesNum = substr($routeNumber, 0, -1) . "0"; | $seriesNum = substr($routeNumber, 0, -1) . "0"; |
if ($seriesNum == "0") $seriesNum = $routeNumber; | if ($seriesNum == "0") $seriesNum = $routeNumber; |
$finalDigit = substr($routeNumber, sizeof($routeNumber) - 1, 1); | $finalDigit = substr($routeNumber, sizeof($routeNumber) - 1, 1); |
if (isset($seriesRange[$seriesNum])) { | if (isset($seriesRange[$seriesNum])) { |
if ($finalDigit < $seriesRange[$seriesNum]['max']) $seriesRange[$seriesNum]['max'] = $routeNumber; | if ($finalDigit < $seriesRange[$seriesNum]['max']) $seriesRange[$seriesNum]['max'] = $routeNumber; |
if ($finalDigit > $seriesRange[$seriesNum]['min']) $seriesRange[$seriesNum]['min'] = $routeNumber; | if ($finalDigit > $seriesRange[$seriesNum]['min']) $seriesRange[$seriesNum]['min'] = $routeNumber; |
} | } |
else { | else { |
$seriesRange[$seriesNum]['max'] = $routeNumber; | $seriesRange[$seriesNum]['max'] = $routeNumber; |
$seriesRange[$seriesNum]['min'] = $routeNumber; | $seriesRange[$seriesNum]['min'] = $routeNumber; |
} | } |
$routeSeries[$seriesNum][$seriesNum . "-" . $row[1] . "-" . $row[0]] = $row; | $routeSeries[$seriesNum][$seriesNum . "-" . $row[1] . "-" . $row[0]] = $row; |
} | } |
} | } |
ksort($routeSeries); | ksort($routeSeries); |
ksort($seriesRange); | ksort($seriesRange); |
echo '<div class="noscriptnav"> Go to route numbers: '; | echo '<div class="noscriptnav"> Go to route numbers: '; |
foreach ($seriesRange as $series => $range) { | foreach ($seriesRange as $series => $range) { |
if ($range['min'] == $range['max']) echo "<a href=\"#$series\">$series</a> "; | if ($range['min'] == $range['max']) echo "<a href=\"#$series\">$series</a> "; |
else echo "<a href=\"#$series\">{$range['min']}-{$range['max']}</a> "; | else echo "<a href=\"#$series\">{$range['min']}-{$range['max']}</a> "; |
} | } |
echo "</div> | echo "</div> |
<script> | <script> |
$('.noscriptnav').hide(); | $('.noscriptnav').hide(); |
</script>"; | </script>"; |
foreach ($routeSeries as $series => $routes) { | foreach ($routeSeries as $series => $routes) { |
echo '<a name="' . $series . '"></a>'; | echo '<a name="' . $series . '"></a>'; |
if ($series <= 9) echo '<li>' . $series . "<ul>\n"; | if ($series <= 9) echo '<li>' . $series . "<ul>\n"; |
else echo "<li>{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}<ul>\n"; | else echo "<li>{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}<ul>\n"; |
printRoutes($routes); | foreach ($routes as $row) { |
echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; | |
} | |
echo "</ul></li>\n"; | echo "</ul></li>\n"; |
} | } |
} | } |
else { | else { |
include_header("Routes by Destination", "routeList"); | |
navbar(); | |
echo ' <ul data-role="listview" data-inset="true">'; | |
$url = $APIurl . "/json/routes"; | |
$contents = json_decode(getPage($url)); | |
// by destination! | |
foreach ($contents as $key => $row) { | foreach ($contents as $key => $row) { |
$routeDestinations[$row[2]][] = $row; | $routeDestinations[$row[2]][] = $row; |
} | } |
echo '<div class="noscriptnav"> Go to Destination: '; | echo '<div class="noscriptnav"> Go to Destination: '; |
foreach (ksort($routeDestinations) as $destination => $routes) { | foreach (ksort($routeDestinations) as $destination => $routes) { |
echo "<a href=\"#$destination\">$destination</a> "; | echo "<a href=\"#$destination\">$destination</a> "; |
} | } |
echo "</div> | echo "</div> |
<script> | <script> |
$('.noscriptnav').hide(); | $('.noscriptnav').hide(); |
</script>"; | </script>"; |
foreach ($routeDestinations as $destination => $routes) { | foreach ($routeDestinations as $destination => $routes) { |
echo '<a name="' . $destination . '"></a>'; | echo '<a name="' . $destination . '"></a>'; |
echo '<li>' . $destination . "... <ul>\n"; | echo '<li>' . $destination . "... <ul>\n"; |
printRoutes($routes); | foreach ($routes as $row) { |
echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; | |
} | |
echo "</ul></li>\n"; | echo "</ul></li>\n"; |
} | } |
} | } |
echo "</ul>\n"; | echo "</ul>\n"; |
include_footer(); | include_footer(); |
?> | ?> |
#!/usr/bin/python2.5 | #!/usr/bin/python2.5 |
# Copyright (C) 2007 Google Inc. | # Copyright (C) 2007 Google Inc. |
# | # |
# Licensed under the Apache License, Version 2.0 (the "License"); | # Licensed under the Apache License, Version 2.0 (the "License"); |
# you may not use this file except in compliance with the License. | # you may not use this file except in compliance with the License. |
# You may obtain a copy of the License at | # You may obtain a copy of the License at |
# | # |
# http://www.apache.org/licenses/LICENSE-2.0 | # http://www.apache.org/licenses/LICENSE-2.0 |
# | # |
# Unless required by applicable law or agreed to in writing, software | # Unless required by applicable law or agreed to in writing, software |
# distributed under the License is distributed on an "AS IS" BASIS, | # distributed under the License is distributed on an "AS IS" BASIS, |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
# See the License for the specific language governing permissions and | # See the License for the specific language governing permissions and |
# limitations under the License. | # limitations under the License. |
""" | """ |
An example application that uses the transitfeed module. | An example application that uses the transitfeed module. |
You must provide a Google Maps API key. | You must provide a Google Maps API key. |
""" | """ |
import BaseHTTPServer, sys, urlparse | import BaseHTTPServer, sys, urlparse |
import bisect | import bisect |
from gtfsscheduleviewer.marey_graph import MareyGraph | from gtfsscheduleviewer.marey_graph import MareyGraph |
import gtfsscheduleviewer | import gtfsscheduleviewer |