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