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
4 years ago
Helper.php
4 years ago
Feature_Enhancer.php
939 lines
| 1 | <?php |
| 2 | namespace EmbedPress\Includes\Classes; |
| 3 | |
| 4 | class Feature_Enhancer { |
| 5 | |
| 6 | public function __construct() { |
| 7 | add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90 ); |
| 8 | add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90 ); |
| 9 | add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90 ); |
| 10 | add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90 ); |
| 11 | add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90 ); |
| 12 | add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90 ); |
| 13 | add_filter( 'embedpress_gutenberg_youtube_params', |
| 14 | [$this, 'embedpress_gutenberg_register_block_youtube'] ); |
| 15 | add_action( 'init', array( $this, 'embedpress_gutenberg_register_block_vimeo' ) ); |
| 16 | add_action('embedpress_gutenberg_wistia_block_after_embed', array($this,'embedpress_wistia_block_after_embed')); |
| 17 | add_action( 'elementor/widget/embedpres_elementor/skins_init', [ $this, 'elementor_setting_init' ] ); |
| 18 | } |
| 19 | |
| 20 | public function elementor_setting_init( ) { |
| 21 | $this->remove_classic_filters(); |
| 22 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'youtube'], 10, 2 ); |
| 23 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'wistia'], 10, 2 ); |
| 24 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'twitch'], 10, 2 ); |
| 25 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'soundcloud'], 10, 2 ); |
| 26 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'dailymotion'], 10, 2 ); |
| 27 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'spotify'], 10, 2 ); |
| 28 | add_filter( 'embedpress_elementor_embed', [Elementor_Enhancer::class, 'vimeo'], 10, 2 ); |
| 29 | } |
| 30 | public function remove_classic_filters( ) { |
| 31 | remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90 ); |
| 32 | remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90 ); |
| 33 | remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90 ); |
| 34 | remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90 ); |
| 35 | remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90 ); |
| 36 | remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90 ); |
| 37 | } |
| 38 | public function getOptions($provider='', $schema=[]) |
| 39 | { |
| 40 | $options = (array)get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []); |
| 41 | if (empty($options) || (count($options) === 1 && empty($options[0]))) { |
| 42 | $options = []; |
| 43 | |
| 44 | foreach ($schema as $fieldSlug => $field) { |
| 45 | $value = isset($field['default']) ? $field['default'] : ""; |
| 46 | |
| 47 | settype($value, isset($field['type']) && in_array(strtolower($field['type']), |
| 48 | ['bool', 'boolean', 'int', 'integer', 'float', 'string']) ? $field['type'] : 'string'); |
| 49 | |
| 50 | if ($fieldSlug === "license_key") { |
| 51 | $options['license'] = [ |
| 52 | 'key' => true, |
| 53 | 'status' => "missing", |
| 54 | ]; |
| 55 | } else { |
| 56 | $options[$fieldSlug] = $value; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | $options['license'] = [ |
| 62 | 'key' => true, |
| 63 | 'status' => "missing", |
| 64 | ]; |
| 65 | return apply_filters( 'emebedpress_get_options', $options); |
| 66 | } |
| 67 | public function get_youtube_params( $options ) |
| 68 | { |
| 69 | $params = []; |
| 70 | |
| 71 | // Handle `autoplay` option. |
| 72 | if ( isset( $options[ 'autoplay' ] ) && (bool)$options[ 'autoplay' ] === true ) { |
| 73 | $params[ 'autoplay' ] = 1; |
| 74 | } else { |
| 75 | unset( $params[ 'autoplay' ] ); |
| 76 | } |
| 77 | |
| 78 | // Handle `controls` option. |
| 79 | if ( isset( $options[ 'controls' ] ) && in_array( (int)$options[ 'controls' ], [0, 1, 2] ) ) { |
| 80 | $params[ 'controls' ] = (int)$options[ 'controls' ]; |
| 81 | } else { |
| 82 | unset( $params[ 'controls' ] ); |
| 83 | } |
| 84 | |
| 85 | // Handle `fs` option. |
| 86 | if ( isset( $options[ 'fs' ] ) && in_array( (int)$options[ 'fs' ], [0, 1] ) ) { |
| 87 | $params[ 'fs' ] = (int)$options[ 'fs' ]; |
| 88 | } else { |
| 89 | unset( $params[ 'fs' ] ); |
| 90 | } |
| 91 | |
| 92 | // Handle `iv_load_policy` option. |
| 93 | if ( isset( $options[ 'iv_load_policy' ] ) && in_array( (int)$options[ 'iv_load_policy' ], [1, 3] ) ) { |
| 94 | $params[ 'iv_load_policy' ] = (int)$options[ 'iv_load_policy' ]; |
| 95 | } else { |
| 96 | unset( $params[ 'iv_load_policy' ] ); |
| 97 | } |
| 98 | |
| 99 | return apply_filters( 'embedpress_youtube_params', $params); |
| 100 | |
| 101 | } |
| 102 | public function get_vimeo_params($options) { |
| 103 | $params = []; |
| 104 | |
| 105 | // Handle `display_title` option. |
| 106 | if (isset($options['display_title']) && (bool)$options['display_title'] === true) { |
| 107 | $params['title'] = 1; |
| 108 | } else { |
| 109 | $params['title'] = 0; |
| 110 | } |
| 111 | |
| 112 | // Handle `autoplay` option. |
| 113 | if (!empty($options['autoplay'])) { |
| 114 | $params['autoplay'] = 1; |
| 115 | } else { |
| 116 | unset($params['autoplay']); |
| 117 | } |
| 118 | |
| 119 | // Handle `color` option. |
| 120 | if (!empty($options['color'])) { |
| 121 | $params['color'] = str_replace('#', '', $options['color']); |
| 122 | } else { |
| 123 | unset($params['color']); |
| 124 | } |
| 125 | return apply_filters( 'embedpress_vimeo_params', $params); |
| 126 | |
| 127 | } |
| 128 | //--- For CLASSIC AND BLOCK EDITOR |
| 129 | public function enhance_youtube( $embed ) |
| 130 | { |
| 131 | $isYoutube = ( isset($embed->provider_name) && strtoupper( $embed->provider_name ) === 'YOUTUBE' ) || (isset( $embed->url) && isset( $embed->{$embed->url}) && isset( $embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name'] ) === 'YOUTUBE'); |
| 132 | |
| 133 | if ( $isYoutube && isset( $embed->embed ) |
| 134 | && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) { |
| 135 | // for compatibility only, @TODO; remove later after deep testing. |
| 136 | $options = $this->getOptions('youtube', $this->get_youtube_settings_schema()); |
| 137 | // Parse the url to retrieve all its info like variables etc. |
| 138 | $url_full = $match[ 1 ]; |
| 139 | $query = parse_url( $url_full, PHP_URL_QUERY ); |
| 140 | parse_str( $query, $params ); |
| 141 | // Handle `color` option. |
| 142 | if ( !empty( $options[ 'color' ] ) ) { |
| 143 | $params[ 'color' ] = $options[ 'color' ]; |
| 144 | } else { |
| 145 | unset( $params[ 'color' ] ); |
| 146 | } |
| 147 | // Handle `rel` option. |
| 148 | if ( isset( $options[ 'rel' ] ) && in_array( (int)$options[ 'rel' ], [0, 1] ) ) { |
| 149 | $params[ 'rel' ] = (int)$options[ 'rel' ]; |
| 150 | } else { |
| 151 | unset( $params[ 'rel' ] ); |
| 152 | } |
| 153 | |
| 154 | // Handle `autoplay` option. |
| 155 | if ( isset( $options[ 'autoplay' ] ) && (bool)$options[ 'autoplay' ] === true ) { |
| 156 | $params[ 'autoplay' ] = 1; |
| 157 | } else { |
| 158 | unset( $params[ 'autoplay' ] ); |
| 159 | } |
| 160 | |
| 161 | // Handle `controls` option. |
| 162 | if ( isset( $options[ 'controls' ] ) && in_array( (int)$options[ 'controls' ], [0, 1, 2] ) ) { |
| 163 | $params[ 'controls' ] = (int)$options[ 'controls' ]; |
| 164 | } else { |
| 165 | unset( $params[ 'controls' ] ); |
| 166 | } |
| 167 | if ( isset($options[ 'start_time' ]) ) { |
| 168 | $params[ 'start' ] = $options[ 'start_time' ]; |
| 169 | }else { |
| 170 | unset($params[ 'start' ]); |
| 171 | } |
| 172 | if ( isset($options[ 'end_time' ]) ) { |
| 173 | $params[ 'end' ] = $options[ 'end_time' ]; |
| 174 | }else { |
| 175 | unset($params[ 'end' ]); |
| 176 | } |
| 177 | |
| 178 | // Handle `fs` option. |
| 179 | if ( isset( $options[ 'fs' ] ) && in_array( (int)$options[ 'fs' ], [0, 1] ) ) { |
| 180 | $params[ 'fs' ] = (int)$options[ 'fs' ]; |
| 181 | } else { |
| 182 | unset( $params[ 'fs' ] ); |
| 183 | } |
| 184 | |
| 185 | // Handle `iv_load_policy` option. |
| 186 | if ( isset( $options[ 'iv_load_policy' ] ) && in_array( (int)$options[ 'iv_load_policy' ], [1, 3] ) ) { |
| 187 | $params[ 'iv_load_policy' ] = (int)$options[ 'iv_load_policy' ]; |
| 188 | } else { |
| 189 | unset( $params[ 'iv_load_policy' ] ); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | // pro controls will be handled by the pro so remove it from the free. |
| 194 | $pro_controls = [ 'cc_load_policy', 'modestbranding']; |
| 195 | foreach ( $pro_controls as $pro_control ) { |
| 196 | if ( isset( $params[ $pro_control ]) ) { |
| 197 | unset( $params[ $pro_control ]); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 202 | preg_match( '/(.+)?\?/', $url_full, $url ); |
| 203 | $url = $url[ 1 ]; |
| 204 | |
| 205 | // Reassemble the url with the new variables. |
| 206 | $url_modified = $url . '?'; |
| 207 | foreach ( $params as $paramName => $paramValue ) { |
| 208 | $url_modified .= $paramName . '=' . $paramValue . '&'; |
| 209 | } |
| 210 | |
| 211 | // Replaces the old url with the new one. |
| 212 | $embed->embed = str_replace( $url_full, rtrim( $url_modified, '&' ), $embed->embed ); |
| 213 | |
| 214 | } |
| 215 | |
| 216 | return $embed; |
| 217 | } |
| 218 | public function enhance_vimeo( $embed ) { |
| 219 | if ( isset( $embed->provider_name ) |
| 220 | && strtoupper( $embed->provider_name ) === 'VIMEO' |
| 221 | && isset( $embed->embed ) |
| 222 | && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) { |
| 223 | // old schema is for backward compatibility only @todo; remove it in the next version after deep test |
| 224 | $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema()); |
| 225 | |
| 226 | $url_full = $match[1]; |
| 227 | $params = []; |
| 228 | |
| 229 | // Handle `display_title` option. |
| 230 | if ( isset( $options['display_title'] ) && (bool)$options['display_title'] === true ) { |
| 231 | $params['title'] = 1; |
| 232 | } else { |
| 233 | $params['title'] = 0; |
| 234 | } |
| 235 | |
| 236 | // Handle `autoplay` option. |
| 237 | if ( isset( $options['autoplay'] ) && (bool)$options['autoplay'] === true ) { |
| 238 | $params['autoplay'] = 1; |
| 239 | } else { |
| 240 | unset( $params['autoplay'] ); |
| 241 | } |
| 242 | |
| 243 | // Handle `color` option. |
| 244 | if ( !empty( $options['color'] ) ) { |
| 245 | $params['color'] = str_replace( '#', '', $options['color'] ); |
| 246 | } else { |
| 247 | unset( $params['color'] ); |
| 248 | } |
| 249 | // Handle `display_author` option. |
| 250 | if ( isset( $options['display_author'] ) && (bool)$options['display_author'] === true ) { |
| 251 | $params['byline'] = 1; |
| 252 | } else { |
| 253 | $params['byline'] = 0; |
| 254 | } |
| 255 | |
| 256 | // Handle `display_avatar` option. |
| 257 | if ( isset( $options['display_avatar'] ) && (bool)$options['display_avatar'] === true ) { |
| 258 | $params['portrait'] = 1; |
| 259 | } else { |
| 260 | $params['portrait'] = 0; |
| 261 | } |
| 262 | |
| 263 | // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only |
| 264 | //@todo; maybe extract unsetting pro vars to a function later |
| 265 | $pro_controls = ['loop', 'autopause', 'dnt',]; |
| 266 | foreach ( $pro_controls as $pro_control ) { |
| 267 | if ( isset( $params[ $pro_control ]) ) { |
| 268 | unset( $params[ $pro_control ]); |
| 269 | } |
| 270 | } |
| 271 | // Reassemble the url with the new variables. |
| 272 | $url_modified = $url_full; |
| 273 | foreach ( $params as $param => $value ) { |
| 274 | $url_modified = add_query_arg( $param, $value, $url_modified ); |
| 275 | } |
| 276 | if ( isset( $options[ 'start_time' ]) ) { |
| 277 | $url_modified .= '#t=' . $options[ 'start_time' ]; |
| 278 | } |
| 279 | |
| 280 | do_action( 'embedpress_after_modified_url', $url_modified, $url_full, $params); |
| 281 | // Replaces the old url with the new one. |
| 282 | $embed->embed = str_replace( $url_full, $url_modified, $embed->embed ); |
| 283 | |
| 284 | } |
| 285 | |
| 286 | return $embed; |
| 287 | } |
| 288 | public function enhance_wistia( $embed ) { |
| 289 | if (isset($embed->provider_name) |
| 290 | && strtoupper($embed->provider_name) === 'WISTIA, INC.' |
| 291 | && isset($embed->embed) |
| 292 | && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)) { |
| 293 | $options = $this->getOptions('wistia', $this->get_wistia_settings_schema()); |
| 294 | |
| 295 | $url_full = $match[1]; |
| 296 | |
| 297 | // Parse the url to retrieve all its info like variables etc. |
| 298 | $query = parse_url($embed->url, PHP_URL_QUERY); |
| 299 | $url = str_replace('?'.$query, '', $url_full); |
| 300 | |
| 301 | parse_str($query, $params); |
| 302 | |
| 303 | // Set the class in the attributes |
| 304 | $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class); |
| 305 | $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed); |
| 306 | |
| 307 | // Embed Options |
| 308 | $embedOptions = new \stdClass; |
| 309 | $embedOptions->videoFoam = true; |
| 310 | $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true); |
| 311 | $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true); |
| 312 | |
| 313 | $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true); |
| 314 | |
| 315 | $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true); |
| 316 | |
| 317 | $embedOptions->time = isset( $options[ 'start_time' ]) ? $options[ 'start_time' ] : 0; |
| 318 | |
| 319 | if (isset($options['player_color'])) { |
| 320 | $color = $options['player_color']; |
| 321 | if (null !== $color) { |
| 322 | $embedOptions->playerColor = $color; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // Plugins |
| 327 | $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__).'/embedpress-Wistia.php'); |
| 328 | |
| 329 | $pluginList = array(); |
| 330 | |
| 331 | // Resumable |
| 332 | if (isset($options['plugin_resumable'])) { |
| 333 | $isResumableEnabled = $options['plugin_resumable']; |
| 334 | if ($isResumableEnabled) { |
| 335 | // Add the resumable plugin |
| 336 | $pluginList['resumable'] = array( |
| 337 | 'src' => $pluginsBaseURL.'/resumable.min.js', |
| 338 | 'async' => false |
| 339 | ); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | // Add a fix for the autoplay and resumable work better together |
| 344 | if (isset($options->autoPlay)) { |
| 345 | if ($isResumableEnabled) { |
| 346 | $pluginList['fixautoplayresumable'] = array( |
| 347 | 'src' => $pluginsBaseURL.'/fixautoplayresumable.min.js' |
| 348 | ); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // Focus plugin |
| 353 | if (isset($options['plugin_focus'])) { |
| 354 | $isFocusEnabled = $options['plugin_focus']; |
| 355 | $pluginList['dimthelights'] = array( |
| 356 | 'src' => $pluginsBaseURL.'/dimthelights.min.js', |
| 357 | 'autoDim' => $isFocusEnabled |
| 358 | ); |
| 359 | $embedOptions->focus = $isFocusEnabled; |
| 360 | } |
| 361 | |
| 362 | // Rewind plugin |
| 363 | if (isset($options['plugin_rewind'])) { |
| 364 | if ($options['plugin_rewind']) { |
| 365 | $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10; |
| 366 | |
| 367 | $pluginList['rewind'] = array( |
| 368 | 'src' => $pluginsBaseURL.'/rewind.min.js' |
| 369 | ); |
| 370 | } |
| 371 | } |
| 372 | $embedOptions->plugin = $pluginList; |
| 373 | $embedOptions = json_encode($embedOptions); |
| 374 | |
| 375 | // Get the video ID |
| 376 | $videoId = $this->getVideoIDFromURL($embed->url); |
| 377 | $shortVideoId = substr($videoId, 0, 3); |
| 378 | |
| 379 | // Responsive? |
| 380 | |
| 381 | $class = array( |
| 382 | 'wistia_embed', |
| 383 | 'wistia_async_'.$videoId |
| 384 | ); |
| 385 | |
| 386 | $attribs = array( |
| 387 | sprintf('id="wistia_%s"', $videoId), |
| 388 | sprintf('class="%s"', join(' ', $class)), |
| 389 | sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height) |
| 390 | ); |
| 391 | |
| 392 | $labels = array( |
| 393 | 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'), |
| 394 | 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'), |
| 395 | 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', |
| 396 | 'embedpress'), |
| 397 | ); |
| 398 | $labels = json_encode($labels); |
| 399 | |
| 400 | preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches); |
| 401 | $uid = $matches[1]; |
| 402 | |
| 403 | $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">"; |
| 404 | $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>'; |
| 405 | $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n"; |
| 406 | $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n"; |
| 407 | $html .= '<div '.join(' ', $attribs)."></div>\n"; |
| 408 | $html .= '</div>'; |
| 409 | $embed->embed = $html; |
| 410 | } |
| 411 | |
| 412 | return $embed; |
| 413 | } |
| 414 | public function enhance_twitch( $embed_content ) { |
| 415 | $e = isset( $embed_content->url) && isset( $embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : []; |
| 416 | if ( isset( $e['provider_name'] ) && strtoupper( $e['provider_name'] ) === 'TWITCH' && isset( $embed_content->embed ) ) { |
| 417 | $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema()); |
| 418 | |
| 419 | $atts = isset( $embed_content->attributes) ? $embed_content->attributes : []; |
| 420 | $time = '0h0m0s'; |
| 421 | $type = $e['type']; |
| 422 | $content_id = $e['content_id']; |
| 423 | $channel = 'channel' === $type ? $content_id : ''; |
| 424 | $video = 'video' === $type ? $content_id : ''; |
| 425 | $muted = ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true': 'false'; |
| 426 | $full_screen = ('yes' === $settings['embedpress_pro_fs']) ? 'true': 'false'; |
| 427 | $autoplay = ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true': 'false'; |
| 428 | $theme = ! empty( $settings['embedpress_pro_twitch_theme'] ) ? $settings['embedpress_pro_twitch_theme'] : 'dark'; |
| 429 | |
| 430 | $layout = 'video'; |
| 431 | $width = !empty( $atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800; |
| 432 | $height = !empty( $atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450; |
| 433 | if ( ! empty( $settings['start_time'] ) ) { |
| 434 | $ta = explode( ':', gmdate( "G:i:s", $settings['start_time'] ) ); |
| 435 | $h = $ta[0] . 'h'; |
| 436 | $m = ( $ta[1] * 1 ) . 'm'; |
| 437 | $s = ( $ta[2] * 1 ) . 's'; |
| 438 | $time = $h . $m . $s; |
| 439 | } |
| 440 | $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}"; |
| 441 | $pars_url = wp_parse_url(get_site_url()); |
| 442 | $url = !empty($pars_url['host'])?$url.'&parent='.$pars_url['host']:$url; |
| 443 | ob_start(); |
| 444 | ?> |
| 445 | <div class="embedpress_wrapper" data-url="<?php echo esc_attr(esc_url( $embed_content->url));?>"> |
| 446 | <iframe src="<?php echo esc_url( $url); ?>" allowfullscreen="" scrolling="no" frameborder="0" allow="autoplay; fullscreen" title="Twitch" sandbox="allow-modals allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" width="<?php echo esc_attr($width); ?>" height="<?php echo esc_attr($height); ?>" style="max-width: 100%; max-height:<?php echo esc_attr($width); ?>px;"></iframe> |
| 447 | </div> |
| 448 | <?php |
| 449 | $c = ob_get_clean(); |
| 450 | $embed_content->embed = $c; |
| 451 | } |
| 452 | |
| 453 | return $embed_content; |
| 454 | } |
| 455 | public function enhance_dailymotion( $embed ) { |
| 456 | $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema()); |
| 457 | $isDailymotion = ( isset($embed->provider_name) && strtoupper( $embed->provider_name ) === 'DAILYMOTION' ) || (isset( $embed->url) && isset( $embed->{$embed->url}) && isset( $embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name'] ) === 'DAILYMOTION'); |
| 458 | |
| 459 | if ( $isDailymotion && isset( $embed->embed ) |
| 460 | && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) { |
| 461 | // Parse the url to retrieve all its info like variables etc. |
| 462 | $url_full = $match[ 1 ]; |
| 463 | $params = [ |
| 464 | 'ui-highlight' => str_replace( '#', '', $options[ 'color' ] ), |
| 465 | 'mute' => (int) $options[ 'mute' ], |
| 466 | 'autoplay' => (int) $options[ 'autoplay' ], |
| 467 | 'controls' => (int) $options[ 'controls' ], |
| 468 | 'ui-start-screen-info' => (int) $options[ 'video_info' ], |
| 469 | 'endscreen-enable' => 0, |
| 470 | ]; |
| 471 | |
| 472 | if ( $options[ 'play_on_mobile' ] == '1' ) { |
| 473 | $params[ 'playsinline' ] = 1; |
| 474 | } |
| 475 | $params['start'] = (int) $options[ 'start_time' ]; |
| 476 | if ( is_embedpress_pro_active() ) { |
| 477 | $params['ui-logo'] = (int) $options[ 'show_logo' ]; |
| 478 | } |
| 479 | |
| 480 | $url_modified = $url_full; |
| 481 | foreach ( $params as $param => $value ) { |
| 482 | $url_modified = add_query_arg( $param, $value, $url_modified ); |
| 483 | } |
| 484 | $embed->embed = str_replace( $url_full, $url_modified, $embed->embed ); |
| 485 | |
| 486 | } |
| 487 | |
| 488 | return $embed; |
| 489 | } |
| 490 | public function enhance_soundcloud( $embed ) { |
| 491 | |
| 492 | $isSoundcloud = ( isset($embed->provider_name) && strtoupper( $embed->provider_name ) === 'SOUNDCLOUD' ) || (isset( $embed->url) && isset( $embed->{$embed->url}) && isset( $embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name'] ) === 'SOUNDCLOUD'); |
| 493 | |
| 494 | if ( $isSoundcloud && isset( $embed->embed ) |
| 495 | && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) { |
| 496 | $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema()); |
| 497 | // Parse the url to retrieve all its info like variables etc. |
| 498 | $url_full = $match[ 1 ]; |
| 499 | $params = [ |
| 500 | 'color' => str_replace( '#', '', $options[ 'color' ] ), |
| 501 | 'visual' => isset($options[ 'visual' ] ) && $options['visual']== '1' ? 'true' : 'false', |
| 502 | 'auto_play' => isset($options[ 'autoplay' ] ) && $options['autoplay']== '1' ? 'true' : 'false', |
| 503 | 'sharing' => isset($options[ 'share_button' ] ) && $options['share_button']== '1' ? 'true' : 'false', |
| 504 | 'show_comments' => isset($options[ 'comments' ] ) && $options['comments']== '1' ? 'true' : 'false', |
| 505 | 'buying' => 'false', |
| 506 | 'download' => 'false', |
| 507 | 'show_artwork' => isset($options[ 'artwork' ] ) && $options['artwork']== '1' ? 'true' : 'false', |
| 508 | 'show_playcount' => isset($options[ 'play_count' ] ) && $options['play_count']== '1' ? 'true' : 'false', |
| 509 | 'show_user' => isset($options[ 'username' ] ) && $options['username']== '1' ? 'true' : 'false', |
| 510 | ]; |
| 511 | |
| 512 | if ( is_embedpress_pro_active() ) { |
| 513 | $params['buying'] = isset($options[ 'buy_button' ] ) && $options['buy_button']== '1' ? 'true' : 'false'; |
| 514 | $params['download'] = isset($options[ 'download_button' ] ) && $options['download_button']== '1' ? 'true' : 'false'; |
| 515 | } |
| 516 | |
| 517 | $url_modified = $url_full; |
| 518 | foreach ( $params as $param => $value ) { |
| 519 | $url_modified = add_query_arg( $param, $value, $url_modified ); |
| 520 | } |
| 521 | |
| 522 | // Replaces the old url with the new one. |
| 523 | $embed->embed = str_replace( $url_full, $url_modified, $embed->embed ); |
| 524 | if ( 'false' === $params[ 'visual' ] ) { |
| 525 | $embed->embed = str_replace( 'height="400"', 'height="200 !important"', $embed->embed ); |
| 526 | } |
| 527 | |
| 528 | } |
| 529 | |
| 530 | return $embed; |
| 531 | } |
| 532 | public function embedpress_gutenberg_register_block_youtube( $youtube_params ) { |
| 533 | $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema()); |
| 534 | return $this->get_youtube_params( $youtube_options ); |
| 535 | } |
| 536 | public function embedpress_gutenberg_register_block_vimeo() { |
| 537 | if ( function_exists( 'register_block_type' ) ) : |
| 538 | register_block_type( 'embedpress/vimeo-block', array( |
| 539 | 'attributes' => array( |
| 540 | 'url' => array( |
| 541 | 'type' => 'string', |
| 542 | 'default' => '' |
| 543 | ), |
| 544 | 'iframeSrc' => array( |
| 545 | 'type' => 'string', |
| 546 | 'default' => '' |
| 547 | ), |
| 548 | ), |
| 549 | 'render_callback' => [ $this, 'embedpress_gutenberg_render_block_vimeo' ] |
| 550 | ) ); |
| 551 | endif; |
| 552 | } |
| 553 | public function embedpress_gutenberg_render_block_vimeo( $attributes ) { |
| 554 | ob_start(); |
| 555 | if ( !empty( $attributes ) && !empty( $attributes['iframeSrc'] ) ) : |
| 556 | $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema()); |
| 557 | $vimeo_params = $this->get_vimeo_params( $vimeo_options ); |
| 558 | $iframeUrl = $attributes['iframeSrc']; |
| 559 | $align = 'align' . ( isset( $attributes[ 'align' ] ) ? $attributes[ 'align' ] : 'center' ); |
| 560 | foreach ( $vimeo_params as $param => $value ) { |
| 561 | $iframeUrl = add_query_arg( $param, $value, $iframeUrl ); |
| 562 | } |
| 563 | //@TODO; test responsive without static height width, keeping for now backward compatibility |
| 564 | ?> |
| 565 | <div class="ose-vimeo wp-block-embed-vimeo <?php echo $align; ?>"> |
| 566 | <iframe src="<?php echo $iframeUrl; ?>" allowtransparency="true" frameborder="0" width="640" height="360"> |
| 567 | </iframe> |
| 568 | </div> |
| 569 | <?php |
| 570 | endif; |
| 571 | |
| 572 | return apply_filters( 'embedpress_gutenberg_block_markup', ob_get_clean()); |
| 573 | } |
| 574 | public function get_youtube_settings_schema() { |
| 575 | return [ |
| 576 | 'autoplay' => [ |
| 577 | 'type' => 'bool', |
| 578 | 'default' => false |
| 579 | ], |
| 580 | 'color' => [ |
| 581 | 'type' => 'string', |
| 582 | 'default' => 'red' |
| 583 | ], |
| 584 | 'cc_load_policy' => [ |
| 585 | 'type' => 'bool', |
| 586 | 'default' => false |
| 587 | ], |
| 588 | 'controls' => [ |
| 589 | 'type' => 'string', |
| 590 | 'default' => '1' |
| 591 | ], |
| 592 | 'fs' => [ |
| 593 | 'type' => 'bool', |
| 594 | 'default' => true |
| 595 | ], |
| 596 | 'iv_load_policy' => [ |
| 597 | 'type' => 'radio', |
| 598 | 'default' => '1' |
| 599 | ], |
| 600 | 'rel' => [ |
| 601 | 'type' => 'bool', |
| 602 | 'default' => true |
| 603 | ], |
| 604 | 'modestbranding' => [ |
| 605 | 'type' => 'string', |
| 606 | 'default' => '0' |
| 607 | ], |
| 608 | 'logo_url' => [ |
| 609 | 'type' => 'url', |
| 610 | ], |
| 611 | 'logo_xpos' => [ |
| 612 | 'type' => 'number', |
| 613 | 'default' => 10 |
| 614 | ], |
| 615 | 'logo_ypos' => [ |
| 616 | 'type' => 'number', |
| 617 | 'default' => 10 |
| 618 | ], |
| 619 | 'cta_url' => [ |
| 620 | 'type' => 'url', |
| 621 | ], |
| 622 | 'start_time' => [ |
| 623 | 'type' => 'number', |
| 624 | 'default' => 10 |
| 625 | ], |
| 626 | 'end_time' => [ |
| 627 | 'type' => 'number', |
| 628 | 'default' => 10 |
| 629 | ], |
| 630 | ]; |
| 631 | } |
| 632 | public function get_vimeo_settings_schema() { |
| 633 | return array( |
| 634 | 'start_time' => [ |
| 635 | 'type' => 'number', |
| 636 | 'default' => 10 |
| 637 | ], |
| 638 | 'autoplay' => array( |
| 639 | 'type' => 'bool', |
| 640 | 'default' => false |
| 641 | ), |
| 642 | 'loop' => array( |
| 643 | 'type' => 'bool', |
| 644 | 'default' => false |
| 645 | ), |
| 646 | 'autopause' => array( |
| 647 | 'type' => 'bool', |
| 648 | 'default' => false |
| 649 | ), |
| 650 | 'vimeo_dnt' => array( |
| 651 | 'type' => 'bool', |
| 652 | 'default' => true, |
| 653 | ), |
| 654 | 'color' => array( |
| 655 | 'type' => 'text', |
| 656 | 'default' => '#00adef', |
| 657 | 'classes' => 'color-field' |
| 658 | ), |
| 659 | 'display_title' => array( |
| 660 | 'type' => 'bool', |
| 661 | 'default' => true |
| 662 | ), |
| 663 | 'display_author' => array( |
| 664 | 'type' => 'bool', |
| 665 | 'default' => true |
| 666 | ), |
| 667 | 'display_avatar' => array( |
| 668 | 'type' => 'bool', |
| 669 | 'default' => true |
| 670 | ) |
| 671 | ); |
| 672 | } |
| 673 | public function get_wistia_settings_schema() { |
| 674 | return array( |
| 675 | 'start_time' => [ |
| 676 | 'type' => 'number', |
| 677 | 'default' => 0 |
| 678 | ], |
| 679 | 'display_fullscreen_button' => array( |
| 680 | 'type' => 'bool', |
| 681 | 'default' => true |
| 682 | ), |
| 683 | 'display_playbar' => array( |
| 684 | 'type' => 'bool', |
| 685 | 'default' => true |
| 686 | ), |
| 687 | 'small_play_button' => array( |
| 688 | 'type' => 'bool', |
| 689 | 'default' => true |
| 690 | ), |
| 691 | 'display_volume_control' => array( |
| 692 | 'type' => 'bool', |
| 693 | 'default' => true |
| 694 | ), |
| 695 | 'autoplay' => array( |
| 696 | 'type' => 'bool', |
| 697 | 'default' => false |
| 698 | ), |
| 699 | 'volume' => array( |
| 700 | 'type' => 'text', |
| 701 | 'default' => '100' |
| 702 | ), |
| 703 | 'player_color' => array( |
| 704 | 'type' => 'text', |
| 705 | 'default' => '#00adef', |
| 706 | ), |
| 707 | 'plugin_resumable' => array( |
| 708 | 'type' => 'bool', |
| 709 | 'default' => false |
| 710 | ), |
| 711 | 'plugin_captions' => array( |
| 712 | 'type' => 'bool', |
| 713 | 'default' => false |
| 714 | ), |
| 715 | 'plugin_captions_default' => array( |
| 716 | 'type' => 'bool', |
| 717 | 'default' => false |
| 718 | ), |
| 719 | 'plugin_focus' => array( |
| 720 | 'type' => 'bool', |
| 721 | 'default' => false |
| 722 | ), |
| 723 | 'plugin_rewind' => array( |
| 724 | 'type' => 'bool', |
| 725 | 'default' => false |
| 726 | ), |
| 727 | 'plugin_rewind_time' => array( |
| 728 | 'type' => 'text', |
| 729 | 'default' => '10' |
| 730 | ), |
| 731 | ); |
| 732 | } |
| 733 | public function getVideoIDFromURL ($url) { |
| 734 | // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp |
| 735 | // https://ostraining-1.wistia.com/medias/xf1edjzn92 |
| 736 | preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches); |
| 737 | |
| 738 | $id = false; |
| 739 | if (isset($matches[1])) { |
| 740 | $id = $matches[1]; |
| 741 | } |
| 742 | |
| 743 | return $id; |
| 744 | } |
| 745 | public function embedpress_wistia_block_after_embed( $attributes ){ |
| 746 | $embedOptions= $this->embedpress_wistia_pro_get_options(); |
| 747 | // Get the video ID |
| 748 | $videoId = $this->getVideoIDFromURL($attributes['url']); |
| 749 | $shortVideoId = $videoId; |
| 750 | |
| 751 | $labels = array( |
| 752 | 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'), |
| 753 | 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'), |
| 754 | 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'), |
| 755 | ); |
| 756 | $labels = json_encode($labels); |
| 757 | |
| 758 | |
| 759 | $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>'; |
| 760 | $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n"; |
| 761 | $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n"; |
| 762 | echo $html; |
| 763 | } |
| 764 | public function embedpress_wistia_pro_get_options() { |
| 765 | $options = $this->getOptions('wistia', $this->get_wistia_settings_schema()); |
| 766 | // Embed Options |
| 767 | $embedOptions = new \stdClass; |
| 768 | $embedOptions->videoFoam = true; |
| 769 | $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool)$options['display_fullscreen_button'] === true); |
| 770 | $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool)$options['small_play_button'] === true); |
| 771 | $embedOptions->autoPlay = (isset($options['autoplay']) && (bool)$options['autoplay'] === true); |
| 772 | |
| 773 | if (isset($options['player_color'])) { |
| 774 | $color = $options['player_color']; |
| 775 | if (null !== $color) { |
| 776 | $embedOptions->playerColor = $color; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | // Plugins |
| 781 | $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php'); |
| 782 | |
| 783 | $pluginList = array(); |
| 784 | |
| 785 | // Resumable |
| 786 | if (isset($options['plugin_resumable'])) { |
| 787 | $isResumableEnabled = $options['plugin_resumable']; |
| 788 | if ($isResumableEnabled) { |
| 789 | // Add the resumable plugin |
| 790 | $pluginList['resumable'] = array( |
| 791 | 'src' => '//fast.wistia.com/labs/resumable/plugin.js', |
| 792 | 'async' => false |
| 793 | ); |
| 794 | } |
| 795 | } |
| 796 | // Add a fix for the autoplay and resumable work better together |
| 797 | //@TODO; check baseurl deeply, not looking good |
| 798 | if ($options['autoplay']) { |
| 799 | if ($isResumableEnabled) { |
| 800 | $pluginList['fixautoplayresumable'] = array( |
| 801 | 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js' |
| 802 | ); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | |
| 807 | // Focus plugin |
| 808 | if (isset($options['plugin_focus'])) { |
| 809 | $isFocusEnabled = $options['plugin_focus']; |
| 810 | $pluginList['dimthelights'] = array( |
| 811 | 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js', |
| 812 | 'autoDim' => $isFocusEnabled |
| 813 | ); |
| 814 | $embedOptions->focus = $isFocusEnabled; |
| 815 | } |
| 816 | |
| 817 | $embedOptions->plugin = $pluginList; |
| 818 | $embedOptions = apply_filters( 'embedpress_wistia_params', $embedOptions); |
| 819 | $embedOptions = json_encode($embedOptions); |
| 820 | return apply_filters( 'embedpress_wistia_params_after_encode', $embedOptions); |
| 821 | } |
| 822 | public function get_twitch_settings_schema() { |
| 823 | return [ |
| 824 | 'start_time' => [ |
| 825 | 'type' => 'number', |
| 826 | 'default' => 0, |
| 827 | ], |
| 828 | 'embedpress_pro_twitch_autoplay' => [ |
| 829 | 'type' => 'string', |
| 830 | 'default' => 'no', |
| 831 | ], |
| 832 | 'embedpress_pro_twitch_chat' => [ |
| 833 | 'type' => 'string', |
| 834 | 'default' => 'no', |
| 835 | ], |
| 836 | |
| 837 | 'embedpress_pro_twitch_theme' => [ |
| 838 | 'type' => 'string', |
| 839 | 'default' => 'dark', |
| 840 | ], |
| 841 | 'embedpress_pro_fs' => [ |
| 842 | 'type' => 'string', |
| 843 | 'default' => 'yes', |
| 844 | ], |
| 845 | 'embedpress_pro_twitch_mute' => [ |
| 846 | 'type' => 'string', |
| 847 | 'default' => 'yes', |
| 848 | ], |
| 849 | |
| 850 | ]; |
| 851 | } |
| 852 | public function get_dailymotion_settings_schema() { |
| 853 | return [ |
| 854 | 'autoplay' => [ |
| 855 | 'type' => 'string', |
| 856 | 'default' => '' |
| 857 | ], |
| 858 | 'play_on_mobile' => [ |
| 859 | 'type' => 'string', |
| 860 | 'default' => '' |
| 861 | ], |
| 862 | 'color' => [ |
| 863 | 'type' => 'string', |
| 864 | 'default' => '#dd3333' |
| 865 | ], |
| 866 | 'mute' => [ |
| 867 | 'type' => 'string', |
| 868 | 'default' => '' |
| 869 | ], |
| 870 | 'controls' => [ |
| 871 | 'type' => 'string', |
| 872 | 'default' => '1' |
| 873 | ], |
| 874 | 'video_info' => [ |
| 875 | 'type' => 'string', |
| 876 | 'default' => '1' |
| 877 | ], |
| 878 | 'show_logo' => [ |
| 879 | 'type' => 'string', |
| 880 | 'default' => '1' |
| 881 | ], |
| 882 | 'start_time' => [ |
| 883 | 'type' => 'string', |
| 884 | 'default' => '0' |
| 885 | ], |
| 886 | ]; |
| 887 | } |
| 888 | public function get_soundcloud_settings_schema() { |
| 889 | return [ |
| 890 | 'visual' => [ |
| 891 | 'type' => 'string', |
| 892 | 'default' => '' |
| 893 | ], |
| 894 | 'autoplay' => [ |
| 895 | 'type' => 'string', |
| 896 | 'default' => '' |
| 897 | ], |
| 898 | 'play_on_mobile' => [ |
| 899 | 'type' => 'string', |
| 900 | 'default' => '' |
| 901 | ], |
| 902 | 'color' => [ |
| 903 | 'type' => 'string', |
| 904 | 'default' => '#dd3333' |
| 905 | ], |
| 906 | |
| 907 | 'share_button' => [ |
| 908 | 'type' => 'string', |
| 909 | 'default' => '' |
| 910 | ], |
| 911 | 'comments' => [ |
| 912 | 'type' => 'string', |
| 913 | 'default' => '1' |
| 914 | ], |
| 915 | 'artwork' => [ |
| 916 | 'type' => 'string', |
| 917 | 'default' => '' |
| 918 | ], |
| 919 | 'play_count' => [ |
| 920 | 'type' => 'string', |
| 921 | 'default' => '1' |
| 922 | ], |
| 923 | 'username' => [ |
| 924 | 'type' => 'string', |
| 925 | 'default' => '1' |
| 926 | ], |
| 927 | 'download_button' => [ |
| 928 | 'type' => 'string', |
| 929 | 'default' => '1' |
| 930 | ], |
| 931 | 'buy_button' => [ |
| 932 | 'type' => 'string', |
| 933 | 'default' => '1' |
| 934 | ], |
| 935 | ]; |
| 936 | } |
| 937 | |
| 938 | |
| 939 | } |