Changeset 7640 for trunk/src


Ignore:
Timestamp:
Mar 31, 2010, 10:46:12 PM (15 years ago)
Author:
Pieter Naber
Message:

KMLFile can read from the node location file provided. It parses the file into nodes.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/inc/FileHandler.class.php

    r7637 r7640  
    3030                        trigger_log(SYSLOG_INFO, 'Reading from file "' . $filename . '" is done', __FILE__, __LINE__);
    3131                } catch (Exception $err) {
    32                         // TODO: Better error description
    3332                        trigger_log(SYSLOG_ERR, 'Reading from file "' . $filename . '" failed', __FILE__, __LINE__);
    3433                }
  • trunk/src/inc/KMLFile.class.php

    r7637 r7640  
    9393        }
    9494
    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                 */
    96129                $fileContents = explode("\r\n", $file);
    97130
  • trunk/src/index.php

    r7639 r7640  
    3131echo $kml->toString();
    3232
     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
    3337// Let's try to read the node location file
    3438$nodeLocation = new FileHandler($config['node_location_file']);
    35 // TODO: Needs parsing
     39$kmlFile->parseLocationFile($nodeLocation->getFile());
     40echo $kmlFile->toString();
    3641
    3742// Let's try to read the node status file
    3843$nodeStatus = new FileHandler($config['node_status_file']);
    39 $kmlFile = KMLFile::parseFile($nodeStatus->getFile());
     44$kmlFile->parseStatusFile($nodeStatus->getFile());
    4045/*
    4146 * TODO: Needs better parsing of the file now we have two seperate
Note: See TracChangeset for help on using the changeset viewer.