Exemple #1
0
 /**
  * @param $xml
  * @param $time
  * @param $lang
  * @param bool $fast
  * @param bool $showAlerts
  * @return array
  */
 private static function parseData($xml, $time, $lang, $fast = false, $showAlerts = false)
 {
     //clean XML
     if (class_exists('tidy', false)) {
         $tidy = new tidy();
         $tidy->parseString($xml, ['input-xml' => true, 'output-xml' => true], 'utf8');
         $tidy->cleanRepair();
         $xml = $tidy;
     }
     $data = new SimpleXMLElement($xml);
     $hour = substr($time, 0, 2);
     $data = $data->StationTable;
     //<Journey fpTime="08:36" fpDate="03/09/11" delay="-"
     //platform="2" targetLoc="Gent-Dampoort [B]" prod="L    758#L"
     //dir="Eeklo [B]" is_reachable="0" />
     $nodes = [];
     $i = 0;
     $hour = substr($time, 0, 2);
     $hour_ = substr((string) $data->Journey[0]['fpTime'], 0, 2);
     if ($hour_ != '23' && $hour == '23') {
         $hour_ = 24;
     }
     $minutes = substr($time, 3, 2);
     $minutes_ = substr((string) $data->Journey[0]['fpTime'], 3, 2);
     while (isset($data->Journey[$i]) && ($hour_ - $hour) * 60 + ($minutes_ - $minutes) <= 60) {
         $journey = $data->Journey[$i];
         $left = 0;
         $canceled = false;
         $delay = (string) $journey['delay'];
         if ($delay == '-') {
             $delay = '0';
         }
         if ($delay == 'cancel') {
             $delay = 0;
             $canceled = true;
         }
         if (isset($journey['e_delay'])) {
             $delay = $journey['e_delay'] * 60;
         }
         preg_match("/\\+\\s*(\\d+)/", $delay, $d);
         if (isset($d[1])) {
             $delay = $d[1] * 60;
         }
         preg_match("/\\+\\s*(\\d):(\\d+)/", $delay, $d);
         if (isset($d[1])) {
             $delay = $d[1] * 3600 + $d[2] * 60;
         }
         $platform = '?';
         // Indicate to end user platform is unknown
         $platformNormal = true;
         if (isset($journey['platform'])) {
             $platform = (string) $journey['platform'];
         }
         if (isset($journey['newpl'])) {
             $platform = (string) $journey['newpl'];
             $platformNormal = false;
         }
         $time = '00d' . (string) $journey['fpTime'] . ':00';
         preg_match("/(..)\\/(..)\\/(..)/si", (string) $journey['fpDate'], $dayxplode);
         $dateparam = '20' . $dayxplode[3] . $dayxplode[2] . $dayxplode[1];
         $unixtime = tools::transformtime($time, $dateparam);
         if ($fast) {
             $stationNode = new Station();
             $stationNode->name = (string) $journey['targetLoc'];
             $stationNode->name = str_replace(' [B]', '', $stationNode->name);
             $stationNode->name = str_replace(' [NMBS/SNCB]', '', $stationNode->name);
         } else {
             $stationNode = stations::getStationFromName($journey['targetLoc'], $lang);
         }
         $veh = $journey['hafasname'];
         $veh = substr($veh, 0, 8);
         $veh = str_replace(' ', '', $veh);
         $vehicle = 'BE.NMBS.' . $veh;
         $nodes[$i] = new DepartureArrival();
         $nodes[$i]->delay = $delay;
         $nodes[$i]->station = $stationNode;
         $nodes[$i]->time = $unixtime;
         $nodes[$i]->vehicle = $vehicle;
         $nodes[$i]->platform = new Platform();
         $nodes[$i]->platform->name = $platform;
         $nodes[$i]->platform->normal = $platformNormal;
         $nodes[$i]->canceled = $canceled;
         $nodes[$i]->left = $left;
         $hour_ = substr((string) $data->Journey[$i]['fpTime'], 0, 2);
         if ($hour_ != '23' && $hour == '23') {
             $hour_ = 24;
         }
         $minutes_ = substr((string) $data->Journey[$i]['fpTime'], 3, 2);
         // Alerts
         if ($showAlerts && isset($journey->HIMMessage)) {
             $alerts = [];
             $himmessage = $journey->HIMMessage;
             for ($a = 0; $a < count($himmessage); $a++) {
                 $alert = new Alert();
                 $alert->header = htmlentities(trim($himmessage[$a]['header']));
                 $alert->description = htmlentities(trim($himmessage[$a]['lead']));
                 array_push($alerts, $alert);
             }
             $nodes[$i]->alert = $alerts;
         }
         $i++;
     }
     return array_merge($nodes);
     //array merge reindexes the array
 }
Exemple #2
0
 /**
  * @param $xml
  * @param $time
  * @param $lang
  * @param bool $fast
  * @return array
  */
 private static function parseData($xml, $time, $lang, $fast = false)
 {
     //clean XML
     if (class_exists("tidy", false)) {
         $tidy = new tidy();
         $tidy->parseString($xml, ['input-xml' => true, 'output-xml' => true], 'utf8');
         $tidy->cleanRepair();
         $xml = $tidy;
     }
     $data = new SimpleXMLElement($xml);
     $hour = substr($time, 0, 2);
     $data = $data->StationTable;
     //<Journey fpTime="08:36" fpDate="03/09/11" delay="-"
     //platform="2" targetLoc="Gent-Dampoort [B]" prod="L    758#L"
     //dir="Eeklo [B]" is_reachable="0" />
     $nodes = [];
     $i = 0;
     $hour = substr($time, 0, 2);
     $hour_ = substr((string) $data->Journey[0]["fpTime"], 0, 2);
     if ($hour_ != "23" && $hour == "23") {
         $hour_ = 24;
     }
     $minutes = substr($time, 3, 2);
     $minutes_ = substr((string) $data->Journey[0]["fpTime"], 3, 2);
     while (isset($data->Journey[$i]) && ($hour_ - $hour) * 60 + ($minutes_ - $minutes) <= 60) {
         $journey = $data->Journey[$i];
         $left = 0;
         $delay = (string) $journey["delay"];
         if ($delay == "-") {
             $delay = "0";
         }
         $platform = "";
         if (isset($journey["platform"])) {
             $platform = (string) $journey["platform"];
         }
         $time = "00d" . (string) $journey["fpTime"] . ":00";
         preg_match("/(..)\\/(..)\\/(..)/si", (string) $journey["fpDate"], $dayxplode);
         $dateparam = "20" . $dayxplode[3] . $dayxplode[2] . $dayxplode[1];
         $unixtime = tools::transformtime($time, $dateparam);
         //GET DELAY
         preg_match("/\\+\\s*(\\d+)/", $delay, $d);
         if (isset($d[1])) {
             $delay = $d[1] * 60;
         }
         preg_match("/\\+\\s*(\\d):(\\d+)/", $delay, $d);
         if (isset($d[1])) {
             $delay = $d[1] * 3600 + $d[2] * 60;
         }
         if ($fast) {
             $stationNode = new Station();
             $stationNode->name = (string) $journey["dir"];
             $stationNode->name = str_replace(" [B]", "", $stationNode->name);
             $stationNode->name = str_replace(" [NMBS/SNCB]", "", $stationNode->name);
         } else {
             $stationNode = stations::getStationFromName($journey["dir"], $lang);
         }
         //GET VEHICLE AND PLATFORM
         $platformNormal = true;
         $veh = $journey["hafasname"];
         $veh = substr($veh, 0, 8);
         $veh = str_replace(" ", "", $veh);
         $vehicle = "BE.NMBS." . $veh;
         $nodes[$i] = new DepartureArrival();
         $nodes[$i]->delay = $delay;
         $nodes[$i]->station = $stationNode;
         $nodes[$i]->time = $unixtime;
         $nodes[$i]->vehicle = $vehicle;
         $nodes[$i]->platform = new Platform();
         $nodes[$i]->platform->name = $platform;
         $nodes[$i]->platform->normal = $platformNormal;
         $nodes[$i]->left = $left;
         $hour_ = substr((string) $data->Journey[$i]["fpTime"], 0, 2);
         if ($hour_ != "23" && $hour == "23") {
             $hour_ = 24;
         }
         $minutes_ = substr((string) $data->Journey[$i]["fpTime"], 3, 2);
         $i++;
     }
     return array_merge($nodes);
     //array merge reindexes the array
 }