1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of Wszetko Sitemap. |
7
|
|
|
* |
8
|
|
|
* (c) Paweł Kłopotek-Główczewski <[email protected]> |
9
|
|
|
* |
10
|
|
|
* This source file is subject to the MIT license that is bundled |
11
|
|
|
* with this source code in the file LICENSE. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Wszetko\Sitemap\Items; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException as InvalidArgumentException; |
17
|
|
|
use Wszetko\Sitemap\Traits\DateTime; |
18
|
|
|
use Wszetko\Sitemap\Traits\IsAssoc; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Video. |
22
|
|
|
* |
23
|
|
|
* @todo : add support for content_segment_loc tag |
24
|
|
|
* @todo : add support for tvshow tag |
25
|
|
|
* @todo : add support for id tag |
26
|
|
|
* |
27
|
|
|
* @package Wszetko\Sitemap\Items |
28
|
|
|
* |
29
|
|
|
* @method setThumbnailLoc($thumbnail) |
30
|
|
|
* @method getThumbnailLoc() |
31
|
|
|
* @method setTitle($title) |
32
|
|
|
* @method getTitle() |
33
|
|
|
* @method setDescription($description) |
34
|
|
|
* @method getDescription() |
35
|
|
|
* @method setRating($rating) |
36
|
|
|
* @method getRating() |
37
|
|
|
* @method setViewCount($viewCount) |
38
|
|
|
* @method getViewCount() |
39
|
|
|
* @method setExpirationDate($expirationDate) |
40
|
|
|
* @method getExpirationDate() |
41
|
|
|
* @method setPublicationDate($publicationDate) |
42
|
|
|
* @method getPublicationDate() |
43
|
|
|
* @method setDuration($duration) |
44
|
|
|
* @method getDuration() |
45
|
|
|
* @method setGalleryLoc($galleryLoc) |
46
|
|
|
* @method getGalleryLoc() |
47
|
|
|
* @method setCategory($category) |
48
|
|
|
* @method getCategory() |
49
|
|
|
* @method setLive($live) |
50
|
|
|
* @method getLive() |
51
|
|
|
* @method setRequiresSubscription($subscription) |
52
|
|
|
* @method getRequiresSubscription() |
53
|
|
|
* @method setFamilyFriendly($familyFriendly) |
54
|
|
|
* @method getFamilyFriendly() |
55
|
|
|
* @method setContentLoc($contentLoc) |
56
|
|
|
* @method getContentLoc() |
57
|
|
|
* @method setPlayerLoc($player, $allow_embed = null, $autoplay = null) |
58
|
|
|
* @method getPlayerLoc() |
59
|
|
|
* @method addTag($tags) |
60
|
|
|
* @method setTag($tag) |
61
|
|
|
* @method getTag() |
62
|
|
|
* @method setUploader($uploader, $info = null) |
63
|
|
|
* @method getUploader() |
64
|
|
|
* @method setRestriction($countries, $relationship) |
65
|
|
|
* @method getRestriction() |
66
|
|
|
* @method setPlatform($platform, $relationship) |
67
|
|
|
* @method getPlatform() |
68
|
|
|
* @method setPrice($price, $currency, $type = null, $resolution = null) |
69
|
|
|
* @method addPrice($price, $currency, $type = null, $resolution = null) |
70
|
|
|
* @method getPrice() |
71
|
|
|
*/ |
72
|
|
|
class Video extends Extension |
73
|
|
|
{ |
74
|
|
|
use DateTime; |
75
|
|
|
use IsAssoc; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Name of Namescapce. |
79
|
|
|
*/ |
80
|
|
|
public const NAMESPACE_NAME = 'video'; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Namespace URL. |
84
|
|
|
*/ |
85
|
|
|
public const NAMESPACE_URL = 'http://www.google.com/schemas/sitemap-video/1.1'; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Element name. |
89
|
|
|
*/ |
90
|
|
|
public const ELEMENT_NAME = 'video'; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* URL pointing to an image thumbnail. |
94
|
|
|
* |
95
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
96
|
|
|
*/ |
97
|
|
|
protected $thumbnailLoc; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Title of the video, max 100 characters. |
101
|
|
|
* |
102
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
103
|
|
|
*/ |
104
|
|
|
protected $title; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Description of the video, max 2048 characters. |
108
|
|
|
* |
109
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
110
|
|
|
*/ |
111
|
|
|
protected $description; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* URL pointing to the actual media file (mp4). |
115
|
|
|
* |
116
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
117
|
|
|
*/ |
118
|
|
|
protected $contentLoc; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* URL pointing to the player file (normally a SWF). |
122
|
|
|
* |
123
|
|
|
* @attribute allow_embed |
124
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\YesNoType |
125
|
|
|
* @attribute autoplay |
126
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
127
|
|
|
* |
128
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
129
|
|
|
*/ |
130
|
|
|
protected $playerLoc; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Indicates whether the video is live. |
134
|
|
|
* |
135
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\YesNoType |
136
|
|
|
*/ |
137
|
|
|
protected $live; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Duration of the video in seconds. |
141
|
|
|
* |
142
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\IntegerType |
143
|
|
|
*/ |
144
|
|
|
protected $duration; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* String of space delimited platform values. |
148
|
|
|
* Allowed values are web, mobile, and tv. |
149
|
|
|
* |
150
|
|
|
* @attribute relationship |
151
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
152
|
|
|
* |
153
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
154
|
|
|
*/ |
155
|
|
|
protected $platform; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Does the video require a subscription? |
159
|
|
|
* |
160
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\YesNoType |
161
|
|
|
*/ |
162
|
|
|
protected $requiresSubscription; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @dataType \Wszetko\Sitemap\Items\DataTypes\FloatType |
166
|
|
|
* @attribute currency |
167
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
168
|
|
|
* @attribute type |
169
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
170
|
|
|
* @attribute resolution |
171
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
172
|
|
|
* |
173
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\ArrayType |
174
|
|
|
*/ |
175
|
|
|
protected $price; |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Link to gallery of which this video appears in. |
179
|
|
|
* |
180
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
181
|
|
|
*/ |
182
|
|
|
protected $galleryLoc; |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* A space-delimited list of countries where the video may or may not be played. |
186
|
|
|
* |
187
|
|
|
* @attribute relationship |
188
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
189
|
|
|
* |
190
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
191
|
|
|
*/ |
192
|
|
|
protected $restriction; |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* A tag associated with the video. |
196
|
|
|
* |
197
|
|
|
* @dataType \Wszetko\Sitemap\Items\DataTypes\StringType |
198
|
|
|
* |
199
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\ArrayType |
200
|
|
|
*/ |
201
|
|
|
protected $tag; |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* The video's category. For example, cooking. |
205
|
|
|
* |
206
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
207
|
|
|
*/ |
208
|
|
|
protected $category; |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* No if the video should be available only to users with SafeSearch turned off. |
212
|
|
|
* |
213
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\YesNoType |
214
|
|
|
*/ |
215
|
|
|
protected $familyFriendly; |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* The date the video was first published. |
219
|
|
|
* |
220
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\DateTimeType |
221
|
|
|
*/ |
222
|
|
|
protected $publicationDate; |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* The number of times the video has been viewed. |
226
|
|
|
* |
227
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\IntegerType |
228
|
|
|
*/ |
229
|
|
|
protected $viewCount; |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* The video uploader's name. Only one <video:uploader> is allowed per video. |
233
|
|
|
* |
234
|
|
|
* @attribute info |
235
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\URLType |
236
|
|
|
* |
237
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
238
|
|
|
*/ |
239
|
|
|
protected $uploader; |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
243
|
|
|
* |
244
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\FloatType |
245
|
|
|
*/ |
246
|
|
|
protected $rating; |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* The date after which the video will no longer be available. |
250
|
|
|
* |
251
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\DateTimeType |
252
|
|
|
*/ |
253
|
|
|
protected $expirationDate; |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Video constructor. |
257
|
|
|
* |
258
|
|
|
* @param string $thumbnailLoc |
259
|
|
|
* @param string $title |
260
|
|
|
* @param string $description |
261
|
|
|
* |
262
|
|
|
* @throws InvalidArgumentException |
263
|
|
|
* @throws \ReflectionException |
264
|
|
|
* @throws \Error |
265
|
|
|
*/ |
266
|
302 |
|
public function __construct($thumbnailLoc, $title, $description) |
267
|
|
|
{ |
268
|
302 |
|
parent::__construct(); |
269
|
302 |
|
$this->setUpValues(); |
270
|
302 |
|
$this->setThumbnailLoc($thumbnailLoc); |
271
|
300 |
|
$this->setTitle($title); |
272
|
298 |
|
$this->setDescription($description); |
273
|
296 |
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @return array |
277
|
|
|
* |
278
|
|
|
* @throws \InvalidArgumentException |
279
|
|
|
* @throws \Error |
280
|
|
|
*/ |
281
|
4 |
|
public function toArray(): array |
282
|
|
|
{ |
283
|
|
|
if ( |
284
|
4 |
|
(null === $this->getContentLoc() || |
285
|
4 |
|
'' === $this->getContentLoc()) && |
286
|
2 |
|
(null === $this->getPlayerLoc() || |
287
|
4 |
|
'' === $this->getPlayerLoc()) |
288
|
|
|
) { |
289
|
2 |
|
throw new InvalidArgumentException('Nor content_loc or player_loc parameter is set.'); |
290
|
|
|
} |
291
|
|
|
|
292
|
4 |
|
return parent::toArray(); |
293
|
|
|
} |
294
|
|
|
|
295
|
302 |
|
private function setUpValues(): void |
296
|
|
|
{ |
297
|
302 |
|
$this->thumbnailLoc |
298
|
302 |
|
->setRequired(true) |
299
|
|
|
; |
300
|
302 |
|
$this->title |
301
|
302 |
|
->setRequired(true) |
302
|
302 |
|
->setMinLength(1) |
303
|
302 |
|
->setMaxLength(100) |
304
|
|
|
; |
305
|
302 |
|
$this->description |
306
|
302 |
|
->setRequired(true) |
307
|
302 |
|
->setMinLength(1) |
308
|
302 |
|
->setMaxLength(2048) |
309
|
|
|
; |
310
|
302 |
|
$this->rating |
311
|
302 |
|
->setMinValue(0) |
312
|
302 |
|
->setMaxValue(5) |
313
|
302 |
|
->setPrecision(1) |
314
|
|
|
; |
315
|
302 |
|
$this->viewCount |
316
|
302 |
|
->setMinValue(0) |
317
|
|
|
; |
318
|
302 |
|
$this->duration |
319
|
302 |
|
->setMinValue(0) |
320
|
302 |
|
->setMaxValue(28800) |
321
|
|
|
; |
322
|
302 |
|
$this->restriction |
323
|
302 |
|
->setConversion('upper') |
324
|
302 |
|
->setValueRegex("/^([A-Z]{2}( +[A-Z]{2})*)?$/") |
325
|
|
|
; |
326
|
|
|
/** @var \Wszetko\Sitemap\Items\DataTypes\StringType $restrictionRelationship */ |
327
|
302 |
|
$restrictionRelationship = $this->restriction->getAttribute('relationship'); |
328
|
|
|
$restrictionRelationship |
329
|
302 |
|
->setConversion('lower') |
330
|
302 |
|
->setAllowedValues('allow, deny') |
331
|
|
|
; |
332
|
302 |
|
$this->platform |
333
|
302 |
|
->setConversion('lower') |
334
|
302 |
|
->setValueRegex("/^((web|mobile|tv)( (web|mobile|tv))*)?/") |
335
|
|
|
; |
336
|
|
|
/** @var \Wszetko\Sitemap\Items\DataTypes\StringType $platformRelationship */ |
337
|
302 |
|
$platformRelationship = $this->platform->getAttribute('relationship'); |
338
|
|
|
$platformRelationship |
339
|
302 |
|
->setConversion('lower') |
340
|
302 |
|
->setAllowedValues('allow, deny') |
341
|
|
|
; |
342
|
|
|
/** @var \Wszetko\Sitemap\Items\DataTypes\FloatType $priceType */ |
343
|
302 |
|
$priceType = $this->price->getBaseDataType(); |
344
|
|
|
$priceType |
345
|
302 |
|
->setMinValue(0) |
346
|
302 |
|
->setPrecision(2) |
347
|
|
|
; |
348
|
|
|
/** @var \Wszetko\Sitemap\Items\DataTypes\StringType $priceCurrency */ |
349
|
302 |
|
$priceCurrency = $priceType->getAttribute('currency'); |
350
|
|
|
$priceCurrency |
351
|
302 |
|
->setConversion('upper') |
352
|
302 |
|
->setRequired(true) |
353
|
302 |
|
->setValueRegex("/^([A-Z]{3})$/") |
354
|
|
|
; |
355
|
|
|
/** @var \Wszetko\Sitemap\Items\DataTypes\StringType $priceType */ |
356
|
302 |
|
$priceType = $this->price->getBaseDataType()->getAttribute('type'); |
357
|
|
|
$priceType |
358
|
302 |
|
->setConversion('lower') |
359
|
302 |
|
->setAllowedValues('rent, purchase') |
360
|
|
|
; |
361
|
|
|
/** @var \Wszetko\Sitemap\Items\DataTypes\StringType $priceResolution */ |
362
|
302 |
|
$priceResolution = $this->price->getBaseDataType()->getAttribute('resolution'); |
363
|
|
|
$priceResolution |
364
|
302 |
|
->setConversion('upper') |
365
|
302 |
|
->setAllowedValues('SD, HD') |
366
|
|
|
; |
367
|
302 |
|
$this->tag |
368
|
302 |
|
->setMaxElements(32) |
369
|
|
|
; |
370
|
302 |
|
$this->category |
371
|
302 |
|
->setMaxLength(256) |
372
|
|
|
; |
373
|
302 |
|
} |
374
|
|
|
} |
375
|
|
|
|