-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfield.video_url.php
executable file
·174 lines (150 loc) · 5.67 KB
/
field.video_url.php
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
* PyroStreams Video URL Field Type
*
* @package PyroStreams
* @author Rigo B Castro
* @author Jose Luis Fonseca
* @team WeDreamPro
* @copyright Copyright (c) 2013, WeDreamPro
* @link https://www.pyrocms.com/store/details/video_url_field_type
*/
class Field_video_url {
public $field_type_slug = 'video_url';
public $db_col_type = 'text';
public $version = '1.2.1';
public $custom_parameters = array('video_heigth', 'video_width', 'video_autoplay');
public $author = array('name' => 'Rigo B Castro', 'url' => 'http://rigobcastro.com');
// --------------------------------------------------------------------------
/**
* Output form input
*
* @access public
* @param $params array
* @return string
*/
public function form_output($params) {
$video_info = !empty($params['value']) ? json_decode($params['value']) : null;
$input_options = array(
'name' => $params['form_slug'] . '_url',
'type' => 'text',
'id' => $params['form_slug'],
'data-fieldtype' => 'video_url',
'data-video-width' => !empty($params['video_width']) ? $params['video_width'] : '100%',
'data-video-height' => !empty($params['video_height']) ? $params['video_height'] : '100%',
'data-video-autoplay' => !empty($params['video_autoplay']) ? $params['video_autoplay'] : 0,
'value' => !empty($video_info->url) ? $video_info->url : null,
'placeholder' => lang('streams:video_url.input_placeholder')
);
$input_hidden_options = array(
$params['form_slug'] => $params['value']
);
return $this->CI->type->load_view('video_url', 'input', array(
'input_options' => $input_options,
'input_hidden_options' => $input_hidden_options
));
}
// ----------------------------------------------------------------------
/**
* Custom parameters
* @author Jose Fonseca <[email protected]>
*/
public function param_video_heigth($value = null) {
return array(
'input' => form_input('video_heigth', $value),
'instructions' => $this->CI->lang->line('streams.video_heigth.instructions')
);
}
public function param_video_width($value = null) {
return array(
'input' => form_input('video_width', $value),
'instructions' => $this->CI->lang->line('streams.video_width.instructions')
);
}
public function param_video_autoplay($value = null) {
$options = array(
'0' => $this->CI->lang->line('streams.video_width.no'),
'1' => $this->CI->lang->line('streams.video_width.yes')
);
return array(
'input' => form_dropdown('video_autoplay', $options, $value),
'instructions' => $this->CI->lang->line('streams.video_autoplay.instructions')
);
}
// --------------------------------------------------------------------------
/**
* Tag output variables
*
*
* @access public
* @param string
* @param array
* @return array
*/
public function pre_output($input, $params) {
if (!$input)
return null;
$data = json_decode($input);
/** define defaults * */
$height = 315;
$width = 560;
$source = $data->provider_name == 'Vimeo' ? "//player.vimeo.com/video/" . $data->video_id : "//youtube.com/embed/" . $data->video_id;
/** set options * */
if (!empty($params['video_heigth'])) {
$height = $params['video_heigth'];
}
if (!empty($params['video_width'])) {
$width = $params['video_width'];
}
if (!empty($params['video_autoplay'])) {
$source = $source . '?autoplay=1';
}
$iframe = '<iframe width="' . $width . '" src="' . $source . '" height="' . $height . '" frameborder="0" allowfullscreen></iframe>';
$data->html = $iframe;
$data->src = $this->_get_src($iframe);
return $data->html;
}
// ----------------------------------------------------------------------
public function pre_output_plugin($input, $params) {
if (!$input)
return null;
$data = json_decode($input);
/** define defaults * */
$height = 315;
$width = 560;
$source = $data->provider_name == 'Vimeo' ? "//player.vimeo.com/video/" . $data->video_id : "//youtube.com/embed/" . $data->video_id;
/** set options * */
if (!empty($params['video_heigth'])) {
$height = $params['video_heigth'];
}
if (!empty($params['video_width'])) {
$width = $params['video_width'];
}
if (!empty($params['video_autoplay'])) {
$source = $source . '?autoplay=1';
}
$iframe = '<iframe width="' . $width . '" src="' . $source . '" height="' . $height . '" frameborder="0" allowfullscreen></iframe>';
$data->html = $iframe;
$data->src = $this->_get_src($iframe);
return (array) $data;
}
// ----------------------------------------------------------------------
/**
* Event
*
* Load assets
*
* @access public
* @param $field object
* @return void
*/
public function event() {
$this->CI->type->add_js('video_url', 'video_url.js');
}
private function _get_src($iframe_string) {
$match = array();
preg_match('/src="([^"]+)"/', $iframe_string, $match);
return $match[1];
}
}