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