- Timestamp:
- Mar 31, 2010, 10:46:12 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/inc/FileHandler.class.php
r7637 r7640 30 30 trigger_log(SYSLOG_INFO, 'Reading from file "' . $filename . '" is done', __FILE__, __LINE__); 31 31 } catch (Exception $err) { 32 // TODO: Better error description33 32 trigger_log(SYSLOG_ERR, 'Reading from file "' . $filename . '" failed', __FILE__, __LINE__); 34 33 } -
trunk/src/inc/KMLFile.class.php
r7637 r7640 93 93 } 94 94 95 public function parseFile($file) { 95 public function parseLocationFile($file) { 96 //preg_match_all('#\[(^\/.+?)\]#is', $file, $matches); 97 $nodesCount = preg_match_all('/\[[a-zA-Z0-9]*\]/i', $file, $nodes, PREG_OFFSET_CAPTURE); 98 for ($i = 0; $i < $nodesCount; $i++) { 99 $location = $this->findInLocationFile($file, 'location', $nodes[0][$i][1]); 100 $status = $this->findInLocationFile($file, 'status', $nodes[0][$i][1]); 101 $latitude = $this->findInLocationFile($file, 'latitude', $nodes[0][$i][1]); 102 $longitude = $this->findInLocationFile($file, 'longitude', $nodes[0][$i][1]); 103 $interfaces = $this->findInLocationFile($file, 'interfaces', $nodes[0][$i][1]); 104 $masterip = $this->findInLocationFile($file, 'masterip', $nodes[0][$i][1]); 105 $nodetype = $this->findInLocationFile($file, 'nodetype', $nodes[0][$i][1]); 106 $name = $this->findInLocationFile($file, 'name', $nodes[0][$i][1]); 107 108 $placemark = new KMLPlacemark(); 109 $placemark->setName($name); 110 $placemark->setDescription('Naam: ' . $name . '<br/>Locatie: ' . $location . '<br/>Status: ' . $status . '<br/>Latitude: ' . $latitude . '<br/>Longitude: ' . $longitude . '<br/>Interfaces: ' . $interfaces . '<br/>Master IP: ' . $masterip . '<br/>Node type: ' . $nodetype); 111 $placemark->setLongitude($longitude); 112 $placemark->setLatitude($latitude); 113 $placemark->setStyle($status == 'up' ? 'greenArrowIcon' : 'redArrowIcon'); 114 $this->addPlacemark($placemark); 115 } 116 } 117 118 private function findInLocationFile($file, $keyword, $offset) { 119 $start = strpos($file, $keyword, $offset) + strlen($keyword . ' = '); 120 $end = strpos($file, "\n", $start); 121 return substr($file, $start, $end - $start); 122 } 123 124 public function parseStatusFile($file) { 125 /* 126 * TODO: Needs to be rebuild so it doesn't create a new KMLFile object, 127 * but add the KMLPlacemarks to the current object. 128 */ 96 129 $fileContents = explode("\r\n", $file); 97 130 -
trunk/src/index.php
r7639 r7640 31 31 echo $kml->toString(); 32 32 33 // Now let's try reading from files and parsing the data in the files. 34 // First off, we create a new KMLFile object 35 $kmlFile = new KMLFile(); 36 33 37 // Let's try to read the node location file 34 38 $nodeLocation = new FileHandler($config['node_location_file']); 35 // TODO: Needs parsing 39 $kmlFile->parseLocationFile($nodeLocation->getFile()); 40 echo $kmlFile->toString(); 36 41 37 42 // Let's try to read the node status file 38 43 $nodeStatus = new FileHandler($config['node_status_file']); 39 $kmlFile = KMLFile::parseFile($nodeStatus->getFile());44 $kmlFile->parseStatusFile($nodeStatus->getFile()); 40 45 /* 41 46 * TODO: Needs better parsing of the file now we have two seperate
Note:
See TracChangeset
for help on using the changeset viewer.