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