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