@@ -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); |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | * |
380 | 380 | * @return string |
381 | 381 | */ |
382 | - public static function byteFormat (int $byte, int $precision = 2, bool $space_between = true): string { |
|
382 | + public static function byteFormat(int $byte, int $precision = 2, bool $space_between = true): string { |
|
383 | 383 | $rate_counter = 0; |
384 | 384 | |
385 | - while ($byte > 1024){ |
|
385 | + while ($byte > 1024) { |
|
386 | 386 | $byte /= 1024; |
387 | 387 | $rate_counter++; |
388 | 388 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $byte = round($byte, $precision); |
392 | 392 | } |
393 | 393 | |
394 | - return $byte . ($space_between ? ' ' : '') . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
394 | + return $byte.($space_between ? ' ' : '').['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -408,10 +408,10 @@ discard block |
||
408 | 408 | * |
409 | 409 | * @return string|false return false when mode is incorrect |
410 | 410 | */ |
411 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
411 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
412 | 412 | return match ($mode) { |
413 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
414 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
413 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
414 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
415 | 415 | parseMode::MARKDOWNV2 => str_replace( |
416 | 416 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
417 | 417 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -450,9 +450,9 @@ discard block |
||
450 | 450 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
451 | 451 | * @throws Exception |
452 | 452 | */ |
453 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
453 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
454 | 454 | $base_time = new DateTime($base_time ?? '@'.time()); |
455 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
455 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
456 | 456 | |
457 | 457 | $diff = $base_time->diff($target_time); |
458 | 458 | |
@@ -479,12 +479,12 @@ discard block |
||
479 | 479 | * |
480 | 480 | * @return string[]|string |
481 | 481 | */ |
482 | - public static function realEscapeString(string|array $input): string|array { |
|
483 | - if(is_array($input)) { |
|
482 | + public static function realEscapeString(string | array $input): string | array { |
|
483 | + if (is_array($input)) { |
|
484 | 484 | return array_map(__METHOD__, $input); |
485 | 485 | } |
486 | 486 | |
487 | - if(!empty($input) && is_string($input)) { |
|
487 | + if (!empty($input) && is_string($input)) { |
|
488 | 488 | return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input); |
489 | 489 | } |
490 | 490 | |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return string[]|string |
504 | 504 | */ |
505 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
505 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
506 | 506 | $pos = strpos($subject, $search); |
507 | 507 | if ($pos !== false) { |
508 | 508 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @return string see possible values in fileType class |
521 | 521 | */ |
522 | - public static function fileType (string $file_id): string { |
|
522 | + public static function fileType(string $file_id): string { |
|
523 | 523 | $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '=')); |
524 | 524 | $new = ''; |
525 | 525 | $last = ''; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $last = $char; |
534 | 534 | } |
535 | 535 | } |
536 | - $data = unpack('VtypeId/Vdc_id', $new . $last); |
|
536 | + $data = unpack('VtypeId/Vdc_id', $new.$last); |
|
537 | 537 | $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216; |
538 | 538 | return [ |
539 | 539 | fileTypes::THUMBNAIL, |
@@ -571,10 +571,10 @@ discard block |
||
571 | 571 | * |
572 | 572 | * @return string |
573 | 573 | */ |
574 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
574 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
575 | 575 | $rand_string = ''; |
576 | 576 | $char_len = strlen($characters) - 1; |
577 | - for ($i = 0; $i < $length; $i ++) { |
|
577 | + for ($i = 0; $i < $length; $i++) { |
|
578 | 578 | $rand_string .= $characters[rand(0, $char_len)]; |
579 | 579 | } |
580 | 580 | return $rand_string; |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
604 | 604 | * @throws bptException |
605 | 605 | */ |
606 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
606 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
607 | 607 | if (!empty($keyboard)) { |
608 | 608 | $keyboard_object = new replyKeyboardMarkup(); |
609 | 609 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | return $keyboard_object; |
668 | 668 | } |
669 | 669 | else { |
670 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
670 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
671 | 671 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
672 | 672 | } |
673 | 673 | } |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | * |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
687 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
688 | 688 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
689 | 689 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
690 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
690 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -711,9 +711,9 @@ discard block |
||
711 | 711 | * @return string|bool|array{hash:string, key:string, iv:string} |
712 | 712 | * @throws bptException |
713 | 713 | */ |
714 | - public static function codec (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
714 | + public static function codec(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
715 | 715 | if (!extension_loaded('openssl')) { |
716 | - logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
716 | + logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
717 | 717 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
718 | 718 | } |
719 | 719 | if ($action === codecAction::ENCRYPT) { |
@@ -724,17 +724,17 @@ discard block |
||
724 | 724 | } |
725 | 725 | elseif ($action === codecAction::DECRYPT) { |
726 | 726 | if (empty($key)) { |
727 | - logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR); |
|
727 | + logger::write("tools::codec function used\nkey parameter is not set", loggerTypes::ERROR); |
|
728 | 728 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
729 | 729 | } |
730 | 730 | if (empty($iv)) { |
731 | - logger::write("tools::codec function used\niv parameter is not set",loggerTypes::ERROR); |
|
731 | + logger::write("tools::codec function used\niv parameter is not set", loggerTypes::ERROR); |
|
732 | 732 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
733 | 733 | } |
734 | 734 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
735 | 735 | } |
736 | 736 | else { |
737 | - logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
737 | + logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
738 | 738 | return false; |
739 | 739 | } |
740 | 740 | } |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | public static function shortEncode(int $num): string { |
752 | 752 | $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
753 | 753 | $array = []; |
754 | - while ($num > 0){ |
|
754 | + while ($num > 0) { |
|
755 | 755 | $array[] = $num % 62; |
756 | 756 | $num = floor($num / 62); |
757 | 757 | } |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | foreach ($array as &$value) { |
760 | 760 | $value = $codes[$value]; |
761 | 761 | } |
762 | - return strrev(implode('',$array)); |
|
762 | + return strrev(implode('', $array)); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | $num = 0; |
777 | 777 | $text = str_split(strrev($text)); |
778 | 778 | foreach ($text as $key=>$value) { |
779 | - $num += strpos($codes,$value) * pow(62,$key); |
|
779 | + $num += strpos($codes, $value) * pow(62, $key); |
|
780 | 780 | } |
781 | 781 | return $num; |
782 | 782 | } |
@@ -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 | return; |
11 | 11 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | /** |
18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
19 | 19 | */ |
20 | - public static function init (): void { |
|
20 | + public static function init(): void { |
|
21 | 21 | if (!isset(settings::$db['type'])) { |
22 | 22 | settings::$db['type'] = dbTypes::JSON; |
23 | 23 | } |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | * @method bool|responseError unhideGeneralForumTopic (int|string|array $chat_id, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success. |
269 | 269 | * @method bool|responseError unhideGeneralTopic (int|string|array $chat_id, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success. |
270 | 270 | */ |
271 | -class BPT extends telegram{ |
|
271 | +class BPT extends telegram { |
|
272 | 272 | public static update $update; |
273 | 273 | |
274 | 274 | public static BPT $handler; |
275 | 275 | |
276 | 276 | |
277 | - public function __construct (array|stdClass $settings) { |
|
277 | + public function __construct(array | stdClass $settings) { |
|
278 | 278 | static::$handler = &$this; |
279 | 279 | settings::init($settings); |
280 | 280 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | #[NoReturn] |
287 | - public static function exit (string|null $message = null) { |
|
287 | + public static function exit (string | null $message = null) { |
|
288 | 288 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
289 | 289 | } |
290 | 290 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | public string $name; |
16 | 16 | |
17 | 17 | /** Optional. New identifier of the custom emoji shown as the topic icon, if it was edited; an empty string if the icon was removed */ |
18 | - public null|string $icon_custom_emoji_id = null; |
|
18 | + public null | string $icon_custom_emoji_id = null; |
|
19 | 19 | |
20 | 20 | |
21 | - public function __construct(stdClass|null $object = null) { |
|
21 | + public function __construct(stdClass | null $object = null) { |
|
22 | 22 | if ($object != null) { |
23 | 23 | parent::__construct($object, self::subs); |
24 | 24 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | /** Keep all of properties which has sub properties */ |
12 | 12 | private const subs = []; |
13 | 13 | |
14 | - public function __construct(stdClass|null $object = null) { |
|
14 | + public function __construct(stdClass | null $object = null) { |
|
15 | 15 | if ($object != null) { |
16 | 16 | parent::__construct($object, self::subs); |
17 | 17 | } |
@@ -30,97 +30,97 @@ discard block |
||
30 | 30 | public string $type; |
31 | 31 | |
32 | 32 | /** Optional. Title, for supergroups, channels and group chats */ |
33 | - public null|string $title = null; |
|
33 | + public null | string $title = null; |
|
34 | 34 | |
35 | 35 | /** Optional. Username, for private chats, supergroups and channels if available */ |
36 | - public null|string $username = null; |
|
36 | + public null | string $username = null; |
|
37 | 37 | |
38 | 38 | /** Optional. First name of the other party in a private chat */ |
39 | - public null|string $first_name = null; |
|
39 | + public null | string $first_name = null; |
|
40 | 40 | |
41 | 41 | /** Optional. Last name of the other party in a private chat */ |
42 | - public null|string $last_name = null; |
|
42 | + public null | string $last_name = null; |
|
43 | 43 | |
44 | 44 | /** Optional. True, if the supergroup chat is a forum (has topics enabled) */ |
45 | - public null|bool $is_forum = null; |
|
45 | + public null | bool $is_forum = null; |
|
46 | 46 | |
47 | 47 | /** Optional. Chat photo. Returned only in getChat. */ |
48 | - public null|chatPhoto $photo = null; |
|
48 | + public null | chatPhoto $photo = null; |
|
49 | 49 | |
50 | 50 | /** Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in getChat. */ |
51 | - public null|array $active_usernames = null; |
|
51 | + public null | array $active_usernames = null; |
|
52 | 52 | |
53 | 53 | /** Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat. */ |
54 | - public null|string $emoji_status_custom_emoji_id = null; |
|
54 | + public null | string $emoji_status_custom_emoji_id = null; |
|
55 | 55 | |
56 | 56 | /** Optional. Bio of the other party in a private chat. Returned only in getChat. */ |
57 | - public null|string $bio = null; |
|
57 | + public null | string $bio = null; |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Optional. True, if privacy settings of the other party in the private chat allows to use |
61 | 61 | * tg://user?id=<user_id> links only in chats with the user. Returned only in getChat. |
62 | 62 | */ |
63 | - public null|bool $has_private_forwards = null; |
|
63 | + public null | bool $has_private_forwards = null; |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in |
67 | 67 | * the private chat. Returned only in getChat. |
68 | 68 | */ |
69 | - public null|bool $has_restricted_voice_and_video_messages = null; |
|
69 | + public null | bool $has_restricted_voice_and_video_messages = null; |
|
70 | 70 | |
71 | 71 | /** Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. */ |
72 | - public null|bool $join_to_send_messages = null; |
|
72 | + public null | bool $join_to_send_messages = null; |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. |
76 | 76 | * Returned only in getChat. |
77 | 77 | */ |
78 | - public null|bool $join_by_request = null; |
|
78 | + public null | bool $join_by_request = null; |
|
79 | 79 | |
80 | 80 | /** Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. */ |
81 | - public null|string $description = null; |
|
81 | + public null | string $description = null; |
|
82 | 82 | |
83 | 83 | /** Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. */ |
84 | - public null|string $invite_link = null; |
|
84 | + public null | string $invite_link = null; |
|
85 | 85 | |
86 | 86 | /** Optional. The most recent pinned message (by sending date). Returned only in getChat. */ |
87 | - public null|message $pinned_message = null; |
|
87 | + public null | message $pinned_message = null; |
|
88 | 88 | |
89 | 89 | /** Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. */ |
90 | - public null|chatPermissions $permissions = null; |
|
90 | + public null | chatPermissions $permissions = null; |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged |
94 | 94 | * user; in seconds. Returned only in getChat. |
95 | 95 | */ |
96 | - public null|int $slow_mode_delay = null; |
|
96 | + public null | int $slow_mode_delay = null; |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. |
100 | 100 | * Returned only in getChat. |
101 | 101 | */ |
102 | - public null|int $message_auto_delete_time = null; |
|
102 | + public null | int $message_auto_delete_time = null; |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Optional. True, if aggressive anti-spam checks are enabled in the supergroup. |
106 | 106 | * The field is only available to chat administrators. Returned only in getChat. |
107 | 107 | */ |
108 | - public null|bool $has_aggressive_anti_spam_enabled = null; |
|
108 | + public null | bool $has_aggressive_anti_spam_enabled = null; |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Optional. True, if non-administrators can only get the list of bots and administrators in the chat. |
112 | 112 | * Returned only in getChat. |
113 | 113 | */ |
114 | - public null|bool $has_hidden_members = null; |
|
114 | + public null | bool $has_hidden_members = null; |
|
115 | 115 | |
116 | 116 | /** Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. */ |
117 | - public null|bool $has_protected_content = null; |
|
117 | + public null | bool $has_protected_content = null; |
|
118 | 118 | |
119 | 119 | /** Optional. For supergroups, name of group sticker set. Returned only in getChat. */ |
120 | - public null|string $sticker_set_name = null; |
|
120 | + public null | string $sticker_set_name = null; |
|
121 | 121 | |
122 | 122 | /** Optional. True, if the bot can change the group sticker set. Returned only in getChat. */ |
123 | - public null|bool $can_set_sticker_set = null; |
|
123 | + public null | bool $can_set_sticker_set = null; |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice |
@@ -128,87 +128,87 @@ discard block |
||
128 | 128 | * languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed |
129 | 129 | * 64 bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat. |
130 | 130 | */ |
131 | - public null|int $linked_chat_id = null; |
|
131 | + public null | int $linked_chat_id = null; |
|
132 | 132 | |
133 | 133 | /** Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. */ |
134 | - public null|chatLocation $location = null; |
|
134 | + public null | chatLocation $location = null; |
|
135 | 135 | |
136 | 136 | |
137 | - public function __construct(stdClass|null $object = null) { |
|
137 | + public function __construct(stdClass | null $object = null) { |
|
138 | 138 | if ($object != null) { |
139 | 139 | parent::__construct($object, self::subs); |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - public function isPrivate (): bool { |
|
143 | + public function isPrivate(): bool { |
|
144 | 144 | return $this->type === chatType::PRIVATE; |
145 | 145 | } |
146 | 146 | |
147 | - public function isGroup (): bool { |
|
147 | + public function isGroup(): bool { |
|
148 | 148 | return $this->type === chatType::GROUP; |
149 | 149 | } |
150 | 150 | |
151 | - public function isSuperGroup (): bool { |
|
151 | + public function isSuperGroup(): bool { |
|
152 | 152 | return $this->type === chatType::SUPERGROUP; |
153 | 153 | } |
154 | 154 | |
155 | - public function isChannel (): bool { |
|
155 | + public function isChannel(): bool { |
|
156 | 156 | return $this->type === chatType::CHANNEL; |
157 | 157 | } |
158 | 158 | |
159 | - public function leave(): responseError|bool { |
|
159 | + public function leave(): responseError | bool { |
|
160 | 160 | if ($this->isPrivate()) { |
161 | 161 | return false; |
162 | 162 | } |
163 | 163 | return telegram::leave($this->id); |
164 | 164 | } |
165 | 165 | |
166 | - public function setPhoto(CURLFile|array $photo): responseError|bool { |
|
166 | + public function setPhoto(CURLFile | array $photo): responseError | bool { |
|
167 | 167 | if ($this->isPrivate()) { |
168 | 168 | return false; |
169 | 169 | } |
170 | - return telegram::setChatPhoto($photo,$this->id); |
|
170 | + return telegram::setChatPhoto($photo, $this->id); |
|
171 | 171 | } |
172 | 172 | |
173 | - public function delPhoto(): responseError|bool { |
|
173 | + public function delPhoto(): responseError | bool { |
|
174 | 174 | if ($this->isPrivate()) { |
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | return telegram::deleteChatPhoto($this->id); |
178 | 178 | } |
179 | 179 | |
180 | - public function setTitle(string|array $title): responseError|bool { |
|
180 | + public function setTitle(string | array $title): responseError | bool { |
|
181 | 181 | if ($this->isPrivate()) { |
182 | 182 | return false; |
183 | 183 | } |
184 | - return telegram::setChatTitle($title,$this->id); |
|
184 | + return telegram::setChatTitle($title, $this->id); |
|
185 | 185 | } |
186 | 186 | |
187 | - public function setDescription(string|null $description = null): responseError|bool { |
|
187 | + public function setDescription(string | null $description = null): responseError | bool { |
|
188 | 188 | if ($this->isPrivate()) { |
189 | 189 | return false; |
190 | 190 | } |
191 | - return telegram::setChatDescription($this->id,$description); |
|
191 | + return telegram::setChatDescription($this->id, $description); |
|
192 | 192 | } |
193 | 193 | |
194 | - public function getAdmins(): bool|responseError|array { |
|
194 | + public function getAdmins(): bool | responseError | array { |
|
195 | 195 | if ($this->isPrivate()) { |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | return telegram::getChatAdministrators($this->id); |
199 | 199 | } |
200 | 200 | |
201 | - public function getMembersCount(): bool|responseError|int { |
|
201 | + public function getMembersCount(): bool | responseError | int { |
|
202 | 202 | if ($this->isPrivate()) { |
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | return telegram::getChatMemberCount($this->id); |
206 | 206 | } |
207 | 207 | |
208 | - public function getMember(int|null $user_id = null): chatMember|bool|responseError { |
|
208 | + public function getMember(int | null $user_id = null): chatMember | bool | responseError { |
|
209 | 209 | if ($this->isPrivate()) { |
210 | 210 | return false; |
211 | 211 | } |
212 | - return telegram::getChatMember($this->id,$user_id); |
|
212 | + return telegram::getChatMember($this->id, $user_id); |
|
213 | 213 | } |
214 | 214 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | /** Keep all of properties which has sub properties */ |
12 | 12 | private const subs = []; |
13 | 13 | |
14 | - public function __construct(stdClass|null $object = null) { |
|
14 | + public function __construct(stdClass | null $object = null) { |
|
15 | 15 | if ($object != null) { |
16 | 16 | parent::__construct($object, self::subs); |
17 | 17 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | /** Keep all of properties which has sub properties */ |
12 | 12 | private const subs = []; |
13 | 13 | |
14 | - public function __construct(stdClass|null $object = null) { |
|
14 | + public function __construct(stdClass | null $object = null) { |
|
15 | 15 | if ($object != null) { |
16 | 16 | parent::__construct($object, self::subs); |
17 | 17 | } |