video.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* @class FLVideoModule
*/
class FLVideoModule extends FLBuilderModule {
/**
* @property $data
*/
public $data = null;
/**
* @method __construct
*/
public function __construct()
{
parent::__construct(array(
'name' => __('视频', 'fl-builder'),
'description' => __('Render a WordPress or embedable video.', 'fl-builder'),
'category' => __('高级模块', 'fl-builder'),
'partial_refresh' => true
));
$this->add_js('jquery-fitvids');
}
/**
* @method get_data
*/
public function get_data()
{
if(!$this->data) {
$this->data = FLBuilderPhoto::get_attachment_data($this->settings->video);
if(!$this->data && isset($this->settings->data)) {
$this->data = $this->settings->data;
}
if($this->data) {
$parts = explode('.', $this->data->filename);
$this->data->extension = array_pop($parts);
$this->data->poster = isset($this->settings->poster_src) ? $this->settings->poster_src : '';
$this->data->loop = isset($this->settings->loop) && $this->settings->loop ? ' loop="yes"' : '';
$this->data->autoplay = isset($this->settings->autoplay) && $this->settings->autoplay ? ' autoplay="yes"' : '';
// WebM format
$webm_data = FLBuilderPhoto::get_attachment_data($this->settings->video_webm);
$this->data->video_webm = isset($this->settings->video_webm) && $webm_data ? ' webm="'. $webm_data->url .'"' : '';
}
}
return $this->data;
}
/**
* @method update
* @param $settings {object}
*/
public function update($settings)
{
// Cache the attachment data.
if($settings->video_type == 'media_library') {
$video = FLBuilderPhoto::get_attachment_data($settings->video);
if($video) {
$settings->data = $video;
}
}
return $settings;
}
}
/**
* Register the module and its form settings.
*/
FLBuilder::register_module('FLVideoModule', array(
'general' => array(
'title' => __('General', 'fl-builder'),
'sections' => array(
'general' => array(
'title' => '',
'fields' => array(
'video_type' => array(
'type' => 'select',
'label' => __('Video Type', 'fl-builder'),
'default' => 'wordpress',
'options' => array(
'media_library' => __('Media Library', 'fl-builder'),
'embed' => __('Embed', 'fl-builder')
),
'toggle' => array(
'media_library' => array(
'fields' => array('video', 'video_webm', 'poster', 'autoplay', 'loop')
),
'embed' => array(
'fields' => array('embed_code')
)
)
),
'video' => array(
'type' => 'video',
'label' => __( 'Video (MP4)', 'fl-builder' ),
'help' => __('A video in the MP4 format. Most modern browsers support this format.', 'fl-builder'),
),
'video_webm' => array(
'type' => 'video',
'label' => __('Video (WebM)', 'fl-builder'),
'help' => __('A video in the WebM format to use as fallback. This format is required to support browsers such as FireFox and Opera.', 'fl-builder'),
'preview' => array(
'type' => 'none'
)
),
'poster' => array(
'type' => 'photo',
'label' => _x( 'Poster', 'Video preview/fallback image.', 'fl-builder' )
),
'autoplay' => array(
'type' => 'select',
'label' => __('Auto Play', 'fl-builder'),
'default' => '0',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
),
'loop' => array(
'type' => 'select',
'label' => __('Loop', 'fl-builder'),
'default' => '0',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
),
'embed_code' => array(
'type' => 'textarea',
'label' => __( 'Video Embed Code', 'fl-builder' ),
'rows' => '6'
)
)
)
)
)
));