@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace BPT; |
4 | 4 | |
5 | -use BPT\tools\{is,file,convert,generator,encrypt}; |
|
5 | +use BPT\tools\{is, file, convert, generator, encrypt}; |
|
6 | 6 | |
7 | -class tools{ |
|
7 | +class tools { |
|
8 | 8 | use is; |
9 | 9 | use file; |
10 | 10 | use convert; |
@@ -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', '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 | } |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return bool|user return array when verify is active and token is true array of telegram getMe result |
97 | 97 | */ |
98 | - public static function isToken (string $token, bool $verify = false): bool|user { |
|
98 | + public static function isToken(string $token, bool $verify = false): bool | user { |
|
99 | 99 | if (preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) { |
100 | - if ($verify){ |
|
100 | + if ($verify) { |
|
101 | 101 | $res = telegram::me($token); |
102 | 102 | if (telegram::$status) { |
103 | 103 | return $res; |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool { |
|
132 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool { |
|
133 | 133 | if (!is_array($ids)) { |
134 | 134 | $ids = [$ids]; |
135 | 135 | } |
136 | 136 | $user_id = $user_id ?? request::catchFields('user_id'); |
137 | 137 | |
138 | 138 | foreach ($ids as $id) { |
139 | - $check = telegram::getChatMember($id,$user_id); |
|
139 | + $check = telegram::getChatMember($id, $user_id); |
|
140 | 140 | if (telegram::$status) { |
141 | 141 | $check = $check->status; |
142 | 142 | if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) { |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return array keys will be id and values will be bool(null for not founded ids) |
165 | 165 | */ |
166 | - public static function joinChecker (array|string|int $ids , int|null $user_id = null): array { |
|
166 | + public static function joinChecker(array | string | int $ids, int | null $user_id = null): array { |
|
167 | 167 | if (!is_array($ids)) { |
168 | 168 | $ids = [$ids]; |
169 | 169 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | $result = []; |
173 | 173 | foreach ($ids as $id) { |
174 | - $check = telegram::getChatMember($id,$user_id); |
|
174 | + $check = telegram::getChatMember($id, $user_id); |
|
175 | 175 | if (telegram::$status) { |
176 | 176 | $check = $check->status; |
177 | 177 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
@@ -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 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
28 | 28 | */ |
29 | - public static function size (string $path, bool $format = true): string|int|false { |
|
29 | + public static function size(string $path, bool $format = true): string | int | false { |
|
30 | 30 | if (filter_var($path, FILTER_VALIDATE_URL)) { |
31 | 31 | $ch = curl_init($path); |
32 | 32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @return bool |
60 | 60 | * @throws bptException |
61 | 61 | */ |
62 | - public static function delete (string $path, bool $sub = true): bool { |
|
62 | + public static function delete(string $path, bool $sub = true): bool { |
|
63 | 63 | if (is_dir($path)) { |
64 | 64 | if (count(scandir($path)) > 2) { |
65 | 65 | if ($sub) { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | return rmdir($path); |
72 | 72 | } |
73 | 73 | else { |
74 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
74 | + 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 | 75 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
76 | 76 | } |
77 | 77 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @return bool |
94 | 94 | * @throws bptException when zip extension not found |
95 | 95 | */ |
96 | - public static function zip (string $path, string $destination, bool $self = true, bool $sub_folder = true): bool { |
|
96 | + public static function zip(string $path, string $destination, bool $self = true, bool $sub_folder = true): bool { |
|
97 | 97 | if (extension_loaded('zip')) { |
98 | 98 | if (file_exists($destination)) unlink($destination); |
99 | 99 | |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | $zip = new ZipArchive(); |
102 | 102 | $zip->open($destination, ZipArchive::CREATE); |
103 | 103 | |
104 | - if (is_dir($path)){ |
|
105 | - if ($self){ |
|
106 | - $dirs = explode('\\',$path); |
|
104 | + if (is_dir($path)) { |
|
105 | + if ($self) { |
|
106 | + $dirs = explode('\\', $path); |
|
107 | 107 | $dir_count = count($dirs); |
108 | - $main_dir = $dirs[$dir_count-1]; |
|
108 | + $main_dir = $dirs[$dir_count - 1]; |
|
109 | 109 | |
110 | 110 | $path = ''; |
111 | - for ($i=0; $i < $dir_count - 1; $i++) { |
|
112 | - $path .= '\\' . $dirs[$i]; |
|
111 | + for ($i = 0; $i < $dir_count - 1; $i++) { |
|
112 | + $path .= '\\'.$dirs[$i]; |
|
113 | 113 | } |
114 | 114 | $path = substr($path, 1); |
115 | 115 | $zip->addEmptyDir($main_dir); |
@@ -118,27 +118,27 @@ discard block |
||
118 | 118 | $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); |
119 | 119 | $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST); |
120 | 120 | foreach ($files as $file) { |
121 | - if ($file->isFile()){ |
|
122 | - if ($sub_folder){ |
|
123 | - $zip->addFile($file, str_replace($path . '\\', '', $file)); |
|
121 | + if ($file->isFile()) { |
|
122 | + if ($sub_folder) { |
|
123 | + $zip->addFile($file, str_replace($path.'\\', '', $file)); |
|
124 | 124 | } |
125 | - else{ |
|
125 | + else { |
|
126 | 126 | $zip->addFile($file, basename($file)); |
127 | 127 | } |
128 | 128 | } |
129 | 129 | elseif ($file->isDir() && $sub_folder) { |
130 | - $zip->addEmptyDir(str_replace($path . '\\', '', $file . '\\')); |
|
130 | + $zip->addEmptyDir(str_replace($path.'\\', '', $file.'\\')); |
|
131 | 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 | 139 | } |
140 | 140 | else { |
141 | - logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
141 | + logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
142 | 142 | throw new bptException('ZIP_EXTENSION_MISSING'); |
143 | 143 | } |
144 | 144 | } |
@@ -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 | } |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
31 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
32 | 32 | $rand_string = ''; |
33 | 33 | $char_len = strlen($characters) - 1; |
34 | - for ($i = 0; $i < $length; $i ++) { |
|
34 | + for ($i = 0; $i < $length; $i++) { |
|
35 | 35 | $rand_string .= $characters[rand(0, $char_len)]; |
36 | 36 | } |
37 | 37 | return $rand_string; |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
61 | 61 | * @throws bptException |
62 | 62 | */ |
63 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
63 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
64 | 64 | if (!empty($keyboard)) { |
65 | 65 | $keyboard_object = new replyKeyboardMarkup(); |
66 | 66 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
67 | 67 | if (isset($keyboard['one_time'])) { |
68 | - $keyboard_object->setOne_time_keyboard($keyboard['one_time']) ; |
|
68 | + $keyboard_object->setOne_time_keyboard($keyboard['one_time']); |
|
69 | 69 | } |
70 | 70 | foreach ($keyboard as $row) { |
71 | 71 | $buttons = []; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | return $keyboard_object; |
119 | 119 | } |
120 | 120 | else { |
121 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
121 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
122 | 122 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
123 | 123 | } |
124 | 124 | } |
@@ -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 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return array|string|bool |
30 | 30 | * @throws bptException |
31 | 31 | */ |
32 | - public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
32 | + public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
33 | 33 | |
34 | 34 | if (extension_loaded('openssl')) { |
35 | 35 | if ($action === cryptoAction::ENCRYPT) { |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | } |
41 | 41 | elseif ($action === cryptoAction::DECRYPT) { |
42 | 42 | if (empty($key)) { |
43 | - logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
|
43 | + logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR); |
|
44 | 44 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
45 | 45 | } |
46 | 46 | if (empty($iv)) { |
47 | - logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
|
47 | + logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR); |
|
48 | 48 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
49 | 49 | } |
50 | 50 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | } |
57 | 57 | else { |
58 | - logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
58 | + logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
59 | 59 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
60 | 60 | } |
61 | 61 | } |
@@ -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 | } |
@@ -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 (empty($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 | $status = $base_time < $target_time ? 'later' : 'ago'; |
103 | 103 | $diff = $base_time->diff($target_time); |
@@ -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 |