Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature 2885: Add geoip info in the stats / history page
git-svn-id: http://piwigo.org/svn/trunk@22664 68402e56-0260-453c-a942-63ccdbb3a9ee
- Loading branch information
rvelices
committed
May 14, 2013
1 parent
e979634
commit d2c695e
Showing
5 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
GeoIp = { | ||
cache: {}, | ||
pending: {}, | ||
|
||
get: function(ip, callback){ | ||
if (GeoIp.cache.hasOwnProperty(ip)) | ||
callback(GeoIp.cache[ip]); | ||
else if (GeoIp.pending[ip]) | ||
GeoIp.pending[ip].push(callback); | ||
else { | ||
GeoIp.pending[ip] = [callback]; | ||
jQuery.ajax( { | ||
url: "http://freegeoip.net/json/" + ip, | ||
dataType: "json", | ||
success: function(data) { | ||
var res=[]; | ||
if (data.city) res.push(data.city); | ||
if (data.region_name) res.push(data.region_name); | ||
if (data.country_name) res.push(data.country_name); | ||
data.fullName = res.join(", "); | ||
|
||
GeoIp.cache[ip] = data; | ||
var callbacks = GeoIp.pending[ip]; | ||
delete GeoIp.pending[ip]; | ||
for (var i=0; i<callbacks.length; i++) | ||
callbacks[i].call(null, data); | ||
}, | ||
|
||
error: function() { | ||
var data = {ip:ip, fullName:""}; | ||
|
||
GeoIp.cache[ip] = data; | ||
var callbacks = GeoIp.pending[ip]; | ||
delete GeoIp.pending[ip]; | ||
for (var i=0; i<callbacks.length; i++) | ||
callbacks[i].call(null, data); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters