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