@@ -10,8 +10,8 @@ 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') { |
|
14 | - $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
|
13 | + public static function jdate($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
14 | + $T_sec = 0; /* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
|
15 | 15 | if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
16 | 16 | $ts = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
17 | 17 | $date = explode('_', date('H_i_j_n_O_P_s_w_Y', $ts)); |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | $out .= (int) ($j_m / 3.1) + 1; |
56 | 56 | break; |
57 | 57 | case 'c': |
58 | - $out .= $j_y . '/' . $j_m . '/' . $j_d . ' ،' . $date[0] . ':' . $date[1] . ':' . $date[6] . ' ' . $date[5]; |
|
58 | + $out .= $j_y.'/'.$j_m.'/'.$j_d.' ،'.$date[0].':'.$date[1].':'.$date[6].' '.$date[5]; |
|
59 | 59 | break; |
60 | 60 | case 'C': |
61 | 61 | $out .= (int) (($j_y + 99) / 100); |
62 | 62 | break; |
63 | 63 | case 'd': |
64 | - $out .= ($j_d < 10) ? '0' . $j_d : $j_d; |
|
64 | + $out .= ($j_d < 10) ? '0'.$j_d : $j_d; |
|
65 | 65 | break; |
66 | 66 | case 'D': |
67 | 67 | $out .= self::jdate_words(['kh' => $date[7]], ' '); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $out .= $kab; |
98 | 98 | break; |
99 | 99 | case 'm': |
100 | - $out .= ($j_m > 9) ? $j_m : '0' . $j_m; |
|
100 | + $out .= ($j_m > 9) ? $j_m : '0'.$j_m; |
|
101 | 101 | break; |
102 | 102 | case 'M': |
103 | 103 | $out .= self::jdate_words(['km' => $j_m], ' '); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | break; |
131 | 131 | case 'r': |
132 | 132 | $key = self::jdate_words(['rh' => $date[7], 'mm' => $j_m]); |
133 | - $out .= $date[0] . ':' . $date[1] . ':' . $date[6] . ' ' . $date[4] . ' ' . $key['rh'] . '، ' . $j_d . ' ' . $key['mm'] . ' ' . $j_y; |
|
133 | + $out .= $date[0].':'.$date[1].':'.$date[6].' '.$date[4].' '.$key['rh'].'، '.$j_d.' '.$key['mm'].' '.$j_y; |
|
134 | 134 | break; |
135 | 135 | case 's': |
136 | 136 | $out .= $date[6]; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | $aks = $avs + $kab; |
167 | 167 | if ($aks == 7) $aks = 0; |
168 | - $out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
|
168 | + $out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0'.$num : $num); |
|
169 | 169 | break; |
170 | 170 | case 'y': |
171 | 171 | $out .= substr($j_y, 2, 2); |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | } |
183 | 183 | return ($tr_num != 'en') ? self::tr_num($out, 'fa', '.') : $out; |
184 | 184 | } |
185 | - public static function jstrftime ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
186 | - $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
|
185 | + public static function jstrftime($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
|
186 | + $T_sec = 0; /* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
|
187 | 187 | if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
188 | 188 | $ts = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
189 | 189 | $date = explode('_', date('h_H_i_j_n_s_w_Y', $ts)); |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | $out .= self::jdate_words(['rh' => $date[6]], ' '); |
212 | 212 | break; |
213 | 213 | case 'd': |
214 | - $out .= ($j_d < 10) ? '0' . $j_d : $j_d; |
|
214 | + $out .= ($j_d < 10) ? '0'.$j_d : $j_d; |
|
215 | 215 | break; |
216 | 216 | case 'e': |
217 | - $out .= ($j_d < 10) ? ' ' . $j_d : $j_d; |
|
217 | + $out .= ($j_d < 10) ? ' '.$j_d : $j_d; |
|
218 | 218 | break; |
219 | 219 | case 'j': |
220 | 220 | $out .= str_pad($doy + 1, 3, 0, STR_PAD_LEFT); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | if ($avs < 0) $avs += 7; |
232 | 232 | $num = (int) (($doy + $avs) / 7) + 1; |
233 | 233 | if ($avs > 3 or $avs == 1) $num--; |
234 | - $out .= ($num < 10) ? '0' . $num : $num; |
|
234 | + $out .= ($num < 10) ? '0'.$num : $num; |
|
235 | 235 | break; |
236 | 236 | case 'V': |
237 | 237 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | } |
246 | 246 | $aks = $avs + $kab; |
247 | 247 | if ($aks == 7) $aks = 0; |
248 | - $out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
|
248 | + $out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0'.$num : $num); |
|
249 | 249 | break; |
250 | 250 | case 'W': |
251 | 251 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
252 | 252 | if ($avs < 0) $avs += 7; |
253 | 253 | $num = (int) (($doy + $avs) / 7) + 1; |
254 | 254 | if ($avs > 3) $num--; |
255 | - $out .= ($num < 10) ? '0' . $num : $num; |
|
255 | + $out .= ($num < 10) ? '0'.$num : $num; |
|
256 | 256 | break; |
257 | 257 | /* Month */ |
258 | 258 | case 'b': |
@@ -263,12 +263,12 @@ discard block |
||
263 | 263 | $out .= self::jdate_words(['mm' => $j_m], ' '); |
264 | 264 | break; |
265 | 265 | case 'm': |
266 | - $out .= ($j_m > 9) ? $j_m : '0' . $j_m; |
|
266 | + $out .= ($j_m > 9) ? $j_m : '0'.$j_m; |
|
267 | 267 | break; |
268 | 268 | /* Year */ |
269 | 269 | case 'C': |
270 | 270 | $tmp = (int) ($j_y / 100); |
271 | - $out .= ($tmp > 9) ? $tmp : '0' . $tmp; |
|
271 | + $out .= ($tmp > 9) ? $tmp : '0'.$tmp; |
|
272 | 272 | break; |
273 | 273 | case 'g': |
274 | 274 | $jdw = ($date[6] == 6) ? 0 : $date[6] + 1; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $out .= $date[0]; |
295 | 295 | break; |
296 | 296 | case 'l': |
297 | - $out .= ($date[0] > 9) ? $date[0] : ' ' . (int) $date[0]; |
|
297 | + $out .= ($date[0] > 9) ? $date[0] : ' '.(int) $date[0]; |
|
298 | 298 | break; |
299 | 299 | case 'M': |
300 | 300 | $out .= $date[2]; |
@@ -306,19 +306,19 @@ discard block |
||
306 | 306 | $out .= ($date[1] < 12) ? 'ق.ظ' : 'ب.ظ'; |
307 | 307 | break; |
308 | 308 | case 'r': |
309 | - $out .= $date[0] . ':' . $date[2] . ':' . $date[5] . ' ' . (($date[1] < 12) ? 'قبل از ظهر' : 'بعد از ظهر'); |
|
309 | + $out .= $date[0].':'.$date[2].':'.$date[5].' '.(($date[1] < 12) ? 'قبل از ظهر' : 'بعد از ظهر'); |
|
310 | 310 | break; |
311 | 311 | case 'R': |
312 | - $out .= $date[1] . ':' . $date[2]; |
|
312 | + $out .= $date[1].':'.$date[2]; |
|
313 | 313 | break; |
314 | 314 | case 'S': |
315 | 315 | $out .= $date[5]; |
316 | 316 | break; |
317 | 317 | case 'T': |
318 | - $out .= $date[1] . ':' . $date[2] . ':' . $date[5]; |
|
318 | + $out .= $date[1].':'.$date[2].':'.$date[5]; |
|
319 | 319 | break; |
320 | 320 | case 'X': |
321 | - $out .= $date[0] . ':' . $date[2] . ':' . $date[5]; |
|
321 | + $out .= $date[0].':'.$date[2].':'.$date[5]; |
|
322 | 322 | break; |
323 | 323 | case 'z': |
324 | 324 | $out .= date('O', $ts); |
@@ -329,19 +329,19 @@ discard block |
||
329 | 329 | /* Time and Date Stamps */ |
330 | 330 | case 'c': |
331 | 331 | $key = self::jdate_words(['rh' => $date[6], 'mm' => $j_m]); |
332 | - $out .= $date[1] . ':' . $date[2] . ':' . $date[5] . ' ' . date('P', $ts) . ' ' . $key['rh'] . '، ' . $j_d . ' ' . $key['mm'] . ' ' . $j_y; |
|
332 | + $out .= $date[1].':'.$date[2].':'.$date[5].' '.date('P', $ts).' '.$key['rh'].'، '.$j_d.' '.$key['mm'].' '.$j_y; |
|
333 | 333 | break; |
334 | 334 | case 'D': |
335 | - $out .= substr($j_y, 2, 2) . '/' . (($j_m > 9) ? $j_m : '0' . $j_m) . '/' . (($j_d < 10) ? '0' . $j_d : $j_d); |
|
335 | + $out .= substr($j_y, 2, 2).'/'.(($j_m > 9) ? $j_m : '0'.$j_m).'/'.(($j_d < 10) ? '0'.$j_d : $j_d); |
|
336 | 336 | break; |
337 | 337 | case 'F': |
338 | - $out .= $j_y . '-' . (($j_m > 9) ? $j_m : '0' . $j_m) . '-' . (($j_d < 10) ? '0' . $j_d : $j_d); |
|
338 | + $out .= $j_y.'-'.(($j_m > 9) ? $j_m : '0'.$j_m).'-'.(($j_d < 10) ? '0'.$j_d : $j_d); |
|
339 | 339 | break; |
340 | 340 | case 's': |
341 | 341 | $out .= $ts; |
342 | 342 | break; |
343 | 343 | case 'x': |
344 | - $out .= substr($j_y, 2, 2) . '/' . (($j_m > 9) ? $j_m : '0' . $j_m) . '/' . (($j_d < 10) ? '0' . $j_d : $j_d); |
|
344 | + $out .= substr($j_y, 2, 2).'/'.(($j_m > 9) ? $j_m : '0'.$j_m).'/'.(($j_d < 10) ? '0'.$j_d : $j_d); |
|
345 | 345 | break; |
346 | 346 | /* Miscellaneous */ |
347 | 347 | case 'n': |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | } |
360 | 360 | return ($tr_num != 'en') ? self::tr_num($out, 'fa', '.') : $out; |
361 | 361 | } |
362 | - public static function jmktime ($h = '', $m = '', $s = '', $jm = '', $jd = '', $jy = '', $none = '', $timezone = 'Asia/Tehran') { |
|
362 | + public static function jmktime($h = '', $m = '', $s = '', $jm = '', $jd = '', $jy = '', $none = '', $timezone = 'Asia/Tehran') { |
|
363 | 363 | if ($timezone != 'local') date_default_timezone_set($timezone); |
364 | 364 | if ($h === '') { |
365 | 365 | return time(); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | $jm, |
373 | 373 | $jd, |
374 | 374 | $jy |
375 | - ] = explode('_', self::tr_num($h . '_' . $m . '_' . $s . '_' . $jm . '_' . $jd . '_' . $jy)); |
|
375 | + ] = explode('_', self::tr_num($h.'_'.$m.'_'.$s.'_'.$jm.'_'.$jd.'_'.$jy)); |
|
376 | 376 | if ($m === '') { |
377 | 377 | return mktime($h); |
378 | 378 | } |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
408 | - public static function jgetdate ($timestamp = '', $none = '', $timezone = 'Asia/Tehran', $tn = 'en') { |
|
408 | + public static function jgetdate($timestamp = '', $none = '', $timezone = 'Asia/Tehran', $tn = 'en') { |
|
409 | 409 | $ts = ($timestamp === '') ? time() : self::tr_num($timestamp); |
410 | 410 | $jdate = explode('_', self::jdate('F_G_i_j_l_n_s_w_Y_z', $ts, '', $timezone, $tn)); |
411 | 411 | return [ |
@@ -422,17 +422,17 @@ discard block |
||
422 | 422 | 0 => self::tr_num($ts, $tn) |
423 | 423 | ]; |
424 | 424 | } |
425 | - public static function jcheckdate ($jm, $jd, $jy) { |
|
426 | - [$jm, $jd, $jy] = explode('_', self::tr_num($jm . '_' . $jd . '_' . $jy)); |
|
425 | + public static function jcheckdate($jm, $jd, $jy) { |
|
426 | + [$jm, $jd, $jy] = explode('_', self::tr_num($jm.'_'.$jd.'_'.$jy)); |
|
427 | 427 | $l_d = ($jm == 12 and ((($jy + 12) % 33) % 4) != 1) ? 29 : (31 - (int) ($jm / 6.5)); |
428 | 428 | return ($jm > 12 or $jd > $l_d or $jm < 1 or $jd < 1 or $jy < 1) ? false : true; |
429 | 429 | } |
430 | - public static function tr_num ($str, $mod = 'en', $mf = '٫') { |
|
430 | + public static function tr_num($str, $mod = 'en', $mf = '٫') { |
|
431 | 431 | $num_a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.']; |
432 | 432 | $key_a = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', $mf]; |
433 | 433 | return ($mod == 'fa') ? str_replace($num_a, $key_a, $str) : str_replace($key_a, $num_a, $str); |
434 | 434 | } |
435 | - public static function jdate_words ($array, $mod = '') { |
|
435 | + public static function jdate_words($array, $mod = '') { |
|
436 | 436 | foreach ($array as $type => $num) { |
437 | 437 | $num = (int) self::tr_num($num); |
438 | 438 | switch ($type) { |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | 'هزار و چهارصد', |
461 | 461 | 'هزار و نهصد', |
462 | 462 | 'دوهزار' |
463 | - ], substr($num, 0, 2)) . ((substr($num, 2, 2) == '00') ? '' : ' و ') : '') . $h3 . $p34 . $h34 . $h4; |
|
463 | + ], substr($num, 0, 2)).((substr($num, 2, 2) == '00') ? '' : ' و ') : '').$h3.$p34.$h34.$h4; |
|
464 | 464 | break; |
465 | 465 | case 'mm': |
466 | 466 | $key = [ |
@@ -545,8 +545,8 @@ discard block |
||
545 | 545 | } |
546 | 546 | return ($mod === '') ? $array : implode($mod, $array); |
547 | 547 | } |
548 | - public static function gregorian_to_jalali ($gy, $gm, $gd, $mod = '') { |
|
549 | - [$gy, $gm, $gd] = explode('_', self::tr_num($gy . '_' . $gm . '_' . $gd));/* <= Extra :اين سطر ، جزء تابع اصلي نيست */ |
|
548 | + public static function gregorian_to_jalali($gy, $gm, $gd, $mod = '') { |
|
549 | + [$gy, $gm, $gd] = explode('_', self::tr_num($gy.'_'.$gm.'_'.$gd)); /* <= Extra :اين سطر ، جزء تابع اصلي نيست */ |
|
550 | 550 | $g_d_m = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; |
551 | 551 | $gy2 = ($gm > 2) ? ($gy + 1) : $gy; |
552 | 552 | $days = 355666 + (365 * $gy) + ((int) (($gy2 + 3) / 4)) - ((int) (($gy2 + 99) / 100)) + ((int) (($gy2 + 399) / 400)) + $gd + $g_d_m[$gm - 1]; |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | $jm = 7 + (int) (($days - 186) / 30); |
567 | 567 | $jd = 1 + (($days - 186) % 30); |
568 | 568 | } |
569 | - return ($mod == '') ? [$jy, $jm, $jd] : $jy . $mod . $jm . $mod . $jd; |
|
569 | + return ($mod == '') ? [$jy, $jm, $jd] : $jy.$mod.$jm.$mod.$jd; |
|
570 | 570 | } |
571 | - public static function jalali_to_gregorian ($jy, $jm, $jd, $mod = '') { |
|
572 | - [$jy, $jm, $jd] = explode('_', self::tr_num($jy . '_' . $jm . '_' . $jd));/* <= Extra :اين سطر ، جزء تابع اصلي نيست */ |
|
571 | + public static function jalali_to_gregorian($jy, $jm, $jd, $mod = '') { |
|
572 | + [$jy, $jm, $jd] = explode('_', self::tr_num($jy.'_'.$jm.'_'.$jd)); /* <= Extra :اين سطر ، جزء تابع اصلي نيست */ |
|
573 | 573 | $jy += 1595; |
574 | 574 | $days = -355668 + (365 * $jy) + (((int) ($jy / 33)) * 8) + ((int) ((($jy % 33) + 3) / 4)) + $jd + (($jm < 7) ? ($jm - 1) * 31 : (($jm - 7) * 30) + 186); |
575 | 575 | $gy = 400 * ((int) ($days / 146097)); |
@@ -602,6 +602,6 @@ discard block |
||
602 | 602 | 31 |
603 | 603 | ]; |
604 | 604 | for ($gm = 0; $gm < 13 and $gd > $sal_a[$gm]; $gm++) $gd -= $sal_a[$gm]; |
605 | - return ($mod == '') ? [$gy, $gm, $gd] : $gy . $mod . $gm . $mod . $gd; |
|
605 | + return ($mod == '') ? [$gy, $gm, $gd] : $gy.$mod.$gm.$mod.$gd; |
|
606 | 606 | } |
607 | 607 | } |
608 | 608 | \ No newline at end of file |
@@ -12,7 +12,9 @@ discard block |
||
12 | 12 | class jdf { |
13 | 13 | public static function jdate ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
14 | 14 | $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
15 | - if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
15 | + if ($time_zone != 'local') { |
|
16 | + date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
17 | + } |
|
16 | 18 | $ts = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
17 | 19 | $date = explode('_', date('H_i_j_n_O_P_s_w_Y', $ts)); |
18 | 20 | [$j_y, $j_m, $j_d] = self::gregorian_to_jalali($date[8], $date[3], $date[2]); |
@@ -155,16 +157,19 @@ discard block |
||
155 | 157 | break; |
156 | 158 | case 'W': |
157 | 159 | $avs = (($date[7] == 6) ? 0 : $date[7] + 1) - ($doy % 7); |
158 | - if ($avs < 0) $avs += 7; |
|
160 | + if ($avs < 0) { |
|
161 | + $avs += 7; |
|
162 | + } |
|
159 | 163 | $num = (int) (($doy + $avs) / 7); |
160 | 164 | if ($avs < 4) { |
161 | 165 | $num++; |
162 | - } |
|
163 | - elseif ($num < 1) { |
|
166 | + } elseif ($num < 1) { |
|
164 | 167 | $num = ($avs == 4 or $avs == ((((($j_y % 33) % 4) - 2) == ((int) (($j_y % 33) * 0.05))) ? 5 : 4)) ? 53 : 52; |
165 | 168 | } |
166 | 169 | $aks = $avs + $kab; |
167 | - if ($aks == 7) $aks = 0; |
|
170 | + if ($aks == 7) { |
|
171 | + $aks = 0; |
|
172 | + } |
|
168 | 173 | $out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
169 | 174 | break; |
170 | 175 | case 'y': |
@@ -184,7 +189,9 @@ discard block |
||
184 | 189 | } |
185 | 190 | public static function jstrftime ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
186 | 191 | $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
187 | - if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
192 | + if ($time_zone != 'local') { |
|
193 | + date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
194 | + } |
|
188 | 195 | $ts = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
189 | 196 | $date = explode('_', date('h_H_i_j_n_s_w_Y', $ts)); |
190 | 197 | [$j_y, $j_m, $j_d] = self::gregorian_to_jalali($date[7], $date[4], $date[3]); |
@@ -196,8 +203,7 @@ discard block |
||
196 | 203 | $sub = substr($format, $i, 1); |
197 | 204 | if ($sub == '%') { |
198 | 205 | $sub = substr($format, ++$i, 1); |
199 | - } |
|
200 | - else { |
|
206 | + } else { |
|
201 | 207 | $out .= $sub; |
202 | 208 | continue; |
203 | 209 | } |
@@ -228,30 +234,41 @@ discard block |
||
228 | 234 | /* Week */ |
229 | 235 | case 'U': |
230 | 236 | $avs = (($date[6] < 5) ? $date[6] + 2 : $date[6] - 5) - ($doy % 7); |
231 | - if ($avs < 0) $avs += 7; |
|
237 | + if ($avs < 0) { |
|
238 | + $avs += 7; |
|
239 | + } |
|
232 | 240 | $num = (int) (($doy + $avs) / 7) + 1; |
233 | - if ($avs > 3 or $avs == 1) $num--; |
|
241 | + if ($avs > 3 or $avs == 1) { |
|
242 | + $num--; |
|
243 | + } |
|
234 | 244 | $out .= ($num < 10) ? '0' . $num : $num; |
235 | 245 | break; |
236 | 246 | case 'V': |
237 | 247 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
238 | - if ($avs < 0) $avs += 7; |
|
248 | + if ($avs < 0) { |
|
249 | + $avs += 7; |
|
250 | + } |
|
239 | 251 | $num = (int) (($doy + $avs) / 7); |
240 | 252 | if ($avs < 4) { |
241 | 253 | $num++; |
242 | - } |
|
243 | - elseif ($num < 1) { |
|
254 | + } elseif ($num < 1) { |
|
244 | 255 | $num = ($avs == 4 or $avs == ((((($j_y % 33) % 4) - 2) == ((int) (($j_y % 33) * 0.05))) ? 5 : 4)) ? 53 : 52; |
245 | 256 | } |
246 | 257 | $aks = $avs + $kab; |
247 | - if ($aks == 7) $aks = 0; |
|
258 | + if ($aks == 7) { |
|
259 | + $aks = 0; |
|
260 | + } |
|
248 | 261 | $out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
249 | 262 | break; |
250 | 263 | case 'W': |
251 | 264 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
252 | - if ($avs < 0) $avs += 7; |
|
265 | + if ($avs < 0) { |
|
266 | + $avs += 7; |
|
267 | + } |
|
253 | 268 | $num = (int) (($doy + $avs) / 7) + 1; |
254 | - if ($avs > 3) $num--; |
|
269 | + if ($avs > 3) { |
|
270 | + $num--; |
|
271 | + } |
|
255 | 272 | $out .= ($num < 10) ? '0' . $num : $num; |
256 | 273 | break; |
257 | 274 | /* Month */ |
@@ -360,11 +377,12 @@ discard block |
||
360 | 377 | return ($tr_num != 'en') ? self::tr_num($out, 'fa', '.') : $out; |
361 | 378 | } |
362 | 379 | public static function jmktime ($h = '', $m = '', $s = '', $jm = '', $jd = '', $jy = '', $none = '', $timezone = 'Asia/Tehran') { |
363 | - if ($timezone != 'local') date_default_timezone_set($timezone); |
|
380 | + if ($timezone != 'local') { |
|
381 | + date_default_timezone_set($timezone); |
|
382 | + } |
|
364 | 383 | if ($h === '') { |
365 | 384 | return time(); |
366 | - } |
|
367 | - else { |
|
385 | + } else { |
|
368 | 386 | [ |
369 | 387 | $h, |
370 | 388 | $m, |
@@ -375,27 +393,22 @@ discard block |
||
375 | 393 | ] = explode('_', self::tr_num($h . '_' . $m . '_' . $s . '_' . $jm . '_' . $jd . '_' . $jy)); |
376 | 394 | if ($m === '') { |
377 | 395 | return mktime($h); |
378 | - } |
|
379 | - else { |
|
396 | + } else { |
|
380 | 397 | if ($s === '') { |
381 | 398 | return mktime($h, $m); |
382 | - } |
|
383 | - else { |
|
399 | + } else { |
|
384 | 400 | if ($jm === '') { |
385 | 401 | return mktime($h, $m, $s); |
386 | - } |
|
387 | - else { |
|
402 | + } else { |
|
388 | 403 | $jdate = explode('_', self::jdate('Y_j', '', '', $timezone, 'en')); |
389 | 404 | if ($jd === '') { |
390 | 405 | [$gy, $gm, $gd] = self::jalali_to_gregorian($jdate[0], $jm, $jdate[1]); |
391 | 406 | return mktime($h, $m, $s, $gm); |
392 | - } |
|
393 | - else { |
|
407 | + } else { |
|
394 | 408 | if ($jy === '') { |
395 | 409 | [$gy, $gm, $gd] = self::jalali_to_gregorian($jdate[0], $jm, $jd); |
396 | 410 | return mktime($h, $m, $s, $gm, $gd); |
397 | - } |
|
398 | - else { |
|
411 | + } else { |
|
399 | 412 | [$gy, $gm, $gd] = self::jalali_to_gregorian($jy, $jm, $jd); |
400 | 413 | return mktime($h, $m, $s, $gm, $gd, $gy); |
401 | 414 | } |
@@ -445,8 +458,7 @@ discard block |
||
445 | 458 | $p34 = ''; |
446 | 459 | $k34 = ['ده', 'یازده', 'دوازده', 'سیزده', 'چهارده', 'پانزده', 'شانزده', 'هفده', 'هجده', 'نوزده']; |
447 | 460 | $h34 = $k34[substr($num, 2 - $sl, 2) - 10]; |
448 | - } |
|
449 | - else { |
|
461 | + } else { |
|
450 | 462 | $xy4 = substr($num, 3 - $sl, 1); |
451 | 463 | $p34 = ($xy3 == 0 or $xy4 == 0) ? '' : ' و '; |
452 | 464 | $k3 = ['', '', 'بیست', 'سی', 'چهل', 'پنجاه', 'شصت', 'هفتاد', 'هشتاد', 'نود']; |
@@ -561,8 +573,7 @@ discard block |
||
561 | 573 | if ($days < 186) { |
562 | 574 | $jm = 1 + (int) ($days / 31); |
563 | 575 | $jd = 1 + ($days % 31); |
564 | - } |
|
565 | - else { |
|
576 | + } else { |
|
566 | 577 | $jm = 7 + (int) (($days - 186) / 30); |
567 | 578 | $jd = 1 + (($days - 186) % 30); |
568 | 579 | } |
@@ -577,7 +588,9 @@ discard block |
||
577 | 588 | if ($days > 36524) { |
578 | 589 | $gy += 100 * ((int) (--$days / 36524)); |
579 | 590 | $days %= 36524; |
580 | - if ($days >= 365) $days++; |
|
591 | + if ($days >= 365) { |
|
592 | + $days++; |
|
593 | + } |
|
581 | 594 | } |
582 | 595 | $gy += 4 * ((int) ($days / 1461)); |
583 | 596 | $days %= 1461; |
@@ -601,7 +614,9 @@ discard block |
||
601 | 614 | 30, |
602 | 615 | 31 |
603 | 616 | ]; |
604 | - for ($gm = 0; $gm < 13 and $gd > $sal_a[$gm]; $gm++) $gd -= $sal_a[$gm]; |
|
617 | + for ($gm = 0; $gm < 13 and $gd > $sal_a[$gm]; $gm++) { |
|
618 | + $gd -= $sal_a[$gm]; |
|
619 | + } |
|
605 | 620 | return ($mod == '') ? [$gy, $gm, $gd] : $gy . $mod . $gm . $mod . $gd; |
606 | 621 | } |
607 | 622 | } |
608 | 623 | \ No newline at end of file |
@@ -25,13 +25,13 @@ |
||
25 | 25 | public shippingAddress $shipping_address; |
26 | 26 | |
27 | 27 | |
28 | - public function __construct(stdClass|null $object = null) { |
|
28 | + public function __construct(stdClass | null $object = null) { |
|
29 | 29 | if ($object != null) { |
30 | 30 | parent::__construct($object, self::subs); |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - public function answer (bool $ok, null|array $shipping_options = null, string|null $error_message = null): responseError|bool { |
|
34 | + public function answer(bool $ok, null | array $shipping_options = null, string | null $error_message = null): responseError | bool { |
|
35 | 35 | return telegram::answerShippingQuery($ok, $this->id, $shipping_options, $error_message); |
36 | 36 | } |
37 | 37 | } |
@@ -31,19 +31,19 @@ |
||
31 | 31 | * should be always known for requests sent from official clients and most third-party clients, unless the |
32 | 32 | * request was sent from a secret chat |
33 | 33 | */ |
34 | - public null|string $chat_type = null; |
|
34 | + public null | string $chat_type = null; |
|
35 | 35 | |
36 | 36 | /** Optional. Sender location, only for bots that request user location */ |
37 | - public null|location $location = null; |
|
37 | + public null | location $location = null; |
|
38 | 38 | |
39 | 39 | |
40 | - public function __construct(stdClass|null $object = null) { |
|
40 | + public function __construct(stdClass | null $object = null) { |
|
41 | 41 | if ($object != null) { |
42 | 42 | parent::__construct($object, self::subs); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - public function answer(array $results, int|null $cache_time = null, bool|null $is_personal = null, string|null $next_offset = null, string|null $switch_pm_text = null, string|null $switch_pm_parameter = null): responseError|bool { |
|
46 | + public function answer(array $results, int | null $cache_time = null, bool | null $is_personal = null, string | null $next_offset = null, string | null $switch_pm_text = null, string | null $switch_pm_parameter = null): responseError | bool { |
|
47 | 47 | return telegram::answerInlineQuery($results, $this->id, $cache_time, $is_personal, $next_offset, $switch_pm_text, $switch_pm_parameter); |
48 | 48 | } |
49 | 49 | } |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | * Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events |
39 | 39 | * only. |
40 | 40 | */ |
41 | - public null|chatInviteLink $invite_link = null; |
|
41 | + public null | chatInviteLink $invite_link = null; |
|
42 | 42 | |
43 | 43 | |
44 | - public function __construct(stdClass|null $object = null) { |
|
44 | + public function __construct(stdClass | null $object = null) { |
|
45 | 45 | if ($object != null) { |
46 | 46 | parent::__construct($object, self::subs); |
47 | 47 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | return $this->chat->isPrivate() && $this->isMe() && $this->isKicked(); |
56 | 56 | } |
57 | 57 | |
58 | - public function isMe (): bool { |
|
58 | + public function isMe(): bool { |
|
59 | 59 | return $this->new_chat_member->user->id == settings::$bot_id; |
60 | 60 | } |
61 | 61 | |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | return $this->isJoined() && !empty($this->invite_link); |
72 | 72 | } |
73 | 73 | |
74 | - public function isLeaved (): bool { |
|
74 | + public function isLeaved(): bool { |
|
75 | 75 | return $this->new_chat_member->status === chatMemberStatus::LEFT; |
76 | 76 | } |
77 | 77 | |
78 | - public function isKicked (): bool { |
|
78 | + public function isKicked(): bool { |
|
79 | 79 | return $this->new_chat_member->status === chatMemberStatus::KICKED; |
80 | 80 | } |
81 | 81 | |
82 | - public function isOldAdmin (): bool { |
|
82 | + public function isOldAdmin(): bool { |
|
83 | 83 | return $this->old_chat_member->status === chatMemberStatus::ADMINISTRATOR && $this->isJoined(); |
84 | 84 | } |
85 | 85 | |
86 | - public function isNewAdmin (): bool { |
|
86 | + public function isNewAdmin(): bool { |
|
87 | 87 | return $this->new_chat_member->status === chatMemberStatus::ADMINISTRATOR; |
88 | 88 | } |
89 | 89 | } |
@@ -32,19 +32,19 @@ |
||
32 | 32 | public string $invoice_payload; |
33 | 33 | |
34 | 34 | /** Optional. Identifier of the shipping option chosen by the user */ |
35 | - public null|string $shipping_option_id = null; |
|
35 | + public null | string $shipping_option_id = null; |
|
36 | 36 | |
37 | 37 | /** Optional. Order information provided by the user */ |
38 | - public null|orderInfo $order_info = null; |
|
38 | + public null | orderInfo $order_info = null; |
|
39 | 39 | |
40 | 40 | |
41 | - public function __construct(stdClass|null $object = null) { |
|
41 | + public function __construct(stdClass | null $object = null) { |
|
42 | 42 | if ($object != null) { |
43 | 43 | parent::__construct($object, self::subs); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - public function answer (bool $ok, string|null $error_message = null): responseError|bool { |
|
47 | + public function answer(bool $ok, string | null $error_message = null): responseError | bool { |
|
48 | 48 | return telegram::answerPreCheckoutQuery($ok, $this->id, $error_message); |
49 | 49 | } |
50 | 50 | } |
@@ -25,50 +25,50 @@ |
||
25 | 25 | * Optional. Message with the callback button that originated the query. Note that message content and message |
26 | 26 | * date will not be available if the message is too old |
27 | 27 | */ |
28 | - public null|message $message = null; |
|
28 | + public null | message $message = null; |
|
29 | 29 | |
30 | 30 | /** Optional. Identifier of the message sent via the bot in inline mode, that originated the query. */ |
31 | - public null|string $inline_message_id = null; |
|
31 | + public null | string $inline_message_id = null; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. |
35 | 35 | * Useful for high scores in games. |
36 | 36 | */ |
37 | - public null|string $chat_instance = null; |
|
37 | + public null | string $chat_instance = null; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Optional. Data associated with the callback button. Be aware that the message originated the query can contain |
41 | 41 | * no callback buttons with this data. |
42 | 42 | */ |
43 | - public null|string $data = null; |
|
43 | + public null | string $data = null; |
|
44 | 44 | |
45 | 45 | /** Optional. Short name of a Game to be returned, serves as the unique identifier for the game */ |
46 | - public null|string $game_short_name = null; |
|
46 | + public null | string $game_short_name = null; |
|
47 | 47 | |
48 | 48 | |
49 | - public function __construct(stdClass|null $object = null) { |
|
49 | + public function __construct(stdClass | null $object = null) { |
|
50 | 50 | if ($object != null) { |
51 | 51 | parent::__construct($object, self::subs); |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - public function answer (string|null $text = null, bool|null $show_alert = null, string|null $url = null, int|null $cache_time = null): responseError|bool { |
|
55 | + public function answer(string | null $text = null, bool | null $show_alert = null, string | null $url = null, int | null $cache_time = null): responseError | bool { |
|
56 | 56 | return telegram::answerCallbackQuery($this->id, $text, $show_alert, $url, $cache_time); |
57 | 57 | } |
58 | 58 | |
59 | - public function editText (string $text): message|responseError|bool { |
|
59 | + public function editText(string $text): message | responseError | bool { |
|
60 | 60 | return telegram::editMessageText($text); |
61 | 61 | } |
62 | 62 | |
63 | - public function editCaption (string $text = ''): message|responseError|bool { |
|
63 | + public function editCaption(string $text = ''): message | responseError | bool { |
|
64 | 64 | return telegram::editMessageCaption(caption: $text); |
65 | 65 | } |
66 | 66 | |
67 | - public function editKeyboard (inlineKeyboardMarkup|stdClass|array $reply_markup = null): message|responseError|bool { |
|
67 | + public function editKeyboard(inlineKeyboardMarkup | stdClass | array $reply_markup = null): message | responseError | bool { |
|
68 | 68 | return telegram::editMessageReplyMarkup(reply_markup: $reply_markup); |
69 | 69 | } |
70 | 70 | |
71 | - public function editMedia (inputMedia|array|stdClass $media): message|responseError|bool { |
|
71 | + public function editMedia(inputMedia | array | stdClass $media): message | responseError | bool { |
|
72 | 72 | return telegram::editMessageMedia($media); |
73 | 73 | } |
74 | 74 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * telegram class , Adding normal method call to request class and a simple name for being easy to call |
7 | 7 | */ |
8 | 8 | class telegram extends request { |
9 | - public function __call (string $name, array $arguments) { |
|
9 | + public function __call(string $name, array $arguments) { |
|
10 | 10 | return request::$name(...$arguments); |
11 | 11 | } |
12 | 12 | } |
13 | 13 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * If you want to use it in standalone mode , you MUST set `auto_process` to `false` |
29 | 29 | */ |
30 | - public static function init (string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void { |
|
30 | + public static function init(string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void { |
|
31 | 31 | $host = settings::$db['host'] ?? $host; |
32 | 32 | $port = settings::$db['port'] ?? $port; |
33 | 33 | $user = settings::$db['user'] ?? settings::$db['username'] ?? $username; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $dbname = settings::$db['dbname'] ?? $dbname; |
37 | 37 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
38 | 38 | if (self::$connection->connect_errno) { |
39 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
39 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
40 | 40 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
41 | 41 | } |
42 | 42 | if (self::$auto_process && !lock::exist('BPT-MYSQL')) { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - private static function install (): void { |
|
47 | + private static function install(): void { |
|
48 | 48 | self::pureQuery(" |
49 | 49 | CREATE TABLE `users` |
50 | 50 | ( |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * @internal Only for BPT self usage , Don't use it in your source! |
67 | 67 | */ |
68 | - public static function process (): void { |
|
68 | + public static function process(): void { |
|
69 | 69 | if (self::$auto_process) { |
70 | 70 | if (isset(BPT::$update->message)) { |
71 | 71 | self::processMessage(BPT::$update->message); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - private static function processMessage (message $update): void { |
|
88 | + private static function processMessage(message $update): void { |
|
89 | 89 | $type = $update->chat->type; |
90 | 90 | if ($type === chatType::PRIVATE) { |
91 | 91 | $user_id = $update->from->id; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
114 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
115 | 115 | $type = $update->message->chat->type; |
116 | 116 | if ($type === chatType::PRIVATE) { |
117 | 117 | $user_id = $update->from->id; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - private static function processInlineQuery (inlineQuery $update): void { |
|
124 | + private static function processInlineQuery(inlineQuery $update): void { |
|
125 | 125 | $type = $update->chat_type; |
126 | 126 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
127 | 127 | $user_id = $update->from->id; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
134 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
134 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
135 | 135 | $type = $update->chat->type; |
136 | 136 | if ($type === chatType::PRIVATE) { |
137 | 137 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return mysqli |
150 | 150 | */ |
151 | - public static function getMysqli (): mysqli { |
|
151 | + public static function getMysqli(): mysqli { |
|
152 | 152 | return self::$connection; |
153 | 153 | } |
154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return int|string |
159 | 159 | */ |
160 | - public static function affected_rows (): int|string { |
|
160 | + public static function affected_rows(): int | string { |
|
161 | 161 | return self::$connection->affected_rows; |
162 | 162 | } |
163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return int|string |
168 | 168 | */ |
169 | - public static function insert_id (): int|string { |
|
169 | + public static function insert_id(): int | string { |
|
170 | 170 | return self::$connection->insert_id; |
171 | 171 | } |
172 | 172 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return string |
179 | 179 | */ |
180 | - public static function escapeString (string $text): string { |
|
180 | + public static function escapeString(string $text): string { |
|
181 | 181 | return self::$connection->real_escape_string($text); |
182 | 182 | } |
183 | 183 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public static function error (): string { |
|
189 | + public static function error(): string { |
|
190 | 190 | return self::$connection->error; |
191 | 191 | } |
192 | 192 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @return int |
197 | 197 | */ |
198 | - public static function errno (): int { |
|
198 | + public static function errno(): int { |
|
199 | 199 | return self::$connection->errno; |
200 | 200 | } |
201 | 201 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return bool |
208 | 208 | */ |
209 | - public static function setCharset (string $charset): bool { |
|
209 | + public static function setCharset(string $charset): bool { |
|
210 | 210 | return self::$connection->set_charset($charset); |
211 | 211 | } |
212 | 212 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return mysqli_result|bool |
223 | 223 | */ |
224 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
224 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
225 | 225 | return self::$connection->query($query); |
226 | 226 | } |
227 | 227 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @return mysqli_result|bool |
244 | 244 | */ |
245 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
245 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
246 | 246 | if (empty($vars)) { |
247 | 247 | return self::pureQuery($query); |
248 | 248 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $types .= 's'; |
260 | 260 | } |
261 | 261 | } |
262 | - $prepare->bind_param($types,...$vars); |
|
262 | + $prepare->bind_param($types, ...$vars); |
|
263 | 263 | if (!$prepare->execute()) { |
264 | 264 | logger::write(loggerTypes::WARNING, $prepare->error); |
265 | 265 | return false; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | return $need_result ? $prepare->get_result() : true; |
268 | 268 | } |
269 | 269 | |
270 | - private static function makeArrayReady (string &$query, array $array, string $operator = ' AND ', bool $is_update = false): array { |
|
270 | + private static function makeArrayReady(string &$query, array $array, string $operator = ' AND ', bool $is_update = false): array { |
|
271 | 271 | $first = true; |
272 | 272 | $values = []; |
273 | 273 | foreach ($array as $name => $value) { |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | else { |
278 | 278 | $query .= $operator; |
279 | 279 | } |
280 | - if ($is_update && str_starts_with($value, '.=') && is_numeric(substr($value,2))) { |
|
280 | + if ($is_update && str_starts_with($value, '.=') && is_numeric(substr($value, 2))) { |
|
281 | 281 | $query .= " `$name` = `$name` + ?"; |
282 | - $values[] = substr($value,2); |
|
282 | + $values[] = substr($value, 2); |
|
283 | 283 | } |
284 | 284 | else { |
285 | 285 | $query .= " `$name` = ?"; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | return $values; |
291 | 291 | } |
292 | 292 | |
293 | - private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
293 | + private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
294 | 294 | $values = []; |
295 | 295 | if (!empty($where)) { |
296 | 296 | $query .= " WHERE"; |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | $query .= ' AND'; |
323 | 323 | } |
324 | 324 | |
325 | - $operator = substr($value,0,2); |
|
326 | - $operator_value = substr($value,2); |
|
325 | + $operator = substr($value, 0, 2); |
|
326 | + $operator_value = substr($value, 2); |
|
327 | 327 | switch ($operator) { |
328 | 328 | case '>=': |
329 | 329 | $query .= " `$name` >= ?"; |
@@ -360,17 +360,17 @@ discard block |
||
360 | 360 | return $values; |
361 | 361 | } |
362 | 362 | |
363 | - private static function groupByBuilder(string &$query, string|array $group_by = []): void { |
|
363 | + private static function groupByBuilder(string &$query, string | array $group_by = []): void { |
|
364 | 364 | if (empty($group_by)) { |
365 | 365 | return; |
366 | 366 | } |
367 | 367 | if (is_string($group_by)) { |
368 | 368 | $group_by = [$group_by]; |
369 | 369 | } |
370 | - $query .= ' GROUP BY `' . implode('`, `',$group_by) . '`'; |
|
370 | + $query .= ' GROUP BY `'.implode('`, `', $group_by).'`'; |
|
371 | 371 | } |
372 | 372 | |
373 | - private static function orderByBuilder(string &$query, string|array $order_by = []): void { |
|
373 | + private static function orderByBuilder(string &$query, string | array $order_by = []): void { |
|
374 | 374 | if (empty($order_by)) { |
375 | 375 | return; |
376 | 376 | } |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | $query .= ' ,'; |
418 | 418 | } |
419 | 419 | |
420 | - $operator = substr($value,0,2); |
|
421 | - $operator_value = substr($value,2); |
|
420 | + $operator = substr($value, 0, 2); |
|
421 | + $operator_value = substr($value, 2); |
|
422 | 422 | switch ($operator) { |
423 | 423 | case '+=': |
424 | 424 | $query .= " `$name` = `$name` + ?"; |
@@ -451,19 +451,19 @@ discard block |
||
451 | 451 | return $values; |
452 | 452 | } |
453 | 453 | |
454 | - private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
|
455 | - $query .= '(`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
|
454 | + private static function insertBuilder(string &$query, string | array $columns, array | string $values): array { |
|
455 | + $query .= '(`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES ('; |
|
456 | 456 | if (is_string($values)) $values = [$values]; |
457 | - $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
|
457 | + $query .= '?'.str_repeat(',?', count($values) - 1).')'; |
|
458 | 458 | return $values; |
459 | 459 | } |
460 | 460 | |
461 | - private static function selectBuilder(string &$query, string|array $columns): void { |
|
461 | + private static function selectBuilder(string &$query, string | array $columns): void { |
|
462 | 462 | if ($columns == '*') { |
463 | 463 | $query .= " * "; |
464 | 464 | } |
465 | 465 | else { |
466 | - $query .= ' `' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
|
466 | + $query .= ' `'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` '; |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * |
480 | 480 | * @return mysqli_result|bool |
481 | 481 | */ |
482 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null): bool { |
|
482 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null): bool { |
|
483 | 483 | $query = "DELETE FROM `$table`"; |
484 | 484 | $vars = self::whereBuilder($query, $where); |
485 | 485 | return self::query($query, $vars, false); |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * |
499 | 499 | * @return mysqli_result|bool |
500 | 500 | */ |
501 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): bool { |
|
501 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): bool { |
|
502 | 502 | $query = "UPDATE `$table` SET"; |
503 | 503 | $modify_vars = self::updateBuilder($query, $modify); |
504 | 504 | $where_vars = self::whereBuilder($query, $where); |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | * |
518 | 518 | * @return mysqli_result|bool |
519 | 519 | */ |
520 | - public static function insert (string $table, string|array $columns, array|string $values): bool { |
|
520 | + public static function insert(string $table, string | array $columns, array | string $values): bool { |
|
521 | 521 | $query = "INSERT INTO `$table`"; |
522 | 522 | $values = self::insertBuilder($query, $columns, $values); |
523 | 523 | return self::query($query, $values, false); |
@@ -540,14 +540,14 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @return mysqli_result|bool |
542 | 542 | */ |
543 | - 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 = []): mysqli_result|bool { |
|
543 | + 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 = []): mysqli_result | bool { |
|
544 | 544 | $query = "SELECT"; |
545 | 545 | self::selectBuilder($query, $columns); |
546 | 546 | $query .= "FROM `$table`"; |
547 | - $var = self::whereBuilder($query,$where); |
|
547 | + $var = self::whereBuilder($query, $where); |
|
548 | 548 | self::groupByBuilder($query, $group_by); |
549 | 549 | self::orderByBuilder($query, $order_by); |
550 | - self::countBuilder($query,$count,$offset); |
|
550 | + self::countBuilder($query, $count, $offset); |
|
551 | 551 | return self::query($query, $var); |
552 | 552 | } |
553 | 553 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | * |
563 | 563 | * @return null|bool|array |
564 | 564 | */ |
565 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null { |
|
565 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null { |
|
566 | 566 | $res = self::select($table, $columns, $where, 1); |
567 | 567 | if ($res) { |
568 | 568 | return $res->fetch_assoc(); |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*' |
580 | 580 | * @param array|null $where Set your ifs default : null |
581 | 581 | */ |
582 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null) { |
|
582 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null) { |
|
583 | 583 | $res = self::select($table, $columns, $where, 1); |
584 | 584 | if ($res) { |
585 | 585 | return $res->fetch_object(); |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | * |
602 | 602 | * @return bool|Generator |
603 | 603 | */ |
604 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
|
604 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator { |
|
605 | 605 | $res = self::select($table, $columns, $where, $count, $offset); |
606 | 606 | if ($res) { |
607 | 607 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -619,21 +619,21 @@ discard block |
||
619 | 619 | * |
620 | 620 | * @return string if save is true , return file name otherwise return sql data |
621 | 621 | */ |
622 | - public static function backup (array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string { |
|
622 | + public static function backup(array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string { |
|
623 | 623 | self::setCharset('utf8mb4'); |
624 | - $tables = array_column(self::query('SHOW TABLES')->fetch_all(),0); |
|
624 | + $tables = array_column(self::query('SHOW TABLES')->fetch_all(), 0); |
|
625 | 625 | if (!empty($wanted_tables)) { |
626 | 626 | $tables = array_intersect($tables, $wanted_tables); |
627 | 627 | } |
628 | 628 | $sql = ''; |
629 | 629 | foreach ($tables as $table) { |
630 | - $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1] . ";\n\n"; |
|
630 | + $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1].";\n\n"; |
|
631 | 631 | |
632 | 632 | if ($table_data) { |
633 | 633 | $total_rows = self::query("SELECT COUNT(*) as `cnt` FROM `$table`")->fetch_object()->cnt; |
634 | 634 | for ($i = 0; $i < $total_rows; $i = $i + 1000) { |
635 | - $sql .= "INSERT INTO " . $table . " VALUES"; |
|
636 | - $result = self::select($table, '*' , null, 1000, $i); |
|
635 | + $sql .= "INSERT INTO ".$table." VALUES"; |
|
636 | + $result = self::select($table, '*', null, 1000, $i); |
|
637 | 637 | $field_count = $result->field_count; |
638 | 638 | $affected_rows = self::affected_rows(); |
639 | 639 | $counter = 1; |
@@ -641,12 +641,12 @@ discard block |
||
641 | 641 | $sql .= "\n("; |
642 | 642 | for ($column = 0; $column < $field_count; $column++) { |
643 | 643 | $row[$column] = str_replace("\n", "\\n", addslashes($row[$column])); |
644 | - $sql .= !empty($row[$column]) ? '"' . $row[$column] . '"' : '""'; |
|
644 | + $sql .= !empty($row[$column]) ? '"'.$row[$column].'"' : '""'; |
|
645 | 645 | if ($column < $field_count - 1) { |
646 | 646 | $sql .= ','; |
647 | 647 | } |
648 | 648 | } |
649 | - $sql .= ')' . ($counter == $affected_rows ? ';' : ','); |
|
649 | + $sql .= ')'.($counter == $affected_rows ? ';' : ','); |
|
650 | 650 | $counter++; |
651 | 651 | } |
652 | 652 | } |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | return $sql; |
661 | 661 | } |
662 | 662 | if (empty($file_name)) { |
663 | - $file_name = self::query('SELECT database() as `db_name`')->fetch_object()->db_name . time() . '.sql'; |
|
663 | + $file_name = self::query('SELECT database() as `db_name`')->fetch_object()->db_name.time().'.sql'; |
|
664 | 664 | } |
665 | 665 | file_put_contents($file_name, $sql); |
666 | 666 | return $file_name; |
@@ -69,17 +69,13 @@ discard block |
||
69 | 69 | if (self::$auto_process) { |
70 | 70 | if (isset(BPT::$update->message)) { |
71 | 71 | self::processMessage(BPT::$update->message); |
72 | - } |
|
73 | - elseif (isset(BPT::$update->edited_message)) { |
|
72 | + } elseif (isset(BPT::$update->edited_message)) { |
|
74 | 73 | self::processMessage(BPT::$update->edited_message); |
75 | - } |
|
76 | - elseif (isset(BPT::$update->callback_query)) { |
|
74 | + } elseif (isset(BPT::$update->callback_query)) { |
|
77 | 75 | self::processCallbackQuery(BPT::$update->callback_query); |
78 | - } |
|
79 | - elseif (isset(BPT::$update->inline_query)) { |
|
76 | + } elseif (isset(BPT::$update->inline_query)) { |
|
80 | 77 | self::processInlineQuery(BPT::$update->inline_query); |
81 | - } |
|
82 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
78 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
83 | 79 | self::processMyChatMember(BPT::$update->my_chat_member); |
84 | 80 | } |
85 | 81 | } |
@@ -136,8 +132,7 @@ discard block |
||
136 | 132 | if ($type === chatType::PRIVATE) { |
137 | 133 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
138 | 134 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
139 | - } |
|
140 | - else { |
|
135 | + } else { |
|
141 | 136 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
142 | 137 | } |
143 | 138 | } |
@@ -251,11 +246,9 @@ discard block |
||
251 | 246 | foreach ($vars as $var) { |
252 | 247 | if (is_int($var)) { |
253 | 248 | $types .= 'i'; |
254 | - } |
|
255 | - elseif (is_double($var)) { |
|
249 | + } elseif (is_double($var)) { |
|
256 | 250 | $types .= 'd'; |
257 | - } |
|
258 | - else { |
|
251 | + } else { |
|
259 | 252 | $types .= 's'; |
260 | 253 | } |
261 | 254 | } |
@@ -273,15 +266,13 @@ discard block |
||
273 | 266 | foreach ($array as $name => $value) { |
274 | 267 | if ($first) { |
275 | 268 | $first = false; |
276 | - } |
|
277 | - else { |
|
269 | + } else { |
|
278 | 270 | $query .= $operator; |
279 | 271 | } |
280 | 272 | if ($is_update && str_starts_with($value, '.=') && is_numeric(substr($value,2))) { |
281 | 273 | $query .= " `$name` = `$name` + ?"; |
282 | 274 | $values[] = substr($value,2); |
283 | - } |
|
284 | - else { |
|
275 | + } else { |
|
285 | 276 | $query .= " `$name` = ?"; |
286 | 277 | $values[] = $value; |
287 | 278 | } |
@@ -298,8 +289,7 @@ discard block |
||
298 | 289 | } |
299 | 290 | if (!empty($count)) { |
300 | 291 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
301 | - } |
|
302 | - elseif (!empty($offset)) { |
|
292 | + } elseif (!empty($offset)) { |
|
303 | 293 | $query .= " OFFSET $offset"; |
304 | 294 | } |
305 | 295 | return $values; |
@@ -317,8 +307,7 @@ discard block |
||
317 | 307 | foreach ($where as $name => $value) { |
318 | 308 | if ($first) { |
319 | 309 | $first = false; |
320 | - } |
|
321 | - else { |
|
310 | + } else { |
|
322 | 311 | $query .= ' AND'; |
323 | 312 | } |
324 | 313 | |
@@ -384,8 +373,7 @@ discard block |
||
384 | 373 | foreach ($order_by as $key => $mode) { |
385 | 374 | if ($first) { |
386 | 375 | $first = false; |
387 | - } |
|
388 | - else { |
|
376 | + } else { |
|
389 | 377 | $query .= ', '; |
390 | 378 | } |
391 | 379 | if (is_numeric($key)) { |
@@ -399,8 +387,7 @@ discard block |
||
399 | 387 | private static function countBuilder(string &$query, int $count = null, int $offset = null): void { |
400 | 388 | if (!empty($count)) { |
401 | 389 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
402 | - } |
|
403 | - elseif (!empty($offset)) { |
|
390 | + } elseif (!empty($offset)) { |
|
404 | 391 | $query .= " OFFSET $offset"; |
405 | 392 | } |
406 | 393 | } |
@@ -412,8 +399,7 @@ discard block |
||
412 | 399 | foreach ($modify as $name => $value) { |
413 | 400 | if ($first) { |
414 | 401 | $first = false; |
415 | - } |
|
416 | - else { |
|
402 | + } else { |
|
417 | 403 | $query .= ' ,'; |
418 | 404 | } |
419 | 405 | |
@@ -453,7 +439,9 @@ discard block |
||
453 | 439 | |
454 | 440 | private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
455 | 441 | $query .= '(`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
456 | - if (is_string($values)) $values = [$values]; |
|
442 | + if (is_string($values)) { |
|
443 | + $values = [$values]; |
|
444 | + } |
|
457 | 445 | $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
458 | 446 | return $values; |
459 | 447 | } |
@@ -461,8 +449,7 @@ discard block |
||
461 | 449 | private static function selectBuilder(string &$query, string|array $columns): void { |
462 | 450 | if ($columns == '*') { |
463 | 451 | $query .= " * "; |
464 | - } |
|
465 | - else { |
|
452 | + } else { |
|
466 | 453 | $query .= ' `' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
467 | 454 | } |
468 | 455 | } |
@@ -604,9 +591,12 @@ discard block |
||
604 | 591 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
605 | 592 | $res = self::select($table, $columns, $where, $count, $offset); |
606 | 593 | if ($res) { |
607 | - while ($row = $res->fetch_assoc()) yield $row; |
|
594 | + while ($row = $res->fetch_assoc()) { |
|
595 | + yield $row; |
|
596 | + } |
|
597 | + } else { |
|
598 | + return $res; |
|
608 | 599 | } |
609 | - else return $res; |
|
610 | 600 | } |
611 | 601 | |
612 | 602 | /** |
@@ -271,13 +271,13 @@ discard block |
||
271 | 271 | * @method bool downloadFile(string|null $destination = null, string|null $file_id = null) download file by file_id and save it to destination |
272 | 272 | * @method message|bool|responseError sendFile(string $file_id, int|string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null) send file only with file_id |
273 | 273 | */ |
274 | -class BPT extends telegram{ |
|
274 | +class BPT extends telegram { |
|
275 | 275 | public static update $update; |
276 | 276 | |
277 | 277 | public static BPT $handler; |
278 | 278 | |
279 | 279 | |
280 | - public function __construct (array|stdClass $settings) { |
|
280 | + public function __construct(array | stdClass $settings) { |
|
281 | 281 | static::$handler = &$this; |
282 | 282 | settings::init($settings); |
283 | 283 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | #[NoReturn] |
290 | - public static function exit (string|null $message = null) { |
|
290 | + public static function exit (string | null $message = null) { |
|
291 | 291 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
292 | 292 | } |
293 | 293 | } |