@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
34 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
35 | 35 | $rand_string = ''; |
36 | 36 | $char_len = strlen($characters) - 1; |
37 | - for ($i = 0; $i < $length; $i ++) { |
|
37 | + for ($i = 0; $i < $length; $i++) { |
|
38 | 38 | $rand_string .= $characters[rand(0, $char_len)]; |
39 | 39 | } |
40 | 40 | return $rand_string; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
64 | 64 | * @throws bptException |
65 | 65 | */ |
66 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
66 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
67 | 67 | if (!empty($keyboard)) { |
68 | 68 | $keyboard_object = new replyKeyboardMarkup(); |
69 | 69 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | return $keyboard_object; |
123 | 123 | } |
124 | 124 | else { |
125 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
125 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
126 | 126 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
127 | 127 | } |
128 | 128 | } |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
142 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
143 | 143 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
144 | 144 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
145 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
145 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | \ No newline at end of file |
@@ -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 | } |
@@ -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 = 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 | } |
@@ -9,4 +9,4 @@ |
||
9 | 9 | * |
10 | 10 | * @todo make it usefully (it's not called at all) |
11 | 11 | */ |
12 | -class telegramException extends Exception{} |
|
13 | 12 | \ No newline at end of file |
13 | +class telegramException extends Exception {} |
|
14 | 14 | \ No newline at end of file |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | * curl class , for multiprocessing with curl tricks |
15 | 15 | */ |
16 | 16 | class curl extends webhook { |
17 | - public static function init (): string|null { |
|
17 | + public static function init(): string | null { |
|
18 | 18 | if (self::checkIP()) { |
19 | 19 | return self::getUpdate(); |
20 | 20 | } |
21 | 21 | else { |
22 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
22 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
23 | 23 | BPT::exit(); |
24 | 24 | return null; |
25 | 25 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
30 | 30 | } |
31 | 31 | |
32 | - private static function getUpdate (): string { |
|
32 | + private static function getUpdate(): string { |
|
33 | 33 | $input = json_decode(file_get_contents("php://input"), true); |
34 | 34 | webhook::telegramVerify($input['ip']); |
35 | 35 | return $input['update']; |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | $urls = self::setURLS(); |
43 | 43 | $file = $urls['file']; |
44 | 44 | $timeout = self::getTimeout($file); |
45 | - self::create($file,$timeout); |
|
45 | + self::create($file, $timeout); |
|
46 | 46 | self::setWebhook($urls['url']); |
47 | 47 | lock::set('BPT-MULTI-CURL'); |
48 | 48 | } |
49 | 49 | |
50 | - private static function getTimeout($url): float|int { |
|
50 | + private static function getTimeout($url): float | int { |
|
51 | 51 | $times = []; |
52 | - for ($i = 0; $i < 10; $i ++) { |
|
52 | + for ($i = 0; $i < 10; $i++) { |
|
53 | 53 | $ch = curl_init($url); |
54 | 54 | curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([]), CURLOPT_TIMEOUT_MS => 100, CURLOPT_NOBODY => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => 100, CURLOPT_HTTPHEADER => ['accept: application/json', 'content-type: application/json']]); |
55 | 55 | $start = microtime(true); |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | return $timeout > 50 ? $timeout + 10 : 50; |
61 | 61 | } |
62 | 62 | |
63 | - private static function create($file,$timeout) { |
|
64 | - file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\'' . $file . '\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => ' . $timeout . ', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => ' . $timeout . ', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
63 | + private static function create($file, $timeout) { |
|
64 | + file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\''.$file.'\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => '.$timeout.', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => '.$timeout.', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | private static function setURLS(): array { |
68 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
68 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
69 | 69 | $file = basename($_SERVER['REQUEST_URI']); |
70 | 70 | return [ |
71 | 71 | 'url'=>str_replace($file, 'receiver.php', $base_url), |
@@ -17,8 +17,7 @@ |
||
17 | 17 | public static function init (): string|null { |
18 | 18 | if (self::checkIP()) { |
19 | 19 | return self::getUpdate(); |
20 | - } |
|
21 | - else { |
|
20 | + } else { |
|
22 | 21 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
23 | 22 | BPT::exit(); |
24 | 23 | return null; |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
19 | 19 | */ |
20 | - public static function init(): string|null { |
|
20 | + public static function init(): string | null { |
|
21 | 21 | return self::getUpdate(); |
22 | 22 | } |
23 | 23 | |
24 | - private static function getUpdate (): string|null { |
|
24 | + private static function getUpdate(): string | null { |
|
25 | 25 | $up = glob('*.update'); |
26 | 26 | if (isset($up[0])) { |
27 | 27 | $up = end($up); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | return $update; |
33 | 33 | } |
34 | 34 | else { |
35 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
35 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
36 | 36 | BPT::exit(); |
37 | 37 | return null; |
38 | 38 | } |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | private static function create($file) { |
62 | - file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php ' . $file . ' > /dev/null &");'); |
|
62 | + file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php '.$file.' > /dev/null &");'); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | private static function setURLS(): array { |
66 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
66 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
67 | 67 | return [ |
68 | 68 | 'url'=>str_replace(basename($_SERVER['REQUEST_URI']), 'receiver.php', $base_url), |
69 | 69 | 'file'=>basename($_SERVER['SCRIPT_NAME']) |
@@ -30,8 +30,7 @@ |
||
30 | 30 | $update = file_get_contents($up); |
31 | 31 | unlink($up); |
32 | 32 | return $update; |
33 | - } |
|
34 | - else { |
|
33 | + } else { |
|
35 | 34 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
36 | 35 | BPT::exit(); |
37 | 36 | return null; |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | if (!tools::isTelegram($ip ?? '')) { |
44 | - logger::write('not authorized access denied. IP : '. $ip ?? 'unknown',loggerTypes::WARNING); |
|
44 | + logger::write('not authorized access denied. IP : '.$ip ?? 'unknown', loggerTypes::WARNING); |
|
45 | 45 | BPT::exit(); |
46 | 46 | } |
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - protected static function processUpdate(string|stdClass|update $update = null): void { |
|
50 | + protected static function processUpdate(string | stdClass | update $update = null): void { |
|
51 | 51 | if (!is_object($update)) { |
52 | 52 | $update = json_decode($update ?? file_get_contents("php://input")); |
53 | 53 | if (!$update) { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - if (!is_a($update,'update')) { |
|
58 | + if (!is_a($update, 'update')) { |
|
59 | 59 | $update = new update($update); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | db::save(); |
67 | 67 | } |
68 | 68 | |
69 | - protected static function setMessageExtra (update &$update): void { |
|
69 | + protected static function setMessageExtra(update & $update): void { |
|
70 | 70 | if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) { |
71 | 71 | $type = isset($update->message) ? 'message' : 'edited_message'; |
72 | 72 | $text = &$update->$type->text; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | BPT::$handler->something_else(BPT::$update); |
140 | 140 | } |
141 | 141 | else { |
142 | - logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
|
142 | + logger::write('Update received but handlers does not set', loggerTypes::WARNING); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) { |
36 | 36 | $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; |
37 | 37 | } |
38 | - } |
|
39 | - elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
|
38 | + } elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
|
40 | 39 | $ip = $_SERVER['HTTP_AR_REAL_IP']; |
41 | 40 | } |
42 | 41 | |
@@ -94,51 +93,41 @@ discard block |
||
94 | 93 | if (self::handlerExist('message')) { |
95 | 94 | BPT::$handler->message(BPT::$update->message); |
96 | 95 | } |
97 | - } |
|
98 | - elseif (isset(BPT::$update->edited_message)) { |
|
96 | + } elseif (isset(BPT::$update->edited_message)) { |
|
99 | 97 | if (self::handlerExist('edited_message')) { |
100 | 98 | BPT::$handler->edited_message(BPT::$update->edited_message); |
101 | 99 | } |
102 | - } |
|
103 | - elseif (isset(BPT::$update->channel_post)) { |
|
100 | + } elseif (isset(BPT::$update->channel_post)) { |
|
104 | 101 | if (self::handlerExist('channel_post')) { |
105 | 102 | BPT::$handler->channel_post(BPT::$update->channel_post); |
106 | 103 | } |
107 | - } |
|
108 | - elseif (isset(BPT::$update->edited_channel_post)) { |
|
104 | + } elseif (isset(BPT::$update->edited_channel_post)) { |
|
109 | 105 | if (self::handlerExist('edited_channel_post')) { |
110 | 106 | BPT::$handler->edited_channel_post(BPT::$update->edited_channel_post); |
111 | 107 | } |
112 | - } |
|
113 | - elseif (isset(BPT::$update->inline_query)) { |
|
108 | + } elseif (isset(BPT::$update->inline_query)) { |
|
114 | 109 | if (self::handlerExist('inline_query')) { |
115 | 110 | BPT::$handler->inline_query(BPT::$update->inline_query); |
116 | 111 | } |
117 | - } |
|
118 | - elseif (isset(BPT::$update->callback_query)) { |
|
112 | + } elseif (isset(BPT::$update->callback_query)) { |
|
119 | 113 | if (self::handlerExist('callback_query')) { |
120 | 114 | BPT::$handler->callback_query(BPT::$update->callback_query); |
121 | 115 | } |
122 | - } |
|
123 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
116 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
124 | 117 | if (self::handlerExist('my_chat_member')) { |
125 | 118 | BPT::$handler->my_chat_member(BPT::$update->my_chat_member); |
126 | 119 | } |
127 | - } |
|
128 | - elseif (isset(BPT::$update->chat_member)) { |
|
120 | + } elseif (isset(BPT::$update->chat_member)) { |
|
129 | 121 | if (self::handlerExist('chat_member')) { |
130 | 122 | BPT::$handler->chat_member(BPT::$update->chat_member); |
131 | 123 | } |
132 | - } |
|
133 | - elseif (isset(BPT::$update->chat_join_request)) { |
|
124 | + } elseif (isset(BPT::$update->chat_join_request)) { |
|
134 | 125 | if (self::handlerExist('chat_join_request')) { |
135 | 126 | BPT::$handler->chat_join_request(BPT::$update->chat_join_request); |
136 | 127 | } |
137 | - } |
|
138 | - elseif (self::handlerExist('something_else')) { |
|
128 | + } elseif (self::handlerExist('something_else')) { |
|
139 | 129 | BPT::$handler->something_else(BPT::$update); |
140 | - } |
|
141 | - else { |
|
130 | + } else { |
|
142 | 131 | logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
143 | 132 | } |
144 | 133 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return bool|int |
37 | 37 | */ |
38 | - public static function save(string $name, string $data): bool|int { |
|
39 | - return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock",0640); |
|
38 | + public static function save(string $name, string $data): bool | int { |
|
39 | + return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock", 0640); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return bool|string |
48 | 48 | */ |
49 | - public static function read(string $name): bool|string { |
|
49 | + public static function read(string $name): bool | string { |
|
50 | 50 | return file_get_contents(settings::$name."$name.lock"); |
51 | 51 | } |
52 | 52 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return bool|int |
59 | 59 | */ |
60 | - public static function mtime(string $name): bool|int { |
|
60 | + public static function mtime(string $name): bool | int { |
|
61 | 61 | return filemtime(settings::$name."$name.lock"); |
62 | 62 | } |
63 | 63 |
@@ -2,12 +2,12 @@ |
||
2 | 2 | |
3 | 3 | namespace BPT; |
4 | 4 | |
5 | -use BPT\tools\{is,file,convert,generator,encrypt}; |
|
5 | +use BPT\tools\{is, file, convert, generator, encrypt}; |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * tools class , gather what ever you need |
9 | 9 | */ |
10 | -class tools{ |
|
10 | +class tools { |
|
11 | 11 | use is; |
12 | 12 | use file; |
13 | 13 | use convert; |
@@ -78,11 +78,9 @@ discard block |
||
78 | 78 | $value = 'bots_files/'.$value.'/'; |
79 | 79 | } |
80 | 80 | self::$$setting = $value; |
81 | - } |
|
82 | - catch (TypeError){ |
|
81 | + } catch (TypeError){ |
|
83 | 82 | logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
84 | - } |
|
85 | - catch (Error){ |
|
83 | + } catch (Error){ |
|
86 | 84 | logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
87 | 85 | } |
88 | 86 | } |
@@ -99,13 +97,11 @@ discard block |
||
99 | 97 | if (!empty(self::$receiver)) { |
100 | 98 | self::$receiver !== receiver::GETUPDATES ? webhook::init() : self::getUpdates(); |
101 | 99 | } |
102 | - } |
|
103 | - else { |
|
100 | + } else { |
|
104 | 101 | logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
105 | 102 | throw new bptException('TOKEN_NOT_TRUE'); |
106 | 103 | } |
107 | - } |
|
108 | - else { |
|
104 | + } else { |
|
109 | 105 | logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
110 | 106 | throw new bptException('TOKEN_NOT_FOUND'); |
111 | 107 | } |
@@ -159,8 +155,7 @@ discard block |
||
159 | 155 | private static function getUpdates(): void { |
160 | 156 | if (self::$handler) { |
161 | 157 | getUpdates::init(); |
162 | - } |
|
163 | - else { |
|
158 | + } else { |
|
164 | 159 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
165 | 160 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
166 | 161 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | public static int $log_size = 10; |
27 | 27 | |
28 | - public static string|CURLFile|null $certificate = null; |
|
28 | + public static string | CURLFile | null $certificate = null; |
|
29 | 29 | |
30 | 30 | public static bool $handler = true; |
31 | 31 | |
@@ -58,16 +58,16 @@ discard block |
||
58 | 58 | |
59 | 59 | public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query']; |
60 | 60 | |
61 | - public static array|null $db = ['type' => 'json']; |
|
61 | + public static array | null $db = ['type' => 'json']; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @internal Only for BPT self usage , Don't use it in your source! |
65 | 65 | */ |
66 | - public static function init (array|stdClass $settings): void { |
|
66 | + public static function init(array | stdClass $settings): void { |
|
67 | 67 | $settings = (array) $settings; |
68 | 68 | |
69 | 69 | foreach ($settings as $setting => $value) { |
70 | - try{ |
|
70 | + try { |
|
71 | 71 | if ($setting === 'name') { |
72 | 72 | if (!is_dir('bots_files')) { |
73 | 73 | mkdir('bots_files'); |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | } |
80 | 80 | self::$$setting = $value; |
81 | 81 | } |
82 | - catch (TypeError){ |
|
83 | - logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
|
82 | + catch (TypeError) { |
|
83 | + logger::write("$setting setting has wrong type , its set to default value", loggerTypes::WARNING); |
|
84 | 84 | } |
85 | - catch (Error){ |
|
86 | - logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
|
85 | + catch (Error) { |
|
86 | + logger::write("$setting setting is not one of library settings", loggerTypes::WARNING); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | else { |
104 | - logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
|
104 | + logger::write('token format is not right, check it and try again', loggerTypes::ERROR); |
|
105 | 105 | throw new bptException('TOKEN_NOT_TRUE'); |
106 | 106 | } |
107 | 107 | } |
108 | 108 | else { |
109 | - logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
|
109 | + logger::write('You must specify token parameter in settings', loggerTypes::ERROR); |
|
110 | 110 | throw new bptException('TOKEN_NOT_FOUND'); |
111 | 111 | } |
112 | 112 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public static function done(): void { |
118 | 118 | if (self::$logger) { |
119 | - $estimated = round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000,2); |
|
119 | + $estimated = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2); |
|
120 | 120 | $status_message = match (true) { |
121 | 121 | $estimated < 100 => 'Excellent', |
122 | 122 | $estimated < 500 => 'Very good', |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | if (self::$secure_folder) { |
149 | 149 | $address = explode('/', $_SERVER['REQUEST_URI']); |
150 | 150 | unset($address[count($address) - 1]); |
151 | - $address = implode('/', $address) . '/BPT.php'; |
|
151 | + $address = implode('/', $address).'/BPT.php'; |
|
152 | 152 | $text = "ErrorDocument 404 $address\nErrorDocument 403 $address\n Options -Indexes\n Order Deny,Allow\nDeny from all\nAllow from 127.0.0.1\n<Files *.php>\n Order Allow,Deny\n Allow from all\n</Files>"; |
153 | 153 | if (!file_exists('.htaccess') || filesize('.htaccess') != strlen($text)) { |
154 | 154 | file_put_contents('.htaccess', $text); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | getUpdates::init(); |
162 | 162 | } |
163 | 163 | else { |
164 | - logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
|
164 | + logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler', loggerTypes::ERROR); |
|
165 | 165 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
166 | 166 | } |
167 | 167 | } |