@@ -13,8 +13,7 @@ |
||
| 13 | 13 | if (file_exists('BPT.log') && !(filesize('BPT.log') > self::$log_size * 1024 * 1024)) {
|
| 14 | 14 | $mode = 'a'; |
| 15 | 15 | $write = false; |
| 16 | - } |
|
| 17 | - else {
|
|
| 16 | + } else {
|
|
| 18 | 17 | $mode = 'w'; |
| 19 | 18 | $write = true; |
| 20 | 19 | } |
@@ -12,11 +12,9 @@ |
||
| 12 | 12 | public static function init() {
|
| 13 | 13 | if (lock::exist('BPT-MULTI-EXEC')) {
|
| 14 | 14 | self::setUpdate(exec::init()); |
| 15 | - } |
|
| 16 | - elseif(lock::exist('BPT-MULTI-CURL')) {
|
|
| 15 | + } elseif(lock::exist('BPT-MULTI-CURL')) {
|
|
| 17 | 16 | self::setUpdate(curl::init()); |
| 18 | - } |
|
| 19 | - else {
|
|
| 17 | + } else {
|
|
| 20 | 18 | self::deleteOldLocks(); |
| 21 | 19 | self::checkURL(); |
| 22 | 20 | self::setCertificate(); |
@@ -36,8 +36,7 @@ discard block |
||
| 36 | 36 | $curl_handler = curl_init(settings::$base_url."$token/"); |
| 37 | 37 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 38 | 38 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 39 | - } |
|
| 40 | - else{
|
|
| 39 | + } else{
|
|
| 41 | 40 | $token = settings::$token; |
| 42 | 41 | if (!isset(self::$curl_handler)){
|
| 43 | 42 | self::$curl_handler = curl_init(settings::$base_url."$token/"); |
@@ -59,11 +58,9 @@ discard block |
||
| 59 | 58 | if (isset($data['forgot'])) {
|
| 60 | 59 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 61 | 60 | unset($data['forgot']); |
| 62 | - } |
|
| 63 | - elseif ($method === 'getUpdates'){
|
|
| 61 | + } elseif ($method === 'getUpdates'){
|
|
| 64 | 62 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 65 | - } |
|
| 66 | - else{
|
|
| 63 | + } else{
|
|
| 67 | 64 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300); |
| 68 | 65 | } |
| 69 | 66 | } |
@@ -13,8 +13,7 @@ |
||
| 13 | 13 | public static function init (): string|null {
|
| 14 | 14 | if (self::checkIP()) {
|
| 15 | 15 | return self::getUpdate(); |
| 16 | - } |
|
| 17 | - else {
|
|
| 16 | + } else {
|
|
| 18 | 17 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
|
| 19 | 18 | BPT::exit(); |
| 20 | 19 | } |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | $update = file_get_contents($up); |
| 24 | 24 | unlink($up); |
| 25 | 25 | return $update; |
| 26 | - } |
|
| 27 | - else {
|
|
| 26 | + } else {
|
|
| 28 | 27 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
|
| 29 | 28 | BPT::exit(); |
| 30 | 29 | } |
@@ -233,8 +233,7 @@ |
||
| 233 | 233 | public function __call (string $name, array $arguments) {
|
| 234 | 234 | if (!isset($arguments[1]) && isset($arguments[0]) && is_array($arguments[0])) {
|
| 235 | 235 | return request::$name(...$arguments[0]); |
| 236 | - } |
|
| 237 | - else {
|
|
| 236 | + } else {
|
|
| 238 | 237 | return request::$name(...$arguments); |
| 239 | 238 | } |
| 240 | 239 | } |
@@ -22,8 +22,7 @@ discard block |
||
| 22 | 22 | self::handleUpdates($updates); |
| 23 | 23 | lock::save('getUpdate',BPT::$update->update_id+1);
|
| 24 | 24 | $last_update_id = BPT::$update->update_id+1; |
| 25 | - } |
|
| 26 | - else {
|
|
| 25 | + } else {
|
|
| 27 | 26 | logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR);
|
| 28 | 27 | BPT::exit(print_r($updates,true)); |
| 29 | 28 | } |
@@ -34,8 +33,7 @@ discard block |
||
| 34 | 33 | private static function loadData(): bool|int|string {
|
| 35 | 34 | if (lock::exist('getUpdate')) {
|
| 36 | 35 | $last_update_id = lock::read('getUpdate');
|
| 37 | - } |
|
| 38 | - else {
|
|
| 36 | + } else {
|
|
| 39 | 37 | self::deleteOldLocks(); |
| 40 | 38 | telegram::deleteWebhook(); |
| 41 | 39 | $last_update_id = 0; |
@@ -34,8 +34,7 @@ discard block |
||
| 34 | 34 | if (!$update) {
|
| 35 | 35 | BPT::exit(); |
| 36 | 36 | } |
| 37 | - } |
|
| 38 | - elseif (!is_a($update,'update')) {
|
|
| 37 | + } elseif (!is_a($update,'update')) {
|
|
| 39 | 38 | $update = new update($update); |
| 40 | 39 | } |
| 41 | 40 | |
@@ -72,26 +71,21 @@ discard block |
||
| 72 | 71 | if (self::handlerExist('message')) {
|
| 73 | 72 | BPT::$handler->message(BPT::$update->message); |
| 74 | 73 | } |
| 75 | - } |
|
| 76 | - elseif (isset(BPT::$update->callback_query)) {
|
|
| 74 | + } elseif (isset(BPT::$update->callback_query)) {
|
|
| 77 | 75 | if (self::handlerExist('callback_query')) {
|
| 78 | 76 | BPT::$handler->callback_query(BPT::$update->callback_query); |
| 79 | 77 | } |
| 80 | - } |
|
| 81 | - elseif (isset(BPT::$update->inline_query)) {
|
|
| 78 | + } elseif (isset(BPT::$update->inline_query)) {
|
|
| 82 | 79 | if (self::handlerExist('inline_query')) {
|
| 83 | 80 | BPT::$handler->inline_query(BPT::$update->inline_query); |
| 84 | 81 | } |
| 85 | - } |
|
| 86 | - elseif (isset(BPT::$update->edited_message)) {
|
|
| 82 | + } elseif (isset(BPT::$update->edited_message)) {
|
|
| 87 | 83 | if (self::handlerExist('edited_message')) {
|
| 88 | 84 | BPT::$handler->edited_message(BPT::$update->edited_message); |
| 89 | 85 | } |
| 90 | - } |
|
| 91 | - elseif (self::handlerExist('something_else')) {
|
|
| 86 | + } elseif (self::handlerExist('something_else')) {
|
|
| 92 | 87 | BPT::$handler->something_else(BPT::$update); |
| 93 | - } |
|
| 94 | - else {
|
|
| 88 | + } else {
|
|
| 95 | 89 | logger::write('Update received but handlers does not set',loggerTypes::WARNING);
|
| 96 | 90 | } |
| 97 | 91 | } |
@@ -706,12 +706,10 @@ discard block |
||
| 706 | 706 | self::setDefaults($action,$arguments); |
| 707 | 707 | if (isset($arguments['answer'])) {
|
| 708 | 708 | return answer::init($action,$arguments); |
| 709 | - } |
|
| 710 | - else {
|
|
| 709 | + } else {
|
|
| 711 | 710 | return self::processResponse($action,curl::init($action,$arguments)); |
| 712 | 711 | } |
| 713 | - } |
|
| 714 | - else {
|
|
| 712 | + } else {
|
|
| 715 | 713 | logger::write("$name method is not supported",loggerTypes::ERROR);
|
| 716 | 714 | throw new bptException('METHOD_NOT_FOUND');
|
| 717 | 715 | } |
@@ -737,8 +735,7 @@ discard block |
||
| 737 | 735 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
| 738 | 736 | } |
| 739 | 737 | } |
| 740 | - } |
|
| 741 | - elseif ($file_params = self::methodFile($name)) {
|
|
| 738 | + } elseif ($file_params = self::methodFile($name)) {
|
|
| 742 | 739 | foreach ($file_params as $param) {
|
| 743 | 740 | if (isset($arguments[$param]) && file_exists($arguments[$param])) {
|
| 744 | 741 | $arguments[$param] = new CURLFile($arguments[$param]); |
@@ -760,12 +757,10 @@ discard block |
||
| 760 | 757 | $value = new ($return[0]) ($value); |
| 761 | 758 | } |
| 762 | 759 | return $response; |
| 763 | - } |
|
| 764 | - else {
|
|
| 760 | + } else {
|
|
| 765 | 761 | return new ($return) ($response->result); |
| 766 | 762 | } |
| 767 | - } |
|
| 768 | - else {
|
|
| 763 | + } else {
|
|
| 769 | 764 | return $response->result; |
| 770 | 765 | } |
| 771 | 766 | } |
@@ -777,8 +772,7 @@ discard block |
||
| 777 | 772 | if (!isset($arguments[$default])){
|
| 778 | 773 | $arguments[$default] = self::catchFields($default); |
| 779 | 774 | } |
| 780 | - } |
|
| 781 | - elseif (isset(BPT::$update->$key) || $key === 'other') {
|
|
| 775 | + } elseif (isset(BPT::$update->$key) || $key === 'other') {
|
|
| 782 | 776 | foreach ($default as $def) {
|
| 783 | 777 | if (!isset($arguments[$def])){
|
| 784 | 778 | $arguments[$def] = self::catchFields($def); |
@@ -794,8 +788,7 @@ discard block |
||
| 794 | 788 | self::$status = true; |
| 795 | 789 | self::$pure_response = $response; |
| 796 | 790 | return self::methodReturn($name,$response); |
| 797 | - } |
|
| 798 | - else {
|
|
| 791 | + } else {
|
|
| 799 | 792 | self::$status = false; |
| 800 | 793 | self::$pure_response = $response; |
| 801 | 794 | return new responseError($response); |
@@ -831,9 +824,13 @@ discard block |
||
| 831 | 824 | default => false |
| 832 | 825 | }; |
| 833 | 826 | case 'file_id' : |
| 834 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
| 835 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
| 836 | - else return false; |
|
| 827 | + if (isset(BPT::$update->message)) { |
|
| 828 | + $type = 'message'; |
|
| 829 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 830 | + $type = 'edited_message'; |
|
| 831 | + } else { |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 837 | 834 | |
| 838 | 835 | return match(true) {
|
| 839 | 836 | isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id, |