PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.9.15
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.9.15
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 2 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 2 years ago EmbedPress_Plugin_Usage_Tracker.php 2 years ago Extend_CustomPlayer_Controls.php 3 years ago Extend_Elementor_Controls.php 2 years ago Feature_Enhancer.php 2 years ago Helper.php 2 years ago
Feature_Enhancer.php
1615 lines
1 <?php
2
3 namespace EmbedPress\Includes\Classes;
4
5 use \EmbedPress\Providers\Youtube;
6 use EmbedPress\Shortcode;
7 use EmbedPress\Includes\Classes\Helper;
8 use \Elementor\Controls_Manager;
9 use EmbedPress\Providers\TikTok;
10 use EmbedPress\Providers\Wrapper;
11
12 class Feature_Enhancer
13 {
14 public static $attributes_data;
15
16 public function __construct()
17 {
18 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
19 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
20 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
21 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
22 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
23 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
24 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_missing_title'], 90);
25
26 add_filter(
27 'embedpress_gutenberg_youtube_params',
28 [$this, 'embedpress_gutenberg_register_block_youtube']
29 );
30
31 add_action('init', array($this, 'embedpress_gutenberg_register_block_vimeo'));
32 add_action('embedpress_gutenberg_wistia_block_after_embed', array($this, 'embedpress_wistia_block_after_embed'));
33 add_action('elementor/widget/embedpres_elementor/skins_init', [$this, 'elementor_setting_init']);
34 add_action('wp_ajax_youtube_rest_api', [$this, 'youtube_rest_api']);
35 add_action('wp_ajax_nopriv_youtube_rest_api', [$this, 'youtube_rest_api']);
36 add_action('embedpress_gutenberg_embed', [$this, 'gutenberg_embed'], 10, 2);
37 add_action('wp_ajax_save_source_data', [$this, 'save_source_data']);
38 add_action('save_post', [$this, 'save_source_data_on_post_update'], 10, 3);
39 add_action('wp_ajax_delete_source_data', [$this, 'delete_source_data']);
40 add_action('load-post.php', [$this, 'delete_source_temp_data_on_reload']);
41 add_action('embedpress:isEmbra', [$this, 'isEmbra'], 10, 3);
42 add_action('elementor/editor/after_save', [$this, 'save_el_source_data_on_post_update']);
43
44 add_action('wp_head', [$this, 'embedpress_generate_social_share_meta']);
45
46 add_action('wp_ajax_get_viewer', function () {
47 $pdf = EMBEDPRESS_PATH_BASE . 'assets/pdf/web/viewer.html';
48 // header type html
49 header('Content-Type: text/html');
50 $contents = file_get_contents($pdf);
51 echo str_replace('<head>', '<head><base href="' . EMBEDPRESS_URL_ASSETS . 'pdf/web/' . '">', $contents);
52 die;
53 });
54 add_action('wp_ajax_nopriv_get_viewer', function () {
55 $pdf = EMBEDPRESS_PATH_BASE . 'assets/pdf/web/viewer.html';
56 // header type html
57 header('Content-Type: text/html');
58 $contents = file_get_contents($pdf);
59 echo str_replace('<head>', '<head><base href="' . EMBEDPRESS_URL_ASSETS . 'pdf/web/' . '">', $contents);
60 die;
61 });
62 }
63
64 public function save_source_data()
65 {
66 if (!isset($_POST['_source_nonce']) || !wp_verify_nonce($_POST['_source_nonce'], 'source_nonce_embedpress')) {
67 return;
68 }
69
70 if (!current_user_can('manage_options')) {
71 return;
72 }
73
74 $source_url = isset($_POST['source_url']) ? $_POST['source_url'] : null;
75 $blockid = isset($_POST['block_id']) ? $_POST['block_id'] : null;
76
77
78 Helper::get_source_data($blockid, $source_url, 'gutenberg_source_data', 'gutenberg_temp_source_data');
79 }
80
81 function save_el_source_data_on_post_update($post_id)
82 {
83 Helper::get_save_source_data_on_post_update('elementor_source_data', 'elementor_temp_source_data');
84 }
85
86 function save_source_data_on_post_update($post_id, $post, $update)
87 {
88 if (!empty(strpos($post->post_content, 'wp:embedpress'))) {
89 Helper::get_save_source_data_on_post_update('gutenberg_source_data', 'gutenberg_temp_source_data');
90 }
91 }
92
93 public function delete_source_data()
94 {
95 if (!isset($_POST['_source_nonce']) || !wp_verify_nonce($_POST['_source_nonce'], 'source_nonce_embedpress')) {
96 return;
97 }
98 if (!current_user_can('manage_options')) {
99 return;
100 }
101
102 $blockid = isset($_POST['block_id']) ? $_POST['block_id'] : '';
103
104 Helper::get_delete_source_data($blockid, 'gutenberg_source_data', 'gutenberg_temp_source_data');
105 }
106
107 public function delete_source_temp_data_on_reload()
108 {
109 Helper::get_delete_source_temp_data_on_reload('gutenberg_temp_source_data');
110 }
111
112 public function isEmbra($isEmbra, $url, $atts)
113 {
114
115 if (strpos($url, 'youtube.com') !== false) {
116 $youtube = new Youtube($url, $atts);
117 if ($youtube->validateUrl($youtube->getUrl(false))) {
118 return true;
119 }
120 }
121 if (strpos($url, 'tiktok.com') !== false) {
122 $tiktok = new TikTok($url, $atts);
123 if ($tiktok->validateUrl($tiktok->getUrl(false))) {
124 return true;
125 }
126 }
127
128 if (strpos($url, site_url()) !== false) {
129 $wrapper = new Wrapper($url, $atts);
130 if ($wrapper->validateUrl($wrapper->getUrl(false))) {
131 return true;
132 }
133 }
134
135 return $isEmbra;
136 }
137
138 public function youtube_rest_api()
139 {
140 $result = Youtube::get_gallery_page([
141 'playlistId' => isset($_POST['playlistid']) ? sanitize_text_field($_POST['playlistid']) : null,
142 'pageToken' => isset($_POST['pagetoken']) ? sanitize_text_field($_POST['pagetoken']) : null,
143 'pagesize' => isset($_POST['pagesize']) ? sanitize_text_field($_POST['pagesize']) : null,
144 'currentpage' => isset($_POST['currentpage']) ? sanitize_text_field($_POST['currentpage']) : null,
145 'columns' => isset($_POST['epcolumns']) ? sanitize_text_field($_POST['epcolumns']) : null,
146 'showTitle' => isset($_POST['showtitle']) ? sanitize_text_field($_POST['showtitle']) : null,
147 'showPaging' => isset($_POST['showpaging']) ? sanitize_text_field($_POST['showpaging']) : null,
148 'autonext' => isset($_POST['autonext']) ? sanitize_text_field($_POST['autonext']) : null,
149 'thumbplay' => isset($_POST['thumbplay']) ? sanitize_text_field($_POST['thumbplay']) : null,
150 'thumbnail_quality' => isset($_POST['thumbnail_quality']) ? sanitize_text_field($_POST['thumbnail_quality']) : null,
151 ]);
152
153 wp_send_json($result);
154 }
155
156
157 //Check is YouTube single video
158 public function ytValidateUrl($url)
159 {
160 return (bool) (preg_match('~v=(?:[a-z0-9_\-]+)~i', (string) $url));
161 }
162
163 //Check is YouTube live video
164 public function ytValidateLiveUrl($url)
165 {
166 return (bool) (preg_match('/^https?:\/\/(?:www\.)?youtube\.com\/(?:channel\/[\w-]+|@[\w-]+)\/live$/', (string) $url));
167 }
168
169
170 //Check is Wistia validate url
171 public function wistiaValidateUrl($url)
172 {
173 return (bool) (preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', (string) $url));
174 }
175
176 //Check is Wistia validate url
177 public function vimeoValidateUrl($url)
178 {
179 return (bool) preg_match('/https?:\/\/(www\.)?vimeo\.com\/\d+/', (string) $url);
180 }
181
182
183
184 // Get wistia block attributes
185 public function get_wistia_block_attributes($attributes)
186 {
187
188 // Embed Options
189 $embedOptions = new \stdClass;
190 $embedOptions->videoFoam = false;
191 $embedOptions->fullscreenButton = (isset($attributes['wfullscreen']) && (bool) $attributes['wfullscreen'] === true);
192 $embedOptions->playbar = (isset($attributes['playbar']) && (bool) $attributes['playbar'] === true);
193
194 $embedOptions->playButton = (isset($attributes['playbutton']) && (bool) $attributes['playbutton'] === true);
195 $embedOptions->smallPlayButton = (isset($attributes['smallplaybutton']) && (bool) $attributes['smallplaybutton'] === true);
196
197 $embedOptions->autoPlay = (isset($attributes['wautoplay']) && (bool) $attributes['wautoplay'] === true);
198 $embedOptions->resumable = (isset($attributes['resumable']) && (bool) $attributes['resumable'] === true);
199
200 if (!empty($attributes['wstarttime'])) {
201 $embedOptions->time = isset($attributes['wstarttime']) ? $attributes['wstarttime'] : '';
202 }
203
204 if (is_embedpress_pro_active()) {
205 $embedOptions->volumeControl = (isset($attributes['volumecontrol']) && (bool) $attributes['volumecontrol'] === true);
206
207 $volume = isset($attributes['volume']) ? (float) $attributes['volume'] : 0;
208
209 if ($volume > 1) {
210 $volume = $volume / 100;
211 }
212 $embedOptions->volume = $volume;
213 }
214
215 $pluginList = [];
216
217 if (isset($attributes['scheme'])) {
218 $color = $attributes['scheme'];
219 if (null !== $color) {
220 $embedOptions->playerColor = $color;
221 }
222 }
223
224 // Closed Captions plugin
225 if ($attributes['captions'] === true) {
226 $isCaptionsEnabled = ($attributes['captions'] === true);
227 $isCaptionsEnabledByDefault = ($attributes['captions'] === true);
228 if ($isCaptionsEnabled) {
229 $pluginList['captions-v1'] = [
230 'onByDefault' => $isCaptionsEnabledByDefault,
231 ];
232 }
233 $embedOptions->captions = $isCaptionsEnabled;
234 $embedOptions->captionsDefault = $isCaptionsEnabledByDefault;
235 }
236
237 $embedOptions->plugin = $pluginList;
238
239
240
241 return json_encode($embedOptions);
242 }
243
244 public function gutenberg_embed($embedHTML, $attributes)
245 {
246 if (!empty($attributes['url'])) {
247 $youtube = new Youtube($attributes['url']);
248
249 $is_youtube = $youtube->validateUrl($youtube->getUrl(false));
250 if ($is_youtube && empty($this->ytValidateLiveUrl($attributes['url']))) {
251 $atts = [
252 'width' => intval($attributes['width']),
253 'height' => intval($attributes['height']),
254 'pagesize' => isset($attributes['pagesize']) ? intval($attributes['pagesize']) : 6,
255 'columns' => isset($attributes['columns']) ? intval($attributes['columns']) : 3,
256 'ispagination' => isset($attributes['ispagination']) ? $attributes['ispagination'] : 0,
257 'gapbetweenvideos' => isset($attributes['gapbetweenvideos']) ? $attributes['gapbetweenvideos'] : 30,
258 ];
259
260 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
261
262 if (!empty($urlInfo->embed)) {
263 $embedHTML = $urlInfo->embed;
264 }
265 }
266
267 if (!empty($attributes['url']) && ($this->ytValidateUrl($attributes['url']) || $this->ytValidateLiveUrl($attributes['url']))) {
268
269 $atts = [
270 'url' => $attributes['url'],
271 'starttime' => !empty($attributes['starttime']) ? $attributes['starttime'] : '',
272 'endtime' => !empty($attributes['endtime']) ? $attributes['endtime'] : '',
273 'autoplay' => !empty($attributes['autoplay']) ? 1 : 0,
274 'controls' => isset($attributes['controls']) ? $attributes['controls'] : '1',
275 'fullscreen' => !empty($attributes['fullscreen']) ? 1 : 0,
276 'videoannotations' => !empty($attributes['videoannotations']) ? 1 : 0,
277 'progressbarcolor' => !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red',
278 'closedcaptions' => !empty($attributes['closedcaptions']) ? 1 : 0,
279 'modestbranding' => !empty($attributes['modestbranding']) ? $attributes['modestbranding'] : '',
280 'relatedvideos' => !empty($attributes['relatedvideos']) ? 1 : 0,
281 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
282 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
283 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
284 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
285 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
286 ];
287
288 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
289
290 if (!empty($urlInfo->embed)) {
291 $embedHTML = $urlInfo->embed;
292 }
293
294 if (isset($urlInfo->embed) && preg_match('/src=\"(.+?)\"/', $urlInfo->embed, $match)) {
295 $url_full = $match[1];
296 $query = parse_url($url_full, PHP_URL_QUERY);
297
298 parse_str($query ?? '', $params);
299
300 $params['controls'] = isset($attributes['controls']) ? $attributes['controls'] : '1';
301 $params['iv_load_policy'] = !empty($attributes['videoannotations']) ? 1 : 0;
302 $params['fs'] = !empty($attributes['fullscreen']) ? 1 : 0;
303 $params['rel'] = !empty($attributes['relatedvideos']) ? 1 : 0;
304 $params['end'] = !empty($attributes['endtime']) ? $attributes['endtime'] : '';
305 $params['autoplay'] = !empty($attributes['autoplay']) ? 1 : 0;
306 $params['start'] = !empty($attributes['starttime']) ? $attributes['starttime'] : '';
307 $params['color'] = !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red';
308 $params['modestbranding'] = empty($attributes['modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
309 $params['cc_load_policy'] = !empty($attributes['closedcaptions']) ? 0 : 1;
310
311 preg_match('/(.+)?\?/', $url_full, $url);
312
313 if (empty($url)) {
314 return $embedHTML;
315 }
316
317 $url = $url[1];
318
319 // Reassemble the url with the new variables.
320 $url_modified = $url . '?';
321
322 foreach ($params as $paramName => $paramValue) {
323
324 $and = '&';
325 if (array_key_last($params) === $paramName) {
326 $and = '';
327 }
328
329 if (isset($paramValue) && $paramValue !== '') {
330 $url_modified .= $paramName . '=' . $paramValue . $and;
331 }
332 }
333
334 // Replaces the old url with the new one.
335 $embedHTML = str_replace($url_full, rtrim($url_modified, '&'), $urlInfo->embed);
336 }
337 }
338 }
339
340 if (!empty($attributes['url']) && $this->wistiaValidateUrl($attributes['url'])) {
341
342
343 $embedOptions = $this->get_wistia_block_attributes($attributes);
344
345 // Get the video ID
346 $videoId = $this->getVideoIDFromURL($attributes['url']);
347 $shortVideoId = substr($videoId, 0, 3);
348
349 // Responsive?
350
351 $class = array(
352 'wistia_embed',
353 'wistia_async_' . $videoId
354 );
355
356 $attribs = array(
357 sprintf('id="wistia_%s"', $videoId),
358 sprintf('class="%s"', join(' ', $class)),
359 sprintf('style="width:%spx; height:%spx;"', $attributes['width'], $attributes['height'])
360 );
361
362 $labels = array(
363 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
364 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
365 'you_have_watched_it_before' => __(
366 'It looks like you\'ve watched<br />part of this video before!',
367 'embedpress'
368 ),
369 );
370 $labels = json_encode($labels);
371
372 preg_match('/ose-uid-([a-z0-9]*)/', $attributes['embedHTML'], $matches);
373 $uid = $matches[1];
374
375 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
376 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
377 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
378 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
379 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
380 $html .= '</div>';
381 $embedHTML = $html;
382 }
383
384 if (!empty($attributes['url']) && $this->vimeoValidateUrl($attributes['url'])) {
385 $atts = [
386 'url' => $attributes['url'],
387 'vstarttime' => !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '',
388 'vscheme' => !empty($attributes['vscheme']) ? $attributes['vscheme'] : 'red',
389 'vautoplay' => !empty($attributes['vautoplay']) ? 1 : 0,
390 'vtitle' => !empty($attributes['vtitle']) ? 1 : 0,
391 'vauthor' => !empty($attributes['vauthor']) ? 1 : 0,
392 'vavatar' => !empty($attributes['vavatar']) ? 1 : 0,
393 'vautopause' => !empty($attributes['vautopause']) ? 1 : 0,
394 'vdnt' => !empty($attributes['vdnt']) ? 1 : 0,
395 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
396 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
397 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
398 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
399 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
400 ];
401
402 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
403
404 if (!empty($urlInfo->embed)) {
405 $embedHTML = $urlInfo->embed;
406 }
407
408 if (isset($urlInfo->embed) && preg_match('/src=\"(.+?)\"/', $urlInfo->embed, $match)) {
409 $url_full = $match[1];
410 $query = parse_url($url_full, PHP_URL_QUERY);
411 parse_str($query, $params);
412
413
414 unset($params['amp;dnt']);
415
416 $params['title'] = !empty($attributes['vtitle']) ? 1 : 0;
417 $params['byline'] = !empty($attributes['vauthor']) ? 1 : 0;
418 $params['portrait'] = !empty($attributes['vavatar']) ? 1 : 0;
419 $params['autoplay'] = !empty($attributes['vautoplay']) ? 1 : 0;
420 $params['loop'] = !empty($attributes['vloop']) ? 1 : 0;
421 $params['autopause'] = !empty($attributes['vautopause']) ? 1 : 0;
422 if (empty($attributes['vautopause'])) :
423 $params['dnt'] = !empty($attributes['vdnt']) ? 1 : 0;
424 endif;
425 $params['color'] = !empty($attributes['vscheme']) ? str_replace("#", "", $attributes['vscheme']) : '00ADEF';
426
427 if (!empty($attributes['vstarttime'])) :
428 $params['t'] = !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '';
429 endif;
430
431 preg_match('/(.+)?\?/', $url_full, $url);
432
433 if (empty($url)) {
434 return $embedHTML;
435 }
436
437 $url = $url[1];
438
439 // Reassemble the url with the new variables.
440 $url_modified = $url . '?';
441
442 // print_r($url_modified);
443
444
445 foreach ($params as $param => $value) {
446 $url_modified = add_query_arg($param, $value, $url_modified);
447 }
448
449 $url_modified = str_replace("&t=", "#t=", $url_modified);
450
451 // Replaces the old url with the new one.
452 $embedHTML = str_replace($url_full, rtrim($url_modified, '&'), $urlInfo->embed);
453 }
454 }
455
456 return $embedHTML;
457 }
458
459
460 public function elementor_setting_init()
461 {
462 $this->remove_classic_filters();
463 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'youtube'], 10, 2);
464 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'wistia'], 10, 2);
465 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'twitch'], 10, 2);
466 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'soundcloud'], 10, 2);
467 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'dailymotion'], 10, 2);
468 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'spotify'], 10, 2);
469 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'vimeo'], 10, 2);
470 }
471 public function remove_classic_filters()
472 {
473 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
474 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
475 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
476 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
477 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
478 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
479 }
480 public function getOptions($provider = '', $schema = [])
481 {
482 $options = (array) get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
483 if (empty($options) || (count($options) === 1 && empty($options[0]))) {
484 $options = [];
485
486 foreach ($schema as $fieldSlug => $field) {
487 $value = isset($field['default']) ? $field['default'] : "";
488
489 settype($value, isset($field['type']) && in_array(
490 strtolower($field['type']),
491 ['bool', 'boolean', 'int', 'integer', 'float', 'string']
492 ) ? $field['type'] : 'string');
493
494 if ($fieldSlug === "license_key") {
495 $options['license'] = [
496 'key' => true,
497 'status' => "missing",
498 ];
499 } else {
500 $options[$fieldSlug] = $value;
501 }
502 }
503 }
504
505 $options['license'] = [
506 'key' => true,
507 'status' => "missing",
508 ];
509 return apply_filters('emebedpress_get_options', $options);
510 }
511
512 public function get_youtube_params($options)
513 {
514 $params = [];
515
516 // Handle `autoplay` option.
517 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
518 $params['autoplay'] = 1;
519 } else {
520 unset($params['autoplay']);
521 }
522
523 // Handle `controls` option.
524 if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) {
525 $params['controls'] = (int) $options['controls'];
526 } else {
527 unset($params['controls']);
528 }
529
530 // Handle `fs` option.
531 if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) {
532 $params['fs'] = (int) $options['fs'];
533 } else {
534 unset($params['fs']);
535 }
536
537 // Handle `iv_load_policy` option.
538 if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) {
539 $params['iv_load_policy'] = (int) $options['iv_load_policy'];
540 } else {
541 unset($params['iv_load_policy']);
542 }
543
544 return apply_filters('embedpress_youtube_params', $params);
545 }
546
547 public function get_vimeo_params($options)
548 {
549 $params = [];
550
551 // Handle `display_title` option.
552 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
553 $params['title'] = 1;
554 } else {
555 $params['title'] = 0;
556 }
557
558 // Handle `autoplay` option.
559 if (!empty($options['autoplay'])) {
560 $params['autoplay'] = 1;
561 } else {
562 unset($params['autoplay']);
563 }
564
565 // Handle `color` option.
566 if (!empty($options['color'])) {
567 $params['color'] = str_replace('#', '', $options['color']);
568 } else {
569 unset($params['color']);
570 }
571 return apply_filters('embedpress_vimeo_params', $params);
572 }
573
574 //--- For CLASSIC AND BLOCK EDITOR
575 public function enhance_youtube($embed)
576 {
577
578
579 $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');
580
581 if (
582 $isYoutube && isset($embed->embed)
583 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
584 ) {
585
586 // for compatibility only, @TODO; remove later after deep testing.
587 $options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
588
589 // Parse the url to retrieve all its info like variables etc.
590 $url_full = $match[1];
591 $query = parse_url($url_full, PHP_URL_QUERY);
592 parse_str($query, $params);
593 // Handle `color` option.
594 if (!empty($options['color'])) {
595 $params['color'] = $options['color'];
596 } else {
597 unset($params['color']);
598 }
599 // Handle `rel` option.
600 if (isset($options['rel']) && in_array((int) $options['rel'], [0, 1])) {
601 $params['rel'] = (int) $options['rel'];
602 } else {
603 unset($params['rel']);
604 }
605
606 // Handle `autoplay` option.
607 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
608 $params['autoplay'] = 1;
609 } else {
610 unset($params['autoplay']);
611 }
612
613 // Handle `controls` option.
614 if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) {
615 $params['controls'] = (int) $options['controls'];
616 } else {
617 unset($params['controls']);
618 }
619 if (isset($options['start_time'])) {
620 $params['start'] = $options['start_time'];
621 } else {
622 unset($params['start']);
623 }
624 if (isset($options['end_time'])) {
625 $params['end'] = $options['end_time'];
626 } else {
627 unset($params['end']);
628 }
629
630 // Handle `fs` option.
631 if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) {
632 $params['fs'] = (int) $options['fs'];
633 } else {
634 unset($params['fs']);
635 }
636
637 // Handle `iv_load_policy` option.
638 if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) {
639 $params['iv_load_policy'] = (int) $options['iv_load_policy'];
640 } else {
641 unset($params['iv_load_policy']);
642 }
643
644 // pro controls will be handled by the pro so remove it from the free.
645 $pro_controls = ['cc_load_policy', 'modestbranding'];
646 foreach ($pro_controls as $pro_control) {
647 if (isset($params[$pro_control])) {
648 unset($params[$pro_control]);
649 }
650 }
651
652 preg_match('/(.+)?\?/', $url_full, $url);
653 $url = $url[1];
654
655 if (is_object($embed->attributes) && !empty($embed->attributes)) {
656 $attributes = (array) $embed->attributes;
657
658 $params['controls'] = isset($attributes['data-controls']) ? $attributes['data-controls'] : '1';
659 $params['iv_load_policy'] = !empty($attributes['data-videoannotations']) && ($attributes['data-videoannotations'] == 'true') ? 1 : 0;
660 $params['fs'] = !empty($attributes['data-fullscreen']) && ($attributes['data-fullscreen'] == 'true') ? 1 : 0;
661 $params['rel'] = !empty($attributes['data-relatedvideos']) && ($attributes['data-relatedvideos'] == 'true') ? 1 : 0;
662 $params['end'] = !empty($attributes['data-endtime']) ? $attributes['data-endtime'] : '';
663 $params['autoplay'] = !empty($attributes['data-autoplay']) && ($attributes['data-autoplay'] == 'true') ? 1 : 0;
664 $params['start'] = !empty($attributes['data-starttime']) ? $attributes['data-starttime'] : '';
665 $params['color'] = !empty($attributes['data-progressbarcolor']) ? $attributes['data-progressbarcolor'] : 'red';
666 $params['modestbranding'] = empty($attributes['data-modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
667 $params['cc_load_policy'] = !empty($attributes['data-closedcaptions']) && ($attributes['data-closedcaptions'] == 'true') ? 0 : 1;
668 }
669
670 // Reassemble the url with the new variables.
671 $url_modified = $url . '?';
672 foreach ($params as $paramName => $paramValue) {
673 $url_modified .= $paramName . '=' . $paramValue . '&';
674 }
675
676 // Replaces the old url with the new one.
677 $embed->embed = str_replace($url_full, rtrim($url_modified, '&'), $embed->embed);
678 }
679
680 return $embed;
681 }
682
683 public function enhance_vimeo($embed)
684 {
685
686
687 if (
688 isset($embed->provider_name)
689 && strtoupper($embed->provider_name) === 'VIMEO'
690 && isset($embed->embed)
691 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
692 ) {
693 // old schema is for backward compatibility only @todo; remove it in the next version after deep test
694 $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
695
696 $url_full = $match[1];
697 $params = [];
698
699 // Handle `display_title` option.
700 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
701 $params['title'] = 1;
702 } else {
703 $params['title'] = 0;
704 }
705
706 // Handle `autoplay` option.
707 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
708 $params['autoplay'] = 1;
709 } else {
710 unset($params['autoplay']);
711 }
712
713 // Handle `color` option.
714 if (!empty($options['color'])) {
715 $params['color'] = str_replace('#', '', $options['color']);
716 } else {
717 unset($params['color']);
718 }
719 // Handle `display_author` option.
720 if (isset($options['display_author']) && (bool) $options['display_author'] === true) {
721 $params['byline'] = 1;
722 } else {
723 $params['byline'] = 0;
724 }
725
726 // Handle `display_avatar` option.
727 if (isset($options['display_avatar']) && (bool) $options['display_avatar'] === true) {
728 $params['portrait'] = 1;
729 } else {
730 $params['portrait'] = 0;
731 }
732
733 // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only
734 //@todo; maybe extract unsetting pro vars to a function later
735 $pro_controls = ['loop', 'autopause', 'dnt',];
736 foreach ($pro_controls as $pro_control) {
737 if (isset($params[$pro_control])) {
738 unset($params[$pro_control]);
739 }
740 }
741
742 if (!empty($params['autopause'])) {
743 unset($params['dnt']);
744 unset($params['amp;dnt']);
745 }
746
747 // Reassemble the url with the new variables.
748 $url_modified = str_replace("&amp;dnt=1", "", $url_full);
749
750 if (is_object($embed->attributes) && !empty($embed->attributes)) {
751 $attributes = (array) $embed->attributes;
752 $attributes = stringToBoolean($attributes);
753
754 $params['title'] = !empty($attributes['data-vtitle']) ? 1 : 0;
755 $params['byline'] = !empty($attributes['data-vauthor']) ? 1 : 0;
756 $params['portrait'] = !empty($attributes['data-vavatar']) ? 1 : 0;
757 $params['autoplay'] = !empty($attributes['data-vautoplay']) ? 1 : 0;
758 $params['loop'] = !empty($attributes['data-vloop']) ? 1 : 0;
759 $params['autopause'] = !empty($attributes['data-vautopause']) ? 1 : 0;
760 if (empty($attributes['data-vautopause'])) :
761 $params['dnt'] = !empty($attributes['data-vdnt']) ? 1 : 0;
762 endif;
763 $params['color'] = !empty($attributes['data-vscheme']) ? str_replace("#", "", $attributes['data-vscheme']) : '00ADEF';
764
765 if (!empty($attributes['data-vstarttime'])) :
766 $params['t'] = !empty($attributes['data-vstarttime']) ? $attributes['data-vstarttime'] : '';
767 endif;
768
769 foreach ($params as $param => $value) {
770 $url_modified = add_query_arg($param, $value, $url_modified);
771 }
772
773 $url_modified = str_replace("&t=", "#t=", $url_modified);
774 } else {
775 foreach ($params as $param => $value) {
776 $url_modified = add_query_arg($param, $value, $url_modified);
777 }
778
779 if (empty($attributes['data-vstarttime']) && isset($options['start_time'])) {
780 $url_modified .= '#t=' . $options['start_time'];
781 }
782 }
783
784 do_action('embedpress_after_modified_url', $url_modified, $url_full, $params);
785
786 // Replaces the old url with the new one.
787 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
788 }
789
790 return $embed;
791 }
792
793 public function enhance_wistia($embed)
794 {
795
796 if (
797 isset($embed->provider_name)
798 && strtoupper($embed->provider_name) === 'WISTIA, INC.'
799 && isset($embed->embed)
800 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
801 ) {
802 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
803
804 $url_full = $match[1];
805
806 // Parse the url to retrieve all its info like variables etc.
807 $query = parse_url($embed->url, PHP_URL_QUERY);
808 $url = str_replace('?' . $query, '', $url_full);
809
810 if ($query !== null) {
811 parse_str($query, $params);
812 }
813
814 // Set the class in the attributes
815 $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class);
816 $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed);
817
818
819 // Embed Options
820 $embedOptions = new \stdClass;
821 $embedOptions->videoFoam = false;
822 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
823 $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true);
824
825 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
826
827 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
828
829 if (!empty($options['start_time'])) {
830 $embedOptions->time = isset($options['start_time']) ? $options['start_time'] : 0;
831 }
832
833 if (isset($options['player_color'])) {
834 $color = $options['player_color'];
835 if (null !== $color) {
836 $embedOptions->playerColor = $color;
837 }
838 }
839
840 // Plugins
841 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
842
843 $pluginList = array();
844
845 // Resumable
846 if (isset($options['plugin_resumable'])) {
847 $isResumableEnabled = $options['plugin_resumable'];
848 if ($isResumableEnabled) {
849 // Add the resumable plugin
850 $pluginList['resumable'] = array(
851 'src' => $pluginsBaseURL . '/resumable.min.js',
852 'async' => false
853 );
854 }
855 }
856
857 // Add a fix for the autoplay and resumable work better together
858 if (isset($options->autoPlay)) {
859 if ($isResumableEnabled) {
860 $pluginList['fixautoplayresumable'] = array(
861 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
862 );
863 }
864 }
865
866 // Focus plugin
867 if (isset($options['plugin_focus'])) {
868 $isFocusEnabled = $options['plugin_focus'];
869 $pluginList['dimthelights'] = array(
870 'src' => $pluginsBaseURL . '/dimthelights.min.js',
871 'autoDim' => $isFocusEnabled
872 );
873 $embedOptions->focus = $isFocusEnabled;
874 }
875
876 // Rewind plugin
877 if (isset($options['plugin_rewind'])) {
878 if ($options['plugin_rewind']) {
879 $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10;
880
881 $pluginList['rewind'] = array(
882 'src' => $pluginsBaseURL . '/rewind.min.js'
883 );
884 }
885 }
886 $embedOptions->plugin = $pluginList;
887
888 $embedOptions = json_encode($embedOptions);
889
890 // Get the video ID
891 $videoId = $this->getVideoIDFromURL($embed->url);
892 $shortVideoId = substr($videoId, 0, 3);
893
894 // Responsive?
895
896 $class = array(
897 'wistia_embed',
898 'wistia_async_' . $videoId
899 );
900
901 $attribs = array(
902 sprintf('id="wistia_%s"', $videoId),
903 sprintf('class="%s"', join(' ', $class)),
904 sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height)
905 );
906
907 $labels = array(
908 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
909 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
910 'you_have_watched_it_before' => __(
911 'It looks like you\'ve watched<br />part of this video before!',
912 'embedpress'
913 ),
914 );
915 $labels = json_encode($labels);
916
917 preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches);
918 $uid = $matches[1];
919
920 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
921 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
922 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
923 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
924 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
925 $html .= '</div>';
926 $embed->embed = $html;
927 }
928
929 return $embed;
930 }
931
932 public function enhance_twitch($embed_content)
933 {
934 $e = isset($embed_content->url) && isset($embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : [];
935 if (isset($e['provider_name']) && strtoupper($e['provider_name']) === 'TWITCH' && isset($embed_content->embed)) {
936 $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema());
937
938 $atts = isset($embed_content->attributes) ? $embed_content->attributes : [];
939 $time = '0h0m0s';
940 $type = $e['type'];
941 $content_id = $e['content_id'];
942 $channel = 'channel' === $type ? $content_id : '';
943 $video = 'video' === $type ? $content_id : '';
944 $muted = isset($settings['embedpress_pro_twitch_mute']) && ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true' : 'false';
945 $full_screen = isset($settings['embedpress_pro_fs']) && ('yes' === $settings['embedpress_pro_fs']) ? 'true' : 'false';
946 $autoplay = isset($settings['embedpress_pro_twitch_autoplay']) && ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true' : 'false';
947 $theme = !empty($settings['embedpress_pro_twitch_theme']) ? esc_attr($settings['embedpress_pro_twitch_theme']) : 'dark';
948
949 $layout = 'video';
950 $width = !empty($atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800;
951 $height = !empty($atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450;
952 if (!empty($settings['start_time'])) {
953 $ta = explode(':', gmdate("G:i:s", $settings['start_time']));
954 $h = $ta[0] . 'h';
955 $m = ($ta[1] * 1) . 'm';
956 $s = ($ta[2] * 1) . 's';
957 $time = $h . $m . $s;
958 }
959 $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}";
960 $pars_url = wp_parse_url(get_site_url());
961 $url = !empty($pars_url['host']) ? $url . '&parent=' . $pars_url['host'] : $url;
962 ob_start();
963 ?>
964 <div class="embedpress_wrapper" data-url="<?php echo esc_url($embed_content->url); ?>">
965 <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>
966 </div>
967 <?php
968 $c = ob_get_clean();
969 $embed_content->embed = $c;
970 }
971
972 return $embed_content;
973 }
974 public function enhance_dailymotion($embed)
975 {
976 $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema());
977 $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');
978
979 if (
980 $isDailymotion && isset($embed->embed)
981 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
982 ) {
983 // Parse the url to retrieve all its info like variables etc.
984 $url_full = $match[1];
985 $params = [
986 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null),
987 'mute' => (int) isset($options['mute']) ? $options['mute'] : null,
988 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null,
989 'controls' => (int) isset($options['controls']) ? $options['controls'] : null,
990 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null,
991 'endscreen-enable' => 0,
992 ];
993
994 if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') {
995 $params['playsinline'] = 1;
996 }
997 $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null;
998 if (is_embedpress_pro_active()) {
999 $params['ui-logo'] = (int) isset($options['show_logo']) ? $options['show_logo'] : null;
1000 }
1001
1002 $url_modified = $url_full;
1003 foreach ($params as $param => $value) {
1004 $url_modified = add_query_arg($param, $value, $url_modified);
1005 }
1006 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1007 }
1008
1009 return $embed;
1010 }
1011 public function enhance_soundcloud($embed)
1012 {
1013
1014 $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');
1015
1016 if (
1017 $isSoundcloud && isset($embed->embed)
1018 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
1019 ) {
1020 $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema());
1021 // Parse the url to retrieve all its info like variables etc.
1022 $url_full = $match[1];
1023 $params = [
1024 'color' => str_replace('#', '', $options['color']),
1025 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false',
1026 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false',
1027 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false',
1028 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false',
1029 'buying' => 'false',
1030 'download' => 'false',
1031 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false',
1032 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false',
1033 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false',
1034 ];
1035
1036 if (is_embedpress_pro_active()) {
1037 $params['buying'] = isset($options['buy_button']) && $options['buy_button'] == '1' ? 'true' : 'false';
1038 $params['download'] = isset($options['download_button']) && $options['download_button'] == '1' ? 'true' : 'false';
1039 }
1040
1041 $url_modified = $url_full;
1042 foreach ($params as $param => $value) {
1043 $url_modified = add_query_arg($param, $value, $url_modified);
1044 }
1045
1046 // Replaces the old url with the new one.
1047 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1048 if ('false' === $params['visual']) {
1049 $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed);
1050 }
1051 }
1052
1053 return $embed;
1054 }
1055 public function embedpress_gutenberg_register_block_youtube($youtube_params)
1056 {
1057 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
1058 return $this->get_youtube_params($youtube_options);
1059 }
1060 public function embedpress_gutenberg_register_block_vimeo()
1061 {
1062 if (function_exists('register_block_type')) :
1063 register_block_type('embedpress/vimeo-block', array(
1064 'attributes' => array(
1065 'url' => array(
1066 'type' => 'string',
1067 'default' => ''
1068 ),
1069 'iframeSrc' => array(
1070 'type' => 'string',
1071 'default' => ''
1072 ),
1073 ),
1074 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo']
1075 ));
1076 endif;
1077 }
1078 public function embedpress_gutenberg_render_block_vimeo($attributes)
1079 {
1080 ob_start();
1081 if (!empty($attributes) && !empty($attributes['iframeSrc'])) :
1082 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
1083 $vimeo_params = $this->get_vimeo_params($vimeo_options);
1084 $iframeUrl = $attributes['iframeSrc'];
1085 $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center');
1086 foreach ($vimeo_params as $param => $value) {
1087 $iframeUrl = add_query_arg($param, $value, $iframeUrl);
1088 }
1089 //@TODO; test responsive without static height width, keeping for now backward compatibility
1090 ?>
1091 <div class="ose-vimeo wp-block-embed-vimeo <?php echo esc_attr($align); ?>">
1092 <iframe src="<?php echo esc_url($iframeUrl); ?>" allowtransparency="true" frameborder="0" width="640" height="360">
1093 </iframe>
1094 </div>
1095 <?php
1096 endif;
1097
1098 return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean());
1099 }
1100 public function get_youtube_settings_schema()
1101 {
1102 return [
1103 'autoplay' => [
1104 'type' => 'bool',
1105 'default' => false
1106 ],
1107 'color' => [
1108 'type' => 'string',
1109 'default' => 'red'
1110 ],
1111 'cc_load_policy' => [
1112 'type' => 'bool',
1113 'default' => false
1114 ],
1115 'controls' => [
1116 'type' => 'string',
1117 'default' => '1'
1118 ],
1119 'fs' => [
1120 'type' => 'bool',
1121 'default' => true
1122 ],
1123 'iv_load_policy' => [
1124 'type' => 'radio',
1125 'default' => '1'
1126 ],
1127 'rel' => [
1128 'type' => 'bool',
1129 'default' => true
1130 ],
1131 'modestbranding' => [
1132 'type' => 'string',
1133 'default' => '0'
1134 ],
1135 'logo_url' => [
1136 'type' => 'url',
1137 ],
1138 'logo_xpos' => [
1139 'type' => 'number',
1140 'default' => 10
1141 ],
1142 'logo_ypos' => [
1143 'type' => 'number',
1144 'default' => 10
1145 ],
1146 'cta_url' => [
1147 'type' => 'url',
1148 ],
1149 'start_time' => [
1150 'type' => 'number',
1151 'default' => 10
1152 ],
1153 'end_time' => [
1154 'type' => 'number',
1155 'default' => 10
1156 ],
1157 ];
1158 }
1159 public function get_vimeo_settings_schema()
1160 {
1161 return array(
1162 'start_time' => [
1163 'type' => 'number',
1164 'default' => 10
1165 ],
1166 'autoplay' => array(
1167 'type' => 'bool',
1168 'default' => false
1169 ),
1170 'loop' => array(
1171 'type' => 'bool',
1172 'default' => false
1173 ),
1174 'autopause' => array(
1175 'type' => 'bool',
1176 'default' => false
1177 ),
1178 'vimeo_dnt' => array(
1179 'type' => 'bool',
1180 'default' => true,
1181 ),
1182 'color' => array(
1183 'type' => 'text',
1184 'default' => '#00adef',
1185 'classes' => 'color-field'
1186 ),
1187 'display_title' => array(
1188 'type' => 'bool',
1189 'default' => true
1190 ),
1191 'display_author' => array(
1192 'type' => 'bool',
1193 'default' => true
1194 ),
1195 'display_avatar' => array(
1196 'type' => 'bool',
1197 'default' => true
1198 )
1199 );
1200 }
1201 public function get_wistia_settings_schema()
1202 {
1203 return array(
1204 'start_time' => [
1205 'type' => 'number',
1206 'default' => 0
1207 ],
1208 'display_fullscreen_button' => array(
1209 'type' => 'bool',
1210 'default' => true
1211 ),
1212 'display_playbar' => array(
1213 'type' => 'bool',
1214 'default' => true
1215 ),
1216 'small_play_button' => array(
1217 'type' => 'bool',
1218 'default' => true
1219 ),
1220 'display_volume_control' => array(
1221 'type' => 'bool',
1222 'default' => true
1223 ),
1224 'autoplay' => array(
1225 'type' => 'bool',
1226 'default' => false
1227 ),
1228 'volume' => array(
1229 'type' => 'text',
1230 'default' => '100'
1231 ),
1232 'player_color' => array(
1233 'type' => 'text',
1234 'default' => '#00adef',
1235 ),
1236 'plugin_resumable' => array(
1237 'type' => 'bool',
1238 'default' => false
1239 ),
1240 'plugin_captions' => array(
1241 'type' => 'bool',
1242 'default' => false
1243 ),
1244 'plugin_captions_default' => array(
1245 'type' => 'bool',
1246 'default' => false
1247 ),
1248 'plugin_focus' => array(
1249 'type' => 'bool',
1250 'default' => false
1251 ),
1252 'plugin_rewind' => array(
1253 'type' => 'bool',
1254 'default' => false
1255 ),
1256 'plugin_rewind_time' => array(
1257 'type' => 'text',
1258 'default' => '10'
1259 ),
1260 );
1261 }
1262
1263
1264 public function getVideoIDFromURL($url)
1265 {
1266 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
1267 // https://ostraining-1.wistia.com/medias/xf1edjzn92
1268 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
1269
1270 $id = false;
1271 if (isset($matches[1])) {
1272 $id = $matches[1];
1273 }
1274
1275 return $id;
1276 }
1277 public function embedpress_wistia_block_after_embed($attributes)
1278 {
1279 $embedOptions = $this->embedpress_wistia_pro_get_options();
1280 // Get the video ID
1281 $videoId = $this->getVideoIDFromURL($attributes['url']);
1282 $shortVideoId = $videoId;
1283
1284 $labels = array(
1285 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
1286 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
1287 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
1288 );
1289 $labels = json_encode($labels);
1290
1291
1292 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
1293 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
1294 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
1295
1296
1297
1298 echo $html;
1299 }
1300 public function embedpress_wistia_pro_get_options()
1301 {
1302 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
1303 // Embed Options
1304 $embedOptions = new \stdClass;
1305 // $embedOptions->videoFoam = true;
1306 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
1307 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
1308 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
1309
1310 if (isset($options['player_color'])) {
1311 $color = $options['player_color'];
1312 if (null !== $color) {
1313 $embedOptions->playerColor = $color;
1314 }
1315 }
1316
1317 // Plugins
1318 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
1319
1320 $pluginList = array();
1321
1322 // Resumable
1323 if (isset($options['plugin_resumable'])) {
1324 $isResumableEnabled = $options['plugin_resumable'];
1325 if ($isResumableEnabled) {
1326 // Add the resumable plugin
1327 $pluginList['resumable'] = array(
1328 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
1329 'async' => false
1330 );
1331 }
1332 }
1333 // Add a fix for the autoplay and resumable work better together
1334 //@TODO; check baseurl deeply, not looking good
1335 if ($options['autoplay']) {
1336 if ($isResumableEnabled) {
1337 $pluginList['fixautoplayresumable'] = array(
1338 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
1339 );
1340 }
1341 }
1342
1343
1344 // Focus plugin
1345 if (isset($options['plugin_focus'])) {
1346 $isFocusEnabled = $options['plugin_focus'];
1347 $pluginList['dimthelights'] = array(
1348 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
1349 'autoDim' => $isFocusEnabled
1350 );
1351 $embedOptions->focus = $isFocusEnabled;
1352 }
1353
1354 $embedOptions->plugin = $pluginList;
1355 $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions);
1356 $embedOptions = json_encode($embedOptions);
1357 return apply_filters('embedpress_wistia_params_after_encode', $embedOptions);
1358 }
1359
1360
1361 public function get_twitch_settings_schema()
1362 {
1363 return [
1364 'start_time' => [
1365 'type' => 'number',
1366 'default' => 0,
1367 ],
1368 'embedpress_pro_twitch_autoplay' => [
1369 'type' => 'string',
1370 'default' => 'no',
1371 ],
1372 'embedpress_pro_twitch_chat' => [
1373 'type' => 'string',
1374 'default' => 'no',
1375 ],
1376
1377 'embedpress_pro_twitch_theme' => [
1378 'type' => 'string',
1379 'default' => 'dark',
1380 ],
1381 'embedpress_pro_fs' => [
1382 'type' => 'string',
1383 'default' => 'yes',
1384 ],
1385 'embedpress_pro_twitch_mute' => [
1386 'type' => 'string',
1387 'default' => 'yes',
1388 ],
1389
1390 ];
1391 }
1392 public function get_dailymotion_settings_schema()
1393 {
1394 return [
1395 'autoplay' => [
1396 'type' => 'string',
1397 'default' => ''
1398 ],
1399 'play_on_mobile' => [
1400 'type' => 'string',
1401 'default' => ''
1402 ],
1403 'color' => [
1404 'type' => 'string',
1405 'default' => '#dd3333'
1406 ],
1407 'mute' => [
1408 'type' => 'string',
1409 'default' => ''
1410 ],
1411 'controls' => [
1412 'type' => 'string',
1413 'default' => '1'
1414 ],
1415 'video_info' => [
1416 'type' => 'string',
1417 'default' => '1'
1418 ],
1419 'show_logo' => [
1420 'type' => 'string',
1421 'default' => '1'
1422 ],
1423 'start_time' => [
1424 'type' => 'string',
1425 'default' => '0'
1426 ],
1427 ];
1428 }
1429 public function get_soundcloud_settings_schema()
1430 {
1431 return [
1432 'visual' => [
1433 'type' => 'string',
1434 'default' => ''
1435 ],
1436 'autoplay' => [
1437 'type' => 'string',
1438 'default' => ''
1439 ],
1440 'play_on_mobile' => [
1441 'type' => 'string',
1442 'default' => ''
1443 ],
1444 'color' => [
1445 'type' => 'string',
1446 'default' => '#dd3333'
1447 ],
1448
1449 'share_button' => [
1450 'type' => 'string',
1451 'default' => ''
1452 ],
1453 'comments' => [
1454 'type' => 'string',
1455 'default' => '1'
1456 ],
1457 'artwork' => [
1458 'type' => 'string',
1459 'default' => ''
1460 ],
1461 'play_count' => [
1462 'type' => 'string',
1463 'default' => '1'
1464 ],
1465 'username' => [
1466 'type' => 'string',
1467 'default' => '1'
1468 ],
1469 'download_button' => [
1470 'type' => 'string',
1471 'default' => '1'
1472 ],
1473 'buy_button' => [
1474 'type' => 'string',
1475 'default' => '1'
1476 ],
1477 ];
1478 }
1479
1480 public function enhance_missing_title($embed)
1481 {
1482
1483 $embed_arr = get_object_vars($embed);
1484
1485 $url = $embed->url;
1486
1487 if (strpos($url, 'gettyimages') !== false) {
1488 $title = $embed_arr[$url]['title'];
1489 $embed->embed = $embed->embed . "
1490 <script>
1491 if (typeof gie === 'function') {
1492 gie(function(){
1493 var iframe = document.querySelector('.ose-embedpress-responsive iframe');
1494 if(iframe && !iframe.getAttribute('title')){
1495 iframe.setAttribute('title', '$title')
1496 }
1497 });
1498 }
1499 </script>
1500 ";
1501 }
1502
1503
1504 return $embed;
1505 }
1506
1507
1508 public function embedpress_generate_social_share_meta()
1509 {
1510 $post_id = get_the_ID();
1511 $post = get_post($post_id);
1512 $tags = '';
1513
1514 $thumbnail_url = get_the_post_thumbnail_url($post_id);
1515
1516 if (!empty($_GET['hash'])) {
1517
1518 $id_value = sanitize_text_field($_GET['hash']);
1519
1520 $url = get_the_permalink($post_id);
1521
1522 if (class_exists('Elementor\Plugin') && \Elementor\Plugin::$instance->db->is_built_with_elementor(get_the_ID())) {
1523 $page_settings = get_post_meta($post_id, '_elementor_data', true);
1524
1525 $ep_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_elementor');
1526 $pdf_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpress_pdf');
1527 $doc_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_document');
1528
1529
1530
1531 if (is_array($ep_settings) && !empty($ep_settings)) {
1532 $title = !empty($ep_settings['settings']['embedpress_content_title']) ? $ep_settings['settings']['embedpress_content_title'] : '';
1533
1534 $description = !empty($ep_settings['settings']['embedpress_content_descripiton']) ? $ep_settings['settings']['embedpress_content_descripiton'] : '';
1535
1536 $image_url = !empty($ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url']) ? $ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url'] : '';
1537 } else if (is_array($pdf_settings) && !empty($pdf_settings)) {
1538 $title = !empty($pdf_settings['settings']['embedpress_pdf_content_title']) ? $pdf_settings['settings']['embedpress_pdf_content_title'] : '';
1539
1540 $description = !empty($pdf_settings['settings']['embedpress_pdf_content_descripiton']) ? $pdf_settings['settings']['embedpress_pdf_content_descripiton'] : '';
1541
1542 $image_url = !empty($pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url'] : '';
1543 } else if (is_array($doc_settings) && !empty($doc_settings)) {
1544 $title = !empty($doc_settings['settings']['embedpress_doc_content_title']) ? $doc_settings['settings']['embedpress_doc_content_title'] : '';
1545
1546 $description = !empty($doc_settings['settings']['embedpress_doc_content_descripiton']) ? $doc_settings['settings']['embedpress_doc_content_descripiton'] : '';
1547
1548 $image_url = !empty($doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url']) ? $doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url'] : '';
1549 }
1550
1551 if (!empty($image_url)) {
1552 $tags .= "<meta name='twitter:image' content='" . esc_url($image_url) . "'/>\n";
1553 $tags .= "<meta property='og:image' content='" . esc_url($image_url) . "'/>\n";
1554 $tags .= "<meta property='og:url' content='" . esc_url("$url?hash=$id_value") . "'/>\n";
1555 } else if (!empty($thumbnail_url)) {
1556 $tags .= "<meta name='twitter:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1557 $tags .= "<meta property='og:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1558 }
1559
1560 if (!empty($title)) {
1561 $title = json_decode('"' . $title . '"', JSON_UNESCAPED_UNICODE);
1562 $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1563 $tags .= "<meta name='title' property='og:title' content='" . esc_attr($title) . "'>\n";
1564 $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1565 }
1566
1567 if (!empty($description)) {
1568 $description = json_decode('"' . $description . '"', JSON_UNESCAPED_UNICODE);
1569 $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1570 $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1571 }
1572 } else {
1573
1574 $block_content = $post->post_content;
1575
1576 // Regular expression to match the id and href keys and their values
1577 $thumb = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customThumbnail":"(.*?)"/';
1578 $title = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customTitle":"(.*?)"/';
1579 $description = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customDescription":"(.*?)"/';
1580
1581 // Search for the regex pattern in the string and extract the href value
1582 // Search for the regex pattern in the string and extract the href value
1583 if (preg_match($thumb, $block_content, $matches1)) {
1584 $image_url = esc_url($matches1[1]);
1585 echo "\n<meta name='twitter:image' content='" . esc_attr($image_url) . "'/>\n";
1586 echo "<meta property='og:image' content='" . esc_attr($image_url) . "'/>\n";
1587 echo "<meta property='og:url' content='" . esc_url("$url?hash=$id_value") . "'/>\n";
1588 } else if (!empty($thumbnail_url)) {
1589 echo "\n<meta name='twitter:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1590 echo "<meta property='og:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1591 }
1592
1593 if (preg_match($title, $block_content, $matches2)) {
1594 $title = json_decode('"' . $matches2[1] . '"', JSON_UNESCAPED_UNICODE);
1595 echo "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1596 echo "<meta name='title' property='og:title' content='" . esc_attr($title) . "'>\n";
1597 echo "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1598 }
1599
1600 if (preg_match($description, $block_content, $matches3)) {
1601 $description = json_decode('"' . $matches3[1] . '"', JSON_UNESCAPED_UNICODE);
1602 echo "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1603 echo "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1604 }
1605 }
1606
1607 $tags .= "<meta name='twitter:card' content='summary_large_image'/>\n";
1608
1609 remove_action('wp_head', 'rel_canonical');
1610
1611 echo $tags;
1612 }
1613 }
1614 }
1615