Changeset 7773 for trunk/src/inc/KMLFile.class.php
- Timestamp:
- Apr 15, 2010, 10:40:35 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/inc/KMLFile.class.php
r7765 r7773 76 76 private $KMLNodes; 77 77 private $KMLLines; 78 78 private $NetworkList; 79 79 80 /* 80 81 * Function: __construct (constructor) … … 86 87 $this->KMLNodes = array(); 87 88 $this->KMLLines = array(); 89 $this->NetworkList = new NetworkList(); 88 90 } 89 91 … … 119 121 $toString = $this->template; 120 122 123 // Add all nodes to the string 121 124 $nodeString = ''; 122 125 $nodeCount = count($this->KMLNodes); … … 125 128 } 126 129 130 // Add all connected lines to the string 127 131 $lineString = ''; 128 132 $lineCount = count($this->KMLLines); 129 133 for ($i = 0; $i < $lineCount; $i++) { 130 $lineString .= $this->KMLLines[$i]->toString(); 134 // If longitude2 and latitude2 aren't set, ignore the lines 135 // This happens with all the connections that don't connect 2 nodes 136 if ($this->KMLLines[$i]->isConnected()) { 137 $lineString .= $this->KMLLines[$i]->toString(); 138 } 131 139 } 132 140 … … 137 145 $toString = str_replace('%NODESCONTENT%', $nodeString, $toString); 138 146 $toString = str_replace('%LINESCONTENT%', $lineString, $toString); 139 147 140 148 return $toString; 141 }142 143 /*144 * Function: write145 * Description: Write KMLFile to a KML file146 * Parameters: string $filename147 * Returns: true if we can write to the file, otherwise false148 */149 public function write($filename) {150 // TODO: David: Needs to be placed in FileHandler.class.php. Here we just want to call our file handler.151 152 trigger_log(SYSLOG_DEBUG, 'Opening the file "' . $filename . '"', __FILE__, __LINE__);153 $file = new FileHandler($filename, 'w')154 or trigger_log(SYSLOG_ERR, 'Opening the file "' . $filename . '"', __FILE__, __LINE__);155 156 trigger_log(SYSLOG_DEBUG, 'Writing file "' . $filename . '"', __FILE__, __LINE__);157 $file->write($file,$this->toString());158 159 trigger_log(SYSLOG_DEBUG, 'Closing file "' . $filename . '"', __FILE__, __LINE__);160 fclose($file);161 149 } 162 150 … … 185 173 */ 186 174 public function parseLocationFile($file) { 175 // We want to find all the nodes in the location file and store information of the nodes... 187 176 $nodesCount = preg_match_all('/\[[a-zA-Z0-9]*\]/i', $file, $nodes, PREG_OFFSET_CAPTURE); 188 177 for ($i = 0; $i < $nodesCount; $i++) { 189 178 // Looking for "location" of the node 190 if (!$location = $this->findInLocationFile($file, 'location ', $nodes[0][$i][1])) {179 if (!$location = $this->findInLocationFile($file, 'location = ', $nodes[0][$i][1])) { 191 180 trigger_log(SYSLOG_WARNING, 'Could not find the "location" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 192 181 continue; 193 182 } 194 183 // Looking for "status" of the node 195 if (!$status = $this->findInLocationFile($file, 'status ', $nodes[0][$i][1])) {184 if (!$status = $this->findInLocationFile($file, 'status = ', $nodes[0][$i][1])) { 196 185 trigger_log(SYSLOG_WARNING, 'Could not find the "status" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 197 186 continue; 198 187 } 199 188 // Looking for "latitude" of the node 200 if (!$latitude = $this->findInLocationFile($file, 'latitude ', $nodes[0][$i][1])) {189 if (!$latitude = $this->findInLocationFile($file, 'latitude = ', $nodes[0][$i][1])) { 201 190 trigger_log(SYSLOG_WARNING, 'Could not find the "latitude" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 202 191 continue; 203 192 } 204 193 // Looking for "longitude" of the node 205 if (!$longitude = $this->findInLocationFile($file, 'longitude ', $nodes[0][$i][1])) {194 if (!$longitude = $this->findInLocationFile($file, 'longitude = ', $nodes[0][$i][1])) { 206 195 trigger_log(SYSLOG_WARNING, 'Could not find the "longitude" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 207 196 continue; 208 197 } 209 198 // Looking for "interfaces" of the node 210 if (!$interfaces = $this->findInLocationFile($file, 'interfaces ', $nodes[0][$i][1])) {199 if (!$interfaces = $this->findInLocationFile($file, 'interfaces = ', $nodes[0][$i][1])) { 211 200 trigger_log(SYSLOG_WARNING, 'Could not find the "interfaces" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 212 201 continue; 213 202 } 214 203 // Looking for "masterip" of the node 215 if (!$masterip = $this->findInLocationFile($file, 'masterip ', $nodes[0][$i][1])) {204 if (!$masterip = $this->findInLocationFile($file, 'masterip = ', $nodes[0][$i][1])) { 216 205 trigger_log(SYSLOG_WARNING, 'Could not find the "masterip" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 217 206 continue; 218 207 } 219 208 // Looking for "nodetype" of the node 220 if (!$nodetype = $this->findInLocationFile($file, 'nodetype ', $nodes[0][$i][1])) {209 if (!$nodetype = $this->findInLocationFile($file, 'nodetype = ', $nodes[0][$i][1])) { 221 210 trigger_log(SYSLOG_WARNING, 'Could not find the "nodetype" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 222 211 continue; 223 212 } 224 213 // Looking for "name" of the node 225 if (!$name = $this->findInLocationFile($file, 'name ', $nodes[0][$i][1])) {214 if (!$name = $this->findInLocationFile($file, 'name = ', $nodes[0][$i][1])) { 226 215 trigger_log(SYSLOG_WARNING, 'Could not find the "name" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 227 216 continue; … … 246 235 $this->addNode($placemark); 247 236 } 237 238 // Now let's find all interlinks with this node 239 $position = $nodes[0][$i][1]; 240 while (($position = strpos($file, 'ip=', $position + 1)) && (isset($nodes[0][$i + 1][1]) && $position < $nodes[0][$i + 1][1])) { 241 $ipAddress = $this->findInLocationFile($file, 'ip=', $position); 242 $posSlash = strpos($ipAddress, '/'); 243 $ip = substr($ipAddress, 0, $posSlash); 244 $netmask = substr($ipAddress, $posSlash + 1); 245 246 $posNetwork = $this->NetworkList->find($ip); 247 if ($posNetwork) { 248 // Network already excists in list, just need to add longitude2 en latitude2 to KMLLine 249 // and add the node name to the name of the line. 250 // Position in network equals position in KMLLine array :-) 251 252 $this->KMLLines[$posNetwork]->setName($this->KMLLines[$posNetwork]->getName() . $name); 253 $this->KMLLines[$posNetwork]->setLongitude2($longitude); 254 $this->KMLLines[$posNetwork]->setLatitude2($latitude); 255 } else { 256 // Network doesn't excist. We create a new network and a new line. 257 258 $network = new Network($ip, $netmask); 259 $this->NetworkList->add($network); 260 261 $line = new KMLLine(); 262 $line->setID($network->networkDecimal); 263 $line->setName('Link: Van ' . $name . ' naar '); 264 $line->setDescription($network->toString()); 265 $line->setLongitude1($longitude); 266 $line->setLatitude1($latitude); 267 $this->KMLLines[] = $line; 268 } 269 } 248 270 } 249 271 } … … 256 278 */ 257 279 private function findInLocationFile($file, $keyword, $offset) { 258 $start = strpos($file, $keyword, $offset) + strlen($keyword . ' = ');280 $start = strpos($file, $keyword, $offset) + strlen($keyword); 259 281 $end = strpos($file, "\n", $start); 260 282
Note:
See TracChangeset
for help on using the changeset viewer.