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