@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @internal Only for BPT self usage , Don't use it in your source! |
| 21 | 21 | */ |
| 22 | - public static function init () { |
|
| 22 | + public static function init() { |
|
| 23 | 23 | if (settings::$multi) { |
| 24 | 24 | multi::init(); |
| 25 | 25 | } |
@@ -48,26 +48,26 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - protected static function setWebhook(string $url,string $secret = '') { |
|
| 51 | + protected static function setWebhook(string $url, string $secret = '') { |
|
| 52 | 52 | $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); |
| 53 | 53 | if (telegram::$status) { |
| 54 | - logger::write('Webhook was set successfully',loggerTypes::INFO); |
|
| 54 | + logger::write('Webhook was set successfully', loggerTypes::INFO); |
|
| 55 | 55 | } |
| 56 | 56 | else { |
| 57 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
|
| 58 | - BPT::exit(print_r($res,true)); |
|
| 57 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR); |
|
| 58 | + BPT::exit(print_r($res, true)); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | protected static function checkURL() { |
| 63 | 63 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
| 64 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR); |
|
| 64 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR); |
|
| 65 | 65 | throw new bptException('WEBHOOK_NEED_URL'); |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | private static function setURL(): string { |
| 70 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
| 70 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | 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 | } |
@@ -72,7 +72,9 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | $rows = []; |
| 74 | 74 | foreach ($keyboard as $row) { |
| 75 | - if (!is_array($row)) continue; |
|
| 75 | + if (!is_array($row)) { |
|
| 76 | + continue; |
|
| 77 | + } |
|
| 76 | 78 | $buttons = []; |
| 77 | 79 | foreach ($row as $base_button) { |
| 78 | 80 | $button_info = explode('||', $base_button); |
@@ -81,15 +83,12 @@ discard block |
||
| 81 | 83 | if (count($button_info) > 1) { |
| 82 | 84 | if ($button_info[1] === 'con') { |
| 83 | 85 | $button->setRequest_contact(true); |
| 84 | - } |
|
| 85 | - elseif ($button_info[1] === 'loc') { |
|
| 86 | + } elseif ($button_info[1] === 'loc') { |
|
| 86 | 87 | $button->setRequest_location(true); |
| 87 | - } |
|
| 88 | - elseif ($button_info[1] === 'poll') { |
|
| 88 | + } elseif ($button_info[1] === 'poll') { |
|
| 89 | 89 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
| 90 | 90 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
| 91 | - } |
|
| 92 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 91 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 93 | 92 | $url = $button_info[2]; |
| 94 | 93 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
| 95 | 94 | } |
@@ -100,8 +99,7 @@ discard block |
||
| 100 | 99 | } |
| 101 | 100 | $keyboard_object->setKeyboard($rows); |
| 102 | 101 | return $keyboard_object; |
| 103 | - } |
|
| 104 | - elseif (!empty($inline)) { |
|
| 102 | + } elseif (!empty($inline)) { |
|
| 105 | 103 | $keyboard_object = new inlineKeyboardMarkup(); |
| 106 | 104 | $rows = []; |
| 107 | 105 | foreach ($inline as $row) { |
@@ -111,12 +109,10 @@ discard block |
||
| 111 | 109 | if (isset($button_info[1])) { |
| 112 | 110 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
| 113 | 111 | $button->setText($button_info[0])->setUrl($button_info[1]); |
| 114 | - } |
|
| 115 | - else { |
|
| 112 | + } else { |
|
| 116 | 113 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
| 117 | 114 | } |
| 118 | - } |
|
| 119 | - else { |
|
| 115 | + } else { |
|
| 120 | 116 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
| 121 | 117 | } |
| 122 | 118 | $buttons[] = $button; |
@@ -125,8 +121,7 @@ discard block |
||
| 125 | 121 | } |
| 126 | 122 | $keyboard_object->setInline_keyboard($rows); |
| 127 | 123 | return $keyboard_object; |
| 128 | - } |
|
| 129 | - else { |
|
| 124 | + } else { |
|
| 130 | 125 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
| 131 | 126 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 132 | 127 | } |
@@ -145,8 +140,12 @@ discard block |
||
| 145 | 140 | * @return string |
| 146 | 141 | */ |
| 147 | 142 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
| 148 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
| 149 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
| 143 | + if (empty($user_id)) { |
|
| 144 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
| 145 | + } |
|
| 146 | + if (empty($bot_username)) { |
|
| 147 | + $bot_username = telegram::getMe()->username; |
|
| 148 | + } |
|
| 150 | 149 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
| 151 | 150 | } |
| 152 | 151 | } |
| 153 | 152 | \ No newline at end of file |