public static function setupCache($ip) { $driver = Config::inst()->get('IPInfoCache', 'Driver'); if (!$driver) { foreach (self::$defaultDrivers as $defaultDriver) { if (class_exists($defaultDriver)) { $driver = $defaultDriver; break; } } if (!$driver) { user_error('A driver needs to be specified'); } } $ipService = new $driver(); $dbJson = $ipService->processIP($ip); // do not cache a empty object if ($dbJson) { $cache = IPInfoCache::create(); $cache->IP = $ip; $cache->Info = $dbJson; $cache->write(); } return $ipService->getJSON(); }
public function geoip() { $ip = $this->getRequest()->param('IP'); $fn = $this->getRequest()->getVar('callback'); $requestType = $this->getRequest()->getExtension(); $ipCache = IPInfoCache::get()->filter(array('IP' => $ip))->first(); if ($ipCache && $ipCache->exists()) { if (strtotime($ipCache->LastEdited) < strtotime('24 hours ago')) { $ipCache->clearIPCache(); } $details = $ipCache->getDetails(); } else { $details = IPInfoCache::setupCache($ip); } $this->response->addHeader('Content-Type', 'application/json'); $cors = Config::inst()->get('IPInfoCache', 'CORS'); if ($cors) { $this->response->addHeader('Access-Control-Allow-Origin', '*'); } if ($requestType == 'jsonp') { $fn = isset($fn) ? $fn : Config::inst()->get('IPInfoCache', 'jsonp'); if ($fn) { return "{$fn}(" . $details . ');'; } } return $details; }
public static function setupCache($ip) { $driver = Config::inst()->get('IPInfoCache', 'Driver'); $ipService = new $driver(); $dbJson = $ipService->processIP($ip); $cache = IPInfoCache::create(); $cache->IP = $ip; $cache->Info = $dbJson; $cache->write(); return $ipService->getJSON(); }
public function geoip() { $ip = $this->getRequest()->param('IP'); $ipCache = IPInfoCache::get()->filter(array('IP' => $ip))->first(); if ($ipCache && $ipCache->exists()) { if (strtotime($ipCache->LastEdited) < strtotime('24 hours ago')) { $ipCache->clearIPCache(); } $details = $ipCache->getDetails(); } else { $details = IPInfoCache::setupCache($ip); } return $details; }