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 getPrice() |
70
|
|
|
*/ |
71
|
|
|
class Video extends Extension |
72
|
|
|
{ |
73
|
|
|
use DateTime; |
74
|
|
|
use IsAssoc; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Name of Namescapce. |
78
|
|
|
*/ |
79
|
|
|
public const NAMESPACE_NAME = 'video'; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Namespace URL. |
83
|
|
|
*/ |
84
|
|
|
public const NAMESPACE_URL = 'http://www.google.com/schemas/sitemap-video/1.1'; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Element name. |
88
|
|
|
*/ |
89
|
|
|
public const ELEMENT_NAME = 'video'; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* URL pointing to an image thumbnail. |
93
|
|
|
* |
94
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
95
|
|
|
*/ |
96
|
|
|
protected $thumbnailLoc; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Title of the video, max 100 characters. |
100
|
|
|
* |
101
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
102
|
|
|
*/ |
103
|
|
|
protected $title; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Description of the video, max 2048 characters. |
107
|
|
|
* |
108
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
109
|
|
|
*/ |
110
|
|
|
protected $description; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* URL pointing to the actual media file (mp4). |
114
|
|
|
* |
115
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
116
|
|
|
*/ |
117
|
|
|
protected $contentLoc; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* URL pointing to the player file (normally a SWF). |
121
|
|
|
* |
122
|
|
|
* @attribute allow_embed |
123
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\YesNoType |
124
|
|
|
* @attribute autoplay |
125
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
126
|
|
|
* |
127
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
128
|
|
|
*/ |
129
|
|
|
protected $playerLoc; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Indicates whether the video is live. |
133
|
|
|
* |
134
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\YesNoType |
135
|
|
|
*/ |
136
|
|
|
protected $live; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Duration of the video in seconds. |
140
|
|
|
* |
141
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\IntegerType |
142
|
|
|
*/ |
143
|
|
|
protected $duration; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* String of space delimited platform values. |
147
|
|
|
* Allowed values are web, mobile, and tv. |
148
|
|
|
* |
149
|
|
|
* @attribute relationship |
150
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
151
|
|
|
* |
152
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
153
|
|
|
*/ |
154
|
|
|
protected $platform; |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Does the video require a subscription? |
158
|
|
|
* |
159
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\YesNoType |
160
|
|
|
*/ |
161
|
|
|
protected $requiresSubscription; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @attribute currency |
165
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
166
|
|
|
* @attribute type |
167
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
168
|
|
|
* @attribute resolution |
169
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
170
|
|
|
* |
171
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\FloatType |
172
|
|
|
*/ |
173
|
|
|
protected $price; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Link to gallery of which this video appears in. |
177
|
|
|
* |
178
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\URLType |
179
|
|
|
*/ |
180
|
|
|
protected $galleryLoc; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* A space-delimited list of countries where the video may or may not be played. |
184
|
|
|
* |
185
|
|
|
* @attribute relationship |
186
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType |
187
|
|
|
* |
188
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
189
|
|
|
*/ |
190
|
|
|
protected $restriction; |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* A tag associated with the video. |
194
|
|
|
* |
195
|
|
|
* @dataType \Wszetko\Sitemap\Items\DataTypes\StringType |
196
|
|
|
* |
197
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\ArrayType |
198
|
|
|
*/ |
199
|
|
|
protected $tag; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* The video's category. For example, cooking. |
203
|
|
|
* |
204
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
205
|
|
|
*/ |
206
|
|
|
protected $category; |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* No if the video should be available only to users with SafeSearch turned off. |
210
|
|
|
* |
211
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\YesNoType |
212
|
|
|
*/ |
213
|
|
|
protected $familyFriendly; |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* The date the video was first published. |
217
|
|
|
* |
218
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\DateTimeType |
219
|
|
|
*/ |
220
|
|
|
protected $publicationDate; |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* The number of times the video has been viewed. |
224
|
|
|
* |
225
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\IntegerType |
226
|
|
|
*/ |
227
|
|
|
protected $viewCount; |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* The video uploader's name. Only one <video:uploader> is allowed per video. |
231
|
|
|
* |
232
|
|
|
* @attribute info |
233
|
|
|
* @attributeDataType \Wszetko\Sitemap\Items\DataTypes\URLType |
234
|
|
|
* |
235
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\StringType |
236
|
|
|
*/ |
237
|
|
|
protected $uploader; |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
241
|
|
|
* |
242
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\FloatType |
243
|
|
|
*/ |
244
|
|
|
protected $rating; |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* The date after which the video will no longer be available. |
248
|
|
|
* |
249
|
|
|
* @var \Wszetko\Sitemap\Items\DataTypes\DateTimeType |
250
|
|
|
*/ |
251
|
|
|
protected $expirationDate; |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Video constructor. |
255
|
|
|
* |
256
|
|
|
* @param string $thumbnailLoc |
257
|
|
|
* @param string $title |
258
|
|
|
* @param string $description |
259
|
|
|
* |
260
|
|
|
* @throws InvalidArgumentException |
261
|
|
|
* @throws \ReflectionException |
262
|
|
|
*/ |
263
|
302 |
|
public function __construct($thumbnailLoc, $title, $description) |
264
|
|
|
{ |
265
|
302 |
|
parent::__construct(); |
266
|
302 |
|
$this->setUpValues(); |
267
|
302 |
|
$this->setThumbnailLoc($thumbnailLoc); |
268
|
300 |
|
$this->setTitle($title); |
269
|
298 |
|
$this->setDescription($description); |
270
|
296 |
|
} |
271
|
|
|
|
272
|
302 |
|
private function setUpValues(): void |
273
|
|
|
{ |
274
|
302 |
|
$this->thumbnailLoc |
275
|
302 |
|
->setRequired(true) |
276
|
|
|
; |
277
|
302 |
|
$this->title |
278
|
302 |
|
->setRequired(true) |
279
|
302 |
|
->setMinLength(1) |
280
|
302 |
|
->setMaxLength(100) |
281
|
|
|
; |
282
|
302 |
|
$this->description |
283
|
302 |
|
->setRequired(true) |
284
|
302 |
|
->setMinLength(1) |
285
|
302 |
|
->setMaxLength(2048) |
286
|
|
|
; |
287
|
302 |
|
$this->rating |
288
|
302 |
|
->setMinValue(0) |
289
|
302 |
|
->setMaxValue(5) |
290
|
302 |
|
->setPrecision(1) |
291
|
|
|
; |
292
|
302 |
|
$this->viewCount |
293
|
302 |
|
->setMinValue(0) |
294
|
|
|
; |
295
|
302 |
|
$this->duration |
296
|
302 |
|
->setMinValue(0) |
297
|
302 |
|
->setMaxValue(28800) |
298
|
|
|
; |
299
|
302 |
|
$this->restriction |
300
|
302 |
|
->setConversion('upper') |
301
|
302 |
|
->setValueRegex("/^(?'countries'[A-Z]{2}( +[A-Z]{2})*)?$/", 'countries') |
302
|
|
|
; |
303
|
302 |
|
$this->restriction |
304
|
302 |
|
->getAttribute('relationship') |
305
|
302 |
|
->setConversion('lower') |
306
|
302 |
|
->setAllowedValues('allow, deny') |
307
|
|
|
; |
308
|
302 |
|
$this->platform |
309
|
302 |
|
->setConversion('lower') |
310
|
302 |
|
->setValueRegex("/^(?'platform'(web|mobile|tv)( (web|mobile|tv))*)?/", 'platform') |
311
|
|
|
; |
312
|
302 |
|
$this->platform |
313
|
302 |
|
->getAttribute('relationship') |
314
|
302 |
|
->setConversion('lower') |
315
|
302 |
|
->setAllowedValues('allow, deny') |
316
|
|
|
; |
317
|
302 |
|
$this->price |
318
|
302 |
|
->setMinValue(0) |
319
|
302 |
|
->setPrecision(2) |
320
|
|
|
; |
321
|
302 |
|
$this->price |
322
|
302 |
|
->getAttribute('currency') |
323
|
302 |
|
->setConversion('upper') |
324
|
302 |
|
->setRequired(true) |
325
|
302 |
|
->setValueRegex("/^(?'currency'[A-Z]{3})$/", 'currency') |
326
|
|
|
; |
327
|
302 |
|
$this->price |
328
|
302 |
|
->getAttribute('type') |
329
|
302 |
|
->setConversion('lower') |
330
|
302 |
|
->setAllowedValues('rent, purchase') |
331
|
|
|
; |
332
|
302 |
|
$this->price |
333
|
302 |
|
->getAttribute('resolution') |
334
|
302 |
|
->setConversion('upper') |
335
|
302 |
|
->setAllowedValues('SD, HD') |
336
|
|
|
; |
337
|
302 |
|
$this->tag |
338
|
302 |
|
->setMaxElements(32) |
339
|
|
|
; |
340
|
302 |
|
$this->category |
341
|
302 |
|
->setMaxLength(256) |
342
|
|
|
; |
343
|
302 |
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @return array |
347
|
|
|
*/ |
348
|
4 |
|
public function toArray(): array |
349
|
|
|
{ |
350
|
4 |
|
if (empty($this->getContentLoc()) && empty($this->getPlayerLoc())) { |
351
|
2 |
|
throw new InvalidArgumentException('Nor content_loc or player_loc parameter is set.'); |
352
|
|
|
} |
353
|
|
|
|
354
|
4 |
|
return parent::toArray(); |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|