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