@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public static int $log_size = 10; |
| 23 | 23 | |
| 24 | - public static string|CURLFile|null $certificate = null; |
|
| 24 | + public static string | CURLFile | null $certificate = null; |
|
| 25 | 25 | |
| 26 | 26 | public static bool $handler = true; |
| 27 | 27 | |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query']; |
| 47 | 47 | |
| 48 | - public static array|mysqli|null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json']; |
|
| 48 | + public static array | mysqli | null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json']; |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - public static function init (array|stdClass $settings) { |
|
| 51 | + public static function init(array | stdClass $settings) { |
|
| 52 | 52 | $settings = (array) $settings; |
| 53 | 53 | |
| 54 | 54 | if (!(isset($settings['logger']) && $settings['logger'] == false)) { |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | foreach ($settings as $setting => $value) { |
| 59 | - try{ |
|
| 59 | + try { |
|
| 60 | 60 | self::$$setting = $value; |
| 61 | 61 | } |
| 62 | - catch (TypeError){ |
|
| 63 | - logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
|
| 62 | + catch (TypeError) { |
|
| 63 | + logger::write("$setting setting has wrong type , its set to default value", loggerTypes::WARNING); |
|
| 64 | 64 | } |
| 65 | - catch (Error){ |
|
| 66 | - logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
|
| 65 | + catch (Error) { |
|
| 66 | + logger::write("$setting setting is not one of library settings", loggerTypes::WARNING); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | else { |
| 80 | - logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
|
| 80 | + logger::write('token format is not right, check it and try again', loggerTypes::ERROR); |
|
| 81 | 81 | throw new bptException('TOKEN_NOT_TRUE'); |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | else { |
| 85 | - logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
|
| 85 | + logger::write('You must specify token parameter in settings', loggerTypes::ERROR); |
|
| 86 | 86 | throw new bptException('TOKEN_NOT_FOUND'); |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public static function done() { |
| 91 | 91 | if (self::$logger) { |
| 92 | - $estimated = round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000,2); |
|
| 92 | + $estimated = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2); |
|
| 93 | 93 | $status_message = match (true) { |
| 94 | 94 | $estimated < 100 => 'Excellent', |
| 95 | 95 | $estimated < 500 => 'Very good', |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | if (self::$secure_folder) { |
| 122 | 122 | $address = explode('/', $_SERVER['REQUEST_URI']); |
| 123 | 123 | unset($address[count($address) - 1]); |
| 124 | - $address = implode('/', $address) . '/BPT.php'; |
|
| 124 | + $address = implode('/', $address).'/BPT.php'; |
|
| 125 | 125 | $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>"; |
| 126 | 126 | if (!file_exists('.htaccess') || filesize('.htaccess') != strlen($text)) { |
| 127 | 127 | file_put_contents('.htaccess', $text); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | getUpdates::init(); |
| 141 | 141 | } |
| 142 | 142 | else { |
| 143 | - logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
|
| 143 | + logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler', loggerTypes::ERROR); |
|
| 144 | 144 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -58,11 +58,9 @@ discard block |
||
| 58 | 58 | foreach ($settings as $setting => $value) { |
| 59 | 59 | try{ |
| 60 | 60 | self::$$setting = $value; |
| 61 | - } |
|
| 62 | - catch (TypeError){ |
|
| 61 | + } catch (TypeError){ |
|
| 63 | 62 | logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
| 64 | - } |
|
| 65 | - catch (Error){ |
|
| 63 | + } catch (Error){ |
|
| 66 | 64 | logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
| 67 | 65 | } |
| 68 | 66 | } |
@@ -75,13 +73,11 @@ discard block |
||
| 75 | 73 | if (!empty(self::$receiver)) { |
| 76 | 74 | self::$receiver !== receiver::GETUPDATES ? self::webhook() : self::getUpdates(); |
| 77 | 75 | } |
| 78 | - } |
|
| 79 | - else { |
|
| 76 | + } else { |
|
| 80 | 77 | logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
| 81 | 78 | throw new bptException('TOKEN_NOT_TRUE'); |
| 82 | 79 | } |
| 83 | - } |
|
| 84 | - else { |
|
| 80 | + } else { |
|
| 85 | 81 | logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
| 86 | 82 | throw new bptException('TOKEN_NOT_FOUND'); |
| 87 | 83 | } |
@@ -138,8 +134,7 @@ discard block |
||
| 138 | 134 | private static function getUpdates() { |
| 139 | 135 | if (self::$handler) { |
| 140 | 136 | getUpdates::init(); |
| 141 | - } |
|
| 142 | - else { |
|
| 137 | + } else { |
|
| 143 | 138 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
| 144 | 139 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
| 145 | 140 | } |
@@ -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 | |
@@ -10,11 +10,11 @@ discard block |
||
| 10 | 10 | use BPT\settings; |
| 11 | 11 | |
| 12 | 12 | class exec extends webhook { |
| 13 | - public static function init(): string|null { |
|
| 13 | + public static function init(): string | null { |
|
| 14 | 14 | return self::getUpdate(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - private static function getUpdate (): string|null { |
|
| 17 | + private static function getUpdate(): string | null { |
|
| 18 | 18 | $up = glob('*.update'); |
| 19 | 19 | if (isset($up[0])) { |
| 20 | 20 | $up = end($up); |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return $update; |
| 26 | 26 | } |
| 27 | 27 | else { |
| 28 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
| 28 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
| 29 | 29 | BPT::exit(); |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | private static function create($file) { |
| 48 | - 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 &");'); |
|
| 48 | + 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 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function setURLS(): array { |
| 52 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 52 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 53 | 53 | return [ |
| 54 | 54 | 'url'=>str_replace(basename($_SERVER['REQUEST_URI']), 'receiver.php', $base_url), |
| 55 | 55 | 'file'=>basename($_SERVER['SCRIPT_NAME']) |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | $update = file_get_contents($up); |
| 24 | 24 | unlink($up); |
| 25 | 25 | return $update; |
| 26 | - } |
|
| 27 | - else { |
|
| 26 | + } else { |
|
| 28 | 27 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
| 29 | 28 | BPT::exit(); |
| 30 | 29 | } |
@@ -10,12 +10,12 @@ discard block |
||
| 10 | 10 | use BPT\settings; |
| 11 | 11 | |
| 12 | 12 | class curl extends webhook { |
| 13 | - public static function init (): string|null { |
|
| 13 | + public static function init(): string | null { |
|
| 14 | 14 | if (self::checkIP()) { |
| 15 | 15 | return self::getUpdate(); |
| 16 | 16 | } |
| 17 | 17 | else { |
| 18 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
| 18 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
| 19 | 19 | BPT::exit(); |
| 20 | 20 | } |
| 21 | 21 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - private static function getUpdate (): string { |
|
| 27 | + private static function getUpdate(): string { |
|
| 28 | 28 | $input = json_decode(file_get_contents("php://input"), true); |
| 29 | 29 | webhook::telegramVerify($input['ip']); |
| 30 | 30 | return $input['update']; |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | $urls = self::setURLS(); |
| 35 | 35 | $file = $urls['file']; |
| 36 | 36 | $timeout = self::getTimeout($file); |
| 37 | - self::create($file,$timeout); |
|
| 37 | + self::create($file, $timeout); |
|
| 38 | 38 | self::setWebhook($urls['url']); |
| 39 | 39 | lock::set('BPT-MULTI-CURL'); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - private static function getTimeout($url): float|int { |
|
| 42 | + private static function getTimeout($url): float | int { |
|
| 43 | 43 | $times = []; |
| 44 | - for ($i = 0; $i < 10; $i ++) { |
|
| 44 | + for ($i = 0; $i < 10; $i++) { |
|
| 45 | 45 | $ch = curl_init($url); |
| 46 | 46 | 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']]); |
| 47 | 47 | $start = microtime(true); |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | return $timeout > 50 ? $timeout + 10 : 50; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private static function create($file,$timeout) { |
|
| 56 | - 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);?>'); |
|
| 55 | + private static function create($file, $timeout) { |
|
| 56 | + 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);?>'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | private static function setURLS(): array { |
| 60 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 60 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 61 | 61 | $file = basename($_SERVER['REQUEST_URI']); |
| 62 | 62 | return [ |
| 63 | 63 | 'url'=>str_replace($file, 'receiver.php', $base_url), |
@@ -13,8 +13,7 @@ |
||
| 13 | 13 | public static function init (): string|null { |
| 14 | 14 | if (self::checkIP()) { |
| 15 | 15 | return self::getUpdate(); |
| 16 | - } |
|
| 17 | - else { |
|
| 16 | + } else { |
|
| 18 | 17 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
| 19 | 18 | BPT::exit(); |
| 20 | 19 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | if (lock::exist('BPT-MULTI-EXEC')) { |
| 14 | 14 | self::setUpdate(exec::init()); |
| 15 | 15 | } |
| 16 | - elseif(lock::exist('BPT-MULTI-CURL')) { |
|
| 16 | + elseif (lock::exist('BPT-MULTI-CURL')) { |
|
| 17 | 17 | self::setUpdate(curl::init()); |
| 18 | 18 | } |
| 19 | 19 | else { |
@@ -12,11 +12,9 @@ |
||
| 12 | 12 | public static function init() { |
| 13 | 13 | if (lock::exist('BPT-MULTI-EXEC')) { |
| 14 | 14 | self::setUpdate(exec::init()); |
| 15 | - } |
|
| 16 | - elseif(lock::exist('BPT-MULTI-CURL')) { |
|
| 15 | + } elseif(lock::exist('BPT-MULTI-CURL')) { |
|
| 17 | 16 | self::setUpdate(curl::init()); |
| 18 | - } |
|
| 19 | - else { |
|
| 17 | + } else { |
|
| 20 | 18 | self::deleteOldLocks(); |
| 21 | 19 | self::checkURL(); |
| 22 | 20 | self::setCertificate(); |
@@ -22,20 +22,20 @@ discard block |
||
| 22 | 22 | protected static function telegramVerify(string $ip = null) { |
| 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) { |
|
| 31 | + protected static function processUpdate(string | stdClass | update $update = null) { |
|
| 32 | 32 | if (!is_object($update)) { |
| 33 | 33 | $update = json_decode($update ?? file_get_contents("php://input")); |
| 34 | 34 | if (!$update) { |
| 35 | 35 | BPT::exit(); |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | - elseif (!is_a($update,'update')) { |
|
| 38 | + elseif (!is_a($update, 'update')) { |
|
| 39 | 39 | $update = new update($update); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | self::processHandler(); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - protected static function setMessageExtra (update &$update) { |
|
| 47 | + protected static function setMessageExtra(update & $update) { |
|
| 48 | 48 | if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) { |
| 49 | 49 | $type = isset($update->message) ? 'message' : 'edited_message'; |
| 50 | 50 | $text = &$update->$type->text; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | BPT::$handler->something_else(BPT::$update); |
| 93 | 93 | } |
| 94 | 94 | else { |
| 95 | - logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
|
| 95 | + logger::write('Update received but handlers does not set', loggerTypes::WARNING); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -34,8 +34,7 @@ discard block |
||
| 34 | 34 | if (!$update) { |
| 35 | 35 | BPT::exit(); |
| 36 | 36 | } |
| 37 | - } |
|
| 38 | - elseif (!is_a($update,'update')) { |
|
| 37 | + } elseif (!is_a($update,'update')) { |
|
| 39 | 38 | $update = new update($update); |
| 40 | 39 | } |
| 41 | 40 | |
@@ -72,26 +71,21 @@ discard block |
||
| 72 | 71 | if (self::handlerExist('message')) { |
| 73 | 72 | BPT::$handler->message(BPT::$update->message); |
| 74 | 73 | } |
| 75 | - } |
|
| 76 | - elseif (isset(BPT::$update->callback_query)) { |
|
| 74 | + } elseif (isset(BPT::$update->callback_query)) { |
|
| 77 | 75 | if (self::handlerExist('callback_query')) { |
| 78 | 76 | BPT::$handler->callback_query(BPT::$update->callback_query); |
| 79 | 77 | } |
| 80 | - } |
|
| 81 | - elseif (isset(BPT::$update->inline_query)) { |
|
| 78 | + } elseif (isset(BPT::$update->inline_query)) { |
|
| 82 | 79 | if (self::handlerExist('inline_query')) { |
| 83 | 80 | BPT::$handler->inline_query(BPT::$update->inline_query); |
| 84 | 81 | } |
| 85 | - } |
|
| 86 | - elseif (isset(BPT::$update->edited_message)) { |
|
| 82 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 87 | 83 | if (self::handlerExist('edited_message')) { |
| 88 | 84 | BPT::$handler->edited_message(BPT::$update->edited_message); |
| 89 | 85 | } |
| 90 | - } |
|
| 91 | - elseif (self::handlerExist('something_else')) { |
|
| 86 | + } elseif (self::handlerExist('something_else')) { |
|
| 92 | 87 | BPT::$handler->something_else(BPT::$update); |
| 93 | - } |
|
| 94 | - else { |
|
| 88 | + } else { |
|
| 95 | 89 | logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
| 96 | 90 | } |
| 97 | 91 | } |
@@ -13,25 +13,25 @@ discard block |
||
| 13 | 13 | use stdClass; |
| 14 | 14 | |
| 15 | 15 | class getUpdates extends receiver { |
| 16 | - public static function init () { |
|
| 16 | + public static function init() { |
|
| 17 | 17 | $last_update_id = self::loadData(); |
| 18 | - while(true) { |
|
| 18 | + while (true) { |
|
| 19 | 19 | if (!lock::exist('getUpdate')) { |
| 20 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates); |
|
| 20 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates); |
|
| 21 | 21 | if (telegram::$status) { |
| 22 | 22 | self::handleUpdates($updates); |
| 23 | - lock::save('getUpdate',BPT::$update->update_id+1); |
|
| 24 | - $last_update_id = BPT::$update->update_id+1; |
|
| 23 | + lock::save('getUpdate', BPT::$update->update_id + 1); |
|
| 24 | + $last_update_id = BPT::$update->update_id + 1; |
|
| 25 | 25 | } |
| 26 | 26 | else { |
| 27 | - logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
|
| 28 | - BPT::exit(print_r($updates,true)); |
|
| 27 | + logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR); |
|
| 28 | + BPT::exit(print_r($updates, true)); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - private static function loadData(): bool|int|string { |
|
| 34 | + private static function loadData(): bool | int | string { |
|
| 35 | 35 | if (lock::exist('getUpdate')) { |
| 36 | 36 | $last_update_id = lock::read('getUpdate'); |
| 37 | 37 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | self::deleteOldLocks(); |
| 40 | 40 | telegram::deleteWebhook(); |
| 41 | 41 | $last_update_id = 0; |
| 42 | - lock::save('getUpdate',0); |
|
| 42 | + lock::save('getUpdate', 0); |
|
| 43 | 43 | } |
| 44 | 44 | return $last_update_id; |
| 45 | 45 | } |
@@ -22,8 +22,7 @@ discard block |
||
| 22 | 22 | self::handleUpdates($updates); |
| 23 | 23 | lock::save('getUpdate',BPT::$update->update_id+1); |
| 24 | 24 | $last_update_id = BPT::$update->update_id+1; |
| 25 | - } |
|
| 26 | - else { |
|
| 25 | + } else { |
|
| 27 | 26 | logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
| 28 | 27 | BPT::exit(print_r($updates,true)); |
| 29 | 28 | } |
@@ -34,8 +33,7 @@ discard block |
||
| 34 | 33 | private static function loadData(): bool|int|string { |
| 35 | 34 | if (lock::exist('getUpdate')) { |
| 36 | 35 | $last_update_id = lock::read('getUpdate'); |
| 37 | - } |
|
| 38 | - else { |
|
| 36 | + } else { |
|
| 39 | 37 | self::deleteOldLocks(); |
| 40 | 38 | telegram::deleteWebhook(); |
| 41 | 39 | $last_update_id = 0; |
@@ -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 | } |
@@ -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."$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) { |
|
| 57 | + private static function setTimeout(array &$data, CurlHandle $curl_handler, string $method) { |
|
| 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) { |
| 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 | } |
@@ -35,8 +35,7 @@ discard block |
||
| 35 | 35 | $curl_handler = curl_init(settings::$base_url."$token/"); |
| 36 | 36 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 37 | 37 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 38 | - } |
|
| 39 | - else{ |
|
| 38 | + } else{ |
|
| 40 | 39 | $token = settings::$token; |
| 41 | 40 | if (!isset(self::$curl_handler)){ |
| 42 | 41 | self::$curl_handler = curl_init(settings::$base_url."$token/"); |
@@ -58,11 +57,9 @@ discard block |
||
| 58 | 57 | if (isset($data['forgot'])) { |
| 59 | 58 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 60 | 59 | unset($data['forgot']); |
| 61 | - } |
|
| 62 | - elseif ($method === 'getUpdates'){ |
|
| 60 | + } elseif ($method === 'getUpdates'){ |
|
| 63 | 61 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 64 | - } |
|
| 65 | - else{ |
|
| 62 | + } else{ |
|
| 66 | 63 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300); |
| 67 | 64 | } |
| 68 | 65 | } |