@@ -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(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\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)); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | private static $handler; |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - public static function init (int $log_size = 10): void { |
|
| 15 | + public static function init(int $log_size = 10): void { |
|
| 16 | 16 | self::$log_size = $log_size; |
| 17 | 17 | if (file_exists(settings::$name.'BPT.log') && !(filesize(settings::$name.'BPT.log') > self::$log_size * 1024 * 1024)) { |
| 18 | 18 | $mode = 'a'; |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | self::$handler = fopen(settings::$name.'BPT.log', $mode); |
| 26 | 26 | |
| 27 | 27 | if ($write) { |
| 28 | - 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"); |
|
| 28 | + 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"); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | if (self::$waited_logs != []) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public static function write(string $data, string $type = loggerTypes::NONE): void { |
| 39 | - $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" ); |
|
| 39 | + $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n"); |
|
| 40 | 40 | if (!is_null(self::$handler)) { |
| 41 | 41 | fwrite(self::$handler, $text); |
| 42 | 42 | } |
@@ -10,17 +10,17 @@ discard block |
||
| 10 | 10 | class curl { |
| 11 | 11 | private static CurlHandle $curl_handler; |
| 12 | 12 | |
| 13 | - public static function init(string $method,array $data) { |
|
| 13 | + public static function init(string $method, array $data) { |
|
| 14 | 14 | $info = self::getInfo($data); |
| 15 | 15 | $data = $info['data']; |
| 16 | 16 | $handler = $info['handler']; |
| 17 | - self::setTimeout($data,$handler,$method); |
|
| 17 | + self::setTimeout($data, $handler, $method); |
|
| 18 | 18 | self::setData($data); |
| 19 | 19 | $data['method'] = $method; |
| 20 | 20 | curl_setopt($handler, CURLOPT_POSTFIELDS, $data); |
| 21 | 21 | $result = curl_exec($handler); |
| 22 | 22 | if (curl_errno($handler)) { |
| 23 | - logger::write(curl_error($handler),loggerTypes::WARNING); |
|
| 23 | + logger::write(curl_error($handler), loggerTypes::WARNING); |
|
| 24 | 24 | } |
| 25 | 25 | if ($info['token'] != settings::$token) { |
| 26 | 26 | curl_close($handler); |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 37 | 37 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 38 | 38 | } |
| 39 | - else{ |
|
| 39 | + else { |
|
| 40 | 40 | $token = settings::$token; |
| 41 | - if (!isset(self::$curl_handler)){ |
|
| 41 | + if (!isset(self::$curl_handler)) { |
|
| 42 | 42 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
| 43 | 43 | curl_setopt(self::$curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 44 | 44 | curl_setopt(self::$curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
@@ -54,22 +54,22 @@ discard block |
||
| 54 | 54 | ]; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - private static function setTimeout(array &$data , CurlHandle $curl_handler,string $method): void { |
|
| 57 | + private static function setTimeout(array &$data, CurlHandle $curl_handler, string $method): void { |
|
| 58 | 58 | if (isset($data['forgot'])) { |
| 59 | 59 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 60 | 60 | unset($data['forgot']); |
| 61 | 61 | } |
| 62 | - elseif ($method === 'getUpdates'){ |
|
| 62 | + elseif ($method === 'getUpdates') { |
|
| 63 | 63 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 64 | 64 | } |
| 65 | - else{ |
|
| 65 | + else { |
|
| 66 | 66 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300); |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | private static function setData(array &$data): void { |
| 71 | - foreach ($data as &$value){ |
|
| 72 | - if (is_array($value) || (is_object($value) && !is_a($value,'CURLFile'))){ |
|
| 71 | + foreach ($data as &$value) { |
|
| 72 | + if (is_array($value) || (is_object($value) && !is_a($value, 'CURLFile'))) { |
|
| 73 | 73 | $value = json_encode($value); |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -11,15 +11,15 @@ |
||
| 11 | 11 | return touch(settings::$name."$name.lock"); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function save(string $name, string $data): bool|int { |
|
| 15 | - return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock",0640); |
|
| 14 | + public static function save(string $name, string $data): bool | int { |
|
| 15 | + return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$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(settings::$name."$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(settings::$name."$name.lock"); |
| 24 | 24 | } |
| 25 | 25 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public static int $log_size = 10; |
| 25 | 25 | |
| 26 | - public static string|CURLFile|null $certificate = null; |
|
| 26 | + public static string | CURLFile | null $certificate = null; |
|
| 27 | 27 | |
| 28 | 28 | public static bool $handler = true; |
| 29 | 29 | |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query']; |
| 53 | 53 | |
| 54 | - public static array|mysqli|null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json']; |
|
| 54 | + public static array | mysqli | null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json']; |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - public static function init (array|stdClass $settings): void { |
|
| 57 | + public static function init(array | stdClass $settings): void { |
|
| 58 | 58 | $settings = (array) $settings; |
| 59 | 59 | |
| 60 | 60 | foreach ($settings as $setting => $value) { |
| 61 | - try{ |
|
| 61 | + try { |
|
| 62 | 62 | if ($setting === 'name') { |
| 63 | 63 | if (!is_dir('bots_files')) { |
| 64 | 64 | mkdir('bots_files'); |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | self::$$setting = $value; |
| 72 | 72 | } |
| 73 | - catch (TypeError){ |
|
| 74 | - logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
|
| 73 | + catch (TypeError) { |
|
| 74 | + logger::write("$setting setting has wrong type , its set to default value", loggerTypes::WARNING); |
|
| 75 | 75 | } |
| 76 | - catch (Error){ |
|
| 77 | - logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
|
| 76 | + catch (Error) { |
|
| 77 | + logger::write("$setting setting is not one of library settings", loggerTypes::WARNING); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -92,19 +92,19 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | else { |
| 95 | - logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
|
| 95 | + logger::write('token format is not right, check it and try again', loggerTypes::ERROR); |
|
| 96 | 96 | throw new bptException('TOKEN_NOT_TRUE'); |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | else { |
| 100 | - logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
|
| 100 | + logger::write('You must specify token parameter in settings', loggerTypes::ERROR); |
|
| 101 | 101 | throw new bptException('TOKEN_NOT_FOUND'); |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | public static function done(): void { |
| 106 | 106 | if (self::$logger) { |
| 107 | - $estimated = round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000,2); |
|
| 107 | + $estimated = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2); |
|
| 108 | 108 | $status_message = match (true) { |
| 109 | 109 | $estimated < 100 => 'Excellent', |
| 110 | 110 | $estimated < 500 => 'Very good', |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | if (self::$secure_folder) { |
| 137 | 137 | $address = explode('/', $_SERVER['REQUEST_URI']); |
| 138 | 138 | unset($address[count($address) - 1]); |
| 139 | - $address = implode('/', $address) . '/BPT.php'; |
|
| 139 | + $address = implode('/', $address).'/BPT.php'; |
|
| 140 | 140 | $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>"; |
| 141 | 141 | if (!file_exists('.htaccess') || filesize('.htaccess') != strlen($text)) { |
| 142 | 142 | file_put_contents('.htaccess', $text); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | getUpdates::init(); |
| 156 | 156 | } |
| 157 | 157 | else { |
| 158 | - logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
|
| 158 | + logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler', loggerTypes::ERROR); |
|
| 159 | 159 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | use JetBrains\PhpStorm\ArrayShape; |
| 12 | 12 | |
| 13 | 13 | class exec extends webhook { |
| 14 | - public static function init(): string|null { |
|
| 14 | + public static function init(): string | null { |
|
| 15 | 15 | return self::getUpdate(); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - private static function getUpdate (): string|null { |
|
| 18 | + private static function getUpdate(): string | null { |
|
| 19 | 19 | $up = glob('*.update'); |
| 20 | 20 | if (isset($up[0])) { |
| 21 | 21 | $up = end($up); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | return $update; |
| 27 | 27 | } |
| 28 | 28 | else { |
| 29 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
| 29 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
| 30 | 30 | BPT::exit(); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | private static function create($file) { |
| 49 | - 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 &");'); |
|
| 49 | + 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 &");'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | private static function setURLS(): array { |
| 53 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 53 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 54 | 54 | return [ |
| 55 | 55 | 'url'=>str_replace(basename($_SERVER['REQUEST_URI']), 'receiver.php', $base_url), |
| 56 | 56 | 'file'=>basename($_SERVER['SCRIPT_NAME']) |
@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | use JetBrains\PhpStorm\ArrayShape; |
| 12 | 12 | |
| 13 | 13 | class curl extends webhook { |
| 14 | - public static function init (): string|null { |
|
| 14 | + public static function init(): string | null { |
|
| 15 | 15 | if (self::checkIP()) { |
| 16 | 16 | return self::getUpdate(); |
| 17 | 17 | } |
| 18 | 18 | else { |
| 19 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
| 19 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
| 20 | 20 | BPT::exit(); |
| 21 | 21 | } |
| 22 | 22 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - private static function getUpdate (): string { |
|
| 28 | + private static function getUpdate(): string { |
|
| 29 | 29 | $input = json_decode(file_get_contents("php://input"), true); |
| 30 | 30 | webhook::telegramVerify($input['ip']); |
| 31 | 31 | return $input['update']; |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | $urls = self::setURLS(); |
| 36 | 36 | $file = $urls['file']; |
| 37 | 37 | $timeout = self::getTimeout($file); |
| 38 | - self::create($file,$timeout); |
|
| 38 | + self::create($file, $timeout); |
|
| 39 | 39 | self::setWebhook($urls['url']); |
| 40 | 40 | lock::set('BPT-MULTI-CURL'); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - private static function getTimeout($url): float|int { |
|
| 43 | + private static function getTimeout($url): float | int { |
|
| 44 | 44 | $times = []; |
| 45 | - for ($i = 0; $i < 10; $i ++) { |
|
| 45 | + for ($i = 0; $i < 10; $i++) { |
|
| 46 | 46 | $ch = curl_init($url); |
| 47 | 47 | 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']]); |
| 48 | 48 | $start = microtime(true); |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | return $timeout > 50 ? $timeout + 10 : 50; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - private static function create($file,$timeout) { |
|
| 57 | - 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);?>'); |
|
| 56 | + private static function create($file, $timeout) { |
|
| 57 | + 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);?>'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | private static function setURLS(): array { |
| 61 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 61 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 62 | 62 | $file = basename($_SERVER['REQUEST_URI']); |
| 63 | 63 | return [ |
| 64 | 64 | 'url'=>str_replace($file, 'receiver.php', $base_url), |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | protected static function telegramVerify(string $ip = null): void { |
| 23 | 23 | if (settings::$telegram_verify) { |
| 24 | 24 | if (!tools::isTelegram($ip ?? $_SERVER['REMOTE_ADDR'] ?? '')) { |
| 25 | - logger::write('not authorized access denied. IP : '. $ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
| 25 | + logger::write('not authorized access denied. IP : '.$ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
| 26 | 26 | BPT::exit(); |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - protected static function processUpdate(string|stdClass|update $update = null): void { |
|
| 31 | + protected static function processUpdate(string | stdClass | update $update = null): void { |
|
| 32 | 32 | if (!is_object($update)) { |
| 33 | 33 | $update = json_decode($update ?? file_get_contents("php://input")); |
| 34 | 34 | if (!$update) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if (!is_a($update,'update')) { |
|
| 39 | + if (!is_a($update, 'update')) { |
|
| 40 | 40 | $update = new update($update); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | self::processHandler(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - protected static function setMessageExtra (update &$update): void { |
|
| 48 | + protected static function setMessageExtra(update & $update): void { |
|
| 49 | 49 | if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) { |
| 50 | 50 | $type = isset($update->message) ? 'message' : 'edited_message'; |
| 51 | 51 | $text = &$update->$type->text; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | BPT::$handler->something_else(BPT::$update); |
| 94 | 94 | } |
| 95 | 95 | else { |
| 96 | - logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
|
| 96 | + logger::write('Update received but handlers does not set', loggerTypes::WARNING); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -11,25 +11,25 @@ discard block |
||
| 11 | 11 | use BPT\types\update; |
| 12 | 12 | |
| 13 | 13 | class getUpdates extends receiver { |
| 14 | - public static function init () { |
|
| 14 | + public static function init() { |
|
| 15 | 15 | $last_update_id = self::loadData(); |
| 16 | - while(true) { |
|
| 16 | + while (true) { |
|
| 17 | 17 | if (!lock::exist('getUpdate')) { |
| 18 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates); |
|
| 18 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates); |
|
| 19 | 19 | if (telegram::$status) { |
| 20 | 20 | self::handleUpdates($updates); |
| 21 | - lock::save('getUpdate',BPT::$update->update_id+1); |
|
| 22 | - $last_update_id = BPT::$update->update_id+1; |
|
| 21 | + lock::save('getUpdate', BPT::$update->update_id + 1); |
|
| 22 | + $last_update_id = BPT::$update->update_id + 1; |
|
| 23 | 23 | } |
| 24 | 24 | else { |
| 25 | - logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
|
| 26 | - BPT::exit(print_r($updates,true)); |
|
| 25 | + logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR); |
|
| 26 | + BPT::exit(print_r($updates, true)); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - private static function loadData(): bool|int|string { |
|
| 32 | + private static function loadData(): bool | int | string { |
|
| 33 | 33 | if (lock::exist('getUpdate')) { |
| 34 | 34 | $last_update_id = lock::read('getUpdate'); |
| 35 | 35 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | self::deleteOldLocks(); |
| 38 | 38 | telegram::deleteWebhook(); |
| 39 | 39 | $last_update_id = 0; |
| 40 | - lock::save('getUpdate',0); |
|
| 40 | + lock::save('getUpdate', 0); |
|
| 41 | 41 | } |
| 42 | 42 | return $last_update_id; |
| 43 | 43 | } |