PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.6.5
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.6.5
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Includes / Classes / Feature_Enhancer.php
embedpress / EmbedPress / Includes / Classes Last commit date
Elementor_Enhancer.php 3 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 4 years ago EmbedPress_Plugin_Usage_Tracker.php 4 years ago Feature_Enhancer.php 3 years ago Helper.php 4 years ago
Feature_Enhancer.php
1386 lines
1 <?php
2
3 namespace EmbedPress\Includes\Classes;
4
5 use \EmbedPress\Providers\Youtube;
6 use EmbedPress\Shortcode;
7
8 class Feature_Enhancer
9 {
10 public static $attributes_data;
11
12 public function __construct()
13 {
14 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
15 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
16 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
17 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
18 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
19 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
20
21 add_filter(
22 'embedpress_gutenberg_youtube_params',
23 [$this, 'embedpress_gutenberg_register_block_youtube']
24 );
25 add_action('init', array($this, 'embedpress_gutenberg_register_block_vimeo'));
26 add_action('embedpress_gutenberg_wistia_block_after_embed', array($this, 'embedpress_wistia_block_after_embed'));
27 add_action('elementor/widget/embedpres_elementor/skins_init', [$this, 'elementor_setting_init']);
28 add_action('wp_ajax_youtube_rest_api', [$this, 'youtube_rest_api']);
29 add_action('wp_ajax_nopriv_youtube_rest_api', [$this, 'youtube_rest_api']);
30 add_action('embedpress_gutenberg_embed', [$this, 'gutenberg_embed'], 10, 2);
31
32 add_action('embedpress:isEmbra', [$this, 'isEmbra'], 10, 3);
33
34 }
35
36 public function isEmbra($isEmbra, $url, $atts)
37 {
38 if (strpos($url, 'youtube.com') !== false) {
39 $youtube = new Youtube($url, $atts);
40 if ($youtube->validateUrl($youtube->getUrl(false))) {
41 return true;
42 }
43 }
44 return $isEmbra;
45 }
46
47 public function youtube_rest_api()
48 {
49 $result = Youtube::get_gallery_page([
50 'playlistId' => isset($_POST['playlistid']) ? sanitize_text_field($_POST['playlistid']) : null,
51 'pageToken' => isset($_POST['pagetoken']) ? sanitize_text_field($_POST['pagetoken']) : null,
52 'pagesize' => isset($_POST['pagesize']) ? sanitize_text_field($_POST['pagesize']) : null,
53 'currentpage' => isset($_POST['currentpage']) ? sanitize_text_field($_POST['currentpage']) : null,
54 'columns' => isset($_POST['epcolumns']) ? sanitize_text_field($_POST['epcolumns']) : null,
55 'showTitle' => isset($_POST['showtitle']) ? sanitize_text_field($_POST['showtitle']) : null,
56 'showPaging' => isset($_POST['showpaging']) ? sanitize_text_field($_POST['showpaging']) : null,
57 'autonext' => isset($_POST['autonext']) ? sanitize_text_field($_POST['autonext']) : null,
58 'thumbplay' => isset($_POST['thumbplay']) ? sanitize_text_field($_POST['thumbplay']) : null,
59 'thumbnail_quality' => isset($_POST['thumbnail_quality']) ? sanitize_text_field($_POST['thumbnail_quality']) : null,
60 ]);
61
62 wp_send_json($result);
63 }
64
65
66 //Check is YouTube single video
67 public function ytValidateUrl(String $url)
68 {
69 return (bool) (preg_match('~v=(?:[a-z0-9_\-]+)~i', (string) $url));
70 }
71
72
73 //Check is Wistia validate url
74 public function wistiaValidateUrl(String $url)
75 {
76 return (bool) (preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', (string) $url ));
77 }
78
79 //Check is Wistia validate url
80 public function vimeoValidateUrl(String $url)
81 {
82 return (bool)preg_match('/https?:\/\/(www\.)?vimeo\.com\/\d+/', (string) $url);
83 }
84
85
86
87 // Get wistia block attributes
88 public function get_wistia_block_attributes($attributes) {
89
90 // Embed Options
91 $embedOptions = new \stdClass;
92 $embedOptions->videoFoam = false;
93 $embedOptions->fullscreenButton = (isset($attributes['wfullscreen']) && (bool) $attributes['wfullscreen'] === true);
94 $embedOptions->playbar = (isset($attributes['playbar']) && (bool) $attributes['playbar'] === true);
95
96 $embedOptions->playButton = (isset($attributes['playbutton']) && (bool) $attributes['playbutton'] === true);
97 $embedOptions->smallPlayButton = (isset($attributes['smallplaybutton']) && (bool) $attributes['smallplaybutton'] === true);
98
99 $embedOptions->autoPlay = (isset($attributes['wautoplay']) && (bool) $attributes['wautoplay'] === true);
100 $embedOptions->resumable = (isset($attributes['resumable']) && (bool) $attributes['resumable'] === true);
101
102 $embedOptions->time = isset($attributes['wstarttime']) ? $attributes['wstarttime'] : '';
103
104 if ( is_embedpress_pro_active() ) {
105 $embedOptions->volumeControl = (isset($attributes['volumecontrol']) && (bool) $attributes['volumecontrol'] === true);
106
107 $volume = isset($attributes['volume']) ? (float) $attributes['volume'] : 0;
108
109 if ( $volume > 1 ) {
110 $volume = $volume / 100;
111 }
112 $embedOptions->volume = $volume;
113 }
114
115 $pluginList = [];
116
117 if (isset($attributes['scheme'])) {
118 $color = $attributes['scheme'];
119 if (null !== $color) {
120 $embedOptions->playerColor = $color;
121 }
122 }
123
124 // Closed Captions plugin
125 if ( $attributes['captions'] === true ) {
126 $isCaptionsEnabled = ( $attributes['captions'] === true );
127 $isCaptionsEnabledByDefault = ( $attributes['captions'] === true );
128 if ( $isCaptionsEnabled ) {
129 $pluginList['captions-v1'] = [
130 'onByDefault' => $isCaptionsEnabledByDefault,
131 ];
132 }
133 $embedOptions->captions = $isCaptionsEnabled;
134 $embedOptions->captionsDefault = $isCaptionsEnabledByDefault;
135 }
136
137 $embedOptions->plugin = $pluginList;
138
139
140
141 return json_encode($embedOptions);
142 }
143
144 public function gutenberg_embed($embedHTML, $attributes)
145 {
146
147 if (!empty($attributes['url'])) {
148 $youtube = new Youtube($attributes['url']);
149
150 $is_youtube = $youtube->validateUrl($youtube->getUrl(false));
151 if ($is_youtube) {
152 $atts = [
153 'width' => intval($attributes['width']),
154 'height' => intval($attributes['height']),
155 'pagesize' => isset($attributes['pagesize']) ? intval($attributes['pagesize']) : 6,
156 'columns' => isset($attributes['columns']) ? intval($attributes['columns']) : 3,
157 'ispagination' => isset($attributes['ispagination']) ? $attributes['ispagination'] : 0,
158 'gapbetweenvideos' => isset($attributes['gapbetweenvideos']) ? $attributes['gapbetweenvideos'] : 30,
159 ];
160
161 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
162
163 if (!empty($urlInfo->embed)) {
164 $embedHTML = $urlInfo->embed;
165 }
166 }
167
168 if($this->ytValidateUrl($attributes['url'])){
169
170 $atts = [
171 'url' => $attributes['url'],
172 'starttime' => !empty($attributes['starttime']) ? $attributes['starttime'] : '',
173 'endtime' => !empty($attributes['endtime']) ? $attributes['endtime'] : '',
174 'autoplay' => !empty($attributes['autoplay']) ? 1 : 0,
175 'controls' => isset($attributes['controls']) ? $attributes['controls'] : '1',
176 'fullscreen' => !empty($attributes['fullscreen']) ? 1 : 0,
177 'videoannotations' => !empty($attributes['videoannotations']) ? 1 : 0,
178 'progressbarcolor' => !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red',
179 'closedcaptions' => !empty($attributes['closedcaptions']) ? 1 : 0,
180 'modestbranding' => !empty($attributes['modestbranding']) ? $attributes['modestbranding'] : '',
181 'relatedvideos' => !empty($attributes['relatedvideos']) ? 1 : 0,
182 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
183 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
184 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
185 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
186 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
187 ];
188
189 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
190
191 if (!empty($urlInfo->embed)) {
192 $embedHTML = $urlInfo->embed;
193 }
194
195 if(isset( $urlInfo->embed ) && preg_match( '/src=\"(.+?)\"/', $urlInfo->embed, $match )){
196 $url_full = $match[1];
197 $query = parse_url( $url_full, PHP_URL_QUERY );
198 parse_str( $query, $params );
199
200 $params['controls'] = isset($attributes['controls']) ? $attributes['controls']: '1';
201 $params['iv_load_policy'] = !empty($attributes['videoannotations']) ? 1 : 0;
202 $params['fs'] = !empty($attributes['fullscreen']) ? 1 : 0;
203 $params['rel'] = !empty($attributes['relatedvideos']) ? 1 : 0;
204 $params['end'] = !empty($attributes['endtime']) ? $attributes['endtime'] : '';
205 $params['autoplay'] = !empty($attributes['autoplay']) ? 1 : 0;
206 $params['start'] = !empty($attributes['starttime']) ? $attributes['starttime'] : '';
207 $params['color'] = !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red';
208 $params['modestbranding'] = empty($attributes['modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
209 $params['cc_load_policy'] = !empty($attributes['closedcaptions']) ? 0 : 1;
210
211 preg_match( '/(.+)?\?/', $url_full, $url );
212
213 if ( empty( $url) ) {
214 return $embedHTML;
215 }
216
217 $url = $url[1];
218
219 // Reassemble the url with the new variables.
220 $url_modified = $url . '?';
221
222 foreach ( $params as $paramName => $paramValue ) {
223
224 $and = '&';
225 if(array_key_last($params) === $paramName){
226 $and = '';
227 }
228
229 if(isset($paramValue) && $paramValue !== ''){
230 $url_modified .= $paramName . '=' . $paramValue . $and;
231 }
232 }
233
234 // Replaces the old url with the new one.
235 $embedHTML = str_replace( $url_full, rtrim( $url_modified, '&' ), $urlInfo->embed );
236
237 }
238
239 }
240
241 }
242
243 if (!empty($attributes['url']) && $this->wistiaValidateUrl($attributes['url'])) {
244
245
246 $embedOptions = $this->get_wistia_block_attributes($attributes);
247
248 // Get the video ID
249 $videoId = $this->getVideoIDFromURL($attributes['url']);
250 $shortVideoId = substr($videoId, 0, 3);
251
252 // Responsive?
253
254 $class = array(
255 'wistia_embed',
256 'wistia_async_' . $videoId
257 );
258
259 $attribs = array(
260 sprintf('id="wistia_%s"', $videoId),
261 sprintf('class="%s"', join(' ', $class)),
262 sprintf('style="width:%spx; height:%spx;"', $attributes['width'], $attributes['height'])
263 );
264
265 $labels = array(
266 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
267 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
268 'you_have_watched_it_before' => __(
269 'It looks like you\'ve watched<br />part of this video before!',
270 'embedpress'
271 ),
272 );
273 $labels = json_encode($labels);
274
275 preg_match('/ose-uid-([a-z0-9]*)/', $attributes['embedHTML'], $matches);
276 $uid = $matches[1];
277
278 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
279 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
280 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
281 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
282 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
283 $html .= '</div>';
284 $embedHTML = $html;
285 }
286
287 if(!empty($attributes['url']) && $this->vimeoValidateUrl($attributes['url'])){
288 $atts = [
289 'url' => $attributes['url'],
290 'vstarttime' => !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '',
291 'vscheme' => !empty($attributes['vscheme']) ? $attributes['vscheme'] : 'red',
292 'vautoplay' => !empty($attributes['vautoplay']) ? 1 : 0,
293 'vtitle' => !empty($attributes['vtitle']) ? 1 : 0,
294 'vauthor' => !empty($attributes['vauthor']) ? 1 : 0,
295 'vavatar' => !empty($attributes['vavatar']) ? 1 : 0,
296 'vautopause' => !empty($attributes['vautopause']) ? 1 : 0,
297 'vdnt' => !empty($attributes['vdnt']) ? 1 : 0,
298 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
299 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
300 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
301 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
302 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
303 ];
304
305 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
306
307 if (!empty($urlInfo->embed)) {
308 $embedHTML = $urlInfo->embed;
309 }
310
311 if(isset( $urlInfo->embed ) && preg_match( '/src=\"(.+?)\"/', $urlInfo->embed, $match )){
312 $url_full = $match[1];
313 $query = parse_url( $url_full, PHP_URL_QUERY );
314 parse_str( $query, $params );
315
316
317 unset($params['amp;dnt']);
318
319 $params['title'] = !empty($attributes['vtitle']) ? 1 : 0;
320 $params['byline'] = !empty($attributes['vauthor']) ? 1 : 0;
321 $params['portrait'] = !empty($attributes['vavatar']) ? 1 : 0;
322 $params['autoplay'] = !empty($attributes['vautoplay']) ? 1 : 0;
323 $params['loop'] = !empty($attributes['vloop']) ? 1 : 0;
324 $params['autopause'] = !empty($attributes['vautopause']) ? 1 : 0;
325 if(empty($attributes['vautopause'])) :
326 $params['dnt'] = !empty($attributes['vdnt']) ? 1 : 0;
327 endif;
328 $params['color'] = !empty($attributes['vscheme']) ? str_replace("#", "", $attributes['vscheme']) : '00ADEF';
329
330 if(!empty($attributes['vstarttime'])) :
331 $params['t'] = !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '';
332 endif;
333
334 preg_match( '/(.+)?\?/', $url_full, $url );
335
336 if ( empty( $url) ) {
337 return $embedHTML;
338 }
339
340 $url = $url[1];
341
342 // Reassemble the url with the new variables.
343 $url_modified = $url . '?';
344
345 // print_r($url_modified);
346
347
348
349 foreach ($params as $param => $value) {
350 $url_modified = add_query_arg($param, $value, $url_modified);
351 }
352
353 $url_modified = str_replace("&t=", "#t=", $url_modified);
354
355 // Replaces the old url with the new one.
356 $embedHTML = str_replace( $url_full, rtrim( $url_modified, '&' ), $urlInfo->embed );
357
358 }
359 }
360
361 return $embedHTML ;
362 }
363
364
365 public function elementor_setting_init()
366 {
367 $this->remove_classic_filters();
368 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'youtube'], 10, 2);
369 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'wistia'], 10, 2);
370 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'twitch'], 10, 2);
371 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'soundcloud'], 10, 2);
372 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'dailymotion'], 10, 2);
373 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'spotify'], 10, 2);
374 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'vimeo'], 10, 2);
375 }
376 public function remove_classic_filters()
377 {
378 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
379 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
380 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
381 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
382 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
383 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
384 }
385 public function getOptions($provider = '', $schema = [])
386 {
387 $options = (array) get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
388 if (empty($options) || (count($options) === 1 && empty($options[0]))) {
389 $options = [];
390
391 foreach ($schema as $fieldSlug => $field) {
392 $value = isset($field['default']) ? $field['default'] : "";
393
394 settype($value, isset($field['type']) && in_array(
395 strtolower($field['type']),
396 ['bool', 'boolean', 'int', 'integer', 'float', 'string']
397 ) ? $field['type'] : 'string');
398
399 if ($fieldSlug === "license_key") {
400 $options['license'] = [
401 'key' => true,
402 'status' => "missing",
403 ];
404 } else {
405 $options[$fieldSlug] = $value;
406 }
407 }
408 }
409
410 $options['license'] = [
411 'key' => true,
412 'status' => "missing",
413 ];
414 return apply_filters('emebedpress_get_options', $options);
415 }
416
417 public function get_youtube_params($options)
418 {
419 $params = [];
420
421 // Handle `autoplay` option.
422 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
423 $params['autoplay'] = 1;
424 } else {
425 unset($params['autoplay']);
426 }
427
428 // Handle `controls` option.
429 if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) {
430 $params['controls'] = (int) $options['controls'];
431 } else {
432 unset($params['controls']);
433 }
434
435 // Handle `fs` option.
436 if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) {
437 $params['fs'] = (int) $options['fs'];
438 } else {
439 unset($params['fs']);
440 }
441
442 // Handle `iv_load_policy` option.
443 if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) {
444 $params['iv_load_policy'] = (int) $options['iv_load_policy'];
445 } else {
446 unset($params['iv_load_policy']);
447 }
448
449 return apply_filters('embedpress_youtube_params', $params);
450 }
451
452 public function get_vimeo_params($options)
453 {
454 $params = [];
455
456 // Handle `display_title` option.
457 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
458 $params['title'] = 1;
459 } else {
460 $params['title'] = 0;
461 }
462
463 // Handle `autoplay` option.
464 if (!empty($options['autoplay'])) {
465 $params['autoplay'] = 1;
466 } else {
467 unset($params['autoplay']);
468 }
469
470 // Handle `color` option.
471 if (!empty($options['color'])) {
472 $params['color'] = str_replace('#', '', $options['color']);
473 } else {
474 unset($params['color']);
475 }
476 return apply_filters('embedpress_vimeo_params', $params);
477 }
478
479 //--- For CLASSIC AND BLOCK EDITOR
480 public function enhance_youtube($embed)
481 {
482
483
484 $isYoutube = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'YOUTUBE') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'YOUTUBE');
485
486 if (
487 $isYoutube && isset($embed->embed)
488 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
489 ) {
490
491 // for compatibility only, @TODO; remove later after deep testing.
492 $options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
493
494 // Parse the url to retrieve all its info like variables etc.
495 $url_full = $match[1];
496 $query = parse_url($url_full, PHP_URL_QUERY);
497 parse_str($query, $params);
498 // Handle `color` option.
499 if (!empty($options['color'])) {
500 $params['color'] = $options['color'];
501 } else {
502 unset($params['color']);
503 }
504 // Handle `rel` option.
505 if (isset($options['rel']) && in_array((int) $options['rel'], [0, 1])) {
506 $params['rel'] = (int) $options['rel'];
507 } else {
508 unset($params['rel']);
509 }
510
511 // Handle `autoplay` option.
512 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
513 $params['autoplay'] = 1;
514 } else {
515 unset($params['autoplay']);
516 }
517
518 // Handle `controls` option.
519 if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) {
520 $params['controls'] = (int) $options['controls'];
521 } else {
522 unset($params['controls']);
523 }
524 if (isset($options['start_time'])) {
525 $params['start'] = $options['start_time'];
526 } else {
527 unset($params['start']);
528 }
529 if (isset($options['end_time'])) {
530 $params['end'] = $options['end_time'];
531 } else {
532 unset($params['end']);
533 }
534
535 // Handle `fs` option.
536 if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) {
537 $params['fs'] = (int) $options['fs'];
538 } else {
539 unset($params['fs']);
540 }
541
542 // Handle `iv_load_policy` option.
543 if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) {
544 $params['iv_load_policy'] = (int) $options['iv_load_policy'];
545 } else {
546 unset($params['iv_load_policy']);
547 }
548
549 // pro controls will be handled by the pro so remove it from the free.
550 $pro_controls = ['cc_load_policy', 'modestbranding'];
551 foreach ($pro_controls as $pro_control) {
552 if (isset($params[$pro_control])) {
553 unset($params[$pro_control]);
554 }
555 }
556
557 preg_match('/(.+)?\?/', $url_full, $url);
558 $url = $url[1];
559
560 if(is_object($embed->attributes) && !empty($embed->attributes)){
561 $attributes = (array) $embed->attributes;
562
563 $params['controls'] = isset($attributes['data-controls']) ? $attributes['data-controls'] : '1';
564 $params['iv_load_policy'] = !empty($attributes['data-videoannotations']) && ($attributes['data-videoannotations'] == 'true') ? 1 : 0;
565 $params['fs'] = !empty($attributes['data-fullscreen']) && ($attributes['data-fullscreen'] == 'true') ? 1 : 0;
566 $params['rel'] = !empty($attributes['data-relatedvideos']) && ($attributes['data-relatedvideos'] == 'true') ? 1 : 0;
567 $params['end'] = !empty($attributes['data-endtime']) ? $attributes['data-endtime'] : '';
568 $params['autoplay'] = !empty($attributes['data-autoplay']) && ($attributes['data-autoplay'] == 'true') ? 1 : 0;
569 $params['start'] = !empty($attributes['data-starttime']) ? $attributes['data-starttime'] : '';
570 $params['color'] = !empty($attributes['data-progressbarcolor']) ? $attributes['data-progressbarcolor'] : 'red';
571 $params['modestbranding'] = empty($attributes['data-modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
572 $params['cc_load_policy'] = !empty($attributes['data-closedcaptions']) && ($attributes['data-closedcaptions'] == 'true') ? 0 : 1;
573 }
574
575 // Reassemble the url with the new variables.
576 $url_modified = $url . '?';
577 foreach ($params as $paramName => $paramValue) {
578 $url_modified .= $paramName . '=' . $paramValue . '&';
579 }
580
581 // Replaces the old url with the new one.
582 $embed->embed = str_replace($url_full, rtrim($url_modified, '&'), $embed->embed);
583 }
584
585 return $embed;
586 }
587
588 public function enhance_vimeo($embed)
589 {
590
591
592 if (
593 isset($embed->provider_name)
594 && strtoupper($embed->provider_name) === 'VIMEO'
595 && isset($embed->embed)
596 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
597 ) {
598 // old schema is for backward compatibility only @todo; remove it in the next version after deep test
599 $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
600
601 $url_full = $match[1];
602 $params = [];
603
604 // Handle `display_title` option.
605 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
606 $params['title'] = 1;
607 } else {
608 $params['title'] = 0;
609 }
610
611 // Handle `autoplay` option.
612 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
613 $params['autoplay'] = 1;
614 } else {
615 unset($params['autoplay']);
616 }
617
618 // Handle `color` option.
619 if (!empty($options['color'])) {
620 $params['color'] = str_replace('#', '', $options['color']);
621 } else {
622 unset($params['color']);
623 }
624 // Handle `display_author` option.
625 if (isset($options['display_author']) && (bool) $options['display_author'] === true) {
626 $params['byline'] = 1;
627 } else {
628 $params['byline'] = 0;
629 }
630
631 // Handle `display_avatar` option.
632 if (isset($options['display_avatar']) && (bool) $options['display_avatar'] === true) {
633 $params['portrait'] = 1;
634 } else {
635 $params['portrait'] = 0;
636 }
637
638 // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only
639 //@todo; maybe extract unsetting pro vars to a function later
640 $pro_controls = ['loop', 'autopause', 'dnt',];
641 foreach ($pro_controls as $pro_control) {
642 if (isset($params[$pro_control])) {
643 unset($params[$pro_control]);
644 }
645 }
646
647 if(!empty($params['autopause'])){
648 unset($params['dnt']);
649 unset($params['amp;dnt']);
650 }
651
652 // Reassemble the url with the new variables.
653 $url_modified = str_replace("&amp;dnt=1", "", $url_full);
654
655 if(is_object($embed->attributes) && !empty($embed->attributes)){
656 $attributes = (array) $embed->attributes;
657 $attributes = stringToBoolean($attributes);
658
659 $params['title'] = !empty($attributes['data-vtitle']) ? 1 : 0;
660 $params['byline'] = !empty($attributes['data-vauthor']) ? 1 : 0;
661 $params['portrait'] = !empty($attributes['data-vavatar']) ? 1 : 0;
662 $params['autoplay'] = !empty($attributes['data-vautoplay']) ? 1 : 0;
663 $params['loop'] = !empty($attributes['data-vloop']) ? 1 : 0;
664 $params['autopause'] = !empty($attributes['data-vautopause']) ? 1 : 0;
665 if(empty($attributes['data-vautopause'])) :
666 $params['dnt'] = !empty($attributes['data-vdnt']) ? 1 : 0;
667 endif;
668 $params['color'] = !empty($attributes['data-vscheme']) ? str_replace("#", "", $attributes['data-vscheme']) : '00ADEF';
669
670 if(!empty($attributes['data-vstarttime'])) :
671 $params['t'] = !empty($attributes['data-vstarttime']) ? $attributes['data-vstarttime'] : '';
672 endif;
673
674 foreach ($params as $param => $value) {
675 $url_modified = add_query_arg($param, $value, $url_modified);
676 }
677
678 $url_modified = str_replace("&t=", "#t=", $url_modified);
679
680 }
681 else{
682 foreach ($params as $param => $value) {
683 $url_modified = add_query_arg($param, $value, $url_modified);
684 }
685
686 if (empty($attributes['data-vstarttime']) && isset($options['start_time'])) {
687 $url_modified .= '#t=' . $options['start_time'];
688 }
689 }
690
691 do_action('embedpress_after_modified_url', $url_modified, $url_full, $params);
692
693 // Replaces the old url with the new one.
694 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
695
696 }
697
698 return $embed;
699 }
700
701 public function enhance_wistia($embed)
702 {
703
704 if (
705 isset($embed->provider_name)
706 && strtoupper($embed->provider_name) === 'WISTIA, INC.'
707 && isset($embed->embed)
708 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
709 ) {
710 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
711
712 $url_full = $match[1];
713
714 // Parse the url to retrieve all its info like variables etc.
715 $query = parse_url($embed->url, PHP_URL_QUERY);
716 $url = str_replace('?' . $query, '', $url_full);
717
718 parse_str($query, $params);
719
720 // Set the class in the attributes
721 $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class);
722 $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed);
723
724
725 // Embed Options
726 $embedOptions = new \stdClass;
727 $embedOptions->videoFoam = false;
728 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
729 $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true);
730
731 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
732
733 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
734
735 $embedOptions->time = isset($options['start_time']) ? $options['start_time'] : 0;
736
737 if (isset($options['player_color'])) {
738 $color = $options['player_color'];
739 if (null !== $color) {
740 $embedOptions->playerColor = $color;
741 }
742 }
743
744 // Plugins
745 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
746
747 $pluginList = array();
748
749 // Resumable
750 if (isset($options['plugin_resumable'])) {
751 $isResumableEnabled = $options['plugin_resumable'];
752 if ($isResumableEnabled) {
753 // Add the resumable plugin
754 $pluginList['resumable'] = array(
755 'src' => $pluginsBaseURL . '/resumable.min.js',
756 'async' => false
757 );
758 }
759 }
760
761 // Add a fix for the autoplay and resumable work better together
762 if (isset($options->autoPlay)) {
763 if ($isResumableEnabled) {
764 $pluginList['fixautoplayresumable'] = array(
765 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
766 );
767 }
768 }
769
770 // Focus plugin
771 if (isset($options['plugin_focus'])) {
772 $isFocusEnabled = $options['plugin_focus'];
773 $pluginList['dimthelights'] = array(
774 'src' => $pluginsBaseURL . '/dimthelights.min.js',
775 'autoDim' => $isFocusEnabled
776 );
777 $embedOptions->focus = $isFocusEnabled;
778 }
779
780 // Rewind plugin
781 if (isset($options['plugin_rewind'])) {
782 if ($options['plugin_rewind']) {
783 $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10;
784
785 $pluginList['rewind'] = array(
786 'src' => $pluginsBaseURL . '/rewind.min.js'
787 );
788 }
789 }
790 $embedOptions->plugin = $pluginList;
791
792 $embedOptions = json_encode($embedOptions);
793
794 // Get the video ID
795 $videoId = $this->getVideoIDFromURL($embed->url);
796 $shortVideoId = substr($videoId, 0, 3);
797
798 // Responsive?
799
800 $class = array(
801 'wistia_embed',
802 'wistia_async_' . $videoId
803 );
804
805 $attribs = array(
806 sprintf('id="wistia_%s"', $videoId),
807 sprintf('class="%s"', join(' ', $class)),
808 sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height)
809 );
810
811 $labels = array(
812 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
813 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
814 'you_have_watched_it_before' => __(
815 'It looks like you\'ve watched<br />part of this video before!',
816 'embedpress'
817 ),
818 );
819 $labels = json_encode($labels);
820
821 preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches);
822 $uid = $matches[1];
823
824 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
825 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
826 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
827 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
828 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
829 $html .= '</div>';
830 $embed->embed = $html;
831 }
832
833 return $embed;
834 }
835
836 public function enhance_twitch($embed_content)
837 {
838 $e = isset($embed_content->url) && isset($embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : [];
839 if (isset($e['provider_name']) && strtoupper($e['provider_name']) === 'TWITCH' && isset($embed_content->embed)) {
840 $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema());
841
842 $atts = isset($embed_content->attributes) ? $embed_content->attributes : [];
843 $time = '0h0m0s';
844 $type = $e['type'];
845 $content_id = $e['content_id'];
846 $channel = 'channel' === $type ? $content_id : '';
847 $video = 'video' === $type ? $content_id : '';
848 $muted = ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true' : 'false';
849 $full_screen = ('yes' === $settings['embedpress_pro_fs']) ? 'true' : 'false';
850 $autoplay = ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true' : 'false';
851 $theme = !empty($settings['embedpress_pro_twitch_theme']) ? $settings['embedpress_pro_twitch_theme'] : 'dark';
852
853 $layout = 'video';
854 $width = !empty($atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800;
855 $height = !empty($atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450;
856 if (!empty($settings['start_time'])) {
857 $ta = explode(':', gmdate("G:i:s", $settings['start_time']));
858 $h = $ta[0] . 'h';
859 $m = ($ta[1] * 1) . 'm';
860 $s = ($ta[2] * 1) . 's';
861 $time = $h . $m . $s;
862 }
863 $url = "https://embed.twitch.tv?autoplay={$autoplay}&channel={$channel}&height={$height}&layout={$layout}&migration=true&muted={$muted}&theme={$theme}&time={$time}&video={$video}&width={$width}&allowfullscreen={$full_screen}";
864 $pars_url = wp_parse_url(get_site_url());
865 $url = !empty($pars_url['host']) ? $url . '&parent=' . $pars_url['host'] : $url;
866 ob_start();
867 ?>
868 <div class="embedpress_wrapper" data-url="<?php echo esc_attr(esc_url($embed_content->url)); ?>">
869 <iframe src="<?php echo esc_url($url); ?>" allowfullscreen="" scrolling="no" frameborder="0" allow="autoplay; fullscreen" title="Twitch" sandbox="allow-modals allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" width="<?php echo esc_attr($width); ?>" height="<?php echo esc_attr($height); ?>" style="max-width: <?php echo esc_attr($width); ?>px; max-height:<?php echo esc_attr($height); ?>px;"></iframe>
870 </div>
871 <?php
872 $c = ob_get_clean();
873 $embed_content->embed = $c;
874 }
875
876 return $embed_content;
877 }
878 public function enhance_dailymotion($embed)
879 {
880 $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema());
881 $isDailymotion = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'DAILYMOTION') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'DAILYMOTION');
882
883 if (
884 $isDailymotion && isset($embed->embed)
885 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
886 ) {
887 // Parse the url to retrieve all its info like variables etc.
888 $url_full = $match[1];
889 $params = [
890 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null),
891 'mute' => (int) isset($options['mute']) ? $options['mute'] : null,
892 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null,
893 'controls' => (int) isset($options['controls']) ? $options['controls'] : null,
894 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null,
895 'endscreen-enable' => 0,
896 ];
897
898 if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') {
899 $params['playsinline'] = 1;
900 }
901 $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null;
902 if (is_embedpress_pro_active()) {
903 $params['ui-logo'] = (int) isset($options['show_logo']) ? $options['show_logo'] : null;
904 }
905
906 $url_modified = $url_full;
907 foreach ($params as $param => $value) {
908 $url_modified = add_query_arg($param, $value, $url_modified);
909 }
910 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
911 }
912
913 return $embed;
914 }
915 public function enhance_soundcloud($embed)
916 {
917
918 $isSoundcloud = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'SOUNDCLOUD') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'SOUNDCLOUD');
919
920 if (
921 $isSoundcloud && isset($embed->embed)
922 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
923 ) {
924 $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema());
925 // Parse the url to retrieve all its info like variables etc.
926 $url_full = $match[1];
927 $params = [
928 'color' => str_replace('#', '', $options['color']),
929 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false',
930 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false',
931 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false',
932 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false',
933 'buying' => 'false',
934 'download' => 'false',
935 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false',
936 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false',
937 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false',
938 ];
939
940 if (is_embedpress_pro_active()) {
941 $params['buying'] = isset($options['buy_button']) && $options['buy_button'] == '1' ? 'true' : 'false';
942 $params['download'] = isset($options['download_button']) && $options['download_button'] == '1' ? 'true' : 'false';
943 }
944
945 $url_modified = $url_full;
946 foreach ($params as $param => $value) {
947 $url_modified = add_query_arg($param, $value, $url_modified);
948 }
949
950 // Replaces the old url with the new one.
951 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
952 if ('false' === $params['visual']) {
953 $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed);
954 }
955 }
956
957 return $embed;
958 }
959 public function embedpress_gutenberg_register_block_youtube($youtube_params)
960 {
961 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
962 return $this->get_youtube_params($youtube_options);
963 }
964 public function embedpress_gutenberg_register_block_vimeo()
965 {
966 if (function_exists('register_block_type')) :
967 register_block_type('embedpress/vimeo-block', array(
968 'attributes' => array(
969 'url' => array(
970 'type' => 'string',
971 'default' => ''
972 ),
973 'iframeSrc' => array(
974 'type' => 'string',
975 'default' => ''
976 ),
977 ),
978 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo']
979 ));
980 endif;
981 }
982 public function embedpress_gutenberg_render_block_vimeo($attributes)
983 {
984 ob_start();
985 if (!empty($attributes) && !empty($attributes['iframeSrc'])) :
986 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
987 $vimeo_params = $this->get_vimeo_params($vimeo_options);
988 $iframeUrl = $attributes['iframeSrc'];
989 $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center');
990 foreach ($vimeo_params as $param => $value) {
991 $iframeUrl = add_query_arg($param, $value, $iframeUrl);
992 }
993 //@TODO; test responsive without static height width, keeping for now backward compatibility
994 ?>
995 <div class="ose-vimeo wp-block-embed-vimeo <?php echo $align; ?>">
996 <iframe src="<?php echo $iframeUrl; ?>" allowtransparency="true" frameborder="0" width="640" height="360">
997 </iframe>
998 </div>
999 <?php
1000 endif;
1001
1002 return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean());
1003 }
1004 public function get_youtube_settings_schema()
1005 {
1006 return [
1007 'autoplay' => [
1008 'type' => 'bool',
1009 'default' => false
1010 ],
1011 'color' => [
1012 'type' => 'string',
1013 'default' => 'red'
1014 ],
1015 'cc_load_policy' => [
1016 'type' => 'bool',
1017 'default' => false
1018 ],
1019 'controls' => [
1020 'type' => 'string',
1021 'default' => '1'
1022 ],
1023 'fs' => [
1024 'type' => 'bool',
1025 'default' => true
1026 ],
1027 'iv_load_policy' => [
1028 'type' => 'radio',
1029 'default' => '1'
1030 ],
1031 'rel' => [
1032 'type' => 'bool',
1033 'default' => true
1034 ],
1035 'modestbranding' => [
1036 'type' => 'string',
1037 'default' => '0'
1038 ],
1039 'logo_url' => [
1040 'type' => 'url',
1041 ],
1042 'logo_xpos' => [
1043 'type' => 'number',
1044 'default' => 10
1045 ],
1046 'logo_ypos' => [
1047 'type' => 'number',
1048 'default' => 10
1049 ],
1050 'cta_url' => [
1051 'type' => 'url',
1052 ],
1053 'start_time' => [
1054 'type' => 'number',
1055 'default' => 10
1056 ],
1057 'end_time' => [
1058 'type' => 'number',
1059 'default' => 10
1060 ],
1061 ];
1062 }
1063 public function get_vimeo_settings_schema()
1064 {
1065 return array(
1066 'start_time' => [
1067 'type' => 'number',
1068 'default' => 10
1069 ],
1070 'autoplay' => array(
1071 'type' => 'bool',
1072 'default' => false
1073 ),
1074 'loop' => array(
1075 'type' => 'bool',
1076 'default' => false
1077 ),
1078 'autopause' => array(
1079 'type' => 'bool',
1080 'default' => false
1081 ),
1082 'vimeo_dnt' => array(
1083 'type' => 'bool',
1084 'default' => true,
1085 ),
1086 'color' => array(
1087 'type' => 'text',
1088 'default' => '#00adef',
1089 'classes' => 'color-field'
1090 ),
1091 'display_title' => array(
1092 'type' => 'bool',
1093 'default' => true
1094 ),
1095 'display_author' => array(
1096 'type' => 'bool',
1097 'default' => true
1098 ),
1099 'display_avatar' => array(
1100 'type' => 'bool',
1101 'default' => true
1102 )
1103 );
1104 }
1105 public function get_wistia_settings_schema()
1106 {
1107 return array(
1108 'start_time' => [
1109 'type' => 'number',
1110 'default' => 0
1111 ],
1112 'display_fullscreen_button' => array(
1113 'type' => 'bool',
1114 'default' => true
1115 ),
1116 'display_playbar' => array(
1117 'type' => 'bool',
1118 'default' => true
1119 ),
1120 'small_play_button' => array(
1121 'type' => 'bool',
1122 'default' => true
1123 ),
1124 'display_volume_control' => array(
1125 'type' => 'bool',
1126 'default' => true
1127 ),
1128 'autoplay' => array(
1129 'type' => 'bool',
1130 'default' => false
1131 ),
1132 'volume' => array(
1133 'type' => 'text',
1134 'default' => '100'
1135 ),
1136 'player_color' => array(
1137 'type' => 'text',
1138 'default' => '#00adef',
1139 ),
1140 'plugin_resumable' => array(
1141 'type' => 'bool',
1142 'default' => false
1143 ),
1144 'plugin_captions' => array(
1145 'type' => 'bool',
1146 'default' => false
1147 ),
1148 'plugin_captions_default' => array(
1149 'type' => 'bool',
1150 'default' => false
1151 ),
1152 'plugin_focus' => array(
1153 'type' => 'bool',
1154 'default' => false
1155 ),
1156 'plugin_rewind' => array(
1157 'type' => 'bool',
1158 'default' => false
1159 ),
1160 'plugin_rewind_time' => array(
1161 'type' => 'text',
1162 'default' => '10'
1163 ),
1164 );
1165 }
1166
1167
1168 public function getVideoIDFromURL($url)
1169 {
1170 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
1171 // https://ostraining-1.wistia.com/medias/xf1edjzn92
1172 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
1173
1174 $id = false;
1175 if (isset($matches[1])) {
1176 $id = $matches[1];
1177 }
1178
1179 return $id;
1180 }
1181 public function embedpress_wistia_block_after_embed($attributes)
1182 {
1183 $embedOptions = $this->embedpress_wistia_pro_get_options();
1184 // Get the video ID
1185 $videoId = $this->getVideoIDFromURL($attributes['url']);
1186 $shortVideoId = $videoId;
1187
1188 $labels = array(
1189 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
1190 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
1191 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
1192 );
1193 $labels = json_encode($labels);
1194
1195
1196 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
1197 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
1198 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
1199
1200
1201
1202 echo $html;
1203 }
1204 public function embedpress_wistia_pro_get_options()
1205 {
1206 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
1207 // Embed Options
1208 $embedOptions = new \stdClass;
1209 // $embedOptions->videoFoam = true;
1210 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
1211 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
1212 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
1213
1214 if (isset($options['player_color'])) {
1215 $color = $options['player_color'];
1216 if (null !== $color) {
1217 $embedOptions->playerColor = $color;
1218 }
1219 }
1220
1221 // Plugins
1222 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
1223
1224 $pluginList = array();
1225
1226 // Resumable
1227 if (isset($options['plugin_resumable'])) {
1228 $isResumableEnabled = $options['plugin_resumable'];
1229 if ($isResumableEnabled) {
1230 // Add the resumable plugin
1231 $pluginList['resumable'] = array(
1232 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
1233 'async' => false
1234 );
1235 }
1236 }
1237 // Add a fix for the autoplay and resumable work better together
1238 //@TODO; check baseurl deeply, not looking good
1239 if ($options['autoplay']) {
1240 if ($isResumableEnabled) {
1241 $pluginList['fixautoplayresumable'] = array(
1242 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
1243 );
1244 }
1245 }
1246
1247
1248 // Focus plugin
1249 if (isset($options['plugin_focus'])) {
1250 $isFocusEnabled = $options['plugin_focus'];
1251 $pluginList['dimthelights'] = array(
1252 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
1253 'autoDim' => $isFocusEnabled
1254 );
1255 $embedOptions->focus = $isFocusEnabled;
1256 }
1257
1258 $embedOptions->plugin = $pluginList;
1259 $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions);
1260 $embedOptions = json_encode($embedOptions);
1261 return apply_filters('embedpress_wistia_params_after_encode', $embedOptions);
1262 }
1263
1264
1265 public function get_twitch_settings_schema()
1266 {
1267 return [
1268 'start_time' => [
1269 'type' => 'number',
1270 'default' => 0,
1271 ],
1272 'embedpress_pro_twitch_autoplay' => [
1273 'type' => 'string',
1274 'default' => 'no',
1275 ],
1276 'embedpress_pro_twitch_chat' => [
1277 'type' => 'string',
1278 'default' => 'no',
1279 ],
1280
1281 'embedpress_pro_twitch_theme' => [
1282 'type' => 'string',
1283 'default' => 'dark',
1284 ],
1285 'embedpress_pro_fs' => [
1286 'type' => 'string',
1287 'default' => 'yes',
1288 ],
1289 'embedpress_pro_twitch_mute' => [
1290 'type' => 'string',
1291 'default' => 'yes',
1292 ],
1293
1294 ];
1295 }
1296 public function get_dailymotion_settings_schema()
1297 {
1298 return [
1299 'autoplay' => [
1300 'type' => 'string',
1301 'default' => ''
1302 ],
1303 'play_on_mobile' => [
1304 'type' => 'string',
1305 'default' => ''
1306 ],
1307 'color' => [
1308 'type' => 'string',
1309 'default' => '#dd3333'
1310 ],
1311 'mute' => [
1312 'type' => 'string',
1313 'default' => ''
1314 ],
1315 'controls' => [
1316 'type' => 'string',
1317 'default' => '1'
1318 ],
1319 'video_info' => [
1320 'type' => 'string',
1321 'default' => '1'
1322 ],
1323 'show_logo' => [
1324 'type' => 'string',
1325 'default' => '1'
1326 ],
1327 'start_time' => [
1328 'type' => 'string',
1329 'default' => '0'
1330 ],
1331 ];
1332 }
1333 public function get_soundcloud_settings_schema()
1334 {
1335 return [
1336 'visual' => [
1337 'type' => 'string',
1338 'default' => ''
1339 ],
1340 'autoplay' => [
1341 'type' => 'string',
1342 'default' => ''
1343 ],
1344 'play_on_mobile' => [
1345 'type' => 'string',
1346 'default' => ''
1347 ],
1348 'color' => [
1349 'type' => 'string',
1350 'default' => '#dd3333'
1351 ],
1352
1353 'share_button' => [
1354 'type' => 'string',
1355 'default' => ''
1356 ],
1357 'comments' => [
1358 'type' => 'string',
1359 'default' => '1'
1360 ],
1361 'artwork' => [
1362 'type' => 'string',
1363 'default' => ''
1364 ],
1365 'play_count' => [
1366 'type' => 'string',
1367 'default' => '1'
1368 ],
1369 'username' => [
1370 'type' => 'string',
1371 'default' => '1'
1372 ],
1373 'download_button' => [
1374 'type' => 'string',
1375 'default' => '1'
1376 ],
1377 'buy_button' => [
1378 'type' => 'string',
1379 'default' => '1'
1380 ],
1381 ];
1382 }
1383
1384
1385 }
1386