forked from kingarthur2/superfecta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource-Telco_Data.module
97 lines (81 loc) · 3.35 KB
/
source-Telco_Data.module
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
96
97
<?php
class Telco_Data extends superfecta_base {
public $description = "http://www.telcodata.com - These listings are generally only return the geographic location of the caller, not a name.";
public $version_requirement = "2.11";
function get_caller_id($thenumber, $run_param=array()) {
$caller_id = null;
$number_error = false;
$this->DebugPrint("Searching Telco Data ... : {$thenumber}");
//check for the correct 11 digits in US/CAN phone numbers in international format.
// country code + number
if (strlen($thenumber) == 11) {
if (substr($thenumber, 0, 1) == 1) {
$thenumber = substr($thenumber, 1);
} else {
$number_error = true;
}
}
// international dialing prefix + country code + number
if (strlen($thenumber) > 11) {
if (substr($thenumber, 0, 3) == '001') {
$thenumber = substr($thenumber, 3);
} else {
if (substr($thenumber, 0, 4) == '0111') {
$thenumber = substr($thenumber, 4);
} else {
$number_error = true;
}
}
}
// check for short number
if (strlen($thenumber) < 10) {
$number_error = true;
}
if (!$number_error) {
$npa = substr($thenumber, 0, 3);
$nxx = substr($thenumber, 3, 3);
// check for valid area code (201 or higher)
if ($npa < '201') {
$number_error = true;
} else {
// Check for Toll-Free numbers (including future TF NPA's)
$TFnpalist = array(
"800", "822", "833", "844", "855", "866", "877", "888"
);
if (in_array($npa, $TFnpalist)) {
$number_error = true;
}
}
}
if ($number_error) {
$this->DebugPrint("Skipping Source - Toll Free or International (non-NANP) number: {$thenumber}");
} else {
$url = "http://www.telcodata.us/query/queryexchangexml.html?npa=$npa&nxx=$nxx";
$value = $this->get_url_contents($url);
// Telcodata will tell us if we have an invalid NPA/NXX
$start = strpos($value, "<valid>");
$valid = substr($value, $start + 7);
$end = strpos($valid, "</valid>");
$valid = substr($valid, 0, $end);
if ($valid == 'NO') {
$this->DebugPrint("Skipping Source - Telcodata reports invalid NPA/NXX: {$thenumber}");
} else {
$start = strpos($value, "<ratecenter>");
$ratecenter = substr($value, $start + 12);
$end = strpos($ratecenter, "</ratecenter>");
$ratecenter = substr($ratecenter, 0, $end);
$start = strpos($value, "<state>");
$state = substr($value, $start + 7);
$end = strpos($state, "</state>");
$state = substr($state, 0, $end);
$value = $ratecenter . ", " . $state;
if (strlen($ratecenter) > 1) {
$caller_id = strip_tags($value);
} else {
$this->DebugPrint("not found");
}
}
}
return($caller_id);
}
}