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