PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.9.15
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.9.15
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 / Elementor_Enhancer.php
embedpress / EmbedPress / Includes / Classes Last commit date
Elementor_Enhancer.php 2 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 2 years ago EmbedPress_Plugin_Usage_Tracker.php 2 years ago Extend_CustomPlayer_Controls.php 3 years ago Extend_Elementor_Controls.php 2 years ago Feature_Enhancer.php 2 years ago Helper.php 2 years ago
Elementor_Enhancer.php
548 lines
1 <?php
2
3 namespace EmbedPress\Includes\Classes;
4
5 use Elementor\Group_Control_Image_Size;
6 use Elementor\Utils;
7 use SplMinHeap;
8 use EmbedPress\Includes\Classes\Helper;
9
10 class Elementor_Enhancer {
11
12 public static function youtube( $embed, $setting ) {
13 if ( isset( $setting['embedpress_pro_embeded_source'] ) && 'youtube' === $setting['embedpress_pro_embeded_source'] && isset( $embed->embed ) && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) {
14
15 $url_full = $match[1];
16 $query = parse_url( $url_full, PHP_URL_QUERY );
17 parse_str( $query, $params );
18 $params['controls'] = $setting['embedpress_pro_youtube_display_controls'];
19 $params['iv_load_policy'] = $setting['embedpress_pro_youtube_display_video_annotations'];
20 $params['fs'] = ( $setting['embedpress_pro_youtube_enable_fullscreen_button'] === 'yes' ) ? 1 : 0;
21 $params['rel'] = ( $setting['embedpress_pro_youtube_display_related_videos'] === 'yes' ) ? 1 : 0;
22 $params['end'] = $setting['embedpress_pro_youtube_end_time'];
23 if ( $setting['embedpress_pro_youtube_auto_play'] === 'yes' ) {
24 $params['autoplay'] = 1;
25 }
26 $params['start'] = $setting['embedpress_pro_video_start_time'];
27
28 $params['color'] = $setting['embedpress_pro_youtube_progress_bar_color'];
29
30 if ( is_embedpress_pro_active() ) {
31 $params['modestbranding'] = $setting['embedpress_pro_youtube_modest_branding'];
32 if ( $setting['embedpress_pro_youtube_force_closed_captions'] === 'yes' ) {
33 $params['cc_load_policy'] = 1;
34 }
35 }
36
37
38 preg_match( '/(.+)?\?/', $url_full, $url );
39 if ( empty( $url) ) {
40 return $embed;
41 }
42 $url = $url[1];
43
44 // Reassemble the url with the new variables.
45 $url_modified = $url . '?';
46 foreach ( $params as $paramName => $paramValue ) {
47 $url_modified .= $paramName . '=' . $paramValue . '&';
48 }
49 // Replaces the old url with the new one.
50 $embed->embed = str_replace( $url_full, rtrim( $url_modified, '&' ), $embed->embed );
51 if ( is_embedpress_pro_active() ) {
52 $embed = self::apply_cta_markup( $embed, $setting, 'youtube' );
53 }
54
55 }
56
57 return $embed;
58 }
59
60 public static function apply_cta_markup( $embed, $settings, $provider_name = '' ) {
61
62 if ( empty( $settings["embedpress_pro_{$provider_name}_logo"] ) || empty( $settings["embedpress_pro_{$provider_name}_logo"]['url'] ) ) {
63 return $embed;
64 }
65 $img = Group_Control_Image_Size::get_attachment_image_html( $settings, "embedpress_pro_{$provider_name}_logo" );
66 if ( empty( $img ) ) {
67 return $embed;
68 }
69
70 $cta = '';
71 $url = '';
72 $target = '';
73 $x = ! empty( $settings["embedpress_pro_{$provider_name}_logo_xpos"] ) && ! empty( $settings["embedpress_pro_{$provider_name}_logo_xpos"]['unit'] ) ? $settings["embedpress_pro_{$provider_name}_logo_xpos"]['size'] . $settings["embedpress_pro_{$provider_name}_logo_xpos"]['unit'] : '10%';
74
75 $y = ! empty( $settings["embedpress_pro_{$provider_name}_logo_ypos"] ) && ! empty( $settings["embedpress_pro_{$provider_name}_logo_ypos"]['unit'] ) ? $settings["embedpress_pro_{$provider_name}_logo_ypos"]['size'] . $settings["embedpress_pro_{$provider_name}_logo_ypos"]['unit'] : '10%';
76 $cssClass = isset( $embed->url ) ? '.ose-uid-' . md5( $embed->url ) : ".ose-{$provider_name}";
77 ob_start();
78 ?>
79 <style type="text/css">
80 .ep-embed-content-wraper .watermark {
81 text-align: left;
82 position: relative;
83 }
84 .ep-embed-content-wraper .watermark {
85 border: 0;
86 position: absolute;
87 bottom: 10%;
88 right: 5%;
89 max-width: 150px;
90 max-height: 75px;
91 opacity: 0.35!important;
92 z-index: 5;
93 -o-transition: opacity 0.5s ease-in-out;
94 -moz-transition: opacity 0.5s ease-in-out;
95 -webkit-transition: opacity 0.5s ease-in-out;
96 transition: opacity 0.5s ease-in-out;
97 }
98
99 <?php echo esc_html($cssClass); ?> .watermark {
100 bottom: <?php echo esc_html($y); ?>;
101 right: <?php echo esc_html($x); ?>;
102 }
103
104 .ep-embed-content-wraper .watermark:hover {
105 opacity: 1!important;
106 }
107 </style>
108 <?php
109 $style = ob_get_clean();
110
111 if ( ! class_exists( '\simple_html_dom' ) ) {
112 include_once EMBEDPRESS_PATH_CORE . 'simple_html_dom.php';
113 }
114
115 if ( ! empty( $settings["embedpress_pro_{$provider_name}_cta"] ) && ! empty( $settings["embedpress_pro_{$provider_name}_cta"]['url'] ) ) {
116 $url = $settings["embedpress_pro_{$provider_name}_cta"]['url'];
117 }
118
119 if ( $url ) {
120 $atts = self::get_link_attributes( $settings["embedpress_pro_{$provider_name}_cta"] );
121 $attributes = '';
122 foreach ( $atts as $att => $value ) {
123 $attributes .= $att . '="' . esc_attr( $value ) . '" ';
124 }
125 $cta .= sprintf( '<a %s>', trim( $attributes ) );
126 }
127
128
129 $imgDom = str_get_html( $img );
130 $imgDom = $imgDom->find( 'img', 0 );
131 $imgDom->setAttribute( 'class', 'watermark' );
132 $imgDom->removeAttribute( 'style' );
133 $imgDom->setAttribute( 'width', 'auto' );
134 $imgDom->setAttribute( 'height', 'auto' );
135 ob_start();
136 echo $imgDom;
137 $cta .= ob_get_clean();
138 $imgDom->clear();
139 unset( $img, $imgDom );
140
141 if ( $url ) {
142 $cta .= '</a>';
143 }
144 $dom = str_get_html( $embed->embed );
145 $wrapDiv = $dom->find( "div.ose-{$provider_name}", 0 );
146 if ( ! empty( $wrapDiv ) && is_object( $wrapDiv ) ) {
147 $wrapDiv->innertext .= $cta;
148 }
149
150 ob_start();
151 echo $wrapDiv;
152 $markup = ob_get_clean();
153 $dom->clear();
154 unset( $dom, $wrapDiv );
155
156 $embed->embed = $style . $markup;
157
158 return $embed;
159 }
160
161 public static function get_link_attributes( $url_control ) {
162 $attributes = [];
163
164 if ( ! empty( $url_control['url'] ) ) {
165 $allowed_protocols = array_merge( wp_allowed_protocols(), [
166 'skype',
167 'viber',
168 ] );
169
170 $attributes['href'] = esc_url( $url_control['url'], $allowed_protocols );
171 }
172
173 if ( ! empty( $url_control['is_external'] ) ) {
174 $attributes['target'] = '_blank';
175 }
176
177 if ( ! empty( $url_control['nofollow'] ) ) {
178 $attributes['rel'] = 'nofollow';
179 }
180
181 if ( ! empty( $url_control['custom_attributes'] ) ) {
182 // Custom URL attributes should come as a string of comma-delimited key|value pairs
183 $attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) );
184 }
185
186 return $attributes;
187 }
188
189 public static function vimeo( $embed, $setting ) {
190
191 if ( ! isset( $embed->provider_name ) || strtoupper( $embed->provider_name ) !== 'VIMEO' || ! isset( $embed->embed ) || $setting['embedpress_pro_embeded_source'] !== 'vimeo' ) {
192 return $embed;
193 }
194 preg_match( '/src=\"(.+?)\"/', $embed->embed, $match );
195 $url_full = $match[1];
196 $params = [
197 'color' => str_replace( '#', '', $setting['embedpress_pro_vimeo_color'] ),
198 'title' => $setting['embedpress_pro_vimeo_display_title'] === 'yes' ? 1 : 0,
199 'byline' => $setting['embedpress_pro_vimeo_display_author'] === 'yes' ? 1 : 0,
200 'portrait' => $setting['embedpress_pro_vimeo_avatar'] === 'yes' ? 1 : 0,
201 'autopause' => 0,
202 ];
203 if ( $setting['embedpress_pro_vimeo_auto_play'] === 'yes' ) {
204 $params['autoplay'] = 1;
205 }
206
207 if ( is_embedpress_pro_active() ) {
208 if ( $setting['embedpress_pro_vimeo_loop'] === 'yes' ) {
209 $params['loop'] = 1;
210 }
211 if ( $setting['embedpress_pro_vimeo_autopause'] === 'yes' ) {
212 $params['autopause'] = 1;
213 }
214
215 if ( $setting['embedpress_pro_vimeo_autopause'] !== 'yes' ) {
216 $params ['dnt'] = $setting['embedpress_pro_vimeo_dnt'] === 'yes' ? 1 : 0;
217 }
218 }
219
220
221 $url_modified = str_replace("dnt=1&", "", $url_full);
222
223 foreach ( $params as $param => $value ) {
224 $url_modified = add_query_arg( $param, $value, $url_modified );
225 }
226
227
228 $url_modified .= '#t=' . $setting['embedpress_pro_video_start_time'];
229 // Replaces the old url with the new one.
230 $embed->embed = str_replace( $url_full, $url_modified, $embed->embed );
231 if ( is_embedpress_pro_active() ) {
232 return self::apply_cta_markup( $embed, $setting, 'vimeo' );
233 }
234
235 return $embed;
236 }
237
238 public static function wistia( $embed, $setting ) {
239 if ( ! isset( $embed->provider_name ) || strtoupper( $embed->provider_name ) !== 'WISTIA, INC.' || ! isset( $embed->embed ) || $setting['embedpress_pro_embeded_source'] !== 'wistia' ) {
240 return $embed;
241 }
242 preg_match( '/src=\"(.+?)\"/', $embed->embed, $match );
243
244 $url_full = $match[1];
245
246 // Parse the url to retrieve all its info like variables etc.
247 $query = parse_url( $embed->url, PHP_URL_QUERY );
248 $url = str_replace( '?' . $query, '', $url_full );
249
250 if ($query !== null) {
251 parse_str($query, $params);
252 }
253
254 // Set the class in the attributes
255 $embed->attributes->class = str_replace( '{provider_alias}', 'wistia', $embed->attributes->class );
256 $embed->embed = str_replace( 'ose-wistia, inc.', 'ose-wistia', $embed->embed );
257
258 // Embed Options
259 $embedOptions = new \stdClass;
260 $embedOptions->videoFoam = false;
261 $embedOptions->fullscreenButton = ( $setting['embedpress_pro_wistia_fullscreen_button'] === 'yes' );
262 $embedOptions->smallPlayButton = ( $setting['embedpress_pro_wistia_small_play_button'] === 'yes' );
263 $embedOptions->autoPlay = ( $setting['embedpress_pro_wistia_auto_play'] === 'yes' );
264 $embedOptions->playerColor = $setting['embedpress_pro_wistia_color'];
265 $embedOptions->playbar = ( $setting['embedpress_pro_wistia_playbar'] === 'yes' );
266 if($setting['embedpress_pro_video_start_time']){
267 $embedOptions->time = $setting['embedpress_pro_video_start_time'];
268 }
269 if ( is_embedpress_pro_active() ) {
270 $embedOptions->volumeControl = ( $setting['embedpress_pro_wistia_volume_control'] === 'yes' );
271
272 $volume = isset($setting['embedpress_pro_wistia_volume']['size']) ? (float) $setting['embedpress_pro_wistia_volume']['size'] : 0;
273 if ( $volume > 1 ) {
274 $volume = $volume / 100;
275 }
276 $embedOptions->volume = $volume;
277 }
278
279
280 // Plugins
281 $pluginsBaseURL = plugins_url( '../assets/js/wistia/min', dirname( __DIR__ ) . '/embedpress-Wistia.php' );
282
283 $pluginList = [];
284
285 // Resumable
286
287 if ( $setting['embedpress_pro_wistia_resumable'] === 'yes' ) {
288 // Add the resumable plugin
289 $pluginList['resumable'] = [
290 'src' => $pluginsBaseURL . '/resumable.min.js',
291 'async' => true,
292 ];
293 }
294
295
296 // Add a fix for the autoplay and resumable work better together
297 if ( isset( $options->autoPlay ) ) {
298 if ( $setting['embedpress_pro_wistia_resumable'] === 'yes' ) {
299 $pluginList['fixautoplayresumable'] = [
300 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js',
301 ];
302 }
303 }
304
305 // Closed Captions plugin
306 if ( is_embedpress_pro_active() ) {
307 if ( $setting['embedpress_pro_wistia_captions'] === 'yes' ) {
308 $isCaptionsEnabled = ( $setting['embedpress_pro_wistia_captions'] === 'yes' );
309 $isCaptionsEnabledByDefault = ( $setting['embedpress_pro_wistia_captions_enabled_by_default'] === 'yes' );
310 if ( $isCaptionsEnabled ) {
311 $pluginList['captions-v1'] = [
312 'onByDefault' => $isCaptionsEnabledByDefault,
313 ];
314 }
315 $embedOptions->captions = $isCaptionsEnabled;
316 $embedOptions->captionsDefault = $isCaptionsEnabledByDefault;
317 }
318
319
320 }
321
322 // Rewind plugin
323 if ( $setting['embedpress_pro_wistia_rewind'] === 'yes' ) {
324
325 $embedOptions->rewindTime = (int) $setting['embedpress_pro_wistia_rewind_time'];
326 $pluginList['rewind'] = [
327 'src' => $pluginsBaseURL . '/rewind.min.js',
328 ];
329
330 }
331 // Focus plugin
332 if ( $setting['embedpress_pro_wistia_focus'] === 'yes' ) {
333 $isFocusEnabled = ( $setting['embedpress_pro_wistia_focus'] === 'yes' );
334 $pluginList['dimthelights'] = [
335 'src' => $pluginsBaseURL . '/dimthelights.min.js',
336 'autoDim' => $isFocusEnabled,
337 ];
338
339 $embedOptions->focus = $isFocusEnabled;
340 }
341 $embedOptions->plugin = $pluginList;
342 $embedOptions = json_encode( $embedOptions );
343
344 // Get the video ID
345 $videoId = self::get_wistia_video_from_url( $embed->url );
346 $shortVideoId = substr( $videoId, 0, 3 );
347
348 // Responsive?
349
350 $class = [
351 'wistia_embed',
352 'wistia_async_' . $videoId,
353 ];
354
355 $attribs = [
356 sprintf( 'id="wistia_%s"', $videoId ),
357 sprintf( 'class="%s"', join( ' ', $class ) ),
358 sprintf( 'style="width:%spx; height:%spx;"', $embed->attributes->{'data-width'}, $embed->attributes->{'data-height'} ),
359 ];
360
361 $labels = [
362 'watch_from_beginning' => __( 'Watch from the beginning', 'embedpress-pro' ),
363 'skip_to_where_you_left_off' => __( 'Skip to where you left off', 'embedpress-pro' ),
364 'you_have_watched_it_before' => __( 'It looks like you\'ve watched<br />part of this video before!', 'embedpress-pro' ),
365 ];
366 $labels = json_encode( $labels );
367
368 preg_match( '/ose-uid-([a-z0-9]*)/', $embed->embed, $matches );
369 $uid = $matches[1];
370
371 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
372 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
373 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
374 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
375 $html .= '<div ' . join( ' ', $attribs ) . "></div>\n";
376 $html .= '</div>';
377 $embed->embed = $html;
378 if ( is_embedpress_pro_active() ) {
379 return self::apply_cta_markup( $embed, $setting, 'wistia' );
380 }
381
382 return $embed;
383 }
384
385 /**
386 * Get the Video ID from the URL
387 *
388 * @param string $url
389 *
390 * @return string
391 */
392 public static function get_wistia_video_from_url( $url ) {
393 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
394 // https://ostraining-1.wistia.com/medias/xf1edjzn92
395 preg_match( '#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches );
396
397 $id = false;
398 if ( isset( $matches[1] ) ) {
399 $id = $matches[1];
400 }
401
402 return $id;
403 }
404
405 public static function soundcloud( $embed, $setting ) {
406
407 if ( ! isset( $embed->provider_name ) || strtoupper( $embed->provider_name ) !== 'SOUNDCLOUD' || ! isset( $embed->embed ) || $setting['embedpress_pro_embeded_source'] !== 'soundcloud' ) {
408 return $embed;
409 }
410 preg_match( '/src=\"(.+?)\"/', $embed->embed, $match );
411 $url_full = $match[1];
412 $params = [
413 'color' => str_replace( '#', '', $setting['embedpress_pro_soundcloud_color'] ),
414 'visual' => $setting['embedpress_pro_soundcloud_visual'] === 'yes' ? 'true' : 'false',
415 'auto_play' => $setting['embedpress_pro_soundcloud_autoplay'] === 'yes' ? 'true' : 'false',
416 'sharing' => $setting['embedpress_pro_soundcloud_share_button'] === 'yes' ? 'true' : 'false',
417 'show_comments' => $setting['embedpress_pro_soundcloud_comments'] === 'yes' ? 'true' : 'false',
418 'show_artwork' => $setting['embedpress_pro_soundcloud_artwork'] === 'yes' ? 'true' : 'false',
419 'show_playcount' => $setting['embedpress_pro_soundcloud_play_count'] === 'yes' ? 'true' : 'false',
420 'show_user' => $setting['embedpress_pro_soundcloud_user_name'] === 'yes' ? 'true' : 'false',
421 'buying' => 'false',
422 'download' => 'false',
423 ];
424 if ( is_embedpress_pro_active() ) {
425 $params['buying'] = $setting['embedpress_pro_soundcloud_buy_button'] === 'yes' ? 'true' : 'false';
426 $params['download'] = $setting['embedpress_pro_soundcloud_download_button'] === 'yes' ? 'true' : 'false';
427 }
428
429 $url_modified = $url_full;
430 foreach ( $params as $param => $value ) {
431 $url_modified = add_query_arg( $param, $value, $url_modified );
432 }
433
434 // Replaces the old url with the new one.
435 $embed->embed = str_replace( $url_full, $url_modified, $embed->embed );
436 if ( 'false' === $params['visual'] ) {
437 $embed->embed = str_replace( 'height="400"', 'height="200 !important"', $embed->embed );
438 }
439
440 return $embed;
441 }
442
443 public static function dailymotion( $embed, $setting ) {
444 if ( ! isset( $embed->provider_name ) || strtoupper( $embed->provider_name ) !== 'DAILYMOTION' || ! isset( $embed->embed ) || $setting['embedpress_pro_embeded_source'] !== 'dailymotion' ) {
445 return $embed;
446 }
447 preg_match( '/src=\"(.+?)\"/', $embed->embed, $match );
448 $url_full = $match[1];
449 $params = [
450 'ui-highlight' => str_replace( '#', '', $setting['embedpress_pro_dailymotion_control_color'] ),
451 'start' => isset( $setting['embedpress_pro_video_start_time'] ) ? (int) $setting['embedpress_pro_video_start_time'] : 0,
452 'mute' => $setting['embedpress_pro_dailymotion_mute'] === 'yes' ? 1 : 0,
453 'autoplay' => $setting['embedpress_pro_dailymotion_autoplay'] === 'yes' ? 1 : 0,
454 'controls' => $setting['embedpress_pro_dailymotion_player_control'] === 'yes' ? 1 : 0,
455 'ui-start-screen-info' => $setting['embedpress_pro_dailymotion_video_info'] === 'yes' ? 1 : 0,
456 'endscreen-enable' => 0,
457 ];
458
459 if ( $setting['embedpress_pro_dailymotion_play_on_mobile'] === 'yes' ) {
460 $params['playsinline'] = 1;
461 }
462 if ( is_embedpress_pro_active() ) {
463 $params['ui-logo'] = isset( $setting['embedpress_pro_dailymotion_ui_logo']) && ($setting['embedpress_pro_dailymotion_ui_logo'] === 'yes') ? 1 : 0;
464 }
465 $url_modified = $url_full;
466 foreach ( $params as $param => $value ) {
467 $url_modified = add_query_arg( $param, $value, $url_modified );
468 }
469 $embed->embed = str_replace( $url_full, $url_modified, $embed->embed );
470 if ( is_embedpress_pro_active() ) {
471 return self::apply_cta_markup( $embed, $setting, 'dailymotion' );
472 }
473 return $embed;
474 }
475
476 public static function twitch( $embed_content, $settings ) {
477 if ( ! isset( $embed_content->embed ) || $settings['embedpress_pro_embeded_source'] !== 'twitch' ) {
478 return $embed_content;
479 }
480 $e = current( $embed_content );
481
482 if ( ! isset( $e['provider_name'] ) || strtoupper( $e['provider_name'] ) !== 'TWITCH' ) {
483 return $embed_content;
484 }
485 $time = '0h0m0s';
486 $type = isset( $e['type'] ) ? $e['type'] : '';
487 $content_id = isset( $e['content_id'] ) ? $e['content_id'] : '';
488 $channel = 'channel' === $type ? $content_id : '';
489 $video = 'video' === $type ? $content_id : '';
490 $full_screen = ( 'yes' === $settings['embedpress_pro_fs'] ) ? 'true' : 'false';
491 $autoplay = ( 'yes' === $settings['embedpress_pro_twitch_autoplay'] ) ? 'true' : 'false';
492 $layout = 'video';
493 $width = (int) $settings['width']['size'];
494 $height = (int) $settings['height']['size'];
495 if ( ! empty( $settings['embedpress_pro_video_start_time'] ) ) {
496 $ta = explode( ':', gmdate( "G:i:s", $settings['embedpress_pro_video_start_time'] ) );
497 $h = $ta[0] . 'h';
498 $m = ( $ta[1] * 1 ) . 'm';
499 $s = ( $ta[2] * 1 ) . 's';
500 $time = $h . $m . $s;
501 }
502 $muted = ( 'yes' === $settings['embedpress_pro_twitch_mute'] ) ? 'true' : 'false';
503 $theme = !empty($settings['embedpress_pro_twitch_theme']) ? esc_attr($settings['embedpress_pro_twitch_theme']) : 'dark';
504
505 if ( is_embedpress_pro_active() ) {
506
507 $layout = ( 'yes' === $settings['embedpress_pro_twitch_chat'] ) ? 'video-with-chat' : 'video';
508
509 }
510
511 $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}";
512
513 $pars_url = wp_parse_url( get_site_url() );
514 $url = ! empty( $pars_url['host'] ) ? $url . '&parent=' . $pars_url['host'] : $url;
515
516 preg_match( '/src=\"(.+?)\"/', $embed_content->embed, $match );
517 $url_full = $match[1];
518 $embed_content->embed = str_replace( $url_full, $url, $embed_content->embed );
519 if ( is_embedpress_pro_active() ) {
520 return self::apply_cta_markup( $embed_content, $settings, 'twitch' );
521 }
522
523 return $embed_content;
524 }
525
526 public static function spotify( $embed, $setting ) {
527 if ( ! isset( $embed->provider_name ) || strtolower( $embed->provider_name ) !== 'spotify' || ! isset( $embed->embed ) ) {
528 return $embed;
529 }
530 preg_match( '/src=\"(.+?)\"/', $embed->embed, $match );
531 $url_full = $match[1];
532 $modified_url = str_replace( 'playlist-v2', 'playlist', $url_full );
533 if ( $setting['embedpress_pro_embeded_source'] == 'spotify' ) {
534 // apply elementor related mod
535 if ( isset( $setting['spotify_theme'] ) ) {
536 if ( strpos( $modified_url, '?' ) !== false ) {
537 $modified_url .= '&theme=' . sanitize_text_field( $setting['spotify_theme'] );
538 } else {
539 $modified_url .= '?theme=' . sanitize_text_field( $setting['spotify_theme'] );
540 }
541 }
542 }
543
544 $embed->embed = str_replace( $url_full, $modified_url, $embed->embed );
545
546 return $embed;
547 }
548 }