|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Wszetko\Sitemap\Items; |
|
5
|
|
|
|
|
6
|
|
|
use DateTimeInterface; |
|
7
|
|
|
use InvalidArgumentException as InvalidArgumentException; |
|
8
|
|
|
use Wszetko\Sitemap\Traits\DateTime; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Video |
|
12
|
|
|
* |
|
13
|
|
|
* @todo : add support for content_segment_loc tag |
|
14
|
|
|
* @package Wszetko\Sitemap\Items |
|
15
|
|
|
*/ |
|
16
|
|
|
class Video extends Extension |
|
17
|
|
|
{ |
|
18
|
|
|
use DateTime; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Name of Namescapce |
|
22
|
|
|
*/ |
|
23
|
|
|
const NAMESPACE_NAME = 'video'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Namespace URL |
|
27
|
|
|
*/ |
|
28
|
|
|
const NAMESPACE_URL = 'http://www.google.com/schemas/sitemap-video/1.1'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* URL pointing to an image thumbnail. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $thumbnailLoc; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Title of the video, max 100 characters. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $title; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Description of the video, max 2048 characters. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $description; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* URL pointing to the actual media file (mp4). |
|
53
|
|
|
* |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $contentLoc; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* URL pointing to the player file (normally a SWF). |
|
60
|
|
|
* |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $playerLoc; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Indicates whether the video is live. |
|
67
|
|
|
* |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $live; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Duration of the video in seconds. |
|
74
|
|
|
* |
|
75
|
|
|
* @var integer |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $duration; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* String of space delimited platform values. |
|
81
|
|
|
* Allowed values are web, mobile, and tv. |
|
82
|
|
|
* |
|
83
|
|
|
* @var array |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $platform; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Does the video require a subscription? |
|
89
|
|
|
* |
|
90
|
|
|
* @var string |
|
91
|
|
|
*/ |
|
92
|
|
|
protected $requiresSubscription; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Information about price |
|
96
|
|
|
* |
|
97
|
|
|
* @var array |
|
98
|
|
|
*/ |
|
99
|
|
|
protected $price; |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* The currency used for the price. |
|
103
|
|
|
* |
|
104
|
|
|
* @var string |
|
105
|
|
|
*/ |
|
106
|
|
|
protected $currency; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Link to gallery of which this video appears in. |
|
110
|
|
|
* |
|
111
|
|
|
* @var string |
|
112
|
|
|
*/ |
|
113
|
|
|
protected $galleryLoc; |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* A space-delimited list of countries where the video may or may not be played. |
|
117
|
|
|
* |
|
118
|
|
|
* @var array |
|
119
|
|
|
*/ |
|
120
|
|
|
protected $restriction; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* A tag associated with the video. |
|
124
|
|
|
* |
|
125
|
|
|
* @var array |
|
126
|
|
|
*/ |
|
127
|
|
|
protected $tags; |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* The video's category. For example, cooking. |
|
131
|
|
|
* |
|
132
|
|
|
* @var string |
|
133
|
|
|
*/ |
|
134
|
|
|
protected $category; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* No if the video should be available only to users with SafeSearch turned off. |
|
138
|
|
|
* |
|
139
|
|
|
* @var string |
|
140
|
|
|
*/ |
|
141
|
|
|
protected $familyFriendly; |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* The date the video was first published. |
|
145
|
|
|
* |
|
146
|
|
|
* @var string|null |
|
147
|
|
|
*/ |
|
148
|
|
|
protected $publicationDate; |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* The number of times the video has been viewed. |
|
152
|
|
|
* |
|
153
|
|
|
* @var integer |
|
154
|
|
|
*/ |
|
155
|
|
|
protected $viewCount; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* The video uploader's name. Only one <video:uploader> is allowed per video. |
|
159
|
|
|
* |
|
160
|
|
|
* @var string|array |
|
161
|
|
|
*/ |
|
162
|
|
|
protected $uploader; |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
|
166
|
|
|
* |
|
167
|
|
|
* @var float |
|
168
|
|
|
*/ |
|
169
|
|
|
protected $rating; |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* The date after which the video will no longer be available |
|
173
|
|
|
* |
|
174
|
|
|
* @var string |
|
175
|
|
|
*/ |
|
176
|
|
|
protected $expirationDate; |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Video constructor. |
|
180
|
|
|
* |
|
181
|
|
|
* @param string $thumbnailLoc |
|
182
|
|
|
* @param string $title |
|
183
|
|
|
* @param string $description |
|
184
|
|
|
* |
|
185
|
|
|
* @throws InvalidArgumentException |
|
186
|
|
|
*/ |
|
187
|
25 |
|
public function __construct($thumbnailLoc, $title, $description) |
|
188
|
|
|
{ |
|
189
|
25 |
|
if (!\Wszetko\Sitemap\Helpers\Url::normalizeUrl('https://example.com' . $thumbnailLoc)) { |
|
|
|
|
|
|
190
|
1 |
|
throw new InvalidArgumentException('Invalid thumbnail location parameter.'); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
25 |
|
$this->thumbnailLoc = '/' . ltrim($thumbnailLoc, '/'); |
|
194
|
25 |
|
$this->title = mb_substr($title, 0, 100); |
|
195
|
25 |
|
$this->description = mb_substr($description, 0, 2048); |
|
196
|
25 |
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* The currency used for the price. |
|
200
|
|
|
* |
|
201
|
|
|
* @return string|null |
|
202
|
|
|
*/ |
|
203
|
1 |
|
public function getCurrency(): ?string |
|
204
|
|
|
{ |
|
205
|
1 |
|
return $this->currency; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* The currency used for the price. |
|
210
|
|
|
* |
|
211
|
|
|
* @param string $currency |
|
212
|
|
|
* |
|
213
|
|
|
* @return self |
|
214
|
|
|
*/ |
|
215
|
1 |
|
public function setCurrency(string $currency): self |
|
216
|
|
|
{ |
|
217
|
1 |
|
preg_match_all("/^(?'currency'[A-Z]{3})$/", $currency, $matches); |
|
218
|
|
|
|
|
219
|
1 |
|
if (!empty($matches['currency'])) { |
|
220
|
1 |
|
$this->currency = $matches['currency'][0]; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
1 |
|
return $this; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @return array |
|
228
|
|
|
*/ |
|
229
|
1 |
|
public function toArray(): array |
|
230
|
|
|
{ |
|
231
|
1 |
|
if (empty($this->getContentLoc()) && empty($this->getPlayerLoc())) { |
|
232
|
1 |
|
throw new InvalidArgumentException('Nor content_loc or player_loc parameter is set.'); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
$array = [ |
|
236
|
1 |
|
'_namespace' => static::NAMESPACE_NAME, |
|
237
|
1 |
|
'_element' => 'video', |
|
238
|
|
|
'video' => [ |
|
239
|
1 |
|
'thumbnail_loc' => $this->getThumbnailLoc(), |
|
240
|
1 |
|
'title' => $this->getTitle(), |
|
241
|
1 |
|
'description' => $this->getDescription() |
|
242
|
|
|
] |
|
243
|
|
|
]; |
|
244
|
|
|
|
|
245
|
1 |
|
if (!empty($this->getContentLoc())) { |
|
246
|
1 |
|
foreach ($this->getContentLoc() as $contentLoc) { |
|
247
|
1 |
|
if ($contentLoc != $this->getDomain()) { |
|
248
|
1 |
|
if (!isset($array['video']['content_loc'])) { |
|
249
|
1 |
|
$array['video']['content_loc'] = []; |
|
250
|
|
|
} |
|
251
|
1 |
|
$array['video']['content_loc'][] = $contentLoc; |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
1 |
|
if (!empty($this->getPlayerLoc())) { |
|
257
|
1 |
|
foreach ($this->getPlayerLoc() as $playerLoc) { |
|
258
|
1 |
|
if ($playerLoc != $this->getDomain()) { |
|
259
|
1 |
|
if (!isset($array['video']['player_loc'])) { |
|
260
|
1 |
|
$array['video']['player_loc'] = []; |
|
261
|
|
|
} |
|
262
|
1 |
|
if (is_array($playerLoc)) { |
|
263
|
1 |
|
$loc = array_key_first($playerLoc); |
|
264
|
1 |
|
$array['video']['player_loc'][] = [ |
|
265
|
1 |
|
'_attributes' => ['allow_embed' => $playerLoc[$loc]], |
|
266
|
1 |
|
'_value' => $loc |
|
267
|
|
|
]; |
|
268
|
|
|
} else { |
|
269
|
1 |
|
$array['video']['player_loc'][] = $playerLoc; |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
1 |
|
if (!empty($this->getDuration())) { |
|
276
|
1 |
|
$array['video']['duration'] = $this->getDuration(); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
1 |
|
if (!empty($this->getExpirationDate())) { |
|
280
|
1 |
|
$array['video']['expiration_date'] = $this->getExpirationDate(); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
1 |
|
if (!empty($this->getRating())) { |
|
284
|
1 |
|
$array['video']['rating'] = $this->getRating(); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
1 |
|
if (!empty($this->getViewCount())) { |
|
288
|
1 |
|
$array['video']['view_count'] = $this->getViewCount(); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
1 |
|
if (!empty($this->getPublicationDate())) { |
|
292
|
1 |
|
$array['video']['publication_date'] = $this->getPublicationDate(); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
1 |
|
if (!empty($this->getFamilyFriendly())) { |
|
296
|
1 |
|
$array['video']['family_friendly'] = $this->getFamilyFriendly(); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
1 |
|
if (!empty($this->getRestriction())) { |
|
300
|
1 |
|
$restriction = $this->getRestriction(); |
|
301
|
1 |
|
$relationship = array_key_first($this->getRestriction()); |
|
302
|
1 |
|
$countries = $restriction[$relationship]; |
|
303
|
|
|
|
|
304
|
1 |
|
$array['video']['restriction'] = [ |
|
305
|
1 |
|
'_attributes' => ['relationship' => $relationship], |
|
306
|
1 |
|
'_value' => $countries |
|
307
|
|
|
]; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
1 |
|
if (!empty($this->getPlatform())) { |
|
311
|
1 |
|
$platform = $this->getPlatform(); |
|
312
|
1 |
|
$relationship = array_key_first($platform); |
|
313
|
1 |
|
$platform = $platform[$relationship]; |
|
314
|
1 |
|
$array['video']['platform'] = [ |
|
315
|
1 |
|
'_attributes' => ['relationship' => $relationship], |
|
316
|
1 |
|
'_value' => $platform |
|
317
|
|
|
]; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
1 |
|
if (!empty($this->getPrice())) { |
|
321
|
1 |
|
$price = $this->getPrice(); |
|
322
|
1 |
|
$array['video']['price'] = [ |
|
323
|
1 |
|
'_attributes' => ['currency' => $price['currency']], |
|
324
|
1 |
|
'_value' => $price['price'] |
|
325
|
|
|
]; |
|
326
|
|
|
|
|
327
|
1 |
|
if (isset($price['type'])) { |
|
328
|
1 |
|
$array['video']['price']['_attributes']['type'] = $price['type']; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
1 |
|
if (isset($price['resolution'])) { |
|
332
|
1 |
|
$array['video']['price']['_attributes']['resolution'] = $price['resolution']; |
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
1 |
|
if (!empty($this->getRequiresSubscription())) { |
|
337
|
1 |
|
$array['video']['requires_subscription'] = $this->getRequiresSubscription(); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
1 |
|
if (!empty($this->getUploader())) { |
|
341
|
1 |
|
if (is_array($this->getUploader())) { |
|
342
|
1 |
|
$uploader = array_key_first($this->getUploader()); |
|
343
|
1 |
|
$array['video']['uploader'] = [ |
|
344
|
1 |
|
'_attributes' => ['info' => $this->getUploader()[$uploader]], |
|
345
|
1 |
|
'_value' => $uploader |
|
346
|
|
|
]; |
|
347
|
|
|
} else { |
|
348
|
1 |
|
$array['video']['uploader'] = $this->getUploader(); |
|
349
|
|
|
} |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
1 |
|
if (!empty($this->getLive())) { |
|
353
|
1 |
|
$array['video']['live'] = $this->getLive(); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
1 |
|
if (!empty($this->getTags())) { |
|
357
|
1 |
|
$tags = $this->getTags(); |
|
358
|
1 |
|
$array['video']['tag'] = []; |
|
359
|
|
|
|
|
360
|
1 |
|
foreach ($tags as $tag) { |
|
361
|
1 |
|
$array['video']['tag'][] = $tag; |
|
362
|
|
|
} |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
1 |
|
if (!empty($this->getCategory())) { |
|
366
|
1 |
|
$array['video']['category'] = $this->getCategory(); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
1 |
|
if (!empty($this->getGalleryLoc())) { |
|
370
|
1 |
|
$array['video']['gallery_loc'] = $this->getGalleryLoc(); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
1 |
|
return $array; |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/** |
|
377
|
|
|
* URL pointing to the actual media file (mp4). |
|
378
|
|
|
* |
|
379
|
|
|
* @return array |
|
380
|
|
|
* @throws \InvalidArgumentException |
|
381
|
|
|
*/ |
|
382
|
3 |
|
public function getContentLoc(): ?array |
|
383
|
|
|
{ |
|
384
|
3 |
|
if ($this->getDomain()) { |
|
|
|
|
|
|
385
|
2 |
|
if (!empty($this->contentLoc)) { |
|
386
|
2 |
|
$result = []; |
|
387
|
2 |
|
foreach ($this->contentLoc as $contentLoc) { |
|
388
|
2 |
|
$result[] = \Wszetko\Sitemap\Helpers\Url::normalizeUrl($this->getDomain() . $contentLoc); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
2 |
|
return $result; |
|
392
|
|
|
} else { |
|
393
|
2 |
|
return null; |
|
394
|
|
|
} |
|
395
|
|
|
} else { |
|
396
|
1 |
|
throw new InvalidArgumentException('Domain is not set.'); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Player location information |
|
402
|
|
|
* |
|
403
|
|
|
* @return string|array |
|
404
|
|
|
* @throws \InvalidArgumentException |
|
405
|
|
|
*/ |
|
406
|
3 |
|
public function getPlayerLoc() |
|
407
|
|
|
{ |
|
408
|
3 |
|
if ($this->getDomain()) { |
|
|
|
|
|
|
409
|
2 |
|
if (!empty($this->playerLoc)) { |
|
410
|
2 |
|
$result = []; |
|
411
|
2 |
|
foreach ($this->playerLoc as $playerLoc) { |
|
412
|
2 |
|
if (is_string($playerLoc)) { |
|
413
|
2 |
|
$result[] = \Wszetko\Sitemap\Helpers\Url::normalizeUrl($this->getDomain() . $playerLoc); |
|
414
|
2 |
|
} elseif (is_array($playerLoc)) { |
|
415
|
2 |
|
$result[] = [\Wszetko\Sitemap\Helpers\Url::normalizeUrl($this->getDomain() . array_key_first($playerLoc)) => array_values($playerLoc)[0]]; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
2 |
|
return $result; |
|
420
|
|
|
} else { |
|
421
|
2 |
|
return null; |
|
422
|
|
|
} |
|
423
|
|
|
} else { |
|
424
|
1 |
|
throw new InvalidArgumentException('Domain is not set.'); |
|
425
|
|
|
} |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* URL pointing to an image thumbnail. |
|
430
|
|
|
* |
|
431
|
|
|
* @return string |
|
432
|
|
|
*/ |
|
433
|
2 |
|
public function getThumbnailLoc(): string |
|
434
|
|
|
{ |
|
435
|
2 |
|
return \Wszetko\Sitemap\Helpers\Url::normalizeUrl($this->getDomain() . $this->thumbnailLoc); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Title of the video, max 100 characters. |
|
440
|
|
|
* |
|
441
|
|
|
* @return string |
|
442
|
|
|
*/ |
|
443
|
2 |
|
public function getTitle(): string |
|
444
|
|
|
{ |
|
445
|
2 |
|
return $this->title; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* Description of the video, max 2048 characters. |
|
450
|
|
|
* |
|
451
|
|
|
* @return string |
|
452
|
|
|
*/ |
|
453
|
2 |
|
public function getDescription(): string |
|
454
|
|
|
{ |
|
455
|
2 |
|
return $this->description; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* Duration of the video in seconds. |
|
460
|
|
|
* |
|
461
|
|
|
* @return integer|null |
|
462
|
|
|
*/ |
|
463
|
2 |
|
public function getDuration(): ?int |
|
464
|
|
|
{ |
|
465
|
2 |
|
return $this->duration; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* Duration of the video in seconds. |
|
470
|
|
|
* |
|
471
|
|
|
* @param int $duration |
|
472
|
|
|
* |
|
473
|
|
|
* @return self |
|
474
|
|
|
* @todo: add support for adding time duration in different format (eg. ISO-8601) |
|
475
|
|
|
*/ |
|
476
|
2 |
|
public function setDuration($duration): self |
|
477
|
|
|
{ |
|
478
|
2 |
|
if ($duration >= 0 && $duration <= 28800) { |
|
479
|
2 |
|
$this->duration = $duration; |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
2 |
|
return $this; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
/** |
|
486
|
|
|
* The date after which the video will no longer be available. |
|
487
|
|
|
* |
|
488
|
|
|
* @return string|null |
|
489
|
|
|
*/ |
|
490
|
2 |
|
public function getExpirationDate(): ?string |
|
491
|
|
|
{ |
|
492
|
2 |
|
return $this->expirationDate; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
/** |
|
496
|
|
|
* The date after which the video will no longer be available. |
|
497
|
|
|
* |
|
498
|
|
|
* @param DateTimeInterface|string $expirationDate |
|
499
|
|
|
* |
|
500
|
|
|
* @return self |
|
501
|
|
|
*/ |
|
502
|
2 |
|
public function setExpirationDate($expirationDate): self |
|
503
|
|
|
{ |
|
504
|
2 |
|
if ($dateTime = $this->processDateTime($expirationDate)) { |
|
505
|
2 |
|
$this->expirationDate = $dateTime; |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
2 |
|
return $this; |
|
509
|
|
|
} |
|
510
|
|
|
|
|
511
|
|
|
/** |
|
512
|
|
|
* The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
|
513
|
|
|
* |
|
514
|
|
|
* @return float|null |
|
515
|
|
|
*/ |
|
516
|
2 |
|
public function getRating(): ?float |
|
517
|
|
|
{ |
|
518
|
2 |
|
return $this->rating; |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
/** |
|
522
|
|
|
* The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
|
523
|
|
|
* |
|
524
|
|
|
* @param float $rating |
|
525
|
|
|
* |
|
526
|
|
|
* @return self |
|
527
|
|
|
* @todo: support other formats like int, string |
|
528
|
|
|
*/ |
|
529
|
2 |
|
public function setRating(float $rating): self |
|
530
|
|
|
{ |
|
531
|
2 |
|
if ($rating >= 0 && $rating <= 5) { |
|
532
|
2 |
|
$this->rating = round($rating, 1); |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
2 |
|
return $this; |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
/** |
|
539
|
|
|
* The number of times the video has been viewed. |
|
540
|
|
|
* |
|
541
|
|
|
* @return integer|null |
|
542
|
|
|
*/ |
|
543
|
2 |
|
public function getViewCount(): ?int |
|
544
|
|
|
{ |
|
545
|
2 |
|
return $this->viewCount; |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
/** |
|
549
|
|
|
* The number of times the video has been viewed. |
|
550
|
|
|
* |
|
551
|
|
|
* @param integer $viewCount |
|
552
|
|
|
* |
|
553
|
|
|
* @return self |
|
554
|
|
|
* @todo: support other format like string |
|
555
|
|
|
*/ |
|
556
|
2 |
|
public function setViewCount(int $viewCount): self |
|
557
|
|
|
{ |
|
558
|
2 |
|
$this->viewCount = $viewCount; |
|
559
|
|
|
|
|
560
|
2 |
|
return $this; |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
/** |
|
564
|
|
|
* The date the video was first published, in W3C format. |
|
565
|
|
|
* |
|
566
|
|
|
* @return string|null |
|
567
|
|
|
*/ |
|
568
|
2 |
|
public function getPublicationDate(): ?string |
|
569
|
|
|
{ |
|
570
|
2 |
|
return $this->publicationDate; |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* The date the video was first published, in W3C format. |
|
575
|
|
|
* |
|
576
|
|
|
* @param DateTimeInterface|string $publicationDate |
|
577
|
|
|
* |
|
578
|
|
|
* @return self |
|
579
|
|
|
*/ |
|
580
|
2 |
|
public function setPublicationDate($publicationDate): self |
|
581
|
|
|
{ |
|
582
|
2 |
|
if ($dateTime = $this->processDateTime($publicationDate)) { |
|
583
|
2 |
|
$this->publicationDate = $dateTime; |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
2 |
|
return $this; |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
/** |
|
590
|
|
|
* No if the video should be available only to users with SafeSearch turned off. |
|
591
|
|
|
* |
|
592
|
|
|
* @return string|null |
|
593
|
|
|
*/ |
|
594
|
2 |
|
public function getFamilyFriendly(): ?string |
|
595
|
|
|
{ |
|
596
|
2 |
|
return $this->familyFriendly; |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
/** |
|
600
|
|
|
* No if the video should be available only to users with SafeSearch turned off. |
|
601
|
|
|
* |
|
602
|
|
|
* @todo: support other format like strings ('Yes', 'No, 'yes', 'no', 'y', 'n') or null |
|
603
|
|
|
* |
|
604
|
|
|
* @param bool $familyFriendly |
|
605
|
|
|
* |
|
606
|
|
|
* @return self |
|
607
|
|
|
*/ |
|
608
|
2 |
|
public function setFamilyFriendly(bool $familyFriendly): self |
|
609
|
|
|
{ |
|
610
|
2 |
|
$this->familyFriendly = $familyFriendly ? 'Yes' : 'No'; |
|
611
|
|
|
|
|
612
|
2 |
|
return $this; |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
/** |
|
616
|
|
|
* A space-delimited list of countries where the video may or may not be played. |
|
617
|
|
|
* |
|
618
|
|
|
* @return array|null |
|
619
|
|
|
*/ |
|
620
|
2 |
|
public function getRestriction(): ?array |
|
621
|
|
|
{ |
|
622
|
2 |
|
return $this->restriction; |
|
623
|
|
|
} |
|
624
|
|
|
|
|
625
|
|
|
/** |
|
626
|
|
|
* A space-delimited list of countries where the video may or may not be played. |
|
627
|
|
|
* |
|
628
|
|
|
* @param string $relationship |
|
629
|
|
|
* @param string $countries |
|
630
|
|
|
* |
|
631
|
|
|
* @return self |
|
632
|
|
|
*/ |
|
633
|
2 |
|
public function setRestriction(string $relationship, string $countries): self |
|
634
|
|
|
{ |
|
635
|
2 |
|
preg_match_all("/^(?'countries'[A-Z]{2}( +[A-Z]{2})*)?$/", $countries, $matches); |
|
636
|
|
|
|
|
637
|
2 |
|
if ($this->validRelationship($relationship) && !empty($matches['countries'])) { |
|
638
|
2 |
|
$this->restriction = [$relationship => $countries]; |
|
639
|
|
|
} |
|
640
|
|
|
|
|
641
|
2 |
|
return $this; |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
/** |
|
645
|
|
|
* String of space delimited platform values. |
|
646
|
|
|
* Allowed values are web, mobile, and tv. |
|
647
|
|
|
* |
|
648
|
|
|
* @return array|null |
|
649
|
|
|
*/ |
|
650
|
2 |
|
public function getPlatform(): ?array |
|
651
|
|
|
{ |
|
652
|
2 |
|
return $this->platform; |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
/** |
|
656
|
|
|
* String of space delimited platform values. |
|
657
|
|
|
* Allowed values are web, mobile, and tv. |
|
658
|
|
|
* |
|
659
|
|
|
* @param string $relationship |
|
660
|
|
|
* @param string $platform |
|
661
|
|
|
* |
|
662
|
|
|
* @return self |
|
663
|
|
|
*/ |
|
664
|
2 |
|
public function setPlatform(string $relationship, string $platform): self |
|
665
|
|
|
{ |
|
666
|
2 |
|
preg_match_all("/^(?'platform'(web|mobile|tv)( (web|mobile|tv))*)?/", $platform, $matches); |
|
667
|
|
|
|
|
668
|
2 |
|
if ($this->validRelationship($relationship) && !empty($matches['platform'])) { |
|
669
|
2 |
|
$this->platform = [$relationship => $platform]; |
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
2 |
|
return $this; |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
/** |
|
676
|
|
|
* The price to download or view the video in ISO 4217 format. |
|
677
|
|
|
* |
|
678
|
|
|
* @return array|null |
|
679
|
|
|
*/ |
|
680
|
2 |
|
public function getPrice(): ?array |
|
681
|
|
|
{ |
|
682
|
2 |
|
return $this->price; |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
/** |
|
686
|
|
|
* The price to download or view the video in ISO 4217 format. |
|
687
|
|
|
* |
|
688
|
|
|
* @param float $price |
|
689
|
|
|
* @param string $currency |
|
690
|
|
|
* @param string $type |
|
691
|
|
|
* @param string $resolution |
|
692
|
|
|
* |
|
693
|
|
|
* @return self |
|
694
|
|
|
* @todo: support more formats for price (rg. int, string) |
|
695
|
|
|
* @todo: normalize output to one format |
|
696
|
|
|
*/ |
|
697
|
2 |
|
public function setPrice(float $price, string $currency, string $type = '', string $resolution = ''): self |
|
698
|
|
|
{ |
|
699
|
2 |
|
preg_match_all("/^(?'currency'[A-Z]{3})$/", $currency, $matches); |
|
700
|
|
|
|
|
701
|
2 |
|
if (!empty($matches['currency'])) { |
|
702
|
2 |
|
$data = []; |
|
703
|
2 |
|
$data['price'] = round($price, 2); |
|
704
|
2 |
|
$data['currency'] = $currency; |
|
705
|
|
|
|
|
706
|
2 |
|
if (in_array($type, ['rent', 'RENT', 'purchase', 'PURCHASE'])) { |
|
707
|
2 |
|
$data['type'] = $type; |
|
708
|
|
|
} |
|
709
|
|
|
|
|
710
|
2 |
|
if (in_array($resolution, ['sd', 'hd', 'SD', 'HD'])) { |
|
711
|
2 |
|
$data['resolution'] = $resolution; |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
2 |
|
$this->price = $data; |
|
715
|
|
|
} |
|
716
|
|
|
|
|
717
|
2 |
|
return $this; |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
/** |
|
721
|
|
|
* Does the video require a subscription? |
|
722
|
|
|
* |
|
723
|
|
|
* @return string|null |
|
724
|
|
|
*/ |
|
725
|
2 |
|
public function getRequiresSubscription(): ?string |
|
726
|
|
|
{ |
|
727
|
2 |
|
return $this->requiresSubscription; |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
/** |
|
731
|
|
|
* Does the video require a subscription? |
|
732
|
|
|
* |
|
733
|
|
|
* @param boolean $requiresSubscription |
|
734
|
|
|
* |
|
735
|
|
|
* @return self |
|
736
|
|
|
*/ |
|
737
|
2 |
|
public function setRequiresSubscription(bool $requiresSubscription): self |
|
738
|
|
|
{ |
|
739
|
2 |
|
$this->requiresSubscription = $requiresSubscription ? 'Yes' : 'No'; |
|
740
|
|
|
|
|
741
|
2 |
|
return $this; |
|
742
|
|
|
} |
|
743
|
|
|
|
|
744
|
|
|
/** |
|
745
|
|
|
* The video uploader's name. Only one <video:uploader> is allowed per video. |
|
746
|
|
|
* |
|
747
|
|
|
* @return string|array |
|
748
|
|
|
*/ |
|
749
|
2 |
|
public function getUploader() |
|
750
|
|
|
{ |
|
751
|
2 |
|
if (is_array($this->uploader)) { |
|
752
|
2 |
|
return [array_key_first($this->uploader) => $this->getDomain() . $this->uploader[array_key_first($this->uploader)]]; |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
2 |
|
return $this->uploader; |
|
756
|
|
|
} |
|
757
|
|
|
|
|
758
|
|
|
/** |
|
759
|
|
|
* The video uploader's name. Only one <video:uploader> is allowed per video. |
|
760
|
|
|
* |
|
761
|
|
|
* @param string $uploader |
|
762
|
|
|
* @param string $info |
|
763
|
|
|
* |
|
764
|
|
|
* @return self |
|
765
|
|
|
*/ |
|
766
|
2 |
|
public function setUploader(string $uploader, string $info = ''): self |
|
767
|
|
|
{ |
|
768
|
2 |
|
if (!empty($info)) { |
|
769
|
2 |
|
$this->uploader = [$uploader => $info]; |
|
770
|
|
|
} else { |
|
771
|
2 |
|
$this->uploader = $uploader; |
|
772
|
|
|
} |
|
773
|
|
|
|
|
774
|
2 |
|
return $this; |
|
775
|
|
|
} |
|
776
|
|
|
|
|
777
|
|
|
/** |
|
778
|
|
|
* Indicates whether the video is live. |
|
779
|
|
|
* |
|
780
|
|
|
* @return string|null |
|
781
|
|
|
*/ |
|
782
|
2 |
|
public function getLive(): ?string |
|
783
|
|
|
{ |
|
784
|
2 |
|
return $this->live; |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
/** |
|
788
|
|
|
* Indicates whether the video is live. |
|
789
|
|
|
* |
|
790
|
|
|
* @param boolean $live |
|
791
|
|
|
* |
|
792
|
|
|
* @return self |
|
793
|
|
|
*/ |
|
794
|
2 |
|
public function setLive(bool $live): self |
|
795
|
|
|
{ |
|
796
|
2 |
|
$this->live = $live ? 'Yes' : 'No'; |
|
797
|
|
|
|
|
798
|
2 |
|
return $this; |
|
799
|
|
|
} |
|
800
|
|
|
|
|
801
|
|
|
/** |
|
802
|
|
|
* A tag associated with the video. |
|
803
|
|
|
* |
|
804
|
|
|
* @return array|null |
|
805
|
|
|
*/ |
|
806
|
2 |
|
public function getTags(): ?array |
|
807
|
|
|
{ |
|
808
|
2 |
|
return $this->tags; |
|
809
|
|
|
} |
|
810
|
|
|
|
|
811
|
|
|
/** |
|
812
|
|
|
* A tag associated with the video. |
|
813
|
|
|
* |
|
814
|
|
|
* @param array $tags |
|
815
|
|
|
* |
|
816
|
|
|
* @return self |
|
817
|
|
|
*/ |
|
818
|
2 |
|
public function setTags(array $tags): self |
|
819
|
|
|
{ |
|
820
|
2 |
|
$this->tags = array_slice($tags, 0, 32); |
|
821
|
|
|
|
|
822
|
2 |
|
return $this; |
|
823
|
|
|
} |
|
824
|
|
|
|
|
825
|
|
|
/** |
|
826
|
|
|
* The video's category. For example, cooking. |
|
827
|
|
|
* |
|
828
|
|
|
* @return string|null |
|
829
|
|
|
*/ |
|
830
|
2 |
|
public function getCategory(): ?string |
|
831
|
|
|
{ |
|
832
|
2 |
|
return $this->category; |
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
/** |
|
836
|
|
|
* The video's category. For example, cooking. |
|
837
|
|
|
* |
|
838
|
|
|
* @param string $category |
|
839
|
|
|
* |
|
840
|
|
|
* @return self |
|
841
|
|
|
*/ |
|
842
|
2 |
|
public function setCategory(string $category): self |
|
843
|
|
|
{ |
|
844
|
2 |
|
$this->category = $category; |
|
845
|
|
|
|
|
846
|
2 |
|
return $this; |
|
847
|
|
|
} |
|
848
|
|
|
|
|
849
|
|
|
/** |
|
850
|
|
|
* Link to gallery of which this video appears in. |
|
851
|
|
|
* |
|
852
|
|
|
* @return string|null |
|
853
|
|
|
*/ |
|
854
|
2 |
|
public function getGalleryLoc(): ?string |
|
855
|
|
|
{ |
|
856
|
2 |
|
return $this->galleryLoc; |
|
857
|
|
|
} |
|
858
|
|
|
|
|
859
|
|
|
/** |
|
860
|
|
|
* @param string $value |
|
861
|
|
|
* |
|
862
|
|
|
* @return bool |
|
863
|
|
|
*/ |
|
864
|
3 |
|
private function validRelationship(string $value): bool |
|
865
|
|
|
{ |
|
866
|
3 |
|
$accepted = ['allow', 'deny']; |
|
867
|
|
|
|
|
868
|
3 |
|
return (bool) in_array($value, $accepted); |
|
869
|
|
|
} |
|
870
|
|
|
|
|
871
|
|
|
/** |
|
872
|
|
|
* Link to gallery of which this video appears in. |
|
873
|
|
|
* |
|
874
|
|
|
* @param string $galleryLoc |
|
875
|
|
|
* |
|
876
|
|
|
* @return self |
|
877
|
|
|
*/ |
|
878
|
2 |
|
public function setGalleryLoc($galleryLoc): self |
|
879
|
|
|
{ |
|
880
|
2 |
|
if (\Wszetko\Sitemap\Helpers\Url::normalizeUrl($galleryLoc)) { |
|
|
|
|
|
|
881
|
2 |
|
$this->galleryLoc = $galleryLoc; |
|
882
|
|
|
} |
|
883
|
|
|
|
|
884
|
2 |
|
return $this; |
|
885
|
|
|
} |
|
886
|
|
|
|
|
887
|
|
|
/** |
|
888
|
|
|
* URL pointing to the actual media file (mp4). |
|
889
|
|
|
* |
|
890
|
|
|
* @param string $contentLoc |
|
891
|
|
|
* |
|
892
|
|
|
* @return self |
|
893
|
|
|
*/ |
|
894
|
2 |
|
public function addContentLoc(string $contentLoc): self |
|
895
|
|
|
{ |
|
896
|
2 |
|
if (!empty($contentLoc)) { |
|
897
|
2 |
|
$this->contentLoc[] = '/' . ltrim($contentLoc, '/'); |
|
898
|
|
|
} |
|
899
|
|
|
|
|
900
|
2 |
|
return $this; |
|
901
|
|
|
} |
|
902
|
|
|
|
|
903
|
|
|
/** |
|
904
|
|
|
* Add player location information |
|
905
|
|
|
* |
|
906
|
|
|
* @param string $playerLoc |
|
907
|
|
|
* @param mixed $allowEmbed |
|
908
|
|
|
* |
|
909
|
|
|
* @return self |
|
910
|
|
|
* @todo: add support to autoplay attribute |
|
911
|
|
|
*/ |
|
912
|
2 |
|
public function addPlayerLoc(string $playerLoc, $allowEmbed = null): self |
|
913
|
|
|
{ |
|
914
|
2 |
|
if (!empty($playerLoc)) { |
|
915
|
2 |
|
$playerLoc = '/' . ltrim($playerLoc, '/'); |
|
916
|
|
|
|
|
917
|
2 |
|
if ($allowEmbed !== null) { |
|
918
|
2 |
|
$this->playerLoc[] = [$playerLoc => $allowEmbed]; |
|
919
|
|
|
} else { |
|
920
|
2 |
|
$this->playerLoc[] = $playerLoc; |
|
921
|
|
|
} |
|
922
|
|
|
} |
|
923
|
|
|
|
|
924
|
2 |
|
return $this; |
|
925
|
|
|
} |
|
926
|
|
|
} |
|
927
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: