[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 | {
|
---|
[7769] | 12 | exit('Failed to open example.xml.');
|
---|
[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 | */
|
---|
| 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;
|
---|
| 45 | elseif($name == "status")
|
---|
| 46 | $status = $data->value;
|
---|
| 47 | elseif($name == "interfaces")
|
---|
| 48 | $interfaces = $data->value;
|
---|
| 49 | elseif($name == "masterIP")
|
---|
| 50 | $masterIP = $data->value;
|
---|
| 51 | elseif($name == "nodeType")
|
---|
| 52 | $nodeType = $data->value;
|
---|
| 53 | elseif($name == "type")
|
---|
| 54 | $type = $data->value;
|
---|
| 55 | elseif($name == "hostname")
|
---|
| 56 | $hostname = $data->value;
|
---|
| 57 | elseif($name == "hasBeenChecked")
|
---|
| 58 | $hasBeenChecked = $data->value;
|
---|
| 59 | elseif($name == "checkExecutionTime")
|
---|
| 60 | $checkExecutionTime = $data->value;
|
---|
| 61 | elseif($name == "currentState")
|
---|
| 62 | $currentState = $data->value;
|
---|
| 63 | elseif($name == "problemHasBeenAcknowledged")
|
---|
| 64 | $problemHasBeenAcknowledged = $data->value;
|
---|
| 65 | elseif($name == "location")
|
---|
| 66 | $location = $data->value;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | /*
|
---|
| 71 | * We now fill up our array with Longitude and Latitude and Name by accessing $placemark
|
---|
| 72 | * Then we fill the rest of the array with the variables we declared and filled earlier
|
---|
| 73 | */
|
---|
| 74 |
|
---|
[7769] | 75 | $markers[] = array( "latitude"=>$placemark->LookAt->latitude,
|
---|
[7767] | 76 | "longitude"=>$placemark->LookAt->longitude,
|
---|
| 77 | "name"=>$placemark->name,
|
---|
[7784] | 78 | "location"=>$location,
|
---|
| 79 | "status"=>$status);
|
---|
| 80 |
|
---|
[7767] | 81 | }
|
---|
| 82 | return $markers;
|
---|
[7722] | 83 | }
|
---|