You are here

function smart_ip_get_csv_source_filename in Smart IP 7

Same name and namespace in other branches
  1. 6.2 smart_ip.module \smart_ip_get_csv_source_filename()
  2. 6 smart_ip.module \smart_ip_get_csv_source_filename()
  3. 7.2 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 699
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() {
  $maxmind_csv =& drupal_static(__FUNCTION__);
  if (!isset($maxmind_csv)) {

    // Get CSV list of zip files
    $html = file_get_contents('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV');
    $regex = '/GeoLiteCity_' . format_date(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(time() - 2764800, 'custom', 'Ym') . '.{2}\\.zip/';
      preg_match($regex, $html, $match);
      if (isset($match[0])) {
        $maxmind_csv = check_url('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/' . $match[0]);
        return $maxmind_csv;
      }
    }
    $maxmind_csv = check_url('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity-latest.zip');
  }
  return $maxmind_csv;
}