/
country.php
77 lines (60 loc) · 1.86 KB
/
country.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
<?php
function CID_get_country($ip) {
require_once(dirname(__FILE__).'/ip2c/ip2c.php');
if (isset($GLOBALS['ip2c'])) {
global $ip2c;
} else {
$ip2c = new ip2country(dirname(__FILE__).'/ip2c/ip-to-country.bin');
$GLOBALS['ip2c'] = $ip2c;
}
return $ip2c->get_country($ip);
}
function CID_get_flag($ip) {
if($ip == '127.0.0.1'){
$code = 'wordpress';
$name = 'Localhost';
}else{
$country = CID_get_country($ip);
if (!$country) return "";
$code = strtolower($country['id2']);
$name = $country['name'];
}
global $CID_options;
$output = stripslashes($CID_options['flag_template']);
if (!$output) return "";
$output = str_replace("%COUNTRY_CODE%", $code, $output);
$output = str_replace("%COUNTRY_NAME%", $name, $output);
$output = str_replace("%COMMENTER_IP%", $ip, $output);
$output = str_replace("%IMAGE_BASE%", $CID_options['flag_icons_url'], $output);
return $output;
}
function CID_get_flag_without_template($ip, $show_image = true, $show_text = true, $before = '', $after = '') {
if($ip == '127.0.0.1'){
$code = 'wordpress';
$name = 'Localhost';
}else{
$country = CID_get_country($ip);
if (!$country) return "";
$code = strtolower($country['id2']);
$name = $country['name'];
}
global $CID_options;
$output = '';
if ($show_image)
$output = '<img src="' . $CID_options['flag_icons_url'] . '/' . $code . '.png" title="' . $name . '" alt="' . $name . '" class="country-flag" />';
if ($show_text)
$output .= ' ' . $name;
return $before . $output . $after;
}
function CID_get_comment_flag() {
$ip = get_comment_author_IP();
return CID_get_flag($ip);
}
function CID_get_comment_flag_without_template() {
$ip = get_comment_author_IP();
return CID_get_flag_without_template($ip);
}
function CID_print_comment_flag() {
echo CID_get_comment_flag();
}
?>