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