forked from icho53/TelegramV2rayCollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
703 lines (647 loc) · 20.6 KB
/
functions.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<?php
function compare_time( $a, $b )
{
$a_time = strtotime( $a->time );
$b_time = strtotime( $b->time );
if ( $a_time == $b_time )
return 0;
return ($a_time > $b_time) ? -1 : 1;
}
function convert_to_timezone( $utc_timestamp, $timezone = 'Asia/Tehran' )
{
$utc_datetime = new DateTime( $utc_timestamp );
$utc_datetime->setTimezone(new DateTimeZone( $timezone ));
return $utc_datetime->format("Y-m-d H:i:s");
}
/** Gregorian & Jalali (Hijri_Shamsi,Solar) Date Converter Functions
Author: JDF.SCR.IR =>> Download Full Version : http://jdf.scr.ir/jdf
License: GNU/LGPL _ Open Source & Free :: Version: 2.80 : [2020=1399]
---------------------------------------------------------------------
355746=361590-5844 & 361590=(30*33*365)+(30*8) & 5844=(16*365)+(16/4)
355666=355746-79-1 & 355668=355746-79+1 & 1595=605+990 & 605=621-16
990=30*33 & 12053=(365*33)+(32/4) & 36524=(365*100)+(100/4)-(100/100)
1461=(365*4)+(4/4) & 146097=(365*400)+(400/4)-(400/100)+(400/400) */
function gregorian_to_jalali( $gy, $gm, $gd )
{
$g_d_m = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
$gy2 = ($gm > 2) ? ($gy + 1) : $gy;
$days = 355666 + (365 * $gy) + ((int)(($gy2 + 3) / 4)) - ((int)(($gy2 + 99) / 100)) + ((int)(($gy2 + 399) / 400)) + $gd + $g_d_m[$gm - 1];
$jy = -1595 + (33 * ((int)($days / 12053)));
$days %= 12053;
$jy += 4 * ((int)($days / 1461));
$days %= 1461;
if ( $days > 365 ) {
$jy += (int)(($days - 1) / 365);
$days = ($days - 1) % 365;
}
if ($days < 186) {
$jm = 1 + (int)($days / 31);
$jd = 1 + ($days % 31);
}
else {
$jm = 7 + (int)(($days - 186) / 30);
$jd = 1 + (($days - 186) % 30);
}
$jm = strlen($jm) == 1 ? "0$jm" : $jm;
$jd = ($jd < 10) ? "0$jd" : $jd;
return array($jy, $jm, $jd);
}
function create_config_name( $channel, $flag, $ping, $custom_id = null, $type = null, $tunnel = false )
{
$subscripts = array('₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉');
// create unique id from date/time
if ( SUB_JALALI_DATE ) {
$jdate = gregorian_to_jalali( date("Y"), date("m"), date("d") );
$date = "$jdate[0]₋$jdate[1]₋$jdate[2]__";
}
else {
$date = date("Y₋m₋d__");
}
$id = ( is_null($custom_id) ? '' : ('[' . $custom_id . '] ') ) . str_replace( range(0, 9), $subscripts, $date . date("H₋i₋s") );
// flag
$flag = is_null($flag) ? "🚩" : $flag;
// reality check
$reality = ( $type === 'reality' ) ? true : false;
// prepare type text
if ( $reality && $tunnel ) {
$typetext = ' • 🆁eality | 🆃unnel';
}
elseif ( $reality ) {
$typetext = ' • 🆁eality';
}
elseif ( $tunnel ) {
$typetext = ' • 🆃unnel';
}
else {
$typetext = '';
}
// final config name
$config_name = "$flag @$channel{$typetext} • $id";
return $config_name;
}
function get_config($channel, $type, $id)
{
$final_data = [];
$get = file_get_contents("https://t.me/s/" . $channel);
$channels_assets = json_decode(file_get_contents("modules/channels/channels_assets.json"), true);
switch( $type )
{
case 'vmess':
preg_match_all(
'/vmess:\/\/[^"]+(?:[^<]+<[^<]+)*<time datetime="([^"]+)"/',
$get,
$matches
);
$pattern_config = "#vmess://(.*?)<#";
break;
case 'vless':
preg_match_all(
'/vless:\/\/[^"]+(?:[^<]+<[^<]+)*<time datetime="([^"]+)"/',
$get,
$matches
);
$pattern_config = "#vless://(.*?)<#";
break;
case 'trojan':
preg_match_all(
'/trojan:\/\/[^"]+(?:[^<]+<[^<]+)*<time datetime="([^"]+)"/',
$get,
$matches
);
$pattern_config = "#trojan://(.*?)<#";
break;
default:
return false;
}
preg_match_all($pattern_config, $get, $configs);
$key_limit = count($configs[1]) - 3;
$i = 0;
foreach ( $configs[1] as $key => $config )
{
if ( $key > $key_limit )
{
if ( !stripos($config, "...") )
{
if ( strpos($config, "<br/>") )
{
$config = substr( $config, 0, strpos($config, "<br/>") );
}
if ( $type == 'vmess' )
{
$the_config = decode_vmess( $type . "://" . $config );
$ip = !empty($the_config["sni"])
? $the_config["sni"]
: ( !empty($the_config["host"]) ? $the_config["host"] : $the_config["add"] );
}
else
{
$the_config = parse_proxy_url( $type . "://" . $config, $type );
$ip = !empty($the_config["params"]["sni"])
? $the_config["params"]["sni"]
: ( !empty($the_config["params"]["host"]) ? $the_config["params"]["host"] : $the_config["hostname"]);
// change type if it is Reality
$type = stripos($config, "reality") ? "reality" : $type;
}
// get port
$port = $the_config["port"];
// check ping base on IP & port
$ping = ping( $ip, $port );
if ( $ping )
{
$i++;
$ip_info = ip_info( $ip );
$country = isset( $ip_info["country"] ) ? $ip_info["country"] : null;
$tunnel = ( strtoupper( $country ) == 'IR' ) ? true : false;
$flag = isset( $ip_info["country"] ) ? get_flag( $ip_info["country"] ) : null;
$custom_id = "$id-$i";
if ( $type == 'vmess' )
{
$the_config["ps"] = create_config_name( $channel, $flag, $ping, $custom_id, $type, $tunnel );
$final_config = encode_vmess($the_config);
}
else
{
$the_config["hash"] = create_config_name( $channel, $flag, $ping, $custom_id, $type, $tunnel );
$final_config = build_proxy_url($the_config, $type);
}
$final_data[$key]["channel"]['username'] = $channel;
$final_data[$key]["channel"]['title'] = $channels_assets[$channel]['title'];
$final_data[$key]["channel"]['logo'] = $channels_assets[$channel]['logo'];
$final_data[$key]["type"] = $type;
$final_data[$key]["config"] = ($type == 'vmess') ? $final_config : urldecode($final_config);
$final_data[$key]["time"] = @convert_to_timezone( $matches[1][$key] );
}
}
}
}
return $final_data;
}
function get_flag( $country_code )
{
$country_list = array(
"AF" => "Afghanistan",
"AL" => "Albania",
"DZ" => "Algeria",
"AS" => "American Samoa",
"AD" => "Andorra",
"AO" => "Angola",
"AI" => "Anguilla",
"AQ" => "Antarctica",
"AG" => "Antigua and Barbuda",
"AR" => "Argentina",
"AM" => "Armenia",
"AW" => "Aruba",
"AU" => "Australia",
"AT" => "Austria",
"AZ" => "Azerbaijan",
"BS" => "Bahamas",
"BH" => "Bahrain",
"BD" => "Bangladesh",
"BB" => "Barbados",
"BY" => "Belarus",
"BE" => "Belgium",
"BZ" => "Belize",
"BJ" => "Benin",
"BM" => "Bermuda",
"BT" => "Bhutan",
"BO" => "Bolivia",
"BA" => "Bosnia and Herzegovina",
"BW" => "Botswana",
"BV" => "Bouvet Island",
"BR" => "Brazil",
"BQ" => "British Antarctic Territory",
"IO" => "British Indian Ocean Territory",
"VG" => "British Virgin Islands",
"BN" => "Brunei",
"BG" => "Bulgaria",
"BF" => "Burkina Faso",
"BI" => "Burundi",
"KH" => "Cambodia",
"CM" => "Cameroon",
"CA" => "Canada",
"CT" => "Canton and Enderbury Islands",
"CV" => "Cape Verde",
"KY" => "Cayman Islands",
"CF" => "Central African Republic",
"TD" => "Chad",
"CL" => "Chile",
"CN" => "China",
"CX" => "Christmas Island",
"CC" => "Cocos [Keeling] Islands",
"CO" => "Colombia",
"KM" => "Comoros",
"CG" => "Congo - Brazzaville",
"CD" => "Congo - Kinshasa",
"CK" => "Cook Islands",
"CR" => "Costa Rica",
"HR" => "Croatia",
"CU" => "Cuba",
"CY" => "Cyprus",
"CZ" => "Czech Republic",
"CI" => "Côte d’Ivoire",
"DK" => "Denmark",
"DJ" => "Djibouti",
"DM" => "Dominica",
"DO" => "Dominican Republic",
"NQ" => "Dronning Maud Land",
"DD" => "East Germany",
"EC" => "Ecuador",
"EG" => "Egypt",
"SV" => "El Salvador",
"GQ" => "Equatorial Guinea",
"ER" => "Eritrea",
"EE" => "Estonia",
"ET" => "Ethiopia",
"FK" => "Falkland Islands",
"FO" => "Faroe Islands",
"FJ" => "Fiji",
"FI" => "Finland",
"FR" => "France",
"GF" => "French Guiana",
"PF" => "French Polynesia",
"TF" => "French Southern Territories",
"FQ" => "French Southern and Antarctic Territories",
"GA" => "Gabon",
"GM" => "Gambia",
"GE" => "Georgia",
"DE" => "Germany",
"GH" => "Ghana",
"GI" => "Gibraltar",
"GR" => "Greece",
"GL" => "Greenland",
"GD" => "Grenada",
"GP" => "Guadeloupe",
"GU" => "Guam",
"GT" => "Guatemala",
"GG" => "Guernsey",
"GN" => "Guinea",
"GW" => "Guinea-Bissau",
"GY" => "Guyana",
"HT" => "Haiti",
"HM" => "Heard Island and McDonald Islands",
"HN" => "Honduras",
"HK" => "Hong Kong SAR China",
"HU" => "Hungary",
"IS" => "Iceland",
"IN" => "India",
"ID" => "Indonesia",
"IR" => "Iran",
"IQ" => "Iraq",
"IE" => "Ireland",
"IM" => "Isle of Man",
"IL" => "Israel",
"IT" => "Italy",
"JM" => "Jamaica",
"JP" => "Japan",
"JE" => "Jersey",
"JT" => "Johnston Island",
"JO" => "Jordan",
"KZ" => "Kazakhstan",
"KE" => "Kenya",
"KI" => "Kiribati",
"KW" => "Kuwait",
"KG" => "Kyrgyzstan",
"LA" => "Laos",
"LV" => "Latvia",
"LB" => "Lebanon",
"LS" => "Lesotho",
"LR" => "Liberia",
"LY" => "Libya",
"LI" => "Liechtenstein",
"LT" => "Lithuania",
"LU" => "Luxembourg",
"MO" => "Macau SAR China",
"MK" => "Macedonia",
"MG" => "Madagascar",
"MW" => "Malawi",
"MY" => "Malaysia",
"MV" => "Maldives",
"ML" => "Mali",
"MT" => "Malta",
"MH" => "Marshall Islands",
"MQ" => "Martinique",
"MR" => "Mauritania",
"MU" => "Mauritius",
"YT" => "Mayotte",
"FX" => "Metropolitan France",
"MX" => "Mexico",
"FM" => "Micronesia",
"MI" => "Midway Islands",
"MD" => "Moldova",
"MC" => "Monaco",
"MN" => "Mongolia",
"ME" => "Montenegro",
"MS" => "Montserrat",
"MA" => "Morocco",
"MZ" => "Mozambique",
"MM" => "Myanmar [Burma]",
"NA" => "Namibia",
"NR" => "Nauru",
"NP" => "Nepal",
"NL" => "Netherlands",
"AN" => "Netherlands Antilles",
"NT" => "Neutral Zone",
"NC" => "New Caledonia",
"NZ" => "New Zealand",
"NI" => "Nicaragua",
"NE" => "Niger",
"NG" => "Nigeria",
"NU" => "Niue",
"NF" => "Norfolk Island",
"KP" => "North Korea",
"VD" => "North Vietnam",
"MP" => "Northern Mariana Islands",
"NO" => "Norway",
"OM" => "Oman",
"PC" => "Pacific Islands Trust Territory",
"PK" => "Pakistan",
"PW" => "Palau",
"PS" => "Palestinian Territories",
"PA" => "Panama",
"PZ" => "Panama Canal Zone",
"PG" => "Papua New Guinea",
"PY" => "Paraguay",
"YD" => "People's Democratic Republic of Yemen",
"PE" => "Peru",
"PH" => "Philippines",
"PN" => "Pitcairn Islands",
"PL" => "Poland",
"PT" => "Portugal",
"PR" => "Puerto Rico",
"QA" => "Qatar",
"RO" => "Romania",
"RU" => "Russia",
"RW" => "Rwanda",
"RE" => "Réunion",
"BL" => "Saint Barthélemy",
"SH" => "Saint Helena",
"KN" => "Saint Kitts and Nevis",
"LC" => "Saint Lucia",
"MF" => "Saint Martin",
"PM" => "Saint Pierre and Miquelon",
"VC" => "Saint Vincent and the Grenadines",
"WS" => "Samoa",
"SM" => "San Marino",
"SA" => "Saudi Arabia",
"SN" => "Senegal",
"RS" => "Serbia",
"CS" => "Serbia and Montenegro",
"SC" => "Seychelles",
"SL" => "Sierra Leone",
"SG" => "Singapore",
"SK" => "Slovakia",
"SI" => "Slovenia",
"SB" => "Solomon Islands",
"SO" => "Somalia",
"ZA" => "South Africa",
"GS" => "South Georgia and the South Sandwich Islands",
"KR" => "South Korea",
"ES" => "Spain",
"LK" => "Sri Lanka",
"SD" => "Sudan",
"SR" => "Suriname",
"SJ" => "Svalbard and Jan Mayen",
"SZ" => "Swaziland",
"SE" => "Sweden",
"CH" => "Switzerland",
"SY" => "Syria",
"ST" => "São Tomé and Príncipe",
"TW" => "Taiwan",
"TJ" => "Tajikistan",
"TZ" => "Tanzania",
"TH" => "Thailand",
"TL" => "Timor-Leste",
"TG" => "Togo",
"TK" => "Tokelau",
"TO" => "Tonga",
"TT" => "Trinidad and Tobago",
"TN" => "Tunisia",
"TR" => "Turkey",
"TM" => "Turkmenistan",
"TC" => "Turks and Caicos Islands",
"TV" => "Tuvalu",
"UM" => "U.S. Minor Outlying Islands",
"PU" => "U.S. Miscellaneous Pacific Islands",
"VI" => "U.S. Virgin Islands",
"UG" => "Uganda",
"UA" => "Ukraine",
"SU" => "Union of Soviet Socialist Republics",
"AE" => "United Arab Emirates",
"GB" => "United Kingdom",
"US" => "United States",
"ZZ" => "Unknown or Invalid Region",
"UY" => "Uruguay",
"UZ" => "Uzbekistan",
"VU" => "Vanuatu",
"VA" => "Vatican City",
"VE" => "Venezuela",
"VN" => "Vietnam",
"WK" => "Wake Island",
"WF" => "Wallis and Futuna",
"EH" => "Western Sahara",
"YE" => "Yemen",
"ZM" => "Zambia",
"ZW" => "Zimbabwe",
"AX" => "Åland Islands",
);
if ( !array_key_exists( strtoupper($country_code), $country_list) )
return "🚩";
return (string) preg_replace_callback(
'/./',
static fn (array $letter) => mb_chr(ord($letter[0]) % 32 + 0x1F1E5),
$country_code
);
}
function get_reality($input)
{
$array = explode("\n", $input);
$output = "";
foreach ( $array as $item )
{
if ( stripos($item, "reality") )
{
$output .= $output === "" ? $item : "\n$item";
}
}
return $output;
}
function get_tunnel($input)
{
$array = explode("\n", $input);
$output = "";
foreach ( $array as $item )
{
if ( stripos($item, "🆃unnel") )
{
$output .= $output === "" ? $item : "\n$item";
}
}
return $output;
}
function is_ip( $string )
{
return filter_var($string, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
function ip_info( $ip )
{
if ( is_ip($ip) === false )
{
$ip_address_array = dns_get_record($ip, DNS_A);
$ip = $ip_address_array[0]['ip'];
}
// change ip request to "curl"
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.country.is/$ip",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
curl_close($curl);
$ipinfo = json_decode($response, true);
if ( isset($ipinfo['error']) )
{
$ipinfo['ip'] = '127.0.0.1';
$ipinfo['country'] = 'Unknown';
}
return $ipinfo;
}
function ping($ip, $port)
{
$it = microtime(true);
if ( is_numeric($port) )
{
try {
$check = @fsockopen($ip, $port, $errno, $errstr, 1);
}
catch (Exception $e) {
return false;
}
}
$ft = microtime(true);
$militime = intval(($ft - $it) * 1e3, 2);
return $militime;
}
function decode_vmess($vmess_config)
{
$vmess_data = substr($vmess_config, 8); // remove "vmess://"
$decoded_data = json_decode(base64_decode($vmess_data), true);
return $decoded_data;
}
function encode_vmess($config)
{
$encoded_data = base64_encode(json_encode($config));
$vmess_config = "vmess://" . $encoded_data;
return $vmess_config;
}
function remove_duplicate_vmess($input)
{
$array = explode("\n", $input);
foreach ($array as $item) {
$parts = decode_vmess($item);
$part_ps = $parts["ps"];
unset($parts["ps"]);
if (count($parts) >= 3) {
ksort($parts);
$part_serialize = serialize($parts);
$result[$part_serialize][] = $part_ps ?? "";
}
}
$finalResult = [];
foreach ($result as $serial => $ps) {
$partAfterHash = $ps[0] ?? "";
$part_serialize = unserialize($serial);
$part_serialize["ps"] = $partAfterHash;
$finalResult[] = encode_vmess($part_serialize);
}
$output = "";
foreach ($finalResult as $config) {
$output .= $output == "" ? $config : "\n" . $config;
}
return $output;
}
function parse_proxy_url($url, $type = "trojan")
{
// Parse the URL into components
$parsedUrl = parse_url($url);
// Extract the parameters from the query string
$params = [];
if ( isset($parsedUrl["query"]) )
{
parse_str($parsedUrl["query"], $params);
}
// Construct the output object
$output = [
"protocol" => $type,
"username" => isset($parsedUrl["user"]) ? $parsedUrl["user"] : "",
"hostname" => isset($parsedUrl["host"]) ? $parsedUrl["host"] : "",
"port" => isset($parsedUrl["port"]) ? $parsedUrl["port"]: "",
"params" => $params,
"hash" => isset($parsedUrl["fragment"]) ? $parsedUrl["fragment"] : "",
];
return $output;
}
function build_proxy_url( $obj, $type = "trojan" )
{
// Construct the base URL
$url = $type . "://";
if ( $obj["username"] !== "" )
{
$url .= $obj["username"];
if ( isset($obj["pass"]) && $obj["pass"] !== "" )
{
$url .= ":" . $obj["pass"];
}
$url .= "@";
}
$url .= $obj["hostname"];
if ( isset($obj["port"]) && $obj["port"] !== "" )
{
$url .= ":" . $obj["port"];
}
// Add the query parameters
if ( !empty($obj["params"]) )
{
$url .= "?" . http_build_query($obj["params"]);
}
// Add the fragment identifier
if ( isset($obj["hash"]) && $obj["hash"] !== "" )
{
$url .= "#" . $obj["hash"];
}
return $url;
}
function remove_duplicate_xray( $input, $type )
{
if ( empty(trim( $input )) )
return;
$array = explode( "\n", $input );
foreach ( $array as $item )
{
$parts = parse_proxy_url( $item, $type );
$part_hash = $parts["hash"];
unset($parts["hash"]);
ksort($parts["params"]);
$part_serialize = serialize( $parts );
$result[$part_serialize][] = $part_hash ?? "";
}
$finalResult = [];
foreach ( $result as $url => $parts )
{
$partAfterHash = $parts[0] ?? "";
$part_serialize = unserialize( $url );
$part_serialize["hash"] = $partAfterHash;
$finalResult[] = build_proxy_url( $part_serialize, $type );
}
$output = "";
foreach ( $finalResult as $config )
{
$output .= $output == "" ? $config : "\n" . $config;
}
return $output;
}