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