|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the TelegramBot package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Longman\TelegramBot\Entities; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class User |
|
15
|
|
|
* |
|
16
|
|
|
* @link https://core.telegram.org/bots/api#user |
|
17
|
|
|
* |
|
18
|
|
|
* @property int $id Unique identifier for this user or bot |
|
19
|
|
|
* @property string $first_name User's or bot’s first name |
|
20
|
|
|
* @property string $last_name Optional. User's or bot’s last name |
|
21
|
|
|
* @property string $username Optional. User's or bot’s username |
|
22
|
|
|
* |
|
23
|
|
|
* @method int getId() Unique identifier for this user or bot |
|
24
|
|
|
* @method string getFirstName() User's or bot’s first name |
|
25
|
|
|
* @method string getLastName() Optional. User's or bot’s last name |
|
26
|
|
|
* @method string getUsername() Optional. User's or bot’s username |
|
27
|
|
|
*/ |
|
28
|
|
|
class User extends Entity |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* tryMention |
|
32
|
|
|
* |
|
33
|
|
|
* Mention the user with the username otherwise print first and last name |
|
34
|
|
|
* if the $markdown arguments is true special characters are escaped from the output |
|
35
|
|
|
* |
|
36
|
|
|
* @param bool $markdown |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function tryMention($markdown = false) |
|
41
|
|
|
{ |
|
42
|
2 |
|
$username = $this->getProperty('username'); |
|
43
|
2 |
|
if ($username !== null) { |
|
44
|
2 |
|
if ($markdown) { |
|
45
|
|
|
//Escaping md special characters |
|
46
|
|
|
//Please notice that just the _ is allowed in the username ` * [ are not allowed |
|
47
|
1 |
|
return '@' . $this->stripMarkDown($this->username); |
|
48
|
|
|
} |
|
49
|
2 |
|
return '@' . $this->username; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
$name = $this->getProperty('first_name'); |
|
53
|
2 |
|
$last_name = $this->getProperty('last_name'); |
|
54
|
2 |
|
if ($last_name !== null) { |
|
55
|
2 |
|
$name .= ' ' . $last_name; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
if ($markdown) { |
|
59
|
|
|
//Escaping md special characters |
|
60
|
1 |
|
return $this->stripMarkDown($name); |
|
61
|
|
|
} |
|
62
|
2 |
|
return $name; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|