PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.9.10
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.9.10
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Includes / Classes / Feature_Enhancer.php
embedpress / EmbedPress / Includes / Classes Last commit date
Elementor_Enhancer.php 3 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 2 years ago EmbedPress_Plugin_Usage_Tracker.php 2 years ago Extend_CustomPlayer_Controls.php 3 years ago Extend_Elementor_Controls.php 2 years ago Feature_Enhancer.php 2 years ago Helper.php 2 years ago
Feature_Enhancer.php
1618 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 if ($query !== null) {
806 parse_str($query, $params);
807 }
808
809 // Set the class in the attributes
810 $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class);
811 $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed);
812
813
814 // Embed Options
815 $embedOptions = new \stdClass;
816 $embedOptions->videoFoam = false;
817 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
818 $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true);
819
820 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
821
822 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
823
824 if(!empty($options['start_time'])){
825 $embedOptions->time = isset($options['start_time']) ? $options['start_time'] : 0;
826 }
827
828 if (isset($options['player_color'])) {
829 $color = $options['player_color'];
830 if (null !== $color) {
831 $embedOptions->playerColor = $color;
832 }
833 }
834
835 // Plugins
836 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
837
838 $pluginList = array();
839
840 // Resumable
841 if (isset($options['plugin_resumable'])) {
842 $isResumableEnabled = $options['plugin_resumable'];
843 if ($isResumableEnabled) {
844 // Add the resumable plugin
845 $pluginList['resumable'] = array(
846 'src' => $pluginsBaseURL . '/resumable.min.js',
847 'async' => false
848 );
849 }
850 }
851
852 // Add a fix for the autoplay and resumable work better together
853 if (isset($options->autoPlay)) {
854 if ($isResumableEnabled) {
855 $pluginList['fixautoplayresumable'] = array(
856 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
857 );
858 }
859 }
860
861 // Focus plugin
862 if (isset($options['plugin_focus'])) {
863 $isFocusEnabled = $options['plugin_focus'];
864 $pluginList['dimthelights'] = array(
865 'src' => $pluginsBaseURL . '/dimthelights.min.js',
866 'autoDim' => $isFocusEnabled
867 );
868 $embedOptions->focus = $isFocusEnabled;
869 }
870
871 // Rewind plugin
872 if (isset($options['plugin_rewind'])) {
873 if ($options['plugin_rewind']) {
874 $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10;
875
876 $pluginList['rewind'] = array(
877 'src' => $pluginsBaseURL . '/rewind.min.js'
878 );
879 }
880 }
881 $embedOptions->plugin = $pluginList;
882
883 $embedOptions = json_encode($embedOptions);
884
885 // Get the video ID
886 $videoId = $this->getVideoIDFromURL($embed->url);
887 $shortVideoId = substr($videoId, 0, 3);
888
889 // Responsive?
890
891 $class = array(
892 'wistia_embed',
893 'wistia_async_' . $videoId
894 );
895
896 $attribs = array(
897 sprintf('id="wistia_%s"', $videoId),
898 sprintf('class="%s"', join(' ', $class)),
899 sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height)
900 );
901
902 $labels = array(
903 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
904 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
905 'you_have_watched_it_before' => __(
906 'It looks like you\'ve watched<br />part of this video before!',
907 'embedpress'
908 ),
909 );
910 $labels = json_encode($labels);
911
912 preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches);
913 $uid = $matches[1];
914
915 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
916 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
917 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
918 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
919 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
920 $html .= '</div>';
921 $embed->embed = $html;
922 }
923
924 return $embed;
925 }
926
927 public function enhance_twitch($embed_content)
928 {
929 $e = isset($embed_content->url) && isset($embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : [];
930 if (isset($e['provider_name']) && strtoupper($e['provider_name']) === 'TWITCH' && isset($embed_content->embed)) {
931 $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema());
932
933 $atts = isset($embed_content->attributes) ? $embed_content->attributes : [];
934 $time = '0h0m0s';
935 $type = $e['type'];
936 $content_id = $e['content_id'];
937 $channel = 'channel' === $type ? $content_id : '';
938 $video = 'video' === $type ? $content_id : '';
939 $muted = isset($settings['embedpress_pro_twitch_mute']) && ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true' : 'false';
940 $full_screen = isset($settings['embedpress_pro_fs']) && ('yes' === $settings['embedpress_pro_fs']) ? 'true' : 'false';
941 $autoplay = isset($settings['embedpress_pro_twitch_autoplay']) && ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true' : 'false';
942 $theme = !empty($settings['embedpress_pro_twitch_theme']) ? $settings['embedpress_pro_twitch_theme'] : 'dark';
943
944 $layout = 'video';
945 $width = !empty($atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800;
946 $height = !empty($atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450;
947 if (!empty($settings['start_time'])) {
948 $ta = explode(':', gmdate("G:i:s", $settings['start_time']));
949 $h = $ta[0] . 'h';
950 $m = ($ta[1] * 1) . 'm';
951 $s = ($ta[2] * 1) . 's';
952 $time = $h . $m . $s;
953 }
954 $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}";
955 $pars_url = wp_parse_url(get_site_url());
956 $url = !empty($pars_url['host']) ? $url . '&parent=' . $pars_url['host'] : $url;
957 ob_start();
958 ?>
959 <div class="embedpress_wrapper" data-url="<?php echo esc_url($embed_content->url); ?>">
960 <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>
961 </div>
962 <?php
963 $c = ob_get_clean();
964 $embed_content->embed = $c;
965 }
966
967 return $embed_content;
968 }
969 public function enhance_dailymotion($embed)
970 {
971 $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema());
972 $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');
973
974 if (
975 $isDailymotion && isset($embed->embed)
976 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
977 ) {
978 // Parse the url to retrieve all its info like variables etc.
979 $url_full = $match[1];
980 $params = [
981 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null),
982 'mute' => (int) isset($options['mute']) ? $options['mute'] : null,
983 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null,
984 'controls' => (int) isset($options['controls']) ? $options['controls'] : null,
985 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null,
986 'endscreen-enable' => 0,
987 ];
988
989 if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') {
990 $params['playsinline'] = 1;
991 }
992 $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null;
993 if (is_embedpress_pro_active()) {
994 $params['ui-logo'] = (int) isset($options['show_logo']) ? $options['show_logo'] : null;
995 }
996
997 $url_modified = $url_full;
998 foreach ($params as $param => $value) {
999 $url_modified = add_query_arg($param, $value, $url_modified);
1000 }
1001 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1002 }
1003
1004 return $embed;
1005 }
1006 public function enhance_soundcloud($embed)
1007 {
1008
1009 $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');
1010
1011 if (
1012 $isSoundcloud && isset($embed->embed)
1013 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
1014 ) {
1015 $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema());
1016 // Parse the url to retrieve all its info like variables etc.
1017 $url_full = $match[1];
1018 $params = [
1019 'color' => str_replace('#', '', $options['color']),
1020 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false',
1021 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false',
1022 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false',
1023 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false',
1024 'buying' => 'false',
1025 'download' => 'false',
1026 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false',
1027 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false',
1028 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false',
1029 ];
1030
1031 if (is_embedpress_pro_active()) {
1032 $params['buying'] = isset($options['buy_button']) && $options['buy_button'] == '1' ? 'true' : 'false';
1033 $params['download'] = isset($options['download_button']) && $options['download_button'] == '1' ? 'true' : 'false';
1034 }
1035
1036 $url_modified = $url_full;
1037 foreach ($params as $param => $value) {
1038 $url_modified = add_query_arg($param, $value, $url_modified);
1039 }
1040
1041 // Replaces the old url with the new one.
1042 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1043 if ('false' === $params['visual']) {
1044 $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed);
1045 }
1046 }
1047
1048 return $embed;
1049 }
1050 public function embedpress_gutenberg_register_block_youtube($youtube_params)
1051 {
1052 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
1053 return $this->get_youtube_params($youtube_options);
1054 }
1055 public function embedpress_gutenberg_register_block_vimeo()
1056 {
1057 if (function_exists('register_block_type')) :
1058 register_block_type('embedpress/vimeo-block', array(
1059 'attributes' => array(
1060 'url' => array(
1061 'type' => 'string',
1062 'default' => ''
1063 ),
1064 'iframeSrc' => array(
1065 'type' => 'string',
1066 'default' => ''
1067 ),
1068 ),
1069 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo']
1070 ));
1071 endif;
1072 }
1073 public function embedpress_gutenberg_render_block_vimeo($attributes)
1074 {
1075 ob_start();
1076 if (!empty($attributes) && !empty($attributes['iframeSrc'])) :
1077 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
1078 $vimeo_params = $this->get_vimeo_params($vimeo_options);
1079 $iframeUrl = $attributes['iframeSrc'];
1080 $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center');
1081 foreach ($vimeo_params as $param => $value) {
1082 $iframeUrl = add_query_arg($param, $value, $iframeUrl);
1083 }
1084 //@TODO; test responsive without static height width, keeping for now backward compatibility
1085 ?>
1086 <div class="ose-vimeo wp-block-embed-vimeo <?php echo $align; ?>">
1087 <iframe src="<?php echo esc_url($iframeUrl); ?>" allowtransparency="true" frameborder="0" width="640" height="360">
1088 </iframe>
1089 </div>
1090 <?php
1091 endif;
1092
1093 return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean());
1094 }
1095 public function get_youtube_settings_schema()
1096 {
1097 return [
1098 'autoplay' => [
1099 'type' => 'bool',
1100 'default' => false
1101 ],
1102 'color' => [
1103 'type' => 'string',
1104 'default' => 'red'
1105 ],
1106 'cc_load_policy' => [
1107 'type' => 'bool',
1108 'default' => false
1109 ],
1110 'controls' => [
1111 'type' => 'string',
1112 'default' => '1'
1113 ],
1114 'fs' => [
1115 'type' => 'bool',
1116 'default' => true
1117 ],
1118 'iv_load_policy' => [
1119 'type' => 'radio',
1120 'default' => '1'
1121 ],
1122 'rel' => [
1123 'type' => 'bool',
1124 'default' => true
1125 ],
1126 'modestbranding' => [
1127 'type' => 'string',
1128 'default' => '0'
1129 ],
1130 'logo_url' => [
1131 'type' => 'url',
1132 ],
1133 'logo_xpos' => [
1134 'type' => 'number',
1135 'default' => 10
1136 ],
1137 'logo_ypos' => [
1138 'type' => 'number',
1139 'default' => 10
1140 ],
1141 'cta_url' => [
1142 'type' => 'url',
1143 ],
1144 'start_time' => [
1145 'type' => 'number',
1146 'default' => 10
1147 ],
1148 'end_time' => [
1149 'type' => 'number',
1150 'default' => 10
1151 ],
1152 ];
1153 }
1154 public function get_vimeo_settings_schema()
1155 {
1156 return array(
1157 'start_time' => [
1158 'type' => 'number',
1159 'default' => 10
1160 ],
1161 'autoplay' => array(
1162 'type' => 'bool',
1163 'default' => false
1164 ),
1165 'loop' => array(
1166 'type' => 'bool',
1167 'default' => false
1168 ),
1169 'autopause' => array(
1170 'type' => 'bool',
1171 'default' => false
1172 ),
1173 'vimeo_dnt' => array(
1174 'type' => 'bool',
1175 'default' => true,
1176 ),
1177 'color' => array(
1178 'type' => 'text',
1179 'default' => '#00adef',
1180 'classes' => 'color-field'
1181 ),
1182 'display_title' => array(
1183 'type' => 'bool',
1184 'default' => true
1185 ),
1186 'display_author' => array(
1187 'type' => 'bool',
1188 'default' => true
1189 ),
1190 'display_avatar' => array(
1191 'type' => 'bool',
1192 'default' => true
1193 )
1194 );
1195 }
1196 public function get_wistia_settings_schema()
1197 {
1198 return array(
1199 'start_time' => [
1200 'type' => 'number',
1201 'default' => 0
1202 ],
1203 'display_fullscreen_button' => array(
1204 'type' => 'bool',
1205 'default' => true
1206 ),
1207 'display_playbar' => array(
1208 'type' => 'bool',
1209 'default' => true
1210 ),
1211 'small_play_button' => array(
1212 'type' => 'bool',
1213 'default' => true
1214 ),
1215 'display_volume_control' => array(
1216 'type' => 'bool',
1217 'default' => true
1218 ),
1219 'autoplay' => array(
1220 'type' => 'bool',
1221 'default' => false
1222 ),
1223 'volume' => array(
1224 'type' => 'text',
1225 'default' => '100'
1226 ),
1227 'player_color' => array(
1228 'type' => 'text',
1229 'default' => '#00adef',
1230 ),
1231 'plugin_resumable' => array(
1232 'type' => 'bool',
1233 'default' => false
1234 ),
1235 'plugin_captions' => array(
1236 'type' => 'bool',
1237 'default' => false
1238 ),
1239 'plugin_captions_default' => array(
1240 'type' => 'bool',
1241 'default' => false
1242 ),
1243 'plugin_focus' => array(
1244 'type' => 'bool',
1245 'default' => false
1246 ),
1247 'plugin_rewind' => array(
1248 'type' => 'bool',
1249 'default' => false
1250 ),
1251 'plugin_rewind_time' => array(
1252 'type' => 'text',
1253 'default' => '10'
1254 ),
1255 );
1256 }
1257
1258
1259 public function getVideoIDFromURL($url)
1260 {
1261 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
1262 // https://ostraining-1.wistia.com/medias/xf1edjzn92
1263 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
1264
1265 $id = false;
1266 if (isset($matches[1])) {
1267 $id = $matches[1];
1268 }
1269
1270 return $id;
1271 }
1272 public function embedpress_wistia_block_after_embed($attributes)
1273 {
1274 $embedOptions = $this->embedpress_wistia_pro_get_options();
1275 // Get the video ID
1276 $videoId = $this->getVideoIDFromURL($attributes['url']);
1277 $shortVideoId = $videoId;
1278
1279 $labels = array(
1280 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
1281 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
1282 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
1283 );
1284 $labels = json_encode($labels);
1285
1286
1287 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
1288 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
1289 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
1290
1291
1292
1293 echo $html;
1294 }
1295 public function embedpress_wistia_pro_get_options()
1296 {
1297 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
1298 // Embed Options
1299 $embedOptions = new \stdClass;
1300 // $embedOptions->videoFoam = true;
1301 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
1302 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
1303 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
1304
1305 if (isset($options['player_color'])) {
1306 $color = $options['player_color'];
1307 if (null !== $color) {
1308 $embedOptions->playerColor = $color;
1309 }
1310 }
1311
1312 // Plugins
1313 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
1314
1315 $pluginList = array();
1316
1317 // Resumable
1318 if (isset($options['plugin_resumable'])) {
1319 $isResumableEnabled = $options['plugin_resumable'];
1320 if ($isResumableEnabled) {
1321 // Add the resumable plugin
1322 $pluginList['resumable'] = array(
1323 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
1324 'async' => false
1325 );
1326 }
1327 }
1328 // Add a fix for the autoplay and resumable work better together
1329 //@TODO; check baseurl deeply, not looking good
1330 if ($options['autoplay']) {
1331 if ($isResumableEnabled) {
1332 $pluginList['fixautoplayresumable'] = array(
1333 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
1334 );
1335 }
1336 }
1337
1338
1339 // Focus plugin
1340 if (isset($options['plugin_focus'])) {
1341 $isFocusEnabled = $options['plugin_focus'];
1342 $pluginList['dimthelights'] = array(
1343 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
1344 'autoDim' => $isFocusEnabled
1345 );
1346 $embedOptions->focus = $isFocusEnabled;
1347 }
1348
1349 $embedOptions->plugin = $pluginList;
1350 $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions);
1351 $embedOptions = json_encode($embedOptions);
1352 return apply_filters('embedpress_wistia_params_after_encode', $embedOptions);
1353 }
1354
1355
1356 public function get_twitch_settings_schema()
1357 {
1358 return [
1359 'start_time' => [
1360 'type' => 'number',
1361 'default' => 0,
1362 ],
1363 'embedpress_pro_twitch_autoplay' => [
1364 'type' => 'string',
1365 'default' => 'no',
1366 ],
1367 'embedpress_pro_twitch_chat' => [
1368 'type' => 'string',
1369 'default' => 'no',
1370 ],
1371
1372 'embedpress_pro_twitch_theme' => [
1373 'type' => 'string',
1374 'default' => 'dark',
1375 ],
1376 'embedpress_pro_fs' => [
1377 'type' => 'string',
1378 'default' => 'yes',
1379 ],
1380 'embedpress_pro_twitch_mute' => [
1381 'type' => 'string',
1382 'default' => 'yes',
1383 ],
1384
1385 ];
1386 }
1387 public function get_dailymotion_settings_schema()
1388 {
1389 return [
1390 'autoplay' => [
1391 'type' => 'string',
1392 'default' => ''
1393 ],
1394 'play_on_mobile' => [
1395 'type' => 'string',
1396 'default' => ''
1397 ],
1398 'color' => [
1399 'type' => 'string',
1400 'default' => '#dd3333'
1401 ],
1402 'mute' => [
1403 'type' => 'string',
1404 'default' => ''
1405 ],
1406 'controls' => [
1407 'type' => 'string',
1408 'default' => '1'
1409 ],
1410 'video_info' => [
1411 'type' => 'string',
1412 'default' => '1'
1413 ],
1414 'show_logo' => [
1415 'type' => 'string',
1416 'default' => '1'
1417 ],
1418 'start_time' => [
1419 'type' => 'string',
1420 'default' => '0'
1421 ],
1422 ];
1423 }
1424 public function get_soundcloud_settings_schema()
1425 {
1426 return [
1427 'visual' => [
1428 'type' => 'string',
1429 'default' => ''
1430 ],
1431 'autoplay' => [
1432 'type' => 'string',
1433 'default' => ''
1434 ],
1435 'play_on_mobile' => [
1436 'type' => 'string',
1437 'default' => ''
1438 ],
1439 'color' => [
1440 'type' => 'string',
1441 'default' => '#dd3333'
1442 ],
1443
1444 'share_button' => [
1445 'type' => 'string',
1446 'default' => ''
1447 ],
1448 'comments' => [
1449 'type' => 'string',
1450 'default' => '1'
1451 ],
1452 'artwork' => [
1453 'type' => 'string',
1454 'default' => ''
1455 ],
1456 'play_count' => [
1457 'type' => 'string',
1458 'default' => '1'
1459 ],
1460 'username' => [
1461 'type' => 'string',
1462 'default' => '1'
1463 ],
1464 'download_button' => [
1465 'type' => 'string',
1466 'default' => '1'
1467 ],
1468 'buy_button' => [
1469 'type' => 'string',
1470 'default' => '1'
1471 ],
1472 ];
1473 }
1474
1475 public function enhance_missing_title($embed){
1476
1477 $embed_arr = get_object_vars($embed);
1478
1479 $url = $embed->url;
1480
1481 if (strpos($url, 'gettyimages') !== false) {
1482 $title = $embed_arr[$url]['title'];
1483 $embed->embed = $embed->embed . "
1484 <script>
1485 if (typeof gie === 'function') {
1486 gie(function(){
1487 var iframe = document.querySelector('.ose-embedpress-responsive iframe');
1488 if(iframe && !iframe.getAttribute('title')){
1489 iframe.setAttribute('title', '$title')
1490 }
1491 });
1492 }
1493 </script>
1494 ";
1495 }
1496
1497
1498 return $embed;
1499 }
1500
1501
1502 public function embedpress_generate_social_share_meta()
1503 {
1504 $post_id = get_the_ID();
1505 $post = get_post($post_id);
1506 $tags = '';
1507
1508 $thumbnail_url = get_the_post_thumbnail_url($post_id);
1509
1510 if (!empty($_GET['hash'])) {
1511
1512 $id_value = sanitize_text_field($_GET['hash']);
1513
1514 $url = get_the_permalink( $post_id );
1515
1516 if (class_exists('Elementor\Plugin') && \Elementor\Plugin::$instance->db->is_built_with_elementor(get_the_ID())) {
1517 $page_settings = get_post_meta( $post_id, '_elementor_data', true );
1518
1519 $ep_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_elementor');
1520 $pdf_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpress_pdf');
1521 $doc_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_document');
1522
1523
1524
1525 if (is_array($ep_settings) && !empty($ep_settings)) {
1526 $title = !empty($ep_settings['settings']['embedpress_content_title']) ? $ep_settings['settings']['embedpress_content_title'] : '';
1527
1528 $description = !empty($ep_settings['settings']['embedpress_content_descripiton']) ? $ep_settings['settings']['embedpress_content_descripiton'] : '';
1529
1530 $image_url = !empty($ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url']) ? $ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url'] : '';
1531 }
1532 else if (is_array($pdf_settings) && !empty($pdf_settings)) {
1533 $title = !empty($pdf_settings['settings']['embedpress_pdf_content_title']) ? $pdf_settings['settings']['embedpress_pdf_content_title'] : '';
1534
1535 $description = !empty($pdf_settings['settings']['embedpress_pdf_content_descripiton']) ? $pdf_settings['settings']['embedpress_pdf_content_descripiton'] : '';
1536
1537 $image_url = !empty($pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url'] : '';
1538 }
1539 else if (is_array($doc_settings) && !empty($doc_settings)) {
1540 $title = !empty($doc_settings['settings']['embedpress_doc_content_title']) ? $doc_settings['settings']['embedpress_doc_content_title'] : '';
1541
1542 $description = !empty($doc_settings['settings']['embedpress_doc_content_descripiton']) ? $doc_settings['settings']['embedpress_doc_content_descripiton'] : '';
1543
1544 $image_url = !empty($doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url']) ? $doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url'] : '';
1545 }
1546
1547 if (!empty($image_url)) {
1548 $tags .= "<meta name='twitter:image' content='" . esc_url($image_url) . "'/>\n";
1549 $tags .= "<meta property='og:image' content='" . esc_url($image_url) . "'/>\n";
1550 $tags .= "<meta property='og:url' content='" . esc_url("$url?hash=$id_value") . "'/>\n";
1551 } else if (!empty($thumbnail_url)) {
1552 $tags .= "<meta name='twitter:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1553 $tags .= "<meta property='og:image' content='" . esc_url($thumbnail_url) . "'/>\n";
1554 }
1555
1556 if (!empty($title)) {
1557 $title = json_decode('"' . $title . '"', JSON_UNESCAPED_UNICODE);
1558 $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1559 $tags .= "<meta name='title' property='og:title' content='" . esc_attr($title) . "'>\n";
1560 $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1561 }
1562
1563 if (!empty($description)) {
1564 $description = json_decode('"' . $description . '"', JSON_UNESCAPED_UNICODE);
1565 $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1566 $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1567 }
1568
1569
1570 } else {
1571
1572 $block_content = $post->post_content;
1573
1574 // Regular expression to match the id and href keys and their values
1575 $thumb = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customThumbnail":"(.*?)"/';
1576 $title = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customTitle":"(.*?)"/';
1577 $description = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customDescription":"(.*?)"/';
1578
1579 // Search for the regex pattern in the string and extract the href value
1580 // Search for the regex pattern in the string and extract the href value
1581 if (preg_match($thumb, $block_content, $matches1)) {
1582 $image_url = esc_url($matches1[1]);
1583 echo "\n<meta name='twitter:image' content='" . esc_attr($image_url) . "'/>\n";
1584 echo "<meta property='og:image' content='" . esc_attr($image_url) . "'/>\n";
1585 echo "<meta property='og:url' content='" . esc_url("$url?hash=$id_value") . "'/>\n";
1586 } else if (!empty($thumbnail_url)) {
1587 echo "\n<meta name='twitter:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1588 echo "<meta property='og:image' content='" . esc_attr($thumbnail_url) . "'/>\n";
1589 }
1590
1591 if (preg_match($title, $block_content, $matches2)) {
1592 $title = json_decode('"' . $matches2[1] . '"', JSON_UNESCAPED_UNICODE);
1593 echo "<meta property='og:title' content='" . esc_attr($title) . "'/>\n";
1594 echo "<meta name='title' property='og:title' content='" . esc_attr($title) . "'>\n";
1595 echo "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n";
1596 }
1597
1598 if (preg_match($description, $block_content, $matches3)) {
1599 $description = json_decode('"' . $matches3[1] . '"', JSON_UNESCAPED_UNICODE);
1600 echo "<meta property='og:description' content='" . esc_attr($description) . "'/>\n";
1601 echo "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n";
1602 }
1603
1604 }
1605
1606 $tags .= "<meta name='twitter:card' content='summary_large_image'/>\n";
1607
1608 remove_action('wp_head', 'rel_canonical');
1609
1610 echo $tags;
1611
1612 }
1613 }
1614
1615
1616
1617 }
1618