@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @internal Only for BPT self usage , Don't use it in your source! |
| 22 | 22 | */ |
| 23 | - public static function init () { |
|
| 23 | + public static function init() { |
|
| 24 | 24 | if (settings::$multi) { |
| 25 | 25 | multi::init(); |
| 26 | 26 | } |
@@ -49,24 +49,24 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - protected static function setWebhook(string $url,string $secret = '') { |
|
| 52 | + protected static function setWebhook(string $url, string $secret = '') { |
|
| 53 | 53 | $res = telegram::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret); |
| 54 | 54 | if (!telegram::$status) { |
| 55 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
|
| 56 | - BPT::exit(print_r($res,true)); |
|
| 55 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR); |
|
| 56 | + BPT::exit(print_r($res, true)); |
|
| 57 | 57 | } |
| 58 | - logger::write('Webhook was set successfully',loggerTypes::INFO); |
|
| 58 | + logger::write('Webhook was set successfully', loggerTypes::INFO); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | protected static function checkURL() { |
| 62 | 62 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
| 63 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR); |
|
| 63 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR); |
|
| 64 | 64 | throw new bptException('WEBHOOK_NEED_URL'); |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | private static function setURL(): string { |
| 69 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
| 69 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | protected static function setCertificate() { |
@@ -89,15 +89,15 @@ discard block |
||
| 89 | 89 | self::setCertificate(); |
| 90 | 90 | $url = self::setURL(); |
| 91 | 91 | $secret = !empty(settings::$secret) ? settings::$secret : tools::randomString(64); |
| 92 | - self::setWebhook($url,$secret); |
|
| 93 | - lock::save('BPT-HOOK',$secret); |
|
| 92 | + self::setWebhook($url, $secret); |
|
| 93 | + lock::save('BPT-HOOK', $secret); |
|
| 94 | 94 | BPT::exit('Done'); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | private static function checkSecret() { |
| 98 | 98 | $secret = lock::read('BPT-HOOK'); |
| 99 | 99 | if ($secret !== self::getSecret()) { |
| 100 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING); |
|
| 100 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING); |
|
| 101 | 101 | self::processSetWebhook(); |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @return bool |
| 117 | 117 | */ |
| 118 | - public static function fastClose (int $timeout = 86400): bool { |
|
| 118 | + public static function fastClose(int $timeout = 86400): bool { |
|
| 119 | 119 | if (settings::$multi || !lock::exist('BPT-HOOK')) { |
| 120 | 120 | return false; |
| 121 | 121 | } |
@@ -23,15 +23,13 @@ discard block |
||
| 23 | 23 | public static function init () { |
| 24 | 24 | if (settings::$multi) { |
| 25 | 25 | multi::init(); |
| 26 | - } |
|
| 27 | - else { |
|
| 26 | + } else { |
|
| 28 | 27 | if (lock::exist('BPT-HOOK')) { |
| 29 | 28 | receiver::telegramVerify(); |
| 30 | 29 | self::checkSecret(); |
| 31 | 30 | logger::write('Update received , lets process it ;)'); |
| 32 | 31 | receiver::processUpdate(); |
| 33 | - } |
|
| 34 | - else { |
|
| 32 | + } else { |
|
| 35 | 33 | self::processSetWebhook(); |
| 36 | 34 | } |
| 37 | 35 | } |
@@ -74,8 +72,7 @@ discard block |
||
| 74 | 72 | if (is_string(settings::$certificate)) { |
| 75 | 73 | if (file_exists(realpath(settings::$certificate))) { |
| 76 | 74 | settings::$certificate = new CURLFile(settings::$certificate); |
| 77 | - } |
|
| 78 | - else { |
|
| 75 | + } else { |
|
| 79 | 76 | settings::$certificate = null; |
| 80 | 77 | } |
| 81 | 78 | } |
@@ -125,11 +122,9 @@ discard block |
||
| 125 | 122 | ignore_user_abort(true); |
| 126 | 123 | if (function_exists('fastcgi_finish_request')) { |
| 127 | 124 | fastcgi_finish_request(); |
| 128 | - } |
|
| 129 | - elseif (function_exists('litespeed_finish_request')) { |
|
| 125 | + } elseif (function_exists('litespeed_finish_request')) { |
|
| 130 | 126 | litespeed_finish_request(); |
| 131 | - } |
|
| 132 | - else { |
|
| 127 | + } else { |
|
| 133 | 128 | return false; |
| 134 | 129 | } |
| 135 | 130 | |
@@ -217,8 +217,9 @@ discard block |
||
| 217 | 217 | if (telegram::$status) { |
| 218 | 218 | $check = $check->status; |
| 219 | 219 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
| 220 | + } else { |
|
| 221 | + $result[$id] = null; |
|
| 220 | 222 | } |
| 221 | - else $result[$id] = null; |
|
| 222 | 223 | } |
| 223 | 224 | return $result; |
| 224 | 225 | } |
@@ -259,8 +260,7 @@ discard block |
||
| 259 | 260 | curl_exec($ch); |
| 260 | 261 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
| 261 | 262 | curl_close($ch); |
| 262 | - } |
|
| 263 | - else { |
|
| 263 | + } else { |
|
| 264 | 264 | $path = realpath($path); |
| 265 | 265 | $size = file_exists($path) ? filesize($path) : false; |
| 266 | 266 | } |
@@ -331,8 +331,7 @@ discard block |
||
| 331 | 331 | $zip->addFile($filePath, substr($filePath, $root_len)); |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | - } |
|
| 335 | - else { |
|
| 334 | + } else { |
|
| 336 | 335 | $zip->addFile($path, basename($path)); |
| 337 | 336 | } |
| 338 | 337 | return $zip->close(); |
@@ -351,9 +350,13 @@ discard block |
||
| 351 | 350 | */ |
| 352 | 351 | public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool { |
| 353 | 352 | $file = fopen($url, 'rb'); |
| 354 | - if (!$file) return false; |
|
| 353 | + if (!$file) { |
|
| 354 | + return false; |
|
| 355 | + } |
|
| 355 | 356 | $path = fopen($path, 'wb'); |
| 356 | - if (!$path) return false; |
|
| 357 | + if (!$path) { |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 357 | 360 | |
| 358 | 361 | $length = $chunk_size * 1024; |
| 359 | 362 | while (!feof($file)){ |
@@ -463,8 +466,9 @@ discard block |
||
| 463 | 466 | foreach ($string as $k => &$v) { |
| 464 | 467 | if ($diff->$v) { |
| 465 | 468 | $v = $diff->$v; |
| 469 | + } else { |
|
| 470 | + unset($string[$k]); |
|
| 466 | 471 | } |
| 467 | - else unset($string[$k]); |
|
| 468 | 472 | } |
| 469 | 473 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
| 470 | 474 | |
@@ -530,8 +534,7 @@ discard block |
||
| 530 | 534 | if ($last === "\0") { |
| 531 | 535 | $new .= str_repeat($last, ord($char)); |
| 532 | 536 | $last = ''; |
| 533 | - } |
|
| 534 | - else { |
|
| 537 | + } else { |
|
| 535 | 538 | $new .= $last; |
| 536 | 539 | $last = $char; |
| 537 | 540 | } |
@@ -615,7 +618,9 @@ discard block |
||
| 615 | 618 | } |
| 616 | 619 | $rows = []; |
| 617 | 620 | foreach ($keyboard as $row) { |
| 618 | - if (!is_array($row)) continue; |
|
| 621 | + if (!is_array($row)) { |
|
| 622 | + continue; |
|
| 623 | + } |
|
| 619 | 624 | $buttons = []; |
| 620 | 625 | foreach ($row as $base_button) { |
| 621 | 626 | $button_info = explode('||', $base_button); |
@@ -624,15 +629,12 @@ discard block |
||
| 624 | 629 | if (count($button_info) > 1) { |
| 625 | 630 | if ($button_info[1] === 'con') { |
| 626 | 631 | $button->setRequest_contact(true); |
| 627 | - } |
|
| 628 | - elseif ($button_info[1] === 'loc') { |
|
| 632 | + } elseif ($button_info[1] === 'loc') { |
|
| 629 | 633 | $button->setRequest_location(true); |
| 630 | - } |
|
| 631 | - elseif ($button_info[1] === 'poll') { |
|
| 634 | + } elseif ($button_info[1] === 'poll') { |
|
| 632 | 635 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
| 633 | 636 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
| 634 | - } |
|
| 635 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 637 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 636 | 638 | $url = $button_info[2]; |
| 637 | 639 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
| 638 | 640 | } |
@@ -643,8 +645,7 @@ discard block |
||
| 643 | 645 | } |
| 644 | 646 | $keyboard_object->setKeyboard($rows); |
| 645 | 647 | return $keyboard_object; |
| 646 | - } |
|
| 647 | - elseif (!empty($inline)) { |
|
| 648 | + } elseif (!empty($inline)) { |
|
| 648 | 649 | $keyboard_object = new inlineKeyboardMarkup(); |
| 649 | 650 | $rows = []; |
| 650 | 651 | foreach ($inline as $row) { |
@@ -654,12 +655,10 @@ discard block |
||
| 654 | 655 | if (isset($button_info[1])) { |
| 655 | 656 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
| 656 | 657 | $button->setText($button_info[0])->setUrl($button_info[1]); |
| 657 | - } |
|
| 658 | - else { |
|
| 658 | + } else { |
|
| 659 | 659 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
| 660 | 660 | } |
| 661 | - } |
|
| 662 | - else { |
|
| 661 | + } else { |
|
| 663 | 662 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
| 664 | 663 | } |
| 665 | 664 | $buttons[] = $button; |
@@ -668,8 +667,7 @@ discard block |
||
| 668 | 667 | } |
| 669 | 668 | $keyboard_object->setInline_keyboard($rows); |
| 670 | 669 | return $keyboard_object; |
| 671 | - } |
|
| 672 | - else { |
|
| 670 | + } else { |
|
| 673 | 671 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
| 674 | 672 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 675 | 673 | } |
@@ -688,8 +686,12 @@ discard block |
||
| 688 | 686 | * @return string |
| 689 | 687 | */ |
| 690 | 688 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
| 691 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
| 692 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
| 689 | + if (empty($user_id)) { |
|
| 690 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
| 691 | + } |
|
| 692 | + if (empty($bot_username)) { |
|
| 693 | + $bot_username = telegram::getMe()->username; |
|
| 694 | + } |
|
| 693 | 695 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
| 694 | 696 | } |
| 695 | 697 | |
@@ -724,8 +726,7 @@ discard block |
||
| 724 | 726 | $iv = self::randomString(); |
| 725 | 727 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
| 726 | 728 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
| 727 | - } |
|
| 728 | - elseif ($action === codecAction::DECRYPT) { |
|
| 729 | + } elseif ($action === codecAction::DECRYPT) { |
|
| 729 | 730 | if (empty($key)) { |
| 730 | 731 | logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR); |
| 731 | 732 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
@@ -735,8 +736,7 @@ discard block |
||
| 735 | 736 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
| 736 | 737 | } |
| 737 | 738 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
| 738 | - } |
|
| 739 | - else { |
|
| 739 | + } else { |
|
| 740 | 740 | logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
| 741 | 741 | return false; |
| 742 | 742 | } |
@@ -765,7 +765,9 @@ discard block |
||
| 765 | 765 | $array[] = $num % 62; |
| 766 | 766 | $num = floor($num / 62); |
| 767 | 767 | } |
| 768 | - if (count($array) < 1) $array = [0]; |
|
| 768 | + if (count($array) < 1) { |
|
| 769 | + $array = [0]; |
|
| 770 | + } |
|
| 769 | 771 | foreach ($array as &$value) { |
| 770 | 772 | $value = $codes[$value]; |
| 771 | 773 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * tools class , gather what ever you need |
| 31 | 31 | */ |
| 32 | -class tools{ |
|
| 32 | +class tools { |
|
| 33 | 33 | /** |
| 34 | 34 | * Check the given username format |
| 35 | 35 | * |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public static function isUsername (string $username): bool { |
|
| 44 | + public static function isUsername(string $username): bool { |
|
| 45 | 45 | $length = strlen($username); |
| 46 | 46 | return !str_contains($username, '__') && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username); |
| 47 | 47 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - public static function ipInRange (string $ip, string $range): bool { |
|
| 61 | + public static function ipInRange(string $ip, string $range): bool { |
|
| 62 | 62 | if (!str_contains($range, '/')) { |
| 63 | 63 | $range .= '/32'; |
| 64 | 64 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return bool |
| 80 | 80 | */ |
| 81 | - public static function isTelegram (string $ip): bool { |
|
| 81 | + public static function isTelegram(string $ip): bool { |
|
| 82 | 82 | return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22'); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - public static function isCloudFlare (string $ip): bool { |
|
| 96 | + public static function isCloudFlare(string $ip): bool { |
|
| 97 | 97 | $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']; |
| 98 | 98 | foreach ($cf_ips as $cf_ip) { |
| 99 | - if (self::ipInRange($ip,$cf_ip)) { |
|
| 99 | + if (self::ipInRange($ip, $cf_ip)) { |
|
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return bool |
| 116 | 116 | */ |
| 117 | - public static function isArvanCloud (string $ip): bool { |
|
| 117 | + public static function isArvanCloud(string $ip): bool { |
|
| 118 | 118 | $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']; |
| 119 | 119 | foreach ($ar_ips as $ar_ip) { |
| 120 | - if (self::ipInRange($ip,$ar_ip)) { |
|
| 120 | + if (self::ipInRange($ip, $ar_ip)) { |
|
| 121 | 121 | return true; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return bool|user return array when verify is active and token is true array of telegram getMe result |
| 139 | 139 | */ |
| 140 | - public static function isToken (string $token, bool $verify = false): bool|user { |
|
| 140 | + public static function isToken(string $token, bool $verify = false): bool | user { |
|
| 141 | 141 | if (!preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) { |
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | - if (!$verify){ |
|
| 144 | + if (!$verify) { |
|
| 145 | 145 | return true; |
| 146 | 146 | } |
| 147 | 147 | $res = telegram::me($token); |
@@ -171,14 +171,14 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return bool |
| 173 | 173 | */ |
| 174 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool { |
|
| 174 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool { |
|
| 175 | 175 | if (!is_array($ids)) { |
| 176 | 176 | $ids = [$ids]; |
| 177 | 177 | } |
| 178 | 178 | $user_id = $user_id ?? request::catchFields('user_id'); |
| 179 | 179 | |
| 180 | 180 | foreach ($ids as $id) { |
| 181 | - $check = telegram::getChatMember($id,$user_id); |
|
| 181 | + $check = telegram::getChatMember($id, $user_id); |
|
| 182 | 182 | if (telegram::$status) { |
| 183 | 183 | $check = $check->status; |
| 184 | 184 | if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) { |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return array keys will be id and values will be bool(null for not founded ids) |
| 207 | 207 | */ |
| 208 | - public static function joinChecker (array|string|int $ids , int|null $user_id = null): array { |
|
| 208 | + public static function joinChecker(array | string | int $ids, int | null $user_id = null): array { |
|
| 209 | 209 | if (!is_array($ids)) { |
| 210 | 210 | $ids = [$ids]; |
| 211 | 211 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | $result = []; |
| 215 | 215 | foreach ($ids as $id) { |
| 216 | - $check = telegram::getChatMember($id,$user_id); |
|
| 216 | + $check = telegram::getChatMember($id, $user_id); |
|
| 217 | 217 | if (telegram::$status) { |
| 218 | 218 | $check = $check->status; |
| 219 | 219 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @return bool |
| 234 | 234 | */ |
| 235 | 235 | public static function isShorted(string $text): bool{ |
| 236 | - return preg_match('/^[a-zA-Z0-9]+$/',$text); |
|
| 236 | + return preg_match('/^[a-zA-Z0-9]+$/', $text); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
| 252 | 252 | */ |
| 253 | - public static function size (string $path, bool $format = true): string|int|false { |
|
| 253 | + public static function size(string $path, bool $format = true): string | int | false { |
|
| 254 | 254 | if (filter_var($path, FILTER_VALIDATE_URL)) { |
| 255 | 255 | $ch = curl_init($path); |
| 256 | 256 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return bool |
| 284 | 284 | * @throws bptException |
| 285 | 285 | */ |
| 286 | - public static function delete (string $path, bool $sub = true): bool { |
|
| 286 | + public static function delete(string $path, bool $sub = true): bool { |
|
| 287 | 287 | $path = realpath($path); |
| 288 | 288 | if (!is_dir($path)) { |
| 289 | 289 | return unlink($path); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | return rmdir($path); |
| 293 | 293 | } |
| 294 | 294 | if (!$sub) { |
| 295 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
| 295 | + logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR); |
|
| 296 | 296 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
| 297 | 297 | } |
| 298 | 298 | $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @return bool |
| 315 | 315 | * @throws bptException when zip extension not found |
| 316 | 316 | */ |
| 317 | - public static function zip (string $path, string $destination): bool { |
|
| 317 | + public static function zip(string $path, string $destination): bool { |
|
| 318 | 318 | if (!extension_loaded('zip')) { |
| 319 | 319 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
| 320 | 320 | throw new bptException('ZIP_EXTENSION_MISSING'); |
@@ -349,14 +349,14 @@ discard block |
||
| 349 | 349 | * |
| 350 | 350 | * @return bool true on success and false in failure |
| 351 | 351 | */ |
| 352 | - public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool { |
|
| 352 | + public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool { |
|
| 353 | 353 | $file = fopen($url, 'rb'); |
| 354 | 354 | if (!$file) return false; |
| 355 | 355 | $path = fopen($path, 'wb'); |
| 356 | 356 | if (!$path) return false; |
| 357 | 357 | |
| 358 | 358 | $length = $chunk_size * 1024; |
| 359 | - while (!feof($file)){ |
|
| 359 | + while (!feof($file)) { |
|
| 360 | 360 | fwrite($path, fread($file, $length), $length); |
| 361 | 361 | } |
| 362 | 362 | fclose($path); |
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | * |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public static function byteFormat (int $byte, int $precision = 2): string { |
|
| 381 | + public static function byteFormat(int $byte, int $precision = 2): string { |
|
| 382 | 382 | $rate_counter = 0; |
| 383 | 383 | |
| 384 | - while ($byte > 1024){ |
|
| 384 | + while ($byte > 1024) { |
|
| 385 | 385 | $byte /= 1024; |
| 386 | 386 | $rate_counter++; |
| 387 | 387 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | $byte = round($byte, $precision); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 393 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -407,10 +407,10 @@ discard block |
||
| 407 | 407 | * |
| 408 | 408 | * @return string|false return false when mode is incorrect |
| 409 | 409 | */ |
| 410 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
| 410 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
| 411 | 411 | return match ($mode) { |
| 412 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
| 413 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
| 412 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
| 413 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
| 414 | 414 | parseMode::MARKDOWNV2 => str_replace( |
| 415 | 415 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
| 416 | 416 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -449,12 +449,12 @@ discard block |
||
| 449 | 449 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
| 450 | 450 | * @throws Exception |
| 451 | 451 | */ |
| 452 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
| 452 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
| 453 | 453 | if (!isset($base_time)) { |
| 454 | 454 | $base_time = '@'.time(); |
| 455 | 455 | } |
| 456 | 456 | $base_time = new DateTime($base_time); |
| 457 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
| 457 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
| 458 | 458 | |
| 459 | 459 | $diff = $base_time->diff($target_time); |
| 460 | 460 | |
@@ -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)); |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | * |
| 522 | 522 | * @return string see possible values in fileType class |
| 523 | 523 | */ |
| 524 | - public static function fileType (string $file_id): string { |
|
| 524 | + public static function fileType(string $file_id): string { |
|
| 525 | 525 | $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '=')); |
| 526 | 526 | $new = ''; |
| 527 | 527 | $last = ''; |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $last = $char; |
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | - $data = unpack('VtypeId/Vdc_id', $new . $last); |
|
| 538 | + $data = unpack('VtypeId/Vdc_id', $new.$last); |
|
| 539 | 539 | $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216; |
| 540 | 540 | return [ |
| 541 | 541 | fileTypes::THUMBNAIL, |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * |
| 574 | 574 | * @return string |
| 575 | 575 | */ |
| 576 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
| 576 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
| 577 | 577 | $rand_string = ''; |
| 578 | 578 | $char_len = strlen($characters) - 1; |
| 579 | - for ($i = 0; $i < $length; $i ++) { |
|
| 579 | + for ($i = 0; $i < $length; $i++) { |
|
| 580 | 580 | $rand_string .= $characters[rand(0, $char_len)]; |
| 581 | 581 | } |
| 582 | 582 | return $rand_string; |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
| 606 | 606 | * @throws bptException |
| 607 | 607 | */ |
| 608 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
| 608 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
| 609 | 609 | if (!empty($keyboard)) { |
| 610 | 610 | $keyboard_object = new replyKeyboardMarkup(); |
| 611 | 611 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | return $keyboard_object; |
| 670 | 670 | } |
| 671 | 671 | else { |
| 672 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
| 672 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
| 673 | 673 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 674 | 674 | } |
| 675 | 675 | } |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | * |
| 687 | 687 | * @return string |
| 688 | 688 | */ |
| 689 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
| 689 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
| 690 | 690 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
| 691 | 691 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
| 692 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
| 692 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -713,9 +713,9 @@ discard block |
||
| 713 | 713 | * @return string|bool|array{hash:string, key:string, iv:string} |
| 714 | 714 | * @throws bptException |
| 715 | 715 | */ |
| 716 | - public static function codec (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
| 716 | + public static function codec(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
| 717 | 717 | if (!extension_loaded('openssl')) { |
| 718 | - logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
| 718 | + logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
| 719 | 719 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
| 720 | 720 | } |
| 721 | 721 | if ($action === codecAction::ENCRYPT) { |
@@ -726,17 +726,17 @@ discard block |
||
| 726 | 726 | } |
| 727 | 727 | elseif ($action === codecAction::DECRYPT) { |
| 728 | 728 | if (empty($key)) { |
| 729 | - logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR); |
|
| 729 | + logger::write("tools::codec function used\nkey parameter is not set", loggerTypes::ERROR); |
|
| 730 | 730 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
| 731 | 731 | } |
| 732 | 732 | if (empty($iv)) { |
| 733 | - logger::write("tools::codec function used\niv parameter is not set",loggerTypes::ERROR); |
|
| 733 | + logger::write("tools::codec function used\niv parameter is not set", loggerTypes::ERROR); |
|
| 734 | 734 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
| 735 | 735 | } |
| 736 | 736 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
| 737 | 737 | } |
| 738 | 738 | else { |
| 739 | - logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
| 739 | + logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
| 740 | 740 | return false; |
| 741 | 741 | } |
| 742 | 742 | } |
@@ -744,8 +744,8 @@ discard block |
||
| 744 | 744 | /** |
| 745 | 745 | * @deprecated use tools::codec() instead , will remove in 1.6.0 |
| 746 | 746 | */ |
| 747 | - public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
| 748 | - return self::codec($action,$text,$key,$iv); |
|
| 747 | + public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
| 748 | + return self::codec($action, $text, $key, $iv); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | public static function shortEncode(int $num): string { |
| 761 | 761 | $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 762 | 762 | $array = []; |
| 763 | - while ($num > 0){ |
|
| 763 | + while ($num > 0) { |
|
| 764 | 764 | $array[] = $num % 62; |
| 765 | 765 | $num = floor($num / 62); |
| 766 | 766 | } |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | foreach ($array as &$value) { |
| 769 | 769 | $value = $codes[$value]; |
| 770 | 770 | } |
| 771 | - return strrev(implode('',$array)); |
|
| 771 | + return strrev(implode('', $array)); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | /** |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | $num = 0; |
| 786 | 786 | $text = str_split(strrev($text)); |
| 787 | 787 | foreach ($text as $key=>$value) { |
| 788 | - $num += strpos($codes,$value) * pow(62,$key); |
|
| 788 | + $num += strpos($codes, $value) * pow(62, $key); |
|
| 789 | 789 | } |
| 790 | 790 | return $num; |
| 791 | 791 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | private static CurlHandle $session; |
| 23 | 23 | |
| 24 | - public static function init (): void { |
|
| 24 | + public static function init(): void { |
|
| 25 | 25 | self::$api_key = settings::$pay['crypto']['api_key'] ?? ''; |
| 26 | 26 | self::$ipn_secret = settings::$pay['crypto']['ipn_secret'] ?? ''; |
| 27 | 27 | self::$session = curl_init(); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYHOST, 2); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - private static function execute (string $method, string $endpoint, string|array $data = '') { |
|
| 33 | + private static function execute(string $method, string $endpoint, string | array $data = '') { |
|
| 34 | 34 | if (is_array($data)) { |
| 35 | 35 | foreach ($data as $key => $value) { |
| 36 | 36 | if (empty($value)) { |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | $session = self::$session; |
| 43 | 43 | curl_setopt($session, CURLOPT_HTTPHEADER, [ |
| 44 | - 'X-API-KEY: ' . self::$api_key, |
|
| 44 | + 'X-API-KEY: '.self::$api_key, |
|
| 45 | 45 | 'Content-Type: application/json' |
| 46 | 46 | ]); |
| 47 | 47 | switch ($method) { |
| 48 | 48 | case 'GET': |
| 49 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint . !empty($data) && is_array($data) ? ('?' . http_build_query($data)) : ''); |
|
| 49 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint.!empty($data) && is_array($data) ? ('?'.http_build_query($data)) : ''); |
|
| 50 | 50 | break; |
| 51 | 51 | case 'POST': |
| 52 | 52 | curl_setopt($session, CURLOPT_POST, true); |
| 53 | 53 | curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($data)); |
| 54 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint); |
|
| 54 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint); |
|
| 55 | 55 | break; |
| 56 | 56 | default: |
| 57 | 57 | return false; |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | return json_decode(curl_exec($session)); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - public static function status (): bool { |
|
| 62 | + public static function status(): bool { |
|
| 63 | 63 | return self::execute('GET', 'status')->message === 'OK'; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * @return estimatePriceInterface|mixed |
| 68 | 68 | */ |
| 69 | - public static function getEstimatePrice (int|float $amount, string $currency_from, string $currency_to) { |
|
| 69 | + public static function getEstimatePrice(int | float $amount, string $currency_from, string $currency_to) { |
|
| 70 | 70 | return self::execute('GET', 'estimate', [ |
| 71 | 71 | 'amount' => $amount, |
| 72 | 72 | 'currency_from' => $currency_from, |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | /** |
| 78 | 78 | * @return invoicePaymentInterface|mixed |
| 79 | 79 | */ |
| 80 | - 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) { |
|
| 80 | + 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) { |
|
| 81 | 81 | return self::execute('POST', 'payment', [ |
| 82 | 82 | 'price_amount' => $price_amount, |
| 83 | 83 | 'price_currency' => $price_currency, |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | /** |
| 98 | 98 | * @return invoicePaymentInterface|mixed |
| 99 | 99 | */ |
| 100 | - 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) { |
|
| 100 | + 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) { |
|
| 101 | 101 | return self::execute('POST', 'invoice', [ |
| 102 | 102 | 'iid' => $iid, |
| 103 | 103 | 'pay_currency' => $pay_currency, |
@@ -113,18 +113,18 @@ discard block |
||
| 113 | 113 | /** |
| 114 | 114 | * @return estimateUpdateInterface|mixed |
| 115 | 115 | */ |
| 116 | - public static function updateEstimatePrice (int $paymentID) { |
|
| 117 | - return self::execute('POST', 'payment/' . $paymentID . '/update-merchant-estimate'); |
|
| 116 | + public static function updateEstimatePrice(int $paymentID) { |
|
| 117 | + return self::execute('POST', 'payment/'.$paymentID.'/update-merchant-estimate'); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * @return paymentInterface|mixed |
| 122 | 122 | */ |
| 123 | - public static function getPaymentStatus (int $paymentID) { |
|
| 124 | - return self::execute('GET', 'payment/' . $paymentID); |
|
| 123 | + public static function getPaymentStatus(int $paymentID) { |
|
| 124 | + return self::execute('GET', 'payment/'.$paymentID); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public static function getMinimumPaymentAmount (string $currency_from, string $currency_to): float { |
|
| 127 | + public static function getMinimumPaymentAmount(string $currency_from, string $currency_to): float { |
|
| 128 | 128 | return self::execute('GET', 'min-amount', [ |
| 129 | 129 | 'currency_from' => $currency_from, |
| 130 | 130 | 'currency_to' => $currency_to |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @return invoiceResponseInterface|mixed |
| 136 | 136 | */ |
| 137 | - public static function createInvoice (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 $success_url = null, string $cancel_url = null) { |
|
| 137 | + public static function createInvoice(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 $success_url = null, string $cancel_url = null) { |
|
| 138 | 138 | return self::execute('POST', 'invoice', [ |
| 139 | 139 | 'price_amount' => $price_amount, |
| 140 | 140 | 'price_currency' => $price_currency, |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ]); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - public static function getCurrencies (): array { |
|
| 151 | + public static function getCurrencies(): array { |
|
| 152 | 152 | return self::execute('GET', 'currencies')->currencies; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | return $ip === '144.76.201.30'; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public static function isIPNRequestValid (): bool { |
|
| 169 | + public static function isIPNRequestValid(): bool { |
|
| 170 | 170 | if (empty($_SERVER['HTTP_X_NOWPAYMENTS_SIG'])) { |
| 171 | 171 | return false; |
| 172 | 172 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | /** |
| 187 | 187 | * @return ipnDataInterface|mixed |
| 188 | 188 | */ |
| 189 | - public static function getIPN () { |
|
| 189 | + public static function getIPN() { |
|
| 190 | 190 | if (!self::isIPNRequestValid()) { |
| 191 | 191 | return false; |
| 192 | 192 | } |
@@ -158,8 +158,7 @@ |
||
| 158 | 158 | if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) { |
| 159 | 159 | $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; |
| 160 | 160 | } |
| 161 | - } |
|
| 162 | - elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
|
| 161 | + } elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
|
| 163 | 162 | $ip = $_SERVER['HTTP_AR_REAL_IP']; |
| 164 | 163 | } |
| 165 | 164 | |
@@ -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 (!empty(settings::$pay)) { |
| 10 | 10 | if (!isset(settings::$pay['crypto'])) { |
| 11 | 11 | return; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public static int $log_size = 10; |
| 28 | 28 | |
| 29 | - public static string|CURLFile|null $certificate = null; |
|
| 29 | + public static string | CURLFile | null $certificate = null; |
|
| 30 | 30 | |
| 31 | 31 | public static bool $handler = true; |
| 32 | 32 | |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query']; |
| 62 | 62 | |
| 63 | - public static array|null $db = ['type' => 'json']; |
|
| 63 | + public static array | null $db = ['type' => 'json']; |
|
| 64 | 64 | |
| 65 | - public static array|null $pay = null; |
|
| 65 | + public static array | null $pay = null; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @internal Only for BPT self usage , Don't use it in your source! |
| 69 | 69 | */ |
| 70 | - public static function init (array|stdClass $settings): void { |
|
| 70 | + public static function init(array | stdClass $settings): void { |
|
| 71 | 71 | $settings = (array) $settings; |
| 72 | 72 | foreach ($settings as $setting => $value) { |
| 73 | 73 | try { |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | if (!is_dir(realpath('bots_files'))) { |
| 76 | 76 | mkdir('bots_files'); |
| 77 | 77 | } |
| 78 | - if (!is_dir(realpath('bots_files/' . $value))) { |
|
| 79 | - mkdir('bots_files/' . $value); |
|
| 78 | + if (!is_dir(realpath('bots_files/'.$value))) { |
|
| 79 | + mkdir('bots_files/'.$value); |
|
| 80 | 80 | } |
| 81 | - $value = 'bots_files/' . $value . '/'; |
|
| 81 | + $value = 'bots_files/'.$value.'/'; |
|
| 82 | 82 | } |
| 83 | 83 | self::$$setting = $value; |
| 84 | 84 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | /** |
| 113 | 113 | * @internal Only for BPT self usage , Don't use it in your source! |
| 114 | 114 | */ |
| 115 | - public static function done (): void { |
|
| 115 | + public static function done(): void { |
|
| 116 | 116 | if (self::$logger) { |
| 117 | 117 | $estimated = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2); |
| 118 | 118 | $status_message = match (true) { |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - private static function security (): void { |
|
| 130 | + private static function security(): void { |
|
| 131 | 131 | if (self::$security) { |
| 132 | 132 | ini_set('magic_quotes_gpc', 'off'); |
| 133 | 133 | ini_set('sql.safe_mode', 'on'); |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - private static function secureFolder (): void { |
|
| 145 | + private static function secureFolder(): void { |
|
| 146 | 146 | if (self::$secure_folder) { |
| 147 | 147 | $address = explode('/', $_SERVER['REQUEST_URI']); |
| 148 | 148 | unset($address[count($address) - 1]); |
| 149 | - $address = implode('/', $address) . '/BPT.php'; |
|
| 149 | + $address = implode('/', $address).'/BPT.php'; |
|
| 150 | 150 | $text = "ErrorDocument 404 $address\nErrorDocument 403 $address\n Options -Indexes\n Order Deny,Allow\nDeny from all\nAllow from 127.0.0.1\n<Files *.php>\n Order Allow,Deny\n Allow from all\n</Files>"; |
| 151 | 151 | $htaccess = realpath('.htaccess'); |
| 152 | 152 | if (!file_exists($htaccess) || filesize($htaccess) != strlen($text)) { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - private static function getUpdates (): void { |
|
| 158 | + private static function getUpdates(): void { |
|
| 159 | 159 | if (!self::$handler) { |
| 160 | 160 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler', loggerTypes::ERROR); |
| 161 | 161 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @internal Only for BPT self usage , Don't use it in your source! |
| 29 | 29 | */ |
| 30 | - public static function init (): void { |
|
| 30 | + public static function init(): void { |
|
| 31 | 31 | $host = settings::$db['host'] ?? 'localhost'; |
| 32 | 32 | $port = settings::$db['port'] ?? 3306; |
| 33 | 33 | $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown'; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $dbname = settings::$db['dbname']; |
| 37 | 37 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
| 38 | 38 | if (self::$connection->connect_errno) { |
| 39 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
| 39 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
| 40 | 40 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
| 41 | 41 | } |
| 42 | 42 | if (self::$auto_process && !lock::exist('BPT-MYSQL')) { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private static function install (): void { |
|
| 47 | + private static function install(): void { |
|
| 48 | 48 | self::pureQuery(" |
| 49 | 49 | CREATE TABLE `users` |
| 50 | 50 | ( |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @internal Only for BPT self usage , Don't use it in your source! |
| 67 | 67 | */ |
| 68 | - public static function process (): void { |
|
| 68 | + public static function process(): void { |
|
| 69 | 69 | if (self::$auto_process) { |
| 70 | 70 | if (isset(BPT::$update->message)) { |
| 71 | 71 | self::processMessage(BPT::$update->message); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - private static function processMessage (message $update): void { |
|
| 88 | + private static function processMessage(message $update): void { |
|
| 89 | 89 | $type = $update->chat->type; |
| 90 | 90 | if ($type === chatType::PRIVATE) { |
| 91 | 91 | $user_id = $update->from->id; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
| 114 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
| 115 | 115 | $type = $update->message->chat->type; |
| 116 | 116 | if ($type === chatType::PRIVATE) { |
| 117 | 117 | $user_id = $update->from->id; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private static function processInlineQuery (inlineQuery $update): void { |
|
| 124 | + private static function processInlineQuery(inlineQuery $update): void { |
|
| 125 | 125 | $type = $update->chat_type; |
| 126 | 126 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
| 127 | 127 | $user_id = $update->from->id; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
| 134 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
| 135 | 135 | $type = $update->chat->type; |
| 136 | 136 | if ($type === chatType::PRIVATE) { |
| 137 | 137 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return mysqli |
| 150 | 150 | */ |
| 151 | - public static function getMysqli (): mysqli { |
|
| 151 | + public static function getMysqli(): mysqli { |
|
| 152 | 152 | return self::$connection; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return int|string |
| 159 | 159 | */ |
| 160 | - public static function affected_rows (): int|string { |
|
| 160 | + public static function affected_rows(): int | string { |
|
| 161 | 161 | return self::$connection->affected_rows; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return int|string |
| 168 | 168 | */ |
| 169 | - public static function insert_id (): int|string { |
|
| 169 | + public static function insert_id(): int | string { |
|
| 170 | 170 | return self::$connection->insert_id; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public static function escapeString (string $text): string { |
|
| 180 | + public static function escapeString(string $text): string { |
|
| 181 | 181 | return self::$connection->real_escape_string($text); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return mysqli_result|bool |
| 194 | 194 | */ |
| 195 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
| 195 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
| 196 | 196 | return self::$connection->query($query); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return mysqli_result|bool |
| 213 | 213 | */ |
| 214 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
| 214 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
| 215 | 215 | $prepare = self::$connection->prepare($query); |
| 216 | 216 | $types = ''; |
| 217 | 217 | foreach ($vars as $var) { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | if (!empty($types) && !empty($vars)) { |
| 229 | - $prepare->bind_param($types,...$vars); |
|
| 229 | + $prepare->bind_param($types, ...$vars); |
|
| 230 | 230 | } |
| 231 | 231 | if (!$prepare->execute()) { |
| 232 | 232 | logger::write(loggerTypes::WARNING, $prepare->error); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | return $need_result ? $prepare->get_result() : true; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array { |
|
| 238 | + private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array { |
|
| 239 | 239 | $first = true; |
| 240 | 240 | $values = []; |
| 241 | 241 | foreach ($array as $name => $value) { |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | return $values; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 254 | + private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 255 | 255 | $values = []; |
| 256 | 256 | if (!empty($where)) { |
| 257 | 257 | $query .= " WHERE"; |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return mysqli_result|bool |
| 280 | 280 | */ |
| 281 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 281 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 282 | 282 | $query = "DELETE FROM `$table`"; |
| 283 | 283 | $res = self::makeQueryReady($query, $where, $count, $offset); |
| 284 | 284 | return self::query($query, $res, false); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * |
| 298 | 298 | * @return mysqli_result|bool |
| 299 | 299 | */ |
| 300 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 300 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 301 | 301 | $query = "UPDATE `$table` SET"; |
| 302 | 302 | $values = self::makeArrayReady($query, $modify, ', '); |
| 303 | 303 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | * |
| 316 | 316 | * @return mysqli_result|bool |
| 317 | 317 | */ |
| 318 | - public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
|
| 318 | + public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool { |
|
| 319 | 319 | $query = "INSERT INTO `$table`("; |
| 320 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
|
| 320 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES ('; |
|
| 321 | 321 | if (is_string($values)) $values = [$values]; |
| 322 | - $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
|
| 322 | + $query .= '?'.str_repeat(',?', count($values) - 1).')'; |
|
| 323 | 323 | return self::query($query, $values, false); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -338,13 +338,13 @@ discard block |
||
| 338 | 338 | * |
| 339 | 339 | * @return mysqli_result|bool |
| 340 | 340 | */ |
| 341 | - public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 341 | + public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 342 | 342 | $query = "SELECT "; |
| 343 | 343 | if ($columns == '*') { |
| 344 | 344 | $query .= "* "; |
| 345 | 345 | } |
| 346 | 346 | else { |
| 347 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
|
| 347 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` '; |
|
| 348 | 348 | } |
| 349 | 349 | $query .= "FROM `$table`"; |
| 350 | 350 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * |
| 363 | 363 | * @return null|bool|array |
| 364 | 364 | */ |
| 365 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null { |
|
| 365 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null { |
|
| 366 | 366 | $res = self::select($table, $columns, $where, 1); |
| 367 | 367 | if ($res) { |
| 368 | 368 | return $res->fetch_assoc(); |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*' |
| 380 | 380 | * @param array|null $where Set your ifs default : null |
| 381 | 381 | */ |
| 382 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null) { |
|
| 382 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null) { |
|
| 383 | 383 | $res = self::select($table, $columns, $where, 1); |
| 384 | 384 | if ($res) { |
| 385 | 385 | return $res->fetch_object(); |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | * |
| 402 | 402 | * @return bool|Generator |
| 403 | 403 | */ |
| 404 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
|
| 404 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator { |
|
| 405 | 405 | $res = self::select($table, $columns, $where, $count, $offset); |
| 406 | 406 | if ($res) { |
| 407 | 407 | while ($row = $res->fetch_assoc()) yield $row; |