@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
| 31 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
| 32 | 32 | $rand_string = ''; |
| 33 | 33 | $char_len = strlen($characters) - 1; |
| 34 | - for ($i = 0; $i < $length; $i ++) { |
|
| 34 | + for ($i = 0; $i < $length; $i++) { |
|
| 35 | 35 | $rand_string .= $characters[rand(0, $char_len)]; |
| 36 | 36 | } |
| 37 | 37 | return $rand_string; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
| 61 | 61 | * @throws bptException |
| 62 | 62 | */ |
| 63 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
| 63 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
| 64 | 64 | if (!empty($keyboard)) { |
| 65 | 65 | $keyboard_object = new replyKeyboardMarkup(); |
| 66 | 66 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | return $keyboard_object; |
| 120 | 120 | } |
| 121 | 121 | else { |
| 122 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
| 122 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
| 123 | 123 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -68,7 +68,9 @@ discard block |
||
| 68 | 68 | $keyboard_object->setOne_time_keyboard($keyboard['one_time']); |
| 69 | 69 | } |
| 70 | 70 | foreach ($keyboard as $row) { |
| 71 | - if (!is_array($row)) continue; |
|
| 71 | + if (!is_array($row)) { |
|
| 72 | + continue; |
|
| 73 | + } |
|
| 72 | 74 | $buttons = []; |
| 73 | 75 | foreach ($row as $base_button) { |
| 74 | 76 | $button_info = explode('||', $base_button); |
@@ -77,15 +79,12 @@ discard block |
||
| 77 | 79 | if (count($button_info) > 1) { |
| 78 | 80 | if ($button_info[1] === 'con') { |
| 79 | 81 | $button->setRequest_contact(true); |
| 80 | - } |
|
| 81 | - elseif ($button_info[1] === 'loc') { |
|
| 82 | + } elseif ($button_info[1] === 'loc') { |
|
| 82 | 83 | $button->setRequest_location(true); |
| 83 | - } |
|
| 84 | - elseif ($button_info[1] === 'poll') { |
|
| 84 | + } elseif ($button_info[1] === 'poll') { |
|
| 85 | 85 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
| 86 | 86 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
| 87 | - } |
|
| 88 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 87 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 89 | 88 | $url = $button_info[2]; |
| 90 | 89 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
| 91 | 90 | } |
@@ -95,8 +94,7 @@ discard block |
||
| 95 | 94 | $keyboard_object->setKeyboard([$buttons]); |
| 96 | 95 | } |
| 97 | 96 | return $keyboard_object; |
| 98 | - } |
|
| 99 | - elseif (!empty($inline)) { |
|
| 97 | + } elseif (!empty($inline)) { |
|
| 100 | 98 | $keyboard_object = new inlineKeyboardMarkup(); |
| 101 | 99 | foreach ($inline as $row) { |
| 102 | 100 | $buttons = []; |
@@ -105,20 +103,17 @@ discard block |
||
| 105 | 103 | if (isset($button_info[1])) { |
| 106 | 104 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
| 107 | 105 | $button->setText($button_info[0])->setUrl($button_info[1]); |
| 108 | - } |
|
| 109 | - else { |
|
| 106 | + } else { |
|
| 110 | 107 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
| 111 | 108 | } |
| 112 | - } |
|
| 113 | - else { |
|
| 109 | + } else { |
|
| 114 | 110 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
| 115 | 111 | } |
| 116 | 112 | } |
| 117 | 113 | $keyboard_object->setInline_keyboard([$buttons]); |
| 118 | 114 | } |
| 119 | 115 | return $keyboard_object; |
| 120 | - } |
|
| 121 | - else { |
|
| 116 | + } else { |
|
| 122 | 117 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
| 123 | 118 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 124 | 119 | } |
@@ -11,15 +11,15 @@ |
||
| 11 | 11 | return touch("$name.lock");
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function save(string $name, string $data): bool|int {
|
|
| 15 | - return file_put_contents("$name.lock", $data) && chmod("$name.lock",0640);
|
|
| 14 | + public static function save(string $name, string $data): bool | int {
|
|
| 15 | + return file_put_contents("$name.lock", $data) && chmod("$name.lock", 0640);
|
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static function read(string $name): bool|string {
|
|
| 18 | + public static function read(string $name): bool | string {
|
|
| 19 | 19 | return file_get_contents("$name.lock");
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public static function mtime(string $name): bool|int {
|
|
| 22 | + public static function mtime(string $name): bool | int {
|
|
| 23 | 23 | return filemtime("$name.lock");
|
| 24 | 24 | } |
| 25 | 25 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use CURLFile; |
| 14 | 14 | |
| 15 | 15 | class webhook extends receiver {
|
| 16 | - public static function init () {
|
|
| 16 | + public static function init() {
|
|
| 17 | 17 | if (settings::$multi) {
|
| 18 | 18 | multi::init(); |
| 19 | 19 | } |
@@ -42,26 +42,26 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - protected static function setWebhook(string $url,string $secret = '') {
|
|
| 45 | + protected static function setWebhook(string $url, string $secret = '') {
|
|
| 46 | 46 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates, secret_token: $secret); |
| 47 | 47 | if (telegram::$status) {
|
| 48 | - logger::write('Webhook was set successfully',loggerTypes::INFO);
|
|
| 48 | + logger::write('Webhook was set successfully', loggerTypes::INFO);
|
|
| 49 | 49 | } |
| 50 | 50 | else {
|
| 51 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
|
| 52 | - BPT::exit(print_r($res,true)); |
|
| 51 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
|
|
| 52 | + BPT::exit(print_r($res, true)); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | protected static function checkURL() {
|
| 57 | 57 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
|
| 58 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
|
|
| 58 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
|
|
| 59 | 59 | throw new bptException('WEBHOOK_NEED_URL');
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | private static function setURL(): string {
|
| 64 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
| 64 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | protected static function setCertificate() {
|
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | self::setCertificate(); |
| 84 | 84 | $url = self::setURL(); |
| 85 | 85 | $secret = tools::randomString(64); |
| 86 | - self::setWebhook($url,$secret); |
|
| 87 | - lock::save('BPT-HOOK',$secret);
|
|
| 86 | + self::setWebhook($url, $secret); |
|
| 87 | + lock::save('BPT-HOOK', $secret);
|
|
| 88 | 88 | BPT::exit('Done');
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | private static function checkSecret() {
|
| 92 | 92 | $secret = lock::read('BPT-HOOK');
|
| 93 | 93 | if (!isset($_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN']) || $_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN'] != $secret) {
|
| 94 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING);
|
|
| 94 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING);
|
|
| 95 | 95 | self::processSetWebhook(); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -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 | receiver::processUpdate(); |
| 25 | 24 | logger::write('Update received , lets process it ;)');
|
| 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, 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 | } |