PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.1.6
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.1.6
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 1 year ago Feature_Enhancer.php 1 year ago Helper.php 1 year ago
Feature_Enhancer.php
1675 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 $params['playsinline'] = '1';
720
721 }
722
723 // Ensure $url is a string. If $url is an array, convert it to a string or use a specific element.
724 $url_string = is_array($url) ? (isset($url[0]) ? $url[0] : '') : $url;
725
726 // Reassemble the URL with the new variables.
727 $url_modified = $url_string . '?';
728 foreach ($params as $paramName => $paramValue) {
729 $url_modified .= urlencode($paramName) . '=' . urlencode($paramValue) . '&';
730 }
731
732 // Remove the trailing '&' or '?' if no parameters were added.
733 $url_modified = rtrim($url_modified, '&?');
734
735
736 // Replaces the old url with the new one.
737 $embed->embed = str_replace($url_full, rtrim($url_modified, '&'), $embed->embed);
738 }
739
740 return $embed;
741 }
742
743 public function enhance_vimeo($embed)
744 {
745
746
747 if (
748 isset($embed->provider_name)
749 && strtoupper($embed->provider_name) === 'VIMEO'
750 && isset($embed->embed)
751 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
752 ) {
753 // old schema is for backward compatibility only @todo; remove it in the next version after deep test
754 $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
755
756 $url_full = $match[1];
757 $params = [];
758
759 // Handle `display_title` option.
760 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
761 $params['title'] = 1;
762 } else {
763 $params['title'] = 0;
764 }
765
766 // Handle `autoplay` option.
767 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
768 $params['autoplay'] = 1;
769 } else {
770 unset($params['autoplay']);
771 }
772
773 // Handle `color` option.
774 if (!empty($options['color'])) {
775 $params['color'] = str_replace('#', '', $options['color']);
776 } else {
777 unset($params['color']);
778 }
779 // Handle `display_author` option.
780 if (isset($options['display_author']) && (bool) $options['display_author'] === true) {
781 $params['byline'] = 1;
782 } else {
783 $params['byline'] = 0;
784 }
785
786 // Handle `display_avatar` option.
787 if (isset($options['display_avatar']) && (bool) $options['display_avatar'] === true) {
788 $params['portrait'] = 1;
789 } else {
790 $params['portrait'] = 0;
791 }
792
793 // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only
794 //@todo; maybe extract unsetting pro vars to a function later
795 $pro_controls = ['loop', 'autopause', 'dnt',];
796 foreach ($pro_controls as $pro_control) {
797 if (isset($params[$pro_control])) {
798 unset($params[$pro_control]);
799 }
800 }
801
802 if (!empty($params['autopause'])) {
803 unset($params['dnt']);
804 unset($params['amp;dnt']);
805 }
806
807 // Reassemble the url with the new variables.
808 $url_modified = str_replace("&amp;dnt=1", "", $url_full);
809
810 if (is_object($embed->attributes) && !empty($embed->attributes)) {
811 $attributes = (array) $embed->attributes;
812
813 $attributes = stringToBoolean($attributes);
814
815
816 $params['title'] = !empty($attributes['data-vtitle']) ? 1 : 0;
817 $params['byline'] = !empty($attributes['data-vauthor']) ? 1 : 0;
818 $params['portrait'] = !empty($attributes['data-vavatar']) ? 1 : 0;
819 $params['autoplay'] = !empty($attributes['data-vautoplay']) ? 1 : 0;
820 $params['loop'] = !empty($attributes['data-vloop']) ? 1 : 0;
821 $params['autopause'] = !empty($attributes['data-vautopause']) ? 1 : 0;
822 if (empty($attributes['data-vautopause'])) :
823 $params['dnt'] = !empty($attributes['data-vdnt']) ? 1 : 0;
824 endif;
825 $params['color'] = !empty($attributes['data-vscheme']) ? str_replace("#", "", $attributes['data-vscheme']) : '00ADEF';
826
827 if (!empty($attributes['data-vstarttime'])) :
828 $params['t'] = !empty($attributes['data-vstarttime']) ? $attributes['data-vstarttime'] : '';
829 endif;
830
831 foreach ($params as $param => $value) {
832 $url_modified = add_query_arg($param, $value, $url_modified);
833 }
834
835 $url_modified = str_replace("&t=", "#t=", $url_modified);
836 } else {
837 foreach ($params as $param => $value) {
838 $url_modified = add_query_arg($param, $value, $url_modified);
839 }
840
841 if (empty($attributes['data-vstarttime']) && isset($options['start_time'])) {
842 $start_time = sanitize_text_field($options['start_time']);
843 $url_modified .= '#t=' . $start_time;
844 }
845 }
846
847 do_action('embedpress_after_modified_url', $url_modified, $url_full, $params);
848
849 // Replaces the old url with the new one.
850 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
851 }
852
853 return $embed;
854 }
855
856 public function enhance_wistia($embed)
857 {
858
859 if (
860 isset($embed->provider_name)
861 && strtoupper($embed->provider_name) === 'WISTIA, INC.'
862 && isset($embed->embed)
863 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
864 ) {
865 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
866
867 $url_full = $match[1];
868
869 // Parse the url to retrieve all its info like variables etc.
870 $query = parse_url($embed->url, PHP_URL_QUERY);
871 $url = str_replace('?' . $query, '', $url_full);
872
873 if ($query !== null) {
874 parse_str($query, $params);
875 }
876
877 // Set the class in the attributes
878 $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class);
879 $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed);
880
881
882 // Embed Options
883 $embedOptions = new \stdClass;
884 $embedOptions->videoFoam = false;
885 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
886 $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true);
887
888 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
889
890 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
891
892 if (!empty($options['start_time'])) {
893 // $embedOptions->time = isset($options['start_time']) ? $options['start_time'] : 0;
894 }
895
896 if (isset($options['player_color'])) {
897 $color = $options['player_color'];
898 if (null !== $color) {
899 $embedOptions->playerColor = $color;
900 }
901 }
902
903 // Plugins
904 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
905
906 $pluginList = array();
907
908 // Resumable
909 if (isset($options['plugin_resumable'])) {
910 $isResumableEnabled = $options['plugin_resumable'];
911 if ($isResumableEnabled) {
912 // Add the resumable plugin
913 $pluginList['resumable'] = array(
914 'src' => $pluginsBaseURL . '/resumable.min.js',
915 'async' => false
916 );
917 }
918 }
919
920 // Add a fix for the autoplay and resumable work better together
921 if (isset($options->autoPlay)) {
922 if ($isResumableEnabled) {
923 $pluginList['fixautoplayresumable'] = array(
924 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
925 );
926 }
927 }
928
929 // Focus plugin
930 if (isset($options['plugin_focus'])) {
931 $isFocusEnabled = $options['plugin_focus'];
932 $pluginList['dimthelights'] = array(
933 'src' => $pluginsBaseURL . '/dimthelights.min.js',
934 'autoDim' => $isFocusEnabled
935 );
936 $embedOptions->focus = $isFocusEnabled;
937 }
938
939 // Rewind plugin
940 if (isset($options['plugin_rewind'])) {
941 if ($options['plugin_rewind']) {
942 $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10;
943
944 $pluginList['rewind'] = array(
945 'src' => $pluginsBaseURL . '/rewind.min.js'
946 );
947 }
948 }
949 $embedOptions->plugin = $pluginList;
950
951 $embedOptions = json_encode($embedOptions);
952
953 // Get the video ID
954 $videoId = $this->getVideoIDFromURL($embed->url);
955 $shortVideoId = substr($videoId, 0, 3);
956
957 // Responsive?
958
959 $class = array(
960 'wistia_embed',
961 'wistia_async_' . $videoId
962 );
963
964 $attribs = array(
965 sprintf('id="wistia_%s"', $videoId),
966 sprintf('class="%s"', join(' ', $class)),
967 sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height)
968 );
969
970 $labels = array(
971 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
972 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
973 'you_have_watched_it_before' => __(
974 'It looks like you\'ve watched<br />part of this video before!',
975 'embedpress'
976 ),
977 );
978 $labels = json_encode($labels);
979
980 preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches);
981 $uid = $matches[1];
982
983 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
984 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
985 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
986 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
987 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
988 $html .= '</div>';
989 $embed->embed = $html;
990 }
991
992 return $embed;
993 }
994
995 public function enhance_twitch($embed_content)
996 {
997 $e = isset($embed_content->url) && isset($embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : [];
998 if (isset($e['provider_name']) && strtoupper($e['provider_name']) === 'TWITCH' && isset($embed_content->embed)) {
999 $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema());
1000
1001 $atts = isset($embed_content->attributes) ? $embed_content->attributes : [];
1002 $time = '0h0m0s';
1003 $type = $e['type'];
1004 $content_id = $e['content_id'];
1005 $channel = 'channel' === $type ? $content_id : '';
1006 $video = 'video' === $type ? $content_id : '';
1007 $muted = isset($settings['embedpress_pro_twitch_mute']) && ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true' : 'false';
1008 $full_screen = isset($settings['embedpress_pro_fs']) && ('yes' === $settings['embedpress_pro_fs']) ? 'true' : 'false';
1009 $autoplay = isset($settings['embedpress_pro_twitch_autoplay']) && ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true' : 'false';
1010 $theme = !empty($settings['embedpress_pro_twitch_theme']) ? esc_attr($settings['embedpress_pro_twitch_theme']) : 'dark';
1011
1012 $layout = 'video';
1013 $width = !empty($atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800;
1014 $height = !empty($atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450;
1015 if (!empty($settings['start_time'])) {
1016 $ta = explode(':', gmdate("G:i:s", $settings['start_time']));
1017 $h = $ta[0] . 'h';
1018 $m = ($ta[1] * 1) . 'm';
1019 $s = ($ta[2] * 1) . 's';
1020 $time = $h . $m . $s;
1021 }
1022 $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}";
1023 $pars_url = wp_parse_url(get_site_url());
1024 $url = !empty($pars_url['host']) ? $url . '&parent=' . $pars_url['host'] : $url;
1025 ob_start();
1026 ?>
1027 <div class="embedpress_wrapper" data-url="<?php echo esc_url($embed_content->url); ?>">
1028 <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>
1029 </div>
1030 <?php
1031 $c = ob_get_clean();
1032 $embed_content->embed = $c;
1033 }
1034
1035 return $embed_content;
1036 }
1037 public function enhance_dailymotion($embed)
1038 {
1039 $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema());
1040 $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');
1041
1042 if (
1043 $isDailymotion && isset($embed->embed)
1044 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
1045 ) {
1046 // Parse the url to retrieve all its info like variables etc.
1047 $url_full = $match[1];
1048 $params = [
1049 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null),
1050 'mute' => (int) isset($options['mute']) ? $options['mute'] : null,
1051 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null,
1052 'controls' => (int) isset($options['controls']) ? $options['controls'] : null,
1053 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null,
1054 'endscreen-enable' => 0,
1055 ];
1056
1057 if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') {
1058 $params['playsinline'] = 1;
1059 }
1060 $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null;
1061
1062 $params = apply_filters('embedpress_enhance_dailymotion', $params, $options);
1063
1064
1065 $url_modified = $url_full;
1066 foreach ($params as $param => $value) {
1067 $url_modified = add_query_arg($param, $value, $url_modified);
1068 }
1069 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1070 }
1071
1072 return $embed;
1073 }
1074 public function enhance_soundcloud($embed)
1075 {
1076
1077 $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');
1078
1079 if (
1080 $isSoundcloud && isset($embed->embed)
1081 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
1082 ) {
1083 $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema());
1084 // Parse the url to retrieve all its info like variables etc.
1085 $url_full = $match[1];
1086 $params = [
1087 'color' => str_replace('#', '', $options['color']),
1088 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false',
1089 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false',
1090 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false',
1091 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false',
1092 'buying' => 'false',
1093 'download' => 'false',
1094 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false',
1095 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false',
1096 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false',
1097 ];
1098
1099 $params = apply_filters('embedpress_enhance_soundcloud', $params, $options);
1100
1101 $url_modified = $url_full;
1102 foreach ($params as $param => $value) {
1103 $url_modified = add_query_arg($param, $value, $url_modified);
1104 }
1105
1106 // Replaces the old url with the new one.
1107 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1108 if ('false' === $params['visual']) {
1109 $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed);
1110 }
1111 }
1112
1113 return $embed;
1114 }
1115 public function embedpress_gutenberg_register_block_youtube($youtube_params)
1116 {
1117 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
1118 return $this->get_youtube_params($youtube_options);
1119 }
1120 public function embedpress_gutenberg_register_block_vimeo()
1121 {
1122 if (function_exists('register_block_type')) :
1123 register_block_type('embedpress/vimeo-block', array(
1124 'attributes' => array(
1125 'url' => array(
1126 'type' => 'string',
1127 'default' => ''
1128 ),
1129 'iframeSrc' => array(
1130 'type' => 'string',
1131 'default' => ''
1132 ),
1133 ),
1134 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo']
1135 ));
1136 endif;
1137 }
1138 public function embedpress_gutenberg_render_block_vimeo($attributes)
1139 {
1140 ob_start();
1141 if (!empty($attributes) && !empty($attributes['iframeSrc'])) :
1142 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
1143 $vimeo_params = $this->get_vimeo_params($vimeo_options);
1144 $iframeUrl = $attributes['iframeSrc'];
1145 $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center');
1146 foreach ($vimeo_params as $param => $value) {
1147 $iframeUrl = add_query_arg($param, $value, $iframeUrl);
1148 }
1149 //@TODO; test responsive without static height width, keeping for now backward compatibility
1150 ?>
1151 <div class="ose-vimeo wp-block-embed-vimeo <?php echo esc_attr($align); ?>">
1152 <iframe src="<?php echo esc_url($iframeUrl); ?>" allowtransparency="true" frameborder="0" width="640" height="360">
1153 </iframe>
1154 </div>
1155 <?php
1156 endif;
1157
1158 return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean());
1159 }
1160 public function get_youtube_settings_schema()
1161 {
1162 return [
1163 'autoplay' => [
1164 'type' => 'bool',
1165 'default' => false
1166 ],
1167 'color' => [
1168 'type' => 'string',
1169 'default' => 'red'
1170 ],
1171 'cc_load_policy' => [
1172 'type' => 'bool',
1173 'default' => false
1174 ],
1175 'controls' => [
1176 'type' => 'string',
1177 'default' => '1'
1178 ],
1179 'fs' => [
1180 'type' => 'bool',
1181 'default' => true
1182 ],
1183 'iv_load_policy' => [
1184 'type' => 'radio',
1185 'default' => '1'
1186 ],
1187 'rel' => [
1188 'type' => 'bool',
1189 'default' => true
1190 ],
1191 'modestbranding' => [
1192 'type' => 'string',
1193 'default' => '0'
1194 ],
1195 'logo_url' => [
1196 'type' => 'url',
1197 ],
1198 'logo_xpos' => [
1199 'type' => 'number',
1200 'default' => 10
1201 ],
1202 'logo_ypos' => [
1203 'type' => 'number',
1204 'default' => 10
1205 ],
1206 'cta_url' => [
1207 'type' => 'url',
1208 ],
1209 'start_time' => [
1210 'type' => 'number',
1211 'default' => 10
1212 ],
1213 'end_time' => [
1214 'type' => 'number',
1215 'default' => 10
1216 ],
1217 ];
1218 }
1219 public function get_vimeo_settings_schema()
1220 {
1221 return array(
1222 'start_time' => [
1223 'type' => 'number',
1224 'default' => 10
1225 ],
1226 'autoplay' => array(
1227 'type' => 'bool',
1228 'default' => false
1229 ),
1230 'loop' => array(
1231 'type' => 'bool',
1232 'default' => false
1233 ),
1234 'autopause' => array(
1235 'type' => 'bool',
1236 'default' => false
1237 ),
1238 'vimeo_dnt' => array(
1239 'type' => 'bool',
1240 'default' => true,
1241 ),
1242 'color' => array(
1243 'type' => 'text',
1244 'default' => '#00adef',
1245 'classes' => 'color-field'
1246 ),
1247 'display_title' => array(
1248 'type' => 'bool',
1249 'default' => true
1250 ),
1251 'display_author' => array(
1252 'type' => 'bool',
1253 'default' => true
1254 ),
1255 'display_avatar' => array(
1256 'type' => 'bool',
1257 'default' => true
1258 )
1259 );
1260 }
1261 public function get_wistia_settings_schema()
1262 {
1263 return array(
1264 'start_time' => [
1265 'type' => 'number',
1266 'default' => 0
1267 ],
1268 'display_fullscreen_button' => array(
1269 'type' => 'bool',
1270 'default' => true
1271 ),
1272 'display_playbar' => array(
1273 'type' => 'bool',
1274 'default' => true
1275 ),
1276 'small_play_button' => array(
1277 'type' => 'bool',
1278 'default' => true
1279 ),
1280 'display_volume_control' => array(
1281 'type' => 'bool',
1282 'default' => true
1283 ),
1284 'autoplay' => array(
1285 'type' => 'bool',
1286 'default' => false
1287 ),
1288 'volume' => array(
1289 'type' => 'text',
1290 'default' => '100'
1291 ),
1292 'player_color' => array(
1293 'type' => 'text',
1294 'default' => '#00adef',
1295 ),
1296 'plugin_resumable' => array(
1297 'type' => 'bool',
1298 'default' => false
1299 ),
1300 'plugin_captions' => array(
1301 'type' => 'bool',
1302 'default' => false
1303 ),
1304 'plugin_captions_default' => array(
1305 'type' => 'bool',
1306 'default' => false
1307 ),
1308 'plugin_focus' => array(
1309 'type' => 'bool',
1310 'default' => false
1311 ),
1312 'plugin_rewind' => array(
1313 'type' => 'bool',
1314 'default' => false
1315 ),
1316 'plugin_rewind_time' => array(
1317 'type' => 'text',
1318 'default' => '10'
1319 ),
1320 );
1321 }
1322
1323
1324 public function getVideoIDFromURL($url)
1325 {
1326 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
1327 // https://ostraining-1.wistia.com/medias/xf1edjzn92
1328 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
1329
1330 $id = false;
1331 if (isset($matches[1])) {
1332 $id = $matches[1];
1333 }
1334
1335 return $id;
1336 }
1337 public function embedpress_wistia_block_after_embed($attributes)
1338 {
1339 $embedOptions = $this->embedpress_wistia_pro_get_options();
1340 // Get the video ID
1341 $videoId = $this->getVideoIDFromURL($attributes['url']);
1342 $shortVideoId = $videoId;
1343
1344 $labels = array(
1345 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
1346 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
1347 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
1348 );
1349 $labels = json_encode($labels);
1350
1351
1352 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
1353 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
1354 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
1355
1356
1357
1358 echo $html;
1359 }
1360 public function embedpress_wistia_pro_get_options()
1361 {
1362 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
1363 // Embed Options
1364 $embedOptions = new \stdClass;
1365 // $embedOptions->videoFoam = true;
1366 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
1367 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
1368 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
1369
1370 if (isset($options['player_color'])) {
1371 $color = $options['player_color'];
1372 if (null !== $color) {
1373 $embedOptions->playerColor = $color;
1374 }
1375 }
1376
1377 // Plugins
1378 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
1379
1380 $pluginList = array();
1381
1382 // Resumable
1383 if (isset($options['plugin_resumable'])) {
1384 $isResumableEnabled = $options['plugin_resumable'];
1385 if ($isResumableEnabled) {
1386 // Add the resumable plugin
1387 $pluginList['resumable'] = array(
1388 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
1389 'async' => false
1390 );
1391 }
1392 }
1393 // Add a fix for the autoplay and resumable work better together
1394 //@TODO; check baseurl deeply, not looking good
1395 if ($options['autoplay']) {
1396 if ($isResumableEnabled) {
1397 $pluginList['fixautoplayresumable'] = array(
1398 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
1399 );
1400 }
1401 }
1402
1403
1404 // Focus plugin
1405 if (isset($options['plugin_focus'])) {
1406 $isFocusEnabled = $options['plugin_focus'];
1407 $pluginList['dimthelights'] = array(
1408 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
1409 'autoDim' => $isFocusEnabled
1410 );
1411 $embedOptions->focus = $isFocusEnabled;
1412 }
1413
1414 $embedOptions->plugin = $pluginList;
1415 $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions);
1416 $embedOptions = json_encode($embedOptions);
1417 return apply_filters('embedpress_wistia_params_after_encode', $embedOptions);
1418 }
1419
1420
1421 public function get_twitch_settings_schema()
1422 {
1423 return [
1424 'start_time' => [
1425 'type' => 'number',
1426 'default' => 0,
1427 ],
1428 'embedpress_pro_twitch_autoplay' => [
1429 'type' => 'string',
1430 'default' => 'no',
1431 ],
1432 'embedpress_pro_twitch_chat' => [
1433 'type' => 'string',
1434 'default' => 'no',
1435 ],
1436
1437 'embedpress_pro_twitch_theme' => [
1438 'type' => 'string',
1439 'default' => 'dark',
1440 ],
1441 'embedpress_pro_fs' => [
1442 'type' => 'string',
1443 'default' => 'yes',
1444 ],
1445 'embedpress_pro_twitch_mute' => [
1446 'type' => 'string',
1447 'default' => 'yes',
1448 ],
1449
1450 ];
1451 }
1452 public function get_dailymotion_settings_schema()
1453 {
1454 return [
1455 'autoplay' => [
1456 'type' => 'string',
1457 'default' => ''
1458 ],
1459 'play_on_mobile' => [
1460 'type' => 'string',
1461 'default' => ''
1462 ],
1463 'color' => [
1464 'type' => 'string',
1465 'default' => '#dd3333'
1466 ],
1467 'mute' => [
1468 'type' => 'string',
1469 'default' => ''
1470 ],
1471 'controls' => [
1472 'type' => 'string',
1473 'default' => '1'
1474 ],
1475 'video_info' => [
1476 'type' => 'string',
1477 'default' => '1'
1478 ],
1479 'show_logo' => [
1480 'type' => 'string',
1481 'default' => '1'
1482 ],
1483 'start_time' => [
1484 'type' => 'string',
1485 'default' => '0'
1486 ],
1487 ];
1488 }
1489 public function get_soundcloud_settings_schema()
1490 {
1491 return [
1492 'visual' => [
1493 'type' => 'string',
1494 'default' => ''
1495 ],
1496 'autoplay' => [
1497 'type' => 'string',
1498 'default' => ''
1499 ],
1500 'play_on_mobile' => [
1501 'type' => 'string',
1502 'default' => ''
1503 ],
1504 'color' => [
1505 'type' => 'string',
1506 'default' => '#dd3333'
1507 ],
1508
1509 'share_button' => [
1510 'type' => 'string',
1511 'default' => ''
1512 ],
1513 'comments' => [
1514 'type' => 'string',
1515 'default' => '1'
1516 ],
1517 'artwork' => [
1518 'type' => 'string',
1519 'default' => ''
1520 ],
1521 'play_count' => [
1522 'type' => 'string',
1523 'default' => '1'
1524 ],
1525 'username' => [
1526 'type' => 'string',
1527 'default' => '1'
1528 ],
1529 'download_button' => [
1530 'type' => 'string',
1531 'default' => '1'
1532 ],
1533 'buy_button' => [
1534 'type' => 'string',
1535 'default' => '1'
1536 ],
1537 ];
1538 }
1539
1540 public function enhance_missing_title($embed)
1541 {
1542
1543 $embed_arr = get_object_vars($embed);
1544
1545 $url = $embed->url;
1546
1547 if (strpos($url, 'gettyimages') !== false) {
1548 $title = $embed_arr[$url]['title'];
1549 $embed->embed = $embed->embed . "
1550 <script>
1551 if (typeof gie === 'function') {
1552 gie(function(){
1553 var iframe = document.querySelector('.ose-embedpress-responsive iframe');
1554 if(iframe && !iframe.getAttribute('title')){
1555 iframe.setAttribute('title', '$title')
1556 }
1557 });
1558 }
1559 </script>
1560 ";
1561 }
1562
1563
1564 return $embed;
1565 }
1566
1567
1568 public function embedpress_generate_social_share_meta()
1569 {
1570 $post_id = get_the_ID();
1571 $post = get_post($post_id);
1572 $tags = '';
1573
1574 $thumbnail_url = get_the_post_thumbnail_url($post_id);
1575
1576 if (!empty($_GET['hash'])) {
1577
1578 $id_value = sanitize_text_field($_GET['hash']);
1579
1580 $url = get_the_permalink($post_id);
1581
1582 if (class_exists('Elementor\Plugin') && \Elementor\Plugin::$instance->db->is_built_with_elementor(get_the_ID())) {
1583 $page_settings = get_post_meta($post_id, '_elementor_data', true);
1584
1585 $ep_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_elementor');
1586 $pdf_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpress_pdf');
1587 $doc_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_document');
1588
1589
1590
1591 if (is_array($ep_settings) && !empty($ep_settings)) {
1592 $title = !empty($ep_settings['settings']['embedpress_content_title']) ? $ep_settings['settings']['embedpress_content_title'] : '';
1593
1594 $description = !empty($ep_settings['settings']['embedpress_content_descripiton']) ? $ep_settings['settings']['embedpress_content_descripiton'] : '';
1595
1596 $image_url = !empty($ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url']) ? $ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url'] : '';
1597 } else if (is_array($pdf_settings) && !empty($pdf_settings)) {
1598 $title = !empty($pdf_settings['settings']['embedpress_pdf_content_title']) ? $pdf_settings['settings']['embedpress_pdf_content_title'] : '';
1599
1600 $description = !empty($pdf_settings['settings']['embedpress_pdf_content_descripiton']) ? $pdf_settings['settings']['embedpress_pdf_content_descripiton'] : '';
1601
1602 $image_url = !empty($pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url'] : '';
1603 } else if (is_array($doc_settings) && !empty($doc_settings)) {
1604 $title = !empty($doc_settings['settings']['embedpress_doc_content_title']) ? $doc_settings['settings']['embedpress_doc_content_title'] : '';
1605
1606 $description = !empty($doc_settings['settings']['embedpress_doc_content_descripiton']) ? $doc_settings['settings']['embedpress_doc_content_descripiton'] : '';
1607
1608 $image_url = !empty($doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url']) ? $doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url'] : '';
1609 }
1610
1611 if (!empty($image_url)) {
1612 $tags .= "<meta name='twitter:image' content='" . esc_url($image_url) . "'/>\n";
1613 $tags .= "<meta property='og:image' content='" . esc_url($image_url) . "'/>\n";
1614 $tags .= "<meta property='og:url' content='" . esc_url("$url?hash=$id_value") . "'/>\n";
1615 } else if (!empty($thumbnail_url)) {
1616 $tags .= "<meta name='twitter:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1617 $tags .= "<meta property='og:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1618 }
1619
1620 if (!empty($title)) {
1621 $title = json_decode('"' . $title . '"', JSON_UNESCAPED_UNICODE);
1622 $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1623 $tags .= "<meta name='title' property='og:title' content='" . esc_attr($title) . "'>\n";
1624 $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1625 }
1626
1627 if (!empty($description)) {
1628 $description = json_decode('"' . $description . '"', JSON_UNESCAPED_UNICODE);
1629 $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1630 $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1631 }
1632 } else {
1633
1634 $block_content = $post->post_content;
1635
1636 // Regular expression to match the id and href keys and their values
1637 $thumb = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customThumbnail":"(.*?)"/';
1638 $title = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customTitle":"(.*?)"/';
1639 $description = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customDescription":"(.*?)"/';
1640
1641 // Search for the regex pattern in the string and extract the href value
1642 // Search for the regex pattern in the string and extract the href value
1643 if (preg_match($thumb, $block_content, $matches1)) {
1644 $image_url = esc_url($matches1[1]);
1645 echo "\n<meta name='twitter:image' content='" . esc_attr($image_url) . "'/>\n";
1646 echo "<meta property='og:image' content='" . esc_attr($image_url) . "'/>\n";
1647 echo "<meta property='og:url' content='" . esc_url("$url?hash=$id_value") . "'/>\n";
1648 } else if (!empty($thumbnail_url)) {
1649 echo "\n<meta name='twitter:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1650 echo "<meta property='og:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1651 }
1652
1653 if (preg_match($title, $block_content, $matches2)) {
1654 $title = json_decode('"' . $matches2[1] . '"', JSON_UNESCAPED_UNICODE);
1655 echo "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1656 echo "<meta name='title' property='og:title' content='" . esc_attr($title) . "'>\n";
1657 echo "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1658 }
1659
1660 if (preg_match($description, $block_content, $matches3)) {
1661 $description = json_decode('"' . $matches3[1] . '"', JSON_UNESCAPED_UNICODE);
1662 echo "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1663 echo "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1664 }
1665 }
1666
1667 $tags .= "<meta name='twitter:card' content='summary_large_image'/>\n";
1668
1669 remove_action('wp_head', 'rel_canonical');
1670
1671 echo $tags;
1672 }
1673 }
1674 }
1675