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