@@ -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 | } |
@@ -706,12 +706,10 @@ discard block |
||
| 706 | 706 | self::setDefaults($action,$arguments); |
| 707 | 707 | if (isset($arguments['answer'])) {
|
| 708 | 708 | return answer::init($action,$arguments); |
| 709 | - } |
|
| 710 | - else {
|
|
| 709 | + } else {
|
|
| 711 | 710 | return self::processResponse($action,curl::init($action,$arguments)); |
| 712 | 711 | } |
| 713 | - } |
|
| 714 | - else {
|
|
| 712 | + } else {
|
|
| 715 | 713 | logger::write("$name method is not supported",loggerTypes::ERROR);
|
| 716 | 714 | throw new bptException('METHOD_NOT_FOUND');
|
| 717 | 715 | } |
@@ -737,8 +735,7 @@ discard block |
||
| 737 | 735 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
| 738 | 736 | } |
| 739 | 737 | } |
| 740 | - } |
|
| 741 | - elseif ($file_params = self::methodFile($name)) {
|
|
| 738 | + } elseif ($file_params = self::methodFile($name)) {
|
|
| 742 | 739 | foreach ($file_params as $param) {
|
| 743 | 740 | if (isset($arguments[$param]) && file_exists($arguments[$param])) {
|
| 744 | 741 | $arguments[$param] = new CURLFile($arguments[$param]); |
@@ -760,12 +757,10 @@ discard block |
||
| 760 | 757 | $value = new ($return[0]) ($value); |
| 761 | 758 | } |
| 762 | 759 | return $response; |
| 763 | - } |
|
| 764 | - else {
|
|
| 760 | + } else {
|
|
| 765 | 761 | return new ($return) ($response->result); |
| 766 | 762 | } |
| 767 | - } |
|
| 768 | - else {
|
|
| 763 | + } else {
|
|
| 769 | 764 | return $response->result; |
| 770 | 765 | } |
| 771 | 766 | } |
@@ -777,8 +772,7 @@ discard block |
||
| 777 | 772 | if (!isset($arguments[$default])){
|
| 778 | 773 | $arguments[$default] = self::catchFields($default); |
| 779 | 774 | } |
| 780 | - } |
|
| 781 | - elseif (isset(BPT::$update->$key) || $key === 'other') {
|
|
| 775 | + } elseif (isset(BPT::$update->$key) || $key === 'other') {
|
|
| 782 | 776 | foreach ($default as $def) {
|
| 783 | 777 | if (!isset($arguments[$def])){
|
| 784 | 778 | $arguments[$def] = self::catchFields($def); |
@@ -794,8 +788,7 @@ discard block |
||
| 794 | 788 | self::$status = true; |
| 795 | 789 | self::$pure_response = $response; |
| 796 | 790 | return self::methodReturn($name,$response); |
| 797 | - } |
|
| 798 | - else {
|
|
| 791 | + } else {
|
|
| 799 | 792 | self::$status = false; |
| 800 | 793 | self::$pure_response = $response; |
| 801 | 794 | return new responseError($response); |
@@ -831,9 +824,13 @@ discard block |
||
| 831 | 824 | default => false |
| 832 | 825 | }; |
| 833 | 826 | case 'file_id' : |
| 834 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
| 835 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
| 836 | - else return false; |
|
| 827 | + if (isset(BPT::$update->message)) { |
|
| 828 | + $type = 'message'; |
|
| 829 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 830 | + $type = 'edited_message'; |
|
| 831 | + } else { |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 837 | 834 | |
| 838 | 835 | return match(true) {
|
| 839 | 836 | isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id, |
@@ -17,21 +17,18 @@ discard block |
||
| 17 | 17 | foreach ($object as $key=>$value) { |
| 18 | 18 | if (isset($subs[$key])) { |
| 19 | 19 | $this->$key = new ($subs[$key]) ($value); |
| 20 | - } |
|
| 21 | - else { |
|
| 20 | + } else { |
|
| 22 | 21 | if (is_array($value)) { |
| 23 | 22 | foreach ($value as $sub_key=>$sub_value) { |
| 24 | 23 | if (is_array($sub_value)) { |
| 25 | 24 | foreach ($sub_value as $sub2_value) { |
| 26 | 25 | $this->$key[$sub_key][] = new ($subs['array']['array'][$key]) ($sub2_value); |
| 27 | 26 | } |
| 28 | - } |
|
| 29 | - else{ |
|
| 27 | + } else{ |
|
| 30 | 28 | $this->$key[] = new ($subs['array'][$key]) ($sub_value); |
| 31 | 29 | } |
| 32 | 30 | } |
| 33 | - } |
|
| 34 | - else{ |
|
| 31 | + } else{ |
|
| 35 | 32 | $this->$key = $value; |
| 36 | 33 | if (ucfirst($key) === basename(get_class($this)).'_id') { |
| 37 | 34 | $this->{'id'} = $value; |
@@ -48,8 +45,7 @@ discard block |
||
| 48 | 45 | $name = substr($name,3); |
| 49 | 46 | if (isset($arguments[0])) { |
| 50 | 47 | $this->$name = $arguments[0]; |
| 51 | - } |
|
| 52 | - elseif (isset($arguments['value'])) { |
|
| 48 | + } elseif (isset($arguments['value'])) { |
|
| 53 | 49 | $this->$name = $arguments['value']; |
| 54 | 50 | } |
| 55 | 51 | } |
@@ -62,13 +62,11 @@ discard block |
||
| 62 | 62 | if ($db) { |
| 63 | 63 | self::$connect = $db; |
| 64 | 64 | print_r($db); |
| 65 | - } |
|
| 66 | - else { |
|
| 65 | + } else { |
|
| 67 | 66 | print self::$username; |
| 68 | 67 | throw new \exception('a problem to connecting'); |
| 69 | 68 | } |
| 70 | - } |
|
| 71 | - else { |
|
| 69 | + } else { |
|
| 72 | 70 | throw new \exception('required parameters not found'); |
| 73 | 71 | } |
| 74 | 72 | } |
@@ -77,13 +75,11 @@ discard block |
||
| 77 | 75 | self::$type = $settings['type']; |
| 78 | 76 | self::$dbname = $settings['dbname']; |
| 79 | 77 | (new database())->json_init(); |
| 80 | - } |
|
| 81 | - else { |
|
| 78 | + } else { |
|
| 82 | 79 | throw new \exception('parameter dbanme not found'); |
| 83 | 80 | } |
| 84 | 81 | } |
| 85 | - } |
|
| 86 | - else { |
|
| 82 | + } else { |
|
| 87 | 83 | throw new \exception('parameter type not found'); |
| 88 | 84 | } |
| 89 | 85 | } |
@@ -96,8 +92,7 @@ discard block |
||
| 96 | 92 | self::$password = $array['password']; |
| 97 | 93 | self::$charset = $array['charset'] ?? 'utf8'; |
| 98 | 94 | return true; |
| 99 | - } |
|
| 100 | - else { |
|
| 95 | + } else { |
|
| 101 | 96 | return false; |
| 102 | 97 | } |
| 103 | 98 | } |
@@ -175,8 +175,9 @@ |
||
| 175 | 175 | if (telegram::$status) { |
| 176 | 176 | $check = $check->status; |
| 177 | 177 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
| 178 | + } else { |
|
| 179 | + $result[$id] = null; |
|
| 178 | 180 | } |
| 179 | - else $result[$id] = null; |
|
| 180 | 181 | } |
| 181 | 182 | return $result; |
| 182 | 183 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | curl_exec($ch); |
| 36 | 36 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
| 37 | 37 | curl_close($ch); |
| 38 | - } |
|
| 39 | - else { |
|
| 38 | + } else { |
|
| 40 | 39 | $size = file_exists($path) ? filesize($path) : false; |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | if (isset($size) && is_numeric($size)) { |
| 44 | 43 | return $format ? tools::byteFormat($size) : $size; |
| 44 | + } else { |
|
| 45 | + return false; |
|
| 45 | 46 | } |
| 46 | - else return false; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -69,15 +69,16 @@ discard block |
||
| 69 | 69 | $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath()); |
| 70 | 70 | } |
| 71 | 71 | return rmdir($path); |
| 72 | - } |
|
| 73 | - else { |
|
| 72 | + } else { |
|
| 74 | 73 | logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
| 75 | 74 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
| 76 | 75 | } |
| 76 | + } else { |
|
| 77 | + return rmdir($path); |
|
| 77 | 78 | } |
| 78 | - else return rmdir($path); |
|
| 79 | + } else { |
|
| 80 | + return unlink($path); |
|
| 79 | 81 | } |
| 80 | - else return unlink($path); |
|
| 81 | 82 | } |
| 82 | 83 | |
| 83 | 84 | /** |
@@ -95,7 +96,9 @@ discard block |
||
| 95 | 96 | */ |
| 96 | 97 | public static function zip (string $path, string $destination, bool $self = true, bool $sub_folder = true): bool { |
| 97 | 98 | if (extension_loaded('zip')) { |
| 98 | - if (file_exists($destination)) unlink($destination); |
|
| 99 | + if (file_exists($destination)) { |
|
| 100 | + unlink($destination); |
|
| 101 | + } |
|
| 99 | 102 | |
| 100 | 103 | $path = realpath($path); |
| 101 | 104 | $zip = new ZipArchive(); |
@@ -121,23 +124,19 @@ discard block |
||
| 121 | 124 | if ($file->isFile()){ |
| 122 | 125 | if ($sub_folder){ |
| 123 | 126 | $zip->addFile($file, str_replace($path . '\\', '', $file)); |
| 124 | - } |
|
| 125 | - else{ |
|
| 127 | + } else{ |
|
| 126 | 128 | $zip->addFile($file, basename($file)); |
| 127 | 129 | } |
| 128 | - } |
|
| 129 | - elseif ($file->isDir() && $sub_folder) { |
|
| 130 | + } elseif ($file->isDir() && $sub_folder) { |
|
| 130 | 131 | $zip->addEmptyDir(str_replace($path . '\\', '', $file . '\\')); |
| 131 | 132 | } |
| 132 | 133 | } |
| 133 | - } |
|
| 134 | - else{ |
|
| 134 | + } else{ |
|
| 135 | 135 | $zip->addFile($path, basename($path)); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | return $zip->close(); |
| 139 | - } |
|
| 140 | - else { |
|
| 139 | + } else { |
|
| 141 | 140 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
| 142 | 141 | throw new bptException('ZIP_EXTENSION_MISSING'); |
| 143 | 142 | } |
@@ -76,15 +76,12 @@ discard block |
||
| 76 | 76 | if (count($button_info) > 1) { |
| 77 | 77 | if ($button_info[1] === 'con') { |
| 78 | 78 | $button->setRequest_contact(true); |
| 79 | - } |
|
| 80 | - elseif ($button_info[1] === 'loc') { |
|
| 79 | + } elseif ($button_info[1] === 'loc') { |
|
| 81 | 80 | $button->setRequest_location(true); |
| 82 | - } |
|
| 83 | - elseif ($button_info[1] === 'poll') { |
|
| 81 | + } elseif ($button_info[1] === 'poll') { |
|
| 84 | 82 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
| 85 | 83 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
| 86 | - } |
|
| 87 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 84 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
| 88 | 85 | $url = $button_info[2]; |
| 89 | 86 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
| 90 | 87 | } |
@@ -94,8 +91,7 @@ discard block |
||
| 94 | 91 | $keyboard_object->setKeyboard([$buttons]); |
| 95 | 92 | } |
| 96 | 93 | return $keyboard_object; |
| 97 | - } |
|
| 98 | - elseif (!empty($inline)) { |
|
| 94 | + } elseif (!empty($inline)) { |
|
| 99 | 95 | $keyboard_object = new inlineKeyboardMarkup(); |
| 100 | 96 | foreach ($inline as $row) { |
| 101 | 97 | $buttons = []; |
@@ -104,20 +100,17 @@ discard block |
||
| 104 | 100 | if (isset($button_info[1])) { |
| 105 | 101 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
| 106 | 102 | $button->setText($button_info[0])->setUrl($button_info[1]); |
| 107 | - } |
|
| 108 | - else { |
|
| 103 | + } else { |
|
| 109 | 104 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
| 110 | 105 | } |
| 111 | - } |
|
| 112 | - else { |
|
| 106 | + } else { |
|
| 113 | 107 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
| 114 | 108 | } |
| 115 | 109 | } |
| 116 | 110 | $keyboard_object->setInline_keyboard([$buttons]); |
| 117 | 111 | } |
| 118 | 112 | return $keyboard_object; |
| 119 | - } |
|
| 120 | - else { |
|
| 113 | + } else { |
|
| 121 | 114 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
| 122 | 115 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 123 | 116 | } |
@@ -37,8 +37,7 @@ discard block |
||
| 37 | 37 | $iv = self::randomString(); |
| 38 | 38 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
| 39 | 39 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
| 40 | - } |
|
| 41 | - elseif ($action === cryptoAction::DECRYPT) { |
|
| 40 | + } elseif ($action === cryptoAction::DECRYPT) { |
|
| 42 | 41 | if (empty($key)) { |
| 43 | 42 | logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
| 44 | 43 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
@@ -48,13 +47,11 @@ discard block |
||
| 48 | 47 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
| 49 | 48 | } |
| 50 | 49 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
| 51 | - } |
|
| 52 | - else { |
|
| 50 | + } else { |
|
| 53 | 51 | logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`"); |
| 54 | 52 | return false; |
| 55 | 53 | } |
| 56 | - } |
|
| 57 | - else { |
|
| 54 | + } else { |
|
| 58 | 55 | logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
| 59 | 56 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
| 60 | 57 | } |
@@ -106,8 +106,9 @@ |
||
| 106 | 106 | foreach ($string as $k => &$v) { |
| 107 | 107 | if ($diff->$v) { |
| 108 | 108 | $v = $diff->$v; |
| 109 | + } else { |
|
| 110 | + unset($string[$k]); |
|
| 109 | 111 | } |
| 110 | - else unset($string[$k]); |
|
| 111 | 112 | } |
| 112 | 113 | $string['status'] = $status; |
| 113 | 114 | |