@@ -97,51 +97,41 @@ |
||
97 | 97 | if (self::handlerExist('message')) { |
98 | 98 | BPT::$handler->message(BPT::$update->message); |
99 | 99 | } |
100 | - } |
|
101 | - elseif (isset(BPT::$update->edited_message)) { |
|
100 | + } elseif (isset(BPT::$update->edited_message)) { |
|
102 | 101 | if (self::handlerExist('edited_message')) { |
103 | 102 | BPT::$handler->edited_message(BPT::$update->edited_message); |
104 | 103 | } |
105 | - } |
|
106 | - elseif (isset(BPT::$update->channel_post)) { |
|
104 | + } elseif (isset(BPT::$update->channel_post)) { |
|
107 | 105 | if (self::handlerExist('channel_post')) { |
108 | 106 | BPT::$handler->channel_post(BPT::$update->channel_post); |
109 | 107 | } |
110 | - } |
|
111 | - elseif (isset(BPT::$update->edited_channel_post)) { |
|
108 | + } elseif (isset(BPT::$update->edited_channel_post)) { |
|
112 | 109 | if (self::handlerExist('edited_channel_post')) { |
113 | 110 | BPT::$handler->edited_channel_post(BPT::$update->edited_channel_post); |
114 | 111 | } |
115 | - } |
|
116 | - elseif (isset(BPT::$update->inline_query)) { |
|
112 | + } elseif (isset(BPT::$update->inline_query)) { |
|
117 | 113 | if (self::handlerExist('inline_query')) { |
118 | 114 | BPT::$handler->inline_query(BPT::$update->inline_query); |
119 | 115 | } |
120 | - } |
|
121 | - elseif (isset(BPT::$update->callback_query)) { |
|
116 | + } elseif (isset(BPT::$update->callback_query)) { |
|
122 | 117 | if (self::handlerExist('callback_query')) { |
123 | 118 | BPT::$handler->callback_query(BPT::$update->callback_query); |
124 | 119 | } |
125 | - } |
|
126 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
120 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
127 | 121 | if (self::handlerExist('my_chat_member')) { |
128 | 122 | BPT::$handler->my_chat_member(BPT::$update->my_chat_member); |
129 | 123 | } |
130 | - } |
|
131 | - elseif (isset(BPT::$update->chat_member)) { |
|
124 | + } elseif (isset(BPT::$update->chat_member)) { |
|
132 | 125 | if (self::handlerExist('chat_member')) { |
133 | 126 | BPT::$handler->chat_member(BPT::$update->chat_member); |
134 | 127 | } |
135 | - } |
|
136 | - elseif (isset(BPT::$update->chat_join_request)) { |
|
128 | + } elseif (isset(BPT::$update->chat_join_request)) { |
|
137 | 129 | if (self::handlerExist('chat_join_request')) { |
138 | 130 | BPT::$handler->chat_join_request(BPT::$update->chat_join_request); |
139 | 131 | } |
140 | - } |
|
141 | - elseif (self::handlerExist('something_else')) { |
|
132 | + } elseif (self::handlerExist('something_else')) { |
|
142 | 133 | BPT::$handler->something_else(BPT::$update); |
143 | - } |
|
144 | - else { |
|
134 | + } else { |
|
145 | 135 | logger::write('Update received but handlers are not set',loggerTypes::WARNING); |
146 | 136 | } |
147 | 137 | } |
@@ -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 | } |
@@ -260,8 +261,7 @@ discard block |
||
260 | 261 | curl_exec($ch); |
261 | 262 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
262 | 263 | curl_close($ch); |
263 | - } |
|
264 | - else { |
|
264 | + } else { |
|
265 | 265 | $path = realpath($path); |
266 | 266 | $size = file_exists($path) ? filesize($path) : false; |
267 | 267 | } |
@@ -332,8 +332,7 @@ discard block |
||
332 | 332 | $zip->addFile($filePath, substr($filePath, $root_len)); |
333 | 333 | } |
334 | 334 | } |
335 | - } |
|
336 | - else { |
|
335 | + } else { |
|
337 | 336 | $zip->addFile($path, basename($path)); |
338 | 337 | } |
339 | 338 | return $zip->close(); |
@@ -352,9 +351,13 @@ discard block |
||
352 | 351 | */ |
353 | 352 | public static function downloadFile (string $url, string $path, int $chunk_size = 512): bool { |
354 | 353 | $file = fopen($url, 'rb'); |
355 | - if (!$file) return false; |
|
354 | + if (!$file) { |
|
355 | + return false; |
|
356 | + } |
|
356 | 357 | $path = fopen($path, 'wb'); |
357 | - if (!$path) return false; |
|
358 | + if (!$path) { |
|
359 | + return false; |
|
360 | + } |
|
358 | 361 | |
359 | 362 | $length = $chunk_size * 1024; |
360 | 363 | while (!feof($file)){ |
@@ -461,8 +464,9 @@ discard block |
||
461 | 464 | foreach ($string as $k => &$v) { |
462 | 465 | if ($diff->$v) { |
463 | 466 | $v = $diff->$v; |
467 | + } else { |
|
468 | + unset($string[$k]); |
|
464 | 469 | } |
465 | - else unset($string[$k]); |
|
466 | 470 | } |
467 | 471 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
468 | 472 | |
@@ -528,8 +532,7 @@ discard block |
||
528 | 532 | if ($last === "\0") { |
529 | 533 | $new .= str_repeat($last, ord($char)); |
530 | 534 | $last = ''; |
531 | - } |
|
532 | - else { |
|
535 | + } else { |
|
533 | 536 | $new .= $last; |
534 | 537 | $last = $char; |
535 | 538 | } |
@@ -613,7 +616,9 @@ discard block |
||
613 | 616 | } |
614 | 617 | $rows = []; |
615 | 618 | foreach ($keyboard as $row) { |
616 | - if (!is_array($row)) continue; |
|
619 | + if (!is_array($row)) { |
|
620 | + continue; |
|
621 | + } |
|
617 | 622 | $buttons = []; |
618 | 623 | foreach ($row as $base_button) { |
619 | 624 | $button_info = explode('||', $base_button); |
@@ -622,15 +627,12 @@ discard block |
||
622 | 627 | if (count($button_info) > 1) { |
623 | 628 | if ($button_info[1] === 'con') { |
624 | 629 | $button->setRequest_contact(true); |
625 | - } |
|
626 | - elseif ($button_info[1] === 'loc') { |
|
630 | + } elseif ($button_info[1] === 'loc') { |
|
627 | 631 | $button->setRequest_location(true); |
628 | - } |
|
629 | - elseif ($button_info[1] === 'poll') { |
|
632 | + } elseif ($button_info[1] === 'poll') { |
|
630 | 633 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
631 | 634 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
632 | - } |
|
633 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
635 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
634 | 636 | $url = $button_info[2]; |
635 | 637 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
636 | 638 | } |
@@ -652,12 +654,10 @@ discard block |
||
652 | 654 | if (isset($button_info[1])) { |
653 | 655 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
654 | 656 | $button->setText($button_info[0])->setUrl($button_info[1]); |
655 | - } |
|
656 | - else { |
|
657 | + } else { |
|
657 | 658 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
658 | 659 | } |
659 | - } |
|
660 | - else { |
|
660 | + } else { |
|
661 | 661 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
662 | 662 | } |
663 | 663 | $buttons[] = $button; |
@@ -684,8 +684,12 @@ discard block |
||
684 | 684 | * @return string |
685 | 685 | */ |
686 | 686 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
687 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
688 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
687 | + if (empty($user_id)) { |
|
688 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
689 | + } |
|
690 | + if (empty($bot_username)) { |
|
691 | + $bot_username = telegram::getMe()->username; |
|
692 | + } |
|
689 | 693 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
690 | 694 | } |
691 | 695 | |
@@ -752,7 +756,9 @@ discard block |
||
752 | 756 | $array[] = $num % 62; |
753 | 757 | $num = floor($num / 62); |
754 | 758 | } |
755 | - if (count($array) < 1) $array = [0]; |
|
759 | + if (count($array) < 1) { |
|
760 | + $array = [0]; |
|
761 | + } |
|
756 | 762 | foreach ($array as &$value) { |
757 | 763 | $value = $codes[$value]; |
758 | 764 | } |