@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @Version: 2.76 =>[ 1399/11/28 = 1442/07/04 = 2021/02/16 ] |
11 | 11 | */ |
12 | 12 | class jdf { |
13 | - public static function jdate ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
13 | + public static function jdate($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
14 | 14 | $T_sec = 0; |
15 | 15 | if ($time_zone != 'local') { |
16 | 16 | date_default_timezone_set(empty($time_zone) ? 'Asia/Tehran' : $time_zone); |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | $output .= (int) ($jalali_month / 3.1) + 1; |
57 | 57 | break; |
58 | 58 | case 'c': |
59 | - $output .= $jalali_year . '/' . $jalali_month . '/' . $jalali_day . ' ،' . $date[0] . ':' . $date[1] . ':' . $date[6] . ' ' . $date[5]; |
|
59 | + $output .= $jalali_year.'/'.$jalali_month.'/'.$jalali_day.' ،'.$date[0].':'.$date[1].':'.$date[6].' '.$date[5]; |
|
60 | 60 | break; |
61 | 61 | case 'C': |
62 | 62 | $output .= (int) (($jalali_year + 99) / 100); |
63 | 63 | break; |
64 | 64 | case 'd': |
65 | - $output .= $jalali_day < 10 ? '0' . $jalali_day : $jalali_day; |
|
65 | + $output .= $jalali_day < 10 ? '0'.$jalali_day : $jalali_day; |
|
66 | 66 | break; |
67 | 67 | case 'D': |
68 | 68 | $output .= self::jdate_words(['kh' => $date[7]], ' '); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $output .= $leap_year; |
99 | 99 | break; |
100 | 100 | case 'm': |
101 | - $output .= $jalali_month > 9 ? $jalali_month : '0' . $jalali_month; |
|
101 | + $output .= $jalali_month > 9 ? $jalali_month : '0'.$jalali_month; |
|
102 | 102 | break; |
103 | 103 | case 'M': |
104 | 104 | $output .= self::jdate_words(['km' => $jalali_month], ' '); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | break; |
132 | 132 | case 'r': |
133 | 133 | $key = self::jdate_words(['rh' => $date[7], 'mm' => $jalali_month]); |
134 | - $output .= $date[0] . ':' . $date[1] . ':' . $date[6] . ' ' . $date[4] . ' ' . $key['rh'] . '، ' . $jalali_day . ' ' . $key['mm'] . ' ' . $jalali_year; |
|
134 | + $output .= $date[0].':'.$date[1].':'.$date[6].' '.$date[4].' '.$key['rh'].'، '.$jalali_day.' '.$key['mm'].' '.$jalali_year; |
|
135 | 135 | break; |
136 | 136 | case 's': |
137 | 137 | $output .= $date[6]; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | if ($aks == 7) { |
169 | 169 | $aks = 0; |
170 | 170 | } |
171 | - $output .= ($leap_year + 363 - $doy < $aks and $aks < 3) ? '01' : ($num < 10 ? '0' . $num : $num); |
|
171 | + $output .= ($leap_year + 363 - $doy < $aks and $aks < 3) ? '01' : ($num < 10 ? '0'.$num : $num); |
|
172 | 172 | break; |
173 | 173 | case 'y': |
174 | 174 | $output .= substr($jalali_year, 2, 2); |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | } |
186 | 186 | return $tr_num != 'en' ? self::tr_num($output, 'fa', '.') : $output; |
187 | 187 | } |
188 | - public static function jstrftime ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
189 | - $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
|
188 | + public static function jstrftime($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
189 | + $T_sec = 0; /* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
|
190 | 190 | if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
191 | 191 | $timestamp = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
192 | 192 | $date = explode('_', date('h_H_i_j_n_s_w_Y', $timestamp)); |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | $output .= self::jdate_words(['rh' => $date[6]], ' '); |
214 | 214 | break; |
215 | 215 | case 'd': |
216 | - $output .= ($jalali_day < 10) ? '0' . $jalali_day : $jalali_day; |
|
216 | + $output .= ($jalali_day < 10) ? '0'.$jalali_day : $jalali_day; |
|
217 | 217 | break; |
218 | 218 | case 'e': |
219 | - $output .= ($jalali_day < 10) ? ' ' . $jalali_day : $jalali_day; |
|
219 | + $output .= ($jalali_day < 10) ? ' '.$jalali_day : $jalali_day; |
|
220 | 220 | break; |
221 | 221 | case 'j': |
222 | 222 | $output .= str_pad($doy + 1, 3, 0, STR_PAD_LEFT); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | if ($avs < 0) $avs += 7; |
233 | 233 | $num = (int) (($doy + $avs) / 7) + 1; |
234 | 234 | if ($avs > 3 or $avs == 1) $num--; |
235 | - $output .= ($num < 10) ? '0' . $num : $num; |
|
235 | + $output .= ($num < 10) ? '0'.$num : $num; |
|
236 | 236 | break; |
237 | 237 | case 'V': |
238 | 238 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | } |
247 | 247 | $aks = $avs + $leap_year; |
248 | 248 | if ($aks == 7) $aks = 0; |
249 | - $output .= (($leap_year + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
|
249 | + $output .= (($leap_year + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0'.$num : $num); |
|
250 | 250 | break; |
251 | 251 | case 'W': |
252 | 252 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
253 | 253 | if ($avs < 0) $avs += 7; |
254 | 254 | $num = (int) (($doy + $avs) / 7) + 1; |
255 | 255 | if ($avs > 3) $num--; |
256 | - $output .= ($num < 10) ? '0' . $num : $num; |
|
256 | + $output .= ($num < 10) ? '0'.$num : $num; |
|
257 | 257 | break; |
258 | 258 | /* Month */ case 'b': |
259 | 259 | case 'h': |
@@ -263,11 +263,11 @@ discard block |
||
263 | 263 | $output .= self::jdate_words(['mm' => $jalali_month], ' '); |
264 | 264 | break; |
265 | 265 | case 'm': |
266 | - $output .= ($jalali_month > 9) ? $jalali_month : '0' . $jalali_month; |
|
266 | + $output .= ($jalali_month > 9) ? $jalali_month : '0'.$jalali_month; |
|
267 | 267 | break; |
268 | 268 | /* Year */ case 'C': |
269 | 269 | $tmp = (int) ($jalali_year / 100); |
270 | - $output .= ($tmp > 9) ? $tmp : '0' . $tmp; |
|
270 | + $output .= ($tmp > 9) ? $tmp : '0'.$tmp; |
|
271 | 271 | break; |
272 | 272 | case 'g': |
273 | 273 | $jdw = ($date[6] == 6) ? 0 : $date[6] + 1; |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $output .= $date[0]; |
293 | 293 | break; |
294 | 294 | case 'l': |
295 | - $output .= ($date[0] > 9) ? $date[0] : ' ' . (int) $date[0]; |
|
295 | + $output .= ($date[0] > 9) ? $date[0] : ' '.(int) $date[0]; |
|
296 | 296 | break; |
297 | 297 | case 'M': |
298 | 298 | $output .= $date[2]; |
@@ -304,19 +304,19 @@ discard block |
||
304 | 304 | $output .= ($date[1] < 12) ? 'ق.ظ' : 'ب.ظ'; |
305 | 305 | break; |
306 | 306 | case 'r': |
307 | - $output .= $date[0] . ':' . $date[2] . ':' . $date[5] . ' ' . (($date[1] < 12) ? 'قبل از ظهر' : 'بعد از ظهر'); |
|
307 | + $output .= $date[0].':'.$date[2].':'.$date[5].' '.(($date[1] < 12) ? 'قبل از ظهر' : 'بعد از ظهر'); |
|
308 | 308 | break; |
309 | 309 | case 'R': |
310 | - $output .= $date[1] . ':' . $date[2]; |
|
310 | + $output .= $date[1].':'.$date[2]; |
|
311 | 311 | break; |
312 | 312 | case 'S': |
313 | 313 | $output .= $date[5]; |
314 | 314 | break; |
315 | 315 | case 'T': |
316 | - $output .= $date[1] . ':' . $date[2] . ':' . $date[5]; |
|
316 | + $output .= $date[1].':'.$date[2].':'.$date[5]; |
|
317 | 317 | break; |
318 | 318 | case 'X': |
319 | - $output .= $date[0] . ':' . $date[2] . ':' . $date[5]; |
|
319 | + $output .= $date[0].':'.$date[2].':'.$date[5]; |
|
320 | 320 | break; |
321 | 321 | case 'z': |
322 | 322 | $output .= date('O', $timestamp); |
@@ -326,19 +326,19 @@ discard block |
||
326 | 326 | break; |
327 | 327 | /* Time and Date Stamps */ case 'c': |
328 | 328 | $key = self::jdate_words(['rh' => $date[6], 'mm' => $jalali_month]); |
329 | - $output .= $date[1] . ':' . $date[2] . ':' . $date[5] . ' ' . date('P', $timestamp) . ' ' . $key['rh'] . '، ' . $jalali_day . ' ' . $key['mm'] . ' ' . $jalali_year; |
|
329 | + $output .= $date[1].':'.$date[2].':'.$date[5].' '.date('P', $timestamp).' '.$key['rh'].'، '.$jalali_day.' '.$key['mm'].' '.$jalali_year; |
|
330 | 330 | break; |
331 | 331 | case 'D': |
332 | - $output .= substr($jalali_year, 2, 2) . '/' . (($jalali_month > 9) ? $jalali_month : '0' . $jalali_month) . '/' . (($jalali_day < 10) ? '0' . $jalali_day : $jalali_day); |
|
332 | + $output .= substr($jalali_year, 2, 2).'/'.(($jalali_month > 9) ? $jalali_month : '0'.$jalali_month).'/'.(($jalali_day < 10) ? '0'.$jalali_day : $jalali_day); |
|
333 | 333 | break; |
334 | 334 | case 'F': |
335 | - $output .= $jalali_year . '-' . (($jalali_month > 9) ? $jalali_month : '0' . $jalali_month) . '-' . (($jalali_day < 10) ? '0' . $jalali_day : $jalali_day); |
|
335 | + $output .= $jalali_year.'-'.(($jalali_month > 9) ? $jalali_month : '0'.$jalali_month).'-'.(($jalali_day < 10) ? '0'.$jalali_day : $jalali_day); |
|
336 | 336 | break; |
337 | 337 | case 's': |
338 | 338 | $output .= $timestamp; |
339 | 339 | break; |
340 | 340 | case 'x': |
341 | - $output .= substr($jalali_year, 2, 2) . '/' . (($jalali_month > 9) ? $jalali_month : '0' . $jalali_month) . '/' . (($jalali_day < 10) ? '0' . $jalali_day : $jalali_day); |
|
341 | + $output .= substr($jalali_year, 2, 2).'/'.(($jalali_month > 9) ? $jalali_month : '0'.$jalali_month).'/'.(($jalali_day < 10) ? '0'.$jalali_day : $jalali_day); |
|
342 | 342 | break; |
343 | 343 | /* Miscellaneous */ case 'n': |
344 | 344 | $output .= "\n"; |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | } |
356 | 356 | return ($tr_num != 'en') ? self::tr_num($output, 'fa', '.') : $output; |
357 | 357 | } |
358 | - public static function jmktime ($hour = '', $minute = '', $second = '', $jalali_month = '', $jalali_day = '', $jalali_year = '', $none = '', $timezone = 'Asia/Tehran'): bool|int { |
|
358 | + public static function jmktime($hour = '', $minute = '', $second = '', $jalali_month = '', $jalali_day = '', $jalali_year = '', $none = '', $timezone = 'Asia/Tehran'): bool | int { |
|
359 | 359 | if ($timezone != 'local') date_default_timezone_set($timezone); |
360 | 360 | if ($hour === '') { |
361 | 361 | return time(); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $jalali_month, |
369 | 369 | $jalali_day, |
370 | 370 | $jalali_year |
371 | - ] = explode('_', self::tr_num($hour . '_' . $minute . '_' . $second . '_' . $jalali_month . '_' . $jalali_day . '_' . $jalali_year)); |
|
371 | + ] = explode('_', self::tr_num($hour.'_'.$minute.'_'.$second.'_'.$jalali_month.'_'.$jalali_day.'_'.$jalali_year)); |
|
372 | 372 | if ($minute === '') { |
373 | 373 | return mktime($hour); |
374 | 374 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | } |
414 | 414 | } |
415 | 415 | } |
416 | - public static function jgetdate ($timestamp = '', $none = '', $timezone = 'Asia/Tehran', $tn = 'en') { |
|
416 | + public static function jgetdate($timestamp = '', $none = '', $timezone = 'Asia/Tehran', $tn = 'en') { |
|
417 | 417 | $timestamp = ($timestamp === '') ? time() : self::tr_num($timestamp); |
418 | 418 | $jdate = explode('_', self::jdate('F_G_i_j_l_n_s_w_Y_z', $timestamp, '', $timezone, $tn)); |
419 | 419 | return [ |
@@ -430,17 +430,17 @@ discard block |
||
430 | 430 | 0 => self::tr_num($timestamp, $tn) |
431 | 431 | ]; |
432 | 432 | } |
433 | - public static function jcheckdate ($jalali_month, $jalali_day, $jalali_year): bool { |
|
434 | - [$jalali_month, $jalali_day, $jalali_year] = explode('_', self::tr_num($jalali_month . '_' . $jalali_day . '_' . $jalali_year)); |
|
433 | + public static function jcheckdate($jalali_month, $jalali_day, $jalali_year): bool { |
|
434 | + [$jalali_month, $jalali_day, $jalali_year] = explode('_', self::tr_num($jalali_month.'_'.$jalali_day.'_'.$jalali_year)); |
|
435 | 435 | $l_d = ($jalali_month == 12 and ($jalali_year + 12) % 33 % 4 != 1) ? 29 : 31 - (int) ($jalali_month / 6.5); |
436 | 436 | return !(($jalali_month > 12 or $jalali_day > $l_d or $jalali_month < 1 or $jalali_day < 1 or $jalali_year < 1)); |
437 | 437 | } |
438 | - public static function tr_num ($string, $mod = 'en', $mf = '٫'): array|string { |
|
438 | + public static function tr_num($string, $mod = 'en', $mf = '٫'): array | string { |
|
439 | 439 | $english_number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.']; |
440 | 440 | $persian_number = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', $mf]; |
441 | 441 | return $mod == 'fa' ? str_replace($english_number, $persian_number, $string) : str_replace($persian_number, $english_number, $string); |
442 | 442 | } |
443 | - public static function jdate_words ($array, $splitter = '') { |
|
443 | + public static function jdate_words($array, $splitter = '') { |
|
444 | 444 | foreach ($array as $type => $num) { |
445 | 445 | $num = (int) self::tr_num($num); |
446 | 446 | switch ($type) { |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | 'هزار و چهارصد', |
479 | 479 | 'هزار و نهصد', |
480 | 480 | 'دوهزار' |
481 | - ], substr($num, 0, 2)) . (substr($num, 2, 2) == '00' ? '' : ' و ') : '') . $h3 . $p34 . $h34 . $h4; |
|
481 | + ], substr($num, 0, 2)).(substr($num, 2, 2) == '00' ? '' : ' و ') : '').$h3.$p34.$h34.$h4; |
|
482 | 482 | break; |
483 | 483 | case 'mm': |
484 | 484 | $array[$type] = [ |
@@ -594,8 +594,8 @@ discard block |
||
594 | 594 | } |
595 | 595 | return $splitter === '' ? $array : implode($splitter, $array); |
596 | 596 | } |
597 | - public static function gregorian_to_jalali ($gregorian_year, $gregorian_month, $gregorian_day, $splitter = ''): array|string { |
|
598 | - [$gregorian_year, $gregorian_month, $gregorian_day] = explode('_', self::tr_num($gregorian_year . '_' . $gregorian_month . '_' . $gregorian_day));/* <= Extra :اين سطر ، جزء تابع اصلي نيست */ |
|
597 | + public static function gregorian_to_jalali($gregorian_year, $gregorian_month, $gregorian_day, $splitter = ''): array | string { |
|
598 | + [$gregorian_year, $gregorian_month, $gregorian_day] = explode('_', self::tr_num($gregorian_year.'_'.$gregorian_month.'_'.$gregorian_day)); /* <= Extra :اين سطر ، جزء تابع اصلي نيست */ |
|
599 | 599 | $g_d_m = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; |
600 | 600 | $gregorian_year2 = ($gregorian_month > 2) ? ($gregorian_year + 1) : $gregorian_year; |
601 | 601 | $days = 355666 + (365 * $gregorian_year) + ((int) (($gregorian_year2 + 3) / 4)) - ((int) (($gregorian_year2 + 99) / 100)) + ((int) (($gregorian_year2 + 399) / 400)) + $gregorian_day + $g_d_m[$gregorian_month - 1]; |
@@ -615,10 +615,10 @@ discard block |
||
615 | 615 | $jalali_month = 7 + (int) (($days - 186) / 30); |
616 | 616 | $jalali_day = 1 + (($days - 186) % 30); |
617 | 617 | } |
618 | - return $splitter == '' ? [$jalali_year, $jalali_month, $jalali_day] : $jalali_year . $splitter . $jalali_month . $splitter . $jalali_day; |
|
618 | + return $splitter == '' ? [$jalali_year, $jalali_month, $jalali_day] : $jalali_year.$splitter.$jalali_month.$splitter.$jalali_day; |
|
619 | 619 | } |
620 | - public static function jalali_to_gregorian ($jalali_year, $jalali_month, $jalali_day, $splitter = ''): array|string { |
|
621 | - [$jalali_year, $jalali_month, $jalali_day] = explode('_', self::tr_num($jalali_year . '_' . $jalali_month . '_' . $jalali_day)); |
|
620 | + public static function jalali_to_gregorian($jalali_year, $jalali_month, $jalali_day, $splitter = ''): array | string { |
|
621 | + [$jalali_year, $jalali_month, $jalali_day] = explode('_', self::tr_num($jalali_year.'_'.$jalali_month.'_'.$jalali_day)); |
|
622 | 622 | $jalali_year += 1595; |
623 | 623 | $days = -355668 + (365 * $jalali_year) + (((int) ($jalali_year / 33)) * 8) + ((int) ((($jalali_year % 33) + 3) / 4)) + $jalali_day + (($jalali_month < 7) ? ($jalali_month - 1) * 31 : (($jalali_month - 7) * 30) + 186); |
624 | 624 | $gregorian_year = 400 * (int) ($days / 146097); |
@@ -655,6 +655,6 @@ discard block |
||
655 | 655 | for ($gregorian_month = 0; $gregorian_month < 13 and $gregorian_day > $month_days[$gregorian_month]; $gregorian_month++) { |
656 | 656 | $gregorian_day -= $month_days[$gregorian_month]; |
657 | 657 | } |
658 | - return $splitter == '' ? [$gregorian_year, $gregorian_month, $gregorian_day] : $gregorian_year . $splitter . $gregorian_month . $splitter . $gregorian_day; |
|
658 | + return $splitter == '' ? [$gregorian_year, $gregorian_month, $gregorian_day] : $gregorian_year.$splitter.$gregorian_month.$splitter.$gregorian_day; |
|
659 | 659 | } |
660 | 660 | } |
661 | 661 | \ No newline at end of file |
@@ -156,12 +156,13 @@ discard block |
||
156 | 156 | break; |
157 | 157 | case 'W': |
158 | 158 | $avs = ($date[7] == 6 ? 0 : $date[7] + 1) - $doy % 7; |
159 | - if ($avs < 0) $avs += 7; |
|
159 | + if ($avs < 0) { |
|
160 | + $avs += 7; |
|
161 | + } |
|
160 | 162 | $num = (int) (($doy + $avs) / 7); |
161 | 163 | if ($avs < 4) { |
162 | 164 | $num++; |
163 | - } |
|
164 | - elseif ($num < 1) { |
|
165 | + } elseif ($num < 1) { |
|
165 | 166 | $num = ($avs == 4 or $avs == ($jalali_year % 33 % 4 - 2 == (int) ($jalali_year % 33 * 0.05) ? 5 : 4)) ? 53 : 52; |
166 | 167 | } |
167 | 168 | $aks = $avs + $leap_year; |
@@ -187,7 +188,9 @@ discard block |
||
187 | 188 | } |
188 | 189 | public static function jstrftime ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
189 | 190 | $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
190 | - if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
191 | + if ($time_zone != 'local') { |
|
192 | + date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
193 | + } |
|
191 | 194 | $timestamp = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
192 | 195 | $date = explode('_', date('h_H_i_j_n_s_w_Y', $timestamp)); |
193 | 196 | [$jalali_year, $jalali_month, $jalali_day] = self::gregorian_to_jalali($date[7], $date[4], $date[3]); |
@@ -199,8 +202,7 @@ discard block |
||
199 | 202 | $sub = substr($format, $i, 1); |
200 | 203 | if ($sub == '%') { |
201 | 204 | $sub = substr($format, ++$i, 1); |
202 | - } |
|
203 | - else { |
|
205 | + } else { |
|
204 | 206 | $output .= $sub; |
205 | 207 | continue; |
206 | 208 | } |
@@ -229,30 +231,41 @@ discard block |
||
229 | 231 | break; |
230 | 232 | /* Week */ case 'U': |
231 | 233 | $avs = (($date[6] < 5) ? $date[6] + 2 : $date[6] - 5) - ($doy % 7); |
232 | - if ($avs < 0) $avs += 7; |
|
234 | + if ($avs < 0) { |
|
235 | + $avs += 7; |
|
236 | + } |
|
233 | 237 | $num = (int) (($doy + $avs) / 7) + 1; |
234 | - if ($avs > 3 or $avs == 1) $num--; |
|
238 | + if ($avs > 3 or $avs == 1) { |
|
239 | + $num--; |
|
240 | + } |
|
235 | 241 | $output .= ($num < 10) ? '0' . $num : $num; |
236 | 242 | break; |
237 | 243 | case 'V': |
238 | 244 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
239 | - if ($avs < 0) $avs += 7; |
|
245 | + if ($avs < 0) { |
|
246 | + $avs += 7; |
|
247 | + } |
|
240 | 248 | $num = (int) (($doy + $avs) / 7); |
241 | 249 | if ($avs < 4) { |
242 | 250 | $num++; |
243 | - } |
|
244 | - elseif ($num < 1) { |
|
251 | + } elseif ($num < 1) { |
|
245 | 252 | $num = ($avs == 4 or $avs == ((((($jalali_year % 33) % 4) - 2) == ((int) (($jalali_year % 33) * 0.05))) ? 5 : 4)) ? 53 : 52; |
246 | 253 | } |
247 | 254 | $aks = $avs + $leap_year; |
248 | - if ($aks == 7) $aks = 0; |
|
255 | + if ($aks == 7) { |
|
256 | + $aks = 0; |
|
257 | + } |
|
249 | 258 | $output .= (($leap_year + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
250 | 259 | break; |
251 | 260 | case 'W': |
252 | 261 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
253 | - if ($avs < 0) $avs += 7; |
|
262 | + if ($avs < 0) { |
|
263 | + $avs += 7; |
|
264 | + } |
|
254 | 265 | $num = (int) (($doy + $avs) / 7) + 1; |
255 | - if ($avs > 3) $num--; |
|
266 | + if ($avs > 3) { |
|
267 | + $num--; |
|
268 | + } |
|
256 | 269 | $output .= ($num < 10) ? '0' . $num : $num; |
257 | 270 | break; |
258 | 271 | /* Month */ case 'b': |
@@ -356,11 +369,12 @@ discard block |
||
356 | 369 | return ($tr_num != 'en') ? self::tr_num($output, 'fa', '.') : $output; |
357 | 370 | } |
358 | 371 | public static function jmktime ($hour = '', $minute = '', $second = '', $jalali_month = '', $jalali_day = '', $jalali_year = '', $none = '', $timezone = 'Asia/Tehran'): bool|int { |
359 | - if ($timezone != 'local') date_default_timezone_set($timezone); |
|
372 | + if ($timezone != 'local') { |
|
373 | + date_default_timezone_set($timezone); |
|
374 | + } |
|
360 | 375 | if ($hour === '') { |
361 | 376 | return time(); |
362 | - } |
|
363 | - else { |
|
377 | + } else { |
|
364 | 378 | [ |
365 | 379 | $hour, |
366 | 380 | $minute, |
@@ -371,16 +385,13 @@ discard block |
||
371 | 385 | ] = explode('_', self::tr_num($hour . '_' . $minute . '_' . $second . '_' . $jalali_month . '_' . $jalali_day . '_' . $jalali_year)); |
372 | 386 | if ($minute === '') { |
373 | 387 | return mktime($hour); |
374 | - } |
|
375 | - else { |
|
388 | + } else { |
|
376 | 389 | if ($second === '') { |
377 | 390 | return mktime($hour, $minute); |
378 | - } |
|
379 | - else { |
|
391 | + } else { |
|
380 | 392 | if ($jalali_month === '') { |
381 | 393 | return mktime($hour, $minute, $second); |
382 | - } |
|
383 | - else { |
|
394 | + } else { |
|
384 | 395 | $jdate = explode('_', self::jdate('Y_j', '', '', $timezone, 'en')); |
385 | 396 | if ($jalali_day === '') { |
386 | 397 | [ |
@@ -389,8 +400,7 @@ discard block |
||
389 | 400 | $gregorian_day |
390 | 401 | ] = self::jalali_to_gregorian($jdate[0], $jalali_month, $jdate[1]); |
391 | 402 | return mktime($hour, $minute, $second, $gregorian_month); |
392 | - } |
|
393 | - else { |
|
403 | + } else { |
|
394 | 404 | if ($jalali_year === '') { |
395 | 405 | [ |
396 | 406 | $gregorian_year, |
@@ -398,8 +408,7 @@ discard block |
||
398 | 408 | $gregorian_day |
399 | 409 | ] = self::jalali_to_gregorian($jdate[0], $jalali_month, $jalali_day); |
400 | 410 | return mktime($hour, $minute, $second, $gregorian_month, $gregorian_day); |
401 | - } |
|
402 | - else { |
|
411 | + } else { |
|
403 | 412 | [ |
404 | 413 | $gregorian_year, |
405 | 414 | $gregorian_month, |
@@ -463,8 +472,7 @@ discard block |
||
463 | 472 | 'نوزده' |
464 | 473 | ]; |
465 | 474 | $h34 = $k34[substr($num, 2 - $length, 2) - 10]; |
466 | - } |
|
467 | - else { |
|
475 | + } else { |
|
468 | 476 | $xy4 = substr($num, 3 - $length, 1); |
469 | 477 | $p34 = ($xy3 == 0 or $xy4 == 0) ? '' : ' و '; |
470 | 478 | $k3 = ['', '', 'بیست', 'سی', 'چهل', 'پنجاه', 'شصت', 'هفتاد', 'هشتاد', 'نود']; |
@@ -610,8 +618,7 @@ discard block |
||
610 | 618 | if ($days < 186) { |
611 | 619 | $jalali_month = 1 + (int) ($days / 31); |
612 | 620 | $jalali_day = 1 + ($days % 31); |
613 | - } |
|
614 | - else { |
|
621 | + } else { |
|
615 | 622 | $jalali_month = 7 + (int) (($days - 186) / 30); |
616 | 623 | $jalali_day = 1 + (($days - 186) % 30); |
617 | 624 | } |
@@ -49,6 +49,6 @@ |
||
49 | 49 | * |
50 | 50 | * @return array|string |
51 | 51 | */ |
52 | -function strReplace(array $replacements, string|array $subject): array|string { |
|
52 | +function strReplace(array $replacements, string | array $subject): array | string { |
|
53 | 53 | return str_replace(array_keys($replacements), array_values($replacements), $subject); |
54 | 54 | } |
55 | 55 | \ No newline at end of file |
@@ -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 | /** |