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