Completed
Push — master ( 72cc95...6cef6f )
by Tim
13s
created

Video::getTechOrder()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
/* * *************************************************************
4
 *  Copyright notice
5
 *
6
 *  (c)  Tim Lochmueller
7
 *  All rights reserved
8
 *
9
 *  This script is part of the TYPO3 project. The TYPO3 project is
10
 *  free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  The GNU General Public License can be found at
16
 *  http://www.gnu.org/copyleft/gpl.html.
17
 *
18
 *  This script is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *
23
 *  This copyright notice MUST APPEAR in all copies of the script!
24
 * ************************************************************* */
25
26
namespace HVP\Html5videoplayer\Domain\Model;
27
28
use HVP\Html5videoplayer\Div;
29
use TYPO3\CMS\Core\Resource\FileInterface;
30
use TYPO3\CMS\Core\Resource\ResourceFactory;
31
use TYPO3\CMS\Core\Utility\GeneralUtility;
32
use TYPO3\CMS\Core\Utility\MathUtility;
33
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
34
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
35
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
36
37
/**
38
 * Report Object
39
 *
40
 * @author     Tim Lochmueller
41
 */
42
class Video extends AbstractEntity
43
{
44
45
    /**
46
     * The title of the Video
47
     *
48
     * @var string
49
     * @validate StringLength(minimum = 1)
50
     */
51
    protected $title;
52
53
    /**
54
     * Vimeo Source Url
55
     *
56
     * @var string
57
     */
58
    protected $vimeo;
59
60
    /**
61
     * The description
62
     *
63
     * @var string
64
     */
65
    protected $description;
66
67
    /**
68
     * The posterimage of the Video
69
     *
70
     * @var string
71
     */
72
    protected $posterimage;
73
74
    /**
75
     * The mp4source of the Video
76
     *
77
     * @var string
78
     */
79
    protected $mp4source;
80
81
    /**
82
     * The webmsource of the Video
83
     *
84
     * @var string
85
     */
86
    protected $webmsource;
87
88
    /**
89
     * The oggsource of the Video
90
     *
91
     * @var string
92
     */
93
    protected $oggsource;
94
95
    /**
96
     * The height of the Video
97
     *
98
     * @var string
99
     */
100
    protected $height;
101
102
    /**
103
     * The width of the Video
104
     *
105
     * @var string
106
     */
107
    protected $width;
108
109
    /**
110
     * Show download links
111
     *
112
     * @var boolean
113
     */
114
    protected $downloadlinks;
115
116
    /**
117
     * Show the support link
118
     *
119
     * @var boolean
120
     */
121
    protected $supportvideojs;
122
123
    /**
124
     * Preload the video
125
     *
126
     * @var string
127
     */
128
    protected $preloadvideo;
129
130
    /**
131
     * Autoplay the video
132
     *
133
     * @var boolean
134
     */
135
    protected $autoplayvideo;
136
137
    /**
138
     * Mute the video
139
     *
140
     * @var boolean
141
     */
142
    protected $mutevideo;
143
144
    /**
145
     * Loop the video
146
     *
147
     * @var boolean
148
     */
149
    protected $loopvideo;
150
151
    /**
152
     * Start time of the video (in s)
153
     *
154
     * @var integer
155
     */
156
    protected $videoStarttime;
157
158
    /**
159
     *
160
     * @var boolean
161
     */
162
    protected $controlsvideo;
163
164
    /**
165
     *
166
     * @var string
167
     */
168
    protected $youtube;
169
170
    /**
171
     * Returns the $title
172
     *
173
     * @return string
174
     */
175
    public function getTitle()
176
    {
177
        return $this->title;
178
    }
179
180
    /**
181
     * Set the title of the Video
182
     *
183
     * @param string $title the $title to set
184
     */
185
    public function setTitle($title)
186
    {
187
        $this->title = $title;
188
    }
189
190
    /**
191
     * Returns the $posterimage
192
     *
193
     * @return string
194
     */
195
    public function getPosterimage()
196
    {
197
        return $this->retrieveMediaUrl($this->posterimage);
198
    }
199
200
    /**
201
     * Set the posterimage of the Video
202
     *
203
     * @param string $posterimage the $posterimage to set
204
     */
205
    public function setPosterimage($posterimage)
206
    {
207
        $this->posterimage = $posterimage;
208
    }
209
210
    /**
211
     * Returns the $mp4source
212
     *
213
     * @return string
214
     */
215
    public function getMp4source()
216
    {
217
        return $this->retrieveMediaUrl($this->mp4source);
218
    }
219
220
    /**
221
     * Set the mp4source of the Video
222
     *
223
     * @param string $mp4source the $mp4source to set
224
     */
225
    public function setMp4source($mp4source)
226
    {
227
        $this->mp4source = $mp4source;
228
    }
229
230
    /**
231
     * Returns the $webmsource
232
     *
233
     * @return string
234
     */
235
    public function getWebmsource()
236
    {
237
        return $this->retrieveMediaUrl($this->webmsource);
238
    }
239
240
    /**
241
     * Set the webmsource of the Video
242
     *
243
     * @param string $webmsource the $webmsource to set
244
     */
245
    public function setWebmsource($webmsource)
246
    {
247
        $this->webmsource = $webmsource;
248
    }
249
250
    /**
251
     * Returns the $oggsource
252
     *
253
     * @return string
254
     */
255
    public function getOggsource()
256
    {
257
        return $this->retrieveMediaUrl($this->oggsource);
258
    }
259
260
    /**
261
     * Set the oggsource of the Video
262
     *
263
     * @param string $oggsource the $oggsource to set
264
     */
265
    public function setOggsource($oggsource)
266
    {
267
        $this->oggsource = $oggsource;
268
    }
269
270
    /**
271
     * Returns the $height
272
     *
273
     * @return string
274
     */
275
    public function getHeight()
276
    {
277
        return $this->height;
278
    }
279
280
    /**
281
     * Set the height of the Video
282
     *
283
     * @param string $height the $height to set
284
     */
285
    public function setHeight($height)
286
    {
287
        $this->height = $height;
288
    }
289
290
    /**
291
     * Returns the $width
292
     *
293
     * @return string
294
     */
295
    public function getWidth()
296
    {
297
        return $this->width;
298
    }
299
300
    /**
301
     * Set the width of the Video
302
     *
303
     * @param string $width the $width to set
304
     */
305
    public function setWidth($width)
306
    {
307
        $this->width = $width;
308
    }
309
310
    /**
311
     * Returns the $downloadlinks
312
     *
313
     * @return string
314
     */
315
    public function getDownloadlinks()
316
    {
317
        return $this->downloadlinks;
318
    }
319
320
    /**
321
     * Set the downloadlinks of the Video
322
     *
323
     * @param boolean $downloadlinks the $downloadlinks to set
324
     */
325
    public function setDownloadlinks($downloadlinks)
326
    {
327
        $this->downloadlinks = $downloadlinks;
328
    }
329
330
    /**
331
     * Returns the $supportvideojs
332
     *
333
     * @return string
334
     */
335
    public function getSupportvideojs()
336
    {
337
        return $this->supportvideojs;
338
    }
339
340
    /**
341
     * Set the supportvideojs of the Video
342
     *
343
     * @param boolean $supportvideojs the $supportvideojs to set
344
     */
345
    public function setSupportvideojs($supportvideojs)
346
    {
347
        $this->supportvideojs = $supportvideojs;
348
    }
349
350
    /**
351
     * Returns the $preloadvideo
352
     *
353
     * @return string
354
     */
355
    public function getPreloadvideo()
356
    {
357
        return $this->preloadvideo;
358
    }
359
360
    /**
361
     * Set the preloadvideo of the Video
362
     *
363
     * @param string $preloadvideo the $preloadvideo to set
364
     */
365
    public function setPreloadvideo($preloadvideo)
366
    {
367
        $this->preloadvideo = $preloadvideo;
368
    }
369
370
    /**
371
     * Returns the $autoplayvideo
372
     *
373
     * @return string
374
     */
375
    public function getAutoplayvideo()
376
    {
377
        return $this->autoplayvideo;
378
    }
379
380
    /**
381
     * Set the autoplayvideo of the Video
382
     *
383
     * @param boolean $autoplayvideo the $autoplayvideo to set
384
     */
385
    public function setAutoplayvideo($autoplayvideo)
386
    {
387
        $this->autoplayvideo = $autoplayvideo;
388
    }
389
390
    /**
391
     * @return int
392
     */
393
    public function getVideoStarttime()
394
    {
395
        return $this->videoStarttime;
396
    }
397
398
    /**
399
     * @param int $videoStarttime
400
     */
401
    public function setVideoStarttime($videoStarttime)
402
    {
403
        $this->videoStarttime = $videoStarttime;
404
    }
405
406
    /**
407
     *
408
     * @return boolean
409
     */
410
    public function getControlsvideo()
411
    {
412
        return (boolean)$this->controlsvideo;
413
    }
414
415
    /**
416
     *
417
     * @param boolean $controlsvideo
418
     */
419
    public function setControlsvideo($controlsvideo)
420
    {
421
        $this->controlsvideo = $controlsvideo;
422
    }
423
424
    /**
425
     *
426
     * @return string
427
     */
428
    public function getDescription()
429
    {
430
        return $this->description;
431
    }
432
433
    /**
434
     *
435
     * @param string $description
436
     */
437
    public function setDescription($description)
438
    {
439
        $this->description = $description;
440
    }
441
442
    /**
443
     * @param boolean $loopvideo
444
     */
445
    public function setLoopvideo($loopvideo)
446
    {
447
        $this->loopvideo = $loopvideo;
448
    }
449
450
    /**
451
     * @return boolean
452
     */
453
    public function getLoopvideo()
454
    {
455
        return (boolean)$this->loopvideo;
456
    }
457
458
    /**
459
     * Set the mute of the Video
460
     *
461
     * @param boolean $mutevideo
462
     */
463
    public function setMutevideo($mutevideo)
464
    {
465
        $this->mutevideo = $mutevideo;
466
    }
467
468
    /**
469
     * Returns the $mutevideo
470
     *
471
     * @return boolean
472
     */
473
    public function getMutevideo()
474
    {
475
        return (boolean)$this->mutevideo;
476
    }
477
478
    /**
479
     * Resolves the URL of an file
480
     *
481
     * @param $media
482
     *
483
     * @return null|string
484
     */
485
    protected function retrieveMediaUrl($media)
486
    {
487
        if (trim($media) === '') {
488
            return '';
489
        }
490
491
        // Quick-fix for the Vimeo api (add "?api=1" to the media address)
492
        if (strpos($media, 'vimeo.com') !== false) {
493
            $media = $media . '?api=1';
494
        }
495
496
        // Get the path relative to the page currently outputted
497
        if (substr($media, 0, 5) === "file:") {
498
            $fileUid = substr($media, 5);
499
500
            if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
501
                $fileObject = ResourceFactory::getInstance()
502
                    ->getFileObject($fileUid);
503
504
                if ($fileObject instanceof FileInterface) {
505
                    return $fileObject->getPublicUrl();
506
                }
507
            }
508
        }
509
510
        if (strpos($media, 't3://') !== false) {
511
            /** @var ContentObjectRenderer $contentObject */
512
            $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
513
            $contentObject->start([], '');
514
            $media = ltrim($contentObject->stdWrap(
515
                '',
516
                [
517
                    'typolink.' => [
518
                        'parameter' => $media,
519
                        'returnLast' => 'url'
520
                    ]
521
                ]
522
            ));
523
        }
524
525
        //
526
527
        if (is_file(PATH_site . $media)) {
528
            return $GLOBALS['TSFE']->tmpl->getFileName($media);
529
        }
530
531
        $mediaWizard = null;
532
        if (class_exists(\TYPO3\CMS\Mediace\MediaWizard\MediaWizardProviderManager::class)) {
533
            // 7.2
534
            $mediaWizard = \TYPO3\CMS\Mediace\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($media);
535
        } elseif (class_exists(\TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::class)) {
536
            // before 7.2
537
            $mediaWizard = \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($media);
538
        }
539
        if ($mediaWizard !== null) {
540
            $cObj = new ContentObjectRenderer();
541
            return $cObj->typoLink_URL([
542
                'parameter' => $mediaWizard->rewriteUrl($media)
543
            ]);
544
        }
545
546
        if (GeneralUtility::isValidUrl($media)) {
547
            // prevent "data:" and "javascript:" Resources! Whitelist!
548
            if (!in_array(parse_url($media, PHP_URL_SCHEME), ['http', 'https'])) {
549
                return '';
550
            }
551
            return $media;
552
        }
553
554
        throw new \Exception('You are running TYPO3 > CMS 7.2. Please install the mediace extension', 12367238462384);
555
    }
556
557
    /**
558
     * @param string $youtube
559
     */
560
    public function setYoutube($youtube)
561
    {
562
        $this->youtube = $youtube;
563
    }
564
565
    /**
566
     * @return string
567
     */
568
    public function getYoutube()
569
    {
570
        return $this->retrieveMediaUrl($this->youtube);
571
    }
572
573
    /**
574
     * @param string $vimeo
575
     */
576
    public function setVimeo($vimeo)
577
    {
578
        $this->vimeo = $vimeo;
579
    }
580
581
    /**
582
     * @return string
583
     */
584
    public function getVimeo()
585
    {
586
        return $this->retrieveMediaUrl($this->vimeo);
587
    }
588
589
    /**
590
     * @return int|string
591
     */
592
    public function getMinWidth()
593
    {
594
        $width = $this->getWidth();
595
        if (trim($width) !== '' &&
596
            (
597
                ((int)$width !== 0) || trim($width) === 'auto'
598
            )
599
        ) {
600
            return $width;
601
        }
602
603
        $default = Div::getConfigurationValue('generalMinWith');
604
        return (int)$default ?: 200;
605
    }
606
607
    /**
608
     * @return int|string
609
     */
610
    public function getMinHeight()
611
    {
612
        $height = $this->getHeight();
613
        if (trim($height) !== '' &&
614
            (
615
                ((int)$height !== 0) || trim($height) === 'auto'
616
            )
617
        ) {
618
            return $height;
619
        }
620
621
        $default = Div::getConfigurationValue('generalMinHeight');
622
        return (int)$default ?: 150;
623
    }
624
625
    /**
626
     * @return string
627
     */
628
    public function getTechOrder()
629
    {
630
        $return = '';
631
        if ($this->getYoutube() !== '') {
632
            $return .= '"youtube",';
633
        }
634
        if ($this->getVimeo() !== '') {
635
            $return .= '"vimeo",';
636
        }
637
        return $return . '"html5"';
638
    }
639
}
640