@@ -219,8 +219,9 @@ discard block |
||
219 | 219 | if (telegram::$status) { |
220 | 220 | $check = $check->status; |
221 | 221 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
222 | + } else { |
|
223 | + $result[$id] = null; |
|
222 | 224 | } |
223 | - else $result[$id] = null; |
|
224 | 225 | } |
225 | 226 | return $result; |
226 | 227 | } |
@@ -262,8 +263,7 @@ discard block |
||
262 | 263 | curl_exec($ch); |
263 | 264 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
264 | 265 | curl_close($ch); |
265 | - } |
|
266 | - else { |
|
266 | + } else { |
|
267 | 267 | $path = realpath($path); |
268 | 268 | $size = file_exists($path) ? filesize($path) : false; |
269 | 269 | } |
@@ -353,9 +353,13 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public static function downloadFile (string $url, string $path, int $chunk_size = 512): bool { |
355 | 355 | $file = fopen($url, 'rb'); |
356 | - if (!$file) return false; |
|
356 | + if (!$file) { |
|
357 | + return false; |
|
358 | + } |
|
357 | 359 | $path = fopen($path, 'wb'); |
358 | - if (!$path) return false; |
|
360 | + if (!$path) { |
|
361 | + return false; |
|
362 | + } |
|
359 | 363 | |
360 | 364 | $length = $chunk_size * 1024; |
361 | 365 | while (!feof($file)){ |
@@ -462,8 +466,9 @@ discard block |
||
462 | 466 | foreach ($string as $k => &$v) { |
463 | 467 | if ($diff->{$v}) { |
464 | 468 | $v = $diff->{$v}; |
469 | + } else { |
|
470 | + unset($string[$k]); |
|
465 | 471 | } |
466 | - else unset($string[$k]); |
|
467 | 472 | } |
468 | 473 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
469 | 474 | |
@@ -529,8 +534,7 @@ discard block |
||
529 | 534 | if ($last === "\0") { |
530 | 535 | $new .= str_repeat($last, ord($char)); |
531 | 536 | $last = ''; |
532 | - } |
|
533 | - else { |
|
537 | + } else { |
|
534 | 538 | $new .= $last; |
535 | 539 | $last = $char; |
536 | 540 | } |
@@ -614,7 +618,9 @@ discard block |
||
614 | 618 | } |
615 | 619 | $rows = []; |
616 | 620 | foreach ($keyboard as $row) { |
617 | - if (!is_array($row)) continue; |
|
621 | + if (!is_array($row)) { |
|
622 | + continue; |
|
623 | + } |
|
618 | 624 | $buttons = []; |
619 | 625 | foreach ($row as $base_button) { |
620 | 626 | $button_info = explode('||', $base_button); |
@@ -623,15 +629,12 @@ discard block |
||
623 | 629 | if (count($button_info) > 1) { |
624 | 630 | if ($button_info[1] === 'con') { |
625 | 631 | $button->setRequest_contact(true); |
626 | - } |
|
627 | - elseif ($button_info[1] === 'loc') { |
|
632 | + } elseif ($button_info[1] === 'loc') { |
|
628 | 633 | $button->setRequest_location(true); |
629 | - } |
|
630 | - elseif ($button_info[1] === 'poll') { |
|
634 | + } elseif ($button_info[1] === 'poll') { |
|
631 | 635 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
632 | 636 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
633 | - } |
|
634 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
637 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
635 | 638 | $url = $button_info[2]; |
636 | 639 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
637 | 640 | } |
@@ -654,12 +657,10 @@ discard block |
||
654 | 657 | if (isset($button_info[1])) { |
655 | 658 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
656 | 659 | $button->setUrl($button_info[1]); |
657 | - } |
|
658 | - else { |
|
660 | + } else { |
|
659 | 661 | $button->setCallback_data($button_info[1]); |
660 | 662 | } |
661 | - } |
|
662 | - else { |
|
663 | + } else { |
|
663 | 664 | $button->setUrl('https://t.me/BPT_CH'); |
664 | 665 | } |
665 | 666 | $buttons[] = $button; |
@@ -686,8 +687,12 @@ discard block |
||
686 | 687 | * @return string |
687 | 688 | */ |
688 | 689 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
689 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
690 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
690 | + if (empty($user_id)) { |
|
691 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
692 | + } |
|
693 | + if (empty($bot_username)) { |
|
694 | + $bot_username = telegram::getMe()->username; |
|
695 | + } |
|
691 | 696 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
692 | 697 | } |
693 | 698 | |
@@ -756,7 +761,9 @@ discard block |
||
756 | 761 | $array[] = $num % 62; |
757 | 762 | $num = floor($num / 62); |
758 | 763 | } |
759 | - if (count($array) < 1) $array = [0]; |
|
764 | + if (count($array) < 1) { |
|
765 | + $array = [0]; |
|
766 | + } |
|
760 | 767 | foreach ($array as &$value) { |
761 | 768 | $value = $codes[$value]; |
762 | 769 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * tools class , gather what ever you need |
33 | 33 | */ |
34 | -class tools{ |
|
34 | +class tools { |
|
35 | 35 | /** |
36 | 36 | * Check the given username format |
37 | 37 | * |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return bool |
45 | 45 | */ |
46 | - public static function isUsername (string $username): bool { |
|
46 | + public static function isUsername(string $username): bool { |
|
47 | 47 | $length = strlen($username); |
48 | 48 | return !str_contains($username, '__') && $length >= 4 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username); |
49 | 49 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | - public static function ipInRange (string $ip, string $range): bool { |
|
63 | + public static function ipInRange(string $ip, string $range): bool { |
|
64 | 64 | if (!str_contains($range, '/')) { |
65 | 65 | $range .= '/32'; |
66 | 66 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public static function isTelegram (string $ip): bool { |
|
83 | + public static function isTelegram(string $ip): bool { |
|
84 | 84 | return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22'); |
85 | 85 | } |
86 | 86 | |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return bool |
97 | 97 | */ |
98 | - public static function isCloudFlare (string $ip): bool { |
|
98 | + public static function isCloudFlare(string $ip): bool { |
|
99 | 99 | $cf_ips = ['173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22', '103.31.4.0/22', '141.101.64.0/18', '108.162.192.0/18', '190.93.240.0/20', '188.114.96.0/20', '197.234.240.0/22', '198.41.128.0/17', '162.158.0.0/15', '104.16.0.0/12', '104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22']; |
100 | 100 | foreach ($cf_ips as $cf_ip) { |
101 | - if (self::ipInRange($ip,$cf_ip)) { |
|
101 | + if (self::ipInRange($ip, $cf_ip)) { |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | } |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return bool |
118 | 118 | */ |
119 | - public static function isArvanCloud (string $ip): bool { |
|
119 | + public static function isArvanCloud(string $ip): bool { |
|
120 | 120 | $ar_ips = ['185.143.232.0/22', '92.114.16.80/28', '2.146.0.0/28', '46.224.2.32/29', '89.187.178.96/29', '195.181.173.128/29', '89.187.169.88/29', '188.229.116.16/29', '83.123.255.56/31', '164.138.128.28/31', '94.182.182.28/30', '185.17.115.176/30', '5.213.255.36/31', '138.128.139.144/29', '5.200.14.8/29', '188.122.68.224/29', '188.122.83.176/29', '213.179.217.16/29', '185.179.201.192/29', '43.239.139.192/29', '213.179.197.16/29', '213.179.201.192/29', '109.200.214.248/29', '138.128.141.16/29', '188.122.78.136/29', '213.179.211.32/29', '103.194.164.24/29', '185.50.105.136/29', '213.179.213.16/29', '162.244.52.120/29', '188.122.80.240/29', '109.200.195.64/29', '109.200.199.224/29', '185.228.238.0/28', '94.182.153.24/29', '94.101.182.0/27', '37.152.184.208/28', '78.39.156.192/28', '158.255.77.238/31', '81.12.28.16/29', '176.65.192.202/31', '2.144.3.128/28', '89.45.48.64/28', '37.32.16.0/27', '37.32.17.0/27', '37.32.18.0/27']; |
121 | 121 | foreach ($ar_ips as $ar_ip) { |
122 | - if (self::ipInRange($ip,$ar_ip)) { |
|
122 | + if (self::ipInRange($ip, $ar_ip)) { |
|
123 | 123 | return true; |
124 | 124 | } |
125 | 125 | } |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return bool|user return array when verify is active and token is true array of telegram getMe result |
141 | 141 | */ |
142 | - public static function isToken (string $token, bool $verify = false): bool|user { |
|
142 | + public static function isToken(string $token, bool $verify = false): bool | user { |
|
143 | 143 | if (!preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) { |
144 | 144 | return false; |
145 | 145 | } |
146 | - if (!$verify){ |
|
146 | + if (!$verify) { |
|
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | $res = telegram::me($token); |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool { |
|
176 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool { |
|
177 | 177 | if (!is_array($ids)) { |
178 | 178 | $ids = [$ids]; |
179 | 179 | } |
180 | 180 | $user_id = $user_id ?? request::catchFields('user_id'); |
181 | 181 | |
182 | 182 | foreach ($ids as $id) { |
183 | - $check = telegram::getChatMember($id,$user_id); |
|
183 | + $check = telegram::getChatMember($id, $user_id); |
|
184 | 184 | if (telegram::$status) { |
185 | 185 | $check = $check->status; |
186 | 186 | if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) { |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return array keys will be id and values will be bool(null for not founded ids) |
209 | 209 | */ |
210 | - public static function joinChecker (array|string|int $ids , int|null $user_id = null): array { |
|
210 | + public static function joinChecker(array | string | int $ids, int | null $user_id = null): array { |
|
211 | 211 | if (!is_array($ids)) { |
212 | 212 | $ids = [$ids]; |
213 | 213 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $result = []; |
217 | 217 | foreach ($ids as $id) { |
218 | - $check = telegram::getChatMember($id,$user_id); |
|
218 | + $check = telegram::getChatMember($id, $user_id); |
|
219 | 219 | if (telegram::$status) { |
220 | 220 | $check = $check->status; |
221 | 221 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @return bool |
236 | 236 | */ |
237 | 237 | public static function isShorted(string $text): bool{ |
238 | - return preg_match('/^[a-zA-Z0-9]+$/',$text); |
|
238 | + return preg_match('/^[a-zA-Z0-9]+$/', $text); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * |
254 | 254 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
255 | 255 | */ |
256 | - public static function size (string $path, bool $format = true, bool $space_between = true): string|int|false { |
|
256 | + public static function size(string $path, bool $format = true, bool $space_between = true): string | int | false { |
|
257 | 257 | if (filter_var($path, FILTER_VALIDATE_URL)) { |
258 | 258 | $ch = curl_init($path); |
259 | 259 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $size = file_exists($path) ? filesize($path) : false; |
269 | 269 | } |
270 | 270 | if (isset($size) && is_numeric($size)) { |
271 | - return $format ? tools::byteFormat($size, space_between: $space_between) : $size; |
|
271 | + return $format ? tools::byteFormat($size, space_between : $space_between) : $size; |
|
272 | 272 | } |
273 | 273 | return false; |
274 | 274 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @return bool |
287 | 287 | * @throws bptException |
288 | 288 | */ |
289 | - public static function delete (string $path, bool $sub = true): bool { |
|
289 | + public static function delete(string $path, bool $sub = true): bool { |
|
290 | 290 | $path = realpath($path); |
291 | 291 | if (!is_dir($path)) { |
292 | 292 | return unlink($path); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | return rmdir($path); |
296 | 296 | } |
297 | 297 | if (!$sub) { |
298 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
298 | + logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR); |
|
299 | 299 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
300 | 300 | } |
301 | 301 | $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @return bool |
318 | 318 | * @throws bptException when zip extension not found |
319 | 319 | */ |
320 | - public static function zip (string $path, string $destination): bool { |
|
320 | + public static function zip(string $path, string $destination): bool { |
|
321 | 321 | if (!extension_loaded('zip')) { |
322 | 322 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
323 | 323 | throw new bptException('ZIP_EXTENSION_MISSING'); |
@@ -351,14 +351,14 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return bool true on success and false in failure |
353 | 353 | */ |
354 | - public static function downloadFile (string $url, string $path, int $chunk_size = 512): bool { |
|
354 | + public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool { |
|
355 | 355 | $file = fopen($url, 'rb'); |
356 | 356 | if (!$file) return false; |
357 | 357 | $path = fopen($path, 'wb'); |
358 | 358 | if (!$path) return false; |
359 | 359 | |
360 | 360 | $length = $chunk_size * 1024; |
361 | - while (!feof($file)){ |
|
361 | + while (!feof($file)) { |
|
362 | 362 | fwrite($path, fread($file, $length), $length); |
363 | 363 | } |
364 | 364 | fclose($path); |
@@ -382,10 +382,10 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @return string |
384 | 384 | */ |
385 | - public static function byteFormat (int $byte, int $precision = 2, bool $space_between = true): string { |
|
385 | + public static function byteFormat(int $byte, int $precision = 2, bool $space_between = true): string { |
|
386 | 386 | $rate_counter = 0; |
387 | 387 | |
388 | - while ($byte > 1024){ |
|
388 | + while ($byte > 1024) { |
|
389 | 389 | $byte /= 1024; |
390 | 390 | $rate_counter++; |
391 | 391 | } |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | $byte = round($byte, $precision); |
395 | 395 | } |
396 | 396 | |
397 | - return $byte . ($space_between ? ' ' : '') . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
397 | + return $byte.($space_between ? ' ' : '').['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -411,10 +411,10 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @return string|false return false when mode is incorrect |
413 | 413 | */ |
414 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
414 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
415 | 415 | return match ($mode) { |
416 | - parseMode::HTML => str_replace(['&', '<', '>',], ['&', '<', '>',], $text), |
|
417 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
416 | + parseMode::HTML => str_replace(['&', '<', '>', ], ['&', '<', '>', ], $text), |
|
417 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
418 | 418 | parseMode::MARKDOWNV2 => str_replace( |
419 | 419 | ['\\', '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'], |
420 | 420 | ['\\\\', '\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!'], |
@@ -453,9 +453,9 @@ discard block |
||
453 | 453 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
454 | 454 | * @throws Exception |
455 | 455 | */ |
456 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
456 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
457 | 457 | $base_time = new DateTime($base_time ?? '@'.time()); |
458 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
458 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
459 | 459 | |
460 | 460 | $diff = $base_time->diff($target_time); |
461 | 461 | $string = ['year' => 'y', 'month' => 'm', 'day' => 'd', 'hour' => 'h', 'minute' => 'i', 'second' => 's']; |
@@ -481,12 +481,12 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return string[]|string |
483 | 483 | */ |
484 | - public static function realEscapeString(string|array $input): string|array { |
|
485 | - if(is_array($input)) { |
|
484 | + public static function realEscapeString(string | array $input): string | array { |
|
485 | + if (is_array($input)) { |
|
486 | 486 | return array_map(__METHOD__, $input); |
487 | 487 | } |
488 | 488 | |
489 | - if(!empty($input) && is_string($input)) { |
|
489 | + if (!empty($input) && is_string($input)) { |
|
490 | 490 | return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input); |
491 | 491 | } |
492 | 492 | |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | * |
505 | 505 | * @return string[]|string |
506 | 506 | */ |
507 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
507 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
508 | 508 | $pos = strpos($subject, $search); |
509 | 509 | if ($pos !== false) { |
510 | 510 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * |
524 | 524 | * @return string[]|string |
525 | 525 | */ |
526 | - public static function strReplaceLast(string|array $search, string|array $replace, string|array $subject): string|array { |
|
526 | + public static function strReplaceLast(string | array $search, string | array $replace, string | array $subject): string | array { |
|
527 | 527 | $pos = strrpos($subject, $search); |
528 | 528 | if ($pos !== false) { |
529 | 529 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @return string see possible values in fileType class |
542 | 542 | */ |
543 | - public static function fileType (string $file_id): string { |
|
543 | + public static function fileType(string $file_id): string { |
|
544 | 544 | $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '=')); |
545 | 545 | $new = ''; |
546 | 546 | $last = ''; |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $last = $char; |
555 | 555 | } |
556 | 556 | } |
557 | - $data = unpack('VtypeId/Vdc_id', $new . $last); |
|
557 | + $data = unpack('VtypeId/Vdc_id', $new.$last); |
|
558 | 558 | $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216; |
559 | 559 | return [ |
560 | 560 | fileTypes::THUMBNAIL, |
@@ -592,10 +592,10 @@ discard block |
||
592 | 592 | * |
593 | 593 | * @return string |
594 | 594 | */ |
595 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
595 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
596 | 596 | $rand_string = ''; |
597 | 597 | $char_len = strlen($characters) - 1; |
598 | - for ($i = 0; $i < $length; $i ++) { |
|
598 | + for ($i = 0; $i < $length; $i++) { |
|
599 | 599 | $rand_string .= $characters[rand(0, $char_len)]; |
600 | 600 | } |
601 | 601 | return $rand_string; |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
625 | 625 | * @throws bptException |
626 | 626 | */ |
627 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
627 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
628 | 628 | if (!empty($keyboard)) { |
629 | 629 | $keyboard_object = new replyKeyboardMarkup(); |
630 | 630 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | $keyboard_object->setInline_keyboard($rows); |
689 | 689 | return $keyboard_object; |
690 | 690 | } |
691 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
691 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
692 | 692 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
693 | 693 | } |
694 | 694 | |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | * |
705 | 705 | * @return string |
706 | 706 | */ |
707 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
707 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
708 | 708 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
709 | 709 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
710 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
710 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
@@ -733,9 +733,9 @@ discard block |
||
733 | 733 | * @return string|bool|array{hash:string, key:string, iv:string} |
734 | 734 | * @throws bptException |
735 | 735 | */ |
736 | - public static function codec (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
736 | + public static function codec(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
737 | 737 | if (!extension_loaded('openssl')) { |
738 | - logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
738 | + logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
739 | 739 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
740 | 740 | } |
741 | 741 | if ($action === codecAction::ENCRYPT) { |
@@ -746,16 +746,16 @@ discard block |
||
746 | 746 | } |
747 | 747 | if ($action === codecAction::DECRYPT) { |
748 | 748 | if (empty($key)) { |
749 | - logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR); |
|
749 | + logger::write("tools::codec function used\nkey parameter is not set", loggerTypes::ERROR); |
|
750 | 750 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
751 | 751 | } |
752 | 752 | if (empty($iv)) { |
753 | - logger::write("tools::codec function used\niv parameter is not set",loggerTypes::ERROR); |
|
753 | + logger::write("tools::codec function used\niv parameter is not set", loggerTypes::ERROR); |
|
754 | 754 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
755 | 755 | } |
756 | 756 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
757 | 757 | } |
758 | - logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
758 | + logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
759 | 759 | return false; |
760 | 760 | } |
761 | 761 | |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | public static function shortEncode(int $num): string { |
772 | 772 | $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
773 | 773 | $array = []; |
774 | - while ($num > 0){ |
|
774 | + while ($num > 0) { |
|
775 | 775 | $array[] = $num % 62; |
776 | 776 | $num = floor($num / 62); |
777 | 777 | } |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | foreach ($array as &$value) { |
780 | 780 | $value = $codes[$value]; |
781 | 781 | } |
782 | - return strrev(implode('',$array)); |
|
782 | + return strrev(implode('', $array)); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | $num = 0; |
797 | 797 | $text = str_split(strrev($text)); |
798 | 798 | foreach ($text as $key=>$value) { |
799 | - $num += strpos($codes,$value) * pow(62,$key); |
|
799 | + $num += strpos($codes, $value) * pow(62, $key); |
|
800 | 800 | } |
801 | 801 | return $num; |
802 | 802 | } |
@@ -881,20 +881,17 @@ discard block |
||
881 | 881 | foreach ($arguments['media'] as $key => $media) { |
882 | 882 | if ($media['media'] instanceof CURLFile) { |
883 | 883 | $remove_answer = true; |
884 | - } |
|
885 | - elseif (is_string($media['media']) && file_exists(realpath($media['media']))) { |
|
884 | + } elseif (is_string($media['media']) && file_exists(realpath($media['media']))) { |
|
886 | 885 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
887 | 886 | $remove_answer = true; |
888 | 887 | } |
889 | 888 | } |
890 | - } |
|
891 | - elseif ($file_params = self::methodFile($name)) { |
|
889 | + } elseif ($file_params = self::methodFile($name)) { |
|
892 | 890 | foreach ($file_params as $param) { |
893 | 891 | if (isset($arguments[$param])) { |
894 | 892 | if ($arguments[$param] instanceof CURLFile) { |
895 | 893 | $remove_answer = true; |
896 | - } |
|
897 | - elseif (is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
|
894 | + } elseif (is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
|
898 | 895 | $arguments[$param] = new CURLFile($arguments[$param]); |
899 | 896 | $remove_answer = true; |
900 | 897 | } |
@@ -937,8 +934,7 @@ discard block |
||
937 | 934 | if (!isset($arguments[$default])){ |
938 | 935 | $arguments[$default] = self::catchFields($default); |
939 | 936 | } |
940 | - } |
|
941 | - elseif (isset(BPT::$update->{$key}) || $key === 'other') { |
|
937 | + } elseif (isset(BPT::$update->{$key}) || $key === 'other') { |
|
942 | 938 | foreach ($default as $def) { |
943 | 939 | if (!isset($arguments[$def])){ |
944 | 940 | $arguments[$def] = self::catchFields($def); |
@@ -1010,9 +1006,13 @@ discard block |
||
1010 | 1006 | default => false |
1011 | 1007 | }; |
1012 | 1008 | case fields::FILE_ID : |
1013 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
1014 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
1015 | - else return false; |
|
1009 | + if (isset(BPT::$update->message)) { |
|
1010 | + $type = 'message'; |
|
1011 | + } elseif (isset(BPT::$update->edited_message)) { |
|
1012 | + $type = 'edited_message'; |
|
1013 | + } else { |
|
1014 | + return false; |
|
1015 | + } |
|
1016 | 1016 | |
1017 | 1017 | return match(true) { |
1018 | 1018 | isset(BPT::$update->{$type}->animation) => BPT::$update->{$type}->animation->file_id, |
@@ -886,30 +886,30 @@ discard block |
||
886 | 886 | 'getGameHighScores' => ['BPT\types\gameHighScore'] |
887 | 887 | ]; |
888 | 888 | |
889 | - public static function __callStatic (string $name, array $arguments) { |
|
889 | + public static function __callStatic(string $name, array $arguments) { |
|
890 | 890 | if (!$action = self::methodAction($name)) { |
891 | - logger::write("$name method is not supported",loggerTypes::ERROR); |
|
891 | + logger::write("$name method is not supported", loggerTypes::ERROR); |
|
892 | 892 | throw new bptException('METHOD_NOT_FOUND'); |
893 | 893 | } |
894 | 894 | self::checkArguments($arguments); |
895 | - self::keysName($action,$arguments); |
|
896 | - self::readyFile($action,$arguments); |
|
895 | + self::keysName($action, $arguments); |
|
896 | + self::readyFile($action, $arguments); |
|
897 | 897 | self::cleanArguments($arguments); |
898 | - self::setDefaults($action,$arguments); |
|
898 | + self::setDefaults($action, $arguments); |
|
899 | 899 | |
900 | 900 | if (isset($arguments['answer']) && $arguments['answer'] === true) { |
901 | 901 | unset($arguments['answer']); |
902 | 902 | if (!answer::isAnswered()) { |
903 | - return answer::init($action,$arguments); |
|
903 | + return answer::init($action, $arguments); |
|
904 | 904 | } |
905 | - logger::write('you can use answer mode only once for each webhook update, Others will be called like normal',loggerTypes::WARNING); |
|
905 | + logger::write('you can use answer mode only once for each webhook update, Others will be called like normal', loggerTypes::WARNING); |
|
906 | 906 | } |
907 | - $result = curl::init($action,$arguments); |
|
907 | + $result = curl::init($action, $arguments); |
|
908 | 908 | if (!is_object($result)) { |
909 | - logger::write("Telegram $action method failed : " . $result, loggerTypes::WARNING); |
|
909 | + logger::write("Telegram $action method failed : ".$result, loggerTypes::WARNING); |
|
910 | 910 | return false; |
911 | 911 | } |
912 | - return self::processResponse($action,$result); |
|
912 | + return self::processResponse($action, $result); |
|
913 | 913 | } |
914 | 914 | |
915 | 915 | private static function checkArguments(array &$arguments): void { |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | } |
919 | 919 | } |
920 | 920 | |
921 | - private static function keysName (string $name, array &$arguments): void { |
|
921 | + private static function keysName(string $name, array &$arguments): void { |
|
922 | 922 | foreach ($arguments as $key => $argument) { |
923 | 923 | if (is_numeric($key) && isset(self::METHODS_KEYS[$name][$key])) { |
924 | 924 | $arguments[self::METHODS_KEYS[$name][$key]] = $argument; |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
930 | - private static function methodAction(string $name): string|false { |
|
930 | + private static function methodAction(string $name): string | false { |
|
931 | 931 | return self::METHODS_ACTION[str_replace('_', '', strtolower($name))] ?? false; |
932 | 932 | } |
933 | 933 | |
@@ -963,11 +963,11 @@ discard block |
||
963 | 963 | } |
964 | 964 | } |
965 | 965 | |
966 | - private static function methodFile(string $name): array|false { |
|
966 | + private static function methodFile(string $name): array | false { |
|
967 | 967 | return self::METHODS_WITH_FILE[$name] ?? false; |
968 | 968 | } |
969 | 969 | |
970 | - private static function methodReturn(string $name,stdClass $response) { |
|
970 | + private static function methodReturn(string $name, stdClass $response) { |
|
971 | 971 | if (!settings::$use_types_classes) { |
972 | 972 | return $response; |
973 | 973 | } |
@@ -989,13 +989,13 @@ discard block |
||
989 | 989 | $defaults = self::METHODS_EXTRA_DEFAULTS[$name] ?? []; |
990 | 990 | foreach ($defaults as $key => $default) { |
991 | 991 | if (is_numeric($key)) { |
992 | - if (!isset($arguments[$default])){ |
|
992 | + if (!isset($arguments[$default])) { |
|
993 | 993 | $arguments[$default] = self::catchFields($default); |
994 | 994 | } |
995 | 995 | } |
996 | 996 | elseif (isset(BPT::$update->{$key}) || $key === 'other') { |
997 | 997 | foreach ($default as $def) { |
998 | - if (!isset($arguments[$def])){ |
|
998 | + if (!isset($arguments[$def])) { |
|
999 | 999 | $arguments[$def] = self::catchFields($def); |
1000 | 1000 | } |
1001 | 1001 | } |
@@ -1014,14 +1014,14 @@ discard block |
||
1014 | 1014 | self::$status = $response->ok; |
1015 | 1015 | self::$pure_response = $response; |
1016 | 1016 | if (!$response->ok) { |
1017 | - logger::write("Telegram $name method failed : " . json_encode($response), loggerTypes::WARNING); |
|
1017 | + logger::write("Telegram $name method failed : ".json_encode($response), loggerTypes::WARNING); |
|
1018 | 1018 | unset($response->ok); |
1019 | 1019 | return new responseError($response); |
1020 | 1020 | } |
1021 | - return self::methodReturn($name,$response); |
|
1021 | + return self::methodReturn($name, $response); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | - private static function cleanArguments (array &$arguments): void { |
|
1024 | + private static function cleanArguments(array &$arguments): void { |
|
1025 | 1025 | foreach ($arguments as $key => $argument) { |
1026 | 1026 | if ($argument == [] || $argument === null) { |
1027 | 1027 | unset($arguments[$key]); |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | * |
1037 | 1037 | * @return int|string|bool |
1038 | 1038 | */ |
1039 | - public static function catchFields (string $field): int|string|bool { |
|
1039 | + public static function catchFields(string $field): int | string | bool { |
|
1040 | 1040 | switch ($field) { |
1041 | 1041 | case fields::CHAT_ID : |
1042 | 1042 | case fields::FROM_CHAT_ID : |
@@ -1183,13 +1183,13 @@ discard block |
||
1183 | 1183 | default => false |
1184 | 1184 | }; |
1185 | 1185 | case fields::URL : |
1186 | - return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
1186 | + return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
1187 | 1187 | default: |
1188 | 1188 | return false; |
1189 | 1189 | } |
1190 | 1190 | } |
1191 | 1191 | |
1192 | - public static function fileLink (string|null $file_id = null): bool|string { |
|
1192 | + public static function fileLink(string | null $file_id = null): bool | string { |
|
1193 | 1193 | $file = request::getFile($file_id); |
1194 | 1194 | if (!isset($file->file_path)) { |
1195 | 1195 | return false; |
@@ -1211,7 +1211,7 @@ discard block |
||
1211 | 1211 | * |
1212 | 1212 | * @return bool |
1213 | 1213 | */ |
1214 | - public static function downloadFile (string $destination, string|null $file_id = null): bool { |
|
1214 | + public static function downloadFile(string $destination, string | null $file_id = null): bool { |
|
1215 | 1215 | return tools::downloadFile(self::fileLink($file_id), $destination); |
1216 | 1216 | } |
1217 | 1217 | |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | * |
1230 | 1230 | * @return message|bool|responseError |
1231 | 1231 | */ |
1232 | - public static function sendFile (string $file_id, int|string $chat_id = null, string|null $business_connection_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, array|object $reply_parameters = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null, int|null $reply_to_message_id = null, bool|null $allow_sending_without_reply = null): message|bool|responseError { |
|
1232 | + public static function sendFile(string $file_id, int | string $chat_id = null, string | null $business_connection_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, array | object $reply_parameters = null, inlineKeyboardMarkup | replyKeyboardMarkup | replyKeyboardRemove | forceReply | stdClass | array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null, int | null $reply_to_message_id = null, bool | null $allow_sending_without_reply = null): message | bool | responseError { |
|
1233 | 1233 | $type = tools::fileType($file_id); |
1234 | 1234 | return match ($type) { |
1235 | 1235 | fileTypes::VIDEO => request::sendVideo(video: $file_id, chat_id: $chat_id, business_connection_id: $business_connection_id, message_thread_id: $message_thread_id, caption: $caption, parse_mode: $parse_mode, caption_entities: $caption_entities, has_spoiler: false, disable_notification: $disable_notification, protect_content: $protect_content, reply_parameters: $reply_parameters, reply_markup: $reply_markup, token: $token, forgot: $forgot, answer: $answer, reply_to_message_id: $reply_to_message_id, allow_sending_without_reply: $allow_sending_without_reply), |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @internal Only for BPT self usage , Don't use it in your source! |
18 | 18 | */ |
19 | - public static function init(): string|null { |
|
19 | + public static function init(): string | null { |
|
20 | 20 | return self::getUpdate(); |
21 | 21 | } |
22 | 22 | |
23 | - private static function getUpdate (): string|null { |
|
23 | + private static function getUpdate(): string | null { |
|
24 | 24 | $up = glob('*.update'); |
25 | 25 | if (!isset($up[0])) { |
26 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
26 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
27 | 27 | BPT::exit(); |
28 | 28 | } |
29 | 29 | $up = end($up); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | private static function create($file) { |
56 | - file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php ' . $file . ' > /dev/null &");'); |
|
56 | + file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php '.$file.' > /dev/null &");'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | #[ArrayShape(['url' => 'array|string|string[]', 'file' => 'string'])] |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * curl class , for multiprocessing with curl tricks |
14 | 14 | */ |
15 | 15 | class curl extends webhook { |
16 | - public static function init (): string|null { |
|
16 | + public static function init(): string | null { |
|
17 | 17 | if (!self::checkIP()) { |
18 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
18 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
19 | 19 | BPT::exit(); |
20 | 20 | } |
21 | 21 | return self::getUpdate(); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
26 | 26 | } |
27 | 27 | |
28 | - private static function getUpdate (): string { |
|
28 | + private static function getUpdate(): string { |
|
29 | 29 | $input = json_decode(file_get_contents('php://input'), true); |
30 | 30 | webhook::telegramVerify($input['ip']); |
31 | 31 | return $input['update']; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | lock::set('BPT-MULTI-CURL'); |
43 | 43 | } |
44 | 44 | |
45 | - private static function getTimeout($url): float|int { |
|
45 | + private static function getTimeout($url): float | int { |
|
46 | 46 | $times = []; |
47 | - for ($i = 0; $i < 10; $i ++) { |
|
47 | + for ($i = 0; $i < 10; $i++) { |
|
48 | 48 | $ch = curl_init($url); |
49 | 49 | curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([]), CURLOPT_TIMEOUT_MS => 100, CURLOPT_NOBODY => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => 100, CURLOPT_HTTPHEADER => ['accept: application/json', 'content-type: application/json']]); |
50 | 50 | $start = microtime(true); |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | return $timeout > 50 ? $timeout + 10 : 50; |
56 | 56 | } |
57 | 57 | |
58 | - private static function create($file,$timeout) { |
|
59 | - file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\'' . $file . '\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => ' . $timeout . ', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => ' . $timeout . ', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
58 | + private static function create($file, $timeout) { |
|
59 | + file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\''.$file.'\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => '.$timeout.', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => '.$timeout.', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | #[ArrayShape(['url' => 'array|string|string[]', 'file' => 'array|string|string[]'])] |
@@ -9,18 +9,18 @@ discard block |
||
9 | 9 | use BPT\tools\tools; |
10 | 10 | |
11 | 11 | class callback { |
12 | - public static function encodeData (array $data): string { |
|
12 | + public static function encodeData(array $data): string { |
|
13 | 13 | return tools::codec(codecAction::ENCRYPT, json_encode($data), md5(settings::$token), 'SguQgUvvKRLvmCyq')['hash']; |
14 | 14 | } |
15 | 15 | |
16 | - public static function decodeData (string $data): array { |
|
16 | + public static function decodeData(string $data): array { |
|
17 | 17 | return json_decode(tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true); |
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @internal Only for BPT self usage , Don't use it in your source! |
22 | 22 | */ |
23 | - public static function process () { |
|
23 | + public static function process() { |
|
24 | 24 | if (!settings::$handler || settings::$receiver != \BPT\constants\receiver::WEBHOOK || settings::$multi || !(isset($_GET['data']) || isset($_POST['data']))) { |
25 | 25 | return false; |
26 | 26 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @internal Only for BPT self usage , Don't use it in your source! |
47 | 47 | */ |
48 | - public static function callHandler (string $handler_name, $input) { |
|
48 | + public static function callHandler(string $handler_name, $input) { |
|
49 | 49 | if (method_exists(BPT::$handler, $handler_name)) { |
50 | 50 | BPT::$handler->$handler_name($input); |
51 | 51 | } |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | * @method gameHighScore[]|responseError getGameHighScores (int|array|null $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects. |
300 | 300 | * @method gameHighScore[]|responseError getGameHigh (int|array|null $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects. |
301 | 301 | */ |
302 | -class BPT extends telegram{ |
|
303 | - public static stdClass|update $update; |
|
302 | +class BPT extends telegram { |
|
303 | + public static stdClass | update $update; |
|
304 | 304 | |
305 | 305 | public static BPT $handler; |
306 | 306 | |
307 | 307 | |
308 | - public function __construct (array|easySettings $settings) { |
|
308 | + public function __construct(array | easySettings $settings) { |
|
309 | 309 | static::$handler = &$this; |
310 | 310 | settings::init($settings); |
311 | 311 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | } |
316 | 316 | |
317 | 317 | #[NoReturn] |
318 | - public static function exit (string|null $message = null): void { |
|
318 | + public static function exit (string | null $message = null): void { |
|
319 | 319 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
320 | 320 | } |
321 | 321 | } |
@@ -16,32 +16,32 @@ |
||
16 | 16 | */ |
17 | 17 | class getUpdates extends receiver { |
18 | 18 | #[NoReturn] |
19 | - public static function init () { |
|
19 | + public static function init() { |
|
20 | 20 | $last_update_id = self::loadData(); |
21 | 21 | lock::set('getUpdateHook'); |
22 | - while(true) { |
|
22 | + while (true) { |
|
23 | 23 | if (!lock::exist('getUpdateHook')) { |
24 | - logger::write('getUpdateHook deleted, loop ended.',loggerTypes::INFO); |
|
24 | + logger::write('getUpdateHook deleted, loop ended.', loggerTypes::INFO); |
|
25 | 25 | break; |
26 | 26 | } |
27 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates); |
|
27 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates); |
|
28 | 28 | if (!telegram::$status) { |
29 | - logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
|
30 | - BPT::exit(print_r($updates,true)); |
|
29 | + logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR); |
|
30 | + BPT::exit(print_r($updates, true)); |
|
31 | 31 | } |
32 | 32 | self::handleUpdates($updates); |
33 | - $last_update_id = BPT::$update->update_id+1; |
|
34 | - lock::save('getUpdate',$last_update_id); |
|
33 | + $last_update_id = BPT::$update->update_id + 1; |
|
34 | + lock::save('getUpdate', $last_update_id); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | - private static function loadData(): bool|int|string { |
|
38 | + private static function loadData(): bool | int | string { |
|
39 | 39 | if (lock::exist('getUpdate')) { |
40 | 40 | return lock::read('getUpdate'); |
41 | 41 | } |
42 | 42 | self::deleteOldLocks(); |
43 | 43 | telegram::deleteWebhook(); |
44 | - lock::save('getUpdate',0); |
|
44 | + lock::save('getUpdate', 0); |
|
45 | 45 | return 0; |
46 | 46 | } |
47 | 47 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | private static CurlHandle $session; |
37 | 37 | |
38 | - public static function init (string $api_key = '', string $ipn_secret = '', int $round_decimal = 4): void { |
|
38 | + public static function init(string $api_key = '', string $ipn_secret = '', int $round_decimal = 4): void { |
|
39 | 39 | self::$ipn_secret = $ipn_secret; |
40 | 40 | self::$round_decimal = $round_decimal; |
41 | 41 | self::$session = curl_init(); |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYPEER, 1); |
44 | 44 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYHOST, 2); |
45 | 45 | curl_setopt(self::$session, CURLOPT_HTTPHEADER, [ |
46 | - 'X-API-KEY: ' . $api_key, |
|
46 | + 'X-API-KEY: '.$api_key, |
|
47 | 47 | 'Content-Type: application/json' |
48 | 48 | ]); |
49 | 49 | } |
50 | 50 | |
51 | - private static function execute (string $method, string $endpoint, string|array $data = '') { |
|
51 | + private static function execute(string $method, string $endpoint, string | array $data = '') { |
|
52 | 52 | if (is_array($data)) { |
53 | 53 | foreach ($data as $key => $value) { |
54 | 54 | if (empty($value)) { |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | |
62 | 62 | switch ($method) { |
63 | 63 | case 'GET': |
64 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint . (!empty($data) && is_array($data) ? ('?' . http_build_query($data)) : '')); |
|
64 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint.(!empty($data) && is_array($data) ? ('?'.http_build_query($data)) : '')); |
|
65 | 65 | break; |
66 | 66 | case 'POST': |
67 | 67 | curl_setopt($session, CURLOPT_POST, true); |
68 | 68 | curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($data)); |
69 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint); |
|
69 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint); |
|
70 | 70 | break; |
71 | 71 | default: |
72 | 72 | return false; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * This is a method to get information about the current state of the API. Receive true if its ok and false in otherwise |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public static function status (): bool { |
|
81 | + public static function status(): bool { |
|
82 | 82 | return self::execute('GET', 'status')->message === 'OK'; |
83 | 83 | } |
84 | 84 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return estimatePriceInterface|errorResponseInterface|mixed |
95 | 95 | */ |
96 | - public static function getEstimatePrice (int|float $amount, string $currency_from, string $currency_to) { |
|
96 | + public static function getEstimatePrice(int | float $amount, string $currency_from, string $currency_to) { |
|
97 | 97 | return self::execute('GET', 'estimate', [ |
98 | 98 | 'amount' => $amount, |
99 | 99 | 'currency_from' => $currency_from, |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return invoicePaymentInterface|errorResponseInterface|mixed |
122 | 122 | */ |
123 | - public static function createPayment (int|float $price_amount, string $price_currency, string $pay_currency, int|float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null, bool $is_fee_paid_by_user = null) { |
|
123 | + public static function createPayment(int | float $price_amount, string $price_currency, string $pay_currency, int | float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null, bool $is_fee_paid_by_user = null) { |
|
124 | 124 | return self::execute('POST', 'payment', [ |
125 | 125 | 'price_amount' => $price_amount, |
126 | 126 | 'price_currency' => $price_currency, |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return invoicePaymentInterface|errorResponseInterface|mixed |
154 | 154 | */ |
155 | - public static function createInvoicePayment (string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) { |
|
155 | + public static function createInvoicePayment(string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) { |
|
156 | 156 | return self::execute('POST', 'invoice-payment', [ |
157 | 157 | 'iid' => $iid, |
158 | 158 | 'pay_currency' => $pay_currency, |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return estimateUpdateInterface|errorResponseInterface|mixed |
175 | 175 | */ |
176 | - public static function updateEstimatePrice (int $paymentID) { |
|
177 | - return self::execute('POST', 'payment/' . $paymentID . '/update-merchant-estimate'); |
|
176 | + public static function updateEstimatePrice(int $paymentID) { |
|
177 | + return self::execute('POST', 'payment/'.$paymentID.'/update-merchant-estimate'); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return paymentInterface|errorResponseInterface|mixed |
186 | 186 | */ |
187 | - public static function getPaymentStatus (int $paymentID) { |
|
188 | - return self::execute('GET', 'payment/' . $paymentID); |
|
187 | + public static function getPaymentStatus(int $paymentID) { |
|
188 | + return self::execute('GET', 'payment/'.$paymentID); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return float |
198 | 198 | */ |
199 | - public static function getMinimumPaymentAmount (string $currency_from, string $currency_to): float { |
|
199 | + public static function getMinimumPaymentAmount(string $currency_from, string $currency_to): float { |
|
200 | 200 | return self::execute('GET', 'min-amount', [ |
201 | 201 | 'currency_from' => $currency_from, |
202 | 202 | 'currency_to' => $currency_to |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @return invoiceResponseInterface|errorResponseInterface|mixed |
219 | 219 | */ |
220 | - public static function createInvoice (int|float $price_amount, string $price_currency, string $pay_currency = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) { |
|
220 | + public static function createInvoice(int | float $price_amount, string $price_currency, string $pay_currency = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) { |
|
221 | 221 | return self::execute('POST', 'invoice', [ |
222 | 222 | 'price_amount' => $price_amount, |
223 | 223 | 'price_currency' => $price_currency, |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return array |
237 | 237 | */ |
238 | - public static function getCurrencies (): array { |
|
238 | + public static function getCurrencies(): array { |
|
239 | 239 | return self::execute('GET', 'currencies')->currencies; |
240 | 240 | } |
241 | 241 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return array |
246 | 246 | */ |
247 | - public static function getFullCurrencies (): array { |
|
247 | + public static function getFullCurrencies(): array { |
|
248 | 248 | return self::execute('GET', 'full-currencies')->currencies; |
249 | 249 | } |
250 | 250 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @return array |
256 | 256 | */ |
257 | - public static function getAvailableCheckedCurrencies (): array { |
|
257 | + public static function getAvailableCheckedCurrencies(): array { |
|
258 | 258 | return self::execute('GET', 'merchant/coins')->currencies; |
259 | 259 | } |
260 | 260 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return bool |
274 | 274 | */ |
275 | - public static function isIPNRequestValid (): bool { |
|
275 | + public static function isIPNRequestValid(): bool { |
|
276 | 276 | if (empty($_SERVER['HTTP_X_NOWPAYMENTS_SIG'])) { |
277 | 277 | return false; |
278 | 278 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @return ipnDataInterface|mixed |
296 | 296 | */ |
297 | - public static function getIPN () { |
|
297 | + public static function getIPN() { |
|
298 | 298 | if (!self::isIPNRequestValid()) { |
299 | 299 | return false; |
300 | 300 | } |
301 | 301 | return json_decode(file_get_contents('php://input')); |
302 | 302 | } |
303 | 303 | |
304 | - protected static function createOrder (float|int $amount, int $user_id, string $description): int|string { |
|
304 | + protected static function createOrder(float | int $amount, int $user_id, string $description): int | string { |
|
305 | 305 | if (!mysql::getMysqli()) { |
306 | 306 | logger::write("crypto::ezPay function used\ncreating order needed mysql connection in our mysql class", loggerTypes::ERROR); |
307 | 307 | throw new bptException('MYSQL_CONNECTION_NEEDED'); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | return mysql::insertId(); |
313 | 313 | } |
314 | 314 | |
315 | - protected static function getOrder (int $order_id): bool|object { |
|
315 | + protected static function getOrder(int $order_id): bool | object { |
|
316 | 316 | if (!mysql::getMysqli()) { |
317 | 317 | logger::write("crypto::ezPay function used\ncreating order needed mysql connection in our mysql class", loggerTypes::ERROR); |
318 | 318 | throw new bptException('MYSQL_CONNECTION_NEEDED'); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @return bool|string |
344 | 344 | * @throws bptException |
345 | 345 | */ |
346 | - public static function ezPay (float|int $amount, int $user_id = null, string $currency = 'usd', string $description = 'Invoice created by BPT library', bool $direct_url = false, bool $one_time_url = true): bool|string { |
|
346 | + public static function ezPay(float | int $amount, int $user_id = null, string $currency = 'usd', string $description = 'Invoice created by BPT library', bool $direct_url = false, bool $one_time_url = true): bool | string { |
|
347 | 347 | if (empty(self::$ipn_secret)) { |
348 | 348 | logger::write("crypto::ezPay function used\nyou must set ipn_secret to use this", loggerTypes::ERROR); |
349 | 349 | return false; |
@@ -355,10 +355,10 @@ discard block |
||
355 | 355 | $user_id = $user_id ?? request::catchFields(fields::USER_ID); |
356 | 356 | $order_id = self::createOrder($amount, $user_id, $description); |
357 | 357 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::CALLBACK, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
358 | - $callback_url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
358 | + $callback_url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
359 | 359 | |
360 | 360 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::SUCCESS, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
361 | - $success_url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
361 | + $success_url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
362 | 362 | |
363 | 363 | $invoice_id = self::createInvoice($amount, $currency, null, $callback_url, $order_id, $description, $success_url)->id; |
364 | 364 | |
@@ -377,17 +377,17 @@ discard block |
||
377 | 377 | ], ['id' => $order_id], 1); |
378 | 378 | |
379 | 379 | if ($direct_url) { |
380 | - return 'https://nowpayments.io/payment/?iid='. $invoice_id; |
|
380 | + return 'https://nowpayments.io/payment/?iid='.$invoice_id; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::REDIRECT, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
384 | - return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
384 | + return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
388 | 388 | * @internal Only for BPT self usage , Don't use it in your source! |
389 | 389 | */ |
390 | - public static function callbackProcess (array $data) { |
|
390 | + public static function callbackProcess(array $data) { |
|
391 | 391 | if (!isset($data['action_type'])) { |
392 | 392 | return false; |
393 | 393 | } |
@@ -407,16 +407,16 @@ discard block |
||
407 | 407 | BPT::exit('This link is one time only, Receive another link'); |
408 | 408 | } |
409 | 409 | } |
410 | - $url = 'https://nowpayments.io/payment/?iid='. $extra_info->invoice_id; |
|
410 | + $url = 'https://nowpayments.io/payment/?iid='.$extra_info->invoice_id; |
|
411 | 411 | |
412 | - @header('Location: ' . $url); |
|
412 | + @header('Location: '.$url); |
|
413 | 413 | die("<meta http-equiv='refresh' content='0; url=$url' /><script>window.location.href = '$url';</script>"); |
414 | 414 | } |
415 | 415 | |
416 | 416 | if ($action_type === cryptoCallbackActionTypes::CALLBACK) { |
417 | 417 | $ipn = self::getIPN(); |
418 | 418 | |
419 | - if ($ipn->payment_status !== cryptoStatus::FINISHED && $ipn->payment_status !== cryptoStatus::PARTIALLY_PAID ) { |
|
419 | + if ($ipn->payment_status !== cryptoStatus::FINISHED && $ipn->payment_status !== cryptoStatus::PARTIALLY_PAID) { |
|
420 | 420 | die(); |
421 | 421 | } |
422 | 422 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | die(); |
439 | 439 | } |
440 | 440 | |
441 | - $paid = round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid/$payment->pay_amount*$payment->price_amount, self::$round_decimal); |
|
441 | + $paid = round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid / $payment->pay_amount * $payment->price_amount, self::$round_decimal); |
|
442 | 442 | $extra_info['related_payments'][$payment_id] = $paid; |
443 | 443 | $extra_info['total_paid'] += $paid; |
444 | 444 | mysql::update('orders', ['extra_info' => json_encode($extra_info)], ['id' => $order_id], 1); |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | 'description' => $order->description, |
501 | 501 | 'real_amount' => $order->amount, |
502 | 502 | 'currency' => $extra_info->currency, |
503 | - 'paid_amount' => round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid/$payment->pay_amount*$payment->price_amount, self::$round_decimal), |
|
503 | + 'paid_amount' => round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid / $payment->pay_amount * $payment->price_amount, self::$round_decimal), |
|
504 | 504 | 'total_paid' => $extra_info->total_paid |
505 | 505 | ]; |
506 | 506 | $callback_data = object(...$callback_data); |
@@ -5,7 +5,7 @@ |
||
5 | 5 | use BPT\settings; |
6 | 6 | |
7 | 7 | class pay { |
8 | - public static function init (): void { |
|
8 | + public static function init(): void { |
|
9 | 9 | if (isset(settings::$pay['crypto'])) { |
10 | 10 | $settings = [ |
11 | 11 | 'api_key' => settings::$pay['crypto']['api_key'] ?? null, |