1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DanySpin97\PhpBotFramework; |
4
|
|
|
|
5
|
|
|
/** \class InlineKeyboard |
6
|
|
|
* \brief Inline Keyboard handler that create and handle inline keyboard buttons. |
7
|
|
|
* \details It stores the inline keyboard buttons added until get() is called. |
8
|
|
|
* It also provides some basic button to get, like Menu and Back buttons plus the dynamic-keyboard for menu browsing. |
9
|
|
|
*/ |
10
|
|
|
class InlineKeyboard { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* \addtogroup InlineKeyboard InlineKeyboard |
14
|
|
|
* \brief Handle an inline keyboard to send along with messages. |
15
|
|
|
* @{ |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
/** \brief Store the array of InlineKeyboardButton */ |
19
|
|
|
protected $inline_keyboard; |
20
|
|
|
|
21
|
|
|
/** \brief Store a reference to the bot that is using this inline keyboard. */ |
22
|
|
|
protected $bot; |
23
|
|
|
|
24
|
|
|
/** \brief Store the current row. */ |
25
|
|
|
private $row; |
26
|
|
|
|
27
|
|
|
/** \brief Store the current column. */ |
28
|
|
|
private $column; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* \brief Create an inline keyboard object. |
32
|
|
|
* @param $bot The bot that owns this object. |
33
|
|
|
* @param $buttons Buttons passed as inizialization. |
34
|
|
|
* @return The object created with the buttons passed. |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct(CoreBot &$bot = null, array $buttons = array()) { |
37
|
|
|
|
38
|
|
|
// Get bot reference |
39
|
|
|
$this->bot = $bot; |
40
|
|
|
|
41
|
|
|
// If $buttons is empty, initialize it with an empty array |
42
|
|
|
$this->inline_keyboard = $buttons; |
43
|
|
|
|
44
|
|
|
// Set up vars |
45
|
|
|
$this->row = 0; |
46
|
|
|
$this->column = 0; |
47
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* \brief Get a JSON-serialized object containg the inline keyboard. |
52
|
|
|
* @param $clear_keyboard Remove all the buttons from this object. |
53
|
|
|
* @return JSON-serialized string with the buttons. |
|
|
|
|
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function get($clear_keyboard = true) { |
|
|
|
|
56
|
|
|
|
57
|
|
|
// Check if it is empty |
58
|
|
|
if (empty($this->inline_keyboard)) { |
59
|
|
|
|
60
|
|
|
throw new BotException("Inline keyboard is empty"); |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Create a new array to put our buttons |
65
|
|
|
$reply_markup = ['inline_keyboard' => $this->inline_keyboard]; |
66
|
|
|
|
67
|
|
|
// Encode the array in a json object |
68
|
|
|
$reply_markup = json_encode($reply_markup); |
69
|
|
|
|
70
|
|
|
if ($clear_keyboard) { |
71
|
|
|
|
72
|
|
|
$this->clearKeyboard(); |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $reply_markup; |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* \brief Get the array containing the buttons. (Use this method when adding keyboard to inline query results) |
82
|
|
|
* @param $clean_keyboard Remove all the button from this object. |
83
|
|
|
* @return An array containing the buttons. |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function getArray($clean_keyboard = true) { |
|
|
|
|
86
|
|
|
|
87
|
|
|
// Check if it is empty |
88
|
|
|
if (empty($this->inline_keyboard)) { |
89
|
|
|
|
90
|
|
|
throw new BotException("Inline keyboard is empty"); |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// Create a new array to put the buttons |
95
|
|
|
$reply_markup = ['inline_keyboard' => $this->inline_keyboard]; |
96
|
|
|
|
97
|
|
|
if ($clean_keyboard) { |
98
|
|
|
|
99
|
|
|
$this->clearKeyboard(); |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $reply_markup; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** \brief Add buttons for the current row of buttons |
107
|
|
|
* \details Each array sent as parameter require a text key |
108
|
|
|
* and one another key (as specified <a href="https://core.telegram.org/bots/api/#inlinekeyboardbutton" target="blank">here</a> between: |
109
|
|
|
* - url |
110
|
|
|
* - callback_data |
111
|
|
|
* - switch_inline_query |
112
|
|
|
* - switch_inline_query_current_chat |
113
|
|
|
* - callback_game |
114
|
|
|
* |
115
|
|
|
* Each call to this function add one or more button to a row. The next call add buttons on the next row. |
116
|
|
|
* Each row allows 8 buttons per row and 12 columns total. |
117
|
|
|
* Use this function with this syntax: |
118
|
|
|
* |
119
|
|
|
* addLevelButtons(['text' => 'Click me!', 'url' => 'https://telegram.me']); |
120
|
|
|
* |
121
|
|
|
* If you want to add more than a button, use this syntax: |
122
|
|
|
* |
123
|
|
|
* addLevelButtons(['text' => 'Button 1', 'url' => 'https://telegram.me/gamedev_ita'], ['text' => 'Button 2', 'url' => 'https://telegram.me/animewallpaper']); |
124
|
|
|
* |
125
|
|
|
* @param ...$buttons One or more arrays, each one represent a button. |
126
|
|
|
*/ |
127
|
|
|
public function addLevelButtons(array ...$buttons) { |
128
|
|
|
|
129
|
|
|
// Add buttons to the next row |
130
|
|
|
$this->inline_keyboard[] = $buttons; |
131
|
|
|
|
132
|
|
|
// Switch to the next row |
133
|
|
|
$this->changeRow(); |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** \brief Add a button. |
138
|
|
|
* \details The button will be added next to the last one or in the next row if the bot has reached the limit for the buttons per row. |
139
|
|
|
* |
140
|
|
|
* Each row allows 8 buttons per row and 12 columns total. |
141
|
|
|
* Use this function with this syntax: |
142
|
|
|
* |
143
|
|
|
* addButton('Click me!', 'url', 'https://telegram.me'); |
144
|
|
|
* |
145
|
|
|
* @param $text Text showed on the button. |
146
|
|
|
* @param $data_type The type of the button data. |
147
|
|
|
* Select one from these types. |
148
|
|
|
* - url |
149
|
|
|
* - callback_data |
150
|
|
|
* - switch_inline_query |
151
|
|
|
* - switch_inline_query_current_chat |
152
|
|
|
* - callback_game |
153
|
|
|
* @param $data Data for the type selected. |
154
|
|
|
*/ |
155
|
|
|
public function addButton($text, string $data_type, $data) { |
156
|
|
|
|
157
|
|
|
// If we get the end of the row |
158
|
|
|
if ($this->column == 8) { |
159
|
|
|
|
160
|
|
|
$this->changeRow(); |
161
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
// Add the button |
165
|
|
|
$this->inline_keyboard[$this->row][$this->column] = ['text' => $text, $data_type => $data]; |
166
|
|
|
|
167
|
|
|
// Update column |
168
|
|
|
$this->column++; |
169
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* \brief Change row for the current keyboard. |
174
|
|
|
* \details Buttons will be added in the next row from now on (until next InlineKeyboard::addLevelButtons() or InlineKeyboard::changeRow() call or InlineKeyboard::addButton() reaches the max). |
175
|
|
|
*/ |
176
|
|
|
public function changeRow() { |
177
|
|
|
|
178
|
|
|
// Reset vars |
179
|
|
|
$this->row++; |
180
|
|
|
$this->column = 0; |
181
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** \brief Remove all the buttons from the current inline keyboard. */ |
185
|
|
|
public function clearKeyboard() { |
186
|
|
|
|
187
|
|
|
// Set the inline keyboard to an empty array |
188
|
|
|
$this->inline_keyboard = []; |
189
|
|
|
|
190
|
|
|
// Reset vars |
191
|
|
|
$this->row = 0; |
192
|
|
|
$this->column = 0; |
193
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* \brief Get a simple Back button with back as callback_data. |
198
|
|
|
* @param $json_serialized return a json serialized string, or an array. |
199
|
|
|
* @return A button with written "back". |
200
|
|
|
*/ |
201
|
|
|
public function getBackButton($json_serialized = true) { |
202
|
|
|
|
203
|
|
|
// Create the button |
204
|
|
|
$inline_keyboard = [ 'inline_keyboard' => |
205
|
|
|
[ |
206
|
|
|
[ |
207
|
|
|
[ |
208
|
|
|
'text' => $this->bot->localization[$this->bot->language]['Back_Button'], |
|
|
|
|
209
|
|
|
'callback_data' => 'back' |
210
|
|
|
] |
211
|
|
|
] |
212
|
|
|
] |
213
|
|
|
]; |
214
|
|
|
|
215
|
|
|
// Does we need it as json-serialized? |
216
|
|
|
if ($json_serialized) { |
217
|
|
|
|
218
|
|
|
return json_encode($inline_keyboard); |
219
|
|
|
|
220
|
|
|
} else { |
221
|
|
|
|
222
|
|
|
return $inline_keyboard; |
|
|
|
|
223
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* \brief Get a Back and a Skip buttons inthe same row. |
230
|
|
|
* \details Back button has callback_data "back" and Skip button has callback_data "skip". |
231
|
|
|
* @param $json_serialized return a json serialized string, or an array. |
232
|
|
|
* @return A button with written "back" and one with written "Skip". |
233
|
|
|
*/ |
234
|
|
|
public function getBackSkipKeyboard($json_serialized = true) { |
235
|
|
|
|
236
|
|
|
// Create the keyboard |
237
|
|
|
$inline_keyboard = [ 'inline_keyboard' => |
238
|
|
|
[ |
239
|
|
|
[ |
240
|
|
|
[ |
241
|
|
|
'text' => $this->bot->localization[$this->bot->language]['Back_Button'], |
|
|
|
|
242
|
|
|
'callback_data' => 'back' |
243
|
|
|
], |
244
|
|
|
[ |
245
|
|
|
'text' => $this->bot->localization[$this->bot->language]['Skip_Button'], |
246
|
|
|
'callback_data' => 'skip' |
247
|
|
|
] |
248
|
|
|
] |
249
|
|
|
] |
250
|
|
|
]; |
251
|
|
|
|
252
|
|
|
// Does we need it as json-serialized? |
253
|
|
|
if ($json_serialized) { |
254
|
|
|
|
255
|
|
|
return json_encode($inline_keyboard); |
256
|
|
|
|
257
|
|
|
} else { |
258
|
|
|
|
259
|
|
|
return $inline_keyboard; |
|
|
|
|
260
|
|
|
|
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* \brief Get button for each language. |
267
|
|
|
* \details Create a button for each language contained in $localization['languages'] variable of $bot object. |
268
|
|
|
* The button will be one per row. |
269
|
|
|
* The text will be the language and the language localizatated for the current user with a slash between them. |
270
|
|
|
* The callback data for each button will be "cl/key" where key is the key in $localization['languages']. |
271
|
|
|
* @param $json_serialized Get a JSON-serialized string or an array. |
272
|
|
|
* @return The buttons in the selected type. |
273
|
|
|
*/ |
274
|
|
|
public function getChooseLanguageKeyboard($json_serialized = true) { |
275
|
|
|
|
276
|
|
|
// Create the empty array |
277
|
|
|
$inline_keyboard = ['inline_keyboard' => array()]; |
278
|
|
|
|
279
|
|
|
foreach ($this->bot->local['languages'] as $languages => $language_msg) { |
280
|
|
|
|
281
|
|
|
// If the language is the same as the one set for the current user in $bot |
282
|
|
|
if (strpos($languages, $this->bot->language) !== false) { |
283
|
|
|
|
284
|
|
|
// Just create a button with one language in it |
285
|
|
|
array_push($inline_keyboard['inline_keyboard'], [ |
286
|
|
|
[ |
287
|
|
|
'text' => $language_msg, |
288
|
|
|
'callback_data' => 'same/language' |
289
|
|
|
] |
290
|
|
|
]); |
291
|
|
|
|
292
|
|
|
} else { |
293
|
|
|
|
294
|
|
|
// Create a button with the language on the left and the language localizated for the current user in the right |
295
|
|
|
array_push($inline_keyboard['inline_keyboard'], [ |
296
|
|
|
[ |
297
|
|
|
'text' => $language_msg . '/' . $this->bot->local[$this->bot->language][$languages], |
|
|
|
|
298
|
|
|
'callback_data' => 'cl/' . $languages |
299
|
|
|
] |
300
|
|
|
]); |
301
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
// Unset the variables from the foreach |
307
|
|
|
unset($languages); |
308
|
|
|
unset($language_msg); |
309
|
|
|
|
310
|
|
|
array_push($inline_keyboard['inline_keyboard'], [ |
311
|
|
|
[ |
312
|
|
|
'text' => $this->bot->local[$this->bot->language]['Back_Button'], |
313
|
|
|
'callback_data' => 'back' |
314
|
|
|
] |
315
|
|
|
]); |
316
|
|
|
|
317
|
|
|
if ($json_serialized) { |
318
|
|
|
|
319
|
|
|
return json_encode($inline_keyboard); |
320
|
|
|
|
321
|
|
|
} else { |
322
|
|
|
|
323
|
|
|
return $inline_keyboard; |
|
|
|
|
324
|
|
|
|
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* \brief */ |
331
|
|
|
public function initilizeCompositeListKeyboard($index, $list, $prefix) { |
332
|
|
|
|
333
|
|
|
if (($list > 0) && ($index >= 0)) { |
334
|
|
|
if ($index == 0) { |
335
|
|
|
if ($list > 1) { |
336
|
|
|
if ($list > 2) { |
337
|
|
|
if ($list > 3) { |
338
|
|
|
if ($list > 4) { |
339
|
|
|
if ($list > 5) { |
340
|
|
|
$buttons = [ |
341
|
|
|
[ |
342
|
|
|
'text' => '1', |
343
|
|
|
'callback_data' => $prefix . '/1' |
344
|
|
|
], |
345
|
|
|
[ |
346
|
|
|
'text' => '2', |
347
|
|
|
'callback_data' => $prefix . '/2' |
348
|
|
|
], |
349
|
|
|
[ |
350
|
|
|
'text' => '3', |
351
|
|
|
'callback_data' => $prefix . '/3' |
352
|
|
|
], |
353
|
|
|
[ |
354
|
|
|
'text' => '4 ›', |
355
|
|
|
'callback_data' => $prefix . '/4' |
356
|
|
|
], |
357
|
|
|
[ |
358
|
|
|
'text' => "$list ››", |
359
|
|
|
'callback_data' => $prefix . "/$list" |
360
|
|
|
] |
361
|
|
|
]; |
362
|
|
|
} else { |
363
|
|
|
$buttons = [ |
364
|
|
|
[ |
365
|
|
|
'text' => '1', |
366
|
|
|
'callback_data' => $prefix . '/1' |
367
|
|
|
], |
368
|
|
|
[ |
369
|
|
|
'text' => '2', |
370
|
|
|
'callback_data' => $prefix . '/2' |
371
|
|
|
], |
372
|
|
|
[ |
373
|
|
|
'text' => '3', |
374
|
|
|
'callback_data' => $prefix . '/3' |
375
|
|
|
], |
376
|
|
|
[ |
377
|
|
|
'text' => '4', |
378
|
|
|
'callback_data' => $prefix . '/4' |
379
|
|
|
], |
380
|
|
|
[ |
381
|
|
|
'text' => '5', |
382
|
|
|
'callback_data' => $prefix . '/5' |
383
|
|
|
] |
384
|
|
|
]; |
385
|
|
|
} |
386
|
|
|
} else { |
387
|
|
|
$buttons = [ |
388
|
|
|
[ |
389
|
|
|
'text' => '1', |
390
|
|
|
'callback_data' => $prefix . '/1' |
391
|
|
|
], |
392
|
|
|
[ |
393
|
|
|
'text' => '2', |
394
|
|
|
'callback_data' => $prefix . '/2' |
395
|
|
|
], |
396
|
|
|
[ |
397
|
|
|
'text' => '3', |
398
|
|
|
'callback_data' => $prefix . '/3' |
399
|
|
|
], |
400
|
|
|
[ |
401
|
|
|
'text' => '4', |
402
|
|
|
'callback_data' => $prefix . '/4' |
403
|
|
|
], |
404
|
|
|
]; |
405
|
|
|
} |
406
|
|
|
} else { |
407
|
|
|
$buttons = [ |
408
|
|
|
[ |
409
|
|
|
'text' => '1', |
410
|
|
|
'callback_data' => $prefix . '/1' |
411
|
|
|
], |
412
|
|
|
[ |
413
|
|
|
'text' => '2', |
414
|
|
|
'callback_data' => $prefix . '/2' |
415
|
|
|
], |
416
|
|
|
[ |
417
|
|
|
'text' => '3', |
418
|
|
|
'callback_data' => $prefix . '/3' |
419
|
|
|
], |
420
|
|
|
]; |
421
|
|
|
} |
422
|
|
|
} elseif ($list == 2) { |
423
|
|
|
$buttons = [ |
424
|
|
|
[ |
425
|
|
|
'text' => '1', |
426
|
|
|
'callback_data' => $prefix . '/1' |
427
|
|
|
], |
428
|
|
|
[ |
429
|
|
|
'text' => '2', |
430
|
|
|
'callback_data' => $prefix . '/2' |
431
|
|
|
], |
432
|
|
|
]; |
433
|
|
|
} |
434
|
|
|
} else { |
435
|
|
|
$buttons = [ |
436
|
|
|
[ |
437
|
|
|
'text' => '1', |
438
|
|
|
'callback_data' => $prefix . '/1' |
439
|
|
|
] |
440
|
|
|
]; |
441
|
|
|
} |
442
|
|
|
} else if ($index == 1) { |
443
|
|
|
if ($list > 1) { |
444
|
|
View Code Duplication |
if ($list > 2) { |
|
|
|
|
445
|
|
|
if ($list > 3) { |
446
|
|
|
if ($list > 4) { |
447
|
|
|
if ($list > 5) { |
448
|
|
|
$buttons = [ |
449
|
|
|
[ |
450
|
|
|
'text' => '• 1 •', |
451
|
|
|
'callback_data' => 'null' |
452
|
|
|
], |
453
|
|
|
[ |
454
|
|
|
'text' => '2', |
455
|
|
|
'callback_data' => $prefix . '/2' |
456
|
|
|
], |
457
|
|
|
[ |
458
|
|
|
'text' => '3', |
459
|
|
|
'callback_data' => $prefix . '/3' |
460
|
|
|
], |
461
|
|
|
[ |
462
|
|
|
'text' => '4 ›', |
463
|
|
|
'callback_data' => $prefix . '/4' |
464
|
|
|
], |
465
|
|
|
[ |
466
|
|
|
'text' => "$list ››", |
467
|
|
|
'callback_data' => $prefix . "/$list" |
468
|
|
|
] |
469
|
|
|
]; |
470
|
|
|
} else { |
471
|
|
|
$buttons = [ |
472
|
|
|
[ |
473
|
|
|
'text' => '• 1 •', |
474
|
|
|
'callback_data' => 'null' |
475
|
|
|
], |
476
|
|
|
[ |
477
|
|
|
'text' => '2', |
478
|
|
|
'callback_data' => $prefix . '/2' |
479
|
|
|
], |
480
|
|
|
[ |
481
|
|
|
'text' => '3', |
482
|
|
|
'callback_data' => $prefix . '/3' |
483
|
|
|
], |
484
|
|
|
[ |
485
|
|
|
'text' => '4', |
486
|
|
|
'callback_data' => $prefix . '/4' |
487
|
|
|
], |
488
|
|
|
[ |
489
|
|
|
'text' => '5', |
490
|
|
|
'callback_data' => $prefix . '/5' |
491
|
|
|
] |
492
|
|
|
]; |
493
|
|
|
} |
494
|
|
|
} else { |
495
|
|
|
$buttons = [ |
496
|
|
|
[ |
497
|
|
|
'text' => '• 1 •', |
498
|
|
|
'callback_data' => 'null' |
499
|
|
|
], |
500
|
|
|
[ |
501
|
|
|
'text' => '2', |
502
|
|
|
'callback_data' => $prefix . '/2' |
503
|
|
|
], |
504
|
|
|
[ |
505
|
|
|
'text' => '3', |
506
|
|
|
'callback_data' => $prefix . '/3' |
507
|
|
|
], |
508
|
|
|
[ |
509
|
|
|
'text' => '4', |
510
|
|
|
'callback_data' => $prefix . '/4' |
511
|
|
|
] |
512
|
|
|
]; |
513
|
|
|
} |
514
|
|
|
} else { |
515
|
|
|
$buttons = [ |
516
|
|
|
[ |
517
|
|
|
'text' => '• 1 •', |
518
|
|
|
'callback_data' => 'null' |
519
|
|
|
], |
520
|
|
|
[ |
521
|
|
|
'text' => '2', |
522
|
|
|
'callback_data' => $prefix . '/2' |
523
|
|
|
], |
524
|
|
|
[ |
525
|
|
|
'text' => '3', |
526
|
|
|
'callback_data' => $prefix . '/3' |
527
|
|
|
] |
528
|
|
|
]; |
529
|
|
|
} |
530
|
|
|
} elseif ($list == 2) { |
531
|
|
|
$buttons = [ |
532
|
|
|
[ |
533
|
|
|
'text' => '• 1 •', |
534
|
|
|
'callback_data' => 'null' |
535
|
|
|
], |
536
|
|
|
[ |
537
|
|
|
'text' => '2', |
538
|
|
|
'callback_data' => $prefix . '/2' |
539
|
|
|
] |
540
|
|
|
]; |
541
|
|
|
} |
542
|
|
|
} else { |
543
|
|
|
$buttons = [ |
544
|
|
|
[ |
545
|
|
|
'text' => '• 1 •', |
546
|
|
|
'callback_data' => 'null' |
547
|
|
|
] |
548
|
|
|
]; |
549
|
|
|
} |
550
|
|
View Code Duplication |
} elseif ($index == 2) { |
|
|
|
|
551
|
|
|
if ($list > 3) { |
552
|
|
|
if ($list > 4) { |
553
|
|
|
if ($list > 5) { |
554
|
|
|
$buttons = [ |
555
|
|
|
[ |
556
|
|
|
'text' => '1', |
557
|
|
|
'callback_data' => $prefix . '/1' |
558
|
|
|
], |
559
|
|
|
[ |
560
|
|
|
'text' => '• 2 •', |
561
|
|
|
'callback_data' => 'null' |
562
|
|
|
], |
563
|
|
|
[ |
564
|
|
|
'text' => '3', |
565
|
|
|
'callback_data' => $prefix . '/3' |
566
|
|
|
], |
567
|
|
|
[ |
568
|
|
|
'text' => '4 ›', |
569
|
|
|
'callback_data' => $prefix . '/4' |
570
|
|
|
], |
571
|
|
|
[ |
572
|
|
|
'text' => "$list ››", |
573
|
|
|
'callback_data' => $prefix . "/$list" |
574
|
|
|
] |
575
|
|
|
]; |
576
|
|
|
} else { |
577
|
|
|
$buttons = [ |
578
|
|
|
[ |
579
|
|
|
'text' => '1', |
580
|
|
|
'callback_data' => $prefix . '/1' |
581
|
|
|
], |
582
|
|
|
[ |
583
|
|
|
'text' => '• 2 •', |
584
|
|
|
'callback_data' => 'null' |
585
|
|
|
], |
586
|
|
|
[ |
587
|
|
|
'text' => '3', |
588
|
|
|
'callback_data' => $prefix . '/3' |
589
|
|
|
], |
590
|
|
|
[ |
591
|
|
|
'text' => '4', |
592
|
|
|
'callback_data' => '4' |
593
|
|
|
], |
594
|
|
|
[ |
595
|
|
|
'text' => '5', |
596
|
|
|
'callback_data' => $prefix . '/5' |
597
|
|
|
] |
598
|
|
|
]; |
599
|
|
|
} |
600
|
|
|
} else { |
601
|
|
|
$buttons = [ |
602
|
|
|
[ |
603
|
|
|
'text' => '1', |
604
|
|
|
'callback_data' => $prefix . '/1' |
605
|
|
|
], |
606
|
|
|
[ |
607
|
|
|
'text' => '• 2 •', |
608
|
|
|
'callback_data' => 'null' |
609
|
|
|
], |
610
|
|
|
[ |
611
|
|
|
'text' => '3', |
612
|
|
|
'callback_data' => $prefix . '/3' |
613
|
|
|
], |
614
|
|
|
[ |
615
|
|
|
'text' => '4', |
616
|
|
|
'callback_data' => $prefix . '/4' |
617
|
|
|
] |
618
|
|
|
]; |
619
|
|
|
} |
620
|
|
|
} elseif ($list == 3) { |
621
|
|
|
$buttons = [ |
622
|
|
|
[ |
623
|
|
|
'text' => '1', |
624
|
|
|
'callback_data' => $prefix . '/1' |
625
|
|
|
], |
626
|
|
|
[ |
627
|
|
|
'text' => '• 2 •', |
628
|
|
|
'callback_data' => 'null' |
629
|
|
|
], |
630
|
|
|
[ |
631
|
|
|
'text' => '3', |
632
|
|
|
'callback_data' => $prefix . '/3' |
633
|
|
|
] |
634
|
|
|
]; |
635
|
|
|
} else { |
636
|
|
|
$buttons = [ |
637
|
|
|
[ |
638
|
|
|
'text' => '1', |
639
|
|
|
'callback_data' => $prefix . '/1' |
640
|
|
|
], |
641
|
|
|
[ |
642
|
|
|
'text' => '• 2 •', |
643
|
|
|
'callback_data' => 'null' |
644
|
|
|
] |
645
|
|
|
]; |
646
|
|
|
} |
647
|
|
|
} elseif ($index == 3) { |
648
|
|
|
if ($list > 4) { |
649
|
|
|
if ($list > 5) { |
650
|
|
|
$buttons = [ |
651
|
|
|
[ |
652
|
|
|
'text' => '1', |
653
|
|
|
'callback_data' => $prefix . '/1' |
654
|
|
|
], |
655
|
|
|
[ |
656
|
|
|
'text' => '2', |
657
|
|
|
'callback_data' => $prefix . '/2' |
658
|
|
|
], |
659
|
|
|
[ |
660
|
|
|
'text' => '• 3 •', |
661
|
|
|
'callback_data' => 'null' |
662
|
|
|
], |
663
|
|
|
[ |
664
|
|
|
'text' => '4 ›', |
665
|
|
|
'callback_data' => $prefix . '/4' |
666
|
|
|
], |
667
|
|
|
[ |
668
|
|
|
'text' => "$list ››", |
669
|
|
|
'callback_data' => $prefix . "/$list" |
670
|
|
|
] |
671
|
|
|
]; |
672
|
|
|
} else { |
673
|
|
|
$buttons = [ |
674
|
|
|
[ |
675
|
|
|
'text' => '1', |
676
|
|
|
'callback_data' => $prefix . '/1' |
677
|
|
|
], |
678
|
|
|
[ |
679
|
|
|
'text' => '2', |
680
|
|
|
'callback_data' => $prefix . '/2' |
681
|
|
|
], |
682
|
|
|
[ |
683
|
|
|
'text' => '• 3 •', |
684
|
|
|
'callback_data' => 'null' |
685
|
|
|
], |
686
|
|
|
[ |
687
|
|
|
'text' => '4', |
688
|
|
|
'callback_data' => $prefix . '/4' |
689
|
|
|
], |
690
|
|
|
[ |
691
|
|
|
'text' => '5', |
692
|
|
|
'callback_data' => $prefix . '/5' |
693
|
|
|
] |
694
|
|
|
]; |
695
|
|
|
} |
696
|
|
|
} elseif ($list == 4) { |
697
|
|
|
$buttons = [ |
698
|
|
|
[ |
699
|
|
|
'text' => '1', |
700
|
|
|
'callback_data' => $prefix . '/1' |
701
|
|
|
], |
702
|
|
|
[ |
703
|
|
|
'text' => '2', |
704
|
|
|
'callback_data' => $prefix . '/2' |
705
|
|
|
], |
706
|
|
|
[ |
707
|
|
|
'text' => '• 3 •', |
708
|
|
|
'callback_data' => 'null' |
709
|
|
|
], |
710
|
|
|
[ |
711
|
|
|
'text' => '4', |
712
|
|
|
'callback_data' => $prefix . '/4' |
713
|
|
|
] |
714
|
|
|
]; |
715
|
|
|
} else { |
716
|
|
|
$buttons = [ |
717
|
|
|
[ |
718
|
|
|
'text' => '1', |
719
|
|
|
'callback_data' => $prefix . '/1' |
720
|
|
|
], |
721
|
|
|
[ |
722
|
|
|
'text' => '2', |
723
|
|
|
'callback_data' => $prefix . '/2' |
724
|
|
|
], |
725
|
|
|
[ |
726
|
|
|
'text' => '• 3 •', |
727
|
|
|
'callback_data' => 'null' |
728
|
|
|
] |
729
|
|
|
]; |
730
|
|
|
} |
731
|
|
|
} elseif ($index == 4 && $list <= 5) { |
732
|
|
|
if ($list == 4) { |
733
|
|
|
$buttons = [ |
734
|
|
|
[ |
735
|
|
|
'text' => '1', |
736
|
|
|
'callback_data' => $prefix . '/1' |
737
|
|
|
], |
738
|
|
|
[ |
739
|
|
|
'text' => '2', |
740
|
|
|
'callback_data' => $prefix . '/2' |
741
|
|
|
], |
742
|
|
|
[ |
743
|
|
|
'text' => '3', |
744
|
|
|
'callback_data' => $prefix . '/3' |
745
|
|
|
], |
746
|
|
|
[ |
747
|
|
|
'text' => '• 4 •', |
748
|
|
|
'callback_data' => 'null' |
749
|
|
|
] |
750
|
|
|
]; |
751
|
|
|
} else if ($list == 5) { |
752
|
|
|
$buttons = [ |
753
|
|
|
[ |
754
|
|
|
'text' => '1', |
755
|
|
|
'callback_data' => $prefix . '/1' |
756
|
|
|
], |
757
|
|
|
[ |
758
|
|
|
'text' => '2', |
759
|
|
|
'callback_data' => $prefix . '/2' |
760
|
|
|
], |
761
|
|
|
[ |
762
|
|
|
'text' => '3', |
763
|
|
|
'callback_data' => $prefix . '/3' |
764
|
|
|
], |
765
|
|
|
[ |
766
|
|
|
'text' => '• 4 •', |
767
|
|
|
'callback_data' => 'null' |
768
|
|
|
], |
769
|
|
|
[ |
770
|
|
|
'text' => '5', |
771
|
|
|
'callback_data' => $prefix . '/5' |
772
|
|
|
] |
773
|
|
|
]; |
774
|
|
|
} |
775
|
|
|
} else if ($index == 5 && $list == 5) { |
776
|
|
|
$buttons = [ |
777
|
|
|
[ |
778
|
|
|
'text' => '1', |
779
|
|
|
'callback_data' => $prefix . '/1' |
780
|
|
|
], |
781
|
|
|
[ |
782
|
|
|
'text' => '2', |
783
|
|
|
'callback_data' => $prefix . '/2' |
784
|
|
|
], |
785
|
|
|
[ |
786
|
|
|
'text' => '3', |
787
|
|
|
'callback_data' => $prefix . '/3' |
788
|
|
|
], |
789
|
|
|
[ |
790
|
|
|
'text' => '4', |
791
|
|
|
'callback_data' => $prefix . '/4' |
792
|
|
|
], |
793
|
|
|
[ |
794
|
|
|
'text' => '• 5 •', |
795
|
|
|
'callback_data' => 'null' |
796
|
|
|
] |
797
|
|
|
]; |
798
|
|
|
} else { |
799
|
|
|
if ($index < $list - 2) { |
800
|
|
|
$indexm = $index - 1; |
801
|
|
|
$indexp = $index + 1; |
802
|
|
|
$buttons = [ |
803
|
|
|
[ |
804
|
|
|
'text' => '‹‹ 1', |
805
|
|
|
'callback_data' => $prefix . '/1' |
806
|
|
|
], |
807
|
|
|
[ |
808
|
|
|
'text' => '‹ ' . $indexm, |
809
|
|
|
'callback_data' => $prefix . '/' . $indexm |
810
|
|
|
], |
811
|
|
|
[ |
812
|
|
|
'text' => '• ' . $index . ' •', |
813
|
|
|
'callback_data' => 'null', |
814
|
|
|
], |
815
|
|
|
[ |
816
|
|
|
'text' => $indexp . ' ›', |
817
|
|
|
'callback_data' => $prefix . '/' . $indexp |
818
|
|
|
], |
819
|
|
|
[ |
820
|
|
|
'text' => $list . ' ››', |
821
|
|
|
'callback_data' => $prefix . '/' . $list |
822
|
|
|
] |
823
|
|
|
]; |
824
|
|
|
} elseif ($index == ($list - 2)) { |
825
|
|
|
$indexm = $index - 1; |
826
|
|
|
$indexp = $index + 1; |
827
|
|
|
$buttons = [ |
828
|
|
|
[ |
829
|
|
|
'text' => '‹‹1', |
830
|
|
|
'callback_data' => $prefix . '/1' |
831
|
|
|
], |
832
|
|
|
[ |
833
|
|
|
'text' => '' . $indexm, |
834
|
|
|
'callback_data' => $prefix . '/' . $indexm |
835
|
|
|
], |
836
|
|
|
[ |
837
|
|
|
'text' => '• ' . $index . ' •', |
838
|
|
|
'callback_data' => 'null', |
839
|
|
|
], |
840
|
|
|
[ |
841
|
|
|
'text' => '' . $indexp, |
842
|
|
|
'callback_data' => $prefix . '/' . $indexp |
843
|
|
|
], |
844
|
|
|
[ |
845
|
|
|
'text' => "$list", |
846
|
|
|
'callback_data' => $prefix . "/$list" |
847
|
|
|
] |
848
|
|
|
]; |
849
|
|
|
} elseif ($index == ($list - 1)) { |
850
|
|
|
$indexm = $index - 1; |
851
|
|
|
$indexmm = $index - 2; |
852
|
|
|
$buttons = [ |
853
|
|
|
[ |
854
|
|
|
'text' => '‹‹ 1', |
855
|
|
|
'callback_data' => $prefix . '/1' |
856
|
|
|
], |
857
|
|
|
[ |
858
|
|
|
'text' => '‹ ' . $indexmm, |
859
|
|
|
'callback_data' => $prefix . '/' . $indexmm |
860
|
|
|
], |
861
|
|
|
[ |
862
|
|
|
'text' => '' . $indexm, |
863
|
|
|
'callback_data' => $prefix . '/' . $indexm |
864
|
|
|
], |
865
|
|
|
[ |
866
|
|
|
'text' => '• ' . $index . ' •', |
867
|
|
|
'callback_data' => $prefix . '/' . $index |
868
|
|
|
], |
869
|
|
|
[ |
870
|
|
|
'text' => "$list", |
871
|
|
|
'callback_data' => $prefix . "/$list" |
872
|
|
|
] |
873
|
|
|
]; |
874
|
|
|
} else if ($index == $list) { |
875
|
|
|
$indexm = $index - 1; |
876
|
|
|
$indexmm = $index - 2; |
877
|
|
|
$indexmmm = $index - 3; |
878
|
|
|
$buttons = [ |
879
|
|
|
[ |
880
|
|
|
'text' => '‹‹ 1', |
881
|
|
|
'callback_data' => $prefix . '/1' |
882
|
|
|
], |
883
|
|
|
[ |
884
|
|
|
'text' => '‹ ' . $indexmmm, |
885
|
|
|
'callback_data' => $prefix . '/' . $indexmmm |
886
|
|
|
], |
887
|
|
|
[ |
888
|
|
|
'text' => '' . $indexmm, |
889
|
|
|
'callback_data' => $prefix . '/' . $indexmm, |
890
|
|
|
], |
891
|
|
|
[ |
892
|
|
|
'text' => '' . $indexm, |
893
|
|
|
'callback_data' => $prefix . '/' . $indexm |
894
|
|
|
], |
895
|
|
|
[ |
896
|
|
|
'text' => '• ' . $index . ' •', |
897
|
|
|
'callback_data' => $prefix . '/' . $index |
898
|
|
|
] |
899
|
|
|
]; |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
$this->inline_keyboard[] = $buttons; |
|
|
|
|
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
/** @} */ |
910
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.