@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | const ADMIN = 123456789; |
20 | 20 | const SHOW_STATUS = true; |
21 | 21 | const UNKNOWN = 'I didnt understand it, Please use commands or reply to a user message'; |
22 | - const HELP = 'Hello dear admin |
|
22 | + const HELP = 'Hello dear admin |
|
23 | 23 | This is a simple messenger bot which also support reply for users and admin itself |
24 | 24 | For answering an user message , You must reply on it |
25 | 25 | If you want to reply , You must first use /reply_on command and this will apply on your next message |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | const SEND_FAILED = 'Failed!'; |
35 | 35 | const SEND_SUCCESSFUL = 'Done!'; |
36 | 36 | |
37 | - public function __construct (array $settings) { |
|
37 | + public function __construct(array $settings) { |
|
38 | 38 | parent::__construct($settings); |
39 | 39 | } |
40 | 40 | |
41 | - public function message (message $update) { |
|
41 | + public function message(message $update) { |
|
42 | 42 | $text = $update->text ?? ''; |
43 | 43 | $user_id = $update->from->id; |
44 | 44 | |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | return $this->sendMessage(self::HELP, answer: true); |
55 | 55 | } |
56 | 56 | if ($text === '/reply_on') { |
57 | - mysql::update('users',['value'=>'reply_on'],['id'=>$user_id],1); |
|
57 | + mysql::update('users', ['value'=>'reply_on'], ['id'=>$user_id], 1); |
|
58 | 58 | return $this->sendMessage(self::REPLY_ON, answer: true); |
59 | 59 | } |
60 | 60 | if ($text === '/reply_off') { |
61 | - mysql::update('users',['value'=>'reply_off'],['id'=>$user_id],1); |
|
61 | + mysql::update('users', ['value'=>'reply_off'], ['id'=>$user_id], 1); |
|
62 | 62 | return $this->sendMessage(self::REPLY_OFF, answer: true); |
63 | 63 | } |
64 | 64 | if (!isset($update->reply_to_message)) { |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | $reply_message_id = $update->reply_to_message->message_id; |
69 | 69 | |
70 | 70 | if ($update->reply_to_message->from->id === $user_id) { |
71 | - $check_message = mysql::select('messages', ['receiver_message_id','receiver_id'], [ |
|
71 | + $check_message = mysql::select('messages', ['receiver_message_id', 'receiver_id'], [ |
|
72 | 72 | 'sender_message_id' => $reply_message_id, |
73 | 73 | 'sender_id' => $user_id |
74 | - ],1); |
|
74 | + ], 1); |
|
75 | 75 | |
76 | 76 | if ($check_message->num_rows < 1) { |
77 | 77 | return $this->sendMessage(self::NOT_FOUND, answer: true); |
@@ -81,19 +81,19 @@ discard block |
||
81 | 81 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id); |
82 | 82 | } |
83 | 83 | else { |
84 | - $check_message = mysql::select('messages', ['sender_message_id','sender_id'], [ |
|
84 | + $check_message = mysql::select('messages', ['sender_message_id', 'sender_id'], [ |
|
85 | 85 | 'receiver_message_id' => $reply_message_id, |
86 | 86 | 'receiver_id' => $user_id |
87 | - ],1); |
|
87 | + ], 1); |
|
88 | 88 | |
89 | 89 | if ($check_message->num_rows < 1) { |
90 | 90 | return $this->sendMessage(self::NOT_FOUND, answer: true); |
91 | 91 | } |
92 | 92 | $data = $check_message->fetch_object(); |
93 | - $value = mysql::select('users','value',['id'=>$user_id])->fetch_object()->value; |
|
93 | + $value = mysql::select('users', 'value', ['id'=>$user_id])->fetch_object()->value; |
|
94 | 94 | $receiver_id = $data->sender_id; |
95 | 95 | if ($value === 'reply_on') { |
96 | - mysql::update('users',['value'=>''],['id'=>$user_id]); |
|
96 | + mysql::update('users', ['value'=>''], ['id'=>$user_id]); |
|
97 | 97 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id); |
98 | 98 | } |
99 | 99 | else { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } |
118 | 118 | $username = $update->from->username; |
119 | 119 | if (empty($username)) { |
120 | - $name = $update->from->first_name . (!empty($update->from->last_name) ? (' ' . $update->from->last_name) : ''); |
|
120 | + $name = $update->from->first_name.(!empty($update->from->last_name) ? (' '.$update->from->last_name) : ''); |
|
121 | 121 | $keyboard = [ |
122 | 122 | 'inline_keyboard' => [ |
123 | 123 | [ |
@@ -155,33 +155,33 @@ discard block |
||
155 | 155 | } |
156 | 156 | if (isset($update->reply_to_message)) { |
157 | 157 | $reply_message_id = $update->reply_to_message->message_id; |
158 | - if ($update->reply_to_message->from->id === $user_id){ |
|
158 | + if ($update->reply_to_message->from->id === $user_id) { |
|
159 | 159 | $check_message = mysql::select('messages', 'receiver_message_id', [ |
160 | 160 | 'sender_message_id' => $reply_message_id, |
161 | 161 | 'sender_id' => $user_id |
162 | - ],1); |
|
162 | + ], 1); |
|
163 | 163 | if ($check_message->num_rows > 0) { |
164 | - $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard); |
|
164 | + $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id, reply_markup: $keyboard); |
|
165 | 165 | } |
166 | 166 | else { |
167 | - $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
|
167 | + $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | else { |
171 | 171 | $check_message = mysql::select('messages', 'sender_message_id', [ |
172 | 172 | 'receiver_message_id' => $reply_message_id, |
173 | 173 | 'receiver_id' => $user_id |
174 | - ],1); |
|
174 | + ], 1); |
|
175 | 175 | if ($check_message->num_rows > 0) { |
176 | - $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard); |
|
176 | + $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id, reply_markup: $keyboard); |
|
177 | 177 | } |
178 | 178 | else { |
179 | - $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
|
179 | + $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
183 | 183 | else { |
184 | - $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
|
184 | + $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | if (file_exists('vendor/autoload.php')) { |
9 | 9 | require 'vendor/autoload.php'; |
10 | -} |
|
11 | -else { |
|
10 | +} else { |
|
12 | 11 | if (!file_exists('BPT.phar')) { |
13 | 12 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
14 | 13 | } |
@@ -79,8 +78,7 @@ discard block |
||
79 | 78 | $data = $check_message->fetch_object(); |
80 | 79 | $receiver_id = $data->receiver_id; |
81 | 80 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id); |
82 | - } |
|
83 | - else { |
|
81 | + } else { |
|
84 | 82 | $check_message = mysql::select('messages', ['sender_message_id','sender_id'], [ |
85 | 83 | 'receiver_message_id' => $reply_message_id, |
86 | 84 | 'receiver_id' => $user_id |
@@ -95,8 +93,7 @@ discard block |
||
95 | 93 | if ($value === 'reply_on') { |
96 | 94 | mysql::update('users',['value'=>''],['id'=>$user_id]); |
97 | 95 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id); |
98 | - } |
|
99 | - else { |
|
96 | + } else { |
|
100 | 97 | $result = $this->copyMessage($receiver_id); |
101 | 98 | } |
102 | 99 | } |
@@ -138,8 +135,7 @@ discard block |
||
138 | 135 | ] |
139 | 136 | ] |
140 | 137 | ]; |
141 | - } |
|
142 | - else { |
|
138 | + } else { |
|
143 | 139 | $keyboard = [ |
144 | 140 | 'inline_keyboard' => [ |
145 | 141 | [ |
@@ -162,25 +158,21 @@ discard block |
||
162 | 158 | ],1); |
163 | 159 | if ($check_message->num_rows > 0) { |
164 | 160 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard); |
165 | - } |
|
166 | - else { |
|
161 | + } else { |
|
167 | 162 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
168 | 163 | } |
169 | - } |
|
170 | - else { |
|
164 | + } else { |
|
171 | 165 | $check_message = mysql::select('messages', 'sender_message_id', [ |
172 | 166 | 'receiver_message_id' => $reply_message_id, |
173 | 167 | 'receiver_id' => $user_id |
174 | 168 | ],1); |
175 | 169 | if ($check_message->num_rows > 0) { |
176 | 170 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard); |
177 | - } |
|
178 | - else { |
|
171 | + } else { |
|
179 | 172 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
180 | 173 | } |
181 | 174 | } |
182 | - } |
|
183 | - else { |
|
175 | + } else { |
|
184 | 176 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
185 | 177 | } |
186 | 178 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * If you want to use it in standalone mode , you MUST set `auto_process` to `false` |
33 | 33 | */ |
34 | - public static function init (string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void { |
|
34 | + public static function init(string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void { |
|
35 | 35 | $host = settings::$db['host'] ?? $host; |
36 | 36 | $port = settings::$db['port'] ?? $port; |
37 | 37 | $user = settings::$db['user'] ?? settings::$db['username'] ?? $username; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | self::$db_name = $dbname; |
42 | 42 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
43 | 43 | if (self::$connection->connect_errno) { |
44 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
44 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
45 | 45 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
46 | 46 | } |
47 | 47 | if (self::$auto_process && !lock::exist('BPT-MYSQL')) { |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - private static function install (): void { |
|
52 | + private static function install(): void { |
|
53 | 53 | self::pureQuery(" |
54 | 54 | CREATE TABLE `users` |
55 | 55 | ( |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @internal Only for BPT self usage , Don't use it in your source! |
72 | 72 | */ |
73 | - public static function process (): void { |
|
73 | + public static function process(): void { |
|
74 | 74 | if (self::$auto_process) { |
75 | 75 | if (isset(BPT::$update->message)) { |
76 | 76 | self::processMessage(BPT::$update->message); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - private static function processMessage (message $update): void { |
|
93 | + private static function processMessage(message $update): void { |
|
94 | 94 | $type = $update->chat->type; |
95 | 95 | if ($type === chatType::PRIVATE) { |
96 | 96 | $user_id = $update->from->id; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
119 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
120 | 120 | $type = $update->message->chat->type; |
121 | 121 | if ($type === chatType::PRIVATE) { |
122 | 122 | $user_id = $update->from->id; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | - private static function processInlineQuery (inlineQuery $update): void { |
|
129 | + private static function processInlineQuery(inlineQuery $update): void { |
|
130 | 130 | $type = $update->chat_type; |
131 | 131 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
132 | 132 | $user_id = $update->from->id; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
139 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
140 | 140 | $type = $update->chat->type; |
141 | 141 | if ($type === chatType::PRIVATE) { |
142 | 142 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return bool |
161 | 161 | */ |
162 | - public static function addDefaultWhere (array $where): bool { |
|
162 | + public static function addDefaultWhere(array $where): bool { |
|
163 | 163 | if (empty(self::$default_where)) { |
164 | 164 | self::$default_where = $where; |
165 | 165 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @return mysqli |
176 | 176 | */ |
177 | - public static function getMysqli (): mysqli { |
|
177 | + public static function getMysqli(): mysqli { |
|
178 | 178 | return self::$connection; |
179 | 179 | } |
180 | 180 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return int|string |
187 | 187 | */ |
188 | - public static function affected_rows (): int|string { |
|
188 | + public static function affected_rows(): int | string { |
|
189 | 189 | return self::$connection->affected_rows; |
190 | 190 | } |
191 | 191 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return int|string |
198 | 198 | */ |
199 | - public static function affectedRows (): int|string { |
|
199 | + public static function affectedRows(): int | string { |
|
200 | 200 | return self::$connection->affected_rows; |
201 | 201 | } |
202 | 202 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return int|string |
209 | 209 | */ |
210 | - public static function insert_id (): int|string { |
|
210 | + public static function insert_id(): int | string { |
|
211 | 211 | return self::$connection->insert_id; |
212 | 212 | } |
213 | 213 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return int|string |
220 | 220 | */ |
221 | - public static function insertId (): int|string { |
|
221 | + public static function insertId(): int | string { |
|
222 | 222 | return self::$connection->insert_id; |
223 | 223 | } |
224 | 224 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return string |
231 | 231 | */ |
232 | - public static function escapeString (string $text): string { |
|
232 | + public static function escapeString(string $text): string { |
|
233 | 233 | return self::$connection->real_escape_string($text); |
234 | 234 | } |
235 | 235 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return string |
240 | 240 | */ |
241 | - public static function error (): string { |
|
241 | + public static function error(): string { |
|
242 | 242 | return self::$connection->error; |
243 | 243 | } |
244 | 244 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return int |
249 | 249 | */ |
250 | - public static function errno (): int { |
|
250 | + public static function errno(): int { |
|
251 | 251 | return self::$connection->errno; |
252 | 252 | } |
253 | 253 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @return bool |
260 | 260 | */ |
261 | - public static function setCharset (string $charset): bool { |
|
261 | + public static function setCharset(string $charset): bool { |
|
262 | 262 | return self::$connection->set_charset($charset); |
263 | 263 | } |
264 | 264 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return mysqli_result|bool |
275 | 275 | */ |
276 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
276 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
277 | 277 | return self::$connection->query($query); |
278 | 278 | } |
279 | 279 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @return mysqli_result|bool |
296 | 296 | */ |
297 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
297 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
298 | 298 | if (empty($vars)) { |
299 | 299 | return self::pureQuery($query); |
300 | 300 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | $types .= 's'; |
312 | 312 | } |
313 | 313 | } |
314 | - $prepare->bind_param($types,...$vars); |
|
314 | + $prepare->bind_param($types, ...$vars); |
|
315 | 315 | if (!$prepare->execute()) { |
316 | 316 | logger::write(loggerTypes::WARNING, $prepare->error); |
317 | 317 | return false; |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | else { |
359 | 359 | $query .= ' AND'; |
360 | 360 | } |
361 | - $operator = substr($sub_value,0,2); |
|
362 | - $operator_value = substr($sub_value,2); |
|
361 | + $operator = substr($sub_value, 0, 2); |
|
362 | + $operator_value = substr($sub_value, 2); |
|
363 | 363 | switch ($operator) { |
364 | 364 | case '>=': |
365 | 365 | $query .= " `$name` >= ?"; |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | $sub_value = $operator_value; |
387 | 387 | break; |
388 | 388 | case '##': |
389 | - $operator = substr($operator_value,0,2); |
|
390 | - $column = substr($operator_value,2); |
|
389 | + $operator = substr($operator_value, 0, 2); |
|
390 | + $column = substr($operator_value, 2); |
|
391 | 391 | $query .= match ($operator) { |
392 | 392 | '>=' => " `$name` >= `$column`", |
393 | 393 | '<=' => " `$name` <= `$column`", |
@@ -411,17 +411,17 @@ discard block |
||
411 | 411 | return $values; |
412 | 412 | } |
413 | 413 | |
414 | - private static function groupByBuilder(string &$query, string|array $group_by = []): void { |
|
414 | + private static function groupByBuilder(string &$query, string | array $group_by = []): void { |
|
415 | 415 | if (empty($group_by)) { |
416 | 416 | return; |
417 | 417 | } |
418 | 418 | if (is_string($group_by)) { |
419 | 419 | $group_by = [$group_by]; |
420 | 420 | } |
421 | - $query .= ' GROUP BY `' . implode('`, `',$group_by) . '`'; |
|
421 | + $query .= ' GROUP BY `'.implode('`, `', $group_by).'`'; |
|
422 | 422 | } |
423 | 423 | |
424 | - private static function orderByBuilder(string &$query, string|array $order_by = []): void { |
|
424 | + private static function orderByBuilder(string &$query, string | array $order_by = []): void { |
|
425 | 425 | if (empty($order_by)) { |
426 | 426 | return; |
427 | 427 | } |
@@ -474,8 +474,8 @@ discard block |
||
474 | 474 | continue; |
475 | 475 | } |
476 | 476 | |
477 | - $operator = substr($value,0,2); |
|
478 | - $operator_value = substr($value,2); |
|
477 | + $operator = substr($value, 0, 2); |
|
478 | + $operator_value = substr($value, 2); |
|
479 | 479 | switch ($operator) { |
480 | 480 | case '+=': |
481 | 481 | $query .= " `$name` = `$name` + ?"; |
@@ -508,14 +508,14 @@ discard block |
||
508 | 508 | return $values; |
509 | 509 | } |
510 | 510 | |
511 | - private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
|
512 | - $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES ('; |
|
511 | + private static function insertBuilder(string &$query, string | array $columns, array | string $values): array { |
|
512 | + $query .= '(`'.(is_string($columns) ? $columns : implode('`, `', $columns)).'`) VALUES ('; |
|
513 | 513 | if (is_string($values)) $values = [$values]; |
514 | - $query .= '?' . str_repeat(', ?', count($values) - 1) . ')'; |
|
514 | + $query .= '?'.str_repeat(', ?', count($values) - 1).')'; |
|
515 | 515 | return $values; |
516 | 516 | } |
517 | 517 | |
518 | - private static function selectBuilder (string &$query, string|array $columns): void { |
|
518 | + private static function selectBuilder(string &$query, string | array $columns): void { |
|
519 | 519 | if ($columns == '*') { |
520 | 520 | $query .= ' * '; |
521 | 521 | return; |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | $formatted = '*'; |
535 | 535 | $column = 'all'; |
536 | 536 | } |
537 | - $query .= strtoupper($function) . "($formatted) as `{$function}_$column`"; |
|
537 | + $query .= strtoupper($function)."($formatted) as `{$function}_$column`"; |
|
538 | 538 | } |
539 | 539 | else { |
540 | 540 | $query .= "`$column`"; |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | * |
560 | 560 | * @return bool |
561 | 561 | */ |
562 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
562 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
563 | 563 | $query = "DELETE FROM `$table`"; |
564 | 564 | $vars = self::whereBuilder($query, $where, $ignore_default_where); |
565 | 565 | self::countBuilder($query, $count, $offset); |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * |
580 | 580 | * @return bool |
581 | 581 | */ |
582 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
582 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
583 | 583 | $query = "UPDATE `$table` SET"; |
584 | 584 | $modify_vars = self::updateBuilder($query, $modify); |
585 | 585 | $where_vars = self::whereBuilder($query, $where, $ignore_default_where); |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * |
599 | 599 | * @return bool |
600 | 600 | */ |
601 | - public static function insert (string $table, string|array $columns, array|string $values): bool { |
|
601 | + public static function insert(string $table, string | array $columns, array | string $values): bool { |
|
602 | 602 | $query = "INSERT INTO `$table`"; |
603 | 603 | $values = self::insertBuilder($query, $columns, $values); |
604 | 604 | return self::query($query, $values, false); |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * |
622 | 622 | * @return bool |
623 | 623 | */ |
624 | - public static function insertUpdate (string $table, string|array $columns, array|string $values, array $modify): bool { |
|
624 | + public static function insertUpdate(string $table, string | array $columns, array | string $values, array $modify): bool { |
|
625 | 625 | $query = "INSERT INTO `$table`"; |
626 | 626 | $values = self::insertBuilder($query, $columns, $values); |
627 | 627 | $query .= ' ON DUPLICATE KEY UPDATE'; |
@@ -646,14 +646,14 @@ discard block |
||
646 | 646 | * |
647 | 647 | * @return mysqli_result|bool |
648 | 648 | */ |
649 | - public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): mysqli_result|bool { |
|
649 | + public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): mysqli_result | bool { |
|
650 | 650 | $query = 'SELECT'; |
651 | 651 | self::selectBuilder($query, $columns); |
652 | 652 | $query .= "FROM `$table`"; |
653 | - $var = self::whereBuilder($query,$where, $ignore_default_where); |
|
653 | + $var = self::whereBuilder($query, $where, $ignore_default_where); |
|
654 | 654 | self::groupByBuilder($query, $group_by); |
655 | 655 | self::orderByBuilder($query, $order_by); |
656 | - self::countBuilder($query,$count,$offset); |
|
656 | + self::countBuilder($query, $count, $offset); |
|
657 | 657 | return self::query($query, $var); |
658 | 658 | } |
659 | 659 | |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | * |
671 | 671 | * @return null|bool|array |
672 | 672 | */ |
673 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|array|null { |
|
673 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): bool | array | null { |
|
674 | 674 | $res = self::select($table, $columns, $where, 1, 0, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
675 | 675 | if ($res) { |
676 | 676 | return $res->fetch_assoc(); |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | * @param array|string $group_by group result based on these columns |
690 | 690 | * @param array|string $order_by order result based on these columns |
691 | 691 | */ |
692 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false) { |
|
692 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false) { |
|
693 | 693 | $res = self::select($table, $columns, $where, 1, 0, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
694 | 694 | if ($res) { |
695 | 695 | return $res->fetch_object(); |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | * |
714 | 714 | * @return bool|Generator |
715 | 715 | */ |
716 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator { |
|
716 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): bool | Generator { |
|
717 | 717 | $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
718 | 718 | if ($res) { |
719 | 719 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -731,10 +731,10 @@ discard block |
||
731 | 731 | * |
732 | 732 | * @return string if save is true , return file name otherwise return sql data |
733 | 733 | */ |
734 | - public static function backup (array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string { |
|
734 | + public static function backup(array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string { |
|
735 | 735 | self::setCharset('utf8mb4'); |
736 | 736 | |
737 | - $tables = array_column(self::query('SHOW TABLES')->fetch_all(),0); |
|
737 | + $tables = array_column(self::query('SHOW TABLES')->fetch_all(), 0); |
|
738 | 738 | if (!empty($wanted_tables)) { |
739 | 739 | $tables = array_intersect($tables, $wanted_tables); |
740 | 740 | } |
@@ -745,12 +745,12 @@ discard block |
||
745 | 745 | logger::write('No table founded for backup, if your database has table : check $wanted_tables argument', loggerTypes::WARNING); |
746 | 746 | } |
747 | 747 | foreach ($tables as $table) { |
748 | - $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1] . ";\n\n"; |
|
748 | + $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1].";\n\n"; |
|
749 | 749 | if ($table_data) { |
750 | 750 | $total_rows = self::query("SELECT COUNT(*) as `cnt` FROM `$table`")->fetch_object()->cnt; |
751 | 751 | for ($i = 0; $i < $total_rows; $i = $i + 1000) { |
752 | - $sql .= 'INSERT INTO ' . $table . ' VALUES'; |
|
753 | - $result = self::select($table, '*' , null, 1000, $i); |
|
752 | + $sql .= 'INSERT INTO '.$table.' VALUES'; |
|
753 | + $result = self::select($table, '*', null, 1000, $i); |
|
754 | 754 | $field_count = $result->field_count; |
755 | 755 | $affected_rows = self::affected_rows(); |
756 | 756 | $counter = 1; |
@@ -758,12 +758,12 @@ discard block |
||
758 | 758 | $sql .= "\n("; |
759 | 759 | for ($column = 0; $column < $field_count; $column++) { |
760 | 760 | $row[$column] = str_replace("\n", "\\n", addslashes($row[$column])); |
761 | - $sql .= !empty($row[$column]) ? '"' . $row[$column] . '"' : '""'; |
|
761 | + $sql .= !empty($row[$column]) ? '"'.$row[$column].'"' : '""'; |
|
762 | 762 | if ($column < $field_count - 1) { |
763 | 763 | $sql .= ','; |
764 | 764 | } |
765 | 765 | } |
766 | - $sql .= ')' . ($counter == $affected_rows ? ';' : ','); |
|
766 | + $sql .= ')'.($counter == $affected_rows ? ';' : ','); |
|
767 | 767 | $counter++; |
768 | 768 | } |
769 | 769 | } |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | } |
780 | 780 | |
781 | 781 | if (empty($file_name)) { |
782 | - $file_name = self::$db_name . time() . '.sql'; |
|
782 | + $file_name = self::$db_name.time().'.sql'; |
|
783 | 783 | } |
784 | 784 | file_put_contents($file_name, $sql); |
785 | 785 | return $file_name; |
@@ -74,17 +74,13 @@ discard block |
||
74 | 74 | if (self::$auto_process) { |
75 | 75 | if (isset(BPT::$update->message)) { |
76 | 76 | self::processMessage(BPT::$update->message); |
77 | - } |
|
78 | - elseif (isset(BPT::$update->edited_message)) { |
|
77 | + } elseif (isset(BPT::$update->edited_message)) { |
|
79 | 78 | self::processMessage(BPT::$update->edited_message); |
80 | - } |
|
81 | - elseif (isset(BPT::$update->callback_query)) { |
|
79 | + } elseif (isset(BPT::$update->callback_query)) { |
|
82 | 80 | self::processCallbackQuery(BPT::$update->callback_query); |
83 | - } |
|
84 | - elseif (isset(BPT::$update->inline_query)) { |
|
81 | + } elseif (isset(BPT::$update->inline_query)) { |
|
85 | 82 | self::processInlineQuery(BPT::$update->inline_query); |
86 | - } |
|
87 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
83 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
88 | 84 | self::processMyChatMember(BPT::$update->my_chat_member); |
89 | 85 | } |
90 | 86 | } |
@@ -141,8 +137,7 @@ discard block |
||
141 | 137 | if ($type === chatType::PRIVATE) { |
142 | 138 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
143 | 139 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
144 | - } |
|
145 | - else { |
|
140 | + } else { |
|
146 | 141 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
147 | 142 | } |
148 | 143 | } |
@@ -162,8 +157,7 @@ discard block |
||
162 | 157 | public static function addDefaultWhere (array $where): bool { |
163 | 158 | if (empty(self::$default_where)) { |
164 | 159 | self::$default_where = $where; |
165 | - } |
|
166 | - else { |
|
160 | + } else { |
|
167 | 161 | self::$default_where = array_merge(self::$default_where, $where); |
168 | 162 | } |
169 | 163 | return true; |
@@ -303,11 +297,9 @@ discard block |
||
303 | 297 | foreach ($vars as $var) { |
304 | 298 | if (is_int($var)) { |
305 | 299 | $types .= 'i'; |
306 | - } |
|
307 | - elseif (is_double($var)) { |
|
300 | + } elseif (is_double($var)) { |
|
308 | 301 | $types .= 'd'; |
309 | - } |
|
310 | - else { |
|
302 | + } else { |
|
311 | 303 | $types .= 's'; |
312 | 304 | } |
313 | 305 | } |
@@ -335,8 +327,7 @@ discard block |
||
335 | 327 | foreach ($where as $name => $value) { |
336 | 328 | if ($first) { |
337 | 329 | $first = false; |
338 | - } |
|
339 | - else { |
|
330 | + } else { |
|
340 | 331 | $query .= ' AND'; |
341 | 332 | } |
342 | 333 | |
@@ -354,8 +345,7 @@ discard block |
||
354 | 345 | foreach ($value as $sub_value) { |
355 | 346 | if ($sub_first) { |
356 | 347 | $sub_first = false; |
357 | - } |
|
358 | - else { |
|
348 | + } else { |
|
359 | 349 | $query .= ' AND'; |
360 | 350 | } |
361 | 351 | $operator = substr($sub_value,0,2); |
@@ -435,8 +425,7 @@ discard block |
||
435 | 425 | foreach ($order_by as $key => $mode) { |
436 | 426 | if ($first) { |
437 | 427 | $first = false; |
438 | - } |
|
439 | - else { |
|
428 | + } else { |
|
440 | 429 | $query .= ', '; |
441 | 430 | } |
442 | 431 | if (is_numeric($key)) { |
@@ -450,8 +439,7 @@ discard block |
||
450 | 439 | private static function countBuilder(string &$query, int $count = null, int $offset = null): void { |
451 | 440 | if (!empty($count)) { |
452 | 441 | $query .= !empty($offset) ? " LIMIT $offset, $count" : " LIMIT $count"; |
453 | - } |
|
454 | - elseif (!empty($offset)) { |
|
442 | + } elseif (!empty($offset)) { |
|
455 | 443 | $query .= " OFFSET $offset"; |
456 | 444 | } |
457 | 445 | } |
@@ -463,8 +451,7 @@ discard block |
||
463 | 451 | foreach ($modify as $name => $value) { |
464 | 452 | if ($first) { |
465 | 453 | $first = false; |
466 | - } |
|
467 | - else { |
|
454 | + } else { |
|
468 | 455 | $query .= ','; |
469 | 456 | } |
470 | 457 | |
@@ -510,7 +497,9 @@ discard block |
||
510 | 497 | |
511 | 498 | private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
512 | 499 | $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES ('; |
513 | - if (is_string($values)) $values = [$values]; |
|
500 | + if (is_string($values)) { |
|
501 | + $values = [$values]; |
|
502 | + } |
|
514 | 503 | $query .= '?' . str_repeat(', ?', count($values) - 1) . ')'; |
515 | 504 | return $values; |
516 | 505 | } |
@@ -535,8 +524,7 @@ discard block |
||
535 | 524 | $column = 'all'; |
536 | 525 | } |
537 | 526 | $query .= strtoupper($function) . "($formatted) as `{$function}_$column`"; |
538 | - } |
|
539 | - else { |
|
527 | + } else { |
|
540 | 528 | $query .= "`$column`"; |
541 | 529 | } |
542 | 530 | |
@@ -716,9 +704,12 @@ discard block |
||
716 | 704 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator { |
717 | 705 | $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
718 | 706 | if ($res) { |
719 | - while ($row = $res->fetch_assoc()) yield $row; |
|
707 | + while ($row = $res->fetch_assoc()) { |
|
708 | + yield $row; |
|
709 | + } |
|
710 | + } else { |
|
711 | + return $res; |
|
720 | 712 | } |
721 | - else return $res; |
|
722 | 713 | } |
723 | 714 | |
724 | 715 | /** |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | if (settings::$telegram_verify) { |
35 | 35 | $ip = $ip ?? tools::remoteIP(); |
36 | 36 | if (!tools::isTelegram($ip)) { |
37 | - logger::write('not authorized access denied. IP : '. $ip ?? 'unknown',loggerTypes::WARNING); |
|
37 | + logger::write('not authorized access denied. IP : '.$ip ?? 'unknown', loggerTypes::WARNING); |
|
38 | 38 | BPT::exit(); |
39 | 39 | } |
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | - protected static function processUpdate(string|stdClass|update $update = null): void { |
|
43 | + protected static function processUpdate(string | stdClass | update $update = null): void { |
|
44 | 44 | if (!is_object($update)) { |
45 | 45 | $update = json_decode($update ?? file_get_contents('php://input')); |
46 | 46 | if (!$update) { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - if (!is_a($update,'update')) { |
|
58 | + if (!is_a($update, 'update')) { |
|
59 | 59 | $update = new update($update); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | db::save(); |
67 | 67 | } |
68 | 68 | |
69 | - protected static function setMessageExtra (update &$update): void { |
|
69 | + protected static function setMessageExtra(update & $update): void { |
|
70 | 70 | if (!isset($update->message->text) && !isset($update->edited_message->text)) { |
71 | 71 | return; |
72 | 72 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | BPT::$handler->something_else(BPT::$update); |
143 | 143 | } |
144 | 144 | else { |
145 | - logger::write('Update received but handlers are not set',loggerTypes::WARNING); |
|
145 | + logger::write('Update received but handlers are not set', loggerTypes::WARNING); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 |
@@ -97,51 +97,41 @@ |
||
97 | 97 | if (self::handlerExist('message')) { |
98 | 98 | BPT::$handler->message(BPT::$update->message); |
99 | 99 | } |
100 | - } |
|
101 | - elseif (isset(BPT::$update->edited_message)) { |
|
100 | + } elseif (isset(BPT::$update->edited_message)) { |
|
102 | 101 | if (self::handlerExist('edited_message')) { |
103 | 102 | BPT::$handler->edited_message(BPT::$update->edited_message); |
104 | 103 | } |
105 | - } |
|
106 | - elseif (isset(BPT::$update->channel_post)) { |
|
104 | + } elseif (isset(BPT::$update->channel_post)) { |
|
107 | 105 | if (self::handlerExist('channel_post')) { |
108 | 106 | BPT::$handler->channel_post(BPT::$update->channel_post); |
109 | 107 | } |
110 | - } |
|
111 | - elseif (isset(BPT::$update->edited_channel_post)) { |
|
108 | + } elseif (isset(BPT::$update->edited_channel_post)) { |
|
112 | 109 | if (self::handlerExist('edited_channel_post')) { |
113 | 110 | BPT::$handler->edited_channel_post(BPT::$update->edited_channel_post); |
114 | 111 | } |
115 | - } |
|
116 | - elseif (isset(BPT::$update->inline_query)) { |
|
112 | + } elseif (isset(BPT::$update->inline_query)) { |
|
117 | 113 | if (self::handlerExist('inline_query')) { |
118 | 114 | BPT::$handler->inline_query(BPT::$update->inline_query); |
119 | 115 | } |
120 | - } |
|
121 | - elseif (isset(BPT::$update->callback_query)) { |
|
116 | + } elseif (isset(BPT::$update->callback_query)) { |
|
122 | 117 | if (self::handlerExist('callback_query')) { |
123 | 118 | BPT::$handler->callback_query(BPT::$update->callback_query); |
124 | 119 | } |
125 | - } |
|
126 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
120 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
127 | 121 | if (self::handlerExist('my_chat_member')) { |
128 | 122 | BPT::$handler->my_chat_member(BPT::$update->my_chat_member); |
129 | 123 | } |
130 | - } |
|
131 | - elseif (isset(BPT::$update->chat_member)) { |
|
124 | + } elseif (isset(BPT::$update->chat_member)) { |
|
132 | 125 | if (self::handlerExist('chat_member')) { |
133 | 126 | BPT::$handler->chat_member(BPT::$update->chat_member); |
134 | 127 | } |
135 | - } |
|
136 | - elseif (isset(BPT::$update->chat_join_request)) { |
|
128 | + } elseif (isset(BPT::$update->chat_join_request)) { |
|
137 | 129 | if (self::handlerExist('chat_join_request')) { |
138 | 130 | BPT::$handler->chat_join_request(BPT::$update->chat_join_request); |
139 | 131 | } |
140 | - } |
|
141 | - elseif (self::handlerExist('something_else')) { |
|
132 | + } elseif (self::handlerExist('something_else')) { |
|
142 | 133 | BPT::$handler->something_else(BPT::$update); |
143 | - } |
|
144 | - else { |
|
134 | + } else { |
|
145 | 135 | logger::write('Update received but handlers are not set',loggerTypes::WARNING); |
146 | 136 | } |
147 | 137 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * tools class , gather what ever you need |
31 | 31 | */ |
32 | -class tools{ |
|
32 | +class tools { |
|
33 | 33 | /** |
34 | 34 | * Check the given username format |
35 | 35 | * |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public static function isUsername (string $username): bool { |
|
44 | + public static function isUsername(string $username): bool { |
|
45 | 45 | $length = strlen($username); |
46 | 46 | return !str_contains($username, '__') && $length >= 4 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username); |
47 | 47 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return bool |
60 | 60 | */ |
61 | - public static function ipInRange (string $ip, string $range): bool { |
|
61 | + public static function ipInRange(string $ip, string $range): bool { |
|
62 | 62 | if (!str_contains($range, '/')) { |
63 | 63 | $range .= '/32'; |
64 | 64 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public static function isTelegram (string $ip): bool { |
|
81 | + public static function isTelegram(string $ip): bool { |
|
82 | 82 | return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22'); |
83 | 83 | } |
84 | 84 | |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return bool |
95 | 95 | */ |
96 | - public static function isCloudFlare (string $ip): bool { |
|
96 | + public static function isCloudFlare(string $ip): bool { |
|
97 | 97 | $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', '104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22']; |
98 | 98 | foreach ($cf_ips as $cf_ip) { |
99 | - if (self::ipInRange($ip,$cf_ip)) { |
|
99 | + if (self::ipInRange($ip, $cf_ip)) { |
|
100 | 100 | return true; |
101 | 101 | } |
102 | 102 | } |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return bool |
116 | 116 | */ |
117 | - public static function isArvanCloud (string $ip): bool { |
|
117 | + public static function isArvanCloud(string $ip): bool { |
|
118 | 118 | $ar_ips = ['185.143.232.0/22', '92.114.16.80/28', '2.146.0.0/28', '46.224.2.32/29', '89.187.178.96/29', '195.181.173.128/29', '89.187.169.88/29', '188.229.116.16/29', '83.123.255.56/31', '164.138.128.28/31', '94.182.182.28/30', '185.17.115.176/30', '5.213.255.36/31', '138.128.139.144/29', '5.200.14.8/29', '188.122.68.224/29', '188.122.83.176/29', '213.179.217.16/29', '185.179.201.192/29', '43.239.139.192/29', '213.179.197.16/29', '213.179.201.192/29', '109.200.214.248/29', '138.128.141.16/29', '188.122.78.136/29', '213.179.211.32/29', '103.194.164.24/29', '185.50.105.136/29', '213.179.213.16/29', '162.244.52.120/29', '188.122.80.240/29', '109.200.195.64/29', '109.200.199.224/29', '185.228.238.0/28', '94.182.153.24/29', '94.101.182.0/27', '37.152.184.208/28', '78.39.156.192/28', '158.255.77.238/31', '81.12.28.16/29', '176.65.192.202/31', '2.144.3.128/28', '89.45.48.64/28', '37.32.16.0/27', '37.32.17.0/27', '37.32.18.0/27']; |
119 | 119 | foreach ($ar_ips as $ar_ip) { |
120 | - if (self::ipInRange($ip,$ar_ip)) { |
|
120 | + if (self::ipInRange($ip, $ar_ip)) { |
|
121 | 121 | return true; |
122 | 122 | } |
123 | 123 | } |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return bool|user return array when verify is active and token is true array of telegram getMe result |
139 | 139 | */ |
140 | - public static function isToken (string $token, bool $verify = false): bool|user { |
|
140 | + public static function isToken(string $token, bool $verify = false): bool | user { |
|
141 | 141 | if (!preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) { |
142 | 142 | return false; |
143 | 143 | } |
144 | - if (!$verify){ |
|
144 | + if (!$verify) { |
|
145 | 145 | return true; |
146 | 146 | } |
147 | 147 | $res = telegram::me($token); |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool { |
|
174 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool { |
|
175 | 175 | if (!is_array($ids)) { |
176 | 176 | $ids = [$ids]; |
177 | 177 | } |
178 | 178 | $user_id = $user_id ?? request::catchFields('user_id'); |
179 | 179 | |
180 | 180 | foreach ($ids as $id) { |
181 | - $check = telegram::getChatMember($id,$user_id); |
|
181 | + $check = telegram::getChatMember($id, $user_id); |
|
182 | 182 | if (telegram::$status) { |
183 | 183 | $check = $check->status; |
184 | 184 | if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) { |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return array keys will be id and values will be bool(null for not founded ids) |
207 | 207 | */ |
208 | - public static function joinChecker (array|string|int $ids , int|null $user_id = null): array { |
|
208 | + public static function joinChecker(array | string | int $ids, int | null $user_id = null): array { |
|
209 | 209 | if (!is_array($ids)) { |
210 | 210 | $ids = [$ids]; |
211 | 211 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | $result = []; |
215 | 215 | foreach ($ids as $id) { |
216 | - $check = telegram::getChatMember($id,$user_id); |
|
216 | + $check = telegram::getChatMember($id, $user_id); |
|
217 | 217 | if (telegram::$status) { |
218 | 218 | $check = $check->status; |
219 | 219 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @return bool |
234 | 234 | */ |
235 | 235 | public static function isShorted(string $text): bool{ |
236 | - return preg_match('/^[a-zA-Z0-9]+$/',$text); |
|
236 | + return preg_match('/^[a-zA-Z0-9]+$/', $text); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
253 | 253 | */ |
254 | - public static function size (string $path, bool $format = true, bool $space_between = true): string|int|false { |
|
254 | + public static function size(string $path, bool $format = true, bool $space_between = true): string | int | false { |
|
255 | 255 | if (filter_var($path, FILTER_VALIDATE_URL)) { |
256 | 256 | $ch = curl_init($path); |
257 | 257 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $size = file_exists($path) ? filesize($path) : false; |
267 | 267 | } |
268 | 268 | if (isset($size) && is_numeric($size)) { |
269 | - return $format ? tools::byteFormat($size, space_between: $space_between) : $size; |
|
269 | + return $format ? tools::byteFormat($size, space_between : $space_between) : $size; |
|
270 | 270 | } |
271 | 271 | return false; |
272 | 272 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * @return bool |
285 | 285 | * @throws bptException |
286 | 286 | */ |
287 | - public static function delete (string $path, bool $sub = true): bool { |
|
287 | + public static function delete(string $path, bool $sub = true): bool { |
|
288 | 288 | $path = realpath($path); |
289 | 289 | if (!is_dir($path)) { |
290 | 290 | return unlink($path); |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | return rmdir($path); |
294 | 294 | } |
295 | 295 | if (!$sub) { |
296 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
296 | + logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR); |
|
297 | 297 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
298 | 298 | } |
299 | 299 | $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @return bool |
316 | 316 | * @throws bptException when zip extension not found |
317 | 317 | */ |
318 | - public static function zip (string $path, string $destination): bool { |
|
318 | + public static function zip(string $path, string $destination): bool { |
|
319 | 319 | if (!extension_loaded('zip')) { |
320 | 320 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
321 | 321 | throw new bptException('ZIP_EXTENSION_MISSING'); |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return bool true on success and false in failure |
352 | 352 | */ |
353 | - public static function downloadFile (string $url, string $path, int $chunk_size = 512): bool { |
|
353 | + public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool { |
|
354 | 354 | $file = fopen($url, 'rb'); |
355 | 355 | if (!$file) return false; |
356 | 356 | $path = fopen($path, 'wb'); |
357 | 357 | if (!$path) return false; |
358 | 358 | |
359 | 359 | $length = $chunk_size * 1024; |
360 | - while (!feof($file)){ |
|
360 | + while (!feof($file)) { |
|
361 | 361 | fwrite($path, fread($file, $length), $length); |
362 | 362 | } |
363 | 363 | fclose($path); |
@@ -380,10 +380,10 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return string |
382 | 382 | */ |
383 | - public static function byteFormat (int $byte, int $precision = 2, bool $space_between = true): string { |
|
383 | + public static function byteFormat(int $byte, int $precision = 2, bool $space_between = true): string { |
|
384 | 384 | $rate_counter = 0; |
385 | 385 | |
386 | - while ($byte > 1024){ |
|
386 | + while ($byte > 1024) { |
|
387 | 387 | $byte /= 1024; |
388 | 388 | $rate_counter++; |
389 | 389 | } |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | $byte = round($byte, $precision); |
393 | 393 | } |
394 | 394 | |
395 | - return $byte . ($space_between ? ' ' : '') . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
395 | + return $byte.($space_between ? ' ' : '').['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -409,10 +409,10 @@ discard block |
||
409 | 409 | * |
410 | 410 | * @return string|false return false when mode is incorrect |
411 | 411 | */ |
412 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
412 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
413 | 413 | return match ($mode) { |
414 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
415 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
414 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
415 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
416 | 416 | parseMode::MARKDOWNV2 => str_replace( |
417 | 417 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
418 | 418 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
452 | 452 | * @throws Exception |
453 | 453 | */ |
454 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
454 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
455 | 455 | $base_time = new DateTime($base_time ?? '@'.time()); |
456 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
456 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
457 | 457 | |
458 | 458 | $diff = $base_time->diff($target_time); |
459 | 459 | |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @return string[]|string |
482 | 482 | */ |
483 | - public static function realEscapeString(string|array $input): string|array { |
|
484 | - if(is_array($input)) { |
|
483 | + public static function realEscapeString(string | array $input): string | array { |
|
484 | + if (is_array($input)) { |
|
485 | 485 | return array_map(__METHOD__, $input); |
486 | 486 | } |
487 | 487 | |
488 | - if(!empty($input) && is_string($input)) { |
|
488 | + if (!empty($input) && is_string($input)) { |
|
489 | 489 | return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input); |
490 | 490 | } |
491 | 491 | |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * |
504 | 504 | * @return string[]|string |
505 | 505 | */ |
506 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
506 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
507 | 507 | $pos = strpos($subject, $search); |
508 | 508 | if ($pos !== false) { |
509 | 509 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * |
521 | 521 | * @return string see possible values in fileType class |
522 | 522 | */ |
523 | - public static function fileType (string $file_id): string { |
|
523 | + public static function fileType(string $file_id): string { |
|
524 | 524 | $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '=')); |
525 | 525 | $new = ''; |
526 | 526 | $last = ''; |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | $last = $char; |
535 | 535 | } |
536 | 536 | } |
537 | - $data = unpack('VtypeId/Vdc_id', $new . $last); |
|
537 | + $data = unpack('VtypeId/Vdc_id', $new.$last); |
|
538 | 538 | $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216; |
539 | 539 | return [ |
540 | 540 | fileTypes::THUMBNAIL, |
@@ -572,10 +572,10 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return string |
574 | 574 | */ |
575 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
575 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
576 | 576 | $rand_string = ''; |
577 | 577 | $char_len = strlen($characters) - 1; |
578 | - for ($i = 0; $i < $length; $i ++) { |
|
578 | + for ($i = 0; $i < $length; $i++) { |
|
579 | 579 | $rand_string .= $characters[rand(0, $char_len)]; |
580 | 580 | } |
581 | 581 | return $rand_string; |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
605 | 605 | * @throws bptException |
606 | 606 | */ |
607 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
607 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
608 | 608 | if (!empty($keyboard)) { |
609 | 609 | $keyboard_object = new replyKeyboardMarkup(); |
610 | 610 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | $keyboard_object->setInline_keyboard($rows); |
668 | 668 | return $keyboard_object; |
669 | 669 | } |
670 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
670 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
671 | 671 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
672 | 672 | } |
673 | 673 | |
@@ -683,10 +683,10 @@ discard block |
||
683 | 683 | * |
684 | 684 | * @return string |
685 | 685 | */ |
686 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
686 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
687 | 687 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
688 | 688 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
689 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
689 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
@@ -710,9 +710,9 @@ discard block |
||
710 | 710 | * @return string|bool|array{hash:string, key:string, iv:string} |
711 | 711 | * @throws bptException |
712 | 712 | */ |
713 | - public static function codec (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
713 | + public static function codec(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
714 | 714 | if (!extension_loaded('openssl')) { |
715 | - logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
715 | + logger::write("tools::codec function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
716 | 716 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
717 | 717 | } |
718 | 718 | if ($action === codecAction::ENCRYPT) { |
@@ -723,16 +723,16 @@ discard block |
||
723 | 723 | } |
724 | 724 | if ($action === codecAction::DECRYPT) { |
725 | 725 | if (empty($key)) { |
726 | - logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR); |
|
726 | + logger::write("tools::codec function used\nkey parameter is not set", loggerTypes::ERROR); |
|
727 | 727 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
728 | 728 | } |
729 | 729 | if (empty($iv)) { |
730 | - logger::write("tools::codec function used\niv parameter is not set",loggerTypes::ERROR); |
|
730 | + logger::write("tools::codec function used\niv parameter is not set", loggerTypes::ERROR); |
|
731 | 731 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
732 | 732 | } |
733 | 733 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
734 | 734 | } |
735 | - logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
735 | + logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
736 | 736 | return false; |
737 | 737 | } |
738 | 738 | |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | public static function shortEncode(int $num): string { |
749 | 749 | $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
750 | 750 | $array = []; |
751 | - while ($num > 0){ |
|
751 | + while ($num > 0) { |
|
752 | 752 | $array[] = $num % 62; |
753 | 753 | $num = floor($num / 62); |
754 | 754 | } |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | foreach ($array as &$value) { |
757 | 757 | $value = $codes[$value]; |
758 | 758 | } |
759 | - return strrev(implode('',$array)); |
|
759 | + return strrev(implode('', $array)); |
|
760 | 760 | } |
761 | 761 | |
762 | 762 | /** |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | $num = 0; |
774 | 774 | $text = str_split(strrev($text)); |
775 | 775 | foreach ($text as $key=>$value) { |
776 | - $num += strpos($codes,$value) * pow(62,$key); |
|
776 | + $num += strpos($codes, $value) * pow(62, $key); |
|
777 | 777 | } |
778 | 778 | return $num; |
779 | 779 | } |
@@ -217,8 +217,9 @@ discard block |
||
217 | 217 | if (telegram::$status) { |
218 | 218 | $check = $check->status; |
219 | 219 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
220 | + } else { |
|
221 | + $result[$id] = null; |
|
220 | 222 | } |
221 | - else $result[$id] = null; |
|
222 | 223 | } |
223 | 224 | return $result; |
224 | 225 | } |
@@ -260,8 +261,7 @@ discard block |
||
260 | 261 | curl_exec($ch); |
261 | 262 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
262 | 263 | curl_close($ch); |
263 | - } |
|
264 | - else { |
|
264 | + } else { |
|
265 | 265 | $path = realpath($path); |
266 | 266 | $size = file_exists($path) ? filesize($path) : false; |
267 | 267 | } |
@@ -332,8 +332,7 @@ discard block |
||
332 | 332 | $zip->addFile($filePath, substr($filePath, $root_len)); |
333 | 333 | } |
334 | 334 | } |
335 | - } |
|
336 | - else { |
|
335 | + } else { |
|
337 | 336 | $zip->addFile($path, basename($path)); |
338 | 337 | } |
339 | 338 | return $zip->close(); |
@@ -352,9 +351,13 @@ discard block |
||
352 | 351 | */ |
353 | 352 | public static function downloadFile (string $url, string $path, int $chunk_size = 512): bool { |
354 | 353 | $file = fopen($url, 'rb'); |
355 | - if (!$file) return false; |
|
354 | + if (!$file) { |
|
355 | + return false; |
|
356 | + } |
|
356 | 357 | $path = fopen($path, 'wb'); |
357 | - if (!$path) return false; |
|
358 | + if (!$path) { |
|
359 | + return false; |
|
360 | + } |
|
358 | 361 | |
359 | 362 | $length = $chunk_size * 1024; |
360 | 363 | while (!feof($file)){ |
@@ -461,8 +464,9 @@ discard block |
||
461 | 464 | foreach ($string as $k => &$v) { |
462 | 465 | if ($diff->$v) { |
463 | 466 | $v = $diff->$v; |
467 | + } else { |
|
468 | + unset($string[$k]); |
|
464 | 469 | } |
465 | - else unset($string[$k]); |
|
466 | 470 | } |
467 | 471 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
468 | 472 | |
@@ -528,8 +532,7 @@ discard block |
||
528 | 532 | if ($last === "\0") { |
529 | 533 | $new .= str_repeat($last, ord($char)); |
530 | 534 | $last = ''; |
531 | - } |
|
532 | - else { |
|
535 | + } else { |
|
533 | 536 | $new .= $last; |
534 | 537 | $last = $char; |
535 | 538 | } |
@@ -613,7 +616,9 @@ discard block |
||
613 | 616 | } |
614 | 617 | $rows = []; |
615 | 618 | foreach ($keyboard as $row) { |
616 | - if (!is_array($row)) continue; |
|
619 | + if (!is_array($row)) { |
|
620 | + continue; |
|
621 | + } |
|
617 | 622 | $buttons = []; |
618 | 623 | foreach ($row as $base_button) { |
619 | 624 | $button_info = explode('||', $base_button); |
@@ -622,15 +627,12 @@ discard block |
||
622 | 627 | if (count($button_info) > 1) { |
623 | 628 | if ($button_info[1] === 'con') { |
624 | 629 | $button->setRequest_contact(true); |
625 | - } |
|
626 | - elseif ($button_info[1] === 'loc') { |
|
630 | + } elseif ($button_info[1] === 'loc') { |
|
627 | 631 | $button->setRequest_location(true); |
628 | - } |
|
629 | - elseif ($button_info[1] === 'poll') { |
|
632 | + } elseif ($button_info[1] === 'poll') { |
|
630 | 633 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
631 | 634 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
632 | - } |
|
633 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
635 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
634 | 636 | $url = $button_info[2]; |
635 | 637 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
636 | 638 | } |
@@ -652,12 +654,10 @@ discard block |
||
652 | 654 | if (isset($button_info[1])) { |
653 | 655 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
654 | 656 | $button->setText($button_info[0])->setUrl($button_info[1]); |
655 | - } |
|
656 | - else { |
|
657 | + } else { |
|
657 | 658 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
658 | 659 | } |
659 | - } |
|
660 | - else { |
|
660 | + } else { |
|
661 | 661 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
662 | 662 | } |
663 | 663 | $buttons[] = $button; |
@@ -684,8 +684,12 @@ discard block |
||
684 | 684 | * @return string |
685 | 685 | */ |
686 | 686 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
687 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
688 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
687 | + if (empty($user_id)) { |
|
688 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
689 | + } |
|
690 | + if (empty($bot_username)) { |
|
691 | + $bot_username = telegram::getMe()->username; |
|
692 | + } |
|
689 | 693 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
690 | 694 | } |
691 | 695 | |
@@ -752,7 +756,9 @@ discard block |
||
752 | 756 | $array[] = $num % 62; |
753 | 757 | $num = floor($num / 62); |
754 | 758 | } |
755 | - if (count($array) < 1) $array = [0]; |
|
759 | + if (count($array) < 1) { |
|
760 | + $array = [0]; |
|
761 | + } |
|
756 | 762 | foreach ($array as &$value) { |
757 | 763 | $value = $codes[$value]; |
758 | 764 | } |