forked from kingarthur2/superfecta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource-SE_clearsearch_HE.module
153 lines (134 loc) · 5.6 KB
/
source-SE_clearsearch_HE.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
class SE_clearsearch_HE extends superfecta_base {
public $description = "http://www.clearsearch.se - This listing include data from the Swedish Clearsearch directory.";
public $version_requirement = "2.11";
public $source_param = array (
'Search_Type' => array (
'description' => 'Enter 1=Personsok 2=Foretagssok 3=Bade Person och Foretag',
'type' => 'number'
)
);
function get_caller_id($thenumber, $run_param=array()) {
$debug = $this->debug;
$this->DebugPrint("Searching clearsearch.se... ");
$number_error = false;
//check for the correct digits for Sweden in international format.
// international dialing prefix + country code + number
if (strlen($thenumber) > 8) {
if (substr($thenumber,0,2) == '46')
{
$thenumber = '0'.substr($thenumber, 2);
}
else
{
if (substr($thenumber,0,4) == '0046')
{
$thenumber = '0'.substr($thenumber, 4);
}
else
{
if (substr($thenumber,0,5) == '01146')
{
$thenumber = '0'.substr($thenumber,5);
}
else
{
$number_error = true;
}
}
}
}
// number
if(strlen($thenumber) < 11)
{
if (substr($thenumber,0,1) == '0')
{
$number_error = false;
}
else
{
$number_error = true;
}
}
if(!$number_error)
{
$this->DebugPrint("Numret ar svenskt, slar nu upp numret.");
if($run_param['Search_Type'] != 2)
{
$this->DebugPrint("Search for PERSON in clearsearch.se... ");
$url="http://www.clearsearch.se/personer/-/q_$thenumber/1/";
$value = $this->get_url_contents($url);
$notfound = strpos($value, "inte hitta"); //No hit.
$notfound = ($notfound < 1) ? strpos($value, "inte hitta") : $notfound;
if($notfound)
{
$value = "";
$this->DebugPrint("clearsearch PERSON reports number not found!<br>\n");
}
else
{
$start = strpos($value, "class=\"result-bn medium\" itemprop=\"name\">");
$value = substr($value,$start+42);
$end = strpos($value, "</span>");
$value = substr($value,0,$end);
$value = str_replace("\r\n", "", $value);
$value = str_replace(" ", "", $value);
$this->DebugPrint("Resultatet:".$value);
}
if (strlen($value) > 1)
{
$caller_id = strip_tags($value);
return($caller_id);
}
else
{
$this->DebugPrint("clearsearch PERSON returns no data!<br>\n");
}
}
if($run_param['Search_Type'] >= 2)
{
$this->DebugPrint("Search for BUSINESS in clearsearch.se... ");
$url="http://www.clearsearch.se/foretag/-/q_$thenumber/1/";
$value = $this->get_url_contents($url);
$notfound = strpos($value, "inte hitta"); //No hit.
$notfound = ($notfound < 1) ? strpos($value, "inte hitta") : $notfound;
if($notfound)
{
$value = "";
$this->DebugPrint("clearsearch BUSINESS reports number not found!<br>\n");
}
else
{
$start = strpos($value, "class=\"result-bn medium\">");
$value = substr($value,$start+30);
$end = strpos($value, "</span>");
$value = substr($value,0,$end);
$value = str_replace("\r\n", "", $value);
$value = str_replace(" ", "", $value);
$this->DebugPrint("Resultatet:".$value);
}
if (strlen($value) > 1)
{
$caller_id = strip_tags($value);
return($caller_id);
}
else
{
$this->DebugPrint("clearserach BUSINESS returns no data!<br>\n");
}
}
}
else
{
$this->DebugPrint("Skipping Source - Non Swedish number: ".$thenumber."<br>\n");
}
}
function cisf_url_encode_array($arr){
$string = "";
foreach ($arr as $key => $value) {
$string .= $key . "=" . urlencode($value) . "&";
}
trim($string,"&");
return $string;
}
}