public function getCity($ip) { $record = $this->fetchRow("select * from auto_pre_iptocity WHERE ip = ?", array($ip), 3600); if (!empty($record)) { $rec = json_decode($record['details'], 1); return $rec; } if (empty($record)) { $this->clearCache($this->sql, array($ip)); $details = iptocity($ip); if (empty($details) || $details['status'] != 'OK') { return false; } $geo = new Models_Geo(); $nearby = $geo->get_nearby_cities($details['lat'], $details['lon']); $rec = array(); foreach ($nearby as $v) { $rec = $v; break; } if (empty($rec)) { return false; } $d = array(); $d['ip'] = $ip; $d['details'] = json_encode($rec); $this->addDetails('auto_pre_iptocity', $d); return $rec; } return false; }
function findCity($city_id, $nearbyResults = false) { $geo = new Models_Geo(); global $modelGeneral; $cityDetails = $geo->cityDetail($city_id); if (empty($cityDetails)) { return false; } $cityDetails['sql'] = $geo->sql; $lat = !empty($cityDetails['latitude']) ? $cityDetails['latitude'] : null; $lon = !empty($cityDetails['longitude']) ? $cityDetails['longitude'] : null; $radius = 30; $order = 'distance'; $limit = 30; if ($nearbyResults) { if (empty($lat) || empty($lon)) { $cityDetails['nearby'] = array(); } else { $cityDetails['nearby'] = $geo->get_nearby_cities($lat, $lon, $radius, $order, $limit); } } if (empty($cityDetails['extraDetails'])) { $etc = fetchCityXtraDetails($lat, $lon); if (!empty($etc)) { $d = array(); $d['extraDetails'] = json_encode($etc); $d['lat_h'] = $etc['location']['lat_h']; $d['lat_m'] = $etc['location']['lat_m']; $d['lat_s'] = $etc['location']['lat_s']; $d['lon_h'] = $etc['location']['lon_h']; $d['lon_m'] = $etc['location']['lon_m']; $d['lon_e'] = $etc['location']['lon_e']; $d['zone_h'] = $etc['location']['zone_h']; $d['zone_m'] = $etc['location']['zone_m']; $d['dst'] = $etc['location']['dst']; $d['rawOffset'] = $etc['timezone']['rawOffset']; $d['dstOffset'] = $etc['timezone']['dstOffset']; $cityDetails = array_merge($cityDetails, $d); $where = sprintf('cty_id = %s', $modelGeneral->qstr($cityDetails['id'])); $modelGeneral->updateDetails('geo_cities', $d, $where); $modelGeneral->clearCache($cityDetails['sql']); } } else { $etc = json_decode($cityDetails['extraDetails'], 1); } $cityDetails['etc'] = $etc; $cityDetails['url'] = HTTPPATH . '/city-' . url_name_v2($cityDetails['city']) . '-' . $cityDetails['id']; $cityDetails['pageTitle'] = $cityDetails['city'] . ', ' . $cityDetails['statename'] . ', ' . $cityDetails['countryname']; return $cityDetails; }
function matchUserDate($uid, $lat, $lng, $custom_date) { if (empty($uid)) { return false; } if (empty($lat)) { return false; } if (empty($lng)) { return false; } if (empty($custom_date)) { return false; } global $modelGeneral; $query = "SELECT * FROM settings LEFT JOIN geo_cities ON settings.birth_city_id = geo_cities.cty_id WHERE 1 AND settings.uid = ?"; $settingsDetail = $modelGeneral->fetchRow($query, array($uid), 3600); if (empty($settingsDetail['dob'])) { return false; } if (empty($settingsDetail['birth_city_id'])) { return false; } $geo = new Models_Geo(); $nearby = $geo->get_nearby_cities($lat, $lng); if (empty($nearby)) { continue; } $cityDetails = array(); foreach ($nearby as $v) { $cityDetails = $v; break; } if (empty($cityDetails)) { return false; } $to = $cityDetails; if (empty($to['extraDetails'])) { $tmp = findCity($to['cty_id']); unset($tmp['nearby']); unset($tmp['etc']); $to = array_merge($to, $tmp); } if (!empty($settingsDetail['extraDetails']) && !empty($settingsDetail['birth_city_id'])) { $tmp = findCity($settingsDetail['birth_city_id']); unset($tmp['nearby']); unset($tmp['etc']); $settingsDetail = array_merge($settingsDetail, $tmp); } $to['dob'] = $custom_date; $matchResult = match($settingsDetail, $to); return $matchResult; }