@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
31 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
32 | 32 | $rand_string = ''; |
33 | 33 | $char_len = strlen($characters) - 1; |
34 | - for ($i = 0; $i < $length; $i ++) { |
|
34 | + for ($i = 0; $i < $length; $i++) { |
|
35 | 35 | $rand_string .= $characters[rand(0, $char_len)]; |
36 | 36 | } |
37 | 37 | return $rand_string; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
61 | 61 | * @throws bptException |
62 | 62 | */ |
63 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
63 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
64 | 64 | if (!empty($keyboard)) { |
65 | 65 | $keyboard_object = new replyKeyboardMarkup(); |
66 | 66 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | return $keyboard_object; |
120 | 120 | } |
121 | 121 | else { |
122 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
122 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
123 | 123 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
124 | 124 | } |
125 | 125 | } |
@@ -68,7 +68,9 @@ discard block |
||
68 | 68 | $keyboard_object->setOne_time_keyboard($keyboard['one_time']); |
69 | 69 | } |
70 | 70 | foreach ($keyboard as $row) { |
71 | - if (!is_array($row)) continue; |
|
71 | + if (!is_array($row)) { |
|
72 | + continue; |
|
73 | + } |
|
72 | 74 | $buttons = []; |
73 | 75 | foreach ($row as $base_button) { |
74 | 76 | $button_info = explode('||', $base_button); |
@@ -77,15 +79,12 @@ discard block |
||
77 | 79 | if (count($button_info) > 1) { |
78 | 80 | if ($button_info[1] === 'con') { |
79 | 81 | $button->setRequest_contact(true); |
80 | - } |
|
81 | - elseif ($button_info[1] === 'loc') { |
|
82 | + } elseif ($button_info[1] === 'loc') { |
|
82 | 83 | $button->setRequest_location(true); |
83 | - } |
|
84 | - elseif ($button_info[1] === 'poll') { |
|
84 | + } elseif ($button_info[1] === 'poll') { |
|
85 | 85 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
86 | 86 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
87 | - } |
|
88 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
87 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
89 | 88 | $url = $button_info[2]; |
90 | 89 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
91 | 90 | } |
@@ -95,8 +94,7 @@ discard block |
||
95 | 94 | $keyboard_object->setKeyboard([$buttons]); |
96 | 95 | } |
97 | 96 | return $keyboard_object; |
98 | - } |
|
99 | - elseif (!empty($inline)) { |
|
97 | + } elseif (!empty($inline)) { |
|
100 | 98 | $keyboard_object = new inlineKeyboardMarkup(); |
101 | 99 | foreach ($inline as $row) { |
102 | 100 | $buttons = []; |
@@ -105,20 +103,17 @@ discard block |
||
105 | 103 | if (isset($button_info[1])) { |
106 | 104 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
107 | 105 | $button->setText($button_info[0])->setUrl($button_info[1]); |
108 | - } |
|
109 | - else { |
|
106 | + } else { |
|
110 | 107 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
111 | 108 | } |
112 | - } |
|
113 | - else { |
|
109 | + } else { |
|
114 | 110 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
115 | 111 | } |
116 | 112 | } |
117 | 113 | $keyboard_object->setInline_keyboard([$buttons]); |
118 | 114 | } |
119 | 115 | return $keyboard_object; |
120 | - } |
|
121 | - else { |
|
116 | + } else { |
|
122 | 117 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
123 | 118 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
124 | 119 | } |
@@ -105,8 +105,9 @@ |
||
105 | 105 | foreach ($string as $k => &$v) { |
106 | 106 | if ($diff->$v) { |
107 | 107 | $v = $diff->$v; |
108 | + } else { |
|
109 | + unset($string[$k]); |
|
108 | 110 | } |
109 | - else unset($string[$k]); |
|
110 | 111 | } |
111 | 112 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
112 | 113 |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - public static function byteFormat (int $byte, int $precision = 2): string { |
|
24 | + public static function byteFormat(int $byte, int $precision = 2): string { |
|
25 | 25 | $rate_counter = 0; |
26 | 26 | |
27 | - while ($byte > 1024){ |
|
27 | + while ($byte > 1024) { |
|
28 | 28 | $byte /= 1024; |
29 | 29 | $rate_counter++; |
30 | 30 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $byte = round($byte, $precision); |
34 | 34 | } |
35 | 35 | |
36 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
36 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return string|false return false when mode is incorrect |
52 | 52 | */ |
53 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
53 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
54 | 54 | return match ($mode) { |
55 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
56 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
55 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
56 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
57 | 57 | parseMode::MARKDOWNV2 => str_replace( |
58 | 58 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
59 | 59 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
93 | 93 | * @throws Exception |
94 | 94 | */ |
95 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
95 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
96 | 96 | if (!isset($base_time)) { |
97 | 97 | $base_time = '@'.time(); |
98 | 98 | } |
99 | 99 | $base_time = new DateTime($base_time); |
100 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
100 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
101 | 101 | |
102 | 102 | $diff = $base_time->diff($target_time); |
103 | 103 | |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return string[]|string |
126 | 126 | */ |
127 | - public static function realEscapeString(string|array $input): string|array { |
|
128 | - if(is_array($input)) { |
|
127 | + public static function realEscapeString(string | array $input): string | array { |
|
128 | + if (is_array($input)) { |
|
129 | 129 | return array_map(__METHOD__, $input); |
130 | 130 | } |
131 | 131 | |
132 | - if(!empty($input) && is_string($input)) { |
|
132 | + if (!empty($input) && is_string($input)) { |
|
133 | 133 | return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $input); |
134 | 134 | } |
135 | 135 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return string[]|string |
149 | 149 | */ |
150 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
150 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
151 | 151 | $pos = strpos($subject, $search); |
152 | 152 | if ($pos !== false) { |
153 | 153 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | /** |
12 | 12 | * @method Json_init |
13 | 13 | */ |
14 | - public function json_init () { |
|
14 | + public function json_init() { |
|
15 | 15 | (new jsondb())->init(handler::$dbname); |
16 | 16 | } |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * |
50 | 50 | */ |
51 | - public function __construct (array $settings) { |
|
51 | + public function __construct(array $settings) { |
|
52 | 52 | if (in_array($settings['type'], self::TYPES)) { |
53 | 53 | if ($settings['type'] === 'Mysqli') { |
54 | 54 | if (self::CheckParam($settings)) { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - private static function CheckParam (array $array) { |
|
91 | + private static function CheckParam(array $array) { |
|
92 | 92 | if (isset($array['username']) && isset($array['dbname']) && isset($array['password'])) { |
93 | 93 | self::$host = $array['host'] ?? 'localhost'; |
94 | 94 | self::$username = $array['username']; |
@@ -62,13 +62,11 @@ discard block |
||
62 | 62 | if ($db) { |
63 | 63 | self::$connect = $db; |
64 | 64 | print_r($db); |
65 | - } |
|
66 | - else { |
|
65 | + } else { |
|
67 | 66 | print self::$username; |
68 | 67 | throw new \exception('a problem to connecting'); |
69 | 68 | } |
70 | - } |
|
71 | - else { |
|
69 | + } else { |
|
72 | 70 | throw new \exception('required parameters not found'); |
73 | 71 | } |
74 | 72 | } |
@@ -77,13 +75,11 @@ discard block |
||
77 | 75 | self::$type = $settings['type']; |
78 | 76 | self::$dbname = $settings['dbname']; |
79 | 77 | (new database())->json_init(); |
80 | - } |
|
81 | - else { |
|
78 | + } else { |
|
82 | 79 | throw new \exception('parameter dbanme not found'); |
83 | 80 | } |
84 | 81 | } |
85 | - } |
|
86 | - else { |
|
82 | + } else { |
|
87 | 83 | throw new \exception('parameter type not found'); |
88 | 84 | } |
89 | 85 | } |
@@ -96,8 +92,7 @@ discard block |
||
96 | 92 | self::$password = $array['password']; |
97 | 93 | self::$charset = $array['charset'] ?? 'utf8'; |
98 | 94 | return true; |
99 | - } |
|
100 | - else { |
|
95 | + } else { |
|
101 | 96 | return false; |
102 | 97 | } |
103 | 98 | } |
@@ -7,4 +7,4 @@ |
||
7 | 7 | /** |
8 | 8 | * Exceptions created by BPT and subclasses |
9 | 9 | */ |
10 | -class bptException extends Exception{} |
|
11 | 10 | \ No newline at end of file |
11 | +class bptException extends Exception {} |
|
12 | 12 | \ No newline at end of file |
@@ -4,4 +4,4 @@ |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -class telegramException extends Exception{} |
|
8 | 7 | \ No newline at end of file |
8 | +class telegramException extends Exception {} |
|
9 | 9 | \ No newline at end of file |
@@ -236,13 +236,13 @@ discard block |
||
236 | 236 | * @method gameHighScore[]|responseError getGameHighScores (int|null|array $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects. |
237 | 237 | * @method gameHighScore[]|responseError getGameHigh (int|null|array $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects. |
238 | 238 | */ |
239 | -class BPT extends telegram{ |
|
239 | +class BPT extends telegram { |
|
240 | 240 | public static update $update; |
241 | 241 | |
242 | 242 | public static BPT $handler; |
243 | 243 | |
244 | 244 | |
245 | - public function __construct (array|stdClass $settings) { |
|
245 | + public function __construct(array | stdClass $settings) { |
|
246 | 246 | static::$handler = &$this; |
247 | 247 | settings::init($settings); |
248 | 248 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | settings::done(); |
252 | 252 | } |
253 | 253 | |
254 | - public static function exit (string|null $message = null) { |
|
254 | + public static function exit (string | null $message = null) { |
|
255 | 255 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
256 | 256 | } |
257 | 257 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | public string $description; |
19 | 19 | |
20 | 20 | |
21 | - public function __construct(stdClass|null $object = null) { |
|
21 | + public function __construct(stdClass | null $object = null) { |
|
22 | 22 | if ($object != null) { |
23 | 23 | parent::__construct($object, self::subs); |
24 | 24 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | /** Keep all of properties which has sub properties */ |
12 | 12 | private const subs = []; |
13 | 13 | |
14 | - public function __construct(stdClass|null $object = null) { |
|
14 | + public function __construct(stdClass | null $object = null) { |
|
15 | 15 | if ($object != null) { |
16 | 16 | parent::__construct($object, self::subs); |
17 | 17 | } |