@@ -32,7 +32,7 @@ |
||
32 | 32 | public bool $selective; |
33 | 33 | |
34 | 34 | |
35 | - public function __construct(stdClass|null $object = null) { |
|
35 | + public function __construct(stdClass | null $object = null) { |
|
36 | 36 | if ($object != null) { |
37 | 37 | parent::__construct($object, self::subs); |
38 | 38 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public chatInviteLink $invite_link; |
32 | 32 | |
33 | 33 | |
34 | - public function __construct(stdClass|null $object = null) { |
|
34 | + public function __construct(stdClass | null $object = null) { |
|
35 | 35 | if ($object != null) { |
36 | 36 | parent::__construct($object, self::subs); |
37 | 37 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | /** |
12 | 12 | * @method Json_init |
13 | 13 | */ |
14 | - public function json_init () { |
|
14 | + public function json_init() { |
|
15 | 15 | (new jsondb())->init(handler::$dbname); |
16 | 16 | } |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * |
50 | 50 | */ |
51 | - public function __construct (array $settings) { |
|
51 | + public function __construct(array $settings) { |
|
52 | 52 | if (in_array($settings['type'], self::TYPES)) { |
53 | 53 | if ($settings['type'] === 'Mysqli') { |
54 | 54 | if (self::CheckParam($settings)) { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - private static function CheckParam (array $array) { |
|
91 | + private static function CheckParam(array $array) { |
|
92 | 92 | if (isset($array['username']) && isset($array['dbname']) && isset($array['password'])) { |
93 | 93 | self::$host = $array['host'] ?? 'localhost'; |
94 | 94 | self::$username = $array['username']; |
@@ -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 | } |
@@ -7,4 +7,4 @@ |
||
7 | 7 | /** |
8 | 8 | * Exceptions created by BPT and subclasses |
9 | 9 | */ |
10 | -class bptException extends Exception{} |
|
11 | 10 | \ No newline at end of file |
11 | +class bptException extends Exception {} |
|
12 | 12 | \ No newline at end of file |
@@ -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 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return string|bool|array{hash:string, key:string, iv:string} |
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 | if (extension_loaded('openssl')) { |
34 | 34 | if ($action === cryptoAction::ENCRYPT) { |
35 | 35 | $key = self::randomString(64); |
@@ -39,22 +39,22 @@ discard block |
||
39 | 39 | } |
40 | 40 | elseif ($action === cryptoAction::DECRYPT) { |
41 | 41 | if (empty($key)) { |
42 | - logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
|
42 | + logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR); |
|
43 | 43 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
44 | 44 | } |
45 | 45 | elseif (empty($iv)) { |
46 | - logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
|
46 | + logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR); |
|
47 | 47 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
48 | 48 | } |
49 | 49 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
50 | 50 | } |
51 | 51 | else { |
52 | - logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
52 | + logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | } |
56 | 56 | else { |
57 | - logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
57 | + logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
58 | 58 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
59 | 59 | } |
60 | 60 | } |
@@ -36,24 +36,20 @@ |
||
36 | 36 | $iv = self::randomString(); |
37 | 37 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
38 | 38 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
39 | - } |
|
40 | - elseif ($action === cryptoAction::DECRYPT) { |
|
39 | + } elseif ($action === cryptoAction::DECRYPT) { |
|
41 | 40 | if (empty($key)) { |
42 | 41 | logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
43 | 42 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
44 | - } |
|
45 | - elseif (empty($iv)) { |
|
43 | + } elseif (empty($iv)) { |
|
46 | 44 | logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
47 | 45 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
48 | 46 | } |
49 | 47 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
50 | - } |
|
51 | - else { |
|
48 | + } else { |
|
52 | 49 | logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
53 | 50 | return false; |
54 | 51 | } |
55 | - } |
|
56 | - else { |
|
52 | + } else { |
|
57 | 53 | logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
58 | 54 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
59 | 55 | } |
@@ -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 |
@@ -105,8 +105,9 @@ |
||
105 | 105 | foreach ($string as $k => &$v) { |
106 | 106 | if ($diff->$v) { |
107 | 107 | $v = $diff->$v; |
108 | + } else { |
|
109 | + unset($string[$k]); |
|
108 | 110 | } |
109 | - else unset($string[$k]); |
|
110 | 111 | } |
111 | 112 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
112 | 113 |