forked from kingarthur2/superfecta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource-Canada411.module
53 lines (43 loc) · 2.04 KB
/
source-Canada411.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
<?php
//Created July 16,2011 by lgaetz
class Canada411 extends superfecta_base {
public $description = "http://www.canada411.ca - These listings include business and residential data for Canada.";
public $version_requirement = "2.11";
function get_caller_id($thenumber, $run_param=array()) {
$caller_id = null;
if (!$this->IsValidNumber('CA', $thenumber)) {
$this->DebugPrint("Skipping Source - Non Canadian number: " . $thenumber);
} else {
$this->DebugPrint("Searching www.canada411.ca ... ");
// By default, there is no match
$name = "";
// Set the url we're searching for valid as of July 16, 2011
$url = "http://canada411.yellowpages.ca/search/re/1/$thenumber";
$value = $this->get_url_contents($url);
// Patterns to search for
$regexp = array(
"/<span class=\"ypgWebNumberColumn ypgWebNumberColumnName\"><a href=\".*\">(.*)<\/a>/", //business results July 16, 2011
"/<div class=\"ypgBackfillListing\">\n(.*)<br>/", //residential results July 16, 2011
"/<span class=\"listingTitle\">(.+?)<\/span>/", //business results Jun 19, 2012
"/<div class=\"ypgBackfillListing\">\n(.+?)<br\/>/", //res results Jun 19, 2012
);
// Look through each pattern to see if we find a match -- take the first match
foreach ($regexp as $pattern) {
preg_match($pattern, $value, $match);
if (isset($match[1]) && (strlen(trim(strip_tags($match[1]))))) {
$name = trim(strip_tags($match[1]));
if ($name <> "UNAVAILABLE") {
break;
}
}
}
// If we found a match, return it
if (strlen($name) > 1 && $name <> "UNAVAILABLE") {
$caller_id = $name;
} else {
$this->DebugPrint("not found");
}
}
return($caller_id);
}
}