forked from dvygolov/YellowCloaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
159 lines (139 loc) · 4.15 KB
/
db.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
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
154
155
156
157
158
159
<?php
require_once __DIR__."/db/Classes/IoHelper.php";
require_once __DIR__."/db/SleekDB.php";
require_once __DIR__."/db/Store.php";
require_once __DIR__."/db/QueryBuilder.php";
require_once __DIR__."/db/Query.php";
require_once __DIR__."/db/Cache.php";
require_once __DIR__."/cookies.php";
use SleekDB\Store;
function add_white_click($data,$reason) {
$dataDir = __DIR__ . "/logs";
$wclicksStore = new Store("whiteclicks", $dataDir);
$calledIp = $data['ip'];
$country = $data['country'];
$dt = new DateTime();
$time = $dt->getTimestamp();
$os = $data['os'];
$isp = str_replace(',',' ',$data['isp']);
$user_agent = str_replace(',',' ',$data['ua']);
parse_str($_SERVER['QUERY_STRING'],$queryarr);
$click =[
"time"=>$time,
"ip"=>$calledIp,
"country"=>$country,
"os"=>$os,
"isp"=>$isp,
"ua"=>$user_agent,
"reason"=>$reason,
"subs"=>$queryarr
];
$wclicksStore->insert($click);
}
function add_black_click($subid,$data,$preland,$land) {
$dataDir = __DIR__ . "/logs";
$bclicksStore = new Store("blackclicks", $dataDir);
$calledIp = $data['ip'];
$country = $data['country'];
$dt = new DateTime();
$time = $dt->getTimestamp();
$os = $data['os'];
$isp = str_replace(',',' ',$data['isp']);
$user_agent = str_replace(',',' ',$data['ua']);
$prelanding=empty($preland)?'unknown':$preland;
$landing=empty($land)?'unknown':$land;
parse_str($_SERVER['QUERY_STRING'],$queryarr);
$click =[
"subid"=>$subid,
"time"=>$time,
"ip"=>$calledIp,
"country"=>$country,
"os"=>$os,
"isp"=>$isp,
"ua"=>$user_agent,
"subs"=>$queryarr,
"preland"=>$prelanding,
"land"=>$landing
];
$bclicksStore->insert($click);
}
function add_lead($subid,$name,$phone,$status='Lead') {
$dataDir = __DIR__ . "/logs";
$leadsStore = new Store("leads", $dataDir);
$fbp=get_cookie('_fbp');
$fbclid=get_cookie('fbclid');
if ($fbclid==='') $fbclid=get_cookie('_fbc');
if ($status=='') $status='Lead';
$dt = new DateTime();
$time = $dt->getTimestamp();
$land = get_cookie('landing');
$preland = get_cookie('prelanding');
if (empty($preland)) $preland='unknown';
$lead=[
"subid"=>$subid,
"time"=>$time,
"name"=>$name,
"phone"=>$phone,
"status"=>$status,
"fbp"=>$fbp,
"fbclid"=>$fbclid,
"preland"=>$preland,
"land" => $land
];
$leadsStore->insert($lead);
}
function email_exists_for_subid($subid){
$dataDir = __DIR__ . "/logs";
$leadsStore = new Store("leads", $dataDir);
$lead=$leadsStore->findOneBy([["subid","=",$subid]]);
if ($lead===null) return false;
if (array_key_exists("email",$lead)) return true;
return false;
}
function add_email($subid,$email){
$dataDir = __DIR__ . "/logs";
$leadsStore = new Store("leads", $dataDir);
$lead=$leadsStore->findOneBy([["subid","=",$subid]]);
if ($lead===null) return;
$lead["email"]=$email;
$leadsStore->update($lead);
}
function add_lpctr($subid,$preland){
$dataDir = __DIR__ . "/logs";
$lpctrStore = new Store("lpctr", $dataDir);
$dt = new DateTime();
$time = $dt->getTimestamp();
$lpctr = [
"time"=>$time,
"subid"=>$subid,
"preland"=>$preland
];
$lpctrStore->insert($lpctr);
}
//проверяем, есть ли в файле лидов subid текущего пользователя
//если есть, и также есть такой же номер - значит ЭТО ДУБЛЬ!
//И нам не нужно слать его в ПП и не нужно показывать пиксель ФБ!!
function lead_is_duplicate($subid,$phone){
$dataDir = __DIR__ . "/logs";
$leadsStore = new Store("leads", $dataDir);
if($subid!=''){
$lead=$leadsStore->findOneBy([["subid","=",$subid]]);
if ($lead===null) return false;
header("YWBDuplicate: We have this sub!");
$phoneexists = ($lead["phone"]===$phone);
if ($phoneexists){
header("YWBDuplicate: We have this phone!");
return true;
}
else{
return false;
}
}
else {
//если куки c subid у нас почему-то нет, то проверяем по номеру телефона
$lead=$leadsStore->findOneBy([["phone","=",$phone]]);
if ($lead===null) return false;
return true;
}
}
?>