@@ -24,8 +24,7 @@ |
||
| 24 | 24 | private static function loadData(): bool|int|string {
|
| 25 | 25 | if (lock::exist('getUpdate')) {
|
| 26 | 26 | $last_update_id = lock::read('getUpdate');
|
| 27 | - } |
|
| 28 | - else {
|
|
| 27 | + } else {
|
|
| 29 | 28 | self::deleteOldLocks(); |
| 30 | 29 | telegram::deleteWebhook(); |
| 31 | 30 | $last_update_id = 0; |
@@ -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::ERROR);
|
| 19 | 18 | BPT::exit(); |
| 20 | 19 | } |
@@ -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::ERROR);
|
| 29 | 28 | BPT::exit(); |
| 30 | 29 | } |
@@ -14,14 +14,12 @@ discard block |
||
| 14 | 14 | public static function init () {
|
| 15 | 15 | if (settings::$multi) {
|
| 16 | 16 | multi::init(); |
| 17 | - } |
|
| 18 | - else {
|
|
| 17 | + } else {
|
|
| 19 | 18 | if (lock::exist('BPT-HOOK')) {
|
| 20 | 19 | receiver::telegramVerify(); |
| 21 | 20 | receiver::processUpdate(); |
| 22 | 21 | logger::write('Update received , lets process it ;)');
|
| 23 | - } |
|
| 24 | - else {
|
|
| 22 | + } else {
|
|
| 25 | 23 | self::deleteOldLocks(); |
| 26 | 24 | self::checkURL(); |
| 27 | 25 | self::setCertificate(); |
@@ -49,8 +47,7 @@ discard block |
||
| 49 | 47 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates); |
| 50 | 48 | if ($res->ok) {
|
| 51 | 49 | logger::write('Webhook was set successfully',loggerTypes::INFO);
|
| 52 | - } |
|
| 53 | - else {
|
|
| 50 | + } else {
|
|
| 54 | 51 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
| 55 | 52 | BPT::exit(print_r($res,true)); |
| 56 | 53 | } |
@@ -72,8 +69,7 @@ discard block |
||
| 72 | 69 | if (is_string(settings::$certificate)) {
|
| 73 | 70 | if (file_exists(settings::$certificate)) {
|
| 74 | 71 | settings::$certificate = new CURLFile(settings::$certificate); |
| 75 | - } |
|
| 76 | - else {
|
|
| 72 | + } else {
|
|
| 77 | 73 | settings::$certificate = null; |
| 78 | 74 | } |
| 79 | 75 | } |
@@ -63,26 +63,21 @@ |
||
| 63 | 63 | if (self::handlerExist('message')) {
|
| 64 | 64 | BPT::$handler->message(BPT::$update->message); |
| 65 | 65 | } |
| 66 | - } |
|
| 67 | - elseif (isset(BPT::$update->callback_query)) {
|
|
| 66 | + } elseif (isset(BPT::$update->callback_query)) {
|
|
| 68 | 67 | if (self::handlerExist('callback_query')) {
|
| 69 | 68 | BPT::$handler->callback_query(BPT::$update->callback_query); |
| 70 | 69 | } |
| 71 | - } |
|
| 72 | - elseif (isset(BPT::$update->inline_query)) {
|
|
| 70 | + } elseif (isset(BPT::$update->inline_query)) {
|
|
| 73 | 71 | if (self::handlerExist('inline_query')) {
|
| 74 | 72 | BPT::$handler->inline_query(BPT::$update->inline_query); |
| 75 | 73 | } |
| 76 | - } |
|
| 77 | - elseif (isset(BPT::$update->edited_message)) {
|
|
| 74 | + } elseif (isset(BPT::$update->edited_message)) {
|
|
| 78 | 75 | if (self::handlerExist('edited_message')) {
|
| 79 | 76 | BPT::$handler->edited_message(BPT::$update->edited_message); |
| 80 | 77 | } |
| 81 | - } |
|
| 82 | - elseif (self::handlerExist('something_else')) {
|
|
| 78 | + } elseif (self::handlerExist('something_else')) {
|
|
| 83 | 79 | BPT::$handler->something_else(BPT::$update); |
| 84 | - } |
|
| 85 | - else {
|
|
| 80 | + } else {
|
|
| 86 | 81 | logger::write('Update received but handlers does not set',loggerTypes::WARNING);
|
| 87 | 82 | } |
| 88 | 83 | } |
@@ -257,15 +257,15 @@ discard block |
||
| 257 | 257 | curl_exec($ch); |
| 258 | 258 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
| 259 | 259 | curl_close($ch); |
| 260 | - } |
|
| 261 | - else {
|
|
| 260 | + } else {
|
|
| 262 | 261 | $size = file_exists($path) ? filesize($path) : false; |
| 263 | 262 | } |
| 264 | 263 | |
| 265 | 264 | if (isset($size) && is_numeric($size)) {
|
| 266 | 265 | return $format ? tools::byteFormat($size) : $size; |
| 267 | - } |
|
| 268 | - else return false; |
|
| 266 | + } else { |
|
| 267 | + return false; |
|
| 268 | + } |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | //fix methods after here comments |
@@ -293,15 +293,16 @@ discard block |
||
| 293 | 293 | $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath()); |
| 294 | 294 | } |
| 295 | 295 | rmdir($path); |
| 296 | - } |
|
| 297 | - else {
|
|
| 296 | + } else {
|
|
| 298 | 297 | logger::write("BPT delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR);
|
| 299 | 298 | return false; |
| 300 | 299 | } |
| 301 | - } |
|
| 302 | - else rmdir($path); |
|
| 303 | - } |
|
| 304 | - else unlink($path); |
|
| 300 | + } else { |
|
| 301 | + rmdir($path); |
|
| 302 | + } |
|
| 303 | + } else { |
|
| 304 | + unlink($path); |
|
| 305 | + } |
|
| 305 | 306 | |
| 306 | 307 | return true; |
| 307 | 308 | } |
@@ -328,8 +329,9 @@ discard block |
||
| 328 | 329 | foreach ($string as $k => &$v) {
|
| 329 | 330 | if ($diff->$v) {
|
| 330 | 331 | $v = $diff->$v; |
| 331 | - } |
|
| 332 | - else unset($string[$k]); |
|
| 332 | + } else { |
|
| 333 | + unset($string[$k]); |
|
| 334 | + } |
|
| 333 | 335 | } |
| 334 | 336 | $string['status'] = $status; |
| 335 | 337 | return count($string) > 1 ? $string : ['status' => 'now']; |
@@ -36,8 +36,7 @@ discard block |
||
| 36 | 36 | $curl_handler = curl_init(settings::$base_url."$token/"); |
| 37 | 37 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 38 | 38 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 39 | - } |
|
| 40 | - else{
|
|
| 39 | + } else{
|
|
| 41 | 40 | $token = settings::$token; |
| 42 | 41 | if (!isset(self::$curl_handler)){
|
| 43 | 42 | self::$curl_handler = curl_init(settings::$base_url."$token/"); |
@@ -59,11 +58,9 @@ discard block |
||
| 59 | 58 | if (isset($data['forgot'])) {
|
| 60 | 59 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 61 | 60 | unset($data['forgot']); |
| 62 | - } |
|
| 63 | - elseif ($method === 'getUpdates'){
|
|
| 61 | + } elseif ($method === 'getUpdates'){
|
|
| 64 | 62 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 65 | - } |
|
| 66 | - else{
|
|
| 63 | + } else{
|
|
| 67 | 64 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300); |
| 68 | 65 | } |
| 69 | 66 | } |
@@ -219,8 +219,7 @@ discard block |
||
| 219 | 219 | public function __call (string $name, array $arguments) {
|
| 220 | 220 | if (!isset($arguments[1]) && isset($arguments[0]) && is_array($arguments[0])) {
|
| 221 | 221 | return request::$name(...$arguments[0]); |
| 222 | - } |
|
| 223 | - else {
|
|
| 222 | + } else {
|
|
| 224 | 223 | return request::$name(...$arguments); |
| 225 | 224 | } |
| 226 | 225 | } |
@@ -228,8 +227,7 @@ discard block |
||
| 228 | 227 | public static function __callStatic (string $name, array $arguments) {
|
| 229 | 228 | if (!isset($arguments[1]) && isset($arguments[0]) && is_array($arguments[0])) {
|
| 230 | 229 | return request::$name(...$arguments[0]); |
| 231 | - } |
|
| 232 | - else {
|
|
| 230 | + } else {
|
|
| 233 | 231 | return request::$name(...$arguments); |
| 234 | 232 | } |
| 235 | 233 | } |
@@ -418,12 +418,10 @@ discard block |
||
| 418 | 418 | self::setDefaults($action,$arguments); |
| 419 | 419 | if (isset($arguments['answer'])) {
|
| 420 | 420 | return answer::init($action,$arguments); |
| 421 | - } |
|
| 422 | - else {
|
|
| 421 | + } else {
|
|
| 423 | 422 | return curl::init($action,$arguments); |
| 424 | 423 | } |
| 425 | - } |
|
| 426 | - else {
|
|
| 424 | + } else {
|
|
| 427 | 425 | logger::write("$name method is not supported",loggerTypes::ERROR);
|
| 428 | 426 | } |
| 429 | 427 | } |
@@ -448,8 +446,7 @@ discard block |
||
| 448 | 446 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
| 449 | 447 | } |
| 450 | 448 | } |
| 451 | - } |
|
| 452 | - elseif ($file_params = self::methodFile($name)) {
|
|
| 449 | + } elseif ($file_params = self::methodFile($name)) {
|
|
| 453 | 450 | foreach ($file_params as $param) {
|
| 454 | 451 | if (isset($arguments[$param]) && file_exists($arguments[$param])) {
|
| 455 | 452 | $arguments[$param] = new CURLFile($arguments[$param]); |
@@ -469,8 +466,7 @@ discard block |
||
| 469 | 466 | if (!isset($arguments[$default])){
|
| 470 | 467 | $arguments[$default] = self::catchFields($default); |
| 471 | 468 | } |
| 472 | - } |
|
| 473 | - elseif (isset(BPT::$update->$key) || $key === 'other') {
|
|
| 469 | + } elseif (isset(BPT::$update->$key) || $key === 'other') {
|
|
| 474 | 470 | foreach ($default as $def) {
|
| 475 | 471 | if (!isset($arguments[$def])){
|
| 476 | 472 | $arguments[$def] = self::catchFields($def); |
@@ -510,9 +506,13 @@ discard block |
||
| 510 | 506 | default => false |
| 511 | 507 | }; |
| 512 | 508 | case 'file_id' : |
| 513 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
| 514 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
| 515 | - else return false; |
|
| 509 | + if (isset(BPT::$update->message)) { |
|
| 510 | + $type = 'message'; |
|
| 511 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 512 | + $type = 'edited_message'; |
|
| 513 | + } else { |
|
| 514 | + return false; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | 517 | return match(true) {
|
| 518 | 518 | isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id, |