@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return bool |
| 22 | 22 | */ |
| 23 | - public static function isUsername (string $username): bool { |
|
| 23 | + public static function isUsername(string $username): bool { |
|
| 24 | 24 | $length = strlen($username); |
| 25 | 25 | return !str_contains($username, '__') && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username); |
| 26 | 26 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return bool |
| 39 | 39 | */ |
| 40 | - public static function ipInRange (string $ip, string $range): bool { |
|
| 40 | + public static function ipInRange(string $ip, string $range): bool { |
|
| 41 | 41 | if (!str_contains($range, '/')) { |
| 42 | 42 | $range .= '/32'; |
| 43 | 43 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | - public static function isTelegram (string $ip): bool { |
|
| 60 | + public static function isTelegram(string $ip): bool { |
|
| 61 | 61 | return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22'); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | - public static function isCloudFlare (string $ip): bool { |
|
| 75 | + public static function isCloudFlare(string $ip): bool { |
|
| 76 | 76 | $cf_ips = ['173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22', '103.31.4.0/22', '141.101.64.0/18', '108.162.192.0/18', '190.93.240.0/20', '188.114.96.0/20', '197.234.240.0/22', '198.41.128.0/17', '162.158.0.0/15', '104.16.0.0/12', '104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22']; |
| 77 | 77 | foreach ($cf_ips as $cf_ip) { |
| 78 | - if (self::ipInRange($ip,$cf_ip)) { |
|
| 78 | + if (self::ipInRange($ip, $cf_ip)) { |
|
| 79 | 79 | return true; |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - public static function isArvanCloud (string $ip): bool { |
|
| 96 | + public static function isArvanCloud(string $ip): bool { |
|
| 97 | 97 | $ar_ips = ['185.143.232.0/22', '92.114.16.80/28', '2.146.0.0/28', '46.224.2.32/29', '89.187.178.96/29', '195.181.173.128/29', '89.187.169.88/29', '188.229.116.16/29', '83.123.255.56/31', '164.138.128.28/31', '94.182.182.28/30', '185.17.115.176/30', '5.213.255.36/31', '138.128.139.144/29', '5.200.14.8/29', '188.122.68.224/29', '188.122.83.176/29', '213.179.217.16/29', '185.179.201.192/29', '43.239.139.192/29', '213.179.197.16/29', '213.179.201.192/29', '109.200.214.248/29', '138.128.141.16/29', '188.122.78.136/29', '213.179.211.32/29', '103.194.164.24/29', '185.50.105.136/29', '213.179.213.16/29', '162.244.52.120/29', '188.122.80.240/29', '109.200.195.64/29', '109.200.199.224/29', '185.228.238.0/28', '94.182.153.24/29', '94.101.182.0/27', '37.152.184.208/28', '78.39.156.192/28', '158.255.77.238/31', '81.12.28.16/29', '176.65.192.202/31', '2.144.3.128/28', '89.45.48.64/28', '37.32.16.0/27', '37.32.17.0/27', '37.32.18.0/27']; |
| 98 | 98 | foreach ($ar_ips as $ar_ip) { |
| 99 | - if (self::ipInRange($ip,$ar_ip)) { |
|
| 99 | + if (self::ipInRange($ip, $ar_ip)) { |
|
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return bool|user return array when verify is active and token is true array of telegram getMe result |
| 118 | 118 | */ |
| 119 | - public static function isToken (string $token, bool $verify = false): bool|user { |
|
| 119 | + public static function isToken(string $token, bool $verify = false): bool | user { |
|
| 120 | 120 | if (preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) { |
| 121 | - if ($verify){ |
|
| 121 | + if ($verify) { |
|
| 122 | 122 | $res = telegram::me($token); |
| 123 | 123 | if (telegram::$status) { |
| 124 | 124 | return $res; |
@@ -150,14 +150,14 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool { |
|
| 153 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool { |
|
| 154 | 154 | if (!is_array($ids)) { |
| 155 | 155 | $ids = [$ids]; |
| 156 | 156 | } |
| 157 | 157 | $user_id = $user_id ?? request::catchFields('user_id'); |
| 158 | 158 | |
| 159 | 159 | foreach ($ids as $id) { |
| 160 | - $check = telegram::getChatMember($id,$user_id); |
|
| 160 | + $check = telegram::getChatMember($id, $user_id); |
|
| 161 | 161 | if (telegram::$status) { |
| 162 | 162 | $check = $check->status; |
| 163 | 163 | if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) { |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return array keys will be id and values will be bool(null for not founded ids) |
| 186 | 186 | */ |
| 187 | - public static function joinChecker (array|string|int $ids , int|null $user_id = null): array { |
|
| 187 | + public static function joinChecker(array | string | int $ids, int | null $user_id = null): array { |
|
| 188 | 188 | if (!is_array($ids)) { |
| 189 | 189 | $ids = [$ids]; |
| 190 | 190 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | $result = []; |
| 194 | 194 | foreach ($ids as $id) { |
| 195 | - $check = telegram::getChatMember($id,$user_id); |
|
| 195 | + $check = telegram::getChatMember($id, $user_id); |
|
| 196 | 196 | if (telegram::$status) { |
| 197 | 197 | $check = $check->status; |
| 198 | 198 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
@@ -212,6 +212,6 @@ discard block |
||
| 212 | 212 | * @return bool |
| 213 | 213 | */ |
| 214 | 214 | public static function isShorted(string $text): bool{ |
| 215 | - return preg_match('/^[a-zA-Z0-9]+$/',$text); |
|
| 215 | + return preg_match('/^[a-zA-Z0-9]+$/', $text); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | \ No newline at end of file |
@@ -21,10 +21,10 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @return string |
| 23 | 23 | */ |
| 24 | - public static function byteFormat (int $byte, int $precision = 2): string { |
|
| 24 | + public static function byteFormat(int $byte, int $precision = 2): string { |
|
| 25 | 25 | $rate_counter = 0; |
| 26 | 26 | |
| 27 | - while ($byte > 1024){ |
|
| 27 | + while ($byte > 1024) { |
|
| 28 | 28 | $byte /= 1024; |
| 29 | 29 | $rate_counter++; |
| 30 | 30 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $byte = round($byte, $precision); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 36 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string|false return false when mode is incorrect |
| 52 | 52 | */ |
| 53 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
| 53 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
| 54 | 54 | return match ($mode) { |
| 55 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
| 56 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
| 55 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
| 56 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
| 57 | 57 | parseMode::MARKDOWNV2 => str_replace( |
| 58 | 58 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
| 59 | 59 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
| 93 | 93 | * @throws Exception |
| 94 | 94 | */ |
| 95 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
| 95 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
| 96 | 96 | if (!isset($base_time)) { |
| 97 | 97 | $base_time = '@'.time(); |
| 98 | 98 | } |
| 99 | 99 | $base_time = new DateTime($base_time); |
| 100 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
| 100 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
| 101 | 101 | |
| 102 | 102 | $diff = $base_time->diff($target_time); |
| 103 | 103 | |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @return string[]|string |
| 126 | 126 | */ |
| 127 | - public static function realEscapeString(string|array $input): string|array { |
|
| 128 | - if(is_array($input)) { |
|
| 127 | + public static function realEscapeString(string | array $input): string | array { |
|
| 128 | + if (is_array($input)) { |
|
| 129 | 129 | return array_map(__METHOD__, $input); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if(!empty($input) && is_string($input)) { |
|
| 132 | + if (!empty($input) && is_string($input)) { |
|
| 133 | 133 | return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @return string[]|string |
| 149 | 149 | */ |
| 150 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
| 150 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
| 151 | 151 | $pos = strpos($subject, $search); |
| 152 | 152 | if ($pos !== false) { |
| 153 | 153 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -17,7 +17,7 @@ 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 (int $log_size = 10): void { |
|
| 20 | + public static function init(int $log_size = 10): void { |
|
| 21 | 21 | self::$log_size = $log_size; |
| 22 | 22 | if (file_exists(settings::$name.'BPT.log') && !(filesize(settings::$name.'BPT.log') > self::$log_size * 1024 * 1024)) { |
| 23 | 23 | $mode = 'a'; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | self::$handler = fopen(settings::$name.'BPT.log', $mode); |
| 31 | 31 | |
| 32 | 32 | if ($write) { |
| 33 | - fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 33 | + fwrite(self::$handler, "♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if (self::$waited_logs != []) { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | 53 | public static function write(string $data, string $type = loggerTypes::NONE): void { |
| 54 | - $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" ); |
|
| 54 | + $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n"); |
|
| 55 | 55 | if (!is_null(self::$handler)) { |
| 56 | 56 | fwrite(self::$handler, $text); |
| 57 | 57 | } |
@@ -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,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']) |
@@ -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 | } |
@@ -14,25 +14,25 @@ discard block |
||
| 14 | 14 | * getUpdates class , For receiving updates by polling methods |
| 15 | 15 | */ |
| 16 | 16 | class getUpdates extends receiver { |
| 17 | - public static function init () { |
|
| 17 | + public static function init() { |
|
| 18 | 18 | $last_update_id = self::loadData(); |
| 19 | - while(true) { |
|
| 19 | + while (true) { |
|
| 20 | 20 | if (!lock::exist('getUpdate')) { |
| 21 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates); |
|
| 21 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates); |
|
| 22 | 22 | if (telegram::$status) { |
| 23 | 23 | self::handleUpdates($updates); |
| 24 | - lock::save('getUpdate',BPT::$update->update_id+1); |
|
| 25 | - $last_update_id = BPT::$update->update_id+1; |
|
| 24 | + lock::save('getUpdate', BPT::$update->update_id + 1); |
|
| 25 | + $last_update_id = BPT::$update->update_id + 1; |
|
| 26 | 26 | } |
| 27 | 27 | else { |
| 28 | - logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
|
| 29 | - BPT::exit(print_r($updates,true)); |
|
| 28 | + logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR); |
|
| 29 | + BPT::exit(print_r($updates, true)); |
|
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - private static function loadData(): bool|int|string { |
|
| 35 | + private static function loadData(): bool | int | string { |
|
| 36 | 36 | if (lock::exist('getUpdate')) { |
| 37 | 37 | $last_update_id = lock::read('getUpdate'); |
| 38 | 38 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | self::deleteOldLocks(); |
| 41 | 41 | telegram::deleteWebhook(); |
| 42 | 42 | $last_update_id = 0; |
| 43 | - lock::save('getUpdate',0); |
|
| 43 | + lock::save('getUpdate', 0); |
|
| 44 | 44 | } |
| 45 | 45 | return $last_update_id; |
| 46 | 46 | } |
@@ -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 | |