diff --git a/website/plugin-rpc/tfl/bus-sequences.csv b/website/plugin-rpc/tfl/bus-sequences.csv new file mode 120000 index 00000000..306122ac --- /dev/null +++ b/website/plugin-rpc/tfl/bus-sequences.csv @@ -0,0 +1 @@ +/home/jon/tfl/bus-sequences.csv \ No newline at end of file diff --git a/website/plugin-rpc/tfl/bus-stops.csv b/website/plugin-rpc/tfl/bus-stops.csv new file mode 120000 index 00000000..efb7cd0e --- /dev/null +++ b/website/plugin-rpc/tfl/bus-stops.csv @@ -0,0 +1 @@ +/home/jon/tfl/bus-stops.csv \ No newline at end of file diff --git a/website/plugin-rpc/tfl/index.php b/website/plugin-rpc/tfl/index.php new file mode 100644 index 00000000..061a1e15 --- /dev/null +++ b/website/plugin-rpc/tfl/index.php @@ -0,0 +1,131 @@ +routes[$rt])) + $this->routes[$rt] = Array(); + + if (!in_array($run,$this->routes[$rt],TRUE)) + array_push($this->routes[$rt], $run); + } + +} + + +class Stops { + var $route; + var $run; + var $stops = Array(); + + function route_run($route,$run) { + $this->route = $route; + $this->run = $run; + } + + function add_stop($row) { + if ($row['Route'] == $this->route && $row['Run'] == $this->run) { + + $easting = (int)$row['Location_Easting']; + $northing = (int)$row['Location_Northing']; + + $os = new OSRef($easting, $northing); + $latlng = $os->toLatLng(); + + $stop = Array ( + 'bus_stop_code' => $row['Bus_Stop_Code'], + 'stop_name' => $row['Stop_Name'], + 'location_os' => Array('easting'=>$easting,'northing'=>$northing), + 'location' => Array('lat' => $latlng->lat, 'lng' => $latlng->lng), + 'heading' => (int)$row['Heading'], + 'virtual_bus_stop' => (int)$row['Virtual_Bus_Stop'] + ); + + array_push($this->stops, $stop); + } + } + +}; + +$result = Array(); + +switch ($_REQUEST['method']) { + + case 'bus-routes': + $routes = new Routes(); + + load_csv_callback("bus-sequences.csv", Array($routes,'add_route')); + + $result = Array('bus-routes'=>$routes->routes); + + break; + + case 'bus-stops': + $route = $_REQUEST['route']; + $run = (int)$_REQUEST['run']; + $stops = new Stops(); + $stops->route_run($route, $run); + + load_csv_callback("bus-sequences.csv", Array($stops,'add_stop')); + + $result = Array('route' => $route, 'run' => $run, 'stops' => $stops->stops); + + break; + + default: + $result = Array('error'=>'Method not found'); + break; +} + + +if (isset($_REQUEST['jsonp'])) + header("Content-Type: application/javascript"); +else + header("Content-Type: application/json"); + + +if (isset($_REQUEST['jsonp'])) + print($_REQUEST['jsonp']."("); + +print json_encode($result); + +if (isset($_REQUEST['jsonp'])) + print(");"); + + +?>