1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* T3Bot. |
4
|
|
|
* |
5
|
|
|
* @author Frank Nägler <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @link http://www.t3bot.de |
8
|
|
|
* @link http://wiki.typo3.org/T3Bot |
9
|
|
|
*/ |
10
|
|
|
namespace T3Bot\Slack\Message; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Attachment. |
14
|
|
|
*/ |
15
|
|
|
class Attachment |
16
|
|
|
{ |
17
|
|
|
const COLOR_NOTICE = '#cccccc'; |
18
|
|
|
const COLOR_INFO = '#5bc0de'; |
19
|
|
|
const COLOR_GOOD = '#5cb85c'; |
20
|
|
|
const COLOR_WARNING = '#f0ad4e'; |
21
|
|
|
const COLOR_DANGER = '#d9534f'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Required plain-text summary of the attachment. |
25
|
|
|
* A plain-text summary of the attachment. This text will be used in clients that |
26
|
|
|
* don't show formatted text (eg. IRC, mobile notifications) and should not contain |
27
|
|
|
* any markup. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $fallback = ''; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Color for the attachment |
35
|
|
|
* An optional value that can either be one of good, warning, danger, or |
36
|
|
|
* any hex color code (eg. #439FE0). This value is used to color the border |
37
|
|
|
* along the left side of the message attachment. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $color = self::COLOR_INFO; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* This is optional text that appears above the message attachment block. |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $pretext = ''; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Small text used to display the author's name. |
52
|
|
|
* |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $authorName = ''; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* A valid URL that will hyperlink the author_name text mentioned above. |
59
|
|
|
* Will only work if author_name is present. |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
protected $authorLink = ''; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* A valid URL that displays a small 16x16px image to the left of the author_name text. |
67
|
|
|
* Will only work if author_name is present. |
68
|
|
|
* |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected $authorIcon = ''; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The title is displayed as larger, bold text near the top of a message attachment. |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
protected $title = ''; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* By passing a valid URL in the title_link parameter (optional), the title text |
82
|
|
|
* will be hyperlinked. |
83
|
|
|
* |
84
|
|
|
* @var string |
85
|
|
|
*/ |
86
|
|
|
protected $titleLink = ''; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* This is the main text in a message attachment, and can contain standard message |
90
|
|
|
* markup. The content will automatically collapse if it contains 700+ characters |
91
|
|
|
* or 5+ linebreaks, and will display a "Show more..." link to expand the content. |
92
|
|
|
* |
93
|
|
|
* @var string |
94
|
|
|
*/ |
95
|
|
|
protected $text = ''; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Fields are defined as an array, and hashes contained within it will be displayed |
99
|
|
|
* in a table inside the message attachment. |
100
|
|
|
* |
101
|
|
|
* @var array<\T3Bot\Slack\Message\Attachment\Field> |
102
|
|
|
*/ |
103
|
|
|
protected $fields = []; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* A valid URL to an image file that will be displayed inside a message attachment. |
107
|
|
|
* We currently support the following formats: GIF, JPEG, PNG, and BMP. |
108
|
|
|
* Large images will be resized to a maximum width of 400px or a maximum height of |
109
|
|
|
* 500px, while still maintaining the original aspect ratio. |
110
|
|
|
* |
111
|
|
|
* @var string |
112
|
|
|
*/ |
113
|
|
|
protected $imageUrl = ''; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* A valid URL to an image file that will be displayed as a thumbnail on the right |
117
|
|
|
* side of a message attachment. We currently support the following formats: GIF, |
118
|
|
|
* JPEG, PNG, and BMP. |
119
|
|
|
* The thumbnail's longest dimension will be scaled down to 75px while maintaining |
120
|
|
|
* the aspect ratio of the image. The filesize of the image must also be less than |
121
|
|
|
* 500 KB. |
122
|
|
|
* |
123
|
|
|
* @var string |
124
|
|
|
*/ |
125
|
|
|
protected $thumbUrl = ''; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Constructor for an attachment. |
129
|
|
|
* |
130
|
|
|
* @param array $data |
131
|
|
|
*/ |
132
|
27 |
|
public function __construct(array $data = []) |
133
|
|
|
{ |
134
|
27 |
|
foreach ($data as $property => $value) { |
135
|
1 |
|
if (property_exists($this, $property)) { |
136
|
1 |
|
$this->$property = $value; |
137
|
|
|
} |
138
|
|
|
} |
139
|
27 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
4 |
|
public function getFallback() : string |
145
|
|
|
{ |
146
|
4 |
|
return $this->fallback; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $fallback |
151
|
|
|
*/ |
152
|
27 |
|
public function setFallback($fallback) |
153
|
|
|
{ |
154
|
27 |
|
$this->fallback = $fallback; |
155
|
27 |
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
4 |
|
public function getColor() : string |
161
|
|
|
{ |
162
|
4 |
|
return $this->color; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $color |
167
|
|
|
*/ |
168
|
26 |
|
public function setColor($color) |
169
|
|
|
{ |
170
|
26 |
|
$this->color = $color; |
171
|
26 |
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
9 |
|
public function getPretext() : string |
177
|
|
|
{ |
178
|
9 |
|
return $this->pretext; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param string $pretext |
183
|
|
|
*/ |
184
|
12 |
|
public function setPretext($pretext) |
185
|
|
|
{ |
186
|
12 |
|
$this->pretext = $pretext; |
187
|
12 |
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
4 |
|
public function getAuthorName() : string |
193
|
|
|
{ |
194
|
4 |
|
return $this->authorName; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $authorName |
199
|
|
|
*/ |
200
|
1 |
|
public function setAuthorName($authorName) |
201
|
|
|
{ |
202
|
1 |
|
$this->authorName = $authorName; |
203
|
1 |
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return string |
207
|
|
|
*/ |
208
|
4 |
|
public function getAuthorLink() : string |
209
|
|
|
{ |
210
|
4 |
|
return $this->authorLink; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param string $authorLink |
215
|
|
|
*/ |
216
|
1 |
|
public function setAuthorLink($authorLink) |
217
|
|
|
{ |
218
|
1 |
|
$this->authorLink = $authorLink; |
219
|
1 |
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return string |
223
|
|
|
*/ |
224
|
4 |
|
public function getAuthorIcon() : string |
225
|
|
|
{ |
226
|
4 |
|
return $this->authorIcon; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @param string $authorIcon |
231
|
|
|
*/ |
232
|
1 |
|
public function setAuthorIcon($authorIcon) |
233
|
|
|
{ |
234
|
1 |
|
$this->authorIcon = $authorIcon; |
235
|
1 |
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
10 |
|
public function getTitle() : string |
241
|
|
|
{ |
242
|
10 |
|
return $this->title; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param string $title |
247
|
|
|
*/ |
248
|
27 |
|
public function setTitle($title) |
249
|
|
|
{ |
250
|
27 |
|
$this->title = $title; |
251
|
27 |
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @return string |
255
|
|
|
*/ |
256
|
4 |
|
public function getTitleLink() : string |
257
|
|
|
{ |
258
|
4 |
|
return $this->titleLink; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @param string $titleLink |
263
|
|
|
*/ |
264
|
13 |
|
public function setTitleLink($titleLink) |
265
|
|
|
{ |
266
|
13 |
|
$this->titleLink = $titleLink; |
267
|
13 |
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @return string |
271
|
|
|
*/ |
272
|
4 |
|
public function getText() : string |
273
|
|
|
{ |
274
|
4 |
|
return $this->text; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param string $text |
279
|
|
|
*/ |
280
|
27 |
|
public function setText($text) |
281
|
|
|
{ |
282
|
27 |
|
$this->text = $text; |
283
|
27 |
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @return string |
287
|
|
|
*/ |
288
|
4 |
|
public function getImageUrl() : string |
289
|
|
|
{ |
290
|
4 |
|
return $this->imageUrl; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param string $imageUrl |
295
|
|
|
*/ |
296
|
1 |
|
public function setImageUrl($imageUrl) |
297
|
|
|
{ |
298
|
1 |
|
$this->imageUrl = $imageUrl; |
299
|
1 |
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @return string |
303
|
|
|
*/ |
304
|
4 |
|
public function getThumbUrl() : string |
305
|
|
|
{ |
306
|
4 |
|
return $this->thumbUrl; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @param string $thumbUrl |
311
|
|
|
*/ |
312
|
1 |
|
public function setThumbUrl($thumbUrl) |
313
|
|
|
{ |
314
|
1 |
|
$this->thumbUrl = $thumbUrl; |
315
|
1 |
|
} |
316
|
|
|
} |
317
|
|
|
|