<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
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. |
*/ | */ |
$service_periods = Array( | $service_periods = Array( |
'sunday', | 'sunday', |
'saturday', | 'saturday', |
'weekday' | 'weekday' |
); | ); |
function service_period($date = "") { | function service_period($date = "") { |
if (isset($_REQUEST['service_period'])) { | if (isset($_REQUEST['service_period'])) { |
return $_REQUEST['service_period']; | return $_REQUEST['service_period']; |
} | } |
$override = getServiceOverride($date); | $override = getServiceOverride($date); |
if (isset($override['service_id'])) { | if (isset($override['service_id'])) { |
return strtolower($override['service_id']); | return strtolower($override['service_id']); |
} | } |
$date = ($date != "" ? $date : time()); | $date = ($date != "" ? $date : time()); |
$dow = date('w', $date); | $dow = date('w', $date); |
switch ($dow) { | switch ($dow) { |
case 0: | case 0: |
return 'sunday'; | return 'sunday'; |
case 6: | case 6: |
return 'saturday'; | return 'saturday'; |
default: | default: |
return 'weekday'; | return 'weekday'; |
} | } |
} | } |
function service_ids($service_period, $date = "") { | function service_ids($service_period, $date = "") { |
switch ($service_period) { | switch ($service_period) { |
case 'sunday': | case 'sunday': |
return Array("Sunday", "Sunday"); | return Array("Sunday", "Sunday"); |
case 'saturday': | case 'saturday': |
return Array("Saturday", "Saturday"); | return Array("Saturday", "Saturday"); |
default: | default: |
$date = ($date != "" ? $date : time()); | $date = ($date != "" ? $date : time()); |
// school holidays | // school holidays |
$ymd = date('Ymd', $date); | $ymd = date('Ymd', $date); |
$dow = date('w', $date); | $dow = date('w', $date); |
if (intval($ymd) < "20120203" && $dow != 0 && $dow != 6) { | if (intval($ymd) < "20120203" && $dow != 0 && $dow != 6) { |
return Array("Weekday-SchoolVacation", "Weekday-SchoolVacation"); | return Array("Weekday-SchoolVacation", "Weekday-SchoolVacation"); |
} else { | } else { |
return Array("Weekday", "Weekday"); | return Array("Weekday", "Weekday"); |
} | } |
} | } |
} | } |
function valid_service_ids() { | function valid_service_ids() { |
return array_merge(service_ids(""), service_ids('saturday'), service_ids('sunday')); | return array_merge(service_ids(""), service_ids('saturday'), service_ids('sunday')); |
} | } |
function midnight_seconds($time = "") { | function midnight_seconds($time = "") { |
// from http://www.perturb.org/display/Perlfunc__Seconds_Since_Midnight.html | // from http://www.perturb.org/display/Perlfunc__Seconds_Since_Midnight.html |
if ($time != "") { | if ($time != "") { |
return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); | return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); |
} | } |
if (isset($_SESSION['time'])) { | if (isset($_SESSION['time'])) { |
$time = strtotime($_SESSION['time']); | $time = strtotime($_SESSION['time']); |
return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); | return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); |
} | } |
return (date("G") * 3600) + (date("i") * 60) + date("s"); | return (date("G") * 3600) + (date("i") * 60) + date("s"); |
} | } |
function midnight_seconds_to_time($seconds) { | function midnight_seconds_to_time($seconds) { |
if ($seconds > 0) { | if ($seconds > 0) { |
$midnight = mktime(0, 0, 0, date("n"), date("j"), date("Y")); | $midnight = mktime(0, 0, 0, date("n"), date("j"), date("Y")); |
return date("h:ia", $midnight + $seconds); | return date("h:ia", $midnight + $seconds); |
} else { | } else { |
return ""; | return ""; |
} | } |
} | } |
if ($GTFSREnabled) { | if ($GTFSREnabled) { |
$serviceAlertCause = Array( | $serviceAlertCause = Array( |
"UNKNOWN_CAUSE" => "Unknown cause", | "UNKNOWN_CAUSE" => "Unknown cause", |
"OTHER_CAUSE" => "Other cause", | "OTHER_CAUSE" => "Other cause", |
"TECHNICAL_PROBLEM" => "Technical problem", | "TECHNICAL_PROBLEM" => "Technical problem", |
"STRIKE" => "Strike", | "STRIKE" => "Strike", |
"DEMONSTRATION" => "Demonstration", | "DEMONSTRATION" => "Demonstration", |
"ACCIDENT" => "Accident", | "ACCIDENT" => "Accident", |
"HOLIDAY" => "Holiday", | "HOLIDAY" => "Holiday", |
"WEATHER" => "Weather", | "WEATHER" => "Weather", |
"MAINTENANCE" => "Maintenance", | "MAINTENANCE" => "Maintenance", |
"CONSTRUCTION" => "Construction", | "CONSTRUCTION" => "Construction", |
"POLICE_ACTIVITY" => "Police activity", | "POLICE_ACTIVITY" => "Police activity", |
"MEDICAL_EMERGENCY" => "Medical emergency" | "MEDICAL_EMERGENCY" => "Medical emergency" |
); | ); |
$serviceAlertEffect = Array( | $serviceAlertEffect = Array( |
"NO_SERVICE" => "No service", | "NO_SERVICE" => "No service", |
"REDUCED_SERVICE" => "Reduced service", | "REDUCED_SERVICE" => "Reduced service", |
"SIGNIFICANT_DELAYS" => "Significant delays", | "SIGNIFICANT_DELAYS" => "Significant delays", |
"DETOUR" => "Detour", | "DETOUR" => "Detour", |
"ADDITIONAL_SERVICE" => "Additional service", | "ADDITIONAL_SERVICE" => "Additional service", |
"MODIFIED_SERVICE" => "Modified service", | "MODIFIED_SERVICE" => "Modified service", |
"OTHER_EFFECT" => "Other effect", | "OTHER_EFFECT" => "Other effect", |
"UNKNOWN_EFFECT" => "Unknown effect", | "UNKNOWN_EFFECT" => "Unknown effect", |
"STOP_MOVED" => "Stop moved"); | "STOP_MOVED" => "Stop moved"); |
set_include_path(get_include_path() . PATH_SEPARATOR . ($basePath . "lib/Protobuf-PHP/library/DrSlump/")); | set_include_path(get_include_path() . PATH_SEPARATOR . ($basePath . "lib/Protobuf-PHP/library/DrSlump/")); |
include_once("Protobuf.php"); | include_once("Protobuf.php"); |
include_once("Protobuf/Message.php"); | include_once("Protobuf/Message.php"); |
include_once("Protobuf/Registry.php"); | include_once("Protobuf/Registry.php"); |
include_once("Protobuf/Descriptor.php"); | include_once("Protobuf/Descriptor.php"); |
include_once("Protobuf/Field.php"); | include_once("Protobuf/Field.php"); |
include_once($basePath . "lib/Protobuf-PHP/gtfs-realtime.php"); | include_once($basePath . "lib/Protobuf-PHP/gtfs-realtime.php"); |
include_once("Protobuf/CodecInterface.php"); | include_once("Protobuf/CodecInterface.php"); |
include_once("Protobuf/Codec/PhpArray.php"); | include_once("Protobuf/Codec/PhpArray.php"); |
include_once("Protobuf/Codec/Binary.php"); | include_once("Protobuf/Codec/Binary.php"); |
include_once("Protobuf/Codec/Binary/Writer.php"); | include_once("Protobuf/Codec/Binary/Writer.php"); |
include_once("Protobuf/Codec/Json.php"); | include_once("Protobuf/Codec/Json.php"); |
function getServiceAlerts($filter_class = "", $filter_id = "") { | function getServiceAlerts($filter_class = "", $filter_id = "") { |
/* | /* |
also need last modified epoch of client gtfs | also need last modified epoch of client gtfs |
- add,remove,patch,inform (null) | - add,remove,patch,inform (null) |
- stop | - stop |
- trip | - trip |
- network | - network |
- classes (WHERE=) | - classes (WHERE=) |
- route (short_name or route_id) | - route (short_name or route_id) |
- street | - street |
- stop | - stop |
- trip | - trip |
Currently support: | Currently support: |
network inform | network inform |
trip patch: stop remove | trip patch: stop remove |
street inform: route inform, trip inform, stop inform | street inform: route inform, trip inform, stop inform |
route patch: trip remove | route patch: trip remove |
*/ | */ |
$current_alerts = getCurrentAlerts(); | $current_alerts = getCurrentAlerts(); |
$informed_count = 0; | $informed_count = 0; |
if (sizeof($current_alerts) > 0) { | if (sizeof($current_alerts) > 0) { |
$fm = new transit_realtime\FeedMessage(); | $fm = new transit_realtime\FeedMessage(); |
$fh = new transit_realtime\FeedHeader(); | $fh = new transit_realtime\FeedHeader(); |
$fh->setGtfsRealtimeVersion(1); | $fh->setGtfsRealtimeVersion(1); |
$fh->setTimestamp(time()); | $fh->setTimestamp(time()); |
$fm->setHeader($fh); | $fm->setHeader($fh); |
foreach ($current_alerts as $current_alert) { | foreach ($current_alerts as $current_alert) { |
$affectsFilteredEntities = false; | $affectsFilteredEntities = false; |
$fe = new transit_realtime\FeedEntity(); | $fe = new transit_realtime\FeedEntity(); |
$fe->setId($current_alert['id']); | $fe->setId($current_alert['id']); |
$fe->setIsDeleted(false); | $fe->setIsDeleted(false); |
$alert = new transit_realtime\Alert(); | $alert = new transit_realtime\Alert(); |
$tr = new transit_realtime\TimeRange(); | $tr = new transit_realtime\TimeRange(); |
$tr->setStart($current_alert['start']); | $tr->setStart($current_alert['start']); |
$tr->setEnd($current_alert['end']); | $tr->setEnd($current_alert['end']); |
$alert->addActivePeriod($tr); | $alert->addActivePeriod($tr); |
$informedEntities = getInformedAlerts($current_alert['id'], $filter_class, $filter_id); | $informedEntities = getInformedAlerts($current_alert['id'], $filter_class, $filter_id); |
if (sizeof($informedEntities) > 0) { | if (sizeof($informedEntities) > 0) { |
$affectsFilteredEntities = true; | $affectsFilteredEntities = true; |
$informed_count++; | foreach ($informedEntities as $informedEntity) { |
$informed_count++; | |
$informed = Array(); | $informed = Array(); |
$es = new transit_realtime\EntitySelector(); | $es = new transit_realtime\EntitySelector(); |
if ($informedEntity['informed_class'] == "agency") { | if ($informedEntity['informed_class'] == "agency") { |
$es->setAgencyId($informedEntity['informed_id']); | $es->setAgencyId($informedEntity['informed_id']); |
} | } |
if ($informedEntity['informed_class'] == "stop") { | if ($informedEntity['informed_class'] == "stop") { |
$es->setStopId($informedEntity['informed_id']); | $es->setStopId($informedEntity['informed_id']); |
} | } |
if ($informedEntity['informed_class'] == "route") { | if ($informedEntity['informed_class'] == "route") { |
$es->setRouteId($informedEntity['informed_id']); | $es->setRouteId($informedEntity['informed_id']); |
} | } |
if ($informedEntity['informed_class'] == "trip") { | if ($informedEntity['informed_class'] == "trip") { |
$td = new transit_realtime\TripDescriptor(); | $td = new transit_realtime\TripDescriptor(); |
$td->setTripId($informedEntity['informed_id']); | $td->setTripId($informedEntity['informed_id']); |
$es->setTrip($td); | $es->setTrip($td); |
} | } |
$alert->addInformedEntity($es); | $alert->addInformedEntity($es); |
} | |
} | } |
if ($current_alert['cause'] != "") { | if ($current_alert['cause'] != "") { |
$alert->setCause(constant("transit_realtime\Alert\Cause::" . $current_alert['cause'])); | $alert->setCause(constant("transit_realtime\Alert\Cause::" . $current_alert['cause'])); |
} | } |
if ($current_alert['effect'] != "") { | if ($current_alert['effect'] != "") { |
$alert->setEffect(constant("transit_realtime\Alert\Effect::" . $current_alert['effect'])); | $alert->setEffect(constant("transit_realtime\Alert\Effect::" . $current_alert['effect'])); |
} | } |
if ($current_alert['url'] != "") { | if ($current_alert['url'] != "") { |
$tsUrl = new transit_realtime\TranslatedString(); | $tsUrl = new transit_realtime\TranslatedString(); |
$tUrl = new transit_realtime\TranslatedString\Translation(); | $tUrl = new transit_realtime\TranslatedString\Translation(); |
$tUrl->setText($current_alert['url']); | $tUrl->setText($current_alert['url']); |
$tUrl->setLanguage("en"); | $tUrl->setLanguage("en"); |
$tsUrl->addTranslation($tUrl); | $tsUrl->addTranslation($tUrl); |
$alert->setUrl($tsUrl); | $alert->setUrl($tsUrl); |
} | } |
if ($current_alert['header'] != "") { | if ($current_alert['header'] != "") { |
$tsHeaderText = new transit_realtime\TranslatedString(); | $tsHeaderText = new transit_realtime\TranslatedString(); |
$tHeaderText = new transit_realtime\TranslatedString\Translation(); | $tHeaderText = new transit_realtime\TranslatedString\Translation(); |
$tHeaderText->setText($current_alert['header']); | $tHeaderText->setText($current_alert['header']); |
$tHeaderText->setLanguage("en"); | $tHeaderText->setLanguage("en"); |
$tsHeaderText->addTranslation($tHeaderText); | $tsHeaderText->addTranslation($tHeaderText); |
$alert->setHeaderText($tsHeaderText); | $alert->setHeaderText($tsHeaderText); |
} | } |
if ($current_alert['description'] != "") { | if ($current_alert['description'] != "") { |
$tsDescriptionText = new transit_realtime\TranslatedString(); | $tsDescriptionText = new transit_realtime\TranslatedString(); |
$tDescriptionText = new transit_realtime\TranslatedString\Translation(); | $tDescriptionText = new transit_realtime\TranslatedString\Translation(); |
$tDescriptionText->setText($current_alert['description']); | $tDescriptionText->setText(trim($current_alert['description'])); |
$tDescriptionText->setLanguage("en"); | $tDescriptionText->setLanguage("en"); |
$tsDescriptionText->addTranslation($tDescriptionText); | $tsDescriptionText->addTranslation($tDescriptionText); |
$alert->setDescriptionText($tsDescriptionText); | $alert->setDescriptionText($tsDescriptionText); |
} | } |
$fe->setAlert($alert); | $fe->setAlert($alert); |
if ($affectsFilteredEntities) { | if ($affectsFilteredEntities) { |
$fm->addEntity($fe); | $fm->addEntity($fe); |
} | } |
} | } |
if ($informed_count > 0) { | if ($informed_count > 0) { |
return $fm; | return $fm; |
} else { | } else { |
return null; | return null; |
} | } |
} else | } else |
return null; | return null; |
} | } |
function getServiceAlertsAsArray($filter_class = "", $filter_id = "") { | function getServiceAlertsAsArray($filter_class = "", $filter_id = "") { |
$alerts = getServiceAlerts($filter_class, $filter_id); | $alerts = getServiceAlerts($filter_class, $filter_id); |
if ($alerts != null) { | if ($alerts != null) { |
$codec = new DrSlump\Protobuf\Codec\PhpArray(); | $codec = new DrSlump\Protobuf\Codec\PhpArray(); |
return $codec->encode($alerts); | return $codec->encode($alerts); |
} else { | } else { |
return nullarray; | return nullarray; |
} | } |
} | } |
function getServiceAlertsAsBinary($filter_class = "", $filter_id = "") { | function getServiceAlertsAsBinary($filter_class = "", $filter_id = "") { |
$codec = new DrSlump\Protobuf\Codec\Binary(); | $codec = new DrSlump\Protobuf\Codec\Binary(); |
return $codec->encode(getServiceAlerts($filter_class, $filter_id)); | return $codec->encode(getServiceAlerts($filter_class, $filter_id)); |
} | } |
function getServiceAlertsAsJSON($filter_class = "", $filter_id = "") { | function getServiceAlertsAsJSON($filter_class = "", $filter_id = "") { |
$codec = new DrSlump\Protobuf\Codec\Json(); | $codec = new DrSlump\Protobuf\Codec\Json(); |
return $codec->encode(getServiceAlerts($filter_class, $filter_id)); | return $codec->encode(getServiceAlerts($filter_class, $filter_id)); |
} | } |
function getServiceAlertsByClass() { | function getServiceAlertsByClass() { |
$return = Array(); | $return = Array(); |
$alerts = getServiceAlertsAsArray("", ""); | $alerts = getServiceAlertsAsArray("", ""); |
foreach ($alerts['entities'] as $entity) { | foreach ($alerts['entities'] as $entity) { |
foreach ($entity['informed'] as $informed) { | foreach ($entity['informed'] as $informed) { |
foreach ($informed as $key => $value) { | foreach ($informed as $key => $value) { |
if (strpos("_id", $key) > 0) { | if (strpos("_id", $key) > 0) { |
$parts = explode($key); | $parts = explode($key); |
$class = $parts[0]; | $class = $parts[0]; |
$id = $value; | $id = $value; |
} | } |
} | } |
$return[$class][$id][] = $entity; | $return[$class][$id][] = $entity; |
} | } |
} | } |
} | } |
function getTripUpdates($filter_class = "", $filter_id = "") { | function getTripUpdates($filter_class = "", $filter_id = "") { |
$fm = new transit_realtime\FeedMessage(); | $fm = new transit_realtime\FeedMessage(); |
$fh = new transit_realtime\FeedHeader(); | $fh = new transit_realtime\FeedHeader(); |
$fh->setGtfsRealtimeVersion(1); | $fh->setGtfsRealtimeVersion(1); |
$fh->setTimestamp(time()); | $fh->setTimestamp(time()); |
$fm->setHeader($fh); | $fm->setHeader($fh); |
foreach (getCurrentAlerts() as $alert) { | foreach (getCurrentAlerts() as $alert) { |
$informedEntities = getInformedAlerts($alert['id'], $_REQUEST['filter_class'], $_REQUEST['filter_id']); | $informedEntities = getInformedAlerts($alert['id'], $_REQUEST['filter_class'], $_REQUEST['filter_id']); |
$stops = Array(); | $stops = Array(); |
$routestrips = Array(); | $routestrips = Array(); |
if (sizeof($informedEntities) > 0) { | if (sizeof($informedEntities) > 0) { |
if ($informedEntity['informed_class'] == "stop" && $informed["x-action"] == "remove") { | if ($informedEntity['informed_class'] == "stop" && $informed["x-action"] == "remove") { |
$stops[] = $informedEntity['informed_id']; | $stops[] = $informedEntity['informed_id']; |
} | } |
if (($informedEntity['informed_class'] == "route" || $informedEntity['informed_class'] == "trip") && $informed["x-action"] == "patch") { | if (($informedEntity['informed_class'] == "route" || $informedEntity['informed_class'] == "trip") && $informed["x-action"] == "patch") { |
$routestrips[] = Array("id" => $informedEntity['informed_id'], | $routestrips[] = Array("id" => $informedEntity['informed_id'], |
"type" => $informedEntity['informed_class']); | "type" => $informedEntity['informed_class']); |
} | } |
} | } |
foreach ($routestrips as $routetrip) { | foreach ($routestrips as $routetrip) { |
$fe = new transit_realtime\FeedEntity(); | $fe = new transit_realtime\FeedEntity(); |
$fe->setId($alert['id'] . $routetrip['id']); | $fe->setId($alert['id'] . $routetrip['id']); |
$fe->setIsDeleted(false); | $fe->setIsDeleted(false); |
$tu = new transit_realtime\TripUpdate(); | $tu = new transit_realtime\TripUpdate(); |
$td = new transit_realtime\TripDescriptor(); | $td = new transit_realtime\TripDescriptor(); |
if ($routetrip['type'] == "route") { | if ($routetrip['type'] == "route") { |
$td->setRouteId($routetrip['id']); | $td->setRouteId($routetrip['id']); |
} else if ($routetrip['type'] == "trip") { | } else if ($routetrip['type'] == "trip") { |
$td->setTripId($routetrip['id']); | $td->setTripId($routetrip['id']); |
} | } |
$tu->setTrip($td); | $tu->setTrip($td); |
foreach ($stops as $stop) { | foreach ($stops as $stop) { |
$stu = new transit_realtime\TripUpdate\StopTimeUpdate(); | $stu = new transit_realtime\TripUpdate\StopTimeUpdate(); |
$stu->setStopId($stop); | $stu->setStopId($stop); |
$stu->setScheduleRelationship(transit_realtime\TripUpdate\StopTimeUpdate\ScheduleRelationship::SKIPPED); | $stu->setScheduleRelationship(transit_realtime\TripUpdate\StopTimeUpdate\ScheduleRelationship::SKIPPED); |
$tu->addStopTimeUpdate($stu); | $tu->addStopTimeUpdate($stu); |
} | } |
$fe->setTripUpdate($tu); | $fe->setTripUpdate($tu); |
$fm->addEntity($fe); | $fm->addEntity($fe); |
} | } |
} | } |
return $fm; | return $fm; |
} | } |
function getTripUpdatesAsArray($filter_class = "", $filter_id = "") { | function getTripUpdatesAsArray($filter_class = "", $filter_id = "") { |
$codec = new DrSlump\Protobuf\Codec\PhpArray(); | $codec = new DrSlump\Protobuf\Codec\PhpArray(); |
return $codec->encode(getTripUpdates($filter_class, $filter_id)); | return $codec->encode(getTripUpdates($filter_class, $filter_id)); |
} | } |
function getTripUpdatesAsBinary($filter_class = "", $filter_id = "") { | function getTripUpdatesAsBinary($filter_class = "", $filter_id = "") { |
$codec = new DrSlump\Protobuf\Codec\Binary(); | $codec = new DrSlump\Protobuf\Codec\Binary(); |
return $codec->encode(getTripUpdates($filter_class, $filter_id)); | return $codec->encode(getTripUpdates($filter_class, $filter_id)); |
} | } |
function getTripUpdatesAsJSON($filter_class = "", $filter_id = "") { | function getTripUpdatesAsJSON($filter_class = "", $filter_id = "") { |
$codec = new DrSlump\Protobuf\Codec\Json(); | $codec = new DrSlump\Protobuf\Codec\Json(); |
return $codec->encode(getTripUpdates($filter_class, $filter_id)); | return $codec->encode(getTripUpdates($filter_class, $filter_id)); |
} | } |
} | } |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
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. |
*/ | */ |
date_default_timezone_set('Australia/ACT'); | date_default_timezone_set('Australia/ACT'); |
$debugOkay = Array( | $debugOkay = Array( |
"session", | "session", |
"json", | "json", |
"phperror", | "phperror", |
"awsotp", | "awsotp", |
//"squallotp", | //"squallotp", |
//"vanilleotp", | //"vanilleotp", |
"database", | "database", |
"other" | "other" |
); | ); |
$GTFSREnabled = true; | $GTFSREnabled = true; |
$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/'; |
if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com" || strstr(php_uname('n'),"actbus")) { | if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com" || strstr(php_uname('n'),"actbus")) { |
$otpAPIurl = 'http://bus-main.lambdacomplex.org:8080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://bus-main.lambdacomplex.org:8080/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("dotcloudotp") || php_uname('n') == "actbus-www") { | if (isDebug("dotcloudotp") || php_uname('n') == "actbus-www") { |
$otpAPIurl = 'http://otp.actbus.dotcloud.com/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://otp.actbus.dotcloud.com/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("squallotp")) { | if (isDebug("squallotp")) { |
$otpAPIurl = 'http://10.0.1.108:5080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://10.0.1.108:5080/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("vanilleotp")) { | if (isDebug("vanilleotp")) { |
$otpAPIurl = 'http://10.0.1.135:8080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://10.0.1.135:8080/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("phperror")) | if (isDebug("phperror")) |
error_reporting(E_ALL ^ E_NOTICE); | error_reporting(E_ALL ^ E_NOTICE); |
$basePath = ""; | $basePath = ""; |
if (strstr($_SERVER['PHP_SELF'], "labs/") | if (strstr($_SERVER['PHP_SELF'], "labs/") |
|| strstr($_SERVER['PHP_SELF'], "myway/") | || strstr($_SERVER['PHP_SELF'], "myway/") |
|| strstr($_SERVER['PHP_SELF'], "lib/") | || strstr($_SERVER['PHP_SELF'], "lib/") |
|| strstr($_SERVER['PHP_SELF'], "geo/") | || strstr($_SERVER['PHP_SELF'], "geo/") |
|| strstr($_SERVER['PHP_SELF'], "include/") | || strstr($_SERVER['PHP_SELF'], "include/") |
|| strstr($_SERVER['PHP_SELF'], "servicealerts/")) | || strstr($_SERVER['PHP_SELF'], "rtpis/")) { |
$basePath = "../"; | $basePath = "../"; |
} | |
function isDebugServer() { | function isDebugServer() { |
return php_sapi_name() == "cli" || strstr(php_uname('n'),"actbus") || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" | return php_sapi_name() == "cli" || strstr(php_uname('n'),"actbus") || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" |
|| $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "192.168.1.8" || $_SERVER['SERVER_NAME'] == "192.168.178.24"); | || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "192.168.1.8" || $_SERVER['SERVER_NAME'] == "192.168.178.24"); |
} | } |
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-transit.inc.php"); | include_once ("common-transit.inc.php"); |
if (!strstr($_SERVER['PHP_SELF'], "feedback")) { | if (!strstr($_SERVER['PHP_SELF'], "feedback")) { |
include_once ("common-db.inc.php"); | include_once ("common-db.inc.php"); |
} | } |
include_once ("common-request.inc.php"); | include_once ("common-request.inc.php"); |
include_once ("common-session.inc.php"); | include_once ("common-session.inc.php"); |
include_once ("common-auth.inc.php"); | include_once ("common-auth.inc.php"); |
include_once ("common-template.inc.php"); | include_once ("common-template.inc.php"); |
function isAnalyticsOn() { | function isAnalyticsOn() { |
$user_agent = $_SERVER['HTTP_USER_AGENT']; | $user_agent = $_SERVER['HTTP_USER_AGENT']; |
return !isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) && | return !isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) && |
!preg_match('/baidu/i', $user_agent); | !preg_match('/baidu/i', $user_agent); |
} | } |
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 debug($msg, $debugReason = "other") { | function debug($msg, $debugReason = "other") { |
if (isDebug($debugReason)) | if (isDebug($debugReason)) |
echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n"; | echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n"; |
} | } |
function isIOSDevice() { | function isIOSDevice() { |
return strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad'); | return strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad'); |
} | } |
function isJQueryMobileDevice() { | function isJQueryMobileDevice() { |
// http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 | // http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 |
$user_agent = $_SERVER['HTTP_USER_AGENT']; | $user_agent = $_SERVER['HTTP_USER_AGENT']; |
return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); | return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); |
} | } |
function array_flatten($a, $f = array()) { | function array_flatten($a, $f = array()) { |
if (!$a || !is_array($a)) | if (!$a || !is_array($a)) |
return ''; | return ''; |
foreach ($a as $k => $v) { | foreach ($a as $k => $v) { |
if (is_array($v)) | if (is_array($v)) |
$f = array_flatten($v, $f); | $f = array_flatten($v, $f); |
else | else |
$f[$k] = $v; | $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 sksort(&$array, $subkey = "id", $sort_ascending = false) { | function sksort(&$array, $subkey = "id", $sort_ascending = false) { |
if (count($array)) | if (count($array)) |
$temp_array[key($array)] = array_shift($array); | $temp_array[key($array)] = array_shift($array); |
foreach ($array as $key => $val) { | foreach ($array as $key => $val) { |
$offset = 0; | $offset = 0; |
$found = false; | $found = false; |
foreach ($temp_array as $tmp_key => $tmp_val) { | foreach ($temp_array as $tmp_key => $tmp_val) { |
if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { | if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { |
$temp_array = array_merge((array) array_slice($temp_array, 0, $offset), array( | $temp_array = array_merge((array) array_slice($temp_array, 0, $offset), array( |
$key => $val | $key => $val |
), array_slice($temp_array, $offset)); | ), array_slice($temp_array, $offset)); |
$found = true; | $found = true; |
} | } |
$offset++; | $offset++; |
} | } |
if (!$found) | if (!$found) |
$temp_array = array_merge($temp_array, array( | $temp_array = array_merge($temp_array, array( |
$key => $val | $key => $val |
)); | )); |
} | } |
if ($sort_ascending) | if ($sort_ascending) |
$array = array_reverse($temp_array); | $array = array_reverse($temp_array); |
else | else |
$array = $temp_array; | $array = $temp_array; |
} | } |
function sktimesort(&$array, $subkey = "id", $sort_ascending = false) { | function sktimesort(&$array, $subkey = "id", $sort_ascending = false) { |
if (count($array)) | if (count($array)) |
$temp_array[key($array)] = array_shift($array); | $temp_array[key($array)] = array_shift($array); |
foreach ($array as $key => $val) { | foreach ($array as $key => $val) { |
$offset = 0; | $offset = 0; |
$found = false; | $found = false; |
foreach ($temp_array as $tmp_key => $tmp_val) { | foreach ($temp_array as $tmp_key => $tmp_val) { |
if (!$found and strtotime($val[$subkey]) > strtotime($tmp_val[$subkey])) { | if (!$found and strtotime($val[$subkey]) > strtotime($tmp_val[$subkey])) { |
$temp_array = array_merge((array) array_slice($temp_array, 0, $offset), array( | $temp_array = array_merge((array) array_slice($temp_array, 0, $offset), array( |
$key => $val | $key => $val |
), array_slice($temp_array, $offset)); | ), array_slice($temp_array, $offset)); |
$found = true; | $found = true; |
} | } |
$offset++; | $offset++; |
} | } |
if (!$found) | if (!$found) |
$temp_array = array_merge($temp_array, array( | $temp_array = array_merge($temp_array, array( |
$key => $val | $key => $val |
)); | )); |
} | } |
if ($sort_ascending && isset($temp_array)) | if ($sort_ascending && isset($temp_array)) |
$array = array_reverse($temp_array); | $array = array_reverse($temp_array); |
else | else |
$array = $temp_array; | $array = $temp_array; |
} | } |
function r_implode($glue, $pieces) { | function r_implode($glue, $pieces) { |
foreach ($pieces as $r_pieces) { | foreach ($pieces as $r_pieces) { |
if (is_array($r_pieces)) { | if (is_array($r_pieces)) { |
$retVal[] = r_implode($glue, $r_pieces); | $retVal[] = r_implode($glue, $r_pieces); |
} else { | } else { |
$retVal[] = $r_pieces; | $retVal[] = $r_pieces; |
} | } |
} | } |
return implode($glue, $retVal); | return implode($glue, $retVal); |
} | } |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
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. |
*/ | */ |
include ('include/common.inc.php'); | include ('../include/common.inc.php'); |
function accept_header($header = false) { | function accept_header($header = false) { |
// http://jrgns.net/parse_http_accept_header | // http://jrgns.net/parse_http_accept_header |
$toret = null; | $toret = null; |
$header = $header ? $header : (array_key_exists('HTTP_ACCEPT', $_SERVER) ? $_SERVER['HTTP_ACCEPT']: false); | $header = $header ? $header : (array_key_exists('HTTP_ACCEPT', $_SERVER) ? $_SERVER['HTTP_ACCEPT']: false); |
if ($header) { | if ($header) { |
$types = explode(',', $header); | $types = explode(',', $header); |
$types = array_map('trim', $types); | $types = array_map('trim', $types); |
foreach ($types as $one_type) { | foreach ($types as $one_type) { |
$one_type = explode(';', $one_type); | $one_type = explode(';', $one_type); |
$type = array_shift($one_type); | $type = array_shift($one_type); |
if ($type) { | if ($type) { |
list($precedence, $tokens) = self::accept_header_options($one_type); | list($precedence, $tokens) = self::accept_header_options($one_type); |
list($main_type, $sub_type) = array_map('trim', explode('/', $type)); | list($main_type, $sub_type) = array_map('trim', explode('/', $type)); |
$toret[] = array('main_type' => $main_type, 'sub_type' => $sub_type, 'precedence' => (float)$precedence, 'tokens' => $tokens); | $toret[] = array('main_type' => $main_type, 'sub_type' => $sub_type, 'precedence' => (float)$precedence, 'tokens' => $tokens); |
} | } |
} | } |
usort($toret, array('Parser', 'compare_media_ranges')); | usort($toret, array('Parser', 'compare_media_ranges')); |
} | } |
return $toret; | return $toret; |
} | } |
function usage() { | |
echo "Usage notes: Must specify format json/protobuf and gtfs-realtime feedtype alerts/updates. If callback is specified, will provide jsonp. Can filter with parmaters filter_class route/stop and filter_id with the id specified in GTFS."; | |
die(); | |
} | |
$filter_class = (isset($_REQUEST['filter_class']) ? $_REQUEST['filter_class'] : ""); | |
$filter_id = (isset($_REQUEST['filter_id']) ? $_REQUEST['filter_id']:""); | |
$json_types = Array("application/json","application/x-javascript","text/javascript","text/x-javascript","text/x-json"); | $json_types = Array("application/json","application/x-javascript","text/javascript","text/x-javascript","text/x-json"); |
if ($_REQUEST['json']) { | if ($_REQUEST['json']) { |
$return = getServiceAlertsAsJSON($_REQUEST['filter_class'], $_REQUEST['filter_id']); | if ($_REQUEST['alerts']) { |
$return = getServiceAlertsAsJSON($filter_class,$filter_id); | |
} else if ($_REQUEST['updates']) { | |
$return = getTripUpdatesAsJSON($filter_class,$filter_id); | |
} else { | |
usage(); | |
} | |
header('Content-Type: application/json; charset=utf8'); | header('Content-Type: application/json; charset=utf8'); |
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); | // header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); |
header('Access-Control-Max-Age: 3628800'); | header('Access-Control-Max-Age: 3628800'); |
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); | header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); |
if (isset($_GET['callback'])) { | if (isset($_GET['callback'])) { |
$json = '(' . $return . ');'; //must wrap in parens and end with semicolon | $json = '(' . $return . ');'; //must wrap in parens and end with semicolon |
//print_r($_GET['callback'] . $json); //callback is prepended for json-p | //print_r($_GET['callback'] . $json); //callback is prepended for json-p |
} | } |
else | else { |
echo $return; | echo $return; |
} | |
} else if ($_REQUEST['protobuf']) { | |
if ($_REQUEST['alerts']) { | |
$return = getServiceAlertsAsBinary($filter_class,$filter_id); | |
} else if ($_REQUEST['updates']) { | |
$return = getTripUpdatesAsBinary($filter_class,$filter_id); | |
} else { | |
usage(); | |
} | |
header('Content-Type: application/x-protobuf'); | |
header('Content-Disposition: attachment; filename="'.(isset($_REQUEST['updates'])?"updates.":"alerts.").date("c").'.protobuf"'); | |
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); | |
header('Access-Control-Max-Age: 3628800'); | |
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); | |
echo $return; | |
} else { | |
usage(); | |
} | } |
?> | ?> |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
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. |
*/ | */ |
include ('../include/common.inc.php'); | include ('../include/common.inc.php'); |
auth(); | auth(); |
include_header("Service Alert Editor", "serviceAlertEditor"); | include_header("Service Alert Editor", "serviceAlertEditor"); |
/** | /** |
* Currently support: | * Currently support: |
* network inform | * network inform |
* stop remove: route patch, stop remove | * stop remove: route patch, stop remove |
* - stop search | * - stop search |
* street inform: route inform, stop inform | * street inform: route inform, stop inform |
* - street search | * - street search |
*/ | */ |
if (isset($_REQUEST['saveedit'])) { | if (isset($_REQUEST['saveedit'])) { |
if ($_REQUEST['saveedit'] != "") { | if ($_REQUEST['saveedit'] != "") { |
updateServiceAlert($_REQUEST['saveedit'], $_REQUEST); | updateServiceAlert($_REQUEST['saveedit'], $_REQUEST); |
} else { | } else { |
addServiceAlert($_REQUEST); | addServiceAlert($_REQUEST); |
} | } |
echo "Saved " . $_REQUEST['saveedit']; | echo "Saved " . $_REQUEST['saveedit']; |
die(); | die(); |
} | } |
if ($_REQUEST['delete']) { | if ($_REQUEST['delete']) { |
$deleteParts = explode(";", $_REQUEST['delete']); | $deleteParts = explode(";", $_REQUEST['delete']); |
deleteInformedAlert($deleteParts[0], $deleteParts[1], $deleteParts[2]); | deleteInformedAlert($deleteParts[0], $deleteParts[1], $deleteParts[2]); |
echo "Deleted network inform for {$deleteParts[0]} ({$deleteParts[1]},{$deleteParts[2]})<br>\n"; | echo "Deleted network inform for {$deleteParts[0]} ({$deleteParts[1]},{$deleteParts[2]})<br>\n"; |
die(); | die(); |
} | } |
if ($_REQUEST['networkinform']) { | if ($_REQUEST['networkinform']) { |
addInformedAlert($_REQUEST['networkinform'], "agency", "0", "inform"); | addInformedAlert($_REQUEST['networkinform'], "agency", "0", "inform"); |
echo "Added network inform for" . $_REQUEST['networkinform']; | echo "Added network inform for" . $_REQUEST['networkinform']; |
die(); | die(); |
} | } |
if ($_REQUEST['stopsearch']) { | if ($_REQUEST['stopsearch']) { |
addInformedAlert($_REQUEST['stopsearch'], "stop", $_REQUEST['stopid'], "remove"); | addInformedAlert($_REQUEST['stopsearch'], "stop", $_REQUEST['stopid'], "remove"); |
echo "Added stop remove for" . $_REQUEST['stopsearch'] . ", stop" . $_REQUEST['stopid'] . "<br>\n"; | echo "Added stop remove for" . $_REQUEST['stopsearch'] . ", stop" . $_REQUEST['stopid'] . "<br>\n"; |
foreach ($service_periods as $sp) { | foreach ($service_periods as $sp) { |
echo "Remove from $sp routes<br>\n"; | echo "Remove from $sp routes<br>\n"; |
foreach (getStopRoutes($_REQUEST['stopid'], $sp) as $route) { | foreach (getStopRoutes($_REQUEST['stopid'], $sp) as $route) { |
addInformedAlert($_REQUEST['stopsearch'], "route", $route['route_id'], "patch"); | addInformedAlert($_REQUEST['stopsearch'], "route", $route['route_id'], "patch"); |
echo "Added route patch for" . $_REQUEST['stopsearch'] . ", route" . $route['route_id'] . "<br>\n"; | echo "Added route patch for" . $_REQUEST['stopsearch'] . ", route" . $route['route_id'] . "<br>\n"; |
} | } |
} | } |
die(); | die(); |
} | } |
if ($_REQUEST['streetsearch']) { | if ($_REQUEST['streetsearch']) { |
echo "Informing stops of street<br>\n"; | echo "Informing stops of street<br>\n"; |
foreach (getStopsByName($_REQUEST['street']) as $stop) { | foreach (getStopsByName($_REQUEST['street']) as $stop) { |
addInformedAlert($_REQUEST['streetsearch'], "stop", $stop['stop_id'], "inform"); | addInformedAlert($_REQUEST['streetsearch'], "stop", $stop['stop_id'], "inform"); |
echo "Added stop inform for" . $_REQUEST['streetsearch'] . ", stop" . $stop['stop_id'] . " ". $stop['stop_name']."<br>\n"; | echo "Added stop inform for" . $_REQUEST['streetsearch'] . ", stop" . $stop['stop_id'] . " ". $stop['stop_name']."<br>\n"; |
foreach ($service_periods as $sp) { | foreach ($service_periods as $sp) { |
echo "Informing $sp routes<br>\n"; | echo "Informing $sp routes<br>\n"; |
foreach (getStopRoutes($stop['stop_id'], $sp) as $route) { | foreach (getStopRoutes($stop['stop_id'], $sp) as $route) { |
addInformedAlert($_REQUEST['streetsearch'], "route", $route['route_id'], "inform"); | addInformedAlert($_REQUEST['streetsearch'], "route", $route['route_id'], "inform"); |
echo "Added route inform for stop" . $_REQUEST['streetsearch'] . ", route" . $route['route_id'] . "<br>\n"; | echo "Added route inform for stop" . $_REQUEST['streetsearch'] . ", route" . $route['route_id'] . "<br>\n"; |
} | } |
} | } |
} | } |
die(); | die(); |
} | } |
?> | ?> |
Active and Future Alerts: | Active and Future Alerts: |
<table> | <table> |
<?php | <?php |
foreach (getFutureAlerts() as $alert) { | foreach (getFutureAlerts() as $alert) { |
echo "<tr><td>" . date("c", $alert['start']) . "</td><td>" . date("c", $alert['end']) . "</td><td>" . substr($alert['description'], 0, 999) . '</td><td><a href="?edit=' . $alert['id'] . '">edit</a></td></tr>'; | echo "<tr><td>" . date("c", $alert['start']) . "</td><td>" . date("c", $alert['end']) . "</td><td>" . substr($alert['description'], 0, 999) . '</td><td><a href="?edit=' . $alert['id'] . '">edit</a></td></tr>'; |
} | } |
?> | ?> |
</table> | </table> |
<?php | <?php |
$alert = getServiceAlert($_REQUEST['edit']); | $alert = getServiceAlert($_REQUEST['edit']); |
?> | ?> |
<form action="<?php echo basename(__FILE__); | <form action="<?php echo basename(__FILE__); |
?>" method="get"> | ?>" method="get"> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="startdate"> Start Date</label> | <label for="startdate"> Start Date</label> |
<input type="text" name="startdate" id="startdate" value="<?php | <input type="text" name="startdate" id="startdate" value="<?php |
if ($alert['start']) | if ($alert['start']) |
echo date("c", $alert['start']); | echo date("c", $alert['start']); |
else | else |
echo date("c", strtotime("0:00")); | echo date("c", strtotime("0:00")); |
?>" /> | ?>" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="enddate"> End Date </label> | <label for="enddate"> End Date </label> |
<input type="text" name="enddate" id="enddate" value="<?php | <input type="text" name="enddate" id="enddate" value="<?php |
if ($alert['end']) | if ($alert['end']) |
echo date("c", $alert['end']); | echo date("c", $alert['end']); |
else | else |
echo date("c", strtotime("23:59")); | echo date("c", strtotime("23:59")); |
?>" /> | ?>" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="header">Header</label> | <label for="header">Header</label> |
<input type="text" name="header" id="header" value="<?php echo $alert['header']; ?>" /> | <input type="text" name="header" id="header" value="<?php echo $alert['header']; ?>" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="description">Description</label> | <label for="description">Description</label> |
<textarea name="description"> | <textarea name="description"><?php echo $alert['description']; ?></textarea> |
<?php echo $alert['description']; ?></textarea> | |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="url">URL</label> | <label for="url">URL</label> |
<input type="text" name="url" id="url" value="<?php echo $alert['url']; ?>" /> | <input type="text" name="url" id="url" value="<?php echo $alert['url']; ?>" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="cause"> Cause: </label> | <label for="cause"> Cause: </label> |
<select name="cause" id="cause"> | <select name="cause" id="cause"> |
<?php | <?php |
foreach ($serviceAlertCause as $key => $value) { | foreach ($serviceAlertCause as $key => $value) { |
echo "<option value=\"$key\"" . ($key === $alert['cause'] ? " SELECTED" : "") . '>' . $value . '</option>'; | echo "<option value=\"$key\"" . ($key === $alert['cause'] ? " SELECTED" : "") . '>' . $value . '</option>'; |
} | } |
?> | ?> |
</select></div> | </select></div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="effect"> Effect: </label> | <label for="effect"> Effect: </label> |
<select name="effect" id="effect"> | <select name="effect" id="effect"> |
<?php | <?php |
foreach ($serviceAlertEffect as $key => $value) { | foreach ($serviceAlertEffect as $key => $value) { |
echo "<option value=\"$key\"" . ($key === $alert['effect'] ? " SELECTED" : "") . '>' . $value . '</option>'; | echo "<option value=\"$key\"" . ($key === $alert['effect'] ? " SELECTED" : "") . '>' . $value . '</option>'; |
} | } |
?> | ?> |
</select></div> | </select></div> |
<input type="hidden" name="saveedit" value="<?php echo $_REQUEST['edit']; ?>"/> | <input type="hidden" name="saveedit" value="<?php echo $_REQUEST['edit']; ?>"/> |
<input type="submit" value="Save"/> | <input type="submit" value="Save"/> |
</div></form> | </div></form> |
<?php | <?php |
if ($_REQUEST['edit']) { | if ($_REQUEST['edit']) { |
echo "Informed Entities for ID {$_REQUEST['edit']}:"; | echo "Informed Entities for ID {$_REQUEST['edit']}:"; |
echo '<table>'; | echo '<table>'; |
foreach (getInformedAlerts($_REQUEST['edit'], "", "") as $informed) { | foreach (getInformedAlerts($_REQUEST['edit'], "", "") as $informed) { |
echo "<tr><td>{$informed['informed_class']}</td><td>{$informed['informed_id']}</td><td>{$informed['informed_action']}" . '</td><td><a href="?delete=' . $_REQUEST['edit'] . ';' . $informed['informed_class'] . ';' . $informed['informed_id'] . '">delete</a></td></tr>'; | echo "<tr><td>{$informed['informed_class']}</td><td>{$informed['informed_id']}</td><td>{$informed['informed_action']}" . '</td><td><a href="?delete=' . $_REQUEST['edit'] . ';' . $informed['informed_class'] . ';' . $informed['informed_id'] . '">delete</a></td></tr>'; |
} | } |
echo '</table>'; | echo '</table>'; |
?> | ?> |
<form action="<?php echo basename(__FILE__); | <form action="<?php echo basename(__FILE__); |
?>" method="get"> | ?>" method="get"> |
<input type="hidden" name="networkinform" value="<?php echo $_REQUEST['edit']; | <input type="hidden" name="networkinform" value="<?php echo $_REQUEST['edit']; |
?>"/> | ?>"/> |
<input type="submit" value="Add Network Inform"/> | <input type="submit" value="Add Network Inform"/> |
</form> | </form> |
<form action="<?php echo basename(__FILE__); | <form action="<?php echo basename(__FILE__); |
?>" method="get"> | ?>" method="get"> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="stopid">StopID to remove</label> | <label for="stopid">StopID to remove</label> |
<input type="text" name="stopid" /> | <input type="text" name="stopid" /> |
</div> | </div> |
<input type="hidden" name="stopsearch" value="<?php echo $_REQUEST['edit']; | <input type="hidden" name="stopsearch" value="<?php echo $_REQUEST['edit']; |
?>"/> | ?>"/> |
<input type="submit" value="Stop Search"/> | <input type="submit" value="Stop Search"/> |
</form> | </form> |
<form action="<?php echo basename(__FILE__); | <form action="<?php echo basename(__FILE__); |
?>" method="get"> | ?>" method="get"> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="street">Street to inform</label> | <label for="street">Street to inform</label> |
<input type="text" name="street" /> | <input type="text" name="street" /> |
</div> | </div> |
<input type="hidden" name="streetsearch" value="<?php echo $_REQUEST['edit']; | <input type="hidden" name="streetsearch" value="<?php echo $_REQUEST['edit']; |
?>"/> | ?>"/> |
<input type="submit" value="Street Search"/> | <input type="submit" value="Street Search"/> |
</form> | </form> |
<?php | <?php |
} | } |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
/* | /* |
* To change this template, choose Tools | Templates | * Copyright 2010,2011 Alexander Sadleir |
* and open the template in the editor. | |
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. | |
*/ | */ |
include ('include/common.inc.php'); | |
function accept_header($header = false) { | |
// http://jrgns.net/parse_http_accept_header | |
$toret = null; | |
$header = $header ? $header : (array_key_exists('HTTP_ACCEPT', $_SERVER) ? $_SERVER['HTTP_ACCEPT']: false); | |
if ($header) { | |
$types = explode(',', $header); | |
$types = array_map('trim', $types); | |
foreach ($types as $one_type) { | |
$one_type = explode(';', $one_type); | |
$type = array_shift($one_type); | |
if ($type) { | |
list($precedence, $tokens) = self::accept_header_options($one_type); | |
list($main_type, $sub_type) = array_map('trim', explode('/', $type)); | |
$toret[] = array('main_type' => $main_type, 'sub_type' => $sub_type, 'precedence' => (float)$precedence, 'tokens' => $tokens); | |
} | |
} | |
usort($toret, array('Parser', 'compare_media_ranges')); | |
} | |
return $toret; | |
} | |
function usage() { | |
echo "Usage notes: Must specify format json/xml. If callback is specified, will provide jsonp. Can filter with parmaters filter_class route/stop and filter_id with the id specified in GTFS." | |
die(); | |
} | |
$json_types = Array("application/json","application/x-javascript","text/javascript","text/x-javascript","text/x-json"); | |
if ($_REQUEST['json']) { | |
if ($_REQUEST['alerts']) { | |
$return = getServiceAlertsAsJSON($_REQUEST['filter_class'], $_REQUEST['filter_id']); | |
} else if ($_REQUEST['updates']) { | |
$return = getTripUpdatesAsJSON($_REQUEST['filter_class'], $_REQUEST['filter_id']); | |
} else { | |
usage(); | |
} | |
header('Content-Type: application/json; charset=utf8'); | |
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); | |
header('Access-Control-Max-Age: 3628800'); | |
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); | |
if (isset($_GET['callback'])) { | |
$json = '(' . $return . ');'; //must wrap in parens and end with semicolon | |
//print_r($_GET['callback'] . $json); //callback is prepended for json-p | |
} | |
else { | |
echo $return; | |
} | |
} else if ($_REQUEST['xml']) { | |
if ($_REQUEST['alerts']) { | |
$return = getServiceAlertsAsBinary($_REQUEST['filter_class'], $_REQUEST['filter_id']); | |
} else if ($_REQUEST['updates']) { | |
$return = getTripUpdatesAsBinary($_REQUEST['filter_class'], $_REQUEST['filter_id']); | |
} else { | |
usage(); | |
} | |
header('Content-Type: application/json; charset=utf8'); | |
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); | |
header('Access-Control-Max-Age: 3628800'); | |
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); | |
echo $return; | |
} else { | |
usage(); | |
} | |
?> | ?> |