This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlovidy_Location.php
95 lines (91 loc) · 3.14 KB
/
Flovidy_Location.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
class Flovidy_Location {
public $country = "";
public $ipaddress;
public $link = "";
public $newRef = "";
function __construct() {
$this->country = "us";
}
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
$this->ipaddress = $ipaddress;
}
function get_country() {
$file = plugins_url('/GeoIP.dat', __FILE__);
include("geoip.inc");
$gi = geoip_open(__DIR__.'/GeoIP.dat', GEOIP_MMAP_CACHE);
$country = geoip_country_code_by_addr($gi, $this->ipaddress);
if ($country == false){
$country = 'us';
} else if ($country == 'US'){
$country = 'us';
} else if ($country == 'IN'){
$country = 'in';
} else if ($country == 'JP'){
$country = 'co.jp';
} else if ($country == 'FR'){
$country = 'fr';
} else if ($country == 'DE'){
$country = 'de';
} else if ($country == 'IT'){
$country = 'it';
} else if ($country == 'ES'){
$country = 'es';
} else if ($country == 'GB'){
$country = 'co.uk';
} else if ($country == 'CA'){
$country = 'ca';
} else if ($country == 'BR'){
$country = 'com.br';
} else if ($country == 'CN'){
$country = 'cn';
} else if ($country == 'AU'){
$country = 'com.au';
} else {
$country = 'us';
}
$this->country = $country;
}
function get_referral_tag(){
if ($this->country == 'co.uk'){
$this->link = 'uk_link';
$this->newRef = trim(get_option("Flovidy_Plugin_uk_ref"));
} elseif ($this->country == 'co.jp'){
$this->link = 'jp_link';
$this->newRef = trim(get_option("Flovidy_Plugin_jp_ref"));
} elseif ($this->country == 'com.br'){
$this->link = 'br_link';
$this->newRef = trim(get_option("Flovidy_Plugin_br_ref"));
} elseif ($this->country == 'com.au'){
$this->link = 'au_link';
$this->newRef = trim(get_option("Flovidy_Plugin_au_ref"));
} else {
$this->link = $this->country.'_link';
$this->newRef = trim(get_option("Flovidy_Plugin_" .$this->country. '_ref'));
}
}
function getNewRef(){
return $this->newRef;
}
function getCountry(){
return $this->country;
}
function getLink(){
return $this->link;
}
}