|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Telegraph package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Arthur Edamov <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types = 1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Telegraph; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Page |
|
19
|
|
|
* |
|
20
|
|
|
* This object represents a page on Telegraph. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Telegraph |
|
23
|
|
|
*/ |
|
24
|
|
|
class Page |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Path to the page. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $path; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* URL of the page. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $url; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Title of the page. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
private $title; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Description of the page. |
|
49
|
|
|
* |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
private $description; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Name of the author, displayed below the title. |
|
56
|
|
|
* |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
private $authorName; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Profile link, opened when users click on the author's name below the title. |
|
63
|
|
|
* Can be any link, not necessarily to a Telegram profile or channel. |
|
64
|
|
|
* |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
private $authorUrl; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Image URL of the page. |
|
71
|
|
|
* |
|
72
|
|
|
* @var string |
|
73
|
|
|
*/ |
|
74
|
|
|
private $imageUrl; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Content of the page. |
|
78
|
|
|
* |
|
79
|
|
|
* @var string|NodeElement[] |
|
80
|
|
|
*/ |
|
81
|
|
|
private $content; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Number of page views for the page. |
|
85
|
|
|
* |
|
86
|
|
|
* @var int |
|
87
|
|
|
*/ |
|
88
|
|
|
private $views; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Only returned if access_token passed. |
|
92
|
|
|
* True, if the target Telegraph account can edit the page. |
|
93
|
|
|
* |
|
94
|
|
|
* @var bool |
|
95
|
|
|
*/ |
|
96
|
|
|
private $canEdit; |
|
97
|
|
|
|
|
98
|
|
|
public function __construct(array $data) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->path = $data['path']; |
|
101
|
|
|
$this->url = $data['url']; |
|
102
|
|
|
$this->title = $data['title'] ?? ''; |
|
103
|
|
|
$this->description = $data['description'] ?? ''; |
|
104
|
|
|
$this->authorName = $data['author_name'] ?? ''; |
|
105
|
|
|
$this->authorUrl = $data['author_url'] ?? ''; |
|
106
|
|
|
$this->imageUrl = $data['image_url'] ?? ''; |
|
107
|
|
|
$this->content = $data['content'] ?? null; |
|
108
|
|
|
$this->views = $data['views'] ?? 0; |
|
109
|
|
|
$this->canEdit = $data['can_edit'] ?? false; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getPath(): string |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->path; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getUrl(): string |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->url; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return string |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getTitle(): string |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->title; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getDescription(): string |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->description; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getAuthorName(): string |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->authorName; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return string |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getAuthorUrl(): string |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->authorUrl; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getImageUrl(): string |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->imageUrl; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return string|NodeElement[] |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getContent() |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->content; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return int |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getViews(): int |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->views; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return bool |
|
186
|
|
|
*/ |
|
187
|
|
|
public function isCanEdit(): bool |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->canEdit; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|