|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Itstructure\MFUploader\helpers; |
|
4
|
|
|
|
|
5
|
|
|
use Itstructure\MFUploader\Module; |
|
6
|
|
|
use yii\helpers\{ArrayHelper, Html as BaseHtml}; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* HTML helper. |
|
10
|
|
|
* |
|
11
|
|
|
* @package Itstructure\MFUploader\helpers |
|
12
|
|
|
* |
|
13
|
|
|
* @author Andrey Girnik <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class Html extends BaseHtml |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Render html 5 audio tag structure. |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $src |
|
21
|
|
|
* @param array $options |
|
22
|
|
|
* |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function audio(string $src, array $options = []): string |
|
26
|
|
|
{ |
|
27
|
|
|
return self::getTag('audio', |
|
28
|
|
|
self::getMainOptions($options), |
|
29
|
|
|
self::getSourceOptions($src, $options), |
|
30
|
|
|
self::getTrackOptions($options) |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Render html 5 video tag structure. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $src |
|
38
|
|
|
* @param array $options |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function video(string $src, array $options = []): string |
|
43
|
|
|
{ |
|
44
|
|
|
return self::getTag('video', |
|
45
|
|
|
ArrayHelper::merge([ |
|
46
|
|
|
'height' => Module::ORIGINAL_PREVIEW_HEIGHT |
|
47
|
|
|
], self::getMainOptions($options)), |
|
48
|
|
|
self::getSourceOptions($src, $options), |
|
49
|
|
|
self::getTrackOptions($options) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get main options of the mediafile. |
|
55
|
|
|
* |
|
56
|
|
|
* @param array $options |
|
57
|
|
|
* |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
|
|
private static function getMainOptions(array $options = []): array |
|
61
|
|
|
{ |
|
62
|
|
|
$mainOptions = [ |
|
63
|
|
|
'controls' => 'controls', |
|
64
|
|
|
'width' => Module::ORIGINAL_PREVIEW_WIDTH, |
|
65
|
|
|
]; |
|
66
|
|
|
if (isset($options['main']) && is_array($options['main'])) { |
|
67
|
|
|
$mainOptions = ArrayHelper::merge($mainOptions, $options['main']); |
|
68
|
|
|
} |
|
69
|
|
|
return $mainOptions; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get source options of the mediafile. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $src |
|
76
|
|
|
* @param array $options |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
private static function getSourceOptions(string $src, array $options = []): array |
|
81
|
|
|
{ |
|
82
|
|
|
$sourceOptions = [ |
|
83
|
|
|
'src' => $src, |
|
84
|
|
|
'preload' => 'auto' |
|
85
|
|
|
]; |
|
86
|
|
|
if (isset($options['source']) && is_array($options['source'])) { |
|
87
|
|
|
$sourceOptions = ArrayHelper::merge($sourceOptions, $options['source']); |
|
88
|
|
|
} |
|
89
|
|
|
return $sourceOptions; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get track options of the mediafile. |
|
94
|
|
|
* |
|
95
|
|
|
* @param array $options |
|
96
|
|
|
* |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
|
|
private static function getTrackOptions(array $options = []): array |
|
100
|
|
|
{ |
|
101
|
|
|
$trackOptions = [ |
|
102
|
|
|
'kind' => 'subtitles' |
|
103
|
|
|
]; |
|
104
|
|
|
if (isset($options['track']) && is_array($options['track'])) { |
|
105
|
|
|
$trackOptions = ArrayHelper::merge($trackOptions, $options['track']); |
|
106
|
|
|
} |
|
107
|
|
|
return $trackOptions; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get tag of the mediafile. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $tagName |
|
114
|
|
|
* @param array $mainOptions |
|
115
|
|
|
* @param array $sourceOptions |
|
116
|
|
|
* @param array $trackOptions |
|
117
|
|
|
* |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
private static function getTag( |
|
121
|
|
|
string $tagName, |
|
122
|
|
|
array $mainOptions, |
|
123
|
|
|
array $sourceOptions, |
|
124
|
|
|
array $trackOptions): string { |
|
125
|
|
|
|
|
126
|
|
|
return static::tag( |
|
127
|
|
|
$tagName, |
|
128
|
|
|
static::tag('source', '', $sourceOptions) . static::tag('track', '', $trackOptions), |
|
129
|
|
|
$mainOptions |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|