--- a/stopList.php +++ b/stopList.php @@ -1,5 +1,6 @@ ' . $suburb . ''; - flush(); @ob_flush(); } } } @@ -41,14 +41,14 @@ // Timing Points / All stops if ($_REQUEST['allstops']) { $listType = 'allstops=yes'; - $url = $APIurl . "/json/stops"; + $stops = getStops(); include_header("All Stops", "stopList"); navbar(); timePlaceSettings(); } else if ($_REQUEST['nearby']) { $listType = 'nearby=yes'; - $url = $APIurl . "/json/neareststops?lat={$_SESSION['lat']}&lon={$_SESSION['lon']}&limit=15"; + $stops = getNearbyStops($_SESSION['lat'],$_SESSION['lon'],15); include_header("Nearby Stops", "stopList", true, true); navbar(); timePlaceSettings(true); @@ -59,14 +59,13 @@ } else if ($_REQUEST['suburb']) { $suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING); - $listType = "suburb=$suburb"; - $url = $APIurl . "/json/stopzonesearch?q=" . $suburb; + $stops = getStopsBySuburb($suburb); include_header("Stops in " . ucwords($suburb) , "stopList"); navbar(); trackEvent("Stop Lists","Stops By Suburb", $suburb); } else { - $url = $APIurl . "/json/timingpoints"; + $stops = getStops(true,$_REQUEST['firstLetter']); include_header("Timing Points / Major Stops", "stopList"); navbar(); timePlaceSettings(); @@ -78,29 +77,21 @@ } } else { - $stops = json_decode(getPage($url)); - foreach ($stops as $key => $row) { - $stopName[$key] = $row[1]; - } - // Sort the stops by name - array_multisort($stopName, SORT_ASC, $stops); - if (!isset($_REQUEST['suburb']) && !isset($_REQUEST['nearby'])) { - $stops = array_filter($stops, "filterByFirstLetter"); - } + //var_dump($stops); $stopsGrouped = Array(); - foreach ($stops as $key => $row) { - if ((trim(preg_replace("/\(Platform.*/", "", $stops[$key][1])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key + 1][1]))) || $key + 1 >= sizeof($stops)) { + foreach ($stops as $key => $stop) { + if ((trim(preg_replace("/\(Platform.*/", "", $stops[$key]["stop_name"])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key + 1]["stop_name"]))) || $key + 1 >= sizeof($stops)) { if (sizeof($stopsGrouped) > 0) { // print and empty grouped stops // subsequent duplicates - $stopsGrouped["stop_ids"][] = $row[0]; + $stopsGrouped["stop_ids"][] = $stop['stop_id']; echo '
  • '; if (!startsWith($stopsGrouped['stop_codes'][0], "Wj")) echo 'Timing Point: '; echo ''; if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { - echo '' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; + echo '' . distance($stop['stop_lat'],$stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; } - echo bracketsMeanNewLine(trim(preg_replace("/\(Platform.*/", "", $row[1])) . '(' . sizeof($stopsGrouped["stop_ids"]) . ' stops)'); + echo bracketsMeanNewLine(trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])) . '(' . sizeof($stopsGrouped["stop_ids"]) . ' stops)'); echo "
  • \n"; flush(); @ob_flush(); $stopsGrouped = Array(); @@ -108,33 +99,33 @@ else { // just a normal stop echo '
  • '; - if (!startsWith($row[5], "Wj")) echo 'Timing Point'; - echo ''; + if (!startsWith($stop['stop_code'], "Wj")) echo 'Timing Point'; + echo ''; if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { - echo '' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; + echo '' . distance($stop['stop_lat'],$stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; } - echo bracketsMeanNewLine($row[1]); + echo bracketsMeanNewLine($stop['stop_name']); echo "
  • \n"; flush(); @ob_flush(); } } else { // this is a duplicated line item - if ($key - 1 <= 0 || (trim(preg_replace("/\(Platform.*/", "", $stops[$key][1])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key - 1][1])))) { + if ($key - 1 <= 0 || (trim(preg_replace("/\(Platform.*/", "", $stops[$key]['stop_name'])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key - 1]['stop_name'])))) { // first duplicate $stopsGrouped = Array( - "name" => trim(preg_replace("/\(Platform.*/", "", $row[1])) , + "name" => trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])) , "stop_ids" => Array( - $row[0] + $stop['stop_id'] ) , "stop_codes" => Array( - $row[5] + $stop['stop_code'] ) ); } else { // subsequent duplicates - $stopsGrouped["stop_ids"][] = $row[0]; + $stopsGrouped["stop_ids"][] = $stop['stop_id'];; } } }