PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.0.3
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.0.3
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Includes / Classes / Feature_Enhancer.php
embedpress / EmbedPress / Includes / Classes Last commit date
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
Feature_Enhancer.php
815 lines
1 <?php
2 namespace EmbedPress\Includes\Classes;
3
4 class Feature_Enhancer {
5
6 public function __construct() {
7
8 if ( !is_embedpress_pro_active() ) {
9 add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_youtube'] );
10 add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_vimeo'] );
11 add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_wistia'] );
12 add_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_twitch'] );
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
21 }
22
23 public function elementor_setting_init( ) {
24 remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_youtube'] );
25 remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_vimeo'] );
26 remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_wistia'] );
27 remove_filter( 'embedpress:onAfterEmbed', [$this, 'enhance_twitch'] );
28 }
29
30 public function getOptions($provider='', $schema=[])
31 {
32 $options = (array)get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
33 if (empty($options) || (count($options) === 1 && empty($options[0]))) {
34 $options = [];
35
36 foreach ($schema as $fieldSlug => $field) {
37 $value = isset($field['default']) ? $field['default'] : "";
38
39 settype($value, isset($field['type']) && in_array(strtolower($field['type']),
40 ['bool', 'boolean', 'int', 'integer', 'float', 'string']) ? $field['type'] : 'string');
41
42 if ($fieldSlug === "license_key") {
43 $options['license'] = [
44 'key' => true,
45 'status' => "missing",
46 ];
47 } else {
48 $options[$fieldSlug] = $value;
49 }
50 }
51 }
52
53 $options['license'] = [
54 'key' => true,
55 'status' => "missing",
56 ];
57 return apply_filters( 'emebedpress_get_options', $options);
58 }
59 public function get_youtube_params( $options )
60 {
61 $params = [];
62
63 // Handle `autoplay` option.
64 if ( isset( $options[ 'autoplay' ] ) && (bool)$options[ 'autoplay' ] === true ) {
65 $params[ 'autoplay' ] = 1;
66 } else {
67 unset( $params[ 'autoplay' ] );
68 }
69
70 // Handle `controls` option.
71 if ( isset( $options[ 'controls' ] ) && in_array( (int)$options[ 'controls' ], [0, 1, 2] ) ) {
72 $params[ 'controls' ] = (int)$options[ 'controls' ];
73 } else {
74 unset( $params[ 'controls' ] );
75 }
76
77 // Handle `fs` option.
78 if ( isset( $options[ 'fs' ] ) && in_array( (int)$options[ 'fs' ], [0, 1] ) ) {
79 $params[ 'fs' ] = (int)$options[ 'fs' ];
80 } else {
81 unset( $params[ 'fs' ] );
82 }
83
84 // Handle `iv_load_policy` option.
85 if ( isset( $options[ 'iv_load_policy' ] ) && in_array( (int)$options[ 'iv_load_policy' ], [1, 3] ) ) {
86 $params[ 'iv_load_policy' ] = (int)$options[ 'iv_load_policy' ];
87 } else {
88 unset( $params[ 'iv_load_policy' ] );
89 }
90
91 return apply_filters( 'embedpress_youtube_params', $params);
92
93 }
94 public function get_vimeo_params($options) {
95 $params = [];
96
97 // Handle `display_title` option.
98 if (isset($options['display_title']) && (bool)$options['display_title'] === true) {
99 $params['title'] = 1;
100 } else {
101 $params['title'] = 0;
102 }
103
104 // Handle `autoplay` option.
105 if (!empty($options['autoplay'])) {
106 $params['autoplay'] = 1;
107 } else {
108 unset($params['autoplay']);
109 }
110
111 // Handle `color` option.
112 if (!empty($options['color'])) {
113 $params['color'] = str_replace('#', '', $options['color']);
114 } else {
115 unset($params['color']);
116 }
117 return apply_filters( 'embedpress_vimeo_params', $params);
118
119 }
120
121 public function enhance_youtube( $embed )
122 {
123 $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');
124
125 if ( $isYoutube && isset( $embed->embed )
126 && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) {
127 // for compatibility only, @TODO; remove later after deep testing.
128 $options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
129 // Parse the url to retrieve all its info like variables etc.
130 $url_full = $match[ 1 ];
131 $query = parse_url( $url_full, PHP_URL_QUERY );
132 parse_str( $query, $params );
133
134 // Handle `autoplay` option.
135 if ( isset( $options[ 'autoplay' ] ) && (bool)$options[ 'autoplay' ] === true ) {
136 $params[ 'autoplay' ] = 1;
137 } else {
138 unset( $params[ 'autoplay' ] );
139 }
140
141 // Handle `controls` option.
142 if ( isset( $options[ 'controls' ] ) && in_array( (int)$options[ 'controls' ], [0, 1, 2] ) ) {
143 $params[ 'controls' ] = (int)$options[ 'controls' ];
144 } else {
145 unset( $params[ 'controls' ] );
146 }
147
148 // Handle `fs` option.
149 if ( isset( $options[ 'fs' ] ) && in_array( (int)$options[ 'fs' ], [0, 1] ) ) {
150 $params[ 'fs' ] = (int)$options[ 'fs' ];
151 } else {
152 unset( $params[ 'fs' ] );
153 }
154
155 // Handle `iv_load_policy` option.
156 if ( isset( $options[ 'iv_load_policy' ] ) && in_array( (int)$options[ 'iv_load_policy' ], [1, 3] ) ) {
157 $params[ 'iv_load_policy' ] = (int)$options[ 'iv_load_policy' ];
158 } else {
159 unset( $params[ 'iv_load_policy' ] );
160 }
161
162
163 // pro controls will be handled by the pro so remove it from the free.
164 $pro_controls = ['color', 'cc_load_policy', 'rel', 'modestbranding'];
165 foreach ( $pro_controls as $pro_control ) {
166 if ( isset( $params[ $pro_control ]) ) {
167 unset( $params[ $pro_control ]);
168 }
169 }
170
171
172 preg_match( '/(.+)?\?/', $url_full, $url );
173 $url = $url[ 1 ];
174
175 // Reassemble the url with the new variables.
176 $url_modified = $url . '?';
177 foreach ( $params as $paramName => $paramValue ) {
178 $url_modified .= $paramName . '=' . $paramValue . '&';
179 }
180
181 // Replaces the old url with the new one.
182 $embed->embed = str_replace( $url_full, rtrim( $url_modified, '&' ), $embed->embed );
183
184 }
185
186 return $embed;
187 }
188 public function enhance_vimeo( $embed ) {
189 if ( isset( $embed->provider_name )
190 && strtoupper( $embed->provider_name ) === 'VIMEO'
191 && isset( $embed->embed )
192 && preg_match( '/src=\"(.+?)\"/', $embed->embed, $match ) ) {
193 // old schema is for backward compatibility only @todo; remove it in the next version after deep test
194 $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
195
196 $url_full = $match[1];
197 $params = [];
198
199 // Handle `display_title` option.
200 if ( isset( $options['display_title'] ) && (bool)$options['display_title'] === true ) {
201 $params['title'] = 1;
202 } else {
203 $params['title'] = 0;
204 }
205
206 // Handle `autoplay` option.
207 if ( isset( $options['autoplay'] ) && (bool)$options['autoplay'] === true ) {
208 $params['autoplay'] = 1;
209 } else {
210 unset( $params['autoplay'] );
211 }
212
213 // Handle `color` option.
214 if ( !empty( $options['color'] ) ) {
215 $params['color'] = str_replace( '#', '', $options['color'] );
216 } else {
217 unset( $params['color'] );
218 }
219 // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only
220 //@todo; maybe extract unsetting pro vars to a function later
221 $pro_controls = ['loop', 'autopause', 'dnt', 'portrait', 'byline'];
222 foreach ( $pro_controls as $pro_control ) {
223 if ( isset( $params[ $pro_control ]) ) {
224 unset( $params[ $pro_control ]);
225 }
226 }
227 // Reassemble the url with the new variables.
228 $url_modified = $url_full;
229 foreach ( $params as $param => $value ) {
230 $url_modified = add_query_arg( $param, $value, $url_modified );
231 }
232 do_action( 'embedpress_after_modified_url', $url_modified, $url_full, $params);
233 // Replaces the old url with the new one.
234 $embed->embed = str_replace( $url_full, $url_modified, $embed->embed );
235
236 }
237
238 return $embed;
239 }
240 public function enhance_wistia( $embed ) {
241 if (isset($embed->provider_name)
242 && strtoupper($embed->provider_name) === 'WISTIA, INC.'
243 && isset($embed->embed)
244 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)) {
245 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
246
247 $url_full = $match[1];
248
249 // Parse the url to retrieve all its info like variables etc.
250 $query = parse_url($embed->url, PHP_URL_QUERY);
251 $url = str_replace('?'.$query, '', $url_full);
252
253 parse_str($query, $params);
254
255 // Set the class in the attributes
256 $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class);
257 $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed);
258
259 // Embed Options
260 $embedOptions = new \stdClass;
261 $embedOptions->videoFoam = true;
262 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
263 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
264
265 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
266
267
268 if (isset($options['player_color'])) {
269 $color = $options['player_color'];
270 if (null !== $color) {
271 $embedOptions->playerColor = $color;
272 }
273 }
274
275 // Plugins
276 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__).'/embedpress-Wistia.php');
277
278 $pluginList = array();
279
280 // Resumable
281 if (isset($options['plugin_resumable'])) {
282 $isResumableEnabled = $options['plugin_resumable'];
283 if ($isResumableEnabled) {
284 // Add the resumable plugin
285 $pluginList['resumable'] = array(
286 'src' => $pluginsBaseURL.'/resumable.min.js',
287 'async' => false
288 );
289 }
290 }
291
292 // Add a fix for the autoplay and resumable work better together
293 if (isset($options->autoPlay)) {
294 if ($isResumableEnabled) {
295 $pluginList['fixautoplayresumable'] = array(
296 'src' => $pluginsBaseURL.'/fixautoplayresumable.min.js'
297 );
298 }
299 }
300
301 // Focus plugin
302 if (isset($options['plugin_focus'])) {
303 $isFocusEnabled = $options['plugin_focus'];
304 $pluginList['dimthelights'] = array(
305 'src' => $pluginsBaseURL.'/dimthelights.min.js',
306 'autoDim' => $isFocusEnabled
307 );
308 $embedOptions->focus = $isFocusEnabled;
309 }
310
311
312 $embedOptions->plugin = $pluginList;
313 $embedOptions = json_encode($embedOptions);
314
315 // Get the video ID
316 $videoId = $this->getVideoIDFromURL($embed->url);
317 $shortVideoId = substr($videoId, 0, 3);
318
319 // Responsive?
320
321 $class = array(
322 'wistia_embed',
323 'wistia_async_'.$videoId
324 );
325
326 $attribs = array(
327 sprintf('id="wistia_%s"', $videoId),
328 sprintf('class="%s"', join(' ', $class)),
329 sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height)
330 );
331
332 $labels = array(
333 'watch_from_beginning' => __('Watch from the beginning', 'embedpress-wistia'),
334 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress-wistia'),
335 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!',
336 'embedpress-wistia'),
337 );
338 $labels = json_encode($labels);
339
340 preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches);
341 $uid = $matches[1];
342
343 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
344 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
345 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
346 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
347 $html .= '<div '.join(' ', $attribs)."></div>\n";
348 $html .= '</div>';
349 $embed->embed = $html;
350 }
351
352 return $embed;
353 }
354 public function enhance_twitch( $embed_content ) {
355 $e = isset( $embed_content->url) && isset( $embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : [];
356 if ( isset( $e['provider_name'] ) && strtoupper( $e['provider_name'] ) === 'TWITCH' && isset( $embed_content->embed ) ) {
357 $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema());
358
359 $atts = isset( $embed_content->attributes) ? $embed_content->attributes : [];
360 $type = $e['type'];
361 $content_id = $e['content_id'];
362 $channel = 'channel' === $type ? $content_id : '';
363 $video = 'video' === $type ? $content_id : '';
364 $full_screen = ('yes' === $settings['embedpress_pro_fs']) ? 'true': 'false';
365 $autoplay = ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true': 'false';
366 $layout = 'video';
367 $width = !empty( $atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800;
368 $height = !empty( $atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450;
369
370 $url = "https://embed.twitch.tv?autoplay={$autoplay}&channel={$channel}&height={$height}&layout={$layout}&migration=true&video={$video}&width={$width}&allowfullscreen={$full_screen}";
371 $pars_url = wp_parse_url(get_site_url());
372 $url = !empty($pars_url['host'])?$url.'&parent='.$pars_url['host']:$url;
373 ob_start();
374 ?>
375 <div class="embedpress_wrapper" data-url="<?php echo esc_attr(esc_url( $embed_content->url));?>">
376 <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>
377 </div>
378 <?php
379 $c = ob_get_clean();
380 $embed_content->embed = $c;
381 }
382
383 return $embed_content;
384 }
385
386 public function embedpress_gutenberg_register_block_youtube( $youtube_params ) {
387 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
388 return $this->get_youtube_params( $youtube_options );
389 }
390 public function embedpress_gutenberg_register_block_vimeo() {
391 if ( function_exists( 'register_block_type' ) ) :
392 register_block_type( 'embedpress/vimeo-block', array(
393 'attributes' => array(
394 'url' => array(
395 'type' => 'string',
396 'default' => ''
397 ),
398 'iframeSrc' => array(
399 'type' => 'string',
400 'default' => ''
401 ),
402 ),
403 'render_callback' => [ $this, 'embedpress_gutenberg_render_block_vimeo' ]
404 ) );
405 endif;
406 }
407 public function embedpress_gutenberg_render_block_vimeo( $attributes ) {
408 ob_start();
409 if ( !empty( $attributes ) && !empty( $attributes['iframeSrc'] ) ) :
410 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
411 $vimeo_params = $this->get_vimeo_params( $vimeo_options );
412 $iframeUrl = $attributes['iframeSrc'];
413 $align = 'align' . ( isset( $attributes[ 'align' ] ) ? $attributes[ 'align' ] : 'center' );
414 foreach ( $vimeo_params as $param => $value ) {
415 $iframeUrl = add_query_arg( $param, $value, $iframeUrl );
416 }
417 //@TODO; test responsive without static height width, keeping for now backward compatibility
418 ?>
419 <div class="ose-vimeo wp-block-embed-vimeo <?php echo $align; ?>">
420 <iframe src="<?php echo $iframeUrl; ?>" allowtransparency="true" frameborder="0" width="640" height="360">
421 </iframe>
422 </div>
423 <?php
424 endif;
425
426 return apply_filters( 'embedpress_gutenberg_block_markup', ob_get_clean());
427 }
428 public function get_youtube_settings_schema() {
429 return [
430 'autoplay' => [
431 'type' => 'bool',
432 'label' => 'Auto Play',
433 'description' => 'Automatically start to play the videos when the player loads.',
434 'default' => false
435 ],
436 'color' => [
437 'type' => 'string',
438 'label' => 'Progress bar color',
439 'description' => 'Specifies the color that will be used in the player\'s video progress bar to highlight the amount of the video that the viewer has already seen.<br/>Note: Setting the color to <strong>white</strong> will disable the <strong>Modest Branding</strong> option (causing a YouTube logo to be displayed in the control bar).',
440 'options' => [
441 'red' => 'Red',
442 'white' => 'White'
443 ],
444 'default' => 'red'
445 ],
446 'cc_load_policy' => [
447 'type' => 'bool',
448 'label' => 'Force Closed Captions',
449 'description' => 'Setting this option to <strong>Yes</strong> causes closed captions to be shown by default, even if the user has turned captions off. This will be based on user preference otherwise.',
450 'default' => false
451 ],
452 'controls' => [
453 'type' => 'string',
454 'label' => 'Display Controls',
455 'description' => 'Indicates whether the video player controls are displayed.',
456 'options' => [
457 '1' => 'Display immediately',
458 '2' => 'Display after user initiation',
459 '0' => 'Hide controls',
460 ],
461 'default' => '1'
462 ],
463 'fs' => [
464 'type' => 'bool',
465 'label' => 'Enable Fullscreen button',
466 'description' => 'Indicates whether the fullscreen button is enabled.',
467 'default' => true
468 ],
469 'iv_load_policy' => [
470 'type' => 'radio',
471 'label' => 'Display video annotations',
472 'description' => 'Indicates whether video annotations are displayed.',
473 'options' => [
474 '1' => 'Display',
475 '3' => 'Do not display'
476 ],
477 'default' => '1'
478 ],
479 'rel' => [
480 'type' => 'bool',
481 'label' => 'Display related videos',
482 'description' => 'Indicates whether the player should show related videos when playback of the initial video ends.',
483 'default' => true
484 ],
485 'modestbranding' => [
486 'type' => 'string',
487 'label' => 'Modest Branding',
488 'description' => 'Indicates whether the player should display a YouTube logo in the control bar.',
489 'options' => [
490 '0' => 'Display',
491 '1' => 'Do not display'
492 ],
493 'default' => '0'
494 ],
495 'logo_url' => [
496 'type' => 'url',
497 'label' => __('Custom Logo URL', 'embedpress-pro'),
498 'description' => __('You can show custom logo watermark on your video', 'embedpress-pro'),
499 ],
500 'logo_xpos' => [
501 'type' => 'number',
502 'label' => __( 'Logo X Position (%)', 'embedpress-pro' ),
503 'description' => __( 'Change this number to move your logo in horizontal direction.', 'embedpress-pro' ),
504 'default' => 10
505 ],
506 'logo_ypos' => [
507 'type' => 'number',
508 'label' => __( 'Logo Y Position (%)', 'embedpress-pro' ),
509 'description' => __( 'Change this number to move your logo in vertical direction.', 'embedpress-pro' ),
510 'default' => 10
511 ],
512 'cta_url' => [
513 'type' => 'url',
514 'label' => __( 'CTA link for Logo', 'embedpress-pro' ),
515 'description' => __( 'You can show the logo inside a link. Leave it empty to hide it', 'embedpress-pro' ),
516 ],
517 ];
518 }
519 public function get_vimeo_settings_schema() {
520 return array(
521 'autoplay' => array(
522 'type' => 'bool',
523 'label' => 'Autoplay',
524 'description' => 'Automatically start to play the videos when the player loads.',
525 'default' => false
526 ),
527 'loop' => array(
528 'type' => 'bool',
529 'label' => 'Loop',
530 'description' => 'Play the video again automatically when it reaches the end.',
531 'default' => false
532 ),
533 'autopause' => array(
534 'type' => 'bool',
535 'label' => 'Autopause',
536 'description' => 'Pause this video automatically when another one plays.',
537 'default' => false
538 ),
539 'vimeo_dnt' => array(
540 'type' => 'bool',
541 'label' => 'DNT',
542 'description' => 'Setting this parameter to "yes" will block the player from tracking any session data, including all cookies',
543 'default' => true,
544 ),
545 'color' => array(
546 'type' => 'text',
547 'label' => 'Color',
548 'description' => 'Specify the color of the video controls.',
549 'default' => '#00adef',
550 'classes' => 'color-field'
551 ),
552 'display_title' => array(
553 'type' => 'bool',
554 'label' => 'Display Title',
555 'description' => 'Indicates whether the title is displayed.',
556 'default' => true
557 ),
558 'display_author' => array(
559 'type' => 'bool',
560 'label' => 'Display Author',
561 'description' => 'Indicates whether the author is displayed.',
562 'default' => true
563 ),
564 'display_avatar' => array(
565 'type' => 'bool',
566 'label' => 'Display Avatar',
567 'description' => 'Indicates whether the avatar is displayed.',
568 'default' => true
569 )
570 );
571 }
572 public function get_wistia_settings_schema() {
573 $schema = array(
574 'display_fullscreen_button' => array(
575 'type' => 'bool',
576 'label' => __('Fullscreen Button', 'embedpress-wistia'),
577 'description' => __('Indicates whether the fullscreen button is visible.', 'embedpress-wistia'),
578 'default' => true
579 ),
580 'display_playbar' => array(
581 'type' => 'bool',
582 'label' => __('Playbar', 'embedpress-wistia'),
583 'description' => __('Indicates whether the playbar is visible.', 'embedpress-wistia'),
584 'default' => true
585 ),
586 'small_play_button' => array(
587 'type' => 'bool',
588 'label' => __('Small Play Button', 'embedpress-wistia'),
589 'description' => __('Indicates whether the small play button is visible on the bottom left.',
590 'embedpress-wistia'),
591 'default' => true
592 ),
593 'display_volume_control' => array(
594 'type' => 'bool',
595 'label' => __('Volume Control', 'embedpress-wistia'),
596 'description' => __('Indicates whether the volume control is visible.', 'embedpress-wistia'),
597 'default' => true
598 ),
599 'autoplay' => array(
600 'type' => 'bool',
601 'label' => __('Auto Play', 'embedpress-wistia'),
602 'description' => __('Automatically start to play the videos when the player loads.',
603 'embedpress-wistia'),
604 'default' => false
605 ),
606 'volume' => array(
607 'type' => 'text',
608 'label' => __('Volume', 'embedpress-wistia'),
609 'description' => __('Start the video with a custom volume level. Set values between 0 and 100.',
610 'embedpress-wistia'),
611 'default' => '100'
612 ),
613 'player_color' => array(
614 'type' => 'text',
615 'label' => __('Color', 'embedpress-wistia'),
616 'description' => __('Specify the color of the video controls.', 'embedpress-wistia'),
617 'default' => '#00adef',
618 'classes' => 'color-field'
619 ),
620 'plugin_resumable' => array(
621 'type' => 'bool',
622 'label' => __('Plugin: Resumable', 'embedpress-wistia'),
623 'description' => __('Indicates whether the Resumable plugin is active. Allow to resume the video or start from the begining.',
624 'embedpress-wistia'),
625 'default' => false
626 ),
627 'plugin_captions' => array(
628 'type' => 'bool',
629 'label' => __('Plugin: Captions', 'embedpress-wistia'),
630 'description' => __('Indicates whether the Captions plugin is active.', 'embedpress-wistia'),
631 'default' => false
632 ),
633 'plugin_captions_default' => array(
634 'type' => 'bool',
635 'label' => __('Captions Enabled By Default', 'embedpress-wistia'),
636 'description' => __('Indicates whether the Captions are enabled by default.', 'embedpress-wistia'),
637 'default' => false
638 ),
639 'plugin_focus' => array(
640 'type' => 'bool',
641 'label' => __('Plugin: Focus', 'embedpress-wistia'),
642 'description' => __('Indicates whether the Focus plugin is active.', 'embedpress-wistia'),
643 'default' => false
644 ),
645 'plugin_rewind' => array(
646 'type' => 'bool',
647 'label' => __('Plugin: Rewind', 'embedpress-wistia'),
648 'description' => __('Indicates whether the Rewind plugin is active.', 'embedpress-wistia'),
649 'default' => false
650 ),
651 'plugin_rewind_time' => array(
652 'type' => 'text',
653 'label' => __('Rewind time (seconds)', 'embedpress-wistia'),
654 'description' => __('The amount of time to rewind, in seconds.', 'embedpress-wistia'),
655 'default' => '10'
656 ),
657 );
658
659 return $schema;
660 }
661 public function getVideoIDFromURL ($url) {
662 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
663 // https://ostraining-1.wistia.com/medias/xf1edjzn92
664 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
665
666 $id = false;
667 if (isset($matches[1])) {
668 $id = $matches[1];
669 }
670
671 return $id;
672 }
673
674 public function embedpress_wistia_block_after_embed( $attributes ){
675 $embedOptions= $this->embedpress_wisita_pro_get_options();
676 // Get the video ID
677 $videoId = $this->getVideoIDFromURL($attributes['url']);
678 $shortVideoId = $videoId;
679
680 $labels = array(
681 'watch_from_beginning' => __('Watch from the beginning', 'embedpress-wistia'),
682 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress-wistia'),
683 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress-wistia'),
684 );
685 $labels = json_encode($labels);
686
687
688 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
689 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
690 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
691 echo $html;
692 }
693 public function embedpress_wisita_pro_get_options() {
694 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
695 // Embed Options
696 $embedOptions = new \stdClass;
697 $embedOptions->videoFoam = true;
698 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool)$options['display_fullscreen_button'] === true);
699 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool)$options['small_play_button'] === true);
700 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool)$options['autoplay'] === true);
701
702 if (isset($options['player_color'])) {
703 $color = $options['player_color'];
704 if (null !== $color) {
705 $embedOptions->playerColor = $color;
706 }
707 }
708
709 // Plugins
710 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
711
712 $pluginList = array();
713
714 // Resumable
715 if (isset($options['plugin_resumable'])) {
716 $isResumableEnabled = $options['plugin_resumable'];
717 if ($isResumableEnabled) {
718 // Add the resumable plugin
719 $pluginList['resumable'] = array(
720 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
721 'async' => false
722 );
723 }
724 }
725 // Add a fix for the autoplay and resumable work better together
726 //@TODO; check baseurl deeply, not looking good
727 if ($options['autoplay']) {
728 if ($isResumableEnabled) {
729 $pluginList['fixautoplayresumable'] = array(
730 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
731 );
732 }
733 }
734
735
736 // Focus plugin
737 if (isset($options['plugin_focus'])) {
738 $isFocusEnabled = $options['plugin_focus'];
739 $pluginList['dimthelights'] = array(
740 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
741 'autoDim' => $isFocusEnabled
742 );
743 $embedOptions->focus = $isFocusEnabled;
744 }
745
746 $embedOptions->plugin = $pluginList;
747 $embedOptions = apply_filters( 'embedpress_wistia_params', $embedOptions);
748 $embedOptions = json_encode($embedOptions);
749 return apply_filters( 'embedpress_wistia_params_after_encode', $embedOptions);
750 }
751
752 public function get_twitch_settings_schema() {
753 return [
754 'embedpress_pro_video_start_time' => [
755 'type' => 'number',
756 'label' => __( 'Start Time (in Seconds)', 'embedpress-pro' ),
757 'description' => __( 'You can put a custom time in seconds to start the video from. Example: 500', 'embedpress-pro' ),
758 'default' => 0,
759 ],
760 'embedpress_pro_twitch_autoplay' => [
761 'type' => 'string',
762 'label' => __( 'Auto Play', 'embedpress-pro' ),
763 'description' => __( 'Automatically start to play the videos when the player loads.', 'embedpress-pro' ),
764 'options' => [
765 'yes' => __( 'Yes', 'embedpress-pro' ),
766 'no' => __( 'No', 'embedpress-pro' ),
767 ],
768 'default' => 'no',
769 ],
770 'embedpress_pro_twitch_chat' => [
771 'type' => 'string',
772 'label' => __( 'Show chat', 'embedpress-pro' ),
773 'description' => __( 'You can show or hide chat using this settings' ),
774 'options' => [
775 'yes' => __( 'Yes', 'embedpress-pro' ),
776 'no' => __( 'No', 'embedpress-pro' ),
777 ],
778 'default' => 'no',
779 ],
780
781 'embedpress_pro_twitch_theme' => [
782 'type' => 'string',
783 'label' => __( 'Theme', 'embedpress-pro' ),
784 'description' => __( 'Set dark or light theme for the twitch comment', 'embedpress-pro' ),
785 'options' => [
786 'dark' => __( 'Dark', 'embedpress-pro' ),
787 'light' => __( 'Light', 'embedpress-pro' ),
788 ],
789 'default' => 'dark',
790 ],
791 'embedpress_pro_fs' => [
792 'type' => 'string',
793 'label' => 'Enable Fullscreen button',
794 'description' => __( 'Indicates whether the fullscreen button is enabled.', 'embedpress-pro' ),
795 'options' => [
796 'yes' => __( 'Yes', 'embedpress-pro' ),
797 'no' => __( 'No', 'embedpress-pro' ),
798 ],
799 'default' => 'yes',
800 ],
801 'embedpress_pro_twitch_mute' => [
802 'type' => 'string',
803 'label' => __( 'Mute on start', 'embedpress-pro' ),
804 'description' => __( 'Set it to Yes to mute the video on start.', 'embedpress-pro' ),
805 'options' => [
806 'yes' => __( 'Yes', 'embedpress-pro' ),
807 'no' => __( 'No', 'embedpress-pro' ),
808 ],
809 'default' => 'yes',
810 ],
811
812 ];
813 }
814
815 }