Beispiel #1
0
 /**
  * Enter description here...
  *
  * In the future, when PHP will support XLS 2.0, then we would do that this way:
  * contains(tokenize(@class, '\s'), "something")
  * @param unknown_type $class
  * @param unknown_type $node
  * @return boolean
  * @access private
  */
 protected function matchClasses($class, $node)
 {
     // multi-class
     if (mb_strpos($class, '.', 1)) {
         $classes = explode('.', substr($class, 1));
         $classesCount = count($classes);
         $nodeClasses = explode(' ', $node->getAttribute('class'));
         $nodeClassesCount = count($nodeClasses);
         if ($classesCount > $nodeClassesCount) {
             return false;
         }
         $diff = count(array_diff($classes, $nodeClasses));
         if (!$diff) {
             return true;
         }
         // single-class
     } else {
         return in_array(substr($class, 1), explode(' ', $node->getAttribute('class')));
     }
 }
Beispiel #2
0
 /**
  * function_description
  *
  * @param   unknown_type  $xmlcontents  XMLreader object
  *
  * @return return_description
  */
 private function extractCoordsGPX($xmlcontents)
 {
     $this->trackname = '';
     $this->trackCount = 0;
     // Iterate nodes
     $countElements = 0;
     $i_wpt = 0;
     $i_trk = 0;
     $wp = array();
     $this->trackCount = 0;
     while ($xmlcontents->read()) {
         // Check to ensure nodeType is an Element not attribute or #Text
         if ($xmlcontents->nodeType == XMLReader::ELEMENT) {
             // Start element found
             $currentElement = $xmlcontents->localName;
             $endElement = '';
             $countElements++;
             switch ($currentElement) {
                 case 'time':
                     // GPS file Time
                     $xmlcontents->read();
                     $time = $xmlcontents->value;
                     $dt = new DateTime($time);
                     $this->Date = $dt->format('Y-m-d');
                     // Read end tag
                     $xmlcontents->read();
                     break;
                 case 'wpt':
                     $wp[] = (array) $xmlcontents->readInnerXML();
                     $i_wpt++;
                     $this->wps[$i_wpt] = new WpClass();
                     $lat = (double) $xmlcontents->getAttribute('lat');
                     $lon = (double) $xmlcontents->getAttribute('lon');
                     $this->wps[$i_wpt]->sym = 'wp';
                     $this->wps[$i_wpt]->lat = $lat;
                     $this->wps[$i_wpt]->lon = $lon;
                     if ($lat > $this->bbox_lat_max) {
                         $this->bbox_lat_max = $lat;
                     }
                     if ($lat < $this->bbox_lat_min) {
                         $this->bbox_lat_min = $lat;
                     }
                     if ($lon > $this->bbox_lon_max) {
                         $this->bbox_lon_max = $lon;
                     }
                     if ($lon < $this->bbox_lon_min) {
                         $this->bbox_lon_min = $lon;
                     }
                     $endWptElement = false;
                     while (!$endWptElement) {
                         $xmlcontents->read();
                         if ($xmlcontents->nodeType == XMLReader::END_ELEMENT) {
                             $endWptElement = $xmlcontents->localName == 'wpt';
                         } else {
                             $endWptElement = false;
                         }
                         // Extract wpt data
                         if ($xmlcontents->nodeType == XMLReader::ELEMENT) {
                             $key = $xmlcontents->localName;
                             $xmlcontents->read();
                             $value = $xmlcontents->value;
                             $this->wps[$i_wpt]->{$key} = $value;
                             $xmlcontents->read();
                         }
                     }
                     break;
                 case 'trk':
                     // Track
                     $trackname = '';
                     $i_trk++;
                     while ('trk' !== $endElement) {
                         $xmlcontents->read();
                         if ($xmlcontents->nodeType == XMLReader::END_ELEMENT) {
                             // </xxx> found
                             $endElement = $xmlcontents->localName;
                         } else {
                             $endElement = '';
                         }
                         // Extract trk data
                         if ($xmlcontents->name == 'name' and $xmlcontents->nodeType == XMLReader::ELEMENT) {
                             $xmlcontents->read();
                             $trackname = $xmlcontents->value;
                             // Read end tag
                             $xmlcontents->read();
                         } elseif ($xmlcontents->name == 'trkseg' and $xmlcontents->nodeType == XMLReader::ELEMENT) {
                             // Trkseg found
                             $endTrksegElement = false;
                             $coords = array();
                             //TODOTODO$trackname = '';
                             $i_trkpt = 0;
                             $ele = 0;
                             $time = '0';
                             while (!$endTrksegElement) {
                                 $xmlcontents->read();
                                 if ($xmlcontents->nodeType == XMLReader::END_ELEMENT) {
                                     $endTrksegElement = $xmlcontents->localName == 'trkseg';
                                 } else {
                                     $endTrksegElement = false;
                                 }
                                 if ($xmlcontents->name == 'trkpt' and $xmlcontents->nodeType == XMLReader::ELEMENT) {
                                     // Trkpt found
                                     $i_trkpt++;
                                     $lat = (double) $xmlcontents->getAttribute('lat');
                                     $lon = (double) $xmlcontents->getAttribute('lon');
                                     if ($lat > $this->bbox_lat_max) {
                                         $this->bbox_lat_max = $lat;
                                     }
                                     if ($lat < $this->bbox_lat_min) {
                                         $this->bbox_lat_min = $lat;
                                     }
                                     if ($lon > $this->bbox_lon_max) {
                                         $this->bbox_lon_max = $lon;
                                     }
                                     if ($lon < $this->bbox_lon_min) {
                                         $this->bbox_lon_min = $lon;
                                     }
                                     // Read end tag
                                     // $xmlcontents->read();
                                 }
                                 if ($xmlcontents->name == 'ele' and $xmlcontents->nodeType == XMLReader::ELEMENT) {
                                     // Trkpt elevation found
                                     $xmlcontents->read();
                                     $ele = (double) $xmlcontents->value;
                                     // Read end tag
                                     $xmlcontents->read();
                                 }
                                 if ($xmlcontents->name == 'time' and $xmlcontents->nodeType == XMLReader::ELEMENT) {
                                     // Trkpt time found
                                     $xmlcontents->read();
                                     $time = (string) $xmlcontents->value;
                                     // Read end tag
                                     $xmlcontents->read();
                                 }
                                 if ($xmlcontents->name == 'trkpt' and $xmlcontents->nodeType == XMLReader::END_ELEMENT) {
                                     // End Trkpt
                                     $coords[] = array((string) $lon, (string) $lat, (string) $ele, (string) $time, 0);
                                 }
                             }
                             // End trkseg
                             $endTrksegElement = true;
                             $coordinatesCount = count($coords);
                             if ($coordinatesCount > 1) {
                                 // This is a track with more than 2 points
                                 $this->isTrack = true;
                                 $this->trackCount++;
                                 $this->track[$this->trackCount] = new stdClass();
                                 $this->track[$this->trackCount]->description = '';
                                 if ($trackname) {
                                     $this->track[$this->trackCount]->trackname = $trackname;
                                 } else {
                                     $this->track[$this->trackCount]->trackname = $this->trackname . '-' . (string) $this->trackCount;
                                 }
                                 $this->track[$this->trackCount]->coords = $coords;
                                 $this->track[$this->trackCount]->start = $coords[0][0] . "," . $coords[0][1];
                                 $this->track[$this->trackCount]->stop = $coords[$coordinatesCount - 1][0] . "," . $coords[$coordinatesCount - 1][1];
                             }
                         } else {
                             // Tag is not trk, trkseg, nor Name: proceed
                         }
                     }
                     break;
             }
         }
     }
     if (strlen($this->trackname) == 0) {
         if ($this->trackCount == 1) {
             if ($this->track[1]->trackname) {
                 $this->trackname = $this->track[1]->trackname;
             } else {
                 $this->trackname = $this->trackfilename;
             }
         } else {
             $this->trackname = $this->trackfilename;
         }
     }
     if (!$this->description) {
         if ($this->trackCount == 1) {
             $this->description = $this->track[1]->description ? $this->track[1]->description : '';
         } elseif ($this->trackCount > 1) {
             $this->description = $this->track[1]->description ? $this->track[1]->description : '';
             for ($i = 2; $i <= $this->trackCount; $i++) {
                 $this->description .= '<br>' . $this->track[$i]->description ? $this->track[$i]->description : '';
             }
         }
     }
     $xmlcontents->close();
     // Nothing to return
     return true;
 }
Beispiel #3
0
 /**
  * Returns the version number of the database.
  * @return mixed $version
  */
 public function getDatabaseVersion()
 {
     $this->connect();
     return $this->pdo->getAttribute(PDO::ATTR_CLIENT_VERSION);
 }
	/**
	 * Enter description here...
	 *
	 * In the future, when PHP will support XLS 2.0, then we would do that this way:
	 * contains(tokenize(@class, '\s'), "something")
	 * @param unknown_type $class
	 * @param unknown_type $node
	 * @return boolean
	 * @access private
	 */
	protected function matchClasses($class, $node) {
		// multi-class
		if ( mb_strpos($class, '.', 1)) {
			$classes = explode('.', substr($class, 1));
			$classesCount = count( $classes );
			$nodeClasses = explode(' ', $node->getAttribute('class') );
			$nodeClassesCount = count( $nodeClasses );
			if ( $classesCount > $nodeClassesCount )
				return false;
			$diff = count(
				array_diff(
					$classes,
					$nodeClasses
				)
			);
			if (! $diff )
				return true;
		// single-class
		} else {
			return in_array(
				// strip leading dot from class name
				substr($class, 1),
				// get classes for element as array
				explode(' ', $node->getAttribute('class') )
			);
		}
	}