forked from ip2location-com/ip2location-piwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.php
More file actions
46 lines (42 loc) · 1.16 KB
/
API.php
File metadata and controls
46 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\IP2Location;
use Piwik\Plugins\IP2Location\IP2Location as IP2LocationPHP;
/**
* API for plugin IP2Location
*
* @method static \Piwik\Plugins\IP2Location\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Example method. Please remove if you do not need this API method.
* You can call this API method like this:
* /index.php?module=API&method=IP2Location.getAnswerToLife
* /index.php?module=API&method=IP2Location.getAnswerToLife?truth=0
*
* @param bool $truth
*
* @return bool
*/
static function lookup($ipAddress, $dbFile)
{
require_once(PIWIK_INCLUDE_PATH . '/plugins/IP2Location/Lookup.php');
$db = new Lookup($dbFile);
$records = $db->lookup($ipAddress, Lookup::ALL);
return array(
'countryCode'=>$records->countryCode,
'countryName'=>$records->countryName,
'regionName'=>$records->regionName,
'cityName'=>$records->cityName,
'latitude'=>$records->latitude,
'longitude'=>$records->longitude,
);
}
}