/** * Initializes the class. The real startup is done by the initialize() call. */ public function __construct() { $this->_component = 'org.routamc.positioning'; parent::__construct(); }
/** * Import manually entered log entry. The entries are associative arrays containing * some or all of the following keys: * * - latitude * - longitude * - altitude * - city * - country * - aerodrome * - timestamp * * @param Array $log Log entry in Array format specific to importer * @return boolean Indicating success. */ function import($log) { $this->log = new org_routamc_positioning_log_dba(); $this->log->importer = 'manual'; // Set different person if required if (array_key_exists('person', $log)) { $this->log->person = $log['person']; } else { $this->log->person = midcom_connection::get_user(); } if (array_key_exists('timestamp', $log)) { $this->log->date = (int) $log['timestamp']; } else { $this->log->date = time(); } // Figure out which option we will use, starting from best option // Best option: we know coordinates if (array_key_exists('latitude', $log) && array_key_exists('longitude', $log)) { // Manually entered positions are assumed to be only semi-accurate $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_MANUAL; // Normalize coordinates to decimal $coordinates = $this->normalize_coordinates($log['latitude'], $log['longitude']); $this->log->latitude = $coordinates['latitude']; $this->log->longitude = $coordinates['longitude']; } // Airport entered if (array_key_exists('aerodrome', $log)) { // Aerodrome position is not usually very accurate, except if we're at the airport of course $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_CITY; // Normalize aerodrome name $aerodrome = strtoupper($log['aerodrome']); // Seek the aerodrome entry, first by accurate match $aerodrome_entry = null; $qb = org_routamc_positioning_aerodrome_dba::new_query_builder(); $qb->begin_group('OR'); // We will seek by both ICAO and IATA codes $qb->add_constraint('icao', '=', $aerodrome); $qb->add_constraint('iata', '=', $aerodrome); $qb->end_group(); $matches = $qb->execute(); if (count($matches) > 0) { $aerodrome_entry = $matches[0]; } if (is_null($aerodrome_entry)) { // Couldn't match the entered city to a location $this->error = 'POSITIONING_AERODROME_NOT_FOUND'; return false; } // Normalize coordinates $this->log->latitude = $aerodrome_entry->latitude; $this->log->longitude = $aerodrome_entry->longitude; $this->log->altitude = $aerodrome_entry->altitude; } // City and country entered if (array_key_exists('city', $log)) { if (!isset($log['geocoder'])) { $log['geocoder'] = 'city'; } $geocoder = org_routamc_positioning_geocoder::create($log['geocoder']); $position = $geocoder->geocode($log); if (!$position['latitude'] || !$position['longitude']) { // Couldn't match the entered city to a location $this->error = 'POSITIONING_CITY_NOT_FOUND'; return false; } foreach ($position as $key => $value) { $this->log->{$key} = $value; } } // Save altitude if provided if (array_key_exists('altitude', $log)) { $this->log->altitude = $log['altitude']; } // Try to create the entry $stat = $this->log->create(); $this->error = midcom_connection::get_error_string(); return $stat; }
<?php midcom::get('auth')->require_valid_user(); // Read location from session or user's location log $user_location = org_routamc_positioning_user::get_location(); if (is_null($user_location)) { // No location found, try to geocode based on user IP $geocoder = org_routamc_positioning_geocoder::create('geoplugin'); $location_parameters = array('ip' => $_SERVER['REMOTE_ADDR']); $user_location = $geocoder->geocode($location_parameters); if (!is_null($user_location)) { // Store geocoded location to session or user's location log org_routamc_positioning_user::set_location($user_location); } } if (!is_null($user_location)) { echo sprintf('You\'re in %s, %s', $user_location['latitude'], $user_location['longitude']); // Will print "You're in 60.2345, 25.00456" } else { if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { echo "You're here"; } else { echo "No location found"; } }
$service = 'city'; } else { $service = $_GET['service']; } if (!isset($_GET['dir'])) { $direction = ''; } else { $direction = 'reverse_'; } $options = array(); if (isset($_GET['options']) && is_array($_GET['options'])) { foreach ($_GET['options'] as $key => $value) { $options[$key] = $value; } } $geocoder = org_routamc_positioning_geocoder::create($service); $location = array(); foreach ($_GET as $key => $value) { switch ($key) { case 'longitude': case 'latitude': if (!empty($direction)) { $location[$key] = $value; } // Accept only XEP-0080 values // Accept only XEP-0080 values case 'area': case 'building': case 'country': case 'description': case 'floor':