function geoip_detect_update() { $download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'; $outFile = geoip_detect_get_database_upload_filename(); // Download $tmpFile = download_url($download_url); if (is_wp_error($tmpFile)) { return $tmpFile->get_error_message(); } // Ungzip File $zh = gzopen($tmpFile, 'r'); $h = fopen($outFile, 'w'); if (!$zh) { return __('Downloaded file could not be opened for reading.', 'geoip-detect'); } if (!$h) { return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile); } while (($string = gzread($zh, 4096)) != false) { fwrite($h, $string, strlen($string)); } gzclose($zh); fclose($h); //unlink($tmpFile); return true; }
function geoip_detect_update() { // TODO: Currently cron is scheduled but not executed. Remove scheduling. if (get_option('geoip-detect-source') != 'auto') { return; } $download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz'; $download_url = apply_filters('geoip_detect2_download_url', $download_url); $outFile = geoip_detect_get_database_upload_filename(); // Download $tmpFile = download_url($download_url); if (is_wp_error($tmpFile)) { return $tmpFile->get_error_message(); } // Ungzip File $zh = gzopen($tmpFile, 'r'); $h = fopen($outFile, 'w'); if (!$zh) { return __('Downloaded file could not be opened for reading.', 'geoip-detect'); } if (!$h) { return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile); } while (($string = gzread($zh, 4096)) != false) { fwrite($h, $string, strlen($string)); } gzclose($zh); fclose($h); unlink($tmpFile); return true; }
function setUp() { parent::setUp(); // unlink uploads file if exists if (function_exists('geoip_detect_get_database_upload_filename')) { $filename = geoip_detect_get_database_upload_filename(); if (file_exists($filename)) { @unlink($filename); } } }
function testUpdaterFileFilter() { $this->assertEquals('', geoip_detect_get_database_upload_filename_filter('')); $this->assertContains('/upload', geoip_detect_get_database_upload_filename()); }