[7725] | 1 | <?php
|
---|
[7769] | 2 | //$file contains place of the KML file we will be getting our node information from
|
---|
| 3 | function get_node_array($file)
|
---|
[7725] | 4 | {
|
---|
[7767] | 5 | //Check if the file exists, if it does we load it. If it doesn't we exit and return an error message
|
---|
| 6 | if (file_exists($file))
|
---|
| 7 | {
|
---|
| 8 | $xml = simplexml_load_file($file);
|
---|
| 9 | }
|
---|
| 10 | else
|
---|
| 11 | {
|
---|
[7800] | 12 | exit('Failed to open example.kml');
|
---|
[7767] | 13 | }
|
---|
[7725] | 14 |
|
---|
[7767] | 15 | //Counter starts at 0. For every foreach done counter will go up by one. Thus resulting in total nodes added(counter starts at 0 so add 1 to the total )
|
---|
| 16 | $counter = 0;
|
---|
| 17 |
|
---|
| 18 | //Now we go through the xml files, storing the data in an array called $markers. More data can be stored by adding more rows in the array
|
---|
| 19 | foreach($xml->Document->Folder->Placemark as $placemark)
|
---|
| 20 | {
|
---|
[7784] | 21 | /*
|
---|
| 22 | * Getting all data from the datatags in the KML file.
|
---|
| 23 | * First we declare variables we will use.
|
---|
| 24 | * Then we itirate trough all the data and fill the variables
|
---|
| 25 | */
|
---|
[7785] | 26 | $location = "";
|
---|
| 27 | $status = "";
|
---|
| 28 | $interfaces = "";
|
---|
| 29 | $masterIP = "";
|
---|
| 30 | $nodeType = "";
|
---|
| 31 | $type = "";
|
---|
| 32 | $hostname = "";
|
---|
| 33 | $hasBeenChecked = "";
|
---|
| 34 | $checkExecutionTime = "";
|
---|
| 35 | $currentState = "";
|
---|
| 36 | $lastCheck = "";
|
---|
| 37 | $problemHasBeenAcknowledged = "";
|
---|
[7767] | 38 |
|
---|
[7784] | 39 | foreach($placemark->ExtendedData->Data as $data)
|
---|
| 40 | {
|
---|
| 41 | foreach($data->attributes() as $nameAttribute => $name)
|
---|
| 42 | {
|
---|
| 43 | if($name == "location")
|
---|
| 44 | $location = $data->value;
|
---|
[7785] | 45 |
|
---|
| 46 | if($name == "status")
|
---|
[7784] | 47 | $status = $data->value;
|
---|
[7785] | 48 |
|
---|
| 49 | if($name == "interfaces")
|
---|
[7784] | 50 | $interfaces = $data->value;
|
---|
[7785] | 51 |
|
---|
| 52 | if($name == "masterIP")
|
---|
[7784] | 53 | $masterIP = $data->value;
|
---|
[7785] | 54 |
|
---|
| 55 | if($name == "nodeType")
|
---|
[7784] | 56 | $nodeType = $data->value;
|
---|
[7785] | 57 |
|
---|
| 58 | if($name == "type")
|
---|
[7784] | 59 | $type = $data->value;
|
---|
[7785] | 60 |
|
---|
| 61 | if($name == "hostname")
|
---|
[7784] | 62 | $hostname = $data->value;
|
---|
[7785] | 63 |
|
---|
| 64 | if($name == "hasBeenChecked")
|
---|
[7784] | 65 | $hasBeenChecked = $data->value;
|
---|
[7785] | 66 |
|
---|
| 67 | if($name == "checkExecutionTime")
|
---|
[7784] | 68 | $checkExecutionTime = $data->value;
|
---|
[7785] | 69 |
|
---|
| 70 | if($name == "currentState")
|
---|
[7784] | 71 | $currentState = $data->value;
|
---|
[7785] | 72 |
|
---|
| 73 | if($name == "problemHasBeenAcknowledged")
|
---|
[7784] | 74 | $problemHasBeenAcknowledged = $data->value;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /*
|
---|
| 79 | * We now fill up our array with Longitude and Latitude and Name by accessing $placemark
|
---|
| 80 | * Then we fill the rest of the array with the variables we declared and filled earlier
|
---|
| 81 | */
|
---|
| 82 |
|
---|
[7769] | 83 | $markers[] = array( "latitude"=>$placemark->LookAt->latitude,
|
---|
[7767] | 84 | "longitude"=>$placemark->LookAt->longitude,
|
---|
| 85 | "name"=>$placemark->name,
|
---|
[7784] | 86 | "location"=>$location,
|
---|
[7785] | 87 | "status"=>$status,
|
---|
| 88 | "interfaces"=>$interfaces,
|
---|
| 89 | "masterIP"=>$masterIP,
|
---|
| 90 | "nodeType"=>$nodeType,
|
---|
| 91 | "type"=>$type,
|
---|
| 92 | "hostname"=>$hostname,
|
---|
| 93 | "hasBeenChecked"=>$hasBeenChecked,
|
---|
| 94 | "checkExecutionTime"=>$checkExecutionTime,
|
---|
| 95 | "currentState"=>$currentState,
|
---|
| 96 | "lastCheck"=>$lastCheck,
|
---|
| 97 | "problemHasBeenAcknowledged"=>$problemHasBeenAcknowledged);
|
---|
[7767] | 98 | }
|
---|
| 99 | return $markers;
|
---|
[7722] | 100 | }
|
---|