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