Esempio n. 1
0
 /**
  * Get geo info by IP from db
  */
 function _get_geo_data_from_db($cur_ip = "")
 {
     $cur_ip = trim(array_pop(explode(",", preg_replace("/[^0-9\\.,]/i", "", $cur_ip))));
     if (empty($cur_ip)) {
         return false;
     }
     if ($this->_is_ip_to_skip($cur_ip)) {
         return false;
     }
     $STORE_UNKNOWN_IPS = true;
     // Also check if IP is not recognized by our system and skip it
     if ($STORE_UNKNOWN_IPS && db()->query_num_rows("SELECT * FROM " . db('geo_skip_ip') . " WHERE ip = INET_ATON('" . _es($cur_ip) . "')")) {
         return false;
     }
     // Prepare query
     $sql = "SELECT * \n\t\t\tFROM " . db('geo_city_location') . " \n\t\t\tWHERE loc_id = ( \n\t\t\t\tSELECT loc_id FROM " . db('geo_city_blocks') . "\n\t\t\t\tWHERE start_ip <= INET_ATON('" . _es($cur_ip) . "') \n\t\t\t\t\tAND end_ip >= INET_ATON('" . _es($cur_ip) . "') \n\t\t\t\tLIMIT 1 \n\t\t\t)";
     $A = db()->query_fetch($sql);
     if (empty($A)) {
         if ($STORE_UNKNOWN_IPS) {
             db()->query("INSERT INTO " . db('geo_skip_ip') . " (\n\t\t\t\t\t\tip, hits\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\tINET_ATON('" . _es($cur_ip) . "'), 1\n\t\t\t\t\t) ON DUPLICATE KEY UPDATE hits = hits + 1");
         }
         return false;
     }
     $geo_data = ["country_code" => $A["country"], "country_name" => _country_name($A["country"]), "region_code" => $A["region"], "city_name" => $A["city"], "dma_code" => $A["dma_code"], "area_code" => $A["area_code"], "longitude" => $A["longitude"], "latitude" => $A["latitude"]];
     return $geo_data;
 }
Esempio n. 2
0
 function change_location_result()
 {
     if (!main()->USE_GEO_IP) {
         return false;
     }
     // Current system selected
     $sel_data = main()->_USER_GEO_DATA;
     if (empty($sel_data)) {
         return _e(t("Internal error #036. Please contact site admin."));
     }
     // Check if something has changed
     if (main()->USER_ID && !empty($sel_data)) {
         if ($sel_data["country_code"] && $sel_data["country_code"] != $this->_user_info["country"] || $sel_data["region_code"] && $sel_data["region_code"] != $this->_user_info["state"] || $sel_data["city_name"] && strtolower($sel_data["city_name"]) != strtolower($this->_user_info["city"]) || $sel_data["zip_code"] && $sel_data["zip_code"] != $this->_user_info["zip_code"]) {
             $something_changed = 1;
         }
     }
     // Prepare template
     $replace2 = ["form_action" => "./?object=" . 'geo_content' . "&action=change_location", "show_update_form" => main()->USER_ID && $something_changed ? 1 : 0, "city" => _prepare_html($sel_data["city_name"]), "region" => _prepare_html(_region_name($sel_data["region_code"], $sel_data["country_code"])), "country" => _prepare_html(_country_name($sel_data["country_code"])), "zip" => _prepare_html($sel_data["zip_code"])];
     return tpl()->parse('geo_content' . "/change_location_success", $replace2);
 }