@@ -17,21 +17,18 @@ discard block |
||
| 17 | 17 | foreach ($object as $key=>$value) { |
| 18 | 18 | if (isset($subs[$key])) { |
| 19 | 19 | $this->$key = new ($subs[$key]) ($value); |
| 20 | - } |
|
| 21 | - else { |
|
| 20 | + } else { |
|
| 22 | 21 | if (is_array($value)) { |
| 23 | 22 | foreach ($value as $sub_key=>$sub_value) { |
| 24 | 23 | if (is_array($sub_value)) { |
| 25 | 24 | foreach ($sub_value as $sub2_value) { |
| 26 | 25 | $this->$key[$sub_key][] = new ($subs['array']['array'][$key]) ($sub2_value); |
| 27 | 26 | } |
| 28 | - } |
|
| 29 | - else{ |
|
| 27 | + } else{ |
|
| 30 | 28 | $this->$key[] = new ($subs['array'][$key]) ($sub_value); |
| 31 | 29 | } |
| 32 | 30 | } |
| 33 | - } |
|
| 34 | - else{ |
|
| 31 | + } else{ |
|
| 35 | 32 | $this->$key = $value; |
| 36 | 33 | if (ucfirst($key) === basename(get_class($this)).'_id') { |
| 37 | 34 | $this->{'id'} = $value; |
@@ -48,8 +45,7 @@ discard block |
||
| 48 | 45 | $name = substr($name,3); |
| 49 | 46 | if (isset($arguments[0])) { |
| 50 | 47 | $this->$name = $arguments[0]; |
| 51 | - } |
|
| 52 | - elseif (isset($arguments['value'])) { |
|
| 48 | + } elseif (isset($arguments['value'])) { |
|
| 53 | 49 | $this->$name = $arguments['value']; |
| 54 | 50 | } |
| 55 | 51 | } |
@@ -36,24 +36,20 @@ discard block |
||
| 36 | 36 | $iv = self::randomString(); |
| 37 | 37 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
| 38 | 38 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
| 39 | - } |
|
| 40 | - elseif ($action === cryptoAction::DECRYPT) { |
|
| 39 | + } elseif ($action === cryptoAction::DECRYPT) { |
|
| 41 | 40 | if (empty($key)) { |
| 42 | 41 | logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
| 43 | 42 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
| 44 | - } |
|
| 45 | - elseif (empty($iv)) { |
|
| 43 | + } elseif (empty($iv)) { |
|
| 46 | 44 | logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
| 47 | 45 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
| 48 | 46 | } |
| 49 | 47 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
| 50 | - } |
|
| 51 | - else { |
|
| 48 | + } else { |
|
| 52 | 49 | logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
| 53 | 50 | return false; |
| 54 | 51 | } |
| 55 | - } |
|
| 56 | - else { |
|
| 52 | + } else { |
|
| 57 | 53 | logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
| 58 | 54 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
| 59 | 55 | } |
@@ -75,7 +71,9 @@ discard block |
||
| 75 | 71 | $array[] = $num % 62; |
| 76 | 72 | $num = floor($num / 62); |
| 77 | 73 | } |
| 78 | - if (count($array) < 1) $array = [0]; |
|
| 74 | + if (count($array) < 1) { |
|
| 75 | + $array = [0]; |
|
| 76 | + } |
|
| 79 | 77 | foreach ($array as &$value) { |
| 80 | 78 | $value = $codes[$value]; |
| 81 | 79 | } |
@@ -17,8 +17,7 @@ discard block |
||
| 17 | 17 | if (file_exists(settings::$name.'BPT.log') && !(filesize(settings::$name.'BPT.log') > self::$log_size * 1024 * 1024)) { |
| 18 | 18 | $mode = 'a'; |
| 19 | 19 | $write = false; |
| 20 | - } |
|
| 21 | - else { |
|
| 20 | + } else { |
|
| 22 | 21 | $mode = 'w'; |
| 23 | 22 | $write = true; |
| 24 | 23 | } |
@@ -39,8 +38,7 @@ discard block |
||
| 39 | 38 | $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" ); |
| 40 | 39 | if (!is_null(self::$handler)) { |
| 41 | 40 | fwrite(self::$handler, $text); |
| 42 | - } |
|
| 43 | - else { |
|
| 41 | + } else { |
|
| 44 | 42 | self::$waited_logs[] = $text; |
| 45 | 43 | } |
| 46 | 44 | } |
@@ -35,8 +35,7 @@ discard block |
||
| 35 | 35 | $curl_handler = curl_init(settings::$base_url."/bot$token/"); |
| 36 | 36 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 37 | 37 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 38 | - } |
|
| 39 | - else{ |
|
| 38 | + } else{ |
|
| 40 | 39 | $token = settings::$token; |
| 41 | 40 | if (!isset(self::$curl_handler)){ |
| 42 | 41 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
@@ -58,11 +57,9 @@ discard block |
||
| 58 | 57 | if (isset($data['forgot'])) { |
| 59 | 58 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 60 | 59 | unset($data['forgot']); |
| 61 | - } |
|
| 62 | - elseif ($method === 'getUpdates'){ |
|
| 60 | + } elseif ($method === 'getUpdates'){ |
|
| 63 | 61 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 64 | - } |
|
| 65 | - else{ |
|
| 62 | + } else{ |
|
| 66 | 63 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300); |
| 67 | 64 | } |
| 68 | 65 | } |
@@ -69,11 +69,9 @@ discard block |
||
| 69 | 69 | $value = 'bots_files/'.$value.'/'; |
| 70 | 70 | } |
| 71 | 71 | self::$$setting = $value; |
| 72 | - } |
|
| 73 | - catch (TypeError){ |
|
| 72 | + } catch (TypeError){ |
|
| 74 | 73 | logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
| 75 | - } |
|
| 76 | - catch (Error){ |
|
| 74 | + } catch (Error){ |
|
| 77 | 75 | logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
| 78 | 76 | } |
| 79 | 77 | } |
@@ -90,13 +88,11 @@ discard block |
||
| 90 | 88 | if (!empty(self::$receiver)) { |
| 91 | 89 | self::$receiver !== receiver::GETUPDATES ? self::webhook() : self::getUpdates(); |
| 92 | 90 | } |
| 93 | - } |
|
| 94 | - else { |
|
| 91 | + } else { |
|
| 95 | 92 | logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
| 96 | 93 | throw new bptException('TOKEN_NOT_TRUE'); |
| 97 | 94 | } |
| 98 | - } |
|
| 99 | - else { |
|
| 95 | + } else { |
|
| 100 | 96 | logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
| 101 | 97 | throw new bptException('TOKEN_NOT_FOUND'); |
| 102 | 98 | } |
@@ -153,8 +149,7 @@ discard block |
||
| 153 | 149 | private static function getUpdates(): void { |
| 154 | 150 | if (self::$handler) { |
| 155 | 151 | getUpdates::init(); |
| 156 | - } |
|
| 157 | - else { |
|
| 152 | + } else { |
|
| 158 | 153 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
| 159 | 154 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
| 160 | 155 | } |
@@ -71,7 +71,9 @@ discard block |
||
| 71 | 71 | $keyboard_object->setOne_time_keyboard($keyboard['one_time']); |
| 72 | 72 | } |
| 73 | 73 | foreach ($keyboard as $row) { |
| 74 | - if (!is_array($row)) continue; |
|
| 74 | + if (!is_array($row)) { |
|
| 75 | + continue; |
|
| 76 | + } |
|
| 75 | 77 | $buttons = []; |
| 76 | 78 | foreach ($row as $base_button) { |
| 77 | 79 | $button_info = explode('||', $base_button); |
@@ -80,15 +82,12 @@ discard block |
||
| 80 | 82 | if (count($button_info) > 1) { |
| 81 | 83 | if ($button_info[1] === 'con') { |
| 82 | 84 | $button->setRequest_contact(true); |
| 83 | - } |
|
| 84 | - elseif ($button_info[1] === 'loc') { |
|
| 85 | + } elseif ($button_info[1] === 'loc') { |
|
| 85 | 86 | $button->setRequest_location(true); |
| 86 | - } |
|
| 87 | - elseif ($button_info[1] === 'poll') { |
|
| 87 | + } elseif ($button_info[1] === 'poll') { |
|
| 88 | 88 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
| 89 | 89 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
| 90 | - } |
|
| 91 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 90 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 92 | 91 | $url = $button_info[2]; |
| 93 | 92 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
| 94 | 93 | } |
@@ -98,8 +97,7 @@ discard block |
||
| 98 | 97 | $keyboard_object->setKeyboard([$buttons]); |
| 99 | 98 | } |
| 100 | 99 | return $keyboard_object; |
| 101 | - } |
|
| 102 | - elseif (!empty($inline)) { |
|
| 100 | + } elseif (!empty($inline)) { |
|
| 103 | 101 | $keyboard_object = new inlineKeyboardMarkup(); |
| 104 | 102 | foreach ($inline as $row) { |
| 105 | 103 | $buttons = []; |
@@ -108,20 +106,17 @@ discard block |
||
| 108 | 106 | if (isset($button_info[1])) { |
| 109 | 107 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
| 110 | 108 | $button->setText($button_info[0])->setUrl($button_info[1]); |
| 111 | - } |
|
| 112 | - else { |
|
| 109 | + } else { |
|
| 113 | 110 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
| 114 | 111 | } |
| 115 | - } |
|
| 116 | - else { |
|
| 112 | + } else { |
|
| 117 | 113 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
| 118 | 114 | } |
| 119 | 115 | } |
| 120 | 116 | $keyboard_object->setInline_keyboard([$buttons]); |
| 121 | 117 | } |
| 122 | 118 | return $keyboard_object; |
| 123 | - } |
|
| 124 | - else { |
|
| 119 | + } else { |
|
| 125 | 120 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
| 126 | 121 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 127 | 122 | } |
@@ -140,8 +135,12 @@ discard block |
||
| 140 | 135 | * @return string |
| 141 | 136 | */ |
| 142 | 137 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
| 143 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
| 144 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
| 138 | + if (empty($user_id)) { |
|
| 139 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
| 140 | + } |
|
| 141 | + if (empty($bot_username)) { |
|
| 142 | + $bot_username = telegram::getMe()->username; |
|
| 143 | + } |
|
| 145 | 144 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
| 146 | 145 | } |
| 147 | 146 | } |
| 148 | 147 | \ No newline at end of file |
@@ -16,15 +16,13 @@ discard block |
||
| 16 | 16 | public static function init () { |
| 17 | 17 | if (settings::$multi) { |
| 18 | 18 | multi::init(); |
| 19 | - } |
|
| 20 | - else { |
|
| 19 | + } else { |
|
| 21 | 20 | if (lock::exist('BPT-HOOK')) { |
| 22 | 21 | receiver::telegramVerify(); |
| 23 | 22 | self::checkSecret(); |
| 24 | 23 | logger::write('Update received , lets process it ;)'); |
| 25 | 24 | receiver::processUpdate(); |
| 26 | - } |
|
| 27 | - else { |
|
| 25 | + } else { |
|
| 28 | 26 | self::processSetWebhook(); |
| 29 | 27 | } |
| 30 | 28 | } |
@@ -46,8 +44,7 @@ discard block |
||
| 46 | 44 | $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); |
| 47 | 45 | if (telegram::$status) { |
| 48 | 46 | logger::write('Webhook was set successfully',loggerTypes::INFO); |
| 49 | - } |
|
| 50 | - else { |
|
| 47 | + } else { |
|
| 51 | 48 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
| 52 | 49 | BPT::exit(print_r($res,true)); |
| 53 | 50 | } |
@@ -69,8 +66,7 @@ discard block |
||
| 69 | 66 | if (is_string(settings::$certificate)) { |
| 70 | 67 | if (file_exists(settings::$certificate)) { |
| 71 | 68 | settings::$certificate = new CURLFile(settings::$certificate); |
| 72 | - } |
|
| 73 | - else { |
|
| 69 | + } else { |
|
| 74 | 70 | settings::$certificate = null; |
| 75 | 71 | } |
| 76 | 72 | } |
@@ -27,8 +27,7 @@ discard block |
||
| 27 | 27 | if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) { |
| 28 | 28 | $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; |
| 29 | 29 | } |
| 30 | - } |
|
| 31 | - elseif (settings::$arvancloud_verify) { |
|
| 30 | + } elseif (settings::$arvancloud_verify) { |
|
| 32 | 31 | if (isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
| 33 | 32 | $ip = $_SERVER['HTTP_AR_REAL_IP']; |
| 34 | 33 | } |
@@ -87,46 +86,37 @@ discard block |
||
| 87 | 86 | if (self::handlerExist('message')) { |
| 88 | 87 | BPT::$handler->message(BPT::$update->message); |
| 89 | 88 | } |
| 90 | - } |
|
| 91 | - elseif (isset(BPT::$update->edited_message)) { |
|
| 89 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 92 | 90 | if (self::handlerExist('edited_message')) { |
| 93 | 91 | BPT::$handler->edited_message(BPT::$update->edited_message); |
| 94 | 92 | } |
| 95 | - } |
|
| 96 | - elseif (isset(BPT::$update->channel_post)) { |
|
| 93 | + } elseif (isset(BPT::$update->channel_post)) { |
|
| 97 | 94 | if (self::handlerExist('channel_post')) { |
| 98 | 95 | BPT::$handler->channel_post(BPT::$update->channel_post); |
| 99 | 96 | } |
| 100 | - } |
|
| 101 | - elseif (isset(BPT::$update->edited_channel_post)) { |
|
| 97 | + } elseif (isset(BPT::$update->edited_channel_post)) { |
|
| 102 | 98 | if (self::handlerExist('edited_channel_post')) { |
| 103 | 99 | BPT::$handler->edited_channel_post(BPT::$update->edited_channel_post); |
| 104 | 100 | } |
| 105 | - } |
|
| 106 | - elseif (isset(BPT::$update->inline_query)) { |
|
| 101 | + } elseif (isset(BPT::$update->inline_query)) { |
|
| 107 | 102 | if (self::handlerExist('inline_query')) { |
| 108 | 103 | BPT::$handler->inline_query(BPT::$update->inline_query); |
| 109 | 104 | } |
| 110 | - } |
|
| 111 | - elseif (isset(BPT::$update->callback_query)) { |
|
| 105 | + } elseif (isset(BPT::$update->callback_query)) { |
|
| 112 | 106 | if (self::handlerExist('callback_query')) { |
| 113 | 107 | BPT::$handler->callback_query(BPT::$update->callback_query); |
| 114 | 108 | } |
| 115 | - } |
|
| 116 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
| 109 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
| 117 | 110 | if (self::handlerExist('my_chat_member')) { |
| 118 | 111 | BPT::$handler->my_chat_member(BPT::$update->my_chat_member); |
| 119 | 112 | } |
| 120 | - } |
|
| 121 | - elseif (isset(BPT::$update->chat_member)) { |
|
| 113 | + } elseif (isset(BPT::$update->chat_member)) { |
|
| 122 | 114 | if (self::handlerExist('chat_member')) { |
| 123 | 115 | BPT::$handler->chat_member(BPT::$update->chat_member); |
| 124 | 116 | } |
| 125 | - } |
|
| 126 | - elseif (self::handlerExist('something_else')) { |
|
| 117 | + } elseif (self::handlerExist('something_else')) { |
|
| 127 | 118 | BPT::$handler->something_else(BPT::$update); |
| 128 | - } |
|
| 129 | - else { |
|
| 119 | + } else { |
|
| 130 | 120 | logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
| 131 | 121 | } |
| 132 | 122 | } |