You are here

function smart_ip_get_csv_source_filename in Smart IP 6.2

Same name and namespace in other branches
  1. 6 smart_ip.module \smart_ip_get_csv_source_filename()
  2. 7.2 smart_ip.module \smart_ip_get_csv_source_filename()
  3. 7 smart_ip.module \smart_ip_get_csv_source_filename()

Helper function for grabbing Maxmind's CSV archive filename.

3 calls to smart_ip_get_csv_source_filename()
smart_ip_admin_settings in includes/smart_ip.admin.inc
Smart IP administration settings.
smart_ip_run_batch in ./smart_ip.module
Menu page callback for Smart IP batch operations.
smart_ip_update_db_batch in includes/smart_ip.utility.inc
Prepare a batch definition

File

./smart_ip.module, line 1325
Determines country, geo location (longitude/latitude), region, city and postal code of the user, based on IP address

Code

function smart_ip_get_csv_source_filename() {
  static $maxmind_csv;
  if (empty($maxmind_csv)) {

    // Get CSV list of zip files
    $html = smart_ip_file_get_contents(SMART_IP_MAXMIND_LITE_CSV_DOWNLOAD_BASE_URL);
    $regex = '/GeoLiteCity_' . format_date((int) $_SERVER['REQUEST_TIME'], 'custom', 'Ym') . '.{2}\\.zip/';
    preg_match($regex, $html, $match);

    // Check if Maxmind CSV file not updated, then fallback to the previous month
    if (empty($match)) {
      $regex = '/GeoLiteCity_' . format_date((int) $_SERVER['REQUEST_TIME'] - 2764800, 'custom', 'Ym') . '.{2}\\.zip/';
      preg_match($regex, $html, $match);
      $maxmind_csv = check_url(SMART_IP_MAXMIND_LITE_CSV_DOWNLOAD_BASE_URL . '/' . $match[0]);
    }
    else {
      $maxmind_csv = check_url(SMART_IP_MAXMIND_LITE_CSV_DOWNLOAD_BASE_URL . '/GeoLiteCity-latest.zip');
    }
  }
  return $maxmind_csv;
}