PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.5.1
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.5.1
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Includes / Classes / Feature_Enhancer.php
embedpress / EmbedPress / Includes / Classes Last commit date
Analytics 2 months ago Database 5 months 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 year ago Extend_Elementor_Controls.php 1 year ago FeatureNoticeManager.php 8 months ago FeatureNotices.php 8 months ago Feature_Enhancer.php 2 months ago Helper.php 2 months ago Pdf_Thumbnail_Handler.php 2 months ago PermalinkHelper.php 10 months ago README_FEATURE_NOTICES.md 8 months ago
Feature_Enhancer.php
1728 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 if (
1086 $isDailymotion && isset($embed->embed)
1087 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
1088 ) {
1089 // Parse the url to retrieve all its info like variables etc.
1090 $url_full = $match[1];
1091 $params = [
1092 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null),
1093 'mute' => (int) isset($options['mute']) ? $options['mute'] : null,
1094 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null,
1095 'controls' => (int) isset($options['controls']) ? $options['controls'] : null,
1096 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null,
1097 'endscreen-enable' => 0,
1098 ];
1099
1100 if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') {
1101 $params['playsinline'] = 1;
1102 }
1103 $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null;
1104
1105 $params = apply_filters('embedpress_enhance_dailymotion', $params, $options);
1106
1107
1108 $url_modified = $url_full;
1109 foreach ($params as $param => $value) {
1110 $url_modified = add_query_arg($param, $value, $url_modified);
1111 }
1112 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1113 }
1114
1115 return $embed;
1116 }
1117 public function enhance_soundcloud($embed)
1118 {
1119
1120 $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');
1121
1122 if (
1123 $isSoundcloud && isset($embed->embed)
1124 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
1125 ) {
1126 $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema());
1127 // Parse the url to retrieve all its info like variables etc.
1128 $url_full = $match[1];
1129 $params = [
1130 'color' => str_replace('#', '', $options['color']),
1131 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false',
1132 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false',
1133 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false',
1134 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false',
1135 'buying' => 'false',
1136 'download' => 'false',
1137 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false',
1138 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false',
1139 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false',
1140 ];
1141
1142 $params = apply_filters('embedpress_enhance_soundcloud', $params, $options);
1143
1144 $url_modified = $url_full;
1145 foreach ($params as $param => $value) {
1146 $url_modified = add_query_arg($param, $value, $url_modified);
1147 }
1148
1149 // Replaces the old url with the new one.
1150 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1151 if ('false' === $params['visual']) {
1152 $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed);
1153 }
1154 }
1155
1156 return $embed;
1157 }
1158 public function embedpress_gutenberg_register_block_youtube($youtube_params)
1159 {
1160 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
1161 return $this->get_youtube_params($youtube_options);
1162 }
1163 public function embedpress_gutenberg_register_block_vimeo()
1164 {
1165 if (function_exists('register_block_type')) :
1166 register_block_type('embedpress/vimeo-block', array(
1167 'attributes' => array(
1168 'url' => array(
1169 'type' => 'string',
1170 'default' => ''
1171 ),
1172 'iframeSrc' => array(
1173 'type' => 'string',
1174 'default' => ''
1175 ),
1176 ),
1177 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo']
1178 ));
1179 endif;
1180 }
1181 public function embedpress_gutenberg_render_block_vimeo($attributes)
1182 {
1183 ob_start();
1184 if (!empty($attributes) && !empty($attributes['iframeSrc'])) :
1185 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
1186 $vimeo_params = $this->get_vimeo_params($vimeo_options);
1187 $iframeUrl = $attributes['iframeSrc'];
1188 $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center');
1189 foreach ($vimeo_params as $param => $value) {
1190 $iframeUrl = add_query_arg($param, $value, $iframeUrl);
1191 }
1192 //@TODO; test responsive without static height width, keeping for now backward compatibility
1193 ?>
1194 <div class="ose-vimeo wp-block-embed-vimeo <?php echo esc_attr($align); ?>">
1195 <iframe src="<?php echo esc_url($iframeUrl); ?>" allowtransparency="true" frameborder="0" width="640" height="360">
1196 </iframe>
1197 </div>
1198 <?php
1199 endif;
1200
1201 return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean());
1202 }
1203 public function get_youtube_settings_schema()
1204 {
1205 return [
1206 'autoplay' => [
1207 'type' => 'bool',
1208 'default' => false
1209 ],
1210 'color' => [
1211 'type' => 'string',
1212 'default' => 'red'
1213 ],
1214 'cc_load_policy' => [
1215 'type' => 'bool',
1216 'default' => false
1217 ],
1218 'controls' => [
1219 'type' => 'string',
1220 'default' => '1'
1221 ],
1222 'fs' => [
1223 'type' => 'bool',
1224 'default' => true
1225 ],
1226 'iv_load_policy' => [
1227 'type' => 'radio',
1228 'default' => '1'
1229 ],
1230 'rel' => [
1231 'type' => 'bool',
1232 'default' => true
1233 ],
1234 'modestbranding' => [
1235 'type' => 'string',
1236 'default' => '0'
1237 ],
1238 'logo_url' => [
1239 'type' => 'url',
1240 ],
1241 'logo_xpos' => [
1242 'type' => 'number',
1243 'default' => 10
1244 ],
1245 'logo_ypos' => [
1246 'type' => 'number',
1247 'default' => 10
1248 ],
1249 'cta_url' => [
1250 'type' => 'url',
1251 ],
1252 'start_time' => [
1253 'type' => 'number',
1254 'default' => 10
1255 ],
1256 'end_time' => [
1257 'type' => 'number',
1258 'default' => 10
1259 ],
1260 ];
1261 }
1262 public function get_vimeo_settings_schema()
1263 {
1264 return array(
1265 'start_time' => [
1266 'type' => 'number',
1267 'default' => 10
1268 ],
1269 'autoplay' => array(
1270 'type' => 'bool',
1271 'default' => false
1272 ),
1273 'loop' => array(
1274 'type' => 'bool',
1275 'default' => false
1276 ),
1277 'autopause' => array(
1278 'type' => 'bool',
1279 'default' => false
1280 ),
1281 'vimeo_dnt' => array(
1282 'type' => 'bool',
1283 'default' => true,
1284 ),
1285 'color' => array(
1286 'type' => 'text',
1287 'default' => '#00adef',
1288 'classes' => 'color-field'
1289 ),
1290 'display_title' => array(
1291 'type' => 'bool',
1292 'default' => true
1293 ),
1294 'display_author' => array(
1295 'type' => 'bool',
1296 'default' => true
1297 ),
1298 'display_avatar' => array(
1299 'type' => 'bool',
1300 'default' => true
1301 )
1302 );
1303 }
1304 public function get_wistia_settings_schema()
1305 {
1306 return array(
1307 'start_time' => [
1308 'type' => 'number',
1309 'default' => 0
1310 ],
1311 'display_fullscreen_button' => array(
1312 'type' => 'bool',
1313 'default' => true
1314 ),
1315 'display_playbar' => array(
1316 'type' => 'bool',
1317 'default' => true
1318 ),
1319 'small_play_button' => array(
1320 'type' => 'bool',
1321 'default' => true
1322 ),
1323 'display_volume_control' => array(
1324 'type' => 'bool',
1325 'default' => true
1326 ),
1327 'autoplay' => array(
1328 'type' => 'bool',
1329 'default' => false
1330 ),
1331 'volume' => array(
1332 'type' => 'text',
1333 'default' => '100'
1334 ),
1335 'player_color' => array(
1336 'type' => 'text',
1337 'default' => '#00adef',
1338 ),
1339 'plugin_resumable' => array(
1340 'type' => 'bool',
1341 'default' => false
1342 ),
1343 'plugin_captions' => array(
1344 'type' => 'bool',
1345 'default' => false
1346 ),
1347 'plugin_captions_default' => array(
1348 'type' => 'bool',
1349 'default' => false
1350 ),
1351 'plugin_focus' => array(
1352 'type' => 'bool',
1353 'default' => false
1354 ),
1355 'plugin_rewind' => array(
1356 'type' => 'bool',
1357 'default' => false
1358 ),
1359 'plugin_rewind_time' => array(
1360 'type' => 'text',
1361 'default' => '10'
1362 ),
1363 );
1364 }
1365
1366
1367 public function getVideoIDFromURL($url)
1368 {
1369 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
1370 // https://ostraining-1.wistia.com/medias/xf1edjzn92
1371 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
1372
1373 $id = false;
1374 if (isset($matches[1])) {
1375 $id = $matches[1];
1376 }
1377
1378 return $id;
1379 }
1380 public function embedpress_wistia_block_after_embed($attributes)
1381 {
1382 $embedOptions = $this->embedpress_wistia_pro_get_options();
1383 // Get the video ID
1384 $videoId = $this->getVideoIDFromURL($attributes['url']);
1385 $shortVideoId = $videoId;
1386
1387 $labels = array(
1388 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
1389 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
1390 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
1391 );
1392 $labels = json_encode($labels);
1393
1394
1395 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
1396 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
1397 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
1398
1399
1400
1401 echo $html;
1402 }
1403 public function embedpress_wistia_pro_get_options()
1404 {
1405 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
1406 // Embed Options
1407 $embedOptions = new \stdClass;
1408 // $embedOptions->videoFoam = true;
1409 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
1410 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
1411 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
1412
1413 if (isset($options['player_color'])) {
1414 $color = $options['player_color'];
1415 if (null !== $color) {
1416 $embedOptions->playerColor = $color;
1417 }
1418 }
1419
1420 // Plugins
1421 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
1422
1423 $pluginList = array();
1424
1425 // Resumable
1426 if (isset($options['plugin_resumable'])) {
1427 $isResumableEnabled = $options['plugin_resumable'];
1428 if ($isResumableEnabled) {
1429 // Add the resumable plugin
1430 $pluginList['resumable'] = array(
1431 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
1432 'async' => false
1433 );
1434 }
1435 }
1436 // Add a fix for the autoplay and resumable work better together
1437 //@TODO; check baseurl deeply, not looking good
1438 if ($options['autoplay']) {
1439 if ($isResumableEnabled) {
1440 $pluginList['fixautoplayresumable'] = array(
1441 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
1442 );
1443 }
1444 }
1445
1446
1447 // Focus plugin
1448 if (isset($options['plugin_focus'])) {
1449 $isFocusEnabled = $options['plugin_focus'];
1450 $pluginList['dimthelights'] = array(
1451 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
1452 'autoDim' => $isFocusEnabled
1453 );
1454 $embedOptions->focus = $isFocusEnabled;
1455 }
1456
1457 $embedOptions->plugin = $pluginList;
1458 $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions);
1459 $embedOptions = json_encode($embedOptions);
1460 return apply_filters('embedpress_wistia_params_after_encode', $embedOptions);
1461 }
1462
1463
1464 public function get_twitch_settings_schema()
1465 {
1466 return [
1467 'start_time' => [
1468 'type' => 'number',
1469 'default' => 0,
1470 ],
1471 'embedpress_pro_twitch_autoplay' => [
1472 'type' => 'string',
1473 'default' => 'no',
1474 ],
1475 'embedpress_pro_twitch_chat' => [
1476 'type' => 'string',
1477 'default' => 'no',
1478 ],
1479
1480 'embedpress_pro_twitch_theme' => [
1481 'type' => 'string',
1482 'default' => 'dark',
1483 ],
1484 'embedpress_pro_fs' => [
1485 'type' => 'string',
1486 'default' => 'yes',
1487 ],
1488 'embedpress_pro_twitch_mute' => [
1489 'type' => 'string',
1490 'default' => 'yes',
1491 ],
1492
1493 ];
1494 }
1495 public function get_dailymotion_settings_schema()
1496 {
1497 return [
1498 'autoplay' => [
1499 'type' => 'string',
1500 'default' => ''
1501 ],
1502 'play_on_mobile' => [
1503 'type' => 'string',
1504 'default' => ''
1505 ],
1506 'color' => [
1507 'type' => 'string',
1508 'default' => '#dd3333'
1509 ],
1510 'mute' => [
1511 'type' => 'string',
1512 'default' => ''
1513 ],
1514 'controls' => [
1515 'type' => 'string',
1516 'default' => '1'
1517 ],
1518 'video_info' => [
1519 'type' => 'string',
1520 'default' => '1'
1521 ],
1522 'show_logo' => [
1523 'type' => 'string',
1524 'default' => '1'
1525 ],
1526 'start_time' => [
1527 'type' => 'string',
1528 'default' => '0'
1529 ],
1530 ];
1531 }
1532 public function get_soundcloud_settings_schema()
1533 {
1534 return [
1535 'visual' => [
1536 'type' => 'string',
1537 'default' => ''
1538 ],
1539 'autoplay' => [
1540 'type' => 'string',
1541 'default' => ''
1542 ],
1543 'play_on_mobile' => [
1544 'type' => 'string',
1545 'default' => ''
1546 ],
1547 'color' => [
1548 'type' => 'string',
1549 'default' => '#dd3333'
1550 ],
1551
1552 'share_button' => [
1553 'type' => 'string',
1554 'default' => ''
1555 ],
1556 'comments' => [
1557 'type' => 'string',
1558 'default' => '1'
1559 ],
1560 'artwork' => [
1561 'type' => 'string',
1562 'default' => ''
1563 ],
1564 'play_count' => [
1565 'type' => 'string',
1566 'default' => '1'
1567 ],
1568 'username' => [
1569 'type' => 'string',
1570 'default' => '1'
1571 ],
1572 'download_button' => [
1573 'type' => 'string',
1574 'default' => '1'
1575 ],
1576 'buy_button' => [
1577 'type' => 'string',
1578 'default' => '1'
1579 ],
1580 ];
1581 }
1582
1583 public function enhance_missing_title($embed)
1584 {
1585
1586 $embed_arr = get_object_vars($embed);
1587
1588 $url = $embed->url;
1589
1590 if (strpos($url, 'gettyimages') !== false) {
1591 $title = $embed_arr[$url]['title'] ?? '';
1592 $embed->embed = $embed->embed . "
1593 <script>
1594 if (typeof gie === 'function') {
1595 gie(function(){
1596 var iframe = document.querySelector('.ose-embedpress-responsive iframe');
1597 if(iframe && !iframe.getAttribute('title')){
1598 iframe.setAttribute('title', '$title')
1599 }
1600 });
1601 }
1602 </script>
1603 ";
1604 }
1605
1606
1607 return $embed;
1608 }
1609
1610
1611 public function embedpress_generate_social_share_meta()
1612 {
1613 $post_id = get_the_ID();
1614 $post = get_post($post_id);
1615 $tags = '';
1616
1617 $thumbnail_url = get_the_post_thumbnail_url($post_id);
1618
1619 if (!empty($_GET['hash'])) {
1620
1621 $id_value = sanitize_text_field($_GET['hash']);
1622 $unique_hash = !empty($_GET['unique']) ? sanitize_text_field($_GET['unique']) : '';
1623
1624 $url = get_the_permalink($post_id);
1625
1626 if (class_exists('Elementor\Plugin') && \Elementor\Plugin::$instance->documents->get(get_the_ID())->is_built_with_elementor()) {
1627
1628 $page_settings = get_post_meta($post_id, '_elementor_data', true);
1629
1630 $ep_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_elementor');
1631 $pdf_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpress_pdf');
1632 $doc_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_document');
1633
1634 if (is_array($ep_settings) && !empty($ep_settings)) {
1635 $title = !empty($ep_settings[0]['embedpress_content_title']) ? $ep_settings[0]['embedpress_content_title'] : '';
1636
1637 $description = !empty($ep_settings[0]['embedpress_content_descripiton']) ? $ep_settings[0]['embedpress_content_descripiton'] : '';
1638
1639 $image_url = !empty($ep_settings[0]['embedpress_content_share_custom_thumbnail']['url']) ? $ep_settings[0]['embedpress_content_share_custom_thumbnail']['url'] : '';
1640 } else if (is_array($pdf_settings) && !empty($pdf_settings)) {
1641 $title = !empty($pdf_settings[0]['embedpress_pdf_content_title']) ? $pdf_settings[0]['embedpress_pdf_content_title'] : '';
1642
1643 $description = !empty($pdf_settings[0]['embedpress_pdf_content_descripiton']) ? $pdf_settings[0]['embedpress_pdf_content_descripiton'] : '';
1644
1645 $image_url = !empty($pdf_settings[0]['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $pdf_settings[0]['embedpress_pdf_content_share_custom_thumbnail']['url'] : '';
1646 } else if (is_array($doc_settings) && !empty($doc_settings)) {
1647 $title = !empty($doc_settings[0]['embedpress_doc_content_title']) ? $doc_settings[0]['embedpress_doc_content_title'] : '';
1648
1649 $description = !empty($doc_settings[0]['embedpress_doc_content_descripiton']) ? $doc_settings[0]['embedpress_doc_content_descripiton'] : '';
1650
1651 $image_url = !empty($doc_settings[0]['embedpress_doc_content_share_custom_thumbnail']['url']) ? $doc_settings[0]['embedpress_doc_content_share_custom_thumbnail']['url'] : '';
1652 }
1653
1654 if (!empty($image_url)) {
1655 $tags .= "<meta name='twitter:image' content='" . esc_url($image_url) . "'/>\n";
1656 $tags .= "<meta property='og:image' content='" . esc_url($image_url) . "'/>\n";
1657 } else if (!empty($thumbnail_url)) {
1658 $tags .= "<meta name='twitter:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1659 $tags .= "<meta property='og:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1660 }
1661
1662 if (!empty($title)) {
1663 $title = json_decode('"' . $title . '"', JSON_UNESCAPED_UNICODE);
1664 $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1665 $tags .= "<meta name='title' content='" . esc_attr($title) . "'>\n";
1666 $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1667
1668 }
1669
1670 if (!empty($description)) {
1671 $description = json_decode('"' . $description . '"', JSON_UNESCAPED_UNICODE);
1672 $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1673 $tags .= "<meta name='description' content='" . esc_attr($description) . "'/>\n";
1674 $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1675
1676 }
1677
1678 } else {
1679
1680 $block_content = $post->post_content;
1681
1682 // Regular expression to match the id and href keys and their values
1683 $thumb = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customThumbnail":"(.*?)"/';
1684 $title_regex = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customTitle":"(.*?)"/';
1685 $description_regex = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customDescription":"(.*?)"/';
1686
1687 // Search for the regex pattern in the string and extract the href value
1688 if (preg_match($thumb, $block_content, $matches1)) {
1689 $image_url = esc_url($matches1[1]);
1690 $tags .= "\n<meta name='twitter:image' content='" . esc_attr($image_url) . "'/>\n";
1691 $tags .= "<meta property='og:image' content='" . esc_attr($image_url) . "'/>\n";
1692
1693 } else if (!empty($thumbnail_url)) {
1694 $tags .= "\n<meta name='twitter:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1695 $tags .= "<meta property='og:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1696 }
1697
1698 if (preg_match($title_regex, $block_content, $matches2)) {
1699 $title = json_decode('"' . $matches2[1] . '"', JSON_UNESCAPED_UNICODE);
1700 $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1701 $tags .= "<meta name='title' content='" . esc_attr($title) . "'>\n";
1702 $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1703
1704 }
1705
1706 if (preg_match($description_regex, $block_content, $matches3)) {
1707 $description = json_decode('"' . $matches3[1] . '"', JSON_UNESCAPED_UNICODE);
1708 $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1709 $tags .= "<meta name='description' content='" . esc_attr($description) . "'/>\n";
1710 $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1711
1712 }
1713 }
1714
1715 $share_url = !empty($unique_hash) ? "$url?hash=$id_value&unique=$unique_hash" : "$url?hash=$id_value";
1716 $tags .= "<meta property='og:url' content='". $share_url . "'/>\n";
1717 $tags .= "<meta name='twitter:card' content='summary_large_image'/>\n";
1718
1719 // Add Open Graph type for better LinkedIn compatibility
1720 $tags .= "<meta property='og:type' content='article'/>\n";
1721
1722 remove_action('wp_head', 'rel_canonical');
1723
1724 echo $tags;
1725 }
1726 }
1727 }
1728